On Fri, Mar 22, 2019 at 12:04:16PM +0530, Aravinda Prasad wrote: > Enable 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. > > Signed-off-by: Aravinda Prasad <aravi...@linux.vnet.ibm.com> > --- > hw/ppc/spapr_rtas.c | 15 +++++++++++++++ > target/ppc/kvm.c | 14 ++++++++++++++ > target/ppc/kvm_ppc.h | 6 ++++++ > 3 files changed, 35 insertions(+) > > diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c > index fb594a4..939f428 100644 > --- a/hw/ppc/spapr_rtas.c > +++ b/hw/ppc/spapr_rtas.c > @@ -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,20 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu, > target_ulong args, > uint32_t nret, target_ulong rets) > { > + int ret; > + > + ret = kvmppc_fwnmi_enable(cpu); > + > + if (ret == 1) { > + rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED);
Urgh, we're here making a guest visible different to the environment depending on a host (KVM) capability. What happens if you start a guest and it registers fwnmi support, then migrate it to a host that lacks the necessary KVM support? > + return; > + } > + > + if (ret < 0) { > + rtas_st(rets, 0, RTAS_OUT_HW_ERROR); > + return; > + } > + > spapr->mc_reset = 0; > spapr->guest_machine_check_addr = rtas_ld(args, 1); > rtas_st(rets, 0, RTAS_OUT_SUCCESS); > diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c > index a593448..161b45e 100644 > --- a/target/ppc/kvm.c > +++ b/target/ppc/kvm.c > @@ -93,6 +93,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; > > @@ -155,6 +156,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. > @@ -2091,6 +2093,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; > diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h > index df5e85f..cf7b24f 100644 > --- a/target/ppc/kvm_ppc.h > +++ b/target/ppc/kvm_ppc.h > @@ -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); > @@ -158,6 +159,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU > *cpu, int mpic_proxy) > { > } > > +int kvmppc_fwnmi_enable(PowerPCCPU *cpu) > +{ > + return 1; > +} > + > static inline int kvmppc_smt_threads(void) > { > return 1; > -- 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
signature.asc
Description: PGP signature