KVM: s390: Use ESCA instead of BSCA at VM init
PATCH v4 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 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 | 7 +- arch/s390/include/asm/kvm_host_types.h | 2 + arch/s390/kvm/gaccess.c | 10 +- arch/s390/kvm/interrupt.c | 71 ++++---------- arch/s390/kvm/kvm-s390.c | 167 ++++++--------------------------- arch/s390/kvm/kvm-s390.h | 9 +- 6 files changed, 58 insertions(+), 208 deletions(-)
arch/s390/include/asm/kvm_host.h +2 -5
@@ -27,8 +27,6 @@#include <asm/isc.h> #include <asm/guarded_storage.h> -#define KVM_MAX_VCPUS 255 -#define KVM_INTERNAL_MEM_SLOTS 1/*
@@ -631,9 +629,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/include/asm/kvm_host_types.h +2 -0
@@ -6,6 +6,8 @@#include <linux/atomic.h> #include <linux/types.h> +#define KVM_MAX_VCPUS 256 +#define KVM_S390_BSCA_CPU_SLOTS 64#define KVM_S390_ESCA_CPU_SLOTS 248
arch/s390/kvm/gaccess.c +5 -5
@@ -112,7 +112,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; }
@@ -129,7 +129,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) {
@@ -154,7 +154,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;
@@ -172,7 +172,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) {
@@ -192,7 +192,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 +18 -53
105 lines not on this page · raw message
arch/s390/kvm/kvm-s390.c +30 -137
248 lines not on this page · raw message
arch/s390/kvm/kvm-s390.h +1 -8
@@ -528,13 +528,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 ) {/*
@@ -542,7 +535,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: 0ff41df1cb268fc69e703a08a57ee14ae967d0ca
change-id: 20250513-rm-bsca-ab1e8649aca7
Best regards,
Signature · 1 line
Christoph Schlameuss <[email protected]>
Janosch Frank
maintainerQuoted 89 lines · Christoph Schlameuss
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_blockinkvm->arch.sca. This will always beesca_blockinstead.
By specifying the type of the sca asesca_blockwe can simplify access to the sca and get rid of some helpers while making the code clearer.
KVM_MAX_VCPUSis also moved tokvm_host_typesto allow using this in future type definitions.Signed-off-by Christoph Schlameuss <[email protected]>---
Changes in v4:
- Squash patches into single patch
- RevertKVM_CAP_MAX_VCPUSto returnKVM_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 whenkvm_s390_use_sca_entries()is false
- consistently usekvm_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 | 7 +- arch/s390/include/asm/kvm_host_types.h | 2 + arch/s390/kvm/gaccess.c | 10 +- arch/s390/kvm/interrupt.c | 71 ++++---------- arch/s390/kvm/kvm-s390.c | 167 ++++++--------------------------- arch/s390/kvm/kvm-s390.h | 9 +- 6 files changed, 58 insertions(+), 208 deletions(-)arch/s390/include/asm/kvm_host.h +2
-5@@ -27,8 +27,6 @@#include <asm/isc.h> #include <asm/guarded_storage.h> -#define KVM_MAX_VCPUS 255 -#define KVM_INTERNAL_MEM_SLOTS 1/* @@ -631,9 +629,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/include/asm/kvm_host_types.h +0
-0
arch/s390/include/asm/kvm_host_types.h line 9
Quoted 4 lines
arch/s390/include/asm/kvm_host_types.h +1
-0@@ -6,6 +6,8 @@#include <linux/atomic.h> #include <linux/types.h> +#define KVM_MAX_VCPUS 256
Why are we doing the whole 256 - 1 game?
arch/s390/include/asm/kvm_host_types.h line 11
Quoted 2 lines
arch/s390/include/asm/kvm_host_types.h +1
-0+#define KVM_S390_BSCA_CPU_SLOTS 64
Can't you remove that now?
Quoted 15 lines
arch/s390/include/asm/kvm_host_types.h +0
-0#define KVM_S390_ESCA_CPU_SLOTS 248arch/s390/kvm/gaccess.c +1
-1@@ -112,7 +112,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; }
[...]
Quoted 5 lines
arch/s390/kvm/gaccess.c +0
-1-static int sca_switch_to_extended (struct kvm *kvm);static void kvm_clock_sync_scb (struct kvm_s390_sie_block *scb,u64 delta) {
arch/s390/kvm/gaccess.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 637
Quoted 9 lines
arch/s390/kvm/gaccess.c +5
-1@@ -631,11 +630,13 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_NR_VCPUS :case KVM_CAP_MAX_VCPUS :case KVM_CAP_MAX_VCPU_ID : - r =KVM_S390_BSCA_CPU_SLOTS ; +/* +* Return the same value for KVM_CAP_MAX_VCPUS and +* KVM_CAP_MAX_VCPU_ID to pass the kvm_create_max_vcpus selftest. +*/ + r =KVM_S390_ESCA_CPU_SLOTS ;
We're not doing this to pass the test, we're doing this to adhere to the KVM API. Yes, the API document explains it with one indirection but it is in there.
The whole KVM_CAP_MAX_VCPU_ID problem will pop up in the future since we can't change the caps name. We'll have to live with it.
Quoted 93 lines · Janosch Frank
Quoted 92 lines · Christoph Schlameuss
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_blockinkvm->arch.sca. This will always beesca_blockinstead.
By specifying the type of the sca asesca_blockwe can simplify access to the sca and get rid of some helpers while making the code clearer.
KVM_MAX_VCPUSis also moved tokvm_host_typesto allow using this in future type definitions.Signed-off-by Christoph Schlameuss <[email protected]>---
Changes in v4:
- Squash patches into single patch
- RevertKVM_CAP_MAX_VCPUSto returnKVM_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 whenkvm_s390_use_sca_entries()is false
- consistently usekvm_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 | 7 +- arch/s390/include/asm/kvm_host_types.h | 2 + arch/s390/kvm/gaccess.c | 10 +- arch/s390/kvm/interrupt.c | 71 ++++---------- arch/s390/kvm/kvm-s390.c | 167 ++++++--------------------------- arch/s390/kvm/kvm-s390.h | 9 +- 6 files changed, 58 insertions(+), 208 deletions(-)arch/s390/include/asm/kvm_host.h +2
-5@@ -27,8 +27,6 @@#include <asm/isc.h> #include <asm/guarded_storage.h> -#define KVM_MAX_VCPUS 255 -#define KVM_INTERNAL_MEM_SLOTS 1/* @@ -631,9 +629,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/include/asm/kvm_host_types.h +0
-0@@ -6,6 +6,8 @@#include <linux/atomic.h> #include <linux/types.h>
Quoted 4 lines
arch/s390/include/asm/kvm_host_types.h line 9
Quoted 1 line
arch/s390/include/asm/kvm_host_types.h +1
-0+#define KVM_MAX_VCPUS 256Why are we doing the whole 256 - 1 game?
I guess that was just me trying to force it to have the proper number there. But you are right, that is moot. I will revert that.
Quoted 5 lines
arch/s390/include/asm/kvm_host_types.h line 11
Quoted 2 lines
arch/s390/include/asm/kvm_host_types.h +1
-0+#define KVM_S390_BSCA_CPU_SLOTS 64Can't you remove that now?
Sadly no. That is still needed along with struct bsca_block to have bsca support in vsie sigp.
Quoted 37 lines
Quoted 15 lines
arch/s390/include/asm/kvm_host_types.h +0
-0#define KVM_S390_ESCA_CPU_SLOTS 248arch/s390/kvm/gaccess.c +1
-1@@ -112,7 +112,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; }[...]
Quoted 5 lines
arch/s390/kvm/gaccess.c +0
-1-static int sca_switch_to_extended (struct kvm *kvm);static void kvm_clock_sync_scb (struct kvm_s390_sie_block *scb,u64 delta) {arch/s390/kvm/gaccess.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 637
Quoted 9 lines
arch/s390/kvm/gaccess.c +5
-1@@ -631,11 +630,13 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_NR_VCPUS :case KVM_CAP_MAX_VCPUS :case KVM_CAP_MAX_VCPU_ID : - r =KVM_S390_BSCA_CPU_SLOTS ; +/* +* Return the same value for KVM_CAP_MAX_VCPUS and +* KVM_CAP_MAX_VCPU_ID to pass the kvm_create_max_vcpus selftest. +*/ + r =KVM_S390_ESCA_CPU_SLOTS ;We're not doing this to pass the test, we're doing this to adhere to the KVM API. Yes, the API document explains it with one indirection but it is in there.
Quoted 2 lines
The whole
KVM_CAP_MAX_VCPU_IDproblem will pop up in the future since we can't change the caps name. We'll have to live with it.
Let me just clarify the comment then. But hopefully that comment will be helpful to the next one trying this.