target-ppc/spapr: Add FWNMI support in QEMU for PowerKVM guests
v8 cover target-ppc/spapr: Add FWNMI support in QEMU for PowerKVM guests
This patch set adds support for FWNMI in PowerKVM guests.
System errors such as SLB multihit and memory errors that cannot be corrected by hardware is passed on to the kernel for handling by raising machine check exception (an NMI). Upon such machine check exceptions, if the address in error belongs to guest then KVM invokes guests' 0x200 interrupt vector if the guest is not FWNMI capable. For FWNMI capable guest KVM passes the control to QEMU by exiting the guest.
This patch series adds functionality to QEMU to pass on such machine check exceptions to the FWNMI capable guest kernel by building an error log and invoking the guest registered machine check handling routine.
The KVM changes are now part of the upstream kernel (commit e20bbd3d). This series contain QEMU changes.
Change Log v8:
- Added functionality to check FWNMI capability during VM migration
Change Log v7:
- Rebased to 4.1
Change Log v6:
- Fetches rtas_addr from fdt
- Handles all error conditions (earlier it was only UEs)
Change Log v5:
- Handled VM migrations by including rtas_addr in VMSTATE.
- Migration is blocked while a machine check is in progress.
---
Aravinda Prasad (6):
ppc: spapr: Handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls Wrapper function to wait on condition for the main loop mutex target/ppc: Handle NMI guest exit
target/ppc: Build rtas error log upon an MCE
ppc: spapr: Enable FWNMI capability
migration: Block migration while handling machine check
cpus.c | 5 + hw/ppc/spapr.c | 26 ++++ hw/ppc/spapr_caps.c | 26 ++++ hw/ppc/spapr_events.c | 284 ++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 84 ++++++++++++++ include/hw/ppc/spapr.h | 26 ++++ include/qemu/main-loop.h | 8 + target/ppc/kvm.c | 30 +++++ target/ppc/kvm_ppc.h | 8 + target/ppc/trace-events | 2 10 files changed, 497 insertions(+), 2 deletions(-)
--
Aravinda
PATCH v8 1/6 ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls
This patch adds support in QEMU to handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls.
The machine check notification address is saved when the OS issues "ibm,nmi-register" RTAS call.
This patch also handles the case when multiple processors experience machine check at or about the same time by handling "ibm,nmi-interlock" call. In such cases, as per PAPR, subsequent processors serialize waiting for the first processor to issue the "ibm,nmi-interlock" call. The second processor that also received a machine check error waits till the first processor is done reading the error log. The first processor issues "ibm,nmi-interlock" call when the error log is consumed. This patch implements the releasing part of the error-log while subsequent patch (which builds error log) handles the locking part.
--- hw/ppc/spapr.c | 18 ++++++++++++++ hw/ppc/spapr_rtas.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 3 files changed, 87 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +18 -0
@@ -1805,6 +1805,11 @@ static void spapr_machine_reset(void) first_ppc_cpu->env.gpr[5 ] =0 ; spapr->cas_reboot = false; + + spapr->guest_machine_check_addr =-1 ; + +/* Signal all vCPUs waiting on this condition */ +qemu_cond_broadcast (&spapr->mc_delivery_cond); }static void spapr_create_nvram (SpaprMachineState *spapr)
@@ -2095,6 +2100,16 @@ static const VMStateDescription vmstate_spapr_dtb = { }, }; +static const VMStateDescription vmstate_spapr_machine_check = { + .name ="spapr_machine_check" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_END_OF_LIST () + }, +}; +static const VMStateDescription vmstate_spapr = { .name ="spapr" , .version_id =3 ,
@@ -2127,6 +2142,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_dtb, &vmstate_spapr_cap_large_decr, &vmstate_spapr_cap_ccf_assist, + &vmstate_spapr_machine_check, NULL } };
@@ -3068,6 +3084,8 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + +qemu_cond_init (&spapr->mc_delivery_cond); }static int spapr_kvm_type (MachineState *machine,const char *vm_type)
hw/ppc/spapr_rtas.c +61 -0
79 lines not on this page · raw message
include/hw/ppc/spapr.h +8 -1
@@ -187,6 +187,10 @@ struct SpaprMachineState {* occurs during the unplug process. */ QTAILQ_HEAD(, SpaprDimmState) pending_dimm_unplugs; +/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ +target_ulong guest_machine_check_addr; +QemuCond mc_delivery_cond; +/*< public >*/ char *kvm_type;char *host_model;
@@ -623,8 +627,10 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define RTAS_IBM_CREATE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x27)#define RTAS_IBM_REMOVE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x28)#define RTAS_IBM_RESET_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x29) +#define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2B) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2C)/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20
@@ -874,4 +880,5 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,#define SPAPR_OV5_XIVE_BOTH 0x80/* Only to advertise on the platform */ void spapr_set_all_lpcrs (target_ulong value,target_ulong mask); +uint64_t spapr_get_rtas_addr (void );#endif /* HW_SPAPR_H */
Re: [Qemu-devel] [PATCH v8 1/6] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls
Quoted 18 lines · Aravinda Prasad
This patch adds support in QEMU to handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls.
The machine check notification address is saved when the OS issues "ibm,nmi-register" RTAS call.
This patch also handles the case when multiple processors experience machine check at or about the same time by handling "ibm,nmi-interlock" call. In such cases, as per PAPR, subsequent processors serialize waiting for the first processor to issue the "ibm,nmi-interlock" call. The second processor that also received a machine check error waits till the first processor is done reading the error log. The first processor issues "ibm,nmi-interlock" call when the error log is consumed. This patch implements the releasing part of the error-log while subsequent patch (which builds error log) handles the locking part.
Quoted 1 line
Signed-off-by Aravinda Prasad <[email protected]>
Although I wonder if it needs to be moved later in the series to avoid advertising the availability of the RTAS calls to the guest before all the prereq patches are in place to make them work properly.
Quoted 176 lines
--- hw/ppc/spapr.c | 18 ++++++++++++++ hw/ppc/spapr_rtas.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 3 files changed, 87 insertions(+), 1 deletion(-)hw/ppc/spapr.c +18
-0@@ -1805,6 +1805,11 @@ static void spapr_machine_reset(void) first_ppc_cpu->env.gpr[5 ] =0 ; spapr->cas_reboot = false; + + spapr->guest_machine_check_addr =-1 ; + +/* Signal all vCPUs waiting on this condition */ +qemu_cond_broadcast (&spapr->mc_delivery_cond); }static void spapr_create_nvram (SpaprMachineState *spapr)@@ -2095,6 +2100,16 @@ static const VMStateDescription vmstate_spapr_dtb = { }, }; +static const VMStateDescription vmstate_spapr_machine_check = { + .name ="spapr_machine_check" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_END_OF_LIST () + }, +}; +static const VMStateDescription vmstate_spapr = { .name ="spapr" , .version_id =3 ,@@ -2127,6 +2142,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_dtb, &vmstate_spapr_cap_large_decr, &vmstate_spapr_cap_ccf_assist, + &vmstate_spapr_machine_check, NULL } };@@ -3068,6 +3084,8 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + +qemu_cond_init (&spapr->mc_delivery_cond); }static int spapr_kvm_type (MachineState *machine,const char *vm_type)hw/ppc/spapr_rtas.c +61
-0@@ -348,6 +348,39 @@ static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr,rtas_st (rets,1 ,100 ); } +static void rtas_ibm_nmi_register (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +uint64_t rtas_addr =spapr_get_rtas_addr (); + +if (!rtas_addr) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + + spapr->guest_machine_check_addr =rtas_ld (args,1 ); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +} + +static void rtas_ibm_nmi_interlock (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +if (!spapr->guest_machine_check_addr) { +/* NMI register not called */ +rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); + }else { +qemu_cond_signal (&spapr->mc_delivery_cond); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); + } +} + + static struct rtas_call { const char *name; spapr_rtas_fn fn;@@ -466,6 +499,30 @@ void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) } } +uint64_t spapr_get_rtas_addr (void ) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int rtas_node; +const struct fdt_property *rtas_addr_prop; +void *fdt = spapr->fdt_blob; +uint32_t rtas_addr; + +/* fetch rtas addr from fdt */ + rtas_node =fdt_path_offset (fdt,"/rtas" ); +if (rtas_node ==0 ) { +return 0 ; + } + + rtas_addr_prop =fdt_get_property (fdt, rtas_node,"linux,rtas-base" ,NULL ); +if (!rtas_addr_prop) { +return 0 ; + } + + rtas_addr =fdt32_to_cpu (*(uint32_t *)rtas_addr_prop->data); +return (uint64_t )rtas_addr; +} + +static void core_rtas_register_types (void ) { spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character",@@ -489,6 +546,10 @@ static void core_rtas_register_types(void) rtas_set_power_level);spapr_rtas_register (RTAS_GET_POWER_LEVEL ,"get-power-level" , rtas_get_power_level); +spapr_rtas_register (RTAS_IBM_NMI_REGISTER ,"ibm,nmi-register" , + rtas_ibm_nmi_register); +spapr_rtas_register (RTAS_IBM_NMI_INTERLOCK ,"ibm,nmi-interlock" , + rtas_ibm_nmi_interlock); }type_init (core_rtas_register_types)include/hw/ppc/spapr.h +8
-1@@ -187,6 +187,10 @@ struct SpaprMachineState {* occurs during the unplug process. */ QTAILQ_HEAD(, SpaprDimmState) pending_dimm_unplugs; +/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ +target_ulong guest_machine_check_addr; +QemuCond mc_delivery_cond; +/*< public >*/ char *kvm_type;char *host_model;@@ -623,8 +627,10 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define RTAS_IBM_CREATE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x27)#define RTAS_IBM_REMOVE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x28)#define RTAS_IBM_RESET_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x29) +#define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2B) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2C)/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20@@ -874,4 +880,5 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,#define SPAPR_OV5_XIVE_BOTH 0x80/* Only to advertise on the platform */ void spapr_set_all_lpcrs (target_ulong value,target_ulong mask); +uint64_t spapr_get_rtas_addr (void );#endif /* HW_SPAPR_H */
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
Re: [Qemu-devel] [PATCH v8 1/6] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls
Quoted 19 lines · David Gibson
Quoted 18 lines · Aravinda Prasad
This patch adds support in QEMU to handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls.
The machine check notification address is saved when the OS issues "ibm,nmi-register" RTAS call.
This patch also handles the case when multiple processors experience machine check at or about the same time by handling "ibm,nmi-interlock" call. In such cases, as per PAPR, subsequent processors serialize waiting for the first processor to issue the "ibm,nmi-interlock" call. The second processor that also received a machine check error waits till the first processor is done reading the error log. The first processor issues "ibm,nmi-interlock" call when the error log is consumed. This patch implements the releasing part of the error-log while subsequent patch (which builds error log) handles the locking part.
Quoted 7 lines
Quoted 1 line
Signed-off-by Aravinda Prasad <[email protected]>Reviewed-by David Gibson <[email protected]>Although I wonder if it needs to be moved later in the series to avoid advertising the availability of the RTAS calls to the guest before all the prereq patches are in place to make them work properly.
Patch 3 and 4 uses "guest_machine_check_addr", which is set in this patch. If we push this beyond patch 4, then I feel the use of "guest_machine_check_addr" looks odd in patch 3 and 4.
Regards,
Aravinda
Quoted 178 lines
Quoted 177 lines
--- hw/ppc/spapr.c | 18 ++++++++++++++ hw/ppc/spapr_rtas.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 3 files changed, 87 insertions(+), 1 deletion(-)hw/ppc/spapr.c +18
-0@@ -1805,6 +1805,11 @@ static void spapr_machine_reset(void) first_ppc_cpu->env.gpr[5 ] =0 ; spapr->cas_reboot = false; + + spapr->guest_machine_check_addr =-1 ; + +/* Signal all vCPUs waiting on this condition */ +qemu_cond_broadcast (&spapr->mc_delivery_cond); }static void spapr_create_nvram (SpaprMachineState *spapr)@@ -2095,6 +2100,16 @@ static const VMStateDescription vmstate_spapr_dtb = { }, }; +static const VMStateDescription vmstate_spapr_machine_check = { + .name ="spapr_machine_check" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_END_OF_LIST () + }, +}; +static const VMStateDescription vmstate_spapr = { .name ="spapr" , .version_id =3 ,@@ -2127,6 +2142,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_dtb, &vmstate_spapr_cap_large_decr, &vmstate_spapr_cap_ccf_assist, + &vmstate_spapr_machine_check, NULL } };@@ -3068,6 +3084,8 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + +qemu_cond_init (&spapr->mc_delivery_cond); }static int spapr_kvm_type (MachineState *machine,const char *vm_type)hw/ppc/spapr_rtas.c +61
-0@@ -348,6 +348,39 @@ static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr,rtas_st (rets,1 ,100 ); } +static void rtas_ibm_nmi_register (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +uint64_t rtas_addr =spapr_get_rtas_addr (); + +if (!rtas_addr) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + + spapr->guest_machine_check_addr =rtas_ld (args,1 ); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +} + +static void rtas_ibm_nmi_interlock (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +if (!spapr->guest_machine_check_addr) { +/* NMI register not called */ +rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); + }else { +qemu_cond_signal (&spapr->mc_delivery_cond); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); + } +} + + static struct rtas_call { const char *name; spapr_rtas_fn fn;@@ -466,6 +499,30 @@ void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) } } +uint64_t spapr_get_rtas_addr (void ) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int rtas_node; +const struct fdt_property *rtas_addr_prop; +void *fdt = spapr->fdt_blob; +uint32_t rtas_addr; + +/* fetch rtas addr from fdt */ + rtas_node =fdt_path_offset (fdt,"/rtas" ); +if (rtas_node ==0 ) { +return 0 ; + } + + rtas_addr_prop =fdt_get_property (fdt, rtas_node,"linux,rtas-base" ,NULL ); +if (!rtas_addr_prop) { +return 0 ; + } + + rtas_addr =fdt32_to_cpu (*(uint32_t *)rtas_addr_prop->data); +return (uint64_t )rtas_addr; +} + +static void core_rtas_register_types (void ) { spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character",@@ -489,6 +546,10 @@ static void core_rtas_register_types(void) rtas_set_power_level);spapr_rtas_register (RTAS_GET_POWER_LEVEL ,"get-power-level" , rtas_get_power_level); +spapr_rtas_register (RTAS_IBM_NMI_REGISTER ,"ibm,nmi-register" , + rtas_ibm_nmi_register); +spapr_rtas_register (RTAS_IBM_NMI_INTERLOCK ,"ibm,nmi-interlock" , + rtas_ibm_nmi_interlock); }type_init (core_rtas_register_types)include/hw/ppc/spapr.h +8
-1@@ -187,6 +187,10 @@ struct SpaprMachineState {* occurs during the unplug process. */ QTAILQ_HEAD(, SpaprDimmState) pending_dimm_unplugs; +/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ +target_ulong guest_machine_check_addr; +QemuCond mc_delivery_cond; +/*< public >*/ char *kvm_type;char *host_model;@@ -623,8 +627,10 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define RTAS_IBM_CREATE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x27)#define RTAS_IBM_REMOVE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x28)#define RTAS_IBM_RESET_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x29) +#define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2B) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2C)/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20@@ -874,4 +880,5 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,#define SPAPR_OV5_XIVE_BOTH 0x80/* Only to advertise on the platform */ void spapr_set_all_lpcrs (target_ulong value,target_ulong mask); +uint64_t spapr_get_rtas_addr (void );#endif /* HW_SPAPR_H */
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 1/6] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls
In reply to Aravinda PrasadQuoted 43 lines · On Mon, 22 Apr 2019 12:32:58 +0530 Aravinda Prasad…
This patch adds support in QEMU to handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls.
The machine check notification address is saved when the OS issues "ibm,nmi-register" RTAS call.
This patch also handles the case when multiple processors experience machine check at or about the same time by handling "ibm,nmi-interlock" call. In such cases, as per PAPR, subsequent processors serialize waiting for the first processor to issue the "ibm,nmi-interlock" call. The second processor that also received a machine check error waits till the first processor is done reading the error log. The first processor issues "ibm,nmi-interlock" call when the error log is consumed. This patch implements the releasing part of the error-log while subsequent patch (which builds error log) handles the locking part.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 18 ++++++++++++++ hw/ppc/spapr_rtas.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 3 files changed, 87 insertions(+), 1 deletion(-)hw/ppc/spapr.c +5
-0@@ -1805,6 +1805,11 @@ static void spapr_machine_reset(void) first_ppc_cpu->env.gpr[5 ] =0 ; spapr->cas_reboot = false; + + spapr->guest_machine_check_addr =-1 ; + +/* Signal all vCPUs waiting on this condition */ +qemu_cond_broadcast (&spapr->mc_delivery_cond); }static void spapr_create_nvram (SpaprMachineState *spapr)@@ -2095,6 +2100,16 @@ static const VMStateDescription vmstate_spapr_dtb = { },
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_dtb = { · line 2110
Quoted 10 lines
hw/ppc/spapr.c +8
-0}; +static const VMStateDescription vmstate_spapr_machine_check = { + .name ="spapr_machine_check" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_END_OF_LIST () + },
This VMState descriptor is missing a .needed field because we only want to migrate the subsection if the guest has called NMI register, ie. spapr->guest_machine_check_addr != (target_ulong) -1.
Quoted 44 lines
hw/ppc/spapr.c +5
-0+}; +static const VMStateDescription vmstate_spapr = { .name ="spapr" , .version_id =3 ,@@ -2127,6 +2142,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_dtb, &vmstate_spapr_cap_large_decr, &vmstate_spapr_cap_ccf_assist, + &vmstate_spapr_machine_check, NULL } };@@ -3068,6 +3084,8 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + +qemu_cond_init (&spapr->mc_delivery_cond); }static int spapr_kvm_type (MachineState *machine,const char *vm_type)hw/ppc/spapr_rtas.c +14
-0@@ -348,6 +348,39 @@ static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr,rtas_st (rets,1 ,100 ); } +static void rtas_ibm_nmi_register (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +uint64_t rtas_addr =spapr_get_rtas_addr (); + +if (!rtas_addr) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + + spapr->guest_machine_check_addr =rtas_ld (args,1 );
hw/ppc/spapr_rtas.c static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 374
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +} + +static void rtas_ibm_nmi_interlock (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +if (!spapr->guest_machine_check_addr) {
Hmm... the default value is -1. It looks like the check should rather be:
if (spapr->guest_machine_check_addr == (target_ulong) -1) {Quoted 13 lines
hw/ppc/spapr_rtas.c +9
-0+/* NMI register not called */ +rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); + }else { +qemu_cond_signal (&spapr->mc_delivery_cond); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); + } +} + + static struct rtas_call { const char *name; spapr_rtas_fn fn;
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 502
Quoted 4 lines
hw/ppc/spapr_rtas.c +1
-0@@ -466,6 +499,30 @@ void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) } } +uint64_t spapr_get_rtas_addr (void )
Shouldn't this be hwaddr instead of uint64_t ?
Quoted 5 lines
hw/ppc/spapr_rtas.c +5
-0+{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int rtas_node; +const struct fdt_property *rtas_addr_prop; +void *fdt = spapr->fdt_blob;
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 517
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+uint32_t rtas_addr; + +/* fetch rtas addr from fdt */ + rtas_node =fdt_path_offset (fdt,"/rtas" ); +if (rtas_node ==0 ) { +return 0 ; + } + + rtas_addr_prop =fdt_get_property (fdt, rtas_node,"linux,rtas-base" ,NULL ); +if (!rtas_addr_prop) {
Just for curiosity: this is ok for linux, but what about other OSes (eg. AIX) ?
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 521
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+return 0 ; + } + + rtas_addr =fdt32_to_cpu (*(uint32_t *)rtas_addr_prop->data);
Also this assumes the OS called RTAS instantiate-rtas, but some other OS might have called RTAS instantiate-rtas-64 instead. I guess it is ok for now because SLOF only provides the 32-bit variant, but a comment would certainly help IMHO.
Quoted 53 lines
hw/ppc/spapr_rtas.c +8
-0+return (uint64_t )rtas_addr; +} + +static void core_rtas_register_types (void ) { spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character",@@ -489,6 +546,10 @@ static void core_rtas_register_types(void) rtas_set_power_level);spapr_rtas_register (RTAS_GET_POWER_LEVEL ,"get-power-level" , rtas_get_power_level); +spapr_rtas_register (RTAS_IBM_NMI_REGISTER ,"ibm,nmi-register" , + rtas_ibm_nmi_register); +spapr_rtas_register (RTAS_IBM_NMI_INTERLOCK ,"ibm,nmi-interlock" , + rtas_ibm_nmi_interlock); }type_init (core_rtas_register_types)include/hw/ppc/spapr.h +8
-1@@ -187,6 +187,10 @@ struct SpaprMachineState {* occurs during the unplug process. */ QTAILQ_HEAD(, SpaprDimmState) pending_dimm_unplugs; +/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ +target_ulong guest_machine_check_addr; +QemuCond mc_delivery_cond; +/*< public >*/ char *kvm_type;char *host_model;@@ -623,8 +627,10 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define RTAS_IBM_CREATE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x27)#define RTAS_IBM_REMOVE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x28)#define RTAS_IBM_RESET_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x29) +#define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2B) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2C)/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20@@ -874,4 +880,5 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,#define SPAPR_OV5_XIVE_BOTH 0x80/* Only to advertise on the platform */ void spapr_set_all_lpcrs (target_ulong value,target_ulong mask); +uint64_t spapr_get_rtas_addr (void );#endif /* HW_SPAPR_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 1/6] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls
Quoted 164 lines · Greg Kurz
Quoted 43 lines · On Mon, 22 Apr 2019 12:32:58 +0530 Aravinda Prasad…
This patch adds support in QEMU to handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls.
The machine check notification address is saved when the OS issues "ibm,nmi-register" RTAS call.
This patch also handles the case when multiple processors experience machine check at or about the same time by handling "ibm,nmi-interlock" call. In such cases, as per PAPR, subsequent processors serialize waiting for the first processor to issue the "ibm,nmi-interlock" call. The second processor that also received a machine check error waits till the first processor is done reading the error log. The first processor issues "ibm,nmi-interlock" call when the error log is consumed. This patch implements the releasing part of the error-log while subsequent patch (which builds error log) handles the locking part.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 18 ++++++++++++++ hw/ppc/spapr_rtas.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 3 files changed, 87 insertions(+), 1 deletion(-)hw/ppc/spapr.c +5
-0@@ -1805,6 +1805,11 @@ static void spapr_machine_reset(void) first_ppc_cpu->env.gpr[5 ] =0 ; spapr->cas_reboot = false; + + spapr->guest_machine_check_addr =-1 ; + +/* Signal all vCPUs waiting on this condition */ +qemu_cond_broadcast (&spapr->mc_delivery_cond); }static void spapr_create_nvram (SpaprMachineState *spapr)@@ -2095,6 +2100,16 @@ static const VMStateDescription vmstate_spapr_dtb = { },hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_dtb = { · line 2110
Quoted 10 lines
hw/ppc/spapr.c +8
-0}; +static const VMStateDescription vmstate_spapr_machine_check = { + .name ="spapr_machine_check" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_END_OF_LIST () + },This VMState descriptor is missing a .needed field because we only want to migrate the subsection if the guest has called NMI register, ie.
spapr->guest_machine_check_addr!= (target_ulong) -1.Quoted 44 lines
hw/ppc/spapr.c +5
-0+}; +static const VMStateDescription vmstate_spapr = { .name ="spapr" , .version_id =3 ,@@ -2127,6 +2142,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_dtb, &vmstate_spapr_cap_large_decr, &vmstate_spapr_cap_ccf_assist, + &vmstate_spapr_machine_check, NULL } };@@ -3068,6 +3084,8 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + +qemu_cond_init (&spapr->mc_delivery_cond); }static int spapr_kvm_type (MachineState *machine,const char *vm_type)hw/ppc/spapr_rtas.c +14
-0@@ -348,6 +348,39 @@ static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr,rtas_st (rets,1 ,100 ); } +static void rtas_ibm_nmi_register (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +uint64_t rtas_addr =spapr_get_rtas_addr (); + +if (!rtas_addr) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + + spapr->guest_machine_check_addr =rtas_ld (args,1 );hw/ppc/spapr_rtas.c static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 374
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +} + +static void rtas_ibm_nmi_interlock (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +if (!spapr->guest_machine_check_addr) {Hmm... the default value is -1. It looks like the check should rather be:
if (spapr->guest_machine_check_addr == (target_ulong) -1) {Quoted 13 lines
hw/ppc/spapr_rtas.c +9
-0+/* NMI register not called */ +rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); + }else { +qemu_cond_signal (&spapr->mc_delivery_cond); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); + } +} + + static struct rtas_call { const char *name; spapr_rtas_fn fn;hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 502
Quoted 4 lines
hw/ppc/spapr_rtas.c +1
-0@@ -466,6 +499,30 @@ void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) } } +uint64_t spapr_get_rtas_addr (void )Shouldn't this be hwaddr instead of
uint64_t?Quoted 5 lines
hw/ppc/spapr_rtas.c +5
-0+{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int rtas_node; +const struct fdt_property *rtas_addr_prop; +void *fdt = spapr->fdt_blob;hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 517
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+uint32_t rtas_addr; + +/* fetch rtas addr from fdt */ + rtas_node =fdt_path_offset (fdt,"/rtas" ); +if (rtas_node ==0 ) { +return 0 ; + } + + rtas_addr_prop =fdt_get_property (fdt, rtas_node,"linux,rtas-base" ,NULL ); +if (!rtas_addr_prop) {Just for curiosity: this is ok for linux, but what about other OSes (eg. AIX) ?
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 521
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+return 0 ; + } + + rtas_addr =fdt32_to_cpu (*(uint32_t *)rtas_addr_prop->data);
Quoted 4 lines
Also this assumes the OS called RTAS instantiate-rtas, but some other OS might have called RTAS instantiate-rtas-64 instead. I guess it is ok for now because SLOF only provides the 32-bit variant, but a comment would certainly help IMHO.
I have a feeling kvm-unit-tests may not call instantiate-rtas at all.
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 1/6] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls
In reply to Greg KurzQuoted 48 lines · On Fri, 10 May 2019 11:06:04 +0200 Greg Kurz <[email protected]> wrote:
Quoted 45 lines · On Mon, 22 Apr 2019 12:32:58 +0530 Aravinda Prasad…
This patch adds support in QEMU to handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls.
The machine check notification address is saved when the OS issues "ibm,nmi-register" RTAS call.
This patch also handles the case when multiple processors experience machine check at or about the same time by handling "ibm,nmi-interlock" call. In such cases, as per PAPR, subsequent processors serialize waiting for the first processor to issue the "ibm,nmi-interlock" call. The second processor that also received a machine check error waits till the first processor is done reading the error log. The first processor issues "ibm,nmi-interlock" call when the error log is consumed. This patch implements the releasing part of the error-log while subsequent patch (which builds error log) handles the locking part.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 18 ++++++++++++++ hw/ppc/spapr_rtas.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 3 files changed, 87 insertions(+), 1 deletion(-)hw/ppc/spapr.c +5
-0@@ -1805,6 +1805,11 @@ static void spapr_machine_reset(void) first_ppc_cpu->env.gpr[5 ] =0 ; spapr->cas_reboot = false; + + spapr->guest_machine_check_addr =-1 ; + +/* Signal all vCPUs waiting on this condition */ +qemu_cond_broadcast (&spapr->mc_delivery_cond); }static void spapr_create_nvram (SpaprMachineState *spapr)@@ -2095,6 +2100,16 @@ static const VMStateDescription vmstate_spapr_dtb = { }, };
Quoted 6 lines
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_dtb = { · line 2108
Quoted 6 lines
hw/ppc/spapr.c +6
-0+static const VMStateDescription vmstate_spapr_machine_check = { + .name ="spapr_machine_check" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState),
Also this should use VMSTATE_UINTTL()
Quoted 170 lines
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_dtb = { · line 2110
Quoted 2 lines
hw/ppc/spapr.c +2
-0+VMSTATE_END_OF_LIST () + },This VMState descriptor is missing a .needed field because we only want to migrate the subsection if the guest has called NMI register, ie.
spapr->guest_machine_check_addr!= (target_ulong) -1.Quoted 44 lines
hw/ppc/spapr.c +5
-0+}; + static const VMStateDescription vmstate_spapr = {765cf442a8afe8e5c8c6896b5072066df5129077 .name ="spapr" , .version_id =3 ,@@ -2127,6 +2142,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_dtb, &vmstate_spapr_cap_large_decr, &vmstate_spapr_cap_ccf_assist, + &vmstate_spapr_machine_check, NULL } };@@ -3068,6 +3084,8 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + +qemu_cond_init (&spapr->mc_delivery_cond); }static int spapr_kvm_type (MachineState *machine,const char *vm_type)hw/ppc/spapr_rtas.c +14
-0@@ -348,6 +348,39 @@ static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr,rtas_st (rets,1 ,100 ); } +static void rtas_ibm_nmi_register (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +uint64_t rtas_addr =spapr_get_rtas_addr (); + +if (!rtas_addr) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + + spapr->guest_machine_check_addr =rtas_ld (args,1 );hw/ppc/spapr_rtas.c static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 374
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +} + +static void rtas_ibm_nmi_interlock (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +if (!spapr->guest_machine_check_addr) {Hmm... the default value is -1. It looks like the check should rather be:
if (spapr->guest_machine_check_addr == (target_ulong) -1) {Quoted 13 lines
hw/ppc/spapr_rtas.c +9
-0+/* NMI register not called */ +rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); + }else { +qemu_cond_signal (&spapr->mc_delivery_cond); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); + } +} + + static struct rtas_call { const char *name; spapr_rtas_fn fn;hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 502
Quoted 4 lines
hw/ppc/spapr_rtas.c +1
-0@@ -466,6 +499,30 @@ void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) } } +uint64_t spapr_get_rtas_addr (void )Shouldn't this be hwaddr instead of
uint64_t?Quoted 5 lines
hw/ppc/spapr_rtas.c +5
-0+{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int rtas_node; +const struct fdt_property *rtas_addr_prop; +void *fdt = spapr->fdt_blob;hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 517
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+uint32_t rtas_addr; + +/* fetch rtas addr from fdt */ + rtas_node =fdt_path_offset (fdt,"/rtas" ); +if (rtas_node ==0 ) { +return 0 ; + } + + rtas_addr_prop =fdt_get_property (fdt, rtas_node,"linux,rtas-base" ,NULL ); +if (!rtas_addr_prop) {Just for curiosity: this is ok for linux, but what about other OSes (eg. AIX) ?
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 521
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+return 0 ; + } + + rtas_addr =fdt32_to_cpu (*(uint32_t *)rtas_addr_prop->data);Also this assumes the OS called RTAS instantiate-rtas, but some other OS might have called RTAS instantiate-rtas-64 instead. I guess it is ok for now because SLOF only provides the 32-bit variant, but a comment would certainly help IMHO.
Quoted 53 lines
hw/ppc/spapr_rtas.c +8
-0+return (uint64_t )rtas_addr; +} + +static void core_rtas_register_types (void ) { spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character",@@ -489,6 +546,10 @@ static void core_rtas_register_types(void) rtas_set_power_level);spapr_rtas_register (RTAS_GET_POWER_LEVEL ,"get-power-level" , rtas_get_power_level); +spapr_rtas_register (RTAS_IBM_NMI_REGISTER ,"ibm,nmi-register" , + rtas_ibm_nmi_register); +spapr_rtas_register (RTAS_IBM_NMI_INTERLOCK ,"ibm,nmi-interlock" , + rtas_ibm_nmi_interlock); }type_init (core_rtas_register_types)include/hw/ppc/spapr.h +8
-1@@ -187,6 +187,10 @@ struct SpaprMachineState {* occurs during the unplug process. */ QTAILQ_HEAD(, SpaprDimmState) pending_dimm_unplugs; +/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ +target_ulong guest_machine_check_addr; +QemuCond mc_delivery_cond; +/*< public >*/ char *kvm_type;char *host_model;@@ -623,8 +627,10 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define RTAS_IBM_CREATE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x27)#define RTAS_IBM_REMOVE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x28)#define RTAS_IBM_RESET_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x29) +#define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2B) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2C)/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20@@ -874,4 +880,5 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,#define SPAPR_OV5_XIVE_BOTH 0x80/* Only to advertise on the platform */ void spapr_set_all_lpcrs (target_ulong value,target_ulong mask); +uint64_t spapr_get_rtas_addr (void );#endif /* HW_SPAPR_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 1/6] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls
Quoted 51 lines · Greg Kurz
Quoted 48 lines · On Fri, 10 May 2019 11:06:04 +0200 Greg Kurz <[email protected]> wrote:
Quoted 45 lines · On Mon, 22 Apr 2019 12:32:58 +0530 Aravinda Prasad…
This patch adds support in QEMU to handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls.
The machine check notification address is saved when the OS issues "ibm,nmi-register" RTAS call.
This patch also handles the case when multiple processors experience machine check at or about the same time by handling "ibm,nmi-interlock" call. In such cases, as per PAPR, subsequent processors serialize waiting for the first processor to issue the "ibm,nmi-interlock" call. The second processor that also received a machine check error waits till the first processor is done reading the error log. The first processor issues "ibm,nmi-interlock" call when the error log is consumed. This patch implements the releasing part of the error-log while subsequent patch (which builds error log) handles the locking part.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 18 ++++++++++++++ hw/ppc/spapr_rtas.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 3 files changed, 87 insertions(+), 1 deletion(-)hw/ppc/spapr.c +5
-0@@ -1805,6 +1805,11 @@ static void spapr_machine_reset(void) first_ppc_cpu->env.gpr[5 ] =0 ; spapr->cas_reboot = false; + + spapr->guest_machine_check_addr =-1 ; + +/* Signal all vCPUs waiting on this condition */ +qemu_cond_broadcast (&spapr->mc_delivery_cond); }static void spapr_create_nvram (SpaprMachineState *spapr)@@ -2095,6 +2100,16 @@ static const VMStateDescription vmstate_spapr_dtb = { }, };
Quoted 8 lines
Quoted 6 lines
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_dtb = { · line 2108
Quoted 6 lines
hw/ppc/spapr.c +6
-0+static const VMStateDescription vmstate_spapr_machine_check = { + .name ="spapr_machine_check" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState),Also this should use
VMSTATE_UINTTL()
sure..
Regards,
Aravinda
Quoted 172 lines
Quoted 171 lines
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_dtb = { · line 2110
Quoted 3 lines
hw/ppc/spapr.c +2
-0+VMSTATE_END_OF_LIST () + },This VMState descriptor is missing a .needed field because we only want to migrate the subsection if the guest has called NMI register, ie.
spapr->guest_machine_check_addr!= (target_ulong) -1.Quoted 44 lines
hw/ppc/spapr.c +5
-0+}; + static const VMStateDescription vmstate_spapr = {765cf442a8afe8e5c8c6896b5072066df5129077 .name ="spapr" , .version_id =3 ,@@ -2127,6 +2142,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_dtb, &vmstate_spapr_cap_large_decr, &vmstate_spapr_cap_ccf_assist, + &vmstate_spapr_machine_check, NULL } };@@ -3068,6 +3084,8 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + +qemu_cond_init (&spapr->mc_delivery_cond); }static int spapr_kvm_type (MachineState *machine,const char *vm_type)hw/ppc/spapr_rtas.c +14
-0@@ -348,6 +348,39 @@ static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr,rtas_st (rets,1 ,100 ); } +static void rtas_ibm_nmi_register (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +uint64_t rtas_addr =spapr_get_rtas_addr (); + +if (!rtas_addr) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + + spapr->guest_machine_check_addr =rtas_ld (args,1 );hw/ppc/spapr_rtas.c static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 374
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +} + +static void rtas_ibm_nmi_interlock (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +if (!spapr->guest_machine_check_addr) {Hmm... the default value is -1. It looks like the check should rather be:
if (spapr->guest_machine_check_addr == (target_ulong) -1) {Quoted 13 lines
hw/ppc/spapr_rtas.c +9
-0+/* NMI register not called */ +rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); + }else { +qemu_cond_signal (&spapr->mc_delivery_cond); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); + } +} + + static struct rtas_call { const char *name; spapr_rtas_fn fn;hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 502
Quoted 4 lines
hw/ppc/spapr_rtas.c +1
-0@@ -466,6 +499,30 @@ void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) } } +uint64_t spapr_get_rtas_addr (void )Shouldn't this be hwaddr instead of
uint64_t?Quoted 5 lines
hw/ppc/spapr_rtas.c +5
-0+{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int rtas_node; +const struct fdt_property *rtas_addr_prop; +void *fdt = spapr->fdt_blob;hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 517
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+uint32_t rtas_addr; + +/* fetch rtas addr from fdt */ + rtas_node =fdt_path_offset (fdt,"/rtas" ); +if (rtas_node ==0 ) { +return 0 ; + } + + rtas_addr_prop =fdt_get_property (fdt, rtas_node,"linux,rtas-base" ,NULL ); +if (!rtas_addr_prop) {Just for curiosity: this is ok for linux, but what about other OSes (eg. AIX) ?
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 521
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+return 0 ; + } + + rtas_addr =fdt32_to_cpu (*(uint32_t *)rtas_addr_prop->data);Also this assumes the OS called RTAS instantiate-rtas, but some other OS might have called RTAS instantiate-rtas-64 instead. I guess it is ok for now because SLOF only provides the 32-bit variant, but a comment would certainly help IMHO.
Quoted 53 lines
hw/ppc/spapr_rtas.c +8
-0+return (uint64_t )rtas_addr; +} + +static void core_rtas_register_types (void ) { spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character",@@ -489,6 +546,10 @@ static void core_rtas_register_types(void) rtas_set_power_level);spapr_rtas_register (RTAS_GET_POWER_LEVEL ,"get-power-level" , rtas_get_power_level); +spapr_rtas_register (RTAS_IBM_NMI_REGISTER ,"ibm,nmi-register" , + rtas_ibm_nmi_register); +spapr_rtas_register (RTAS_IBM_NMI_INTERLOCK ,"ibm,nmi-interlock" , + rtas_ibm_nmi_interlock); }type_init (core_rtas_register_types)include/hw/ppc/spapr.h +8
-1@@ -187,6 +187,10 @@ struct SpaprMachineState {* occurs during the unplug process. */ QTAILQ_HEAD(, SpaprDimmState) pending_dimm_unplugs; +/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ +target_ulong guest_machine_check_addr; +QemuCond mc_delivery_cond; +/*< public >*/ char *kvm_type;char *host_model;@@ -623,8 +627,10 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define RTAS_IBM_CREATE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x27)#define RTAS_IBM_REMOVE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x28)#define RTAS_IBM_RESET_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x29) +#define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2B) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2C)/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20@@ -874,4 +880,5 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,#define SPAPR_OV5_XIVE_BOTH 0x80/* Only to advertise on the platform */ void spapr_set_all_lpcrs (target_ulong value,target_ulong mask); +uint64_t spapr_get_rtas_addr (void );#endif /* HW_SPAPR_H */
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 1/6] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls
In reply to Greg KurzQuoted 48 lines · Greg Kurz
Quoted 45 lines · On Mon, 22 Apr 2019 12:32:58 +0530 Aravinda Prasad…
This patch adds support in QEMU to handle "ibm,nmi-register" and "ibm,nmi-interlock" RTAS calls.
The machine check notification address is saved when the OS issues "ibm,nmi-register" RTAS call.
This patch also handles the case when multiple processors experience machine check at or about the same time by handling "ibm,nmi-interlock" call. In such cases, as per PAPR, subsequent processors serialize waiting for the first processor to issue the "ibm,nmi-interlock" call. The second processor that also received a machine check error waits till the first processor is done reading the error log. The first processor issues "ibm,nmi-interlock" call when the error log is consumed. This patch implements the releasing part of the error-log while subsequent patch (which builds error log) handles the locking part.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 18 ++++++++++++++ hw/ppc/spapr_rtas.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 3 files changed, 87 insertions(+), 1 deletion(-)hw/ppc/spapr.c +5
-0@@ -1805,6 +1805,11 @@ static void spapr_machine_reset(void) first_ppc_cpu->env.gpr[5 ] =0 ; spapr->cas_reboot = false; + + spapr->guest_machine_check_addr =-1 ; + +/* Signal all vCPUs waiting on this condition */ +qemu_cond_broadcast (&spapr->mc_delivery_cond); }static void spapr_create_nvram (SpaprMachineState *spapr)@@ -2095,6 +2100,16 @@ static const VMStateDescription vmstate_spapr_dtb = { }, };
Quoted 12 lines
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_dtb = { · line 2110
Quoted 8 lines
hw/ppc/spapr.c +8
-0+static const VMStateDescription vmstate_spapr_machine_check = { + .name ="spapr_machine_check" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_END_OF_LIST () + },This VMState descriptor is missing a .needed field because we only want to migrate the subsection if the guest has called NMI register, ie.
spapr->guest_machine_check_addr!= (target_ulong) -1.
Ok.. let me check.
Quoted 58 lines
Quoted 45 lines
hw/ppc/spapr.c +5
-0+}; +static const VMStateDescription vmstate_spapr = { .name ="spapr" , .version_id =3 ,@@ -2127,6 +2142,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_dtb, &vmstate_spapr_cap_large_decr, &vmstate_spapr_cap_ccf_assist, + &vmstate_spapr_machine_check, NULL } };@@ -3068,6 +3084,8 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + +qemu_cond_init (&spapr->mc_delivery_cond); }static int spapr_kvm_type (MachineState *machine,const char *vm_type)hw/ppc/spapr_rtas.c +14
-0@@ -348,6 +348,39 @@ static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr,rtas_st (rets,1 ,100 ); } +static void rtas_ibm_nmi_register (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +uint64_t rtas_addr =spapr_get_rtas_addr (); + +if (!rtas_addr) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + + spapr->guest_machine_check_addr =rtas_ld (args,1 );hw/ppc/spapr_rtas.c static void rtas_get_power_level(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 374
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +} + +static void rtas_ibm_nmi_interlock (PowerPCCPU *cpu, +SpaprMachineState *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +if (!spapr->guest_machine_check_addr) {Hmm... the default value is -1. It looks like the check should rather be:
Quoted 1 line
if (spapr->guest_machine_check_addr == (target_ulong) -1) {ok..
Quoted 18 lines
Quoted 18 lines
hw/ppc/spapr_rtas.c +9
-0+/* NMI register not called */ +rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); + }else { +qemu_cond_signal (&spapr->mc_delivery_cond); +rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); + } +} + + static struct rtas_call { const char *name; spapr_rtas_fn fn;@@ -466,6 +499,30 @@ void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) } }
Quoted 3 lines
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 502
Quoted 1 line
hw/ppc/spapr_rtas.c +1
-0+uint64_t spapr_get_rtas_addr (void )Shouldn't this be hwaddr instead of
uint64_t?
Yes, I will change it.
Quoted 10 lines
Quoted 10 lines
hw/ppc/spapr_rtas.c +9
-0+{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int rtas_node; +const struct fdt_property *rtas_addr_prop; +void *fdt = spapr->fdt_blob; +uint32_t rtas_addr; + +/* fetch rtas addr from fdt */ + rtas_node =fdt_path_offset (fdt,"/rtas" );
Quoted 8 lines
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 517
Quoted 6 lines
hw/ppc/spapr_rtas.c +6
-0+if (rtas_node ==0 ) { +return 0 ; + } + + rtas_addr_prop =fdt_get_property (fdt, rtas_node,"linux,rtas-base" ,NULL ); +if (!rtas_addr_prop) {Just for curiosity: this is ok for linux, but what about other OSes (eg. AIX) ?
Really not sure! Need to check.
Quoted 10 lines
hw/ppc/spapr_rtas.c void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr) · line 521
Quoted 5 lines
hw/ppc/spapr_rtas.c +4
-0+return 0 ; + } + + rtas_addr =fdt32_to_cpu (*(uint32_t *)rtas_addr_prop->data);Also this assumes the OS called RTAS instantiate-rtas, but some other OS might have called RTAS instantiate-rtas-64 instead. I guess it is ok for now because SLOF only provides the 32-bit variant, but a comment would certainly help IMHO.
Sure..
Regards,
Aravinda
Quoted 55 lines
Quoted 54 lines
hw/ppc/spapr_rtas.c +8
-0+return (uint64_t )rtas_addr; +} + +static void core_rtas_register_types (void ) { spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character",@@ -489,6 +546,10 @@ static void core_rtas_register_types(void) rtas_set_power_level);spapr_rtas_register (RTAS_GET_POWER_LEVEL ,"get-power-level" , rtas_get_power_level); +spapr_rtas_register (RTAS_IBM_NMI_REGISTER ,"ibm,nmi-register" , + rtas_ibm_nmi_register); +spapr_rtas_register (RTAS_IBM_NMI_INTERLOCK ,"ibm,nmi-interlock" , + rtas_ibm_nmi_interlock); }type_init (core_rtas_register_types)include/hw/ppc/spapr.h +8
-1@@ -187,6 +187,10 @@ struct SpaprMachineState {* occurs during the unplug process. */ QTAILQ_HEAD(, SpaprDimmState) pending_dimm_unplugs; +/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ +target_ulong guest_machine_check_addr; +QemuCond mc_delivery_cond; +/*< public >*/ char *kvm_type;char *host_model;@@ -623,8 +627,10 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define RTAS_IBM_CREATE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x27)#define RTAS_IBM_REMOVE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x28)#define RTAS_IBM_RESET_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x29) +#define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2B) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2C)/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20@@ -874,4 +880,5 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,#define SPAPR_OV5_XIVE_BOTH 0x80/* Only to advertise on the platform */ void spapr_set_all_lpcrs (target_ulong value,target_ulong mask); +uint64_t spapr_get_rtas_addr (void );#endif /* HW_SPAPR_H */
Signature · 2 lines
Regards, Aravinda
PATCH v8 2/6 Wrapper function to wait on condition for the main loop mutex
In reply to Aravinda PrasadIntroduce a wrapper function to wait on condition for the main loop mutex. This function atomically releases the main loop mutex and causes the calling thread to block on the condition. This wrapper is required because qemu_global_mutex is a static variable.
--- cpus.c | 5 +++++ include/qemu/main-loop.h | 8 ++++++++ 2 files changed, 13 insertions(+)
cpus.c +5 -0
@@ -1858,6 +1858,11 @@ void qemu_mutex_unlock_iothread(void)qemu_mutex_unlock (&qemu_global_mutex); } +void qemu_cond_wait_iothread (QemuCond *cond) +{ +qemu_cond_wait (cond, &qemu_global_mutex); +} +static bool all_vcpus_paused (void ) {CPUState *cpu;
include/qemu/main-loop.h +8 -0
@@ -295,6 +295,14 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line);*/ void qemu_mutex_unlock_iothread (void ); +/* +* qemu_cond_wait_iothread: Wait on condition for the main loop mutex +* +* This function atomically releases the main loop mutex and causes +* the calling thread to block on the condition. +*/ +void qemu_cond_wait_iothread (QemuCond *cond); +/* internal interfaces */ void qemu_fd_register (int fd);
Re: [Qemu-devel] [PATCH v8 2/6] Wrapper function to wait on condition for the main loop mutex
Quoted 7 lines · Aravinda Prasad
Introduce a wrapper function to wait on condition for the main loop mutex. This function atomically releases the main loop mutex and causes the calling thread to block on the condition. This wrapper is required because
qemu_global_mutexis a static variable.Signed-off-by Aravinda Prasad <[email protected]>
Quoted 41 lines
--- cpus.c | 5 +++++ include/qemu/main-loop.h | 8 ++++++++ 2 files changed, 13 insertions(+)cpus.c +5
-0@@ -1858,6 +1858,11 @@ void qemu_mutex_unlock_iothread(void)qemu_mutex_unlock (&qemu_global_mutex); } +void qemu_cond_wait_iothread (QemuCond *cond) +{ +qemu_cond_wait (cond, &qemu_global_mutex); +} +static bool all_vcpus_paused (void ) {CPUState *cpu;include/qemu/main-loop.h +8
-0@@ -295,6 +295,14 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line);*/ void qemu_mutex_unlock_iothread (void ); +/* +* qemu_cond_wait_iothread: Wait on condition for the main loop mutex +* +* This function atomically releases the main loop mutex and causes +* the calling thread to block on the condition. +*/ +void qemu_cond_wait_iothread (QemuCond *cond); +/* internal interfaces */ void qemu_fd_register (int fd);
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 2/6] Wrapper function to wait on condition for the main loop mutex
In reply to Aravinda PrasadQuoted 8 lines · On Mon, 22 Apr 2019 12:33:07 +0530 Aravinda Prasad…
Introduce a wrapper function to wait on condition for the main loop mutex. This function atomically releases the main loop mutex and causes the calling thread to block on the condition. This wrapper is required because
qemu_global_mutexis a static variable.Signed-off-by Aravinda Prasad <[email protected]>---
Quoted 41 lines
cpus.c | 5 +++++ include/qemu/main-loop.h | 8 ++++++++ 2 files changed, 13 insertions(+)cpus.c +5
-0@@ -1858,6 +1858,11 @@ void qemu_mutex_unlock_iothread(void)qemu_mutex_unlock (&qemu_global_mutex); } +void qemu_cond_wait_iothread (QemuCond *cond) +{ +qemu_cond_wait (cond, &qemu_global_mutex); +} +static bool all_vcpus_paused (void ) {CPUState *cpu;include/qemu/main-loop.h +8
-0@@ -295,6 +295,14 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line);*/ void qemu_mutex_unlock_iothread (void ); +/* +* qemu_cond_wait_iothread: Wait on condition for the main loop mutex +* +* This function atomically releases the main loop mutex and causes +* the calling thread to block on the condition. +*/ +void qemu_cond_wait_iothread (QemuCond *cond); +/* internal interfaces */ void qemu_fd_register (int fd);
PATCH v8 3/6 target/ppc: Handle NMI guest exit
In reply to Aravinda PrasadMemory error such as bit flips that cannot be corrected by hardware are passed on to the kernel for handling. If the memory address in error belongs to guest then the guest kernel is responsible for taking suitable action. Patch [1] enhances KVM to exit guest with exit reason set to KVM_EXIT_NMI in such cases. This patch handles KVM_EXIT_NMI exit.
[1] https://www.spinics.net/lists/kvm-ppc/msg12637.html
(e20bbd3d and related commits)
--- hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_events.c | 22 ++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++++ include/hw/ppc/spapr.h | 6 ++++++ target/ppc/kvm.c | 16 ++++++++++++++++ target/ppc/kvm_ppc.h | 2 ++ target/ppc/trace-events | 2 ++ 7 files changed, 56 insertions(+)
hw/ppc/spapr.c +3 -0
@@ -1806,6 +1806,7 @@ static void spapr_machine_reset(void) spapr->cas_reboot = false; + spapr->mc_status =-1 ; spapr->guest_machine_check_addr =-1 ;/* Signal all vCPUs waiting on this condition */
@@ -2106,6 +2107,7 @@ static const VMStateDescription vmstate_spapr_machine_check = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_INT32 (mc_status, SpaprMachineState),VMSTATE_END_OF_LIST () }, };
@@ -3085,6 +3087,7 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + spapr->mc_status =-1 ;qemu_cond_init (&spapr->mc_delivery_cond); }
hw/ppc/spapr_events.c +22 -0
@@ -620,6 +620,28 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +while (spapr->mc_status !=-1 ) { +/* +* Check whether the same CPU got machine check error +* while still handling the mc error (i.e., before +* that CPU called "ibm,nmi-interlock" +*/ +if (spapr->mc_status == cpu->vcpu_id) { +qemu_system_guest_panicked (NULL ); + } +qemu_cond_wait_iothread (&spapr->mc_delivery_cond); +/* Meanwhile if the system is reset, then just return */ +if (spapr->guest_machine_check_addr ==-1 ) { +return ; + } + } + spapr->mc_status = cpu->vcpu_id; +} + static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args,
hw/ppc/spapr_rtas.c +5 -0
@@ -375,6 +375,11 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu,/* NMI register not called */ rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); }else { +/* +* vCPU issuing "ibm,nmi-interlock" is done with NMI handling, +* hence unset mc_status. +*/ + spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }
include/hw/ppc/spapr.h +6 -0
@@ -189,6 +189,11 @@ struct SpaprMachineState {/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ target_ulong guest_machine_check_addr; +/* +* mc_status is set to -1 if mc is not in progress, else is set to the CPU +* handling the mc. +*/ +int mc_status;QemuCond mc_delivery_cond;/*< public >*/
@@ -792,6 +797,7 @@ void spapr_clear_pending_events(SpaprMachineState *spapr);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1); +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);
target/ppc/kvm.c +16 -0
@@ -1759,6 +1759,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =0 ;break ; +case KVM_EXIT_NMI : +trace_kvm_handle_nmi_exception (); + ret =kvm_handle_nmi (cpu, run); +break ; +default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason); ret =-1 ;
@@ -2837,6 +2842,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)return data &0xffff ; } +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run) +{ +bool recovered = run->flags &KVM_RUN_PPC_NMI_DISP_FULLY_RECOV ; + +cpu_synchronize_state (CPU (cpu)); + +spapr_mce_req_event (cpu, recovered); + +return 0 ; +} +int kvmppc_enable_hwrng (void ) {if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) {
target/ppc/kvm_ppc.h +2 -0
@@ -80,6 +80,8 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void);void kvm_check_mmu (PowerPCCPU *cpu,Error **errp);void kvmppc_set_reg_ppc_online (PowerPCCPU *cpu,unsigned int online); +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run); +#else static inline uint32_t kvmppc_get_tbfreq (void )
target/ppc/trace-events +2 -0
@@ -28,3 +28,5 @@ kvm_handle_papr_hcall(void) "handle PAPR hypercall" kvm_handle_epr(void) "handle epr" kvm_handle_watchdog_expiry(void) "handle watchdog expiry" kvm_handle_debug_exception(void) "handle debug exception" +kvm_handle_nmi_exception(void) "handle NMI exception" +
Re: [Qemu-devel] [PATCH v8 3/6] target/ppc: Handle NMI guest exit
Quoted 8 lines · Aravinda Prasad
Memory error such as bit flips that cannot be corrected by hardware are passed on to the kernel for handling. If the memory address in error belongs to guest then the guest kernel is responsible for taking suitable action. Patch [1] enhances KVM to exit guest with exit reason set to
KVM_EXIT_NMIin such cases. This patch handlesKVM_EXIT_NMIexit.
Quoted 4 lines
[1] https://www.spinics.net/lists/kvm-ppc/msg12637.html
(e20bbd3dand related commits)Signed-off-by Aravinda Prasad <[email protected]>
LGTM, apart from one detail noted below.
Quoted 23 lines
--- hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_events.c | 22 ++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++++ include/hw/ppc/spapr.h | 6 ++++++ target/ppc/kvm.c | 16 ++++++++++++++++ target/ppc/kvm_ppc.h | 2 ++ target/ppc/trace-events | 2 ++ 7 files changed, 56 insertions(+)hw/ppc/spapr.c +1
-0@@ -1806,6 +1806,7 @@ static void spapr_machine_reset(void) spapr->cas_reboot = false; + spapr->mc_status =-1 ; spapr->guest_machine_check_addr =-1 ;/* Signal all vCPUs waiting on this condition */
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_machine_check = { · line 2110
Quoted 4 lines
hw/ppc/spapr.c +1
-0@@ -2106,6 +2107,7 @@ static const VMStateDescription vmstate_spapr_machine_check = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_INT32 (mc_status, SpaprMachineState),
So, technically this is a breaking change to the migration stream. If this is applied immediately after the earlier patch introducing the subsection it would be ok in practice, but it would still be preferable to make all the migration stream changes together.
Quoted 142 lines
hw/ppc/spapr.c +1
-0VMSTATE_END_OF_LIST () }, };@@ -3085,6 +3087,7 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + spapr->mc_status =-1 ;qemu_cond_init (&spapr->mc_delivery_cond); }hw/ppc/spapr_events.c +22
-0@@ -620,6 +620,28 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +while (spapr->mc_status !=-1 ) { +/* +* Check whether the same CPU got machine check error +* while still handling the mc error (i.e., before +* that CPU called "ibm,nmi-interlock" +*/ +if (spapr->mc_status == cpu->vcpu_id) { +qemu_system_guest_panicked (NULL ); + } +qemu_cond_wait_iothread (&spapr->mc_delivery_cond); +/* Meanwhile if the system is reset, then just return */ +if (spapr->guest_machine_check_addr ==-1 ) { +return ; + } + } + spapr->mc_status = cpu->vcpu_id; +} + static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args,hw/ppc/spapr_rtas.c +5
-0@@ -375,6 +375,11 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu,/* NMI register not called */ rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); }else { +/* +* vCPU issuing "ibm,nmi-interlock" is done with NMI handling, +* hence unset mc_status. +*/ + spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +6
-0@@ -189,6 +189,11 @@ struct SpaprMachineState {/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ target_ulong guest_machine_check_addr; +/* +* mc_status is set to -1 if mc is not in progress, else is set to the CPU +* handling the mc. +*/ +int mc_status;QemuCond mc_delivery_cond;/*< public >*/ @@ -792,6 +797,7 @@ void spapr_clear_pending_events(SpaprMachineState *spapr);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1); +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);target/ppc/kvm.c +16
-0@@ -1759,6 +1759,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =0 ;break ; +case KVM_EXIT_NMI : +trace_kvm_handle_nmi_exception (); + ret =kvm_handle_nmi (cpu, run); +break ; +default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason); ret =-1 ;@@ -2837,6 +2842,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)return data &0xffff ; } +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run) +{ +bool recovered = run->flags &KVM_RUN_PPC_NMI_DISP_FULLY_RECOV ; + +cpu_synchronize_state (CPU (cpu)); + +spapr_mce_req_event (cpu, recovered); + +return 0 ; +} +int kvmppc_enable_hwrng (void ) {if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) {target/ppc/kvm_ppc.h +2
-0@@ -80,6 +80,8 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void);void kvm_check_mmu (PowerPCCPU *cpu,Error **errp);void kvmppc_set_reg_ppc_online (PowerPCCPU *cpu,unsigned int online); +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run); +#else static inline uint32_t kvmppc_get_tbfreq (void )target/ppc/trace-events +2
-0@@ -28,3 +28,5 @@ kvm_handle_papr_hcall(void) "handle PAPR hypercall" kvm_handle_epr(void) "handle epr" kvm_handle_watchdog_expiry(void) "handle watchdog expiry" kvm_handle_debug_exception(void) "handle debug exception" +kvm_handle_nmi_exception(void) "handle NMI exception" +
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 3/6] target/ppc: Handle NMI guest exit
Quoted 37 lines · David Gibson
Quoted 8 lines · Aravinda Prasad
Memory error such as bit flips that cannot be corrected by hardware are passed on to the kernel for handling. If the memory address in error belongs to guest then the guest kernel is responsible for taking suitable action. Patch [1] enhances KVM to exit guest with exit reason set to
KVM_EXIT_NMIin such cases. This patch handlesKVM_EXIT_NMIexit.Quoted 4 lines
[1] https://www.spinics.net/lists/kvm-ppc/msg12637.html
(e20bbd3dand related commits)Signed-off-by Aravinda Prasad <[email protected]>LGTM, apart from one detail noted below.
Quoted 21 lines
--- hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_events.c | 22 ++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++++ include/hw/ppc/spapr.h | 6 ++++++ target/ppc/kvm.c | 16 ++++++++++++++++ target/ppc/kvm_ppc.h | 2 ++ target/ppc/trace-events | 2 ++ 7 files changed, 56 insertions(+)hw/ppc/spapr.c +1
-0@@ -1806,6 +1806,7 @@ static void spapr_machine_reset(void) spapr->cas_reboot = false; + spapr->mc_status =-1 ; spapr->guest_machine_check_addr =-1 ;
Quoted 11 lines
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_machine_check = { · line 2110
Quoted 6 lines
hw/ppc/spapr.c +1
-0/* Signal all vCPUs waiting on this condition */ @@ -2106,6 +2107,7 @@ static const VMStateDescription vmstate_spapr_machine_check = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_INT32 (mc_status, SpaprMachineState),So, technically this is a breaking change to the migration stream. If this is applied immediately after the earlier patch introducing the subsection it would be ok in practice, but it would still be preferable to make all the migration stream changes together.
Do you mean that all .fields entries to vmstate_spapr_machine_check should be in a single patch?
Because this patch introduced the variable mc_status, I added it to vmstate_spapr_machine_check.
Regards,
Aravinda
Quoted 144 lines
Quoted 143 lines
hw/ppc/spapr.c +1
-0VMSTATE_END_OF_LIST () }, };@@ -3085,6 +3087,7 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + spapr->mc_status =-1 ;qemu_cond_init (&spapr->mc_delivery_cond); }hw/ppc/spapr_events.c +22
-0@@ -620,6 +620,28 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +while (spapr->mc_status !=-1 ) { +/* +* Check whether the same CPU got machine check error +* while still handling the mc error (i.e., before +* that CPU called "ibm,nmi-interlock" +*/ +if (spapr->mc_status == cpu->vcpu_id) { +qemu_system_guest_panicked (NULL ); + } +qemu_cond_wait_iothread (&spapr->mc_delivery_cond); +/* Meanwhile if the system is reset, then just return */ +if (spapr->guest_machine_check_addr ==-1 ) { +return ; + } + } + spapr->mc_status = cpu->vcpu_id; +} + static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args,hw/ppc/spapr_rtas.c +5
-0@@ -375,6 +375,11 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu,/* NMI register not called */ rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); }else { +/* +* vCPU issuing "ibm,nmi-interlock" is done with NMI handling, +* hence unset mc_status. +*/ + spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +6
-0@@ -189,6 +189,11 @@ struct SpaprMachineState {/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ target_ulong guest_machine_check_addr; +/* +* mc_status is set to -1 if mc is not in progress, else is set to the CPU +* handling the mc. +*/ +int mc_status;QemuCond mc_delivery_cond;/*< public >*/ @@ -792,6 +797,7 @@ void spapr_clear_pending_events(SpaprMachineState *spapr);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1); +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);target/ppc/kvm.c +16
-0@@ -1759,6 +1759,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =0 ;break ; +case KVM_EXIT_NMI : +trace_kvm_handle_nmi_exception (); + ret =kvm_handle_nmi (cpu, run); +break ; +default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason); ret =-1 ;@@ -2837,6 +2842,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)return data &0xffff ; } +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run) +{ +bool recovered = run->flags &KVM_RUN_PPC_NMI_DISP_FULLY_RECOV ; + +cpu_synchronize_state (CPU (cpu)); + +spapr_mce_req_event (cpu, recovered); + +return 0 ; +} +int kvmppc_enable_hwrng (void ) {if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) {target/ppc/kvm_ppc.h +2
-0@@ -80,6 +80,8 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void);void kvm_check_mmu (PowerPCCPU *cpu,Error **errp);void kvmppc_set_reg_ppc_online (PowerPCCPU *cpu,unsigned int online); +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run); +#else static inline uint32_t kvmppc_get_tbfreq (void )target/ppc/trace-events +2
-0@@ -28,3 +28,5 @@ kvm_handle_papr_hcall(void) "handle PAPR hypercall" kvm_handle_epr(void) "handle epr" kvm_handle_watchdog_expiry(void) "handle watchdog expiry" kvm_handle_debug_exception(void) "handle debug exception" +kvm_handle_nmi_exception(void) "handle NMI exception" +
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 3/6] target/ppc: Handle NMI guest exit
On Wed, Apr 24, 2019 at 10:20:42AM +0530, Aravinda Prasad wrote:
65;5601;1c>
Quoted 51 lines · David Gibson
Quoted 37 lines · Aravinda Prasad
Quoted 8 lines
Memory error such as bit flips that cannot be corrected by hardware are passed on to the kernel for handling. If the memory address in error belongs to guest then the guest kernel is responsible for taking suitable action. Patch [1] enhances KVM to exit guest with exit reason set to
KVM_EXIT_NMIin such cases. This patch handlesKVM_EXIT_NMIexit.Quoted 4 lines
[1] https://www.spinics.net/lists/kvm-ppc/msg12637.html
(e20bbd3dand related commits)Signed-off-by Aravinda Prasad <[email protected]>LGTM, apart from one detail noted below.
Quoted 21 lines
--- hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_events.c | 22 ++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++++ include/hw/ppc/spapr.h | 6 ++++++ target/ppc/kvm.c | 16 ++++++++++++++++ target/ppc/kvm_ppc.h | 2 ++ target/ppc/trace-events | 2 ++ 7 files changed, 56 insertions(+)hw/ppc/spapr.c +1
-0@@ -1806,6 +1806,7 @@ static void spapr_machine_reset(void) spapr->cas_reboot = false; + spapr->mc_status =-1 ; spapr->guest_machine_check_addr =-1 ;Quoted 11 lines
hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_machine_check = { · line 2110
Quoted 6 lines
hw/ppc/spapr.c +1
-0/* Signal all vCPUs waiting on this condition */ @@ -2106,6 +2107,7 @@ static const VMStateDescription vmstate_spapr_machine_check = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_INT32 (mc_status, SpaprMachineState),So, technically this is a breaking change to the migration stream. If this is applied immediately after the earlier patch introducing the subsection it would be ok in practice, but it would still be preferable to make all the migration stream changes together.
Quoted 2 lines
Do you mean that all .fields entries to
vmstate_spapr_machine_checkshould be in a single patch?
Yes, that's preferable. If necessary you can move the migration support out into its own patch which goes after the implementation of the underlying state.
Quoted 152 lines
Because this patch introduced the variable
mc_status, I added it tovmstate_spapr_machine_check.Regards,
AravindaQuoted 144 lines
Quoted 143 lines
hw/ppc/spapr.c +1
-0VMSTATE_END_OF_LIST () }, };@@ -3085,6 +3087,7 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + spapr->mc_status =-1 ;qemu_cond_init (&spapr->mc_delivery_cond); }hw/ppc/spapr_events.c +22
-0@@ -620,6 +620,28 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +while (spapr->mc_status !=-1 ) { +/* +* Check whether the same CPU got machine check error +* while still handling the mc error (i.e., before +* that CPU called "ibm,nmi-interlock" +*/ +if (spapr->mc_status == cpu->vcpu_id) { +qemu_system_guest_panicked (NULL ); + } +qemu_cond_wait_iothread (&spapr->mc_delivery_cond); +/* Meanwhile if the system is reset, then just return */ +if (spapr->guest_machine_check_addr ==-1 ) { +return ; + } + } + spapr->mc_status = cpu->vcpu_id; +} + static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args,hw/ppc/spapr_rtas.c +5
-0@@ -375,6 +375,11 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu,/* NMI register not called */ rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); }else { +/* +* vCPU issuing "ibm,nmi-interlock" is done with NMI handling, +* hence unset mc_status. +*/ + spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +6
-0@@ -189,6 +189,11 @@ struct SpaprMachineState {/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ target_ulong guest_machine_check_addr; +/* +* mc_status is set to -1 if mc is not in progress, else is set to the CPU +* handling the mc. +*/ +int mc_status;QemuCond mc_delivery_cond;/*< public >*/ @@ -792,6 +797,7 @@ void spapr_clear_pending_events(SpaprMachineState *spapr);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1); +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);target/ppc/kvm.c +16
-0@@ -1759,6 +1759,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =0 ;break ; +case KVM_EXIT_NMI : +trace_kvm_handle_nmi_exception (); + ret =kvm_handle_nmi (cpu, run); +break ; +default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason); ret =-1 ;@@ -2837,6 +2842,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)return data &0xffff ; } +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run) +{ +bool recovered = run->flags &KVM_RUN_PPC_NMI_DISP_FULLY_RECOV ; + +cpu_synchronize_state (CPU (cpu)); + +spapr_mce_req_event (cpu, recovered); + +return 0 ; +} +int kvmppc_enable_hwrng (void ) {if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) {target/ppc/kvm_ppc.h +2
-0@@ -80,6 +80,8 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void);void kvm_check_mmu (PowerPCCPU *cpu,Error **errp);void kvmppc_set_reg_ppc_online (PowerPCCPU *cpu,unsigned int online); +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run); +#else static inline uint32_t kvmppc_get_tbfreq (void )target/ppc/trace-events +2
-0@@ -28,3 +28,5 @@ kvm_handle_papr_hcall(void) "handle PAPR hypercall" kvm_handle_epr(void) "handle epr" kvm_handle_watchdog_expiry(void) "handle watchdog expiry" kvm_handle_debug_exception(void) "handle debug exception" +kvm_handle_nmi_exception(void) "handle NMI exception" +
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 3/6] target/ppc: Handle NMI guest exit
Quoted 53 lines · David Gibson
On Wed, Apr 24, 2019 at 10:20:42AM +0530, Aravinda Prasad wrote:
65;5601;1c>Quoted 51 lines · David Gibson
Quoted 48 lines · Aravinda Prasad
Quoted 8 lines
Memory error such as bit flips that cannot be corrected by hardware are passed on to the kernel for handling. If the memory address in error belongs to guest then the guest kernel is responsible for taking suitable action. Patch [1] enhances KVM to exit guest with exit reason set to
KVM_EXIT_NMIin such cases. This patch handlesKVM_EXIT_NMIexit.Quoted 4 lines
[1] https://www.spinics.net/lists/kvm-ppc/msg12637.html
(e20bbd3dand related commits)Signed-off-by Aravinda Prasad <[email protected]>LGTM, apart from one detail noted below.
Quoted 23 lines
--- hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_events.c | 22 ++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++++ include/hw/ppc/spapr.h | 6 ++++++ target/ppc/kvm.c | 16 ++++++++++++++++ target/ppc/kvm_ppc.h | 2 ++ target/ppc/trace-events | 2 ++ 7 files changed, 56 insertions(+)hw/ppc/spapr.c +1
-0@@ -1806,6 +1806,7 @@ static void spapr_machine_reset(void) spapr->cas_reboot = false; + spapr->mc_status =-1 ; spapr->guest_machine_check_addr =-1 ;/* Signal all vCPUs waiting on this condition */ hw/ppc/spapr.c static const VMStateDescription vmstate_spapr_machine_check = { · line 2110
Quoted 4 lines
hw/ppc/spapr.c +1
-0@@ -2106,6 +2107,7 @@ static const VMStateDescription vmstate_spapr_machine_check = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_INT32 (mc_status, SpaprMachineState),So, technically this is a breaking change to the migration stream. If this is applied immediately after the earlier patch introducing the subsection it would be ok in practice, but it would still be preferable to make all the migration stream changes together.
Quoted 6 lines
Quoted 2 lines
Do you mean that all .fields entries to
vmstate_spapr_machine_checkshould be in a single patch?Yes, that's preferable. If necessary you can move the migration support out into its own patch which goes after the implementation of the underlying state.
Sure..
Quoted 154 lines
Quoted 153 lines
Because this patch introduced the variable
mc_status, I added it tovmstate_spapr_machine_check.Regards,
AravindaQuoted 144 lines
Quoted 143 lines
hw/ppc/spapr.c +1
-0VMSTATE_END_OF_LIST () }, };@@ -3085,6 +3087,7 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + spapr->mc_status =-1 ;qemu_cond_init (&spapr->mc_delivery_cond); }hw/ppc/spapr_events.c +22
-0@@ -620,6 +620,28 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +while (spapr->mc_status !=-1 ) { +/* +* Check whether the same CPU got machine check error +* while still handling the mc error (i.e., before +* that CPU called "ibm,nmi-interlock" +*/ +if (spapr->mc_status == cpu->vcpu_id) { +qemu_system_guest_panicked (NULL ); + } +qemu_cond_wait_iothread (&spapr->mc_delivery_cond); +/* Meanwhile if the system is reset, then just return */ +if (spapr->guest_machine_check_addr ==-1 ) { +return ; + } + } + spapr->mc_status = cpu->vcpu_id; +} + static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args,hw/ppc/spapr_rtas.c +5
-0@@ -375,6 +375,11 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu,/* NMI register not called */ rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); }else { +/* +* vCPU issuing "ibm,nmi-interlock" is done with NMI handling, +* hence unset mc_status. +*/ + spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +6
-0@@ -189,6 +189,11 @@ struct SpaprMachineState {/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ target_ulong guest_machine_check_addr; +/* +* mc_status is set to -1 if mc is not in progress, else is set to the CPU +* handling the mc. +*/ +int mc_status;QemuCond mc_delivery_cond;/*< public >*/ @@ -792,6 +797,7 @@ void spapr_clear_pending_events(SpaprMachineState *spapr);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1); +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);target/ppc/kvm.c +16
-0@@ -1759,6 +1759,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =0 ;break ; +case KVM_EXIT_NMI : +trace_kvm_handle_nmi_exception (); + ret =kvm_handle_nmi (cpu, run); +break ; +default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason); ret =-1 ;@@ -2837,6 +2842,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)return data &0xffff ; } +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run) +{ +bool recovered = run->flags &KVM_RUN_PPC_NMI_DISP_FULLY_RECOV ; + +cpu_synchronize_state (CPU (cpu)); + +spapr_mce_req_event (cpu, recovered); + +return 0 ; +} +int kvmppc_enable_hwrng (void ) {if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) {target/ppc/kvm_ppc.h +2
-0@@ -80,6 +80,8 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void);void kvm_check_mmu (PowerPCCPU *cpu,Error **errp);void kvmppc_set_reg_ppc_online (PowerPCCPU *cpu,unsigned int online); +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run); +#else static inline uint32_t kvmppc_get_tbfreq (void )target/ppc/trace-events +2
-0@@ -28,3 +28,5 @@ kvm_handle_papr_hcall(void) "handle PAPR hypercall" kvm_handle_epr(void) "handle epr" kvm_handle_watchdog_expiry(void) "handle watchdog expiry" kvm_handle_debug_exception(void) "handle debug exception" +kvm_handle_nmi_exception(void) "handle NMI exception" +
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 3/6] target/ppc: Handle NMI guest exit
In reply to Aravinda PrasadQuoted 43 lines · On Mon, 22 Apr 2019 12:33:16 +0530 Aravinda Prasad…
Memory error such as bit flips that cannot be corrected by hardware are passed on to the kernel for handling. If the memory address in error belongs to guest then the guest kernel is responsible for taking suitable action. Patch [1] enhances KVM to exit guest with exit reason set to
KVM_EXIT_NMIin such cases. This patch handlesKVM_EXIT_NMIexit.[1] https://www.spinics.net/lists/kvm-ppc/msg12637.html
(e20bbd3dand related commits)Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_events.c | 22 ++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++++ include/hw/ppc/spapr.h | 6 ++++++ target/ppc/kvm.c | 16 ++++++++++++++++ target/ppc/kvm_ppc.h | 2 ++ target/ppc/trace-events | 2 ++ 7 files changed, 56 insertions(+)hw/ppc/spapr.c +2
-0@@ -1806,6 +1806,7 @@ static void spapr_machine_reset(void) spapr->cas_reboot = false; + spapr->mc_status =-1 ; spapr->guest_machine_check_addr =-1 ;/* Signal all vCPUs waiting on this condition */ @@ -2106,6 +2107,7 @@ static const VMStateDescription vmstate_spapr_machine_check = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_INT32 (mc_status, SpaprMachineState),VMSTATE_END_OF_LIST () }, };
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 3090
Quoted 4 lines
hw/ppc/spapr.c +1
-0@@ -3085,6 +3087,7 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); } + spapr->mc_status =-1 ;
Since this is done at reset, do we need it here ?
Quoted 10 lines
hw/ppc/spapr.c +0
-0qemu_cond_init (&spapr->mc_delivery_cond); }hw/ppc/spapr_events.c +0
-0@@ -620,6 +620,28 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); }
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 631
Quoted 10 lines
hw/ppc/spapr_events.c +9
-0+void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +while (spapr->mc_status !=-1 ) { +/* +* Check whether the same CPU got machine check error +* while still handling the mc error (i.e., before +* that CPU called "ibm,nmi-interlock"
Missing )
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 634
Quoted 3 lines
hw/ppc/spapr_events.c +3
-0+*/ +if (spapr->mc_status == cpu->vcpu_id) { +qemu_system_guest_panicked (NULL );
If we don't also return, is there a chance we end up stuck in qemu_cond_wait_iothread() below ?
Quoted 105 lines
hw/ppc/spapr_events.c +10
-0+ } +qemu_cond_wait_iothread (&spapr->mc_delivery_cond); +/* Meanwhile if the system is reset, then just return */ +if (spapr->guest_machine_check_addr ==-1 ) { +return ; + } + } + spapr->mc_status = cpu->vcpu_id; +} + static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args,hw/ppc/spapr_rtas.c +5
-0@@ -375,6 +375,11 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu,/* NMI register not called */ rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); }else { +/* +* vCPU issuing "ibm,nmi-interlock" is done with NMI handling, +* hence unset mc_status. +*/ + spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +6
-0@@ -189,6 +189,11 @@ struct SpaprMachineState {/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ target_ulong guest_machine_check_addr; +/* +* mc_status is set to -1 if mc is not in progress, else is set to the CPU +* handling the mc. +*/ +int mc_status;QemuCond mc_delivery_cond;/*< public >*/ @@ -792,6 +797,7 @@ void spapr_clear_pending_events(SpaprMachineState *spapr);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1); +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);target/ppc/kvm.c +16
-0@@ -1759,6 +1759,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =0 ;break ; +case KVM_EXIT_NMI : +trace_kvm_handle_nmi_exception (); + ret =kvm_handle_nmi (cpu, run); +break ; +default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason); ret =-1 ;@@ -2837,6 +2842,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)return data &0xffff ; } +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run) +{ +bool recovered = run->flags &KVM_RUN_PPC_NMI_DISP_FULLY_RECOV ; + +cpu_synchronize_state (CPU (cpu)); + +spapr_mce_req_event (cpu, recovered); + +return 0 ; +} +int kvmppc_enable_hwrng (void ) {if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) {target/ppc/kvm_ppc.h +2
-0@@ -80,6 +80,8 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void);void kvm_check_mmu (PowerPCCPU *cpu,Error **errp);void kvmppc_set_reg_ppc_online (PowerPCCPU *cpu,unsigned int online); +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run); +#else static inline uint32_t kvmppc_get_tbfreq (void )target/ppc/trace-events +0
-0
target/ppc/trace-events kvm_handle_papr_hcall(void) "handle PAPR hypercall" · line 32
Quoted 5 lines
target/ppc/trace-events +2
-0@@ -28,3 +28,5 @@ kvm_handle_papr_hcall(void) "handle PAPR hypercall" kvm_handle_epr(void) "handle epr" kvm_handle_watchdog_expiry(void) "handle watchdog expiry" kvm_handle_debug_exception(void) "handle debug exception" +kvm_handle_nmi_exception(void) "handle NMI exception" +
new blank line at EOF.
Quoted 2 lines
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 3/6] target/ppc: Handle NMI guest exit
Quoted 49 lines · Greg Kurz
Quoted 46 lines · On Mon, 22 Apr 2019 12:33:16 +0530 Aravinda Prasad…
Memory error such as bit flips that cannot be corrected by hardware are passed on to the kernel for handling. If the memory address in error belongs to guest then the guest kernel is responsible for taking suitable action. Patch [1] enhances KVM to exit guest with exit reason set to
KVM_EXIT_NMIin such cases. This patch handlesKVM_EXIT_NMIexit.[1] https://www.spinics.net/lists/kvm-ppc/msg12637.html
(e20bbd3dand related commits)Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_events.c | 22 ++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++++ include/hw/ppc/spapr.h | 6 ++++++ target/ppc/kvm.c | 16 ++++++++++++++++ target/ppc/kvm_ppc.h | 2 ++ target/ppc/trace-events | 2 ++ 7 files changed, 56 insertions(+)hw/ppc/spapr.c +2
-0@@ -1806,6 +1806,7 @@ static void spapr_machine_reset(void) spapr->cas_reboot = false; + spapr->mc_status =-1 ; spapr->guest_machine_check_addr =-1 ;/* Signal all vCPUs waiting on this condition */ @@ -2106,6 +2107,7 @@ static const VMStateDescription vmstate_spapr_machine_check = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_INT32 (mc_status, SpaprMachineState),VMSTATE_END_OF_LIST () }, };@@ -3085,6 +3087,7 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); }
Quoted 3 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 3090
Quoted 1 line
hw/ppc/spapr.c +1
-0+ spapr->mc_status =-1 ;Since this is done at reset, do we need it here ?
Yes, because we need to initialize this on a fresh boot. I need to check, but if spapr_machine_reset() is called every time a system boots then we don't need qemu_cond_init() here as well.
Quoted 12 lines
Quoted 12 lines
hw/ppc/spapr.c +0
-0qemu_cond_init (&spapr->mc_delivery_cond); }hw/ppc/spapr_events.c +0
-0@@ -620,6 +620,28 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); }
Quoted 11 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 631
Quoted 9 lines
hw/ppc/spapr_events.c +9
-0+void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +while (spapr->mc_status !=-1 ) { +/* +* Check whether the same CPU got machine check error +* while still handling the mc error (i.e., before +* that CPU called "ibm,nmi-interlock" Missing )
ok.
Quoted 7 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 634
Quoted 4 lines
hw/ppc/spapr_events.c +3
-0+*/ +if (spapr->mc_status == cpu->vcpu_id) { +qemu_system_guest_panicked (NULL );If we don't also return, is there a chance we end up stuck in
qemu_cond_wait_iothread()below ?
I think I need to return here
Quoted 100 lines
Quoted 100 lines
hw/ppc/spapr_events.c +10
-0+ } +qemu_cond_wait_iothread (&spapr->mc_delivery_cond); +/* Meanwhile if the system is reset, then just return */ +if (spapr->guest_machine_check_addr ==-1 ) { +return ; + } + } + spapr->mc_status = cpu->vcpu_id; +} + static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args,hw/ppc/spapr_rtas.c +5
-0@@ -375,6 +375,11 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu,/* NMI register not called */ rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); }else { +/* +* vCPU issuing "ibm,nmi-interlock" is done with NMI handling, +* hence unset mc_status. +*/ + spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +6
-0@@ -189,6 +189,11 @@ struct SpaprMachineState {/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ target_ulong guest_machine_check_addr; +/* +* mc_status is set to -1 if mc is not in progress, else is set to the CPU +* handling the mc. +*/ +int mc_status;QemuCond mc_delivery_cond;/*< public >*/ @@ -792,6 +797,7 @@ void spapr_clear_pending_events(SpaprMachineState *spapr);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1); +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);target/ppc/kvm.c +16
-0@@ -1759,6 +1759,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =0 ;break ; +case KVM_EXIT_NMI : +trace_kvm_handle_nmi_exception (); + ret =kvm_handle_nmi (cpu, run); +break ; +default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason); ret =-1 ;@@ -2837,6 +2842,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)return data &0xffff ; } +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run) +{ +bool recovered = run->flags &KVM_RUN_PPC_NMI_DISP_FULLY_RECOV ; + +cpu_synchronize_state (CPU (cpu)); + +spapr_mce_req_event (cpu, recovered); + +return 0 ; +} +int kvmppc_enable_hwrng (void ) {if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) {target/ppc/kvm_ppc.h +2
-0@@ -80,6 +80,8 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void);void kvm_check_mmu (PowerPCCPU *cpu,Error **errp);void kvmppc_set_reg_ppc_online (PowerPCCPU *cpu,unsigned int online); +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run); +#else
Quoted 13 lines
target/ppc/trace-events kvm_handle_papr_hcall(void) "handle PAPR hypercall" · line 32
Quoted 11 lines
target/ppc/kvm_ppc.h +0
-0static inline uint32_t kvmppc_get_tbfreq (void )target/ppc/trace-events +2
-0@@ -28,3 +28,5 @@ kvm_handle_papr_hcall(void) "handle PAPR hypercall" kvm_handle_epr(void) "handle epr" kvm_handle_watchdog_expiry(void) "handle watchdog expiry" kvm_handle_debug_exception(void) "handle debug exception" +kvm_handle_nmi_exception(void) "handle NMI exception" +new blank line at EOF.
ok
Quoted 5 lines
Quoted 3 lines
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 3/6] target/ppc: Handle NMI guest exit
Quoted 52 lines · Aravinda Prasad
Quoted 49 lines · Greg Kurz
Quoted 46 lines · On Mon, 22 Apr 2019 12:33:16 +0530 Aravinda Prasad…
Memory error such as bit flips that cannot be corrected by hardware are passed on to the kernel for handling. If the memory address in error belongs to guest then the guest kernel is responsible for taking suitable action. Patch [1] enhances KVM to exit guest with exit reason set to
KVM_EXIT_NMIin such cases. This patch handlesKVM_EXIT_NMIexit.[1] https://www.spinics.net/lists/kvm-ppc/msg12637.html
(e20bbd3dand related commits)Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_events.c | 22 ++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++++ include/hw/ppc/spapr.h | 6 ++++++ target/ppc/kvm.c | 16 ++++++++++++++++ target/ppc/kvm_ppc.h | 2 ++ target/ppc/trace-events | 2 ++ 7 files changed, 56 insertions(+)hw/ppc/spapr.c +2
-0@@ -1806,6 +1806,7 @@ static void spapr_machine_reset(void) spapr->cas_reboot = false; + spapr->mc_status =-1 ; spapr->guest_machine_check_addr =-1 ;/* Signal all vCPUs waiting on this condition */ @@ -2106,6 +2107,7 @@ static const VMStateDescription vmstate_spapr_machine_check = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT64 (guest_machine_check_addr, SpaprMachineState), +VMSTATE_INT32 (mc_status, SpaprMachineState),VMSTATE_END_OF_LIST () }, };@@ -3085,6 +3087,7 @@ static void spapr_machine_init(MachineState *machine)kvmppc_spapr_enable_inkernel_multitce (); }
Quoted 6 lines
Quoted 3 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 3090
Quoted 1 line
hw/ppc/spapr.c +1
-0+ spapr->mc_status =-1 ;Since this is done at reset, do we need it here ?
Yes, because we need to initialize this on a fresh boot. I need to check, but if
spapr_machine_reset()is called every time a system boots
It is.
Quoted 161 lines
then we don't need
qemu_cond_init()here as well.Quoted 12 lines
Quoted 12 lines
hw/ppc/spapr.c +0
-0qemu_cond_init (&spapr->mc_delivery_cond); }hw/ppc/spapr_events.c +0
-0@@ -620,6 +620,28 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); }Quoted 11 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 631
Quoted 9 lines
hw/ppc/spapr_events.c +9
-0+void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +while (spapr->mc_status !=-1 ) { +/* +* Check whether the same CPU got machine check error +* while still handling the mc error (i.e., before +* that CPU called "ibm,nmi-interlock" Missing )
ok.
Quoted 7 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 634
Quoted 4 lines
hw/ppc/spapr_events.c +3
-0+*/ +if (spapr->mc_status == cpu->vcpu_id) { +qemu_system_guest_panicked (NULL );If we don't also return, is there a chance we end up stuck in
qemu_cond_wait_iothread()below ?I think I need to return here
Quoted 100 lines
Quoted 100 lines
hw/ppc/spapr_events.c +10
-0+ } +qemu_cond_wait_iothread (&spapr->mc_delivery_cond); +/* Meanwhile if the system is reset, then just return */ +if (spapr->guest_machine_check_addr ==-1 ) { +return ; + } + } + spapr->mc_status = cpu->vcpu_id; +} + static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args,hw/ppc/spapr_rtas.c +5
-0@@ -375,6 +375,11 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu,/* NMI register not called */ rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); }else { +/* +* vCPU issuing "ibm,nmi-interlock" is done with NMI handling, +* hence unset mc_status. +*/ + spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +6
-0@@ -189,6 +189,11 @@ struct SpaprMachineState {/* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */ target_ulong guest_machine_check_addr; +/* +* mc_status is set to -1 if mc is not in progress, else is set to the CPU +* handling the mc. +*/ +int mc_status;QemuCond mc_delivery_cond;/*< public >*/ @@ -792,6 +797,7 @@ void spapr_clear_pending_events(SpaprMachineState *spapr);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1); +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);target/ppc/kvm.c +16
-0@@ -1759,6 +1759,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =0 ;break ; +case KVM_EXIT_NMI : +trace_kvm_handle_nmi_exception (); + ret =kvm_handle_nmi (cpu, run); +break ; +default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason); ret =-1 ;@@ -2837,6 +2842,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)return data &0xffff ; } +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run) +{ +bool recovered = run->flags &KVM_RUN_PPC_NMI_DISP_FULLY_RECOV ; + +cpu_synchronize_state (CPU (cpu)); + +spapr_mce_req_event (cpu, recovered); + +return 0 ; +} +int kvmppc_enable_hwrng (void ) {if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) {target/ppc/kvm_ppc.h +2
-0@@ -80,6 +80,8 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void);void kvm_check_mmu (PowerPCCPU *cpu,Error **errp);void kvmppc_set_reg_ppc_online (PowerPCCPU *cpu,unsigned int online); +int kvm_handle_nmi (PowerPCCPU *cpu,struct kvm_run *run); +#else Quoted 13 lines
target/ppc/trace-events kvm_handle_papr_hcall(void) "handle PAPR hypercall" · line 32
Quoted 11 lines
target/ppc/kvm_ppc.h +0
-0static inline uint32_t kvmppc_get_tbfreq (void )target/ppc/trace-events +2
-0@@ -28,3 +28,5 @@ kvm_handle_papr_hcall(void) "handle PAPR hypercall" kvm_handle_epr(void) "handle epr" kvm_handle_watchdog_expiry(void) "handle watchdog expiry" kvm_handle_debug_exception(void) "handle debug exception" +kvm_handle_nmi_exception(void) "handle NMI exception" +new blank line at EOF.
ok
Quoted 5 lines
Quoted 3 lines
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
PATCH v8 4/6 target/ppc: Build rtas error log upon an MCE
In reply to Aravinda PrasadUpon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the rtas_addr and then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.
--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)
hw/ppc/spapr.c +4 -0
@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); + spapr->rtas_blob =g_malloc (spapr->rtas_size);if (load_image_size (filename, spapr->rtas_blob, spapr->rtas_size) <0 ) {error_report ("Could not load LPAR rtas '%s'" , filename);
hw/ppc/spapr_events.c +245 -0
263 lines not on this page · raw message
include/hw/ppc/spapr.h +4 -0
@@ -661,6 +661,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2#define DIAGNOSTICS_RUN_MODE_PERIODIC 3 +/* Offset from rtas-base where error log is placed */ +#define RTAS_ERRLOG_OFFSET 0x25 +static inline uint64_t ppc64_phys_to_real (uint64_t addr) {return addr & ~0xF000000000000000ULL ;
@@ -798,6 +801,7 @@ int spapr_max_server_number(SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1);void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered); +ssize_t spapr_get_rtas_size (ssize_t old_rtas_sizea);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);
Re: [Qemu-devel] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 805
Quoted 9 lines · Aravinda Prasad
hw/ppc/spapr_events.c +9
-0+/* +* Properly set bits in MSR before we invoke the handler. +* SRR0/1, DAR and DSISR are properly set by KVM +*/ +if (!(*pcc->interrupts_big_endian)(cpu)) { + msr |= (1ULL <<MSR_LE ); + } + +if (env->msr && (1ULL <<MSR_SF )) {
Don't you mean & instead of &&?
Quoted 2 lines
(quoted diff) +2
-0+ msr |= (1ULL << MSR_SF); + }
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 12 lines · Fabiano Rosas
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 805
Quoted 9 lines · Aravinda Prasad
hw/ppc/spapr_events.c +9
-0+/* +* Properly set bits in MSR before we invoke the handler. +* SRR0/1, DAR and DSISR are properly set by KVM +*/ +if (!(*pcc->interrupts_big_endian)(cpu)) { + msr |= (1ULL <<MSR_LE ); + } + +if (env->msr && (1ULL <<MSR_SF )) {
Quoted 1 line
Don't you mean & instead of &&?
Ah.. yes.. Thanks for pointing out.
Quoted 5 lines
Quoted 3 lines
(quoted diff) +2
-0+ msr |= (1ULL << MSR_SF); + }
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
In reply to Aravinda PrasadQuoted 274 lines · Aravinda Prasad
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); + spapr->rtas_blob =g_malloc (spapr->rtas_size);if (load_image_size (filename, spapr->rtas_blob, spapr->rtas_size) <0 ) {error_report ("Could not load LPAR rtas '%s'" , filename);hw/ppc/spapr_events.c +224
-0@@ -212,6 +212,106 @@ struct hp_extended_log {struct rtas_event_log_v6_hp hp; }QEMU_PACKED ; +struct rtas_event_log_v6_mc { +#define RTAS_LOG_V6_SECTION_ID_MC 0x4D43/* MC */ +struct rtas_event_log_v6_section_header hdr; +uint32_t fru_id; +uint32_t proc_id; +uint8_t error_type; +#define RTAS_LOG_V6_MC_TYPE_UE 0 +#define RTAS_LOG_V6_MC_TYPE_SLB 1 +#define RTAS_LOG_V6_MC_TYPE_ERAT 2 +#define RTAS_LOG_V6_MC_TYPE_TLB 4 +#define RTAS_LOG_V6_MC_TYPE_D_CACHE 5 +#define RTAS_LOG_V6_MC_TYPE_I_CACHE 7 +uint8_t sub_err_type; +#define RTAS_LOG_V6_MC_UE_INDETERMINATE 0 +#define RTAS_LOG_V6_MC_UE_IFETCH 1 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH 2 +#define RTAS_LOG_V6_MC_UE_LOAD_STORE 3 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE 4 +#define RTAS_LOG_V6_MC_SLB_PARITY 0 +#define RTAS_LOG_V6_MC_SLB_MULTIHIT 1 +#define RTAS_LOG_V6_MC_SLB_INDETERMINATE 2 +#define RTAS_LOG_V6_MC_ERAT_PARITY 1 +#define RTAS_LOG_V6_MC_ERAT_MULTIHIT 2 +#define RTAS_LOG_V6_MC_ERAT_INDETERMINATE 3 +#define RTAS_LOG_V6_MC_TLB_PARITY 1 +#define RTAS_LOG_V6_MC_TLB_MULTIHIT 2 +#define RTAS_LOG_V6_MC_TLB_INDETERMINATE 3 +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint64_t logical_address; +}QEMU_PACKED ; + +struct mc_extended_log { +struct rtas_event_log_v6 v6hdr; +struct rtas_event_log_v6_mc mc; +}QEMU_PACKED ; + +struct MC_ierror_table { +unsigned long srr1_mask; +unsigned long srr1_value; +bool nip_valid;/* nip is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_ierror_table mc_ierror_table[] = { +{0x00000000081c0000 ,0x0000000000040000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000080000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x00000000000c0000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000100000 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000140000 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000180000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 ,0 ,0 ,0 ,0 ,0 } }; + +struct MC_derror_table { +unsigned long dsisr_value; +bool dar_valid;/* dar is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_derror_table mc_derror_table[] = { +{0x00008000 , false, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00004000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000800 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000400 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000080 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT ,/* Before PARITY */ +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000100 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 , false,0 ,0 ,0 ,0 } }; + +#define SRR1_MC_LOADSTORE (srr1) ((srr1) & PPC_BIT(42)) + typedef enum EventClass { EVENT_CLASS_INTERNAL_ERRORS = 0, EVENT_CLASS_EPOW = 1,@@ -620,6 +720,147 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +ssize_t spapr_get_rtas_size (ssize_t old_rtas_size) +{ +g_assert (old_rtas_size <RTAS_ERRLOG_OFFSET ); +return RTAS_ERROR_LOG_MAX ; +} + +static uint32_t spapr_mce_get_elog_type (PowerPCCPU *cpu,bool recovered, +struct mc_extended_log *ext_elog) +{ +int i; +CPUPPCState *env = &cpu->env; +uint32_t summary; +uint64_t dsisr = env->spr[SPR_DSISR ]; + + summary =RTAS_LOG_VERSION_6 |RTAS_LOG_OPTIONAL_PART_PRESENT ; +if (recovered) { + summary |=RTAS_LOG_DISPOSITION_FULLY_RECOVERED ; + }else { + summary |=RTAS_LOG_DISPOSITION_NOT_RECOVERED ; + } + +if (SRR1_MC_LOADSTORE (env->spr[SPR_SRR1 ])) { +for (i =0 ; mc_derror_table[i].dsisr_value; i++) { +if (!(dsisr & mc_derror_table[i].dsisr_value)) { +continue ; + } + + ext_elog->mc.error_type = mc_derror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_derror_table[i].error_subtype; +if (mc_derror_table[i].dar_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->spr[SPR_DAR ]); + } + + summary |= mc_derror_table[i].initiator + | mc_derror_table[i].severity; + +return summary; + } + }else { +for (i =0 ; mc_ierror_table[i].srr1_mask; i++) { +if ((env->spr[SPR_SRR1 ] & mc_ierror_table[i].srr1_mask) != + mc_ierror_table[i].srr1_value) { +continue ; + } + + ext_elog->mc.error_type = mc_ierror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_ierror_table[i].error_subtype; +if (mc_ierror_table[i].nip_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->nip); + } + + summary |= mc_ierror_table[i].initiator + | mc_ierror_table[i].severity; + +return summary; + } + } + + summary |=RTAS_LOG_INITIATOR_CPU ; +return summary; +} + +static void spapr_mce_dispatch_elog (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +CPUState *cs =CPU (cpu); +uint64_t rtas_addr; +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +target_ulong r3, msr =0 ; +struct rtas_error_log log; +struct mc_extended_log *ext_elog; +uint32_t summary; + +/* +* Properly set bits in MSR before we invoke the handler. +* SRR0/1, DAR and DSISR are properly set by KVM +*/ +if (!(*pcc->interrupts_big_endian)(cpu)) { + msr |= (1ULL <<MSR_LE ); + } + +if (env->msr && (1ULL <<MSR_SF )) { + msr |= (1ULL <<MSR_SF ); + } + + msr |= (1ULL <<MSR_ME ); + +if (spapr->guest_machine_check_addr ==-1 ) { +/* +* This implies that we have hit a machine check between system +* reset and "ibm,nmi-register". Fall back to the old machine +* check behavior in such cases. +*/ + env->spr[SPR_SRR0 ] = env->nip; + env->spr[SPR_SRR1 ] = env->msr; + env->msr = msr; + env->nip =0x200 ; +return ; + } + + ext_elog =g_malloc0 (sizeof (struct mc_extended_log )); + summary =spapr_mce_get_elog_type (cpu, recovered, ext_elog); + + log.summary =cpu_to_be32 (summary); + log.extended_length =cpu_to_be32 (sizeof (struct mc_extended_log )); + +/* r3 should be in BE always */ + r3 =cpu_to_be64 (env->gpr[3 ]); + env->msr = msr; + +spapr_init_v6hdr (&ext_elog->v6hdr); + ext_elog->mc.hdr.section_id =cpu_to_be16 (RTAS_LOG_V6_SECTION_ID_MC ); + ext_elog->mc.hdr.section_length = +cpu_to_be16 (sizeof (struct rtas_event_log_v6_mc )); + ext_elog->mc.hdr.section_version =1 ; + +/* get rtas addr from fdt */ + rtas_addr =spapr_get_rtas_addr (); +if (!rtas_addr) { +/* Unable to fetch rtas_addr. Hence reset the guest */ +ppc_cpu_do_system_reset (cs); + } +
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 856
Quoted 10 lines
hw/ppc/spapr_events.c +10
-0+cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET , &r3,sizeof (r3)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3), + &log,sizeof (log)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3) + +sizeof (log), ext_elog, +sizeof (struct mc_extended_log )); + +/* Save gpr[3] in the guest endian mode */ +if ((*pcc->interrupts_big_endian)(cpu)) { + env->gpr[3 ] =cpu_to_be64 (rtas_addr +RTAS_ERRLOG_OFFSET );
I don't think this is right. AIUI env->gpr[] are all stored in *host* endianness (for ease of doing arithmetic).
Quoted 26 lines
hw/ppc/spapr_events.c +11
-0+ }else { + env->gpr[3 ] =cpu_to_le64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + } + + env->nip = spapr->guest_machine_check_addr; +} +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());@@ -640,6 +881,10 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) } } spapr->mc_status = cpu->vcpu_id; + +spapr_mce_dispatch_elog (cpu, recovered); + +return ; } static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr,include/hw/ppc/spapr.h +0
-0
include/hw/ppc/spapr.h target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, · line 665
Quoted 5 lines
include/hw/ppc/spapr.h +2
-0@@ -661,6 +661,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2#define DIAGNOSTICS_RUN_MODE_PERIODIC 3 +/* Offset from rtas-base where error log is placed */ +#define RTAS_ERRLOG_OFFSET 0x25
Is this offset PAPR defined, or chosen here? Using an entirely unaliged (odd) address seems a very strange choice.
Quoted 13 lines
include/hw/ppc/spapr.h +2
-0+static inline uint64_t ppc64_phys_to_real (uint64_t addr) {return addr & ~0xF000000000000000ULL ;@@ -798,6 +801,7 @@ int spapr_max_server_number(SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1);void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered); +ssize_t spapr_get_rtas_size (ssize_t old_rtas_sizea);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);
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
Re: [Qemu-devel] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 280 lines · David Gibson
Quoted 279 lines · Aravinda Prasad
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); + spapr->rtas_blob =g_malloc (spapr->rtas_size);if (load_image_size (filename, spapr->rtas_blob, spapr->rtas_size) <0 ) {error_report ("Could not load LPAR rtas '%s'" , filename);hw/ppc/spapr_events.c +229
-0@@ -212,6 +212,106 @@ struct hp_extended_log {struct rtas_event_log_v6_hp hp; }QEMU_PACKED ; +struct rtas_event_log_v6_mc { +#define RTAS_LOG_V6_SECTION_ID_MC 0x4D43/* MC */ +struct rtas_event_log_v6_section_header hdr; +uint32_t fru_id; +uint32_t proc_id; +uint8_t error_type; +#define RTAS_LOG_V6_MC_TYPE_UE 0 +#define RTAS_LOG_V6_MC_TYPE_SLB 1 +#define RTAS_LOG_V6_MC_TYPE_ERAT 2 +#define RTAS_LOG_V6_MC_TYPE_TLB 4 +#define RTAS_LOG_V6_MC_TYPE_D_CACHE 5 +#define RTAS_LOG_V6_MC_TYPE_I_CACHE 7 +uint8_t sub_err_type; +#define RTAS_LOG_V6_MC_UE_INDETERMINATE 0 +#define RTAS_LOG_V6_MC_UE_IFETCH 1 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH 2 +#define RTAS_LOG_V6_MC_UE_LOAD_STORE 3 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE 4 +#define RTAS_LOG_V6_MC_SLB_PARITY 0 +#define RTAS_LOG_V6_MC_SLB_MULTIHIT 1 +#define RTAS_LOG_V6_MC_SLB_INDETERMINATE 2 +#define RTAS_LOG_V6_MC_ERAT_PARITY 1 +#define RTAS_LOG_V6_MC_ERAT_MULTIHIT 2 +#define RTAS_LOG_V6_MC_ERAT_INDETERMINATE 3 +#define RTAS_LOG_V6_MC_TLB_PARITY 1 +#define RTAS_LOG_V6_MC_TLB_MULTIHIT 2 +#define RTAS_LOG_V6_MC_TLB_INDETERMINATE 3 +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint64_t logical_address; +}QEMU_PACKED ; + +struct mc_extended_log { +struct rtas_event_log_v6 v6hdr; +struct rtas_event_log_v6_mc mc; +}QEMU_PACKED ; + +struct MC_ierror_table { +unsigned long srr1_mask; +unsigned long srr1_value; +bool nip_valid;/* nip is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_ierror_table mc_ierror_table[] = { +{0x00000000081c0000 ,0x0000000000040000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000080000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x00000000000c0000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000100000 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000140000 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000180000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 ,0 ,0 ,0 ,0 ,0 } }; + +struct MC_derror_table { +unsigned long dsisr_value; +bool dar_valid;/* dar is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_derror_table mc_derror_table[] = { +{0x00008000 , false, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00004000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000800 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000400 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000080 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT ,/* Before PARITY */ +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000100 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 , false,0 ,0 ,0 ,0 } }; + +#define SRR1_MC_LOADSTORE (srr1) ((srr1) & PPC_BIT(42)) + typedef enum EventClass { EVENT_CLASS_INTERNAL_ERRORS = 0, EVENT_CLASS_EPOW = 1,@@ -620,6 +720,147 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +ssize_t spapr_get_rtas_size (ssize_t old_rtas_size) +{ +g_assert (old_rtas_size <RTAS_ERRLOG_OFFSET ); +return RTAS_ERROR_LOG_MAX ; +} + +static uint32_t spapr_mce_get_elog_type (PowerPCCPU *cpu,bool recovered, +struct mc_extended_log *ext_elog) +{ +int i; +CPUPPCState *env = &cpu->env; +uint32_t summary; +uint64_t dsisr = env->spr[SPR_DSISR ]; + + summary =RTAS_LOG_VERSION_6 |RTAS_LOG_OPTIONAL_PART_PRESENT ; +if (recovered) { + summary |=RTAS_LOG_DISPOSITION_FULLY_RECOVERED ; + }else { + summary |=RTAS_LOG_DISPOSITION_NOT_RECOVERED ; + } + +if (SRR1_MC_LOADSTORE (env->spr[SPR_SRR1 ])) { +for (i =0 ; mc_derror_table[i].dsisr_value; i++) { +if (!(dsisr & mc_derror_table[i].dsisr_value)) { +continue ; + } + + ext_elog->mc.error_type = mc_derror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_derror_table[i].error_subtype; +if (mc_derror_table[i].dar_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->spr[SPR_DAR ]); + } + + summary |= mc_derror_table[i].initiator + | mc_derror_table[i].severity; + +return summary; + } + }else { +for (i =0 ; mc_ierror_table[i].srr1_mask; i++) { +if ((env->spr[SPR_SRR1 ] & mc_ierror_table[i].srr1_mask) != + mc_ierror_table[i].srr1_value) { +continue ; + } + + ext_elog->mc.error_type = mc_ierror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_ierror_table[i].error_subtype; +if (mc_ierror_table[i].nip_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->nip); + } + + summary |= mc_ierror_table[i].initiator + | mc_ierror_table[i].severity; + +return summary; + } + } + + summary |=RTAS_LOG_INITIATOR_CPU ; +return summary; +} + +static void spapr_mce_dispatch_elog (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +CPUState *cs =CPU (cpu); +uint64_t rtas_addr; +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +target_ulong r3, msr =0 ; +struct rtas_error_log log; +struct mc_extended_log *ext_elog; +uint32_t summary; + +/* +* Properly set bits in MSR before we invoke the handler. +* SRR0/1, DAR and DSISR are properly set by KVM +*/ +if (!(*pcc->interrupts_big_endian)(cpu)) { + msr |= (1ULL <<MSR_LE ); + } + +if (env->msr && (1ULL <<MSR_SF )) { + msr |= (1ULL <<MSR_SF ); + } + + msr |= (1ULL <<MSR_ME ); + +if (spapr->guest_machine_check_addr ==-1 ) { +/* +* This implies that we have hit a machine check between system +* reset and "ibm,nmi-register". Fall back to the old machine +* check behavior in such cases. +*/ + env->spr[SPR_SRR0 ] = env->nip; + env->spr[SPR_SRR1 ] = env->msr; + env->msr = msr; + env->nip =0x200 ; +return ; + } + + ext_elog =g_malloc0 (sizeof (struct mc_extended_log )); + summary =spapr_mce_get_elog_type (cpu, recovered, ext_elog); + + log.summary =cpu_to_be32 (summary); + log.extended_length =cpu_to_be32 (sizeof (struct mc_extended_log )); + +/* r3 should be in BE always */ + r3 =cpu_to_be64 (env->gpr[3 ]); + env->msr = msr; + +spapr_init_v6hdr (&ext_elog->v6hdr); + ext_elog->mc.hdr.section_id =cpu_to_be16 (RTAS_LOG_V6_SECTION_ID_MC ); + ext_elog->mc.hdr.section_length = +cpu_to_be16 (sizeof (struct rtas_event_log_v6_mc )); + ext_elog->mc.hdr.section_version =1 ; + +/* get rtas addr from fdt */ + rtas_addr =spapr_get_rtas_addr (); +if (!rtas_addr) { +/* Unable to fetch rtas_addr. Hence reset the guest */ +ppc_cpu_do_system_reset (cs); + } + +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET , &r3,sizeof (r3)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3), + &log,sizeof (log)); + cpu_physical_memory_write(rtas_addr + RTAS_ERRLOG_OFFSET + sizeof(r3) + + sizeof(log), ext_elog,
Quoted 8 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 856
Quoted 5 lines
hw/ppc/spapr_events.c +5
-0+ sizeof(struct mc_extended_log)); + +/* Save gpr[3] in the guest endian mode */ +if ((*pcc->interrupts_big_endian)(cpu)) { + env->gpr[3 ] =cpu_to_be64 (rtas_addr +RTAS_ERRLOG_OFFSET );I don't think this is right. AIUI env->gpr[] are all stored in *host* endianness (for ease of doing arithmetic).
env-gpr[3] is later used by guest to fetch the RTAS log. My guess is that we will not do an endianness change of all the gprs during a switch from host to guest (that will be costly). But let me cross check.
Quoted 30 lines
Quoted 30 lines
hw/ppc/spapr_events.c +11
-0+ }else { + env->gpr[3 ] =cpu_to_le64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + } + + env->nip = spapr->guest_machine_check_addr; +} +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());@@ -640,6 +881,10 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) } } spapr->mc_status = cpu->vcpu_id; + +spapr_mce_dispatch_elog (cpu, recovered); + +return ; } static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr,include/hw/ppc/spapr.h +0
-0@@ -661,6 +661,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2#define DIAGNOSTICS_RUN_MODE_PERIODIC 3
Quoted 5 lines
include/hw/ppc/spapr.h target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, · line 665
Quoted 2 lines
include/hw/ppc/spapr.h +2
-0+/* Offset from rtas-base where error log is placed */ +#define RTAS_ERRLOG_OFFSET 0x25Is this offset PAPR defined, or chosen here? Using an entirely unaliged (odd) address seems a very strange choice.
This is not PAPR defined. I will make it 0x30. Or do you prefer any other offset?
Regards,
Aravinda
Quoted 15 lines
Quoted 14 lines
include/hw/ppc/spapr.h +2
-0+static inline uint64_t ppc64_phys_to_real (uint64_t addr) {return addr & ~0xF000000000000000ULL ;@@ -798,6 +801,7 @@ int spapr_max_server_number(SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1);void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered); +ssize_t spapr_get_rtas_size (ssize_t old_rtas_sizea);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 292 lines · Aravinda Prasad
Quoted 280 lines · David Gibson
Quoted 279 lines · Aravinda Prasad
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); + spapr->rtas_blob =g_malloc (spapr->rtas_size);if (load_image_size (filename, spapr->rtas_blob, spapr->rtas_size) <0 ) {error_report ("Could not load LPAR rtas '%s'" , filename);hw/ppc/spapr_events.c +229
-0@@ -212,6 +212,106 @@ struct hp_extended_log {struct rtas_event_log_v6_hp hp; }QEMU_PACKED ; +struct rtas_event_log_v6_mc { +#define RTAS_LOG_V6_SECTION_ID_MC 0x4D43/* MC */ +struct rtas_event_log_v6_section_header hdr; +uint32_t fru_id; +uint32_t proc_id; +uint8_t error_type; +#define RTAS_LOG_V6_MC_TYPE_UE 0 +#define RTAS_LOG_V6_MC_TYPE_SLB 1 +#define RTAS_LOG_V6_MC_TYPE_ERAT 2 +#define RTAS_LOG_V6_MC_TYPE_TLB 4 +#define RTAS_LOG_V6_MC_TYPE_D_CACHE 5 +#define RTAS_LOG_V6_MC_TYPE_I_CACHE 7 +uint8_t sub_err_type; +#define RTAS_LOG_V6_MC_UE_INDETERMINATE 0 +#define RTAS_LOG_V6_MC_UE_IFETCH 1 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH 2 +#define RTAS_LOG_V6_MC_UE_LOAD_STORE 3 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE 4 +#define RTAS_LOG_V6_MC_SLB_PARITY 0 +#define RTAS_LOG_V6_MC_SLB_MULTIHIT 1 +#define RTAS_LOG_V6_MC_SLB_INDETERMINATE 2 +#define RTAS_LOG_V6_MC_ERAT_PARITY 1 +#define RTAS_LOG_V6_MC_ERAT_MULTIHIT 2 +#define RTAS_LOG_V6_MC_ERAT_INDETERMINATE 3 +#define RTAS_LOG_V6_MC_TLB_PARITY 1 +#define RTAS_LOG_V6_MC_TLB_MULTIHIT 2 +#define RTAS_LOG_V6_MC_TLB_INDETERMINATE 3 +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint64_t logical_address; +}QEMU_PACKED ; + +struct mc_extended_log { +struct rtas_event_log_v6 v6hdr; +struct rtas_event_log_v6_mc mc; +}QEMU_PACKED ; + +struct MC_ierror_table { +unsigned long srr1_mask; +unsigned long srr1_value; +bool nip_valid;/* nip is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_ierror_table mc_ierror_table[] = { +{0x00000000081c0000 ,0x0000000000040000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000080000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x00000000000c0000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000100000 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000140000 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000180000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 ,0 ,0 ,0 ,0 ,0 } }; + +struct MC_derror_table { +unsigned long dsisr_value; +bool dar_valid;/* dar is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_derror_table mc_derror_table[] = { +{0x00008000 , false, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00004000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000800 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000400 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000080 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT ,/* Before PARITY */ +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000100 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 , false,0 ,0 ,0 ,0 } }; + +#define SRR1_MC_LOADSTORE (srr1) ((srr1) & PPC_BIT(42)) + typedef enum EventClass { EVENT_CLASS_INTERNAL_ERRORS = 0, EVENT_CLASS_EPOW = 1,@@ -620,6 +720,147 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +ssize_t spapr_get_rtas_size (ssize_t old_rtas_size) +{ +g_assert (old_rtas_size <RTAS_ERRLOG_OFFSET ); +return RTAS_ERROR_LOG_MAX ; +} + +static uint32_t spapr_mce_get_elog_type (PowerPCCPU *cpu,bool recovered, +struct mc_extended_log *ext_elog) +{ +int i; +CPUPPCState *env = &cpu->env; +uint32_t summary; +uint64_t dsisr = env->spr[SPR_DSISR ]; + + summary =RTAS_LOG_VERSION_6 |RTAS_LOG_OPTIONAL_PART_PRESENT ; +if (recovered) { + summary |=RTAS_LOG_DISPOSITION_FULLY_RECOVERED ; + }else { + summary |=RTAS_LOG_DISPOSITION_NOT_RECOVERED ; + } + +if (SRR1_MC_LOADSTORE (env->spr[SPR_SRR1 ])) { +for (i =0 ; mc_derror_table[i].dsisr_value; i++) { +if (!(dsisr & mc_derror_table[i].dsisr_value)) { +continue ; + } + + ext_elog->mc.error_type = mc_derror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_derror_table[i].error_subtype; +if (mc_derror_table[i].dar_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->spr[SPR_DAR ]); + } + + summary |= mc_derror_table[i].initiator + | mc_derror_table[i].severity; + +return summary; + } + }else { +for (i =0 ; mc_ierror_table[i].srr1_mask; i++) { +if ((env->spr[SPR_SRR1 ] & mc_ierror_table[i].srr1_mask) != + mc_ierror_table[i].srr1_value) { +continue ; + } + + ext_elog->mc.error_type = mc_ierror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_ierror_table[i].error_subtype; +if (mc_ierror_table[i].nip_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->nip); + } + + summary |= mc_ierror_table[i].initiator + | mc_ierror_table[i].severity; + +return summary; + } + } + + summary |=RTAS_LOG_INITIATOR_CPU ; +return summary; +} + +static void spapr_mce_dispatch_elog (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +CPUState *cs =CPU (cpu); +uint64_t rtas_addr; +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +target_ulong r3, msr =0 ; +struct rtas_error_log log; +struct mc_extended_log *ext_elog; +uint32_t summary; + +/* +* Properly set bits in MSR before we invoke the handler. +* SRR0/1, DAR and DSISR are properly set by KVM +*/ +if (!(*pcc->interrupts_big_endian)(cpu)) { + msr |= (1ULL <<MSR_LE ); + } + +if (env->msr && (1ULL <<MSR_SF )) { + msr |= (1ULL <<MSR_SF ); + } + + msr |= (1ULL <<MSR_ME ); + +if (spapr->guest_machine_check_addr ==-1 ) { +/* +* This implies that we have hit a machine check between system +* reset and "ibm,nmi-register". Fall back to the old machine +* check behavior in such cases. +*/ + env->spr[SPR_SRR0 ] = env->nip; + env->spr[SPR_SRR1 ] = env->msr; + env->msr = msr; + env->nip =0x200 ; +return ; + } + + ext_elog =g_malloc0 (sizeof (struct mc_extended_log )); + summary =spapr_mce_get_elog_type (cpu, recovered, ext_elog); + + log.summary =cpu_to_be32 (summary); + log.extended_length =cpu_to_be32 (sizeof (struct mc_extended_log )); + +/* r3 should be in BE always */ + r3 =cpu_to_be64 (env->gpr[3 ]); + env->msr = msr; + +spapr_init_v6hdr (&ext_elog->v6hdr); + ext_elog->mc.hdr.section_id =cpu_to_be16 (RTAS_LOG_V6_SECTION_ID_MC ); + ext_elog->mc.hdr.section_length = +cpu_to_be16 (sizeof (struct rtas_event_log_v6_mc )); + ext_elog->mc.hdr.section_version =1 ; + +/* get rtas addr from fdt */ + rtas_addr =spapr_get_rtas_addr (); +if (!rtas_addr) { +/* Unable to fetch rtas_addr. Hence reset the guest */ +ppc_cpu_do_system_reset (cs); + } + +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET , &r3,sizeof (r3)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3), + &log,sizeof (log)); + cpu_physical_memory_write(rtas_addr + RTAS_ERRLOG_OFFSET + sizeof(r3) + + sizeof(log), ext_elog,Quoted 8 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 856
Quoted 5 lines
hw/ppc/spapr_events.c +5
-0+ sizeof(struct mc_extended_log)); + +/* Save gpr[3] in the guest endian mode */ +if ((*pcc->interrupts_big_endian)(cpu)) { + env->gpr[3 ] =cpu_to_be64 (rtas_addr +RTAS_ERRLOG_OFFSET );I don't think this is right. AIUI env->gpr[] are all stored in *host* endianness (for ease of doing arithmetic).
Quoted 3 lines
env-gpr[3] is later used by guest to fetch the RTAS log. My guess is that we will not do an endianness change of all the gprs during a switch from host to guest (that will be costly).
There's no need to "change endianness". In TCG the host needs to do arithmetic on the values and so they are in host endian. With KVM the env values are only synchronized when we enter/exit KVM and they're going to registers, not memory and so have no endianness.
Quoted 32 lines
But let me cross check.
Quoted 30 lines
Quoted 30 lines
hw/ppc/spapr_events.c +11
-0+ }else { + env->gpr[3 ] =cpu_to_le64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + } + + env->nip = spapr->guest_machine_check_addr; +} +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());@@ -640,6 +881,10 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) } } spapr->mc_status = cpu->vcpu_id; + +spapr_mce_dispatch_elog (cpu, recovered); + +return ; } static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr,include/hw/ppc/spapr.h +0
-0@@ -661,6 +661,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2#define DIAGNOSTICS_RUN_MODE_PERIODIC 3
Quoted 8 lines
Quoted 5 lines
include/hw/ppc/spapr.h target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, · line 665
Quoted 2 lines
include/hw/ppc/spapr.h +2
-0+/* Offset from rtas-base where error log is placed */ +#define RTAS_ERRLOG_OFFSET 0x25Is this offset PAPR defined, or chosen here? Using an entirely unaliged (odd) address seems a very strange choice.
This is not PAPR defined. I will make it
0x30. Or do you prefer any other offset?
0x30 should be fine.
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
Re: [Qemu-devel] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 5 lines · David Gibson
Quoted 4 lines · Aravinda Prasad
Quoted 1 line · David Gibson
On Mon, Apr 22, 2019 at 12:33:26PM +0530, Aravinda Prasad wrote:
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 856
Quoted 3 lines
hw/ppc/spapr_events.c +3
-0+/* Save gpr[3] in the guest endian mode */ +if ((*pcc->interrupts_big_endian)(cpu)) { + env->gpr[3 ] =cpu_to_be64 (rtas_addr +RTAS_ERRLOG_OFFSET );I don't think this is right. AIUI env->gpr[] are all stored in *host* endianness (for ease of doing arithmetic).
Quoted 8 lines
Quoted 3 lines
env-gpr[3] is later used by guest to fetch the RTAS log. My guess is that we will not do an endianness change of all the gprs during a switch from host to guest (that will be costly).
There's no need to "change endianness". In TCG the host needs to do arithmetic on the values and so they are in host endian. With KVM the env values are only synchronized when we enter/exit KVM and they're going to registers, not memory and so have no endianness.
Ah.. ok.
Quoted 39 lines
Quoted 39 lines
But let me cross check.
Quoted 35 lines
Quoted 27 lines
hw/ppc/spapr_events.c +11
-0+ }else { + env->gpr[3 ] =cpu_to_le64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + } + + env->nip = spapr->guest_machine_check_addr; +} +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());@@ -640,6 +881,10 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) } } spapr->mc_status = cpu->vcpu_id; + +spapr_mce_dispatch_elog (cpu, recovered); + +return ; } static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr,include/hw/ppc/spapr.h +0
-0include/hw/ppc/spapr.h target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, · line 665
Quoted 5 lines
include/hw/ppc/spapr.h +2
-0@@ -661,6 +661,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2#define DIAGNOSTICS_RUN_MODE_PERIODIC 3 +/* Offset from rtas-base where error log is placed */ +#define RTAS_ERRLOG_OFFSET 0x25Is this offset PAPR defined, or chosen here? Using an entirely unaliged (odd) address seems a very strange choice.
Quoted 4 lines
Quoted 2 lines
This is not PAPR defined. I will make it
0x30. Or do you prefer any other offset?
0x30should be fine.
ok..
Quoted 1 line
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
In reply to Aravinda PrasadQuoted 25 lines · On Mon, 22 Apr 2019 12:33:26 +0530 Aravinda Prasad…
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)hw/ppc/spapr.c +0
-0
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2924
Quoted 7 lines
hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); +
This is the only user for spapr_get_rtas_size(), which is trivial. I suggest you simply open-code it here.
But also, spapr->rtas_size is a guest visible thing, "rtas-size" prop in the DT. Since existing machine types don't do that, I guess we should only use the new size if cap-fwnmi-mce=on for the sake of compatibility.
hw/ppc/spapr_events.c struct hp_extended_log { · line 215
Quoted 12 lines
hw/ppc/spapr.c +0
-0spapr->rtas_blob =g_malloc (spapr->rtas_size);if (load_image_size (filename, spapr->rtas_blob, spapr->rtas_size) <0 ) {error_report ("Could not load LPAR rtas '%s'" , filename);hw/ppc/spapr_events.c +1
-0@@ -212,6 +212,106 @@ struct hp_extended_log {struct rtas_event_log_v6_hp hp; }QEMU_PACKED ; +struct rtas_event_log_v6_mc {
Even if the rest of the code in this file seems to ignore CODING_STYLE, maybe it's time to start using CamelCase.
David ?
Quoted 185 lines
hw/ppc/spapr_events.c +178
-0+#define RTAS_LOG_V6_SECTION_ID_MC 0x4D43/* MC */ +struct rtas_event_log_v6_section_header hdr; +uint32_t fru_id; +uint32_t proc_id; +uint8_t error_type; +#define RTAS_LOG_V6_MC_TYPE_UE 0 +#define RTAS_LOG_V6_MC_TYPE_SLB 1 +#define RTAS_LOG_V6_MC_TYPE_ERAT 2 +#define RTAS_LOG_V6_MC_TYPE_TLB 4 +#define RTAS_LOG_V6_MC_TYPE_D_CACHE 5 +#define RTAS_LOG_V6_MC_TYPE_I_CACHE 7 +uint8_t sub_err_type; +#define RTAS_LOG_V6_MC_UE_INDETERMINATE 0 +#define RTAS_LOG_V6_MC_UE_IFETCH 1 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH 2 +#define RTAS_LOG_V6_MC_UE_LOAD_STORE 3 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE 4 +#define RTAS_LOG_V6_MC_SLB_PARITY 0 +#define RTAS_LOG_V6_MC_SLB_MULTIHIT 1 +#define RTAS_LOG_V6_MC_SLB_INDETERMINATE 2 +#define RTAS_LOG_V6_MC_ERAT_PARITY 1 +#define RTAS_LOG_V6_MC_ERAT_MULTIHIT 2 +#define RTAS_LOG_V6_MC_ERAT_INDETERMINATE 3 +#define RTAS_LOG_V6_MC_TLB_PARITY 1 +#define RTAS_LOG_V6_MC_TLB_MULTIHIT 2 +#define RTAS_LOG_V6_MC_TLB_INDETERMINATE 3 +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint64_t logical_address; +}QEMU_PACKED ; + +struct mc_extended_log { +struct rtas_event_log_v6 v6hdr; +struct rtas_event_log_v6_mc mc; +}QEMU_PACKED ; + +struct MC_ierror_table { +unsigned long srr1_mask; +unsigned long srr1_value; +bool nip_valid;/* nip is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_ierror_table mc_ierror_table[] = { +{0x00000000081c0000 ,0x0000000000040000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000080000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x00000000000c0000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000100000 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000140000 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000180000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 ,0 ,0 ,0 ,0 ,0 } }; + +struct MC_derror_table { +unsigned long dsisr_value; +bool dar_valid;/* dar is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_derror_table mc_derror_table[] = { +{0x00008000 , false, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00004000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000800 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000400 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000080 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT ,/* Before PARITY */ +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000100 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 , false,0 ,0 ,0 ,0 } }; + +#define SRR1_MC_LOADSTORE (srr1) ((srr1) & PPC_BIT(42)) + typedef enum EventClass { EVENT_CLASS_INTERNAL_ERRORS = 0, EVENT_CLASS_EPOW = 1,@@ -620,6 +720,147 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +ssize_t spapr_get_rtas_size (ssize_t old_rtas_size) +{ +g_assert (old_rtas_size <RTAS_ERRLOG_OFFSET ); +return RTAS_ERROR_LOG_MAX ; +} + +static uint32_t spapr_mce_get_elog_type (PowerPCCPU *cpu,bool recovered, +struct mc_extended_log *ext_elog) +{ +int i; +CPUPPCState *env = &cpu->env; +uint32_t summary; +uint64_t dsisr = env->spr[SPR_DSISR ]; + + summary =RTAS_LOG_VERSION_6 |RTAS_LOG_OPTIONAL_PART_PRESENT ; +if (recovered) { + summary |=RTAS_LOG_DISPOSITION_FULLY_RECOVERED ; + }else { + summary |=RTAS_LOG_DISPOSITION_NOT_RECOVERED ; + } + +if (SRR1_MC_LOADSTORE (env->spr[SPR_SRR1 ])) { +for (i =0 ; mc_derror_table[i].dsisr_value; i++) { +if (!(dsisr & mc_derror_table[i].dsisr_value)) { +continue ; + } + + ext_elog->mc.error_type = mc_derror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_derror_table[i].error_subtype; +if (mc_derror_table[i].dar_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->spr[SPR_DAR ]); + } + + summary |= mc_derror_table[i].initiator + | mc_derror_table[i].severity; + +return summary; + } + }else { +for (i =0 ; mc_ierror_table[i].srr1_mask; i++) { +if ((env->spr[SPR_SRR1 ] & mc_ierror_table[i].srr1_mask) != + mc_ierror_table[i].srr1_value) { +continue ; + } + + ext_elog->mc.error_type = mc_ierror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_ierror_table[i].error_subtype; +if (mc_ierror_table[i].nip_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->nip); + } + + summary |= mc_ierror_table[i].initiator + | mc_ierror_table[i].severity; + +return summary; + } + } + + summary |=RTAS_LOG_INITIATOR_CPU ; +return summary; +} + +static void spapr_mce_dispatch_elog (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +CPUState *cs =CPU (cpu); +uint64_t rtas_addr; +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +target_ulong r3, msr =0 ; +struct rtas_error_log log; +struct mc_extended_log *ext_elog; +uint32_t summary; + +/* +* Properly set bits in MSR before we invoke the handler. +* SRR0/1, DAR and DSISR are properly set by KVM +*/ +if (!(*pcc->interrupts_big_endian)(cpu)) {
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 811
Quoted 10 lines
hw/ppc/spapr_events.c +10
-0+ msr |= (1ULL <<MSR_LE ); + } + +if (env->msr && (1ULL <<MSR_SF )) { + msr |= (1ULL <<MSR_SF ); + } + + msr |= (1ULL <<MSR_ME ); + +if (spapr->guest_machine_check_addr ==-1 ) {
Should be (target_ulong) -1
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 824
Quoted 13 lines
hw/ppc/spapr_events.c +13
-0+/* +* This implies that we have hit a machine check between system +* reset and "ibm,nmi-register". Fall back to the old machine +* check behavior in such cases. +*/ + env->spr[SPR_SRR0 ] = env->nip; + env->spr[SPR_SRR1 ] = env->msr; + env->msr = msr; + env->nip =0x200 ; +return ; + } + + ext_elog =g_malloc0 (sizeof (struct mc_extended_log ));
sizeof(*ext_elog) is preferable IMHO, same remark for the other sizeof sites.
Also, I can't find the corresponding call to g_free(), which should be somewhere in this function IIUC.
Quoted 58 lines
hw/ppc/spapr_events.c +43
-0+ summary =spapr_mce_get_elog_type (cpu, recovered, ext_elog); + + log.summary =cpu_to_be32 (summary); + log.extended_length =cpu_to_be32 (sizeof (struct mc_extended_log )); + +/* r3 should be in BE always */ + r3 =cpu_to_be64 (env->gpr[3 ]); + env->msr = msr; + +spapr_init_v6hdr (&ext_elog->v6hdr); + ext_elog->mc.hdr.section_id =cpu_to_be16 (RTAS_LOG_V6_SECTION_ID_MC ); + ext_elog->mc.hdr.section_length = +cpu_to_be16 (sizeof (struct rtas_event_log_v6_mc )); + ext_elog->mc.hdr.section_version =1 ; + +/* get rtas addr from fdt */ + rtas_addr =spapr_get_rtas_addr (); +if (!rtas_addr) { +/* Unable to fetch rtas_addr. Hence reset the guest */ +ppc_cpu_do_system_reset (cs); + } + +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET , &r3,sizeof (r3)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3), + &log,sizeof (log)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3) + +sizeof (log), ext_elog, +sizeof (struct mc_extended_log )); + +/* Save gpr[3] in the guest endian mode */ +if ((*pcc->interrupts_big_endian)(cpu)) { + env->gpr[3 ] =cpu_to_be64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + }else { + env->gpr[3 ] =cpu_to_le64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + } + + env->nip = spapr->guest_machine_check_addr; +} +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());@@ -640,6 +881,10 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) } } spapr->mc_status = cpu->vcpu_id; + +spapr_mce_dispatch_elog (cpu, recovered); + +return ; } static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr,include/hw/ppc/spapr.h +0
-0
include/hw/ppc/spapr.h target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, · line 666
Quoted 6 lines
include/hw/ppc/spapr.h +3
-0@@ -661,6 +661,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2#define DIAGNOSTICS_RUN_MODE_PERIODIC 3 +/* Offset from rtas-base where error log is placed */ +#define RTAS_ERRLOG_OFFSET 0x25 +
We already have an RTAS_ERROR_LOG_MAX macro defined in this file. Maybe use the same "ERROR_LOG" wording for consistency.
Quoted 13 lines
include/hw/ppc/spapr.h +1
-0static inline uint64_t ppc64_phys_to_real (uint64_t addr) {return addr & ~0xF000000000000000ULL ;@@ -798,6 +801,7 @@ int spapr_max_server_number(SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1);void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered); +ssize_t spapr_get_rtas_size (ssize_t old_rtas_sizea);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 23 lines · Greg Kurz
Quoted 20 lines · On Mon, 22 Apr 2019 12:33:26 +0530 Aravinda Prasad…
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)
Quoted 15 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2924
Quoted 12 lines
hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); +This is the only user for
spapr_get_rtas_size(), which is trivial. I suggest you simply open-code it here.
I agree.
Quoted 3 lines
But also,
spapr->rtas_sizeis a guest visible thing, "rtas-size" prop in the DT. Since existing machine types don't do that, I guess we should only use the new size if cap-fwnmi-mce=on for the sake of compatibility.
Yes, that's a good idea. Changing this is very unlikely to break a guest, but it's easy to be safe here so let's do it.
Quoted 12 lines
Quoted 12 lines
hw/ppc/spapr.c +0
-0spapr->rtas_blob =g_malloc (spapr->rtas_size);if (load_image_size (filename, spapr->rtas_blob, spapr->rtas_size) <0 ) {error_report ("Could not load LPAR rtas '%s'" , filename);hw/ppc/spapr_events.c +0
-0@@ -212,6 +212,106 @@ struct hp_extended_log {struct rtas_event_log_v6_hp hp; }QEMU_PACKED ;
Quoted 6 lines
hw/ppc/spapr_events.c struct hp_extended_log { · line 215
Quoted 1 line
hw/ppc/spapr_events.c +1
-0+struct rtas_event_log_v6_mc {Even if the rest of the code in this file seems to ignore
CODING_STYLE, maybe it's time to start using CamelCase.David ?
Out of scope here, I think.
Quoted 189 lines
Quoted 189 lines
hw/ppc/spapr_events.c +182
-0+#define RTAS_LOG_V6_SECTION_ID_MC 0x4D43/* MC */ +struct rtas_event_log_v6_section_header hdr; +uint32_t fru_id; +uint32_t proc_id; +uint8_t error_type; +#define RTAS_LOG_V6_MC_TYPE_UE 0 +#define RTAS_LOG_V6_MC_TYPE_SLB 1 +#define RTAS_LOG_V6_MC_TYPE_ERAT 2 +#define RTAS_LOG_V6_MC_TYPE_TLB 4 +#define RTAS_LOG_V6_MC_TYPE_D_CACHE 5 +#define RTAS_LOG_V6_MC_TYPE_I_CACHE 7 +uint8_t sub_err_type; +#define RTAS_LOG_V6_MC_UE_INDETERMINATE 0 +#define RTAS_LOG_V6_MC_UE_IFETCH 1 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH 2 +#define RTAS_LOG_V6_MC_UE_LOAD_STORE 3 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE 4 +#define RTAS_LOG_V6_MC_SLB_PARITY 0 +#define RTAS_LOG_V6_MC_SLB_MULTIHIT 1 +#define RTAS_LOG_V6_MC_SLB_INDETERMINATE 2 +#define RTAS_LOG_V6_MC_ERAT_PARITY 1 +#define RTAS_LOG_V6_MC_ERAT_MULTIHIT 2 +#define RTAS_LOG_V6_MC_ERAT_INDETERMINATE 3 +#define RTAS_LOG_V6_MC_TLB_PARITY 1 +#define RTAS_LOG_V6_MC_TLB_MULTIHIT 2 +#define RTAS_LOG_V6_MC_TLB_INDETERMINATE 3 +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint64_t logical_address; +}QEMU_PACKED ; + +struct mc_extended_log { +struct rtas_event_log_v6 v6hdr; +struct rtas_event_log_v6_mc mc; +}QEMU_PACKED ; + +struct MC_ierror_table { +unsigned long srr1_mask; +unsigned long srr1_value; +bool nip_valid;/* nip is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_ierror_table mc_ierror_table[] = { +{0x00000000081c0000 ,0x0000000000040000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000080000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x00000000000c0000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000100000 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000140000 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000180000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 ,0 ,0 ,0 ,0 ,0 } }; + +struct MC_derror_table { +unsigned long dsisr_value; +bool dar_valid;/* dar is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_derror_table mc_derror_table[] = { +{0x00008000 , false, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00004000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000800 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000400 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000080 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT ,/* Before PARITY */ +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000100 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 , false,0 ,0 ,0 ,0 } }; + +#define SRR1_MC_LOADSTORE (srr1) ((srr1) & PPC_BIT(42)) + typedef enum EventClass { EVENT_CLASS_INTERNAL_ERRORS = 0, EVENT_CLASS_EPOW = 1,@@ -620,6 +720,147 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +ssize_t spapr_get_rtas_size (ssize_t old_rtas_size) +{ +g_assert (old_rtas_size <RTAS_ERRLOG_OFFSET ); +return RTAS_ERROR_LOG_MAX ; +} + +static uint32_t spapr_mce_get_elog_type (PowerPCCPU *cpu,bool recovered, +struct mc_extended_log *ext_elog) +{ +int i; +CPUPPCState *env = &cpu->env; +uint32_t summary; +uint64_t dsisr = env->spr[SPR_DSISR ]; + + summary =RTAS_LOG_VERSION_6 |RTAS_LOG_OPTIONAL_PART_PRESENT ; +if (recovered) { + summary |=RTAS_LOG_DISPOSITION_FULLY_RECOVERED ; + }else { + summary |=RTAS_LOG_DISPOSITION_NOT_RECOVERED ; + } + +if (SRR1_MC_LOADSTORE (env->spr[SPR_SRR1 ])) { +for (i =0 ; mc_derror_table[i].dsisr_value; i++) { +if (!(dsisr & mc_derror_table[i].dsisr_value)) { +continue ; + } + + ext_elog->mc.error_type = mc_derror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_derror_table[i].error_subtype; +if (mc_derror_table[i].dar_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->spr[SPR_DAR ]); + } + + summary |= mc_derror_table[i].initiator + | mc_derror_table[i].severity; + +return summary; + } + }else { +for (i =0 ; mc_ierror_table[i].srr1_mask; i++) { +if ((env->spr[SPR_SRR1 ] & mc_ierror_table[i].srr1_mask) != + mc_ierror_table[i].srr1_value) { +continue ; + } + + ext_elog->mc.error_type = mc_ierror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_ierror_table[i].error_subtype; +if (mc_ierror_table[i].nip_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->nip); + } + + summary |= mc_ierror_table[i].initiator + | mc_ierror_table[i].severity; + +return summary; + } + } + + summary |=RTAS_LOG_INITIATOR_CPU ; +return summary; +} + +static void spapr_mce_dispatch_elog (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +CPUState *cs =CPU (cpu); +uint64_t rtas_addr; +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +target_ulong r3, msr =0 ; +struct rtas_error_log log; +struct mc_extended_log *ext_elog; +uint32_t summary; + +/* +* Properly set bits in MSR before we invoke the handler. +* SRR0/1, DAR and DSISR are properly set by KVM +*/ +if (!(*pcc->interrupts_big_endian)(cpu)) { + msr |= (1ULL <<MSR_LE ); + } + +if (env->msr && (1ULL <<MSR_SF )) {
Quoted 8 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 811
Quoted 6 lines
hw/ppc/spapr_events.c +6
-0+ msr |= (1ULL <<MSR_SF ); + } + + msr |= (1ULL <<MSR_ME ); + +if (spapr->guest_machine_check_addr ==-1 ) {Should be (
target_ulong) -1
I think the == itself should perform the necessary coercion.
Quoted 14 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 824
Quoted 13 lines
hw/ppc/spapr_events.c +13
-0+/* +* This implies that we have hit a machine check between system +* reset and "ibm,nmi-register". Fall back to the old machine +* check behavior in such cases. +*/ + env->spr[SPR_SRR0 ] = env->nip; + env->spr[SPR_SRR1 ] = env->msr; + env->msr = msr; + env->nip =0x200 ; +return ; + } + + ext_elog =g_malloc0 (sizeof (struct mc_extended_log ));
Quoted 1 line
sizeof(*ext_elog)is preferable IMHO, same remark for the other sizeof sites.
Agreed.
Quoted 2 lines
Also, I can't find the corresponding call to
g_free(), which should be somewhere in this function IIUC.
Yes, that needs fixing.
Quoted 62 lines
Quoted 62 lines
hw/ppc/spapr_events.c +43
-0+ summary =spapr_mce_get_elog_type (cpu, recovered, ext_elog); + + log.summary =cpu_to_be32 (summary); + log.extended_length =cpu_to_be32 (sizeof (struct mc_extended_log )); + +/* r3 should be in BE always */ + r3 =cpu_to_be64 (env->gpr[3 ]); + env->msr = msr; + +spapr_init_v6hdr (&ext_elog->v6hdr); + ext_elog->mc.hdr.section_id =cpu_to_be16 (RTAS_LOG_V6_SECTION_ID_MC ); + ext_elog->mc.hdr.section_length = +cpu_to_be16 (sizeof (struct rtas_event_log_v6_mc )); + ext_elog->mc.hdr.section_version =1 ; + +/* get rtas addr from fdt */ + rtas_addr =spapr_get_rtas_addr (); +if (!rtas_addr) { +/* Unable to fetch rtas_addr. Hence reset the guest */ +ppc_cpu_do_system_reset (cs); + } + +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET , &r3,sizeof (r3)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3), + &log,sizeof (log)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3) + +sizeof (log), ext_elog, +sizeof (struct mc_extended_log )); + +/* Save gpr[3] in the guest endian mode */ +if ((*pcc->interrupts_big_endian)(cpu)) { + env->gpr[3 ] =cpu_to_be64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + }else { + env->gpr[3 ] =cpu_to_le64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + } + + env->nip = spapr->guest_machine_check_addr; +} +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());@@ -640,6 +881,10 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) } } spapr->mc_status = cpu->vcpu_id; + +spapr_mce_dispatch_elog (cpu, recovered); + +return ; } static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr,include/hw/ppc/spapr.h +0
-0@@ -661,6 +661,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2#define DIAGNOSTICS_RUN_MODE_PERIODIC 3
Quoted 6 lines
include/hw/ppc/spapr.h target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, · line 666
Quoted 3 lines
include/hw/ppc/spapr.h +3
-0+/* Offset from rtas-base where error log is placed */ +#define RTAS_ERRLOG_OFFSET 0x25 +We already have an
RTAS_ERROR_LOG_MAXmacro defined in this file. Maybe use the same "ERROR_LOG" wording for consistency.
Agreed.
Quoted 14 lines
Quoted 13 lines
include/hw/ppc/spapr.h +1
-0static inline uint64_t ppc64_phys_to_real (uint64_t addr) {return addr & ~0xF000000000000000ULL ;@@ -798,6 +801,7 @@ int spapr_max_server_number(SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1);void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered); +ssize_t spapr_get_rtas_size (ssize_t old_rtas_sizea);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 40 lines · David Gibson
Quoted 23 lines · Greg Kurz
Quoted 20 lines · On Mon, 22 Apr 2019 12:33:26 +0530 Aravinda Prasad…
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)Quoted 15 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2924
Quoted 12 lines
hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); +This is the only user for
spapr_get_rtas_size(), which is trivial. I suggest you simply open-code it here.
Quoted 1 line
I agree.
Sure.
Quoted 7 lines
Quoted 4 lines
But also,
spapr->rtas_sizeis a guest visible thing, "rtas-size" prop in the DT. Since existing machine types don't do that, I guess we should only use the new size if cap-fwnmi-mce=on for the sake of compatibility.Yes, that's a good idea. Changing this is very unlikely to break a guest, but it's easy to be safe here so let's do it.
I did it like that because the rtas_blob is allocated based on rtas_size in spapr_machine_init(). During spapr_machine_init() it is not know if the guest calls "ibm, nmi-register". So if we want to use the new size only when cap_fwnmi=on, then we have to realloc the blob in "ibm, nmi-register".
Quoted 236 lines
Quoted 13 lines
Quoted 13 lines
hw/ppc/spapr.c +0
-0spapr->rtas_blob =g_malloc (spapr->rtas_size);if (load_image_size (filename, spapr->rtas_blob, spapr->rtas_size) <0 ) {error_report ("Could not load LPAR rtas '%s'" , filename);hw/ppc/spapr_events.c +0
-0@@ -212,6 +212,106 @@ struct hp_extended_log {struct rtas_event_log_v6_hp hp; }QEMU_PACKED ;Quoted 6 lines
hw/ppc/spapr_events.c struct hp_extended_log { · line 215
Quoted 1 line
hw/ppc/spapr_events.c +1
-0+struct rtas_event_log_v6_mc {Even if the rest of the code in this file seems to ignore
CODING_STYLE, maybe it's time to start using CamelCase.David ?
Out of scope here, I think.
Quoted 189 lines
Quoted 189 lines
hw/ppc/spapr_events.c +182
-0+#define RTAS_LOG_V6_SECTION_ID_MC 0x4D43/* MC */ +struct rtas_event_log_v6_section_header hdr; +uint32_t fru_id; +uint32_t proc_id; +uint8_t error_type; +#define RTAS_LOG_V6_MC_TYPE_UE 0 +#define RTAS_LOG_V6_MC_TYPE_SLB 1 +#define RTAS_LOG_V6_MC_TYPE_ERAT 2 +#define RTAS_LOG_V6_MC_TYPE_TLB 4 +#define RTAS_LOG_V6_MC_TYPE_D_CACHE 5 +#define RTAS_LOG_V6_MC_TYPE_I_CACHE 7 +uint8_t sub_err_type; +#define RTAS_LOG_V6_MC_UE_INDETERMINATE 0 +#define RTAS_LOG_V6_MC_UE_IFETCH 1 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH 2 +#define RTAS_LOG_V6_MC_UE_LOAD_STORE 3 +#define RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE 4 +#define RTAS_LOG_V6_MC_SLB_PARITY 0 +#define RTAS_LOG_V6_MC_SLB_MULTIHIT 1 +#define RTAS_LOG_V6_MC_SLB_INDETERMINATE 2 +#define RTAS_LOG_V6_MC_ERAT_PARITY 1 +#define RTAS_LOG_V6_MC_ERAT_MULTIHIT 2 +#define RTAS_LOG_V6_MC_ERAT_INDETERMINATE 3 +#define RTAS_LOG_V6_MC_TLB_PARITY 1 +#define RTAS_LOG_V6_MC_TLB_MULTIHIT 2 +#define RTAS_LOG_V6_MC_TLB_INDETERMINATE 3 +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint64_t logical_address; +}QEMU_PACKED ; + +struct mc_extended_log { +struct rtas_event_log_v6 v6hdr; +struct rtas_event_log_v6_mc mc; +}QEMU_PACKED ; + +struct MC_ierror_table { +unsigned long srr1_mask; +unsigned long srr1_value; +bool nip_valid;/* nip is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_ierror_table mc_ierror_table[] = { +{0x00000000081c0000 ,0x0000000000040000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000080000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x00000000000c0000 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000100000 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000140000 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000000081c0000 ,0x0000000000180000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_IFETCH , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 ,0 ,0 ,0 ,0 ,0 } }; + +struct MC_derror_table { +unsigned long dsisr_value; +bool dar_valid;/* dar is a valid indicator of faulting address */ +uint8_t error_type; +uint8_t error_subtype; +unsigned int initiator; +unsigned int severity; +}; + +static const struct MC_derror_table mc_derror_table[] = { +{0x00008000 , false, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00004000 , true, +RTAS_LOG_V6_MC_TYPE_UE ,RTAS_LOG_V6_MC_UE_PAGE_TABLE_WALK_LOAD_STORE , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000800 , true, +RTAS_LOG_V6_MC_TYPE_ERAT ,RTAS_LOG_V6_MC_ERAT_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000400 , true, +RTAS_LOG_V6_MC_TYPE_TLB ,RTAS_LOG_V6_MC_TLB_MULTIHIT , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000080 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_MULTIHIT ,/* Before PARITY */ +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0x00000100 , true, +RTAS_LOG_V6_MC_TYPE_SLB ,RTAS_LOG_V6_MC_SLB_PARITY , +RTAS_LOG_INITIATOR_CPU ,RTAS_LOG_SEVERITY_ERROR_SYNC , }, +{0 , false,0 ,0 ,0 ,0 } }; + +#define SRR1_MC_LOADSTORE (srr1) ((srr1) & PPC_BIT(42)) + typedef enum EventClass { EVENT_CLASS_INTERNAL_ERRORS = 0, EVENT_CLASS_EPOW = 1,@@ -620,6 +720,147 @@ void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, RTAS_LOG_V6_HP_ACTION_REMOVE, drc_type, &drc_id); } +ssize_t spapr_get_rtas_size (ssize_t old_rtas_size) +{ +g_assert (old_rtas_size <RTAS_ERRLOG_OFFSET ); +return RTAS_ERROR_LOG_MAX ; +} + +static uint32_t spapr_mce_get_elog_type (PowerPCCPU *cpu,bool recovered, +struct mc_extended_log *ext_elog) +{ +int i; +CPUPPCState *env = &cpu->env; +uint32_t summary; +uint64_t dsisr = env->spr[SPR_DSISR ]; + + summary =RTAS_LOG_VERSION_6 |RTAS_LOG_OPTIONAL_PART_PRESENT ; +if (recovered) { + summary |=RTAS_LOG_DISPOSITION_FULLY_RECOVERED ; + }else { + summary |=RTAS_LOG_DISPOSITION_NOT_RECOVERED ; + } + +if (SRR1_MC_LOADSTORE (env->spr[SPR_SRR1 ])) { +for (i =0 ; mc_derror_table[i].dsisr_value; i++) { +if (!(dsisr & mc_derror_table[i].dsisr_value)) { +continue ; + } + + ext_elog->mc.error_type = mc_derror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_derror_table[i].error_subtype; +if (mc_derror_table[i].dar_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->spr[SPR_DAR ]); + } + + summary |= mc_derror_table[i].initiator + | mc_derror_table[i].severity; + +return summary; + } + }else { +for (i =0 ; mc_ierror_table[i].srr1_mask; i++) { +if ((env->spr[SPR_SRR1 ] & mc_ierror_table[i].srr1_mask) != + mc_ierror_table[i].srr1_value) { +continue ; + } + + ext_elog->mc.error_type = mc_ierror_table[i].error_type; + ext_elog->mc.sub_err_type = mc_ierror_table[i].error_subtype; +if (mc_ierror_table[i].nip_valid) { + ext_elog->mc.effective_address =cpu_to_be64 (env->nip); + } + + summary |= mc_ierror_table[i].initiator + | mc_ierror_table[i].severity; + +return summary; + } + } + + summary |=RTAS_LOG_INITIATOR_CPU ; +return summary; +} + +static void spapr_mce_dispatch_elog (PowerPCCPU *cpu,bool recovered) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +CPUState *cs =CPU (cpu); +uint64_t rtas_addr; +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +target_ulong r3, msr =0 ; +struct rtas_error_log log; +struct mc_extended_log *ext_elog; +uint32_t summary; + +/* +* Properly set bits in MSR before we invoke the handler. +* SRR0/1, DAR and DSISR are properly set by KVM +*/ +if (!(*pcc->interrupts_big_endian)(cpu)) { + msr |= (1ULL <<MSR_LE ); + } + +if (env->msr && (1ULL <<MSR_SF )) {Quoted 8 lines
hw/ppc/spapr_events.c void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type, · line 811
Quoted 6 lines
hw/ppc/spapr_events.c +6
-0+ msr |= (1ULL <<MSR_SF ); + } + + msr |= (1ULL <<MSR_ME ); + +if (spapr->guest_machine_check_addr ==-1 ) {Should be (
target_ulong) -1I think the == itself should perform the necessary coercion.
Quoted 14 lines
Quoted 13 lines
hw/ppc/spapr_events.c +13
-0+/* +* This implies that we have hit a machine check between system +* reset and "ibm,nmi-register". Fall back to the old machine +* check behavior in such cases. +*/ + env->spr[SPR_SRR0 ] = env->nip; + env->spr[SPR_SRR1 ] = env->msr; + env->msr = msr; + env->nip =0x200 ; +return ; + } + + ext_elog =g_malloc0 (sizeof (struct mc_extended_log ));
Quoted 3 lines
Quoted 1 line
sizeof(*ext_elog)is preferable IMHO, same remark for the other sizeof sites.Agreed.
ok.
Quoted 5 lines
Quoted 3 lines
Also, I can't find the corresponding call to
g_free(), which should be somewhere in this function IIUC.Yes, that needs fixing.
Yes, missed calling free. Will fix it.
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
hw/ppc/spapr_events.c +43
-0+ summary =spapr_mce_get_elog_type (cpu, recovered, ext_elog); + + log.summary =cpu_to_be32 (summary); + log.extended_length =cpu_to_be32 (sizeof (struct mc_extended_log )); + +/* r3 should be in BE always */ + r3 =cpu_to_be64 (env->gpr[3 ]); + env->msr = msr; + +spapr_init_v6hdr (&ext_elog->v6hdr); + ext_elog->mc.hdr.section_id =cpu_to_be16 (RTAS_LOG_V6_SECTION_ID_MC ); + ext_elog->mc.hdr.section_length = +cpu_to_be16 (sizeof (struct rtas_event_log_v6_mc )); + ext_elog->mc.hdr.section_version =1 ; + +/* get rtas addr from fdt */ + rtas_addr =spapr_get_rtas_addr (); +if (!rtas_addr) { +/* Unable to fetch rtas_addr. Hence reset the guest */ +ppc_cpu_do_system_reset (cs); + } + +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET , &r3,sizeof (r3)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3), + &log,sizeof (log)); +cpu_physical_memory_write (rtas_addr +RTAS_ERRLOG_OFFSET +sizeof (r3) + +sizeof (log), ext_elog, +sizeof (struct mc_extended_log )); + +/* Save gpr[3] in the guest endian mode */ +if ((*pcc->interrupts_big_endian)(cpu)) { + env->gpr[3 ] =cpu_to_be64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + }else { + env->gpr[3 ] =cpu_to_le64 (rtas_addr +RTAS_ERRLOG_OFFSET ); + } + + env->nip = spapr->guest_machine_check_addr; +} +void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());@@ -640,6 +881,10 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) } } spapr->mc_status = cpu->vcpu_id; + +spapr_mce_dispatch_elog (cpu, recovered); + +return ; } static void check_exception(PowerPCCPU *cpu, SpaprMachineState *spapr,include/hw/ppc/spapr.h +0
-0@@ -661,6 +661,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,#define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2#define DIAGNOSTICS_RUN_MODE_PERIODIC 3
Quoted 8 lines
Quoted 6 lines
include/hw/ppc/spapr.h target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, · line 666
Quoted 3 lines
include/hw/ppc/spapr.h +3
-0+/* Offset from rtas-base where error log is placed */ +#define RTAS_ERRLOG_OFFSET 0x25 +We already have an
RTAS_ERROR_LOG_MAXmacro defined in this file. Maybe use the same "ERROR_LOG" wording for consistency.Agreed.
ok.
Regards,
Aravinda
Quoted 16 lines
Quoted 15 lines
Quoted 14 lines
include/hw/ppc/spapr.h +1
-0static inline uint64_t ppc64_phys_to_real (uint64_t addr) {return addr & ~0xF000000000000000ULL ;@@ -798,6 +801,7 @@ int spapr_max_server_number(SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1);void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered); +ssize_t spapr_get_rtas_size (ssize_t old_rtas_sizea);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 52 lines · Aravinda Prasad
Quoted 40 lines · David Gibson
Quoted 23 lines · Greg Kurz
Quoted 20 lines · On Mon, 22 Apr 2019 12:33:26 +0530 Aravinda Prasad…
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)Quoted 15 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2924
Quoted 12 lines
hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); +This is the only user for
spapr_get_rtas_size(), which is trivial. I suggest you simply open-code it here.Quoted 1 line
I agree.
Sure.
Quoted 5 lines
Quoted 4 lines
But also,
spapr->rtas_sizeis a guest visible thing, "rtas-size" prop in the DT. Since existing machine types don't do that, I guess we should only use the new size if cap-fwnmi-mce=on for the sake of compatibility.
Quoted 8 lines
Quoted 2 lines
Yes, that's a good idea. Changing this is very unlikely to break a guest, but it's easy to be safe here so let's do it.
I did it like that because the
rtas_blobis allocated based onrtas_sizeinspapr_machine_init(). Duringspapr_machine_init()it is not know if the guest calls "ibm, nmi-register". So if we want to use the new size only when cap_fwnmi=on, then we have to realloc the blob in "ibm, nmi-register".
What? Just always allocate the necessary space in spapr_machine_init() if cap_fwnmi=on, it'll be wasted if ibm,nmi-register is never called, but it's not that much space so we don't really care.
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 62 lines · David Gibson
Quoted 52 lines · Aravinda Prasad
Quoted 40 lines · David Gibson
Quoted 23 lines · Greg Kurz
Quoted 20 lines · On Mon, 22 Apr 2019 12:33:26 +0530 Aravinda Prasad…
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)Quoted 15 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2924
Quoted 12 lines
hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); +This is the only user for
spapr_get_rtas_size(), which is trivial. I suggest you simply open-code it here.Quoted 1 line
I agree.
Sure.
Quoted 5 lines
Quoted 4 lines
But also,
spapr->rtas_sizeis a guest visible thing, "rtas-size" prop in the DT. Since existing machine types don't do that, I guess we should only use the new size if cap-fwnmi-mce=on for the sake of compatibility.Quoted 8 lines
Quoted 2 lines
Yes, that's a good idea. Changing this is very unlikely to break a guest, but it's easy to be safe here so let's do it.
I did it like that because the
rtas_blobis allocated based onrtas_sizeinspapr_machine_init(). Duringspapr_machine_init()it is not know if the guest calls "ibm, nmi-register". So if we want to use the new size only when cap_fwnmi=on, then we have to realloc the blob in "ibm, nmi-register".
Quoted 4 lines
What? Just always allocate the necessary space in
spapr_machine_init()if cap_fwnmi=on, it'll be wasted if ibm,nmi-register is never called, but it's not that much space so we don't really care.
Yes, not that much space, and ibm,nmi-register is called when the Linux kernel boots. I guess, even though other OSes might not call ibm,nmi-register, they do not constitute significant QEMU on Power users.
So I think, I will keep the code as is.
Quoted 1 line
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 70 lines · Aravinda Prasad
Quoted 62 lines · David Gibson
Quoted 52 lines · Aravinda Prasad
Quoted 40 lines · David Gibson
Quoted 23 lines · Greg Kurz
Quoted 20 lines · On Mon, 22 Apr 2019 12:33:26 +0530 Aravinda Prasad…
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)Quoted 15 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2924
Quoted 12 lines
hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); +This is the only user for
spapr_get_rtas_size(), which is trivial. I suggest you simply open-code it here.Quoted 1 line
I agree.
Sure.
Quoted 5 lines
Quoted 4 lines
But also,
spapr->rtas_sizeis a guest visible thing, "rtas-size" prop in the DT. Since existing machine types don't do that, I guess we should only use the new size if cap-fwnmi-mce=on for the sake of compatibility.Quoted 8 lines
Quoted 2 lines
Yes, that's a good idea. Changing this is very unlikely to break a guest, but it's easy to be safe here so let's do it.
I did it like that because the
rtas_blobis allocated based onrtas_sizeinspapr_machine_init(). Duringspapr_machine_init()it is not know if the guest calls "ibm, nmi-register". So if we want to use the new size only when cap_fwnmi=on, then we have to realloc the blob in "ibm, nmi-register".Quoted 4 lines
What? Just always allocate the necessary space in
spapr_machine_init()if cap_fwnmi=on, it'll be wasted if ibm,nmi-register is never called, but it's not that much space so we don't really care.
Quoted 5 lines
Yes, not that much space, and ibm,nmi-register is called when the Linux kernel boots. I guess, even though other OSes might not call ibm,nmi-register, they do not constitute significant QEMU on Power users.
So I think, I will keep the code as is.
No, that's not right. It's impractical to change the allocation depending on whether fwnmi is currently active. But you *can* (and should) base the allocation on whether fwnmi is *possible* - that is, the value of the spapr cap.
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 4/6] target/ppc: Build rtas error log upon an MCE
Quoted 75 lines · David Gibson
Quoted 74 lines · Aravinda Prasad
Quoted 62 lines · David Gibson
Quoted 52 lines · Aravinda Prasad
Quoted 40 lines · David Gibson
Quoted 23 lines · Greg Kurz
Quoted 20 lines · On Mon, 22 Apr 2019 12:33:26 +0530 Aravinda Prasad…
Upon a machine check exception (MCE) in a guest address space, KVM causes a guest exit to enable QEMU to build and pass the error to the guest in the PAPR defined rtas error log format.
This patch builds the rtas error log, copies it to the
rtas_addrand then invokes the guest registered machine check handler. The handler in the guest takes suitable action(s) depending on the type and criticality of the error. For example, if an error is unrecoverable memory corruption in an application inside the guest, then the guest kernel sends a SIGBUS to the application. For recoverable errors, the guest performs recovery actions and logs the error.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 4 + hw/ppc/spapr_events.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 + 3 files changed, 253 insertions(+)Quoted 15 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2924
Quoted 12 lines
hw/ppc/spapr.c +4
-0@@ -2918,6 +2918,10 @@ static void spapr_machine_init(MachineState *machine)error_report ("Could not get size of LPAR rtas '%s'" , filename);exit (1 ); } + +/* Resize blob to accommodate error log. */ + spapr->rtas_size =spapr_get_rtas_size (spapr->rtas_size); +This is the only user for
spapr_get_rtas_size(), which is trivial. I suggest you simply open-code it here.Quoted 1 line
I agree.
Sure.
Quoted 5 lines
Quoted 4 lines
But also,
spapr->rtas_sizeis a guest visible thing, "rtas-size" prop in the DT. Since existing machine types don't do that, I guess we should only use the new size if cap-fwnmi-mce=on for the sake of compatibility.Quoted 8 lines
Quoted 2 lines
Yes, that's a good idea. Changing this is very unlikely to break a guest, but it's easy to be safe here so let's do it.
I did it like that because the
rtas_blobis allocated based onrtas_sizeinspapr_machine_init(). Duringspapr_machine_init()it is not know if the guest calls "ibm, nmi-register". So if we want to use the new size only when cap_fwnmi=on, then we have to realloc the blob in "ibm, nmi-register".Quoted 4 lines
What? Just always allocate the necessary space in
spapr_machine_init()if cap_fwnmi=on, it'll be wasted if ibm,nmi-register is never called, but it's not that much space so we don't really care.Yes, not that much space, and ibm,nmi-register is called when the Linux kernel boots. I guess, even though other OSes might not call ibm,nmi-register, they do not constitute significant QEMU on Power users.
Quoted 6 lines
Quoted 1 line
So I think, I will keep the code as is.
No, that's not right. It's impractical to change the allocation depending on whether fwnmi is currently active. But you *can* (and should) base the allocation on whether fwnmi is *possible* - that is, the value of the spapr cap.
Sure..
Quoted 1 line
Signature · 2 lines
Regards, Aravinda
PATCH v8 5/6 ppc: spapr: Enable FWNMI capability
In reply to Aravinda PrasadEnable the KVM capability KVM_CAP_PPC_FWNMI so that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's 0x200 vector.
This patch also deals with the case when a guest with the KVM_CAP_PPC_FWNMI capability enabled is attempted to migrate to a host that does not support this capability.
--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +1 -0
@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;
hw/ppc/spapr_caps.c +26 -0
@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,
@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,
@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {
hw/ppc/spapr_rtas.c +14 -0
@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,
@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {
@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; } + ret =kvmppc_fwnmi_enable (cpu); + +if (ret ==1 ) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + +if (ret <0 ) { +rtas_st (rets,0 ,RTAS_OUT_HW_ERROR ); +return ; + } + spapr->guest_machine_check_addr =rtas_ld (args,1 );rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }
include/hw/ppc/spapr.h +3 -1
@@ -78,8 +78,10 @@ typedef enum {#define SPAPR_CAP_LARGE_DECREMENTER 0x08/* Count Cache Flush Assist HW Instruction */ #define SPAPR_CAP_CCF_ASSIST 0x09 +/* FWNMI machine check handling */ +#define SPAPR_CAP_FWNMI_MCE 0x0A/* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_CCF_ASSIST + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_FWNMI_MCE + 1)/* * Capability Values
target/ppc/kvm.c +14 -0
@@ -83,6 +83,7 @@ static int cap_ppc_safe_indirect_branch;static int cap_ppc_count_cache_flush_assist;static int cap_ppc_nested_kvm_hv;static int cap_large_decr; +static int cap_ppc_fwnmi;static uint32_t debug_inst_opcode;
@@ -150,6 +151,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)kvmppc_get_cpu_characteristics (s); cap_ppc_nested_kvm_hv =kvm_vm_check_extension (s,KVM_CAP_PPC_NESTED_HV ); cap_large_decr =kvmppc_get_dec_bits (); + cap_ppc_fwnmi =kvm_check_extension (s,KVM_CAP_PPC_FWNMI );/* * Note: setting it to false because there is not such capability * in KVM at this moment.
@@ -2117,6 +2119,18 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) } } +int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); + +if (!cap_ppc_fwnmi) { +return 1 ; + } + +return kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_FWNMI ,0 ); +} + +int kvmppc_smt_threads (void ) {return cap_ppc_smt ? cap_ppc_smt :1 ;
target/ppc/kvm_ppc.h +6 -0
@@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);void kvmppc_set_papr (PowerPCCPU *cpu);int kvmppc_set_compat (PowerPCCPU *cpu,uint32_t compat_pvr);void kvmppc_set_mpic_proxy (PowerPCCPU *cpu,int mpic_proxy); +int kvmppc_fwnmi_enable (PowerPCCPU *cpu);int kvmppc_smt_threads (void );void kvmppc_hint_smt_possible (Error **errp);int kvmppc_set_smt_threads (int smt);
@@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) { } +static inline int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +return 1 ; +} +static inline int kvmppc_smt_threads (void ) {return 1 ;
Re: [Qemu-devel] [PATCH v8 5/6] ppc: spapr: Enable FWNMI capability
Quoted 106 lines · Aravinda Prasad
Enable the KVM capability
KVM_CAP_PPC_FWNMIso that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's0x200vector.This patch also deals with the case when a guest with the
KVM_CAP_PPC_FWNMIcapability enabled is attempted to migrate to a host that does not support this capability.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)hw/ppc/spapr.c +1
-0@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;hw/ppc/spapr_caps.c +26
-0@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {hw/ppc/spapr_rtas.c +2
-0@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {
hw/ppc/spapr_rtas.c static void rtas_ibm_nmi_register(PowerPCCPU *cpu, · line 366
Quoted 4 lines
hw/ppc/spapr_rtas.c +1
-0@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; } + ret =kvmppc_fwnmi_enable (cpu);
You shouldn't need this here as well as in cap_fwnmi_mce_apply().
Instead, you should unconditionally fail the nmi-register if the capability is not enabled.
Quoted 93 lines
hw/ppc/spapr_rtas.c +10
-0+if (ret ==1 ) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + +if (ret <0 ) { +rtas_st (rets,0 ,RTAS_OUT_HW_ERROR ); +return ; + } + spapr->guest_machine_check_addr =rtas_ld (args,1 );rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +3
-1@@ -78,8 +78,10 @@ typedef enum {#define SPAPR_CAP_LARGE_DECREMENTER 0x08/* Count Cache Flush Assist HW Instruction */ #define SPAPR_CAP_CCF_ASSIST 0x09 +/* FWNMI machine check handling */ +#define SPAPR_CAP_FWNMI_MCE 0x0A/* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_CCF_ASSIST + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_FWNMI_MCE + 1)/* * Capability Values target/ppc/kvm.c +14
-0@@ -83,6 +83,7 @@ static int cap_ppc_safe_indirect_branch;static int cap_ppc_count_cache_flush_assist;static int cap_ppc_nested_kvm_hv;static int cap_large_decr; +static int cap_ppc_fwnmi;static uint32_t debug_inst_opcode;@@ -150,6 +151,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)kvmppc_get_cpu_characteristics (s); cap_ppc_nested_kvm_hv =kvm_vm_check_extension (s,KVM_CAP_PPC_NESTED_HV ); cap_large_decr =kvmppc_get_dec_bits (); + cap_ppc_fwnmi =kvm_check_extension (s,KVM_CAP_PPC_FWNMI );/* * Note: setting it to false because there is not such capability * in KVM at this moment. @@ -2117,6 +2119,18 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) } } +int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); + +if (!cap_ppc_fwnmi) { +return 1 ; + } + +return kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_FWNMI ,0 ); +} + +int kvmppc_smt_threads (void ) {return cap_ppc_smt ? cap_ppc_smt :1 ;target/ppc/kvm_ppc.h +6
-0@@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);void kvmppc_set_papr (PowerPCCPU *cpu);int kvmppc_set_compat (PowerPCCPU *cpu,uint32_t compat_pvr);void kvmppc_set_mpic_proxy (PowerPCCPU *cpu,int mpic_proxy); +int kvmppc_fwnmi_enable (PowerPCCPU *cpu);int kvmppc_smt_threads (void );void kvmppc_hint_smt_possible (Error **errp);int kvmppc_set_smt_threads (int smt);@@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) { } +static inline int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +return 1 ; +} +static inline int kvmppc_smt_threads (void ) {return 1 ;
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 5/6] ppc: spapr: Enable FWNMI capability
Quoted 110 lines · David Gibson
Quoted 109 lines · Aravinda Prasad
Enable the KVM capability
KVM_CAP_PPC_FWNMIso that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's0x200vector.This patch also deals with the case when a guest with the
KVM_CAP_PPC_FWNMIcapability enabled is attempted to migrate to a host that does not support this capability.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)hw/ppc/spapr.c +1
-0@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;hw/ppc/spapr_caps.c +26
-0@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {hw/ppc/spapr_rtas.c +2
-0@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; }
Quoted 6 lines
hw/ppc/spapr_rtas.c static void rtas_ibm_nmi_register(PowerPCCPU *cpu, · line 366
Quoted 1 line
hw/ppc/spapr_rtas.c +1
-0+ ret =kvmppc_fwnmi_enable (cpu);You shouldn't need this here as well as in
cap_fwnmi_mce_apply().Instead, you should unconditionally fail the nmi-register if the capability is not enabled.
cap_fwnmi is not enabled by default, because if it is enabled by default them KVM will start routing machine check exceptions via guest exit instead of routing it to guest's 0x200.
During early boot since guest has not yet issued nmi-register, KVM is expected to route exceptions to 0x200. Therefore we enable cap_fwnmi only when a guest issues nmi-register.
Or we should take the approach of enabling this capability by default and then from QEMU route the error to 0x200 if guest has not issued nmi-register.
Quoted 95 lines
Quoted 94 lines
hw/ppc/spapr_rtas.c +10
-0+if (ret ==1 ) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + +if (ret <0 ) { +rtas_st (rets,0 ,RTAS_OUT_HW_ERROR ); +return ; + } + spapr->guest_machine_check_addr =rtas_ld (args,1 );rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +3
-1@@ -78,8 +78,10 @@ typedef enum {#define SPAPR_CAP_LARGE_DECREMENTER 0x08/* Count Cache Flush Assist HW Instruction */ #define SPAPR_CAP_CCF_ASSIST 0x09 +/* FWNMI machine check handling */ +#define SPAPR_CAP_FWNMI_MCE 0x0A/* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_CCF_ASSIST + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_FWNMI_MCE + 1)/* * Capability Values target/ppc/kvm.c +14
-0@@ -83,6 +83,7 @@ static int cap_ppc_safe_indirect_branch;static int cap_ppc_count_cache_flush_assist;static int cap_ppc_nested_kvm_hv;static int cap_large_decr; +static int cap_ppc_fwnmi;static uint32_t debug_inst_opcode;@@ -150,6 +151,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)kvmppc_get_cpu_characteristics (s); cap_ppc_nested_kvm_hv =kvm_vm_check_extension (s,KVM_CAP_PPC_NESTED_HV ); cap_large_decr =kvmppc_get_dec_bits (); + cap_ppc_fwnmi =kvm_check_extension (s,KVM_CAP_PPC_FWNMI );/* * Note: setting it to false because there is not such capability * in KVM at this moment. @@ -2117,6 +2119,18 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) } } +int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); + +if (!cap_ppc_fwnmi) { +return 1 ; + } + +return kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_FWNMI ,0 ); +} + +int kvmppc_smt_threads (void ) {return cap_ppc_smt ? cap_ppc_smt :1 ;target/ppc/kvm_ppc.h +6
-0@@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);void kvmppc_set_papr (PowerPCCPU *cpu);int kvmppc_set_compat (PowerPCCPU *cpu,uint32_t compat_pvr);void kvmppc_set_mpic_proxy (PowerPCCPU *cpu,int mpic_proxy); +int kvmppc_fwnmi_enable (PowerPCCPU *cpu);int kvmppc_smt_threads (void );void kvmppc_hint_smt_possible (Error **errp);int kvmppc_set_smt_threads (int smt);@@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) { } +static inline int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +return 1 ; +} +static inline int kvmppc_smt_threads (void ) {return 1 ;
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 5/6] ppc: spapr: Enable FWNMI capability
Quoted 120 lines · Aravinda Prasad
Quoted 110 lines · David Gibson
Quoted 109 lines · Aravinda Prasad
Enable the KVM capability
KVM_CAP_PPC_FWNMIso that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's0x200vector.This patch also deals with the case when a guest with the
KVM_CAP_PPC_FWNMIcapability enabled is attempted to migrate to a host that does not support this capability.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)hw/ppc/spapr.c +1
-0@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;hw/ppc/spapr_caps.c +26
-0@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {hw/ppc/spapr_rtas.c +2
-0@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; }Quoted 6 lines
hw/ppc/spapr_rtas.c static void rtas_ibm_nmi_register(PowerPCCPU *cpu, · line 366
Quoted 1 line
hw/ppc/spapr_rtas.c +1
-0+ ret =kvmppc_fwnmi_enable (cpu);You shouldn't need this here as well as in
cap_fwnmi_mce_apply().Instead, you should unconditionally fail the nmi-register if the capability is not enabled.
Quoted 7 lines
cap_fwnmiis not enabled by default, because if it is enabled by default them KVM will start routing machine check exceptions via guest exit instead of routing it to guest's0x200.During early boot since guest has not yet issued nmi-register, KVM is expected to route exceptions to
0x200. Therefore we enablecap_fwnmionly when a guest issues nmi-register.
Except that's not true - you enable it in cap_fwnmi_mce_apply() which will be executed whenever the machine capability is enabled.
Quoted 100 lines
Or we should take the approach of enabling this capability by default and then from QEMU route the error to
0x200if guest has not issued nmi-register.Quoted 95 lines
Quoted 94 lines
hw/ppc/spapr_rtas.c +10
-0+if (ret ==1 ) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + +if (ret <0 ) { +rtas_st (rets,0 ,RTAS_OUT_HW_ERROR ); +return ; + } + spapr->guest_machine_check_addr =rtas_ld (args,1 );rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +3
-1@@ -78,8 +78,10 @@ typedef enum {#define SPAPR_CAP_LARGE_DECREMENTER 0x08/* Count Cache Flush Assist HW Instruction */ #define SPAPR_CAP_CCF_ASSIST 0x09 +/* FWNMI machine check handling */ +#define SPAPR_CAP_FWNMI_MCE 0x0A/* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_CCF_ASSIST + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_FWNMI_MCE + 1)/* * Capability Values target/ppc/kvm.c +14
-0@@ -83,6 +83,7 @@ static int cap_ppc_safe_indirect_branch;static int cap_ppc_count_cache_flush_assist;static int cap_ppc_nested_kvm_hv;static int cap_large_decr; +static int cap_ppc_fwnmi;static uint32_t debug_inst_opcode;@@ -150,6 +151,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)kvmppc_get_cpu_characteristics (s); cap_ppc_nested_kvm_hv =kvm_vm_check_extension (s,KVM_CAP_PPC_NESTED_HV ); cap_large_decr =kvmppc_get_dec_bits (); + cap_ppc_fwnmi =kvm_check_extension (s,KVM_CAP_PPC_FWNMI );/* * Note: setting it to false because there is not such capability * in KVM at this moment. @@ -2117,6 +2119,18 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) } } +int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); + +if (!cap_ppc_fwnmi) { +return 1 ; + } + +return kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_FWNMI ,0 ); +} + +int kvmppc_smt_threads (void ) {return cap_ppc_smt ? cap_ppc_smt :1 ;target/ppc/kvm_ppc.h +6
-0@@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);void kvmppc_set_papr (PowerPCCPU *cpu);int kvmppc_set_compat (PowerPCCPU *cpu,uint32_t compat_pvr);void kvmppc_set_mpic_proxy (PowerPCCPU *cpu,int mpic_proxy); +int kvmppc_fwnmi_enable (PowerPCCPU *cpu);int kvmppc_smt_threads (void );void kvmppc_hint_smt_possible (Error **errp);int kvmppc_set_smt_threads (int smt);@@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) { } +static inline int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +return 1 ; +} +static inline int kvmppc_smt_threads (void ) {return 1 ;
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 5/6] ppc: spapr: Enable FWNMI capability
Quoted 125 lines · David Gibson
Quoted 124 lines · Aravinda Prasad
Quoted 110 lines · David Gibson
Quoted 109 lines · Aravinda Prasad
Enable the KVM capability
KVM_CAP_PPC_FWNMIso that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's0x200vector.This patch also deals with the case when a guest with the
KVM_CAP_PPC_FWNMIcapability enabled is attempted to migrate to a host that does not support this capability.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)hw/ppc/spapr.c +1
-0@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;hw/ppc/spapr_caps.c +26
-0@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {hw/ppc/spapr_rtas.c +2
-0@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; }Quoted 6 lines
hw/ppc/spapr_rtas.c static void rtas_ibm_nmi_register(PowerPCCPU *cpu, · line 366
Quoted 1 line
hw/ppc/spapr_rtas.c +1
-0+ ret =kvmppc_fwnmi_enable (cpu);You shouldn't need this here as well as in
cap_fwnmi_mce_apply().Instead, you should unconditionally fail the nmi-register if the capability is not enabled.
cap_fwnmiis not enabled by default, because if it is enabled by default them KVM will start routing machine check exceptions via guest exit instead of routing it to guest's0x200.
Quoted 6 lines
Quoted 3 lines
During early boot since guest has not yet issued nmi-register, KVM is expected to route exceptions to
0x200. Therefore we enablecap_fwnmionly when a guest issues nmi-register.Except that's not true - you enable it in
cap_fwnmi_mce_apply()which will be executed whenever the machine capability is enabled.
I enable cap_fwnmi in cap_fwnmi_mce_apply() only when the "val" argument (which is the effective cap value) is set. In early boot "val" is not set as cap_fwnmi by default is not set, hence cap_fwnmi is not enabled.
My understanding is that, cap_fwnmi_mce_apply() is also called during migration on the target machine. If effective cap for cap_fwnmi is enabled on source machine than I think "val" will be set when cap_fwnmi_mce_apply() is called on target machine. I then call kvmppc_fwnmi_enable() to enable cap_fwnmi on target.
Regards,
Aravinda
Quoted 102 lines
Quoted 101 lines
Or we should take the approach of enabling this capability by default and then from QEMU route the error to
0x200if guest has not issued nmi-register.Quoted 95 lines
Quoted 94 lines
hw/ppc/spapr_rtas.c +10
-0+if (ret ==1 ) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + +if (ret <0 ) { +rtas_st (rets,0 ,RTAS_OUT_HW_ERROR ); +return ; + } + spapr->guest_machine_check_addr =rtas_ld (args,1 );rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +3
-1@@ -78,8 +78,10 @@ typedef enum {#define SPAPR_CAP_LARGE_DECREMENTER 0x08/* Count Cache Flush Assist HW Instruction */ #define SPAPR_CAP_CCF_ASSIST 0x09 +/* FWNMI machine check handling */ +#define SPAPR_CAP_FWNMI_MCE 0x0A/* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_CCF_ASSIST + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_FWNMI_MCE + 1)/* * Capability Values target/ppc/kvm.c +14
-0@@ -83,6 +83,7 @@ static int cap_ppc_safe_indirect_branch;static int cap_ppc_count_cache_flush_assist;static int cap_ppc_nested_kvm_hv;static int cap_large_decr; +static int cap_ppc_fwnmi;static uint32_t debug_inst_opcode;@@ -150,6 +151,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)kvmppc_get_cpu_characteristics (s); cap_ppc_nested_kvm_hv =kvm_vm_check_extension (s,KVM_CAP_PPC_NESTED_HV ); cap_large_decr =kvmppc_get_dec_bits (); + cap_ppc_fwnmi =kvm_check_extension (s,KVM_CAP_PPC_FWNMI );/* * Note: setting it to false because there is not such capability * in KVM at this moment. @@ -2117,6 +2119,18 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) } } +int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); + +if (!cap_ppc_fwnmi) { +return 1 ; + } + +return kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_FWNMI ,0 ); +} + +int kvmppc_smt_threads (void ) {return cap_ppc_smt ? cap_ppc_smt :1 ;target/ppc/kvm_ppc.h +6
-0@@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);void kvmppc_set_papr (PowerPCCPU *cpu);int kvmppc_set_compat (PowerPCCPU *cpu,uint32_t compat_pvr);void kvmppc_set_mpic_proxy (PowerPCCPU *cpu,int mpic_proxy); +int kvmppc_fwnmi_enable (PowerPCCPU *cpu);int kvmppc_smt_threads (void );void kvmppc_hint_smt_possible (Error **errp);int kvmppc_set_smt_threads (int smt);@@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) { } +static inline int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +return 1 ; +} +static inline int kvmppc_smt_threads (void ) {return 1 ;
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 5/6] ppc: spapr: Enable FWNMI capability
Quoted 132 lines · Aravinda Prasad
Quoted 129 lines · David Gibson
Quoted 127 lines · Aravinda Prasad
Quoted 110 lines · David Gibson
Quoted 109 lines · Aravinda Prasad
Enable the KVM capability
KVM_CAP_PPC_FWNMIso that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's0x200vector.This patch also deals with the case when a guest with the
KVM_CAP_PPC_FWNMIcapability enabled is attempted to migrate to a host that does not support this capability.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)hw/ppc/spapr.c +1
-0@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;hw/ppc/spapr_caps.c +26
-0@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {hw/ppc/spapr_rtas.c +2
-0@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; }Quoted 6 lines
hw/ppc/spapr_rtas.c static void rtas_ibm_nmi_register(PowerPCCPU *cpu, · line 366
Quoted 1 line
hw/ppc/spapr_rtas.c +1
-0+ ret =kvmppc_fwnmi_enable (cpu);You shouldn't need this here as well as in
cap_fwnmi_mce_apply().Instead, you should unconditionally fail the nmi-register if the capability is not enabled.
cap_fwnmiis not enabled by default, because if it is enabled by default them KVM will start routing machine check exceptions via guest exit instead of routing it to guest's0x200.During early boot since guest has not yet issued nmi-register, KVM is expected to route exceptions to
0x200. Therefore we enablecap_fwnmionly when a guest issues nmi-register.
Quoted 7 lines
Quoted 2 lines
Except that's not true - you enable it in
cap_fwnmi_mce_apply()which will be executed whenever the machine capability is enabled.I enable
cap_fwnmiincap_fwnmi_mce_apply()only when the "val" argument (which is the effective cap value) is set. In early boot "val" is not set ascap_fwnmiby default is not set, hencecap_fwnmiis not enabled.
Uh.. if that's true, something else is horribly wrong. SPAPR caps are designed to have a fixed value for the lifetime of the VM. Otherwise they will fail in their purpose of making sure we have a consistent environment across migrations. So if the 'val' changes after the first call to apply(), then something is broken.
Quoted 3 lines
My understanding is that,
cap_fwnmi_mce_apply()is also called during migration on the target machine.
Only in the sense that the machine is initialized before processing the incoming migration. The capability values must be equal on either side of the migration (that's checked elsewhere). Well, actually, you're allowed to increase the cap value across a migration, just not decrease it.
Quoted 3 lines
If effective cap for
cap_fwnmiis
enabled on source machine than I think "val" will be set whencap_fwnmi_mce_apply()is called on target machine.
Nope. The migrated value of the cap will be *validated* against the value set on the destination setup, but it won't *alter* the value on the destination (the result is that you have it enabled on the source, but not the destination, the migration will fail).
Quoted 109 lines
I then call
kvmppc_fwnmi_enable()to enablecap_fwnmion target.Regards,
AravindaQuoted 102 lines
Quoted 101 lines
Or we should take the approach of enabling this capability by default and then from QEMU route the error to
0x200if guest has not issued nmi-register.Quoted 95 lines
Quoted 94 lines
hw/ppc/spapr_rtas.c +10
-0+if (ret ==1 ) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + +if (ret <0 ) { +rtas_st (rets,0 ,RTAS_OUT_HW_ERROR ); +return ; + } + spapr->guest_machine_check_addr =rtas_ld (args,1 );rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +3
-1@@ -78,8 +78,10 @@ typedef enum {#define SPAPR_CAP_LARGE_DECREMENTER 0x08/* Count Cache Flush Assist HW Instruction */ #define SPAPR_CAP_CCF_ASSIST 0x09 +/* FWNMI machine check handling */ +#define SPAPR_CAP_FWNMI_MCE 0x0A/* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_CCF_ASSIST + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_FWNMI_MCE + 1)/* * Capability Values target/ppc/kvm.c +14
-0@@ -83,6 +83,7 @@ static int cap_ppc_safe_indirect_branch;static int cap_ppc_count_cache_flush_assist;static int cap_ppc_nested_kvm_hv;static int cap_large_decr; +static int cap_ppc_fwnmi;static uint32_t debug_inst_opcode;@@ -150,6 +151,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)kvmppc_get_cpu_characteristics (s); cap_ppc_nested_kvm_hv =kvm_vm_check_extension (s,KVM_CAP_PPC_NESTED_HV ); cap_large_decr =kvmppc_get_dec_bits (); + cap_ppc_fwnmi =kvm_check_extension (s,KVM_CAP_PPC_FWNMI );/* * Note: setting it to false because there is not such capability * in KVM at this moment. @@ -2117,6 +2119,18 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) } } +int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); + +if (!cap_ppc_fwnmi) { +return 1 ; + } + +return kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_FWNMI ,0 ); +} + +int kvmppc_smt_threads (void ) {return cap_ppc_smt ? cap_ppc_smt :1 ;target/ppc/kvm_ppc.h +6
-0@@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);void kvmppc_set_papr (PowerPCCPU *cpu);int kvmppc_set_compat (PowerPCCPU *cpu,uint32_t compat_pvr);void kvmppc_set_mpic_proxy (PowerPCCPU *cpu,int mpic_proxy); +int kvmppc_fwnmi_enable (PowerPCCPU *cpu);int kvmppc_smt_threads (void );void kvmppc_hint_smt_possible (Error **errp);int kvmppc_set_smt_threads (int smt);@@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) { } +static inline int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +return 1 ; +} +static inline int kvmppc_smt_threads (void ) {return 1 ;
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 5/6] ppc: spapr: Enable FWNMI capability
Quoted 141 lines · David Gibson
Quoted 132 lines · Aravinda Prasad
Quoted 129 lines · David Gibson
Quoted 127 lines · Aravinda Prasad
Quoted 110 lines · David Gibson
Quoted 109 lines · Aravinda Prasad
Enable the KVM capability
KVM_CAP_PPC_FWNMIso that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's0x200vector.This patch also deals with the case when a guest with the
KVM_CAP_PPC_FWNMIcapability enabled is attempted to migrate to a host that does not support this capability.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)hw/ppc/spapr.c +1
-0@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;hw/ppc/spapr_caps.c +26
-0@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {hw/ppc/spapr_rtas.c +2
-0@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; }Quoted 6 lines
hw/ppc/spapr_rtas.c static void rtas_ibm_nmi_register(PowerPCCPU *cpu, · line 366
Quoted 1 line
hw/ppc/spapr_rtas.c +1
-0+ ret =kvmppc_fwnmi_enable (cpu);You shouldn't need this here as well as in
cap_fwnmi_mce_apply().Instead, you should unconditionally fail the nmi-register if the capability is not enabled.
cap_fwnmiis not enabled by default, because if it is enabled by default them KVM will start routing machine check exceptions via guest exit instead of routing it to guest's0x200.During early boot since guest has not yet issued nmi-register, KVM is expected to route exceptions to
0x200. Therefore we enablecap_fwnmionly when a guest issues nmi-register.Quoted 7 lines
Quoted 2 lines
Except that's not true - you enable it in
cap_fwnmi_mce_apply()which will be executed whenever the machine capability is enabled.I enable
cap_fwnmiincap_fwnmi_mce_apply()only when the "val" argument (which is the effective cap value) is set. In early boot "val" is not set ascap_fwnmiby default is not set, hencecap_fwnmiis not enabled.
Quoted 5 lines
Uh.. if that's true, something else is horribly wrong. SPAPR caps are designed to have a fixed value for the lifetime of the VM. Otherwise they will fail in their purpose of making sure we have a consistent environment across migrations. So if the 'val' changes after the first call to
apply(), then something is broken.
If SPAPR caps are initialized before boot that do not change later, then for cap_fwnmi, the default value is off at boot and the cap is enabled only when guest issues "ibm,nmi-register" call. Should SPAPR caps be updated when "ibm,nmi-register" is called?
Quoted 10 lines
Quoted 4 lines
My understanding is that,
cap_fwnmi_mce_apply()is also called during migration on the target machine.Only in the sense that the machine is initialized before processing the incoming migration. The capability values must be equal on either side of the migration (that's checked elsewhere). Well, actually, you're allowed to increase the cap value across a migration, just not decrease it.
Ah.. ok.. I am still familiarizing myself with the migration code..
Quoted 9 lines
Quoted 4 lines
If effective cap for
cap_fwnmiis
enabled on source machine than I think "val" will be set whencap_fwnmi_mce_apply()is called on target machine.Nope. The migrated value of the cap will be *validated* against the value set on the destination setup, but it won't *alter* the value on the destination (the result is that you have it enabled on the source, but not the destination, the migration will fail).
But if cap_fwnmi is set on the host, which function is responsible to enable it on the destination? I think cap_fwnmi_mce_apply() is responsible for enabling it on the destination. If that is the case cap_fwnmi_mce_apply() should know if cap_fwnmi is set on the host and the only way it can check that is based on the "val" argument passed on to it.
Or am I missing something here?
Regards,
Aravinda
Quoted 111 lines
Quoted 110 lines
I then call
kvmppc_fwnmi_enable()to enablecap_fwnmion target.Regards,
AravindaQuoted 102 lines
Quoted 101 lines
Or we should take the approach of enabling this capability by default and then from QEMU route the error to
0x200if guest has not issued nmi-register.Quoted 95 lines
Quoted 94 lines
hw/ppc/spapr_rtas.c +10
-0+if (ret ==1 ) { +rtas_st (rets,0 ,RTAS_OUT_NOT_SUPPORTED ); +return ; + } + +if (ret <0 ) { +rtas_st (rets,0 ,RTAS_OUT_HW_ERROR ); +return ; + } + spapr->guest_machine_check_addr =rtas_ld (args,1 );rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); }include/hw/ppc/spapr.h +3
-1@@ -78,8 +78,10 @@ typedef enum {#define SPAPR_CAP_LARGE_DECREMENTER 0x08/* Count Cache Flush Assist HW Instruction */ #define SPAPR_CAP_CCF_ASSIST 0x09 +/* FWNMI machine check handling */ +#define SPAPR_CAP_FWNMI_MCE 0x0A/* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_CCF_ASSIST + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_FWNMI_MCE + 1)/* * Capability Values target/ppc/kvm.c +14
-0@@ -83,6 +83,7 @@ static int cap_ppc_safe_indirect_branch;static int cap_ppc_count_cache_flush_assist;static int cap_ppc_nested_kvm_hv;static int cap_large_decr; +static int cap_ppc_fwnmi;static uint32_t debug_inst_opcode;@@ -150,6 +151,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)kvmppc_get_cpu_characteristics (s); cap_ppc_nested_kvm_hv =kvm_vm_check_extension (s,KVM_CAP_PPC_NESTED_HV ); cap_large_decr =kvmppc_get_dec_bits (); + cap_ppc_fwnmi =kvm_check_extension (s,KVM_CAP_PPC_FWNMI );/* * Note: setting it to false because there is not such capability * in KVM at this moment. @@ -2117,6 +2119,18 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) } } +int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); + +if (!cap_ppc_fwnmi) { +return 1 ; + } + +return kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_FWNMI ,0 ); +} + +int kvmppc_smt_threads (void ) {return cap_ppc_smt ? cap_ppc_smt :1 ;target/ppc/kvm_ppc.h +6
-0@@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);void kvmppc_set_papr (PowerPCCPU *cpu);int kvmppc_set_compat (PowerPCCPU *cpu,uint32_t compat_pvr);void kvmppc_set_mpic_proxy (PowerPCCPU *cpu,int mpic_proxy); +int kvmppc_fwnmi_enable (PowerPCCPU *cpu);int kvmppc_smt_threads (void );void kvmppc_hint_smt_possible (Error **errp);int kvmppc_set_smt_threads (int smt);@@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) { } +static inline int kvmppc_fwnmi_enable (PowerPCCPU *cpu) +{ +return 1 ; +} +static inline int kvmppc_smt_threads (void ) {return 1 ;
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 5/6] ppc: spapr: Enable FWNMI capability
Quoted 150 lines · Aravinda Prasad
Quoted 141 lines · David Gibson
Quoted 132 lines · Aravinda Prasad
Quoted 129 lines · David Gibson
Quoted 127 lines · Aravinda Prasad
Quoted 110 lines · David Gibson
Quoted 109 lines · Aravinda Prasad
Enable the KVM capability
KVM_CAP_PPC_FWNMIso that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's0x200vector.This patch also deals with the case when a guest with the
KVM_CAP_PPC_FWNMIcapability enabled is attempted to migrate to a host that does not support this capability.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)hw/ppc/spapr.c +1
-0@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;hw/ppc/spapr_caps.c +26
-0@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {hw/ppc/spapr_rtas.c +2
-0@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; }Quoted 6 lines
hw/ppc/spapr_rtas.c static void rtas_ibm_nmi_register(PowerPCCPU *cpu, · line 366
Quoted 1 line
hw/ppc/spapr_rtas.c +1
-0+ ret =kvmppc_fwnmi_enable (cpu);You shouldn't need this here as well as in
cap_fwnmi_mce_apply().Instead, you should unconditionally fail the nmi-register if the capability is not enabled.
cap_fwnmiis not enabled by default, because if it is enabled by default them KVM will start routing machine check exceptions via guest exit instead of routing it to guest's0x200.During early boot since guest has not yet issued nmi-register, KVM is expected to route exceptions to
0x200. Therefore we enablecap_fwnmionly when a guest issues nmi-register.Quoted 7 lines
Quoted 2 lines
Except that's not true - you enable it in
cap_fwnmi_mce_apply()which will be executed whenever the machine capability is enabled.I enable
cap_fwnmiincap_fwnmi_mce_apply()only when the "val" argument (which is the effective cap value) is set. In early boot "val" is not set ascap_fwnmiby default is not set, hencecap_fwnmiis not enabled.Quoted 5 lines
Uh.. if that's true, something else is horribly wrong. SPAPR caps are designed to have a fixed value for the lifetime of the VM. Otherwise they will fail in their purpose of making sure we have a consistent environment across migrations. So if the 'val' changes after the first call to
apply(), then something is broken.
Quoted 4 lines
If SPAPR caps are initialized before boot that do not change later, then for
cap_fwnmi, the default value is off at boot and the cap is enabled only when guest issues "ibm,nmi-register" call. Should SPAPR caps be updated when "ibm,nmi-register" is called?
So the confusing thing here is that there are spapr machine caps, and those are separate from the KVM caps for the VM. Then the KVM caps also have whether the cap is possible and whether it is current activated.
The spapr machine caps *must* remain static for the VM's lifetime and only cover possibilities, not runtime configuration. KVM caps may be activated as necessary.
So you can leave activating the KVM cap until nmi-register. But if the spapr cap is disabled you must prohibit nmi-register.
The apply() functions are responsible for checking if the spapr caps are possible on the KVM implementation. So if cap_fwnmi_mci_apply() is called with val==1 and KVM doesn't support the fwnmi extensions, it must fail outright.
Quoted 16 lines
Quoted 8 lines
Quoted 2 lines
My understanding is that,
cap_fwnmi_mce_apply()is also called during migration on the target machine.Only in the sense that the machine is initialized before processing the incoming migration. The capability values must be equal on either side of the migration (that's checked elsewhere). Well, actually, you're allowed to increase the cap value across a migration, just not decrease it.
Ah.. ok.. I am still familiarizing myself with the migration code..
Quoted 5 lines
Quoted 4 lines
If effective cap for
cap_fwnmiis
enabled on source machine than I think "val" will be set whencap_fwnmi_mce_apply()is called on target machine.
Quoted 6 lines
Quoted 4 lines
Nope. The migrated value of the cap will be *validated* against the value set on the destination setup, but it won't *alter* the value on the destination (the result is that you have it enabled on the source, but not the destination, the migration will fail).
But if
cap_fwnmiis set on the host, which function is responsible to
I'm not sure what you mean by "the host" here.
Quoted 2 lines
enable it on the destination? I think
cap_fwnmi_mce_apply()is responsible for enabling it on the destination.
Enabling the spapr cap? It is set based on the command line and machine type, just like on the source machine.
Quoted 6 lines
If that is the case
cap_fwnmi_mce_apply()should know ifcap_fwnmiis set on the host and the only way it can check that is based on the "val" argument passed on to it.Or am I missing something here?
Probably, but I'm not sure exactly what.
The val argument to apply() is set to the value of the spapr cap. This is based on the qemu command line and machine type, and must be the same on source and destination. As a general rule, qemu requires that the same machine options are used on source and destination.
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 5/6] ppc: spapr: Enable FWNMI capability
Quoted 165 lines · David Gibson
Quoted 150 lines · Aravinda Prasad
Quoted 141 lines · David Gibson
Quoted 132 lines · Aravinda Prasad
Quoted 129 lines · David Gibson
Quoted 127 lines · Aravinda Prasad
Quoted 110 lines · David Gibson
Quoted 109 lines · Aravinda Prasad
Enable the KVM capability
KVM_CAP_PPC_FWNMIso that the KVM causes guest exit with NMI as exit reason when it encounters a machine check exception on the address belonging to a guest. Without this capability enabled, KVM redirects machine check exceptions to guest's0x200vector.This patch also deals with the case when a guest with the
KVM_CAP_PPC_FWNMIcapability enabled is attempted to migrate to a host that does not support this capability.Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 14 ++++++++++++++ include/hw/ppc/spapr.h | 4 +++- target/ppc/kvm.c | 14 ++++++++++++++ target/ppc/kvm_ppc.h | 6 ++++++ 6 files changed, 64 insertions(+), 1 deletion(-)hw/ppc/spapr.c +1
-0@@ -4372,6 +4372,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV ] =SPAPR_CAP_OFF ; smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER ] =SPAPR_CAP_ON ; smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST ] =SPAPR_CAP_OFF ; + smc->default_caps.caps[SPAPR_CAP_FWNMI_MCE ] =SPAPR_CAP_OFF ;spapr_caps_add_properties (smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true;hw/ppc/spapr_caps.c +26
-0@@ -473,6 +473,22 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, } } +static void cap_fwnmi_mce_apply (SpaprMachineState *spapr,uint8_t val, +Error **errp) +{ +PowerPCCPU *cpu =POWERPC_CPU (first_cpu); + +if (!val) { +return ;/* Disabled by default */ + } + +if (kvm_enabled ()) { +if (kvmppc_fwnmi_enable (cpu)) { +error_setg (errp,"Requested fwnmi capability not support by KVM" ); + } + } +} +SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM ] = { [SPAPR_CAP_HTM ] = { .name ="htm" ,@@ -571,6 +587,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_ccf_assist_apply, }, + [SPAPR_CAP_FWNMI_MCE] = { + .name = "fwnmi-mce", + .description = "Handle fwnmi machine check exceptions", + .index = SPAPR_CAP_FWNMI_MCE, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_fwnmi_mce_apply, + }, }; static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,@@ -706,6 +731,7 @@ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);SPAPR_CAP_MIG_STATE (nested_kvm_hv,SPAPR_CAP_NESTED_KVM_HV );SPAPR_CAP_MIG_STATE (large_decr,SPAPR_CAP_LARGE_DECREMENTER );SPAPR_CAP_MIG_STATE (ccf_assist,SPAPR_CAP_CCF_ASSIST ); +SPAPR_CAP_MIG_STATE (fwnmi,SPAPR_CAP_FWNMI_MCE );void spapr_caps_init (SpaprMachineState *spapr) {hw/ppc/spapr_rtas.c +2
-0@@ -49,6 +49,7 @@#include "hw/ppc/fdt.h" #include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" +#include "kvm_ppc.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -354,6 +355,7 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,target_ulong args, uint32_t nret, target_ulong rets) { + int ret;uint64_t rtas_addr =spapr_get_rtas_addr ();if (!rtas_addr) {@@ -361,6 +363,18 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu,return ; }Quoted 6 lines
hw/ppc/spapr_rtas.c static void rtas_ibm_nmi_register(PowerPCCPU *cpu, · line 366
Quoted 1 line
hw/ppc/spapr_rtas.c +1
-0+ ret =kvmppc_fwnmi_enable (cpu);You shouldn't need this here as well as in
cap_fwnmi_mce_apply().Instead, you should unconditionally fail the nmi-register if the capability is not enabled.
cap_fwnmiis not enabled by default, because if it is enabled by default them KVM will start routing machine check exceptions via guest exit instead of routing it to guest's0x200.During early boot since guest has not yet issued nmi-register, KVM is expected to route exceptions to
0x200. Therefore we enablecap_fwnmionly when a guest issues nmi-register.Quoted 7 lines
Quoted 2 lines
Except that's not true - you enable it in
cap_fwnmi_mce_apply()which will be executed whenever the machine capability is enabled.I enable
cap_fwnmiincap_fwnmi_mce_apply()only when the "val" argument (which is the effective cap value) is set. In early boot "val" is not set ascap_fwnmiby default is not set, hencecap_fwnmiis not enabled.Quoted 5 lines
Uh.. if that's true, something else is horribly wrong. SPAPR caps are designed to have a fixed value for the lifetime of the VM. Otherwise they will fail in their purpose of making sure we have a consistent environment across migrations. So if the 'val' changes after the first call to
apply(), then something is broken.Quoted 4 lines
If SPAPR caps are initialized before boot that do not change later, then for
cap_fwnmi, the default value is off at boot and the cap is enabled only when guest issues "ibm,nmi-register" call. Should SPAPR caps be updated when "ibm,nmi-register" is called?So the confusing thing here is that there are spapr machine caps, and those are separate from the KVM caps for the VM. Then the KVM caps also have whether the cap is possible and whether it is current activated.
The spapr machine caps *must* remain static for the VM's lifetime and only cover possibilities, not runtime configuration. KVM caps may be activated as necessary.
Quoted 7 lines
So you can leave activating the KVM cap until nmi-register. But if the spapr cap is disabled you must prohibit nmi-register.
The
apply()functions are responsible for checking if the spapr caps are possible on the KVM implementation. So ifcap_fwnmi_mci_apply()is called with val==1 and KVM doesn't support the fwnmi extensions, it must fail outright.
I see, this clears my confusion on spapr machine caps and KVM caps..
Quoted 37 lines
Quoted 17 lines
Quoted 9 lines
Quoted 3 lines
My understanding is that,
cap_fwnmi_mce_apply()is also called during migration on the target machine.Only in the sense that the machine is initialized before processing the incoming migration. The capability values must be equal on either side of the migration (that's checked elsewhere). Well, actually, you're allowed to increase the cap value across a migration, just not decrease it.
Ah.. ok.. I am still familiarizing myself with the migration code..
Quoted 5 lines
Quoted 4 lines
If effective cap for
cap_fwnmiis
enabled on source machine than I think "val" will be set whencap_fwnmi_mce_apply()is called on target machine.Quoted 6 lines
Quoted 4 lines
Nope. The migrated value of the cap will be *validated* against the value set on the destination setup, but it won't *alter* the value on the destination (the result is that you have it enabled on the source, but not the destination, the migration will fail).
But if
cap_fwnmiis set on the host, which function is responsible toI'm not sure what you mean by "the host" here.
Quoted 2 lines
enable it on the destination? I think
cap_fwnmi_mce_apply()is responsible for enabling it on the destination.Enabling the spapr cap? It is set based on the command line and machine type, just like on the source machine.
Quoted 5 lines
If that is the case
cap_fwnmi_mce_apply()should know ifcap_fwnmiis set on the host and the only way it can check that is based on the "val" argument passed on to it.
Quoted 8 lines
Quoted 1 line
Or am I missing something here?
Probably, but I'm not sure exactly what.
The val argument to
apply()is set to the value of the spapr cap. This is based on the qemu command line and machine type, and must be the same on source and destination. As a general rule, qemu requires that the same machine options are used on source and destination.
Please ignore my previous statements this was made without clear understanding of spapr machine caps and KVM caps.
I will resend the patches with the modifications.
Quoted 1 line
Signature · 2 lines
Regards, Aravinda
PATCH v8 6/6 migration: Block migration while handling machine check
In reply to Aravinda PrasadBlock VM migration requests until the machine check error handling is complete as (i) these errors are specific to the source hardware and is irrelevant on the target hardware, (ii) these errors cause data corruption and should be handled before migration.
--- hw/ppc/spapr_events.c | 17 +++++++++++++++++ hw/ppc/spapr_rtas.c | 4 ++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 24 insertions(+)
hw/ppc/spapr_events.c +17 -0
@@ -41,6 +41,7 @@#include "qemu/bcd.h" #include "hw/ppc/spapr_ovec.h" #include <libfdt.h> +#include "migration/blocker.h" #define RTAS_LOG_VERSION_MASK 0xff000000#define RTAS_LOG_VERSION_6 0x06000000
@@ -864,6 +865,22 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered)void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int ret; +Error *local_err =NULL ; + +error_setg (&spapr->migration_blocker, +"Live migration not supported during machine check handling" ); + ret =migrate_add_blocker (spapr->migration_blocker, &local_err); +if (ret <0 ) { +/* +* We don't want to abort and let the migration to continue. In a +* rare case, the machine check handler will run on the target +* hardware. Though this is not preferable, it is better than aborting +* the migration or killing the VM. +*/ +error_free (spapr->migration_blocker); +fprintf (stderr,"Warning: Machine check during VM migration\n" ); + }while (spapr->mc_status !=-1 ) {/*
hw/ppc/spapr_rtas.c +4 -0
@@ -50,6 +50,7 @@#include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" #include "kvm_ppc.h" +#include "migration/blocker.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,
@@ -396,6 +397,9 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +migrate_del_blocker (spapr->migration_blocker); +error_free (spapr->migration_blocker); + spapr->migration_blocker =NULL ; } }
include/hw/ppc/spapr.h +3 -0
@@ -10,6 +10,7 @@#include "hw/ppc/spapr_irq.h" #include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ +#include "qapi/error.h" struct SpaprVioBus ;struct SpaprPhbState ;
@@ -213,6 +214,8 @@ struct SpaprMachineState {SpaprCapabilities def, eff, mig;unsigned gpu_numa_id; + +Error *migration_blocker; };#define H_SUCCESS 0
Re: [Qemu-devel] [PATCH v8 6/6] migration: Block migration while handling machine check
Quoted 34 lines · Aravinda Prasad
Block VM migration requests until the machine check error handling is complete as (i) these errors are specific to the source hardware and is irrelevant on the target hardware, (ii) these errors cause data corruption and should be handled before migration.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr_events.c | 17 +++++++++++++++++ hw/ppc/spapr_rtas.c | 4 ++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 24 insertions(+)hw/ppc/spapr_events.c +6
-0@@ -41,6 +41,7 @@#include "qemu/bcd.h" #include "hw/ppc/spapr_ovec.h" #include <libfdt.h> +#include "migration/blocker.h" #define RTAS_LOG_VERSION_MASK 0xff000000#define RTAS_LOG_VERSION_6 0x06000000@@ -864,6 +865,22 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered)void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int ret; +Error *local_err =NULL ; + +error_setg (&spapr->migration_blocker, +"Live migration not supported during machine check handling" );
hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 882
Quoted 10 lines
hw/ppc/spapr_events.c +10
-0+ ret =migrate_add_blocker (spapr->migration_blocker, &local_err); +if (ret <0 ) { +/* +* We don't want to abort and let the migration to continue. In a +* rare case, the machine check handler will run on the target +* hardware. Though this is not preferable, it is better than aborting +* the migration or killing the VM. +*/ +error_free (spapr->migration_blocker); +fprintf (stderr,"Warning: Machine check during VM migration\n" );
Use report_err() instead of a raw fprintf().
Quoted 39 lines
hw/ppc/spapr_events.c +1
-0+ }while (spapr->mc_status !=-1 ) {/* hw/ppc/spapr_rtas.c +4
-0@@ -50,6 +50,7 @@#include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" #include "kvm_ppc.h" +#include "migration/blocker.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -396,6 +397,9 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +migrate_del_blocker (spapr->migration_blocker); +error_free (spapr->migration_blocker); + spapr->migration_blocker =NULL ; } }include/hw/ppc/spapr.h +1
-0@@ -10,6 +10,7 @@#include "hw/ppc/spapr_irq.h" #include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ +#include "qapi/error.h" struct SpaprVioBus ;struct SpaprPhbState ;
include/hw/ppc/spapr.h struct SpaprMachineState { · line 218
Quoted 5 lines
include/hw/ppc/spapr.h +2
-0@@ -213,6 +214,8 @@ struct SpaprMachineState {SpaprCapabilities def, eff, mig;unsigned gpu_numa_id; + +Error *migration_blocker;
This name doesn't seem good - it's specific to fwnmi, not any other migration blockers we might have in future. It also always contains the same string - could you just initialize that in a global and just do the migrate_add_blocker() / migrate_del_blocker() instead?
Quoted 4 lines
include/hw/ppc/spapr.h +0
-0};#define H_SUCCESS 0
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
Re: [Qemu-devel] [PATCH v8 6/6] migration: Block migration while handling machine check
Quoted 39 lines · David Gibson
Quoted 38 lines · Aravinda Prasad
Block VM migration requests until the machine check error handling is complete as (i) these errors are specific to the source hardware and is irrelevant on the target hardware, (ii) these errors cause data corruption and should be handled before migration.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr_events.c | 17 +++++++++++++++++ hw/ppc/spapr_rtas.c | 4 ++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 24 insertions(+)hw/ppc/spapr_events.c +10
-0@@ -41,6 +41,7 @@#include "qemu/bcd.h" #include "hw/ppc/spapr_ovec.h" #include <libfdt.h> +#include "migration/blocker.h" #define RTAS_LOG_VERSION_MASK 0xff000000#define RTAS_LOG_VERSION_6 0x06000000@@ -864,6 +865,22 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered)void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int ret; +Error *local_err =NULL ; + +error_setg (&spapr->migration_blocker, +"Live migration not supported during machine check handling" ); + ret =migrate_add_blocker (spapr->migration_blocker, &local_err); +if (ret <0 ) { +/* +* We don't want to abort and let the migration to continue. In a
Quoted 8 lines
hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 882
Quoted 6 lines
hw/ppc/spapr_events.c +6
-0+* rare case, the machine check handler will run on the target +* hardware. Though this is not preferable, it is better than aborting +* the migration or killing the VM. +*/ +error_free (spapr->migration_blocker); +fprintf (stderr,"Warning: Machine check during VM migration\n" );Use
report_err()instead of a rawfprintf().
sure..
Quoted 42 lines
Quoted 42 lines
hw/ppc/spapr_events.c +1
-0+ }while (spapr->mc_status !=-1 ) {/* hw/ppc/spapr_rtas.c +4
-0@@ -50,6 +50,7 @@#include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" #include "kvm_ppc.h" +#include "migration/blocker.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -396,6 +397,9 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +migrate_del_blocker (spapr->migration_blocker); +error_free (spapr->migration_blocker); + spapr->migration_blocker =NULL ; } }include/hw/ppc/spapr.h +1
-0@@ -10,6 +10,7 @@#include "hw/ppc/spapr_irq.h" #include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ +#include "qapi/error.h" struct SpaprVioBus ;struct SpaprPhbState ;@@ -213,6 +214,8 @@ struct SpaprMachineState {SpaprCapabilities def, eff, mig;
Quoted 8 lines
include/hw/ppc/spapr.h struct SpaprMachineState { · line 218
Quoted 3 lines
include/hw/ppc/spapr.h +2
-0unsigned gpu_numa_id; + +Error *migration_blocker;This name doesn't seem good - it's specific to fwnmi, not any other migration blockers we might have in future. It also always contains the same string - could you just initialize that in a global and just do the
migrate_add_blocker()/migrate_del_blocker()instead?
sure..
Quoted 6 lines
Quoted 5 lines
include/hw/ppc/spapr.h +0
-0};#define H_SUCCESS 0
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 6/6] migration: Block migration while handling machine check
In reply to David GibsonQuoted 89 lines · David Gibson
Quoted 34 lines · Aravinda Prasad
Block VM migration requests until the machine check error handling is complete as (i) these errors are specific to the source hardware and is irrelevant on the target hardware, (ii) these errors cause data corruption and should be handled before migration.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr_events.c | 17 +++++++++++++++++ hw/ppc/spapr_rtas.c | 4 ++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 24 insertions(+)hw/ppc/spapr_events.c +6
-0@@ -41,6 +41,7 @@#include "qemu/bcd.h" #include "hw/ppc/spapr_ovec.h" #include <libfdt.h> +#include "migration/blocker.h" #define RTAS_LOG_VERSION_MASK 0xff000000#define RTAS_LOG_VERSION_6 0x06000000@@ -864,6 +865,22 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered)void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int ret; +Error *local_err =NULL ; + +error_setg (&spapr->migration_blocker, +"Live migration not supported during machine check handling" );hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 882
Quoted 10 lines
hw/ppc/spapr_events.c +10
-0+ ret =migrate_add_blocker (spapr->migration_blocker, &local_err); +if (ret <0 ) { +/* +* We don't want to abort and let the migration to continue. In a +* rare case, the machine check handler will run on the target +* hardware. Though this is not preferable, it is better than aborting +* the migration or killing the VM. +*/ +error_free (spapr->migration_blocker); +fprintf (stderr,"Warning: Machine check during VM migration\n" );Use
report_err()instead of a rawfprintf().Quoted 41 lines
hw/ppc/spapr_events.c +1
-0+ }while (spapr->mc_status !=-1 ) {/* hw/ppc/spapr_rtas.c +4
-0@@ -50,6 +50,7 @@#include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" #include "kvm_ppc.h" +#include "migration/blocker.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -396,6 +397,9 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +migrate_del_blocker (spapr->migration_blocker); +error_free (spapr->migration_blocker); + spapr->migration_blocker =NULL ; } }include/hw/ppc/spapr.h +1
-0@@ -10,6 +10,7 @@#include "hw/ppc/spapr_irq.h" #include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ +#include "qapi/error.h" struct SpaprVioBus ;struct SpaprPhbState ;@@ -213,6 +214,8 @@ struct SpaprMachineState {SpaprCapabilities def, eff, mig;
Quoted 8 lines
include/hw/ppc/spapr.h struct SpaprMachineState { · line 218
Quoted 3 lines
include/hw/ppc/spapr.h +2
-0unsigned gpu_numa_id; + +Error *migration_blocker;This name doesn't seem good - it's specific to fwnmi, not any other migration blockers we might have in future. It also always contains the same string - could you just initialize that in a global and just do the
migrate_add_blocker()/migrate_del_blocker()instead?
I retained it in SpaprMachineState instead of a global variable because we add the blocker in spapr_events.c and delete it in spapr_rtas.c
But I have renamed it to fwnmi_migration_blocker.
Regards,
Aravinda
Quoted 6 lines
Quoted 5 lines
include/hw/ppc/spapr.h +0
-0};#define H_SUCCESS 0
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 6/6] migration: Block migration while handling machine check
In reply to Aravinda PrasadQuoted 26 lines · On Mon, 22 Apr 2019 12:33:45 +0530 Aravinda Prasad…
Block VM migration requests until the machine check error handling is complete as (i) these errors are specific to the source hardware and is irrelevant on the target hardware, (ii) these errors cause data corruption and should be handled before migration.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr_events.c | 17 +++++++++++++++++ hw/ppc/spapr_rtas.c | 4 ++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 24 insertions(+)hw/ppc/spapr_events.c +1
-0@@ -41,6 +41,7 @@#include "qemu/bcd.h" #include "hw/ppc/spapr_ovec.h" #include <libfdt.h> +#include "migration/blocker.h" #define RTAS_LOG_VERSION_MASK 0xff000000#define RTAS_LOG_VERSION_6 0x06000000
hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 873
Quoted 9 lines
hw/ppc/spapr_events.c +6
-0@@ -864,6 +865,22 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered)void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int ret; +Error *local_err =NULL ; + +error_setg (&spapr->migration_blocker, +"Live migration not supported during machine check handling" ); + ret =migrate_add_blocker (spapr->migration_blocker, &local_err);
migrate_add_blocker() propagates the reason of the failure in local_err, ie. because a migration is already in progress or --only-migratable was passed on the QEMU command line, along with the error message passed in the first argument. This means that...
hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 882
Quoted 9 lines
hw/ppc/spapr_events.c +9
-0+if (ret <0 ) { +/* +* We don't want to abort and let the migration to continue. In a +* rare case, the machine check handler will run on the target +* hardware. Though this is not preferable, it is better than aborting +* the migration or killing the VM. +*/ +error_free (spapr->migration_blocker); +fprintf (stderr,"Warning: Machine check during VM migration\n" );
... you should just do:
error_report_err(local_err);
This also takes care of freeing local_err which would be leaked otherwise.
Quoted 49 lines
hw/ppc/spapr_events.c +1
-0+ }while (spapr->mc_status !=-1 ) {/* hw/ppc/spapr_rtas.c +4
-0@@ -50,6 +50,7 @@#include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" #include "kvm_ppc.h" +#include "migration/blocker.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -396,6 +397,9 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +migrate_del_blocker (spapr->migration_blocker); +error_free (spapr->migration_blocker); + spapr->migration_blocker =NULL ; } }include/hw/ppc/spapr.h +3
-0@@ -10,6 +10,7 @@#include "hw/ppc/spapr_irq.h" #include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ +#include "qapi/error.h" struct SpaprVioBus ;struct SpaprPhbState ;@@ -213,6 +214,8 @@ struct SpaprMachineState {SpaprCapabilities def, eff, mig;unsigned gpu_numa_id; + +Error *migration_blocker; };#define H_SUCCESS 0
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 6/6] migration: Block migration while handling machine check
Quoted 54 lines · Greg Kurz
Quoted 26 lines · On Mon, 22 Apr 2019 12:33:45 +0530 Aravinda Prasad…
Block VM migration requests until the machine check error handling is complete as (i) these errors are specific to the source hardware and is irrelevant on the target hardware, (ii) these errors cause data corruption and should be handled before migration.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr_events.c | 17 +++++++++++++++++ hw/ppc/spapr_rtas.c | 4 ++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 24 insertions(+)hw/ppc/spapr_events.c +1
-0@@ -41,6 +41,7 @@#include "qemu/bcd.h" #include "hw/ppc/spapr_ovec.h" #include <libfdt.h> +#include "migration/blocker.h" #define RTAS_LOG_VERSION_MASK 0xff000000#define RTAS_LOG_VERSION_6 0x06000000hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 873
Quoted 9 lines
hw/ppc/spapr_events.c +6
-0@@ -864,6 +865,22 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered)void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int ret; +Error *local_err =NULL ; + +error_setg (&spapr->migration_blocker, +"Live migration not supported during machine check handling" ); + ret =migrate_add_blocker (spapr->migration_blocker, &local_err);
migrate_add_blocker()propagates the reason of the failure inlocal_err, ie. because a migration is already in progress or --only-migratable was passed on the QEMU command line, along with the error message passed in the first argument. This means that...hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 882
Quoted 9 lines
hw/ppc/spapr_events.c +9
-0+if (ret <0 ) { +/* +* We don't want to abort and let the migration to continue. In a +* rare case, the machine check handler will run on the target +* hardware. Though this is not preferable, it is better than aborting +* the migration or killing the VM. +*/ +error_free (spapr->migration_blocker); +fprintf (stderr,"Warning: Machine check during VM migration\n" );
Quoted 5 lines
... you should just do:
error_report_err(local_err);This also takes care of freeing
local_errwhich would be leaked otherwise.
Sure. I am planning to use warn_report_err() as I don't want to abort.
Regards,
Aravinda
Quoted 51 lines
Quoted 50 lines
hw/ppc/spapr_events.c +1
-0+ }while (spapr->mc_status !=-1 ) {/* hw/ppc/spapr_rtas.c +4
-0@@ -50,6 +50,7 @@#include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" #include "kvm_ppc.h" +#include "migration/blocker.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -396,6 +397,9 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +migrate_del_blocker (spapr->migration_blocker); +error_free (spapr->migration_blocker); + spapr->migration_blocker =NULL ; } }include/hw/ppc/spapr.h +3
-0@@ -10,6 +10,7 @@#include "hw/ppc/spapr_irq.h" #include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ +#include "qapi/error.h" struct SpaprVioBus ;struct SpaprPhbState ;@@ -213,6 +214,8 @@ struct SpaprMachineState {SpaprCapabilities def, eff, mig;unsigned gpu_numa_id; + +Error *migration_blocker; };#define H_SUCCESS 0
Signature · 2 lines
Regards, Aravinda
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 6/6] migration: Block migration while handling machine check
Quoted 57 lines · * Aravinda Prasad ([email protected]) wrote:
Quoted 54 lines · Greg Kurz
Quoted 26 lines · On Mon, 22 Apr 2019 12:33:45 +0530 Aravinda Prasad…
Block VM migration requests until the machine check error handling is complete as (i) these errors are specific to the source hardware and is irrelevant on the target hardware, (ii) these errors cause data corruption and should be handled before migration.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr_events.c | 17 +++++++++++++++++ hw/ppc/spapr_rtas.c | 4 ++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 24 insertions(+)hw/ppc/spapr_events.c +1
-0@@ -41,6 +41,7 @@#include "qemu/bcd.h" #include "hw/ppc/spapr_ovec.h" #include <libfdt.h> +#include "migration/blocker.h" #define RTAS_LOG_VERSION_MASK 0xff000000#define RTAS_LOG_VERSION_6 0x06000000hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 873
Quoted 9 lines
hw/ppc/spapr_events.c +6
-0@@ -864,6 +865,22 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered)void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int ret; +Error *local_err =NULL ; + +error_setg (&spapr->migration_blocker, +"Live migration not supported during machine check handling" ); + ret =migrate_add_blocker (spapr->migration_blocker, &local_err);
migrate_add_blocker()propagates the reason of the failure inlocal_err, ie. because a migration is already in progress or --only-migratable was passed on the QEMU command line, along with the error message passed in the first argument. This means that...Quoted 9 lines
hw/ppc/spapr_events.c +9
-0+if (ret <0 ) { +/* +* We don't want to abort and let the migration to continue. In a +* rare case, the machine check handler will run on the target +* hardware. Though this is not preferable, it is better than aborting +* the migration or killing the VM. +*/ +error_free (spapr->migration_blocker); +fprintf (stderr,"Warning: Machine check during VM migration\n" );
Quoted 7 lines
Quoted 5 lines
... you should just do:
error_report_err(local_err);This also takes care of freeing
local_errwhich would be leaked otherwise.Sure. I am planning to use
warn_report_err()as I don't want to abort.
I worry what the high level effect of this blocker will be. Since failing hardware is a common reason for wanting to do a migrate I worry that if the hardware is reporting lots of errors you might not be able to migrate the VM to more solid hardware because of this blocker.
Dave
Quoted 50 lines
Regards,
AravindaQuoted 47 lines
Quoted 47 lines
hw/ppc/spapr_events.c +1
-0+ }while (spapr->mc_status !=-1 ) {/* hw/ppc/spapr_rtas.c +4
-0@@ -50,6 +50,7 @@#include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" #include "kvm_ppc.h" +#include "migration/blocker.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -396,6 +397,9 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +migrate_del_blocker (spapr->migration_blocker); +error_free (spapr->migration_blocker); + spapr->migration_blocker =NULL ; } }include/hw/ppc/spapr.h +3
-0@@ -10,6 +10,7 @@#include "hw/ppc/spapr_irq.h" #include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ +#include "qapi/error.h" struct SpaprVioBus ;struct SpaprPhbState ;@@ -213,6 +214,8 @@ struct SpaprMachineState {SpaprCapabilities def, eff, mig;unsigned gpu_numa_id; + +Error *migration_blocker; };
Quoted 10 lines
Quoted 4 lines
Quoted 3 lines
include/hw/ppc/spapr.h +0
-0#define H_SUCCESS 0Signature · 2 lines
Regards, Aravinda
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [Qemu-ppc] [PATCH v8 6/6] migration: Block migration while handling machine check
Quoted 64 lines · Dr. David Alan Gilbert
Quoted 63 lines · * Aravinda Prasad ([email protected]) wrote:
Quoted 59 lines · Greg Kurz
Quoted 26 lines · On Mon, 22 Apr 2019 12:33:45 +0530 Aravinda Prasad…
Block VM migration requests until the machine check error handling is complete as (i) these errors are specific to the source hardware and is irrelevant on the target hardware, (ii) these errors cause data corruption and should be handled before migration.
Signed-off-by Aravinda Prasad <[email protected]>--- hw/ppc/spapr_events.c | 17 +++++++++++++++++ hw/ppc/spapr_rtas.c | 4 ++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 24 insertions(+)hw/ppc/spapr_events.c +1
-0@@ -41,6 +41,7 @@#include "qemu/bcd.h" #include "hw/ppc/spapr_ovec.h" #include <libfdt.h> +#include "migration/blocker.h" #define RTAS_LOG_VERSION_MASK 0xff000000#define RTAS_LOG_VERSION_6 0x06000000hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 873
Quoted 9 lines
hw/ppc/spapr_events.c +6
-0@@ -864,6 +865,22 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered)void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered) {SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int ret; +Error *local_err =NULL ; + +error_setg (&spapr->migration_blocker, +"Live migration not supported during machine check handling" ); + ret =migrate_add_blocker (spapr->migration_blocker, &local_err);
migrate_add_blocker()propagates the reason of the failure inlocal_err, ie. because a migration is already in progress or --only-migratable was passed on the QEMU command line, along with the error message passed in the first argument. This means that...hw/ppc/spapr_events.c static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) · line 882
Quoted 9 lines
hw/ppc/spapr_events.c +9
-0+if (ret <0 ) { +/* +* We don't want to abort and let the migration to continue. In a +* rare case, the machine check handler will run on the target +* hardware. Though this is not preferable, it is better than aborting +* the migration or killing the VM. +*/ +error_free (spapr->migration_blocker); +fprintf (stderr,"Warning: Machine check during VM migration\n" );... you should just do:
error_report_err(local_err);This also takes care of freeing
local_errwhich would be leaked otherwise.
Quoted 7 lines
Quoted 1 line
Sure. I am planning to use
warn_report_err()as I don't want to abort.I worry what the high level effect of this blocker will be. Since failing hardware is a common reason for wanting to do a migrate I worry that if the hardware is reporting lots of errors you might not be able to migrate the VM to more solid hardware because of this blocker.
We handle two cases, (i) migration initiated during error handling which we block as we don't want to migrate when we are handling the error. For example, for memory errors, we need to take some actions like poisoning the page. If we allow migration during error handling, the handler may execute on the target host and may poison a clean page on the target. But, a migration retry will succeed, (ii) errors reported after migration is initiated: in such cases we let the migration continue without blocking/aborting.
This is because memory errors are not very frequent, but are still important to handle as it can cause data corruption. However, if the hardware is reporting lots of errors, then the chances of host itself crashing is very high.
Quoted 66 lines
Dave
Quoted 50 lines
Regards,
AravindaQuoted 47 lines
Quoted 47 lines
hw/ppc/spapr_events.c +1
-0+ }while (spapr->mc_status !=-1 ) {/* hw/ppc/spapr_rtas.c +4
-0@@ -50,6 +50,7 @@#include "target/ppc/mmu-hash64.h" #include "target/ppc/mmu-book3s-v3.h" #include "kvm_ppc.h" +#include "migration/blocker.h" static void rtas_display_character(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs,@@ -396,6 +397,9 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, spapr->mc_status =-1 ;qemu_cond_signal (&spapr->mc_delivery_cond);rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); +migrate_del_blocker (spapr->migration_blocker); +error_free (spapr->migration_blocker); + spapr->migration_blocker =NULL ; } }include/hw/ppc/spapr.h +3
-0@@ -10,6 +10,7 @@#include "hw/ppc/spapr_irq.h" #include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ +#include "qapi/error.h" struct SpaprVioBus ;struct SpaprPhbState ;@@ -213,6 +214,8 @@ struct SpaprMachineState {SpaprCapabilities def, eff, mig;unsigned gpu_numa_id; + +Error *migration_blocker; };Quoted 10 lines
Quoted 4 lines
Quoted 3 lines
include/hw/ppc/spapr.h +0
-0#define H_SUCCESS 0Signature · 2 lines
Regards, Aravinda--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Signature · 2 lines
Regards, Aravinda