Skip to contentSkip to conversation

KVM: PPC: Book3S HV: relax check on H_SVM_INIT_ABORT

PATCH Superseded Laurent Dufour 4 participants 8 messages May 20, 2020 – May 27, 2020

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

PATCH 1/1 KVM: PPC: Book3S HV: relax check on H_SVM_INIT_ABORT

The commit 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls") added checks of secure bit of SRR1 to filter out the Hcall reserved to the Ultravisor.

However, the Hcall H_SVM_INIT_ABORT is made by the Ultravisor passing the context of the VM calling UV_ESM. This allows the Hypervisor to return to the guest without going through the Ultravisor. Thus the Secure bit of SRR1 is not set in that particular case.

In the case a regular VM is calling H_SVM_INIT_ABORT, this hcall will be filtered out in kvmppc_h_svm_init_abort() because kvm->arch.secure_guest is not set in that case.

Fixes 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls")
---
 arch/powerpc/kvm/book3s_hv.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv.c +1 -3
index 93493f0cbfe8..eb1f96cb7b72 100644
@@ -1099,9 +1099,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
 			ret = kvmppc_h_svm_init_done(vcpu->kvm);
 		break;
 	case H_SVM_INIT_ABORT:
-		ret = H_UNSUPPORTED;
-		if (kvmppc_get_srr1(vcpu) & MSR_S)
-			ret = kvmppc_h_svm_init_abort(vcpu->kvm);
+		ret = kvmppc_h_svm_init_abort(vcpu->kvm);
 		break;
 
 	default:
Signature · 1 line
2.26.2
#1 lore raw
Quoted 4 lines · On Wed, 20 May 2020 18:51:10 +0200 Laurent Dufour <[email protected]> wrote:

The commit 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls") added checks of secure bit of SRR1 to filter out the Hcall reserved to the Ultravisor.

Quoted 9 lines

However, the Hcall H_SVM_INIT_ABORT is made by the Ultravisor passing the context of the VM calling UV_ESM. This allows the Hypervisor to return to the guest without going through the Ultravisor. Thus the Secure bit of SRR1 is not set in that particular case.

In the case a regular VM is calling H_SVM_INIT_ABORT, this hcall will be filtered out in kvmppc_h_svm_init_abort() because kvm->arch.secure_guest is not set in that case.

Why not checking vcpu->kvm->arch.secure_guest then ?

Quoted 11 lines
Fixes 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls")
---
 arch/powerpc/kvm/book3s_hv.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv.c +0 -0
index 93493f0cbfe8..eb1f96cb7b72 100644

arch/powerpc/kvm/book3s_hv.c int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) · line 1104

Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c +0 -3
@@ -1099,9 +1099,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
 			ret = kvmppc_h_svm_init_done(vcpu->kvm);
 		break;
 	case H_SVM_INIT_ABORT:
-		ret = H_UNSUPPORTED;
-		if (kvmppc_get_srr1(vcpu) & MSR_S)
-			ret = kvmppc_h_svm_init_abort(vcpu->kvm);

or at least put a comment to explain why H_SVM_INIT_ABORT doesn't have the same sanity check as the other SVM hcalls.

Quoted 4 lines
arch/powerpc/kvm/book3s_hv.c +1 -0
+		ret = kvmppc_h_svm_init_abort(vcpu->kvm);
 		break;
 
 	default:
#2 lore raw

Le 20/05/2020 à 19:32, Greg Kurz a écrit :

Quoted 12 lines
Quoted 9 lines · On Wed, 20 May 2020 18:51:10 +0200 Laurent Dufour <[email protected]> wrote:

The commit 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls") added checks of secure bit of SRR1 to filter out the Hcall reserved to the Ultravisor.

However, the Hcall H_SVM_INIT_ABORT is made by the Ultravisor passing the context of the VM calling UV_ESM. This allows the Hypervisor to return to the guest without going through the Ultravisor. Thus the Secure bit of SRR1 is not set in that particular case.

Quoted 6 lines
Quoted 4 lines

In the case a regular VM is calling H_SVM_INIT_ABORT, this hcall will be filtered out in kvmppc_h_svm_init_abort() because kvm->arch.secure_guest is not set in that case.

Why not checking vcpu->kvm->arch.secure_guest then ?

I don't think that's the right place.

Quoted 7 lines
Quoted 7 lines
Fixes 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls")
---
  arch/powerpc/kvm/book3s_hv.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 14 lines

arch/powerpc/kvm/book3s_hv.c int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) · line 1104

Quoted 11 lines
arch/powerpc/kvm/book3s_hv.c +0 -3
index 93493f0cbfe8..eb1f96cb7b72 100644
@@ -1099,9 +1099,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
  			ret = kvmppc_h_svm_init_done(vcpu->kvm);
  		break;
  	case H_SVM_INIT_ABORT:
-		ret = H_UNSUPPORTED;
-		if (kvmppc_get_srr1(vcpu) & MSR_S)
-			ret = kvmppc_h_svm_init_abort(vcpu->kvm);

or at least put a comment to explain why H_SVM_INIT_ABORT doesn't have the same sanity check as the other SVM hcalls.

I agree that might help. I'll send a v2 with a comment there.

Quoted 6 lines
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +1 -0
+		ret = kvmppc_h_svm_init_abort(vcpu->kvm);
  		break;
 
  	default:
#3 lore raw

PATCH v2 1/1 KVM: PPC: Book3S HV: relax check on H_SVM_INIT_ABORT

In reply to Greg Kurz

The commit 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls") added checks of secure bit of SRR1 to filter out the Hcall reserved to the Ultravisor.

However, the Hcall H_SVM_INIT_ABORT is made by the Ultravisor passing the context of the VM calling UV_ESM. This allows the Hypervisor to return to the guest without going through the Ultravisor. Thus the Secure bit of SRR1 is not set in that particular case.

In the case a regular VM is calling H_SVM_INIT_ABORT, this hcall will be filtered out in kvmppc_h_svm_init_abort() because kvm->arch.secure_guest is not set in that case.

Fixes 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls")
---
 arch/powerpc/kvm/book3s_hv.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv.c +6 -3
index 93493f0cbfe8..6ad1a3b14300 100644
@@ -1099,9 +1099,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
 			ret = kvmppc_h_svm_init_done(vcpu->kvm);
 		break;
 	case H_SVM_INIT_ABORT:
-		ret = H_UNSUPPORTED;
-		if (kvmppc_get_srr1(vcpu) & MSR_S)
-			ret = kvmppc_h_svm_init_abort(vcpu->kvm);
+		/*
+		 * Even if that call is made by the Ultravisor, the SSR1 value
+		 * is the guest context one, with the secure bit clear as it has
+		 * not yet been secured. So we can't check it here.
+		 */
+		ret = kvmppc_h_svm_init_abort(vcpu->kvm);
 		break;
 
 	default:
Signature · 1 line
2.26.2
Reviewed-by on v2 1/1
#4 lore raw
Quoted 9 lines · On Wed, 20 May 2020 19:43:08 +0200 Laurent Dufour <[email protected]> wrote:

The commit 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls") added checks of secure bit of SRR1 to filter out the Hcall reserved to the Ultravisor.

However, the Hcall H_SVM_INIT_ABORT is made by the Ultravisor passing the context of the VM calling UV_ESM. This allows the Hypervisor to return to the guest without going through the Ultravisor. Thus the Secure bit of SRR1 is not set in that particular case.

Quoted 7 lines

In the case a regular VM is calling H_SVM_INIT_ABORT, this hcall will be filtered out in kvmppc_h_svm_init_abort() because kvm->arch.secure_guest is not set in that case.

Fixes 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls")

---

Quoted 23 lines
 arch/powerpc/kvm/book3s_hv.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv.c +6 -3
index 93493f0cbfe8..6ad1a3b14300 100644
@@ -1099,9 +1099,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
 			ret = kvmppc_h_svm_init_done(vcpu->kvm);
 		break;
 	case H_SVM_INIT_ABORT:
-		ret = H_UNSUPPORTED;
-		if (kvmppc_get_srr1(vcpu) & MSR_S)
-			ret = kvmppc_h_svm_init_abort(vcpu->kvm);
+		/*
+		 * Even if that call is made by the Ultravisor, the SSR1 value
+		 * is the guest context one, with the secure bit clear as it has
+		 * not yet been secured. So we can't check it here.
+		 */
+		ret = kvmppc_h_svm_init_abort(vcpu->kvm);
 		break;
 
 	default:
Reviewed-by on v2 1/1
#5 lore raw
In reply to Laurent Dufour
Quoted 9 lines · Laurent Dufour

The commit 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls") added checks of secure bit of SRR1 to filter out the Hcall reserved to the Ultravisor.

However, the Hcall H_SVM_INIT_ABORT is made by the Ultravisor passing the context of the VM calling UV_ESM. This allows the Hypervisor to return to the guest without going through the Ultravisor. Thus the Secure bit of SRR1 is not set in that particular case.

Quoted 6 lines

In the case a regular VM is calling H_SVM_INIT_ABORT, this hcall will be filtered out in kvmppc_h_svm_init_abort() because kvm->arch.secure_guest is not set in that case.

Fixes 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls")
Quoted 10 lines
---
 arch/powerpc/kvm/book3s_hv.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv.c +0 -0
index 93493f0cbfe8..6ad1a3b14300 100644
@@ -1099,9 +1099,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
 			ret = kvmppc_h_svm_init_done(vcpu->kvm);

arch/powerpc/kvm/book3s_hv.c int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) · line 1106

Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +5 -3
 		break;
 	case H_SVM_INIT_ABORT:
-		ret = H_UNSUPPORTED;
-		if (kvmppc_get_srr1(vcpu) & MSR_S)
-			ret = kvmppc_h_svm_init_abort(vcpu->kvm);
+		/*
+		 * Even if that call is made by the Ultravisor, the SSR1 value
+		 * is the guest context one, with the secure bit clear as it has
+		 * not yet been secured. So we can't check it here.
+		 */

Frankly speaking, the comment above when read in isolation; i.e without the delete code above, feels out of place. The reasoning for change is anyway captured in the changelog. So, I think, we should delete this comment.

Also the comment above assumes the Ultravisor will call H_SVM_INIT_ABORT with SRR1(S) bit not set; which may or may not be true. Regardless of who and how H_SVM_INIT_ABORT is called, we should just call kvmppc_h_svm_init_abort() and let it deal with the complexities.

RP

#6 lore raw
In reply to Laurent Dufour
Quoted 9 lines · Laurent Dufour

The commit 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls") added checks of secure bit of SRR1 to filter out the Hcall reserved to the Ultravisor.

However, the Hcall H_SVM_INIT_ABORT is made by the Ultravisor passing the context of the VM calling UV_ESM. This allows the Hypervisor to return to the guest without going through the Ultravisor. Thus the Secure bit of SRR1 is not set in that particular case.

Quoted 6 lines

In the case a regular VM is calling H_SVM_INIT_ABORT, this hcall will be filtered out in kvmppc_h_svm_init_abort() because kvm->arch.secure_guest is not set in that case.

Fixes 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls")

Thanks, applied to my kvm-ppc-next branch. I expanded the comment in the code a little.

Paul.

#7 lore raw

Le 27/05/2020 à 06:16, Paul Mackerras a écrit :

Quoted 14 lines · Laurent Dufour
Quoted 13 lines

The commit 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls") added checks of secure bit of SRR1 to filter out the Hcall reserved to the Ultravisor.

However, the Hcall H_SVM_INIT_ABORT is made by the Ultravisor passing the context of the VM calling UV_ESM. This allows the Hypervisor to return to the guest without going through the Ultravisor. Thus the Secure bit of SRR1 is not set in that particular case.

In the case a regular VM is calling H_SVM_INIT_ABORT, this hcall will be filtered out in kvmppc_h_svm_init_abort() because kvm->arch.secure_guest is not set in that case.

Quoted 5 lines
Quoted 2 lines
Fixes 8c47b6ff29e3 ("KVM: PPC: Book3S HV: Check caller of H_SVM_* Hcalls")

Thanks, applied to my kvm-ppc-next branch. I expanded the comment in the code a little.

Thanks, the comment is more explicit now.

Laurent.