From: "Jan Beulich" Subject: Re: [RFH]: AMD CR intercept for lmsw/clts Date: Tue, 05 Aug 2014 08:46:20 +0100 Message-ID: <53E0A7EC02000078000294FF@mail.emea.novell.com> References: <20140804183337.2bb1b680@mantra.us.oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XEZRw-00032W-WC for xen-devel@lists.xenproject.org; Tue, 05 Aug 2014 07:46:25 +0000 In-Reply-To: <20140804183337.2bb1b680@mantra.us.oracle.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Mukesh Rathor Cc: xen-devel , boris.ostrovsky@oracle.com, Aravind.Gopalakrishnan@amd.com, suravee.suthikulpanit@amd.com List-Id: xen-devel@lists.xenproject.org >>> On 05.08.14 at 03:33, wrote: > Hi, > > On AMD, clts/lmsw will cause "mov cr" vmexit, but unlike intel, they > can't be handled via svm_vmexit_do_cr_access and are emulated thru > handle_mmio() which is a problem for pvh because of: > > handle_mmio(): > .. > ASSERT(!is_pvh_vcpu(curr)); > > AMD CR intercepts in svm.c: > case VMEXIT_CR0_READ ... VMEXIT_CR15_READ: > case VMEXIT_CR0_WRITE ... VMEXIT_CR15_WRITE: > if ( cpu_has_svm_decode && (vmcb->exitinfo1 & (1ULL << 63)) ) > svm_vmexit_do_cr_access(vmcb, regs); > else if ( !handle_mmio() ) <========== > hvm_inject_hw_exception(TRAP_gp_fault, 0); > break; > > Soooo, this leaves no choice but to make the ASSERT conditional > for intel only, and let handle_mmio go thru x86_emulate and let > x86_emulate fail for anything other than lmsw/clts? I was thinking > something like: > > x86_emulate() > int fail_pvh_emul = 1; > ... > case lmsw/clts: > ..... > fail_pvh_emul = 0; > > then > done: > if (fail_pvh_emul) > rc = X86EMUL_UNHANDLEABLE; > return rc; I'd strongly recommend against adding any such to x86_emulate(): There's nothing precluding the emulator to be used for PVH guests. > Or, should I just create a new function for clts/lmsw and call it > directly from vmexit switch itself? I'd prefer this - it seems pretty ugly to me that handle_mmio()/ x86_emulate() gets used for this purpose - but am not certain this will actually work out nicely for other than CLTS: All the instructions currently handled specially are ones with fixed operands, and only CLTS fits that. You'll btw have the same problem with SMSW and DRx accesses, string I/O instructions, as well as (on older CPUs) with moves to/from CRx and INVLPG. In the case this doesn't turn out reasonable, rather than manipulating handle_mmio() any further, I'd suggest to investigate bypassing that function in favor of a more direct access to the x86 emulator. After all you're not after any MMIO emulation here, just bare instructions (many of which without memory operands at all). Jan