All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spapr: Handle HPT allocation failure in nested guest
@ 2020-09-11  4:31 Fabiano Rosas
  2020-09-11  8:25 ` Greg Kurz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Fabiano Rosas @ 2020-09-11  4:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc, david

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.

Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
---
 hw/ppc/spapr.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 9bce1892b5..ea2c755310 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -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,
-- 
2.25.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] spapr: Handle HPT allocation failure in nested guest
  2020-09-11  4:31 [PATCH] spapr: Handle HPT allocation failure in nested guest Fabiano Rosas
@ 2020-09-11  8:25 ` Greg Kurz
  2020-09-11 14:38 ` Fabiano Rosas
  2020-09-14  6:21 ` David Gibson
  2 siblings, 0 replies; 4+ messages in thread
From: Greg Kurz @ 2020-09-11  8:25 UTC (permalink / raw)
  To: Fabiano Rosas; +Cc: qemu-ppc, qemu-devel, david

On Fri, 11 Sep 2020 01:31:23 -0300
Fabiano Rosas <farosas@linux.ibm.com> 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.

> 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.
> 
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
> ---
>  hw/ppc/spapr.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 9bce1892b5..ea2c755310 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -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.

Reviewed-by: Greg Kurz <groug@kaod.org>

> +        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,



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spapr: Handle HPT allocation failure in nested guest
  2020-09-11  4:31 [PATCH] spapr: Handle HPT allocation failure in nested guest Fabiano Rosas
  2020-09-11  8:25 ` Greg Kurz
@ 2020-09-11 14:38 ` Fabiano Rosas
  2020-09-14  6:21 ` David Gibson
  2 siblings, 0 replies; 4+ messages in thread
From: Fabiano Rosas @ 2020-09-11 14:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc, david

Fabiano Rosas <farosas@linux.ibm.com> writes:

> 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.
>

I forgot to add a:

Reported-by: Satheesh Rajendran <sathnaga@linux.vnet.ibm.com>

> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
> ---
>  hw/ppc/spapr.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 9bce1892b5..ea2c755310 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -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,


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spapr: Handle HPT allocation failure in nested guest
  2020-09-11  4:31 [PATCH] spapr: Handle HPT allocation failure in nested guest Fabiano Rosas
  2020-09-11  8:25 ` Greg Kurz
  2020-09-11 14:38 ` Fabiano Rosas
@ 2020-09-14  6:21 ` David Gibson
  2 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2020-09-14  6:21 UTC (permalink / raw)
  To: Fabiano Rosas; +Cc: qemu-ppc, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1668 bytes --]

On Fri, Sep 11, 2020 at 01:31:23AM -0300, Fabiano Rosas 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
> 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.
> 
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>

Applied to ppc-for-5.2.

> ---
>  hw/ppc/spapr.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 9bce1892b5..ea2c755310 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -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,

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-14  6:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11  4:31 [PATCH] spapr: Handle HPT allocation failure in nested guest Fabiano Rosas
2020-09-11  8:25 ` Greg Kurz
2020-09-11 14:38 ` Fabiano Rosas
2020-09-14  6:21 ` David Gibson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.