From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liran Alon Subject: Re: [PATCH 2/3] KVM: x86: emulator: Return to user-mode on L1 CPL=0 emulation failure Date: Mon, 06 Nov 2017 16:08:29 +0200 Message-ID: <5A006CDD.8020700@ORACLE.COM> References: <1509891703-9735-1-git-send-email-liran.alon@oracle.com> <1509891703-9735-3-git-send-email-liran.alon@oracle.com> <61331a1d-3f34-9328-ec28-c223d67fe1e9@redhat.com> <5A0062DC.4030806@ORACLE.COM> <13d602ff-e5f7-18a1-68e2-8c7b3c81cc54@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: idan.brown@ORACLE.COM, Liran Alon , Konrad Rzeszutek Wilk To: Paolo Bonzini , rkrcmar@redhat.com, kvm@vger.kernel.org Return-path: Received: from userp1040.oracle.com ([156.151.31.81]:21735 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753250AbdKFOIj (ORCPT ); Mon, 6 Nov 2017 09:08:39 -0500 In-Reply-To: <13d602ff-e5f7-18a1-68e2-8c7b3c81cc54@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 06/11/17 15:50, Paolo Bonzini wrote: > On 06/11/2017 14:25, Liran Alon wrote: >>> What is the caller of x86_emulate_instruction that you are interested >>> in? #UD is not affected, because emulation_type has EMULTYPE_TRAP_UD >>> set and therefore x86_emulate_instruction exits before invoking >>> handle_emulation_failure. >>> >> I think this patch is still correct from a number of reasons: >> >> 1) If I understand the code correctly, semantically it doesn't make >> sense to fill kvm_run struct without exiting to user-mode. Therefore, if >> emulator filled kvm_run, it makes sense that it needs to return >> EMULATE_USER_EXIT. >> >> 2) EMULTYPE_TRAP_UD only causes the emulator to return EMULATE_FAIL in >> case emulation fails on instruction decoding. However, consider a case >> where #UD intercept happens on a valid instruction (such as VMMCALL AMD >> opcode on physical Intel CPU). In that case, instruction decoding >> doesn't fail but we could still fail on instruction emulation at >> x86_emulate_insn(). In this case, EMULTYPE_TRAP_UD flag is not >> considered anymore and failure will reach handle_emulation_failure(). > > (1) is true, but (2) more or less answers my question. So > > Reviewed-by: Paolo Bonzini > >> 3) We have another KVM commits series (not upstream yet) that adds >> intercept on #GP which calls the x86 emulator. This is done to allow >> access to I/O ports even though they aren't allowed via guest's TSS I/O >> permissions bitmap. > > vmport?... :) Yep. Stay tuned. :) > > Paolo >