Skip to contentSkip to conversation

KVM: s390: fix guarded storage control register handling

PATCH Applied Heiko Carstens 5 participants 5 messages Apr 15, 2021

Subsystems (3)
lore
Share & tools
lore

Heiko Carstens

author maintainer
#0 lore raw

PATCH 1/1 KVM: s390: fix guarded storage control register handling

store_regs_fmt2() has an ordering problem: first the guarded storage facility is enabled on the local cpu, then preemption disabled, and then the STGSC (store guarded storage controls) instruction is executed.

If the process gets scheduled away between enabling the guarded storage facility and before preemption is disabled, this might lead to a special operation exception and therefore kernel crash as soon as the process is scheduled back and the STGSC instruction is executed.

Fixes 4e0b1ab72b8a ("KVM: s390: gs support for kvm guests")
Cc <[email protected]> # 4.12
---
 arch/s390/kvm/kvm-s390.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +2 -2
index 2f09e9d7dc95..24ad447e648c 100644
@@ -4307,16 +4307,16 @@ static void store_regs_fmt2(struct kvm_vcpu *vcpu)
 	kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC;
 	kvm_run->s.regs.diag318 = vcpu->arch.diag318_info.val;
 	if (MACHINE_HAS_GS) {
+		preempt_disable();
 		__ctl_set_bit(2, 4);
 		if (vcpu->arch.gs_enabled)
 			save_gs_cb(current->thread.gs_cb);
-		preempt_disable();
 		current->thread.gs_cb = vcpu->arch.host_gscb;
 		restore_gs_cb(vcpu->arch.host_gscb);
-		preempt_enable();
 		if (!vcpu->arch.host_gscb)
 			__ctl_clear_bit(2, 4);
 		vcpu->arch.host_gscb = NULL;
+		preempt_enable();
 	}
 	/* SIE will save etoken directly into SDNX and therefore kvm_run */
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Heiko Carstens

store_regs_fmt2() has an ordering problem: first the guarded storage facility is enabled on the local cpu, then preemption disabled, and then the STGSC (store guarded storage controls) instruction is executed.

If the process gets scheduled away between enabling the guarded storage facility and before preemption is disabled, this might lead to a special operation exception and therefore kernel crash as soon as the process is scheduled back and the STGSC instruction is executed.

Fixes 4e0b1ab72b8a ("KVM: s390: gs support for kvm guests")
Cc <[email protected]> # 4.12
---
  arch/s390/kvm/kvm-s390.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 2f09e9d7dc95..24ad447e648c 100644
@@ -4307,16 +4307,16 @@ static void store_regs_fmt2(struct kvm_vcpu *vcpu)
  	kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC;
  	kvm_run->s.regs.diag318 = vcpu->arch.diag318_info.val;
  	if (MACHINE_HAS_GS) {
+		preempt_disable();
  		__ctl_set_bit(2, 4);
  		if (vcpu->arch.gs_enabled)
  			save_gs_cb(current->thread.gs_cb);
-		preempt_disable();

arch/s390/kvm/kvm-s390.c static void store_regs_fmt2(struct kvm_vcpu *vcpu) · line 4322

Quoted 10 lines
arch/s390/kvm/kvm-s390.c +1 -1
  		current->thread.gs_cb = vcpu->arch.host_gscb;
  		restore_gs_cb(vcpu->arch.host_gscb);
-		preempt_enable();
  		if (!vcpu->arch.host_gscb)
  			__ctl_clear_bit(2, 4);
  		vcpu->arch.host_gscb = NULL;
+		preempt_enable();
  	}
  	/* SIE will save etoken directly into SDNX and therefore kvm_run */
  }

LGTM

Signature · 3 lines
Thanks,

David / dhildenb
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Heiko Carstens
Quoted 10 lines · Heiko Carstens

store_regs_fmt2() has an ordering problem: first the guarded storage facility is enabled on the local cpu, then preemption disabled, and then the STGSC (store guarded storage controls) instruction is executed.

If the process gets scheduled away between enabling the guarded storage facility and before preemption is disabled, this might lead to a special operation exception and therefore kernel crash as soon as the process is scheduled back and the STGSC instruction is executed.

Quoted 4 lines
Fixes 4e0b1ab72b8a ("KVM: s390: gs support for kvm guests")
Cc <[email protected]> # 4.12
Quoted 28 lines
---
 arch/s390/kvm/kvm-s390.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +2 -2
index 2f09e9d7dc95..24ad447e648c 100644
@@ -4307,16 +4307,16 @@ static void store_regs_fmt2(struct kvm_vcpu *vcpu)
 	kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC;
 	kvm_run->s.regs.diag318 = vcpu->arch.diag318_info.val;
 	if (MACHINE_HAS_GS) {
+		preempt_disable();
 		__ctl_set_bit(2, 4);
 		if (vcpu->arch.gs_enabled)
 			save_gs_cb(current->thread.gs_cb);
-		preempt_disable();
 		current->thread.gs_cb = vcpu->arch.host_gscb;
 		restore_gs_cb(vcpu->arch.host_gscb);
-		preempt_enable();
 		if (!vcpu->arch.host_gscb)
 			__ctl_clear_bit(2, 4);
 		vcpu->arch.host_gscb = NULL;
+		preempt_enable();
 	}
 	/* SIE will save etoken directly into SDNX and therefore kvm_run */
 }
Reviewed-by on v1 1/1
#3 lore raw
In reply to Heiko Carstens
Quoted 10 lines · On Thu, 15 Apr 2021 10:01:27 +0200 Heiko Carstens <[email protected]> wrote:

store_regs_fmt2() has an ordering problem: first the guarded storage facility is enabled on the local cpu, then preemption disabled, and then the STGSC (store guarded storage controls) instruction is executed.

If the process gets scheduled away between enabling the guarded storage facility and before preemption is disabled, this might lead to a special operation exception and therefore kernel crash as soon as the process is scheduled back and the STGSC instruction is executed.

Quoted 7 lines
Fixes 4e0b1ab72b8a ("KVM: s390: gs support for kvm guests")
Cc <[email protected]> # 4.12
---
 arch/s390/kvm/kvm-s390.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#4 lore raw
In reply to Heiko Carstens
Quoted 10 lines · Heiko Carstens

store_regs_fmt2() has an ordering problem: first the guarded storage facility is enabled on the local cpu, then preemption disabled, and then the STGSC (store guarded storage controls) instruction is executed.

If the process gets scheduled away between enabling the guarded storage facility and before preemption is disabled, this might lead to a special operation exception and therefore kernel crash as soon as the process is scheduled back and the STGSC instruction is executed.

Quoted 4 lines
Fixes 4e0b1ab72b8a ("KVM: s390: gs support for kvm guests")
Cc <[email protected]> # 4.12

Thanks applied. Will queue for the s390kvm tree after the CI/regression has finished.

Quoted 28 lines
---
  arch/s390/kvm/kvm-s390.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +2 -2
index 2f09e9d7dc95..24ad447e648c 100644
@@ -4307,16 +4307,16 @@ static void store_regs_fmt2(struct kvm_vcpu *vcpu)
  	kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC;
  	kvm_run->s.regs.diag318 = vcpu->arch.diag318_info.val;
  	if (MACHINE_HAS_GS) {
+		preempt_disable();
  		__ctl_set_bit(2, 4);
  		if (vcpu->arch.gs_enabled)
  			save_gs_cb(current->thread.gs_cb);
-		preempt_disable();
  		current->thread.gs_cb = vcpu->arch.host_gscb;
  		restore_gs_cb(vcpu->arch.host_gscb);
-		preempt_enable();
  		if (!vcpu->arch.host_gscb)
  			__ctl_clear_bit(2, 4);
  		vcpu->arch.host_gscb = NULL;
+		preempt_enable();
  	}
  	/* SIE will save etoken directly into SDNX and therefore kvm_run */
  }