diff mbox series

[v2] spapr: nested: Add support for DPDES SPR in GSB for TCG L0

Message ID 20241018163849.2080847-1-amachhiw@linux.ibm.com (mailing list archive)
State New
Headers show
Series [v2] spapr: nested: Add support for DPDES SPR in GSB for TCG L0 | expand

Commit Message

Amit Machhiwal Oct. 18, 2024, 4:38 p.m. UTC
The DPDES support for doorbell emulation and handling for KVM on PAPR
guests was added in Linux via [1]. Subsequently, a new GSB (Guest State
Buffer) element for DPDES was added in Linux; the same has been missing
in TCG L0 implementation. Add support for DPDES register's APIv2 GSB
element and required handling in `spapr_nested.c`.

Currently, booting a KVM guest inside a QEMU TCG guest fails with the
following crash. The crash occurs while handling the GUEST_RUN_VCPU
hcall made in TCG L0. In the hcall handling path, map_and_getset_state()
calls getset_state(), which, in turn, calls guest_state_request_check()
to validate the GSR (Guest State Request) elements. During this process,
guest_state_request_check() iterates over the GSR elements and receives
a NULL return code from guest_state_element_type_find() for the type
variable corresponding to the DPDES register's elemetn ID (which was
unknown to TCG L0). Subsequently, getset_state() returns H_P3,
ultimately leading to the hcall failure and causing the KVM guest to
crash.

 KVM: unknown exit, hardware reason ffffffffffffffea
 NIP 0000000000000100   LR 0000000000000000 CTR 0000000000000000 XER 0000000000000000 CPU#0
 MSR 0000000000003000 HID0 0000000000000000  HF 6c002000 iidx 3 didx 3
 TB 00000000 00000000 DECR 0
 GPR00 0000000000000000 0000000000000000 0000000000000000 000000007fe00000
 GPR04 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 GPR08 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 GPR12 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 GPR16 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 GPR20 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 GPR24 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 GPR28 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 CR 00000000  [ -  -  -  -  -  -  -  -  ]     RES 000@ffffffffffffffff
  SRR0 0000000000000000  SRR1 0000000000000000    PVR 0000000000801200 VRSAVE 0000000000000000
 SPRG0 0000000000000000 SPRG1 0000000000000000  SPRG2 0000000000000000  SPRG3 0000000000000000
 SPRG4 0000000000000000 SPRG5 0000000000000000  SPRG6 0000000000000000  SPRG7 0000000000000000
 HSRR0 0000000000000000 HSRR1 0000000000000000
  CFAR 0000000000000000
  LPCR 0000000000560413
  PTCR 0000000000000000   DAR 0000000000000000  DSISR 0000000000000000

Fix this by adding the required support in TCG L0 implementation of
APIv2.

[1] https://lore.kernel.org/all/20240605113913.83715-1-gautam@linux.ibm.com/

Fixes: 4a575f9a0567 ("spapr: nested: Initialize the GSB elements lookup table.")
Suggested-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
---
Changes since v1:
    - Addressed Harsh's comments on v1
    - Updated the patch description to more precise details of the issue 
    - v1: https://lore.kernel.org/all/20241017110033.3929988-1-amachhiw@linux.ibm.com/

 hw/ppc/spapr_nested.c         | 1 +
 include/hw/ppc/spapr_nested.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)


base-commit: aa54f5be44be786636a5d51cc1612ad208a24849

Comments

Harsh Prateek Bora Oct. 21, 2024, 7:03 a.m. UTC | #1
On 10/18/24 22:08, Amit Machhiwal wrote:
> The DPDES support for doorbell emulation and handling for KVM on PAPR
> guests was added in Linux via [1]. Subsequently, a new GSB (Guest State
> Buffer) element for DPDES was added in Linux; the same has been missing
> in TCG L0 implementation. Add support for DPDES register's APIv2 GSB
> element and required handling in `spapr_nested.c`.
> 
> Currently, booting a KVM guest inside a QEMU TCG guest fails with the
> following crash. The crash occurs while handling the GUEST_RUN_VCPU
> hcall made in TCG L0. In the hcall handling path, map_and_getset_state()
> calls getset_state(), which, in turn, calls guest_state_request_check()
> to validate the GSR (Guest State Request) elements. During this process,
> guest_state_request_check() iterates over the GSR elements and receives
> a NULL return code from guest_state_element_type_find() for the type
> variable corresponding to the DPDES register's elemetn ID (which was
> unknown to TCG L0). Subsequently, getset_state() returns H_P3,
> ultimately leading to the hcall failure and causing the KVM guest to
> crash.
> 
>   KVM: unknown exit, hardware reason ffffffffffffffea
>   NIP 0000000000000100   LR 0000000000000000 CTR 0000000000000000 XER 0000000000000000 CPU#0
>   MSR 0000000000003000 HID0 0000000000000000  HF 6c002000 iidx 3 didx 3
>   TB 00000000 00000000 DECR 0
>   GPR00 0000000000000000 0000000000000000 0000000000000000 000000007fe00000
>   GPR04 0000000000000000 0000000000000000 0000000000000000 0000000000000000
>   GPR08 0000000000000000 0000000000000000 0000000000000000 0000000000000000
>   GPR12 0000000000000000 0000000000000000 0000000000000000 0000000000000000
>   GPR16 0000000000000000 0000000000000000 0000000000000000 0000000000000000
>   GPR20 0000000000000000 0000000000000000 0000000000000000 0000000000000000
>   GPR24 0000000000000000 0000000000000000 0000000000000000 0000000000000000
>   GPR28 0000000000000000 0000000000000000 0000000000000000 0000000000000000
>   CR 00000000  [ -  -  -  -  -  -  -  -  ]     RES 000@ffffffffffffffff
>    SRR0 0000000000000000  SRR1 0000000000000000    PVR 0000000000801200 VRSAVE 0000000000000000
>   SPRG0 0000000000000000 SPRG1 0000000000000000  SPRG2 0000000000000000  SPRG3 0000000000000000
>   SPRG4 0000000000000000 SPRG5 0000000000000000  SPRG6 0000000000000000  SPRG7 0000000000000000
>   HSRR0 0000000000000000 HSRR1 0000000000000000
>    CFAR 0000000000000000
>    LPCR 0000000000560413
>    PTCR 0000000000000000   DAR 0000000000000000  DSISR 0000000000000000
> 
> Fix this by adding the required support in TCG L0 implementation of
> APIv2.
> 
> [1] https://lore.kernel.org/all/20240605113913.83715-1-gautam@linux.ibm.com/
> 
> Fixes: 4a575f9a0567 ("spapr: nested: Initialize the GSB elements lookup table.")
> Suggested-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>

Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>

> ---
> Changes since v1:
>      - Addressed Harsh's comments on v1
>      - Updated the patch description to more precise details of the issue
>      - v1: https://lore.kernel.org/all/20241017110033.3929988-1-amachhiw@linux.ibm.com/
> 
>   hw/ppc/spapr_nested.c         | 1 +
>   include/hw/ppc/spapr_nested.h | 3 ++-
>   2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
> index c02785756c1e..1b41c8fb8b67 100644
> --- a/hw/ppc/spapr_nested.c
> +++ b/hw/ppc/spapr_nested.c
> @@ -982,6 +982,7 @@ struct guest_state_element_type guest_state_element_types[] = {
>       GUEST_STATE_ELEMENT_ENV_DW(GSB_VCPU_SPR_FSCR,  fscr),
>       GUEST_STATE_ELEMENT_ENV_W(GSB_VCPU_SPR_PSPB,   pspb),
>       GUEST_STATE_ELEMENT_ENV_DW(GSB_VCPU_SPR_CTRL,  ctrl),
> +    GUEST_STATE_ELEMENT_ENV_DW(GSB_VCPU_SPR_DPDES, dpdes),
>       GUEST_STATE_ELEMENT_ENV_W(GSB_VCPU_SPR_VRSAVE, vrsave),
>       GUEST_STATE_ELEMENT_ENV_DW(GSB_VCPU_SPR_DAR,   dar),
>       GUEST_STATE_ELEMENT_ENV_W(GSB_VCPU_SPR_DSISR,  dsisr),
> diff --git a/include/hw/ppc/spapr_nested.h b/include/hw/ppc/spapr_nested.h
> index 93ef14adcc5e..3b5cd993c256 100644
> --- a/include/hw/ppc/spapr_nested.h
> +++ b/include/hw/ppc/spapr_nested.h
> @@ -99,7 +99,8 @@
>   #define GSB_VCPU_SPR_HASHKEYR   0x1050
>   #define GSB_VCPU_SPR_HASHPKEYR  0x1051
>   #define GSB_VCPU_SPR_CTRL       0x1052
> -                    /* RESERVED 0x1053 - 0x1FFF */
> +#define GSB_VCPU_SPR_DPDES      0x1053
> +                    /* RESERVED 0x1054 - 0x1FFF */
>   #define GSB_VCPU_SPR_CR         0x2000
>   #define GSB_VCPU_SPR_PIDR       0x2001
>   #define GSB_VCPU_SPR_DSISR      0x2002
> 
> base-commit: aa54f5be44be786636a5d51cc1612ad208a24849
diff mbox series

Patch

diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index c02785756c1e..1b41c8fb8b67 100644
--- a/hw/ppc/spapr_nested.c
+++ b/hw/ppc/spapr_nested.c
@@ -982,6 +982,7 @@  struct guest_state_element_type guest_state_element_types[] = {
     GUEST_STATE_ELEMENT_ENV_DW(GSB_VCPU_SPR_FSCR,  fscr),
     GUEST_STATE_ELEMENT_ENV_W(GSB_VCPU_SPR_PSPB,   pspb),
     GUEST_STATE_ELEMENT_ENV_DW(GSB_VCPU_SPR_CTRL,  ctrl),
+    GUEST_STATE_ELEMENT_ENV_DW(GSB_VCPU_SPR_DPDES, dpdes),
     GUEST_STATE_ELEMENT_ENV_W(GSB_VCPU_SPR_VRSAVE, vrsave),
     GUEST_STATE_ELEMENT_ENV_DW(GSB_VCPU_SPR_DAR,   dar),
     GUEST_STATE_ELEMENT_ENV_W(GSB_VCPU_SPR_DSISR,  dsisr),
diff --git a/include/hw/ppc/spapr_nested.h b/include/hw/ppc/spapr_nested.h
index 93ef14adcc5e..3b5cd993c256 100644
--- a/include/hw/ppc/spapr_nested.h
+++ b/include/hw/ppc/spapr_nested.h
@@ -99,7 +99,8 @@ 
 #define GSB_VCPU_SPR_HASHKEYR   0x1050
 #define GSB_VCPU_SPR_HASHPKEYR  0x1051
 #define GSB_VCPU_SPR_CTRL       0x1052
-                    /* RESERVED 0x1053 - 0x1FFF */
+#define GSB_VCPU_SPR_DPDES      0x1053
+                    /* RESERVED 0x1054 - 0x1FFF */
 #define GSB_VCPU_SPR_CR         0x2000
 #define GSB_VCPU_SPR_PIDR       0x2001
 #define GSB_VCPU_SPR_DSISR      0x2002