Skip to contentSkip to conversation

spapr: Handle HPT allocation failure in nested guest

PATCH Applied Fabiano Rosas 3 participants 4 messages Sep 11, 2020 – Sep 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr: Handle HPT allocation failure in nested guest

The nested KVM code does not yet support HPT guests. Calling the KVM_CAP_PPC_ALLOC_HTAB ioctl currently leads to KVM setting the guest as HPT and erroneously executing code in L1 that should only run in hypervisor mode, leading to an exception in the L1 vcpu thread when it enters the nested guest.

This can be reproduced with -machine max-cpu-compat=power8 in the L2 guest command line.

The KVM code has since been modified to fail the ioctl when running in a nested environment so QEMU needs to be able to handle that. This patch provides an error message informing the user about the lack of support for HPT in nested guests.

---
 hw/ppc/spapr.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/ppc/spapr.c +6 -0
index 9bce1892b5..ea2c755310 100644
@@ -1483,6 +1483,12 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
     spapr_free_hpt(spapr);
 
     rc = kvmppc_reset_htab(shift);
+
+    if (rc == -EOPNOTSUPP) {
+        error_setg(errp, "HPT not supported in nested guests");
+        return;
+    }
+
     if (rc < 0) {
         /* kernel-side HPT needed, but couldn't allocate one */
         error_setg_errno(errp, errno,
Signature · 1 line
2.25.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · On Fri, 11 Sep 2020 01:31:23 -0300 Fabiano Rosas <[email protected]> wrote:

The nested KVM code does not yet support HPT guests. Calling the KVM_CAP_PPC_ALLOC_HTAB ioctl currently leads to KVM setting the guest as HPT and erroneously executing code in L1 that should only run in hypervisor mode, leading to an exception in the L1 vcpu thread when it enters the nested guest.

This can be reproduced with -machine max-cpu-compat=power8 in the L2 guest command line.

The KVM code has since been modified to fail the ioctl when running in

Well, this isn't technically true for now. The KVM patch hasn't been merged yet, but I guess it's okay to merge the QEMU patch anyway since it shouldn't break older KVMs.

Quoted 14 lines

a nested environment so QEMU needs to be able to handle that. This patch provides an error message informing the user about the lack of support for HPT in nested guests.

---
 hw/ppc/spapr.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/ppc/spapr.c +0 -0
index 9bce1892b5..ea2c755310 100644

hw/ppc/spapr.c void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, · line 1487

Quoted 5 lines
hw/ppc/spapr.c +2 -0
@@ -1483,6 +1483,12 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
     spapr_free_hpt(spapr);
 
     rc = kvmppc_reset_htab(shift);
+
+    if (rc == -EOPNOTSUPP) {

As noted on the kvm-ppc list, from a POSIX standpoint it seems that ENOTSUP would be more appropriate... but since linux only knows about EOPNOTSUPP and it has an unrelated and poorly named ENOTSUPP, I guess it is okay to keep EOPNOTSUPP for the sake of consistency.

Quoted 7 lines
hw/ppc/spapr.c +4 -0
+        error_setg(errp, "HPT not supported in nested guests");
+        return;
+    }
+
     if (rc < 0) {
         /* kernel-side HPT needed, but couldn't allocate one */
         error_setg_errno(errp, errno,
#2 lore raw
In reply to Fabiano Rosas
Quoted 6 lines · Fabiano Rosas

The nested KVM code does not yet support HPT guests. Calling the KVM_CAP_PPC_ALLOC_HTAB ioctl currently leads to KVM setting the guest as HPT and erroneously executing code in L1 that should only run in hypervisor mode, leading to an exception in the L1 vcpu thread when it enters the nested guest.

Quoted 8 lines

This can be reproduced with -machine max-cpu-compat=power8 in the L2 guest command line.

The KVM code has since been modified to fail the ioctl when running in a nested environment so QEMU needs to be able to handle that. This patch provides an error message informing the user about the lack of support for HPT in nested guests.

I forgot to add a:

Quoted 22 lines
---
 hw/ppc/spapr.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/ppc/spapr.c +6 -0
index 9bce1892b5..ea2c755310 100644
@@ -1483,6 +1483,12 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
     spapr_free_hpt(spapr);
 
     rc = kvmppc_reset_htab(shift);
+
+    if (rc == -EOPNOTSUPP) {
+        error_setg(errp, "HPT not supported in nested guests");
+        return;
+    }
+
     if (rc < 0) {
         /* kernel-side HPT needed, but couldn't allocate one */
         error_setg_errno(errp, errno,
Applied
#3 lore raw
In reply to Fabiano Rosas
Quoted 9 lines · Fabiano Rosas

The nested KVM code does not yet support HPT guests. Calling the KVM_CAP_PPC_ALLOC_HTAB ioctl currently leads to KVM setting the guest as HPT and erroneously executing code in L1 that should only run in hypervisor mode, leading to an exception in the L1 vcpu thread when it enters the nested guest.

This can be reproduced with -machine max-cpu-compat=power8 in the L2 guest command line.

Quoted 6 lines

The KVM code has since been modified to fail the ioctl when running in a nested environment so QEMU needs to be able to handle that. This patch provides an error message informing the user about the lack of support for HPT in nested guests.

Applied to ppc-for-5.2.

Quoted 21 lines
---
 hw/ppc/spapr.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/ppc/spapr.c +6 -0
index 9bce1892b5..ea2c755310 100644
@@ -1483,6 +1483,12 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
     spapr_free_hpt(spapr);
 
     rc = kvmppc_reset_htab(shift);
+
+    if (rc == -EOPNOTSUPP) {
+        error_setg(errp, "HPT not supported in nested guests");
+        return;
+    }
+
     if (rc < 0) {
         /* kernel-side HPT needed, but couldn't allocate one */
         error_setg_errno(errp, errno,
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson