Skip to contentSkip to conversation

KVM: s390: vsie: Check alignment of BSCA header

PATCH In review Eric Farman 3 participants 5 messages Nov 7, 2025 – Nov 11, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: s390: vsie: Check alignment of BSCA header

The VSIE code currently checks that the BSCA struct fits within a page, and returns a validity exception 0x003b if it doesn't. The BSCA is pinned in memory rather than shadowed (see block comment at end of kvm_s390_cpu_feat_init()), so enforcing the CPU entries to be on the same pinned page makes sense.

Except those entries aren't going to be used below the guest, and according to the definition of that validity exception only the header of the BSCA (everything but the CPU entries) needs to be within a page. Adjust the alignment check to account for that.

---
 arch/s390/kvm/vsie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/vsie.c +1 -1
index 347268f89f2f..d23ab5120888 100644
@@ -782,7 +782,7 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
 			rc = set_validity_icpt(scb_s, 0x0011U);
 		else if ((gpa & PAGE_MASK) !=
-			 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK))
+			 ((gpa + offsetof(struct bsca_block, cpu[0]) - 1) & PAGE_MASK))
 			rc = set_validity_icpt(scb_s, 0x003bU);
 		if (!rc) {
 			rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
Signature · 1 line
2.48.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 07.11.25 um 03:49 schrieb Eric Farman:

Quoted 10 lines

The VSIE code currently checks that the BSCA struct fits within a page, and returns a validity exception 0x003b if it doesn't. The BSCA is pinned in memory rather than shadowed (see block comment at end of kvm_s390_cpu_feat_init()), so enforcing the CPU entries to be on the same pinned page makes sense.

Except those entries aren't going to be used below the guest, and according to the definition of that validity exception only the header of the BSCA (everything but the CPU entries) needs to be within a page. Adjust the alignment check to account for that.

Right, we do not yet support sigp interpretion for vsie and the validity is indeed defined only for bsca header alignment:
---
The SCA header crosses a 4 K-byte boundary
(VIR code 003B hex).

---

Quoted 18 lines
---
  arch/s390/kvm/vsie.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/vsie.c +1 -1
index 347268f89f2f..d23ab5120888 100644
@@ -782,7 +782,7 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  		else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
  			rc = set_validity_icpt(scb_s, 0x0011U);
  		else if ((gpa & PAGE_MASK) !=
-			 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK))
+			 ((gpa + offsetof(struct bsca_block, cpu[0]) - 1) & PAGE_MASK))
  			rc = set_validity_icpt(scb_s, 0x003bU);
  		if (!rc) {
  			rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
#2 lore raw
In reply to Eric Farman
Quoted 21 lines · Eric Farman

The VSIE code currently checks that the BSCA struct fits within a page, and returns a validity exception 0x003b if it doesn't. The BSCA is pinned in memory rather than shadowed (see block comment at end of kvm_s390_cpu_feat_init()), so enforcing the CPU entries to be on the same pinned page makes sense.

Except those entries aren't going to be used below the guest, and according to the definition of that validity exception only the header of the BSCA (everything but the CPU entries) needs to be within a page. Adjust the alignment check to account for that.

---
 arch/s390/kvm/vsie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/vsie.c +0 -0
index 347268f89f2f..d23ab5120888 100644

arch/s390/kvm/vsie.c static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 785

Quoted 5 lines
arch/s390/kvm/vsie.c +1 -1
@@ -782,7 +782,7 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
 			rc = set_validity_icpt(scb_s, 0x0011U);
 		else if ((gpa & PAGE_MASK) !=
-			 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK))
+			 ((gpa + offsetof(struct bsca_block, cpu[0]) - 1) & PAGE_MASK))

Did you test if this works with an esca, where the header is bigger than this? Previously the esca header was covered by the whole bsca struct.

Quoted 3 lines
arch/s390/kvm/vsie.c +0 -0
 			rc = set_validity_icpt(scb_s, 0x003bU);
 		if (!rc) {
 			rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
#3 lore raw
Quoted 17 lines · Christoph Schlameuss
Quoted 16 lines · Eric Farman

The VSIE code currently checks that the BSCA struct fits within a page, and returns a validity exception 0x003b if it doesn't. The BSCA is pinned in memory rather than shadowed (see block comment at end of kvm_s390_cpu_feat_init()), so enforcing the CPU entries to be on the same pinned page makes sense.

Except those entries aren't going to be used below the guest, and according to the definition of that validity exception only the header of the BSCA (everything but the CPU entries) needs to be within a page. Adjust the alignment check to account for that.

---
 arch/s390/kvm/vsie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

arch/s390/kvm/vsie.c static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 785

Quoted 10 lines
arch/s390/kvm/vsie.c +1 -1
index 347268f89f2f..d23ab5120888 100644
@@ -782,7 +782,7 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
 			rc = set_validity_icpt(scb_s, 0x0011U);
 		else if ((gpa & PAGE_MASK) !=
-			 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK))
+			 ((gpa + offsetof(struct bsca_block, cpu[0]) - 1) & PAGE_MASK))

Did you test if this works with an esca, where the header is bigger than this? Previously the esca header was covered by the whole bsca struct.

I had originally coded up an offset like you did in your vsie sigpif series [*] for just this point, but since we don't surface KVM_S390_VM_CPU_FEAT_SIGPIF to the guest (that comes later in your series), I was having to force my way into driving that path and for minimal benefit. Now that I'm remembering your RFC, having a conditional length is certainly correct but this is a good first step.

[*] https://lore.kernel.org/linux-s390/[email protected]/

Quoted 4 lines
Quoted 4 lines
arch/s390/kvm/vsie.c +0 -0
 			rc = set_validity_icpt(scb_s, 0x003bU);
 		if (!rc) {
 			rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
#4 lore raw
Quoted 32 lines · Eric Farman
Quoted 17 lines · Christoph Schlameuss
Quoted 16 lines · Eric Farman

The VSIE code currently checks that the BSCA struct fits within a page, and returns a validity exception 0x003b if it doesn't. The BSCA is pinned in memory rather than shadowed (see block comment at end of kvm_s390_cpu_feat_init()), so enforcing the CPU entries to be on the same pinned page makes sense.

Except those entries aren't going to be used below the guest, and according to the definition of that validity exception only the header of the BSCA (everything but the CPU entries) needs to be within a page. Adjust the alignment check to account for that.

---
 arch/s390/kvm/vsie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

arch/s390/kvm/vsie.c static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 785

Quoted 10 lines
arch/s390/kvm/vsie.c +1 -1
index 347268f89f2f..d23ab5120888 100644
@@ -782,7 +782,7 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
 			rc = set_validity_icpt(scb_s, 0x0011U);
 		else if ((gpa & PAGE_MASK) !=
-			 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK))
+			 ((gpa + offsetof(struct bsca_block, cpu[0]) - 1) & PAGE_MASK))

Did you test if this works with an esca, where the header is bigger than this? Previously the esca header was covered by the whole bsca struct.

Quoted 8 lines

I had originally coded up an offset like you did in your vsie sigpif series [*] for just this point, but since we don't surface KVM_S390_VM_CPU_FEAT_SIGPIF to the guest (that comes later in your series), I was having to force my way into driving that path and for minimal benefit. Now that I'm remembering your RFC, having a conditional length is certainly correct but this is a good first step.

[*] https://lore.kernel.org/linux-s390/[email protected]/

I agree that this is a good step in that direction. I am only concerned if we may still get a validity intercept from fw when entering SIE while the ESCA header is crossing the page boundary. The chances of that happening are slim as at least Linux does always place the ESCA on the beginning of the page, but other guests might not.
But then again getting the validity intercept from fw is not that much worse than getting it from us directly.

So either way:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
arch/s390/kvm/vsie.c +0 -0
 			rc = set_validity_icpt(scb_s, 0x003bU);
 		if (!rc) {
 			rc = pin_guest_page(vcpu->kvm, gpa, &hpa);