KVM: s390: Use ESCA instead of BSCA at VM init
PATCH v6 1/1 KVM: s390: Use ESCA instead of BSCA at VM init
All modern IBM Z and Linux One machines do offer support for the Extended System Control Area (ESCA). The ESCA is available since the z114/z196 released in 2010.
KVM needs to allocate and manage the SCA for guest VMs. Prior to this change the SCA was setup as Basic SCA only supporting a maximum of 64 vCPUs when initializing the VM. With addition of the 65th vCPU the SCA was needed to be converted to a ESCA.
Instead of allocating a BSCA and upgrading it for PV or when adding the 65th cpu we can always allocate the ESCA directly upon VM creation simplifying the code in multiple places as well as completely removing the need to convert an existing SCA.
In cases where the ESCA is not supported (z10 and earlier) the use of the SCA entries and with that SIGP interpretation are disabled for VMs. This increases the number of exits from the VM in multiprocessor scenarios and thus decreases performance.
The same is true for VSIE where SIGP is currently disabled and thus no SCA entries are used.
The only downside of the change is that we will always allocate 4 pages for a 248 cpu ESCA instead of a single page for the BSCA per VM. In return we can delete a bunch of checks and special handling depending on the SCA type as well as the whole BSCA to ESCA conversion.
With that behavior change we are no longer referencing a bsca_block in kvm->arch.sca. This will always be esca_block instead.
By specifying the type of the sca as esca_block we can simplify access to the sca and get rid of some helpers while making the code clearer.
KVM_MAX_VCPUS is also moved to kvm_host_types to allow using this in future type definitions.
---
Changes in v6:
- Move variable declarations to top of functions
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Revert changes to KVM_MAX_VCPUS
- Correct comments
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Squash patches into single patch
- Revert KVM_CAP_MAX_VCPUS to return KVM_CAP_MAX_VCPU_ID (255) again
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- do not enable sigp for guests when kvm_s390_use_sca_entries() is false
- consistently use kvm_s390_use_sca_entries() instead of sclp.has_sigpif
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- properly apply checkpatch --strict (Thanks Claudio)
- some small comment wording changes
- rebased
- Link to v1: https://lore.kernel.org/r/[email protected]
--- arch/s390/include/asm/kvm_host.h | 5 +- arch/s390/kvm/gaccess.c | 10 +-- arch/s390/kvm/interrupt.c | 78 ++++++------------ arch/s390/kvm/kvm-s390.c | 170 ++++++++------------------------------- arch/s390/kvm/kvm-s390.h | 9 +-- 5 files changed, 66 insertions(+), 206 deletions(-)
arch/s390/include/asm/kvm_host.h +2 -3
@@ -631,9 +631,8 @@ struct kvm_s390_pv {struct mmu_notifier mmu_notifier; }; -struct kvm_arch { -void *sca; -int use_esca; +struct kvm_arch { +struct esca_block *sca;rwlock_t sca_lock;debug_info_t *dbf;struct kvm_s390_float_interrupt float_int;
arch/s390/kvm/gaccess.c +5 -5
@@ -113,7 +113,7 @@ int ipte_lock_held(struct kvm *kvm)int rc;read_lock (&kvm->arch.sca_lock); - rc =kvm_s390_get_ipte_control (kvm)->kh !=0 ; + rc = kvm->arch.sca->ipte_control.kh !=0 ;read_unlock (&kvm->arch.sca_lock);return rc; }
@@ -130,7 +130,7 @@ static void ipte_lock_simple(struct kvm *kvm) goto out; retry:read_lock (&kvm->arch.sca_lock); - ic =kvm_s390_get_ipte_control (kvm); + ic = &kvm->arch.sca->ipte_control; old =READ_ONCE (*ic); do { if (old.k) {
@@ -155,7 +155,7 @@ static void ipte_unlock_simple(struct kvm *kvm)if (kvm->arch.ipte_lock_count) goto out;read_lock (&kvm->arch.sca_lock); - ic =kvm_s390_get_ipte_control (kvm); + ic = &kvm->arch.sca->ipte_control; old =READ_ONCE (*ic); do { new = old;
@@ -173,7 +173,7 @@ static void ipte_lock_siif(struct kvm *kvm) retry:read_lock (&kvm->arch.sca_lock); - ic =kvm_s390_get_ipte_control (kvm); + ic = &kvm->arch.sca->ipte_control; old =READ_ONCE (*ic); do { if (old.kg) {
@@ -193,7 +193,7 @@ static void ipte_unlock_siif(struct kvm *kvm)union ipte_control old, new, *ic;read_lock (&kvm->arch.sca_lock); - ic =kvm_s390_get_ipte_control (kvm); + ic = &kvm->arch.sca->ipte_control; old =READ_ONCE (*ic); do { new = old;
arch/s390/kvm/interrupt.c +25 -53
126 lines not on this page · raw message
arch/s390/kvm/kvm-s390.c +33 -137
258 lines not on this page · raw message
arch/s390/kvm/kvm-s390.h +1 -8
@@ -570,13 +570,6 @@ void kvm_s390_prepare_debug_exit(struct kvm_vcpu *vcpu);int kvm_s390_handle_per_ifetch_icpt (struct kvm_vcpu *vcpu);int kvm_s390_handle_per_event (struct kvm_vcpu *vcpu); -/* support for Basic/Extended SCA handling */ -static inline union ipte_control *kvm_s390_get_ipte_control (struct kvm *kvm) -{ -struct bsca_block *sca = kvm->arch.sca;/* SCA version doesn't matter */ - -return &sca->ipte_control; -}static inline int kvm_s390_use_sca_entries (void ) {/*
@@ -584,7 +577,7 @@ static inline int kvm_s390_use_sca_entries(void)* might use the entries. By not setting the entries and keeping them * invalid, hardware will not access them but intercept. */ -return sclp.has_sigpif; +return sclp.has_sigpif && sclp.has_esca; }void kvm_s390_reinject_machine_check (struct kvm_vcpu *vcpu,struct mcck_volatile_info *mcck_info);
---
base-commit: ec7714e4947909190ffb3041a03311a975350fe0
change-id: 20250513-rm-bsca-ab1e8649aca7
Best regards,
Signature · 1 line
Christoph Schlameuss <[email protected]>