/* trigger a validity icpt for the given scb */ staticint set_validity_icpt(struct kvm_s390_sie_block *scb,
__u16 reason_code)
{
scb->ipa = 0x1000;
scb->ipb = ((__u32) reason_code) << 16;
scb->icptcode = ICPT_VALIDITY; return1;
}
/* mark the prefix as unmapped, this will block the VSIE */ staticvoid prefix_unmapped(struct vsie_page *vsie_page)
{
atomic_or(PROG_REQUEST, &vsie_page->scb_s.prog20);
}
/* mark the prefix as unmapped and wait until the VSIE has been left */ staticvoid prefix_unmapped_sync(struct vsie_page *vsie_page)
{
prefix_unmapped(vsie_page); if (vsie_page->scb_s.prog0c & PROG_IN_SIE)
atomic_or(CPUSTAT_STOP_INT, &vsie_page->scb_s.cpuflags); while (vsie_page->scb_s.prog0c & PROG_IN_SIE)
cpu_relax();
}
/* mark the prefix as mapped, this will allow the VSIE to run */ staticvoid prefix_mapped(struct vsie_page *vsie_page)
{
atomic_andnot(PROG_REQUEST, &vsie_page->scb_s.prog20);
}
/* test if the prefix is mapped into the gmap shadow */ staticint prefix_is_mapped(struct vsie_page *vsie_page)
{ return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST);
}
/* copy the updated intervention request bits into the shadow scb */ staticvoid update_intervention_requests(struct vsie_page *vsie_page)
{ constint bits = CPUSTAT_STOP_INT | CPUSTAT_IO_INT | CPUSTAT_EXT_INT; int cpuflags;
/* xor both blocks in one run */
b1 = (unsignedlong *) vsie_page->crycb.dea_wrapping_key_mask;
b2 = (unsignedlong *)
vcpu->kvm->arch.crypto.crycb->dea_wrapping_key_mask; /* as 56%8 == 0, bitmap_xor won't overwrite any data */
bitmap_xor(b1, b1, b2, BITS_PER_BYTE * 56);
end: switch (ret) { case -EINVAL: return set_validity_icpt(scb_s, 0x0022U); case -EFAULT: return set_validity_icpt(scb_s, 0x0035U); case -EACCES: return set_validity_icpt(scb_s, 0x003CU);
}
scb_s->crycbd = (u32)virt_to_phys(&vsie_page->crycb) | CRYCB_FORMAT2; return0;
}
/* shadow (round up/down) the ibc to avoid validity icpt */ staticvoid prepare_ibc(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
{ struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; /* READ_ONCE does not work on bitfields - use a temporary variable */ const uint32_t __new_ibc = scb_o->ibc; const uint32_t new_ibc = READ_ONCE(__new_ibc) & 0x0fffU;
__u64 min_ibc = (sclp.ibc >> 16) & 0x0fffU;
scb_s->ibc = 0; /* ibc installed in g2 and requested for g3 */ if (vcpu->kvm->arch.model.ibc && new_ibc) {
scb_s->ibc = new_ibc; /* takte care of the minimum ibc level of the machine */ if (scb_s->ibc < min_ibc)
scb_s->ibc = min_ibc; /* take care of the maximum ibc level set for the guest */ if (scb_s->ibc > vcpu->kvm->arch.model.ibc)
scb_s->ibc = vcpu->kvm->arch.model.ibc;
}
}
/* unshadow the scb, copying parameters back to the real scb */ staticvoid unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
{ struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_SM))
new_mso = READ_ONCE(scb_o->mso) & 0xfffffffffff00000UL; /* if the hva of the prefix changes, we have to remap the prefix */ if (scb_s->mso != new_mso || scb_s->prefix != new_prefix)
prefix_unmapped(vsie_page); /* SIE will do mso/msl validity and exception checks for us */
scb_s->msl = scb_o->msl & 0xfffffffffff00000UL;
scb_s->mso = new_mso;
scb_s->prefix = new_prefix;
/* We have to definitely flush the tlb if this scb never ran */ if (scb_s->ihcpu != 0xffffU)
scb_s->ihcpu = scb_o->ihcpu;
/* MVPG and Protection Exception Interpretation are always available */
scb_s->eca |= scb_o->eca & (ECA_MVPGI | ECA_PROTEXCI); /* Host-protection-interruption introduced with ESOP */ if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_ESOP))
scb_s->ecb |= scb_o->ecb & ECB_HOSTPROTINT; /* *CPUTopology *ThisfacilityonlyusestheutilityfieldoftheSCAandnoneof *thecpuentriesthatareproblematicwiththeotherinterpretation *facilitiessowecanpassitthrough
*/ if (test_kvm_facility(vcpu->kvm, 11))
scb_s->ecb |= scb_o->ecb & ECB_PTF; /* transactional execution */ if (test_kvm_facility(vcpu->kvm, 73) && wants_tx) { /* remap the prefix is tx is toggled on */ if (!had_tx)
prefix_unmapped(vsie_page);
scb_s->ecb |= ECB_TE;
} /* specification exception interpretation */
scb_s->ecb |= scb_o->ecb & ECB_SPECI; /* branch prediction */ if (test_kvm_facility(vcpu->kvm, 82))
scb_s->fpf |= scb_o->fpf & FPF_BPBC; /* SIMD */ if (test_kvm_facility(vcpu->kvm, 129)) {
scb_s->eca |= scb_o->eca & ECA_VX;
scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT;
} /* Run-time-Instrumentation */ if (test_kvm_facility(vcpu->kvm, 64))
scb_s->ecb3 |= scb_o->ecb3 & ECB3_RI; /* Instruction Execution Prevention */ if (test_kvm_facility(vcpu->kvm, 130))
scb_s->ecb2 |= scb_o->ecb2 & ECB2_IEP; /* Guarded Storage */ if (test_kvm_facility(vcpu->kvm, 133)) {
scb_s->ecb |= scb_o->ecb & ECB_GS;
scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT;
} if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIIF))
scb_s->eca |= scb_o->eca & ECA_SII; if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IB))
scb_s->eca |= scb_o->eca & ECA_IB; if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_CEI))
scb_s->eca |= scb_o->eca & ECA_CEI; /* Epoch Extension */ if (test_kvm_facility(vcpu->kvm, 139)) {
scb_s->ecd |= scb_o->ecd & ECD_MEF;
scb_s->epdx = scb_o->epdx;
}
if (!gmap_is_shadow(gmap)) return; /* *Onlynewshadowblocksareaddedtothelistduringruntime, *thereforewecansafelyreferencethemallthetime.
*/ for (i = 0; i < kvm->arch.vsie.page_count; i++) {
cur = READ_ONCE(kvm->arch.vsie.pages[i]); if (!cur) continue; if (READ_ONCE(cur->gmap) != gmap) continue;
prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT; /* with mso/msl, the prefix lies at an offset */
prefix += cur->scb_s.mso; if (prefix <= end && start <= prefix + 2 * PAGE_SIZE - 1)
prefix_unmapped_sync(cur);
}
}
/* Unpins a page previously pinned via pin_guest_page, marking it as dirty. */ staticvoid unpin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t hpa)
{
kvm_release_page_dirty(pfn_to_page(hpa >> PAGE_SHIFT)); /* mark the page always as dirty for migration */
mark_page_dirty(kvm, gpa_to_gfn(gpa));
}
/* unpin all blocks previously pinned by pin_blocks(), marking them dirty */ staticvoid unpin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
{ struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
hpa_t hpa;
/* rewind the psw and clear the vsie icpt, so we can retry execution */ staticvoid retry_vsie_icpt(struct vsie_page *vsie_page)
{ struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; int ilen = insn_length(scb_s->ipa >> 8);
/* take care of EXECUTE instructions */ if (scb_s->icptstatus & 1) {
ilen = (scb_s->icptstatus >> 4) & 0x6; if (!ilen)
ilen = 4;
}
scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen);
clear_vsie_icpt(vsie_page);
}
rc_dest = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, dest, &pei_dest);
rc_src = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, src, &pei_src); /* *Eithereverythingwentwell,orsomethingnon-criticalwentwrong *e.g.becauseofarace.Ineithercase,simplyretry.
*/ if (rc_dest == -EAGAIN || rc_src == -EAGAIN || (!rc_dest && !rc_src)) {
retry_vsie_icpt(vsie_page); return -EAGAIN;
} /* Something more serious went wrong, propagate the error */ if (rc_dest < 0) return rc_dest; if (rc_src < 0) return rc_src;
/* The only possible suppressing exception: just deliver it */ if (rc_dest == PGM_TRANSLATION_SPEC || rc_src == PGM_TRANSLATION_SPEC) {
clear_vsie_icpt(vsie_page);
rc_dest = kvm_s390_inject_program_int(vcpu, PGM_TRANSLATION_SPEC);
WARN_ON_ONCE(rc_dest); return1;
}
if (rc > 0)
rc = 0; /* we could still have an icpt */ elseif (current->thread.gmap_int_code) return handle_fault(vcpu, vsie_page);
switch (scb_s->icptcode) { case ICPT_INST: if (scb_s->ipa == 0xb2b0)
rc = handle_stfle(vcpu, vsie_page); break; case ICPT_STOP: /* stop not requested by g2 - must have been a kick */ if (!(atomic_read(&scb_o->cpuflags) & CPUSTAT_STOP_INT))
clear_vsie_icpt(vsie_page); break; case ICPT_VALIDITY: if ((scb_s->ipa & 0xf000) != 0xf000)
scb_s->ipa += 0x1000; break; case ICPT_PARTEXEC: if (scb_s->ipa == 0xb254)
rc = vsie_handle_mvpg(vcpu, vsie_page); break;
} return rc;
}
/* release the old shadow - if any, and mark the prefix as unmapped */
release_gmap_shadow(vsie_page);
gmap = gmap_shadow(vcpu->arch.gmap, asce, edat); if (IS_ERR(gmap)) return PTR_ERR(gmap);
vcpu->kvm->stat.gmap_shadow_create++;
WRITE_ONCE(vsie_page->gmap, gmap); return0;
}
mutex_lock(&kvm->arch.vsie.mutex); if (kvm->arch.vsie.page_count < nr_vcpus) {
vsie_page = (void *)__get_free_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA); if (!vsie_page) {
mutex_unlock(&kvm->arch.vsie.mutex); return ERR_PTR(-ENOMEM);
}
__set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);
kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = vsie_page;
kvm->arch.vsie.page_count++;
} else { /* reuse an existing entry that belongs to nobody */ while (true) {
vsie_page = kvm->arch.vsie.pages[kvm->arch.vsie.next]; if (try_get_vsie_page(vsie_page)) break;
kvm->arch.vsie.next++;
kvm->arch.vsie.next %= nr_vcpus;
} if (vsie_page->scb_gpa != ULONG_MAX)
radix_tree_delete(&kvm->arch.vsie.addr_to_page,
vsie_page->scb_gpa >> 9);
} /* Mark it as invalid until it resides in the tree. */
vsie_page->scb_gpa = ULONG_MAX;
/* Double use of the same address or allocation failure. */ if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9,
vsie_page)) {
put_vsie_page(vsie_page);
mutex_unlock(&kvm->arch.vsie.mutex); return NULL;
}
vsie_page->scb_gpa = addr;
mutex_unlock(&kvm->arch.vsie.mutex);
vsie_page = get_vsie_page(vcpu->kvm, scb_addr); if (IS_ERR(vsie_page)) return PTR_ERR(vsie_page); elseif (!vsie_page) /* double use of sie control block - simply do nothing */ return0;
/* Init the vsie data structures. To be called when a vm is initialized. */ void kvm_s390_vsie_init(struct kvm *kvm)
{
mutex_init(&kvm->arch.vsie.mutex);
INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL_ACCOUNT);
}
/* Destroy the vsie data structures. To be called when a vm is destroyed. */ void kvm_s390_vsie_destroy(struct kvm *kvm)
{ struct vsie_page *vsie_page; int i;
mutex_lock(&kvm->arch.vsie.mutex); for (i = 0; i < kvm->arch.vsie.page_count; i++) {
vsie_page = kvm->arch.vsie.pages[i];
kvm->arch.vsie.pages[i] = NULL;
release_gmap_shadow(vsie_page); /* free the radix tree entry */ if (vsie_page->scb_gpa != ULONG_MAX)
radix_tree_delete(&kvm->arch.vsie.addr_to_page,
vsie_page->scb_gpa >> 9);
free_page((unsignedlong)vsie_page);
}
kvm->arch.vsie.page_count = 0;
mutex_unlock(&kvm->arch.vsie.mutex);
}
/* *EveniftheVCPUletsgooftheshadowsieblockreference,itis *stillvalidinthecache.Sowecansafelykickit.
*/ if (scb) {
atomic_or(PROG_BLOCK_SIE, &scb->prog20); if (scb->prog0c & PROG_IN_SIE)
atomic_or(CPUSTAT_STOP_INT, &scb->cpuflags);
}
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.29Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.