On Thu, Jul 21, 2022, Maxim Levitsky wrote: > On Wed, 2022-07-20 at 23:44 +0000, Sean Christopherson wrote: > > On Tue, Jun 21, 2022, Maxim Levitsky wrote: > > > + if (!ctxt->ops->get_cr(ctxt, 0) & X86_CR0_PE) { > > > + /* Real mode. cpu must not have long mode active */ > > > + if (efer & EFER_LMA) > > > + return X86EMUL_UNHANDLEABLE; > > > > If we hit this, is there any hope of X86EMUL_UNHANDLEABLE doing the right thing? > > Ah, SMM and the ability to swizzle SMRAM state. Bummer. I was hoping we could > > just bug the VM. > > I just tried to be a good citizen here, it is probably impossible to hit this case. > (RSM ignores LMA bit in the EFER in the SMRAM). The reason I asked is because if all of the X86EMUL_UNHANDLEABLE paths are impossible then my preference would be to refactor this slightly to: static int emulator_calc_cpu_mode(const struct x86_emulate_ctxt *ctxt) and return the mode instead of success/failure, and turn those checks into: KVM_EMULATOR_BUG_ON(efer & EFER_LMA); with the callers being: ctxt->mode = emulator_calc_cpu_mode(ctxt); But I think this one: if (!ctxt->ops->get_segment(ctxt, &selector, &cs, &base3, VCPU_SREG_CS)) return X86EMUL_UNHANDLEABLE; is reachable in the em_rsm() case :-/