Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4224244ybi; Mon, 29 Jul 2019 21:58:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyn0YVzjdZkhbE7XDHaVqnUnmrq/ODYb+QfDyDx6+N5DkqohqxZgknaAlGa0bXnKOuJk3ab X-Received: by 2002:aa7:818b:: with SMTP id g11mr40496624pfi.122.1564462694333; Mon, 29 Jul 2019 21:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564462694; cv=none; d=google.com; s=arc-20160816; b=diTmuXejBn3G39fbGt9kka4zMI3V8lXKX/fg+HMeNACKZ0wVtfrlG7Qqc7OHMEfkdN VB874EGIzn9itaJEIBnvhW3yN4Xop2tbFpTnEfDuyIxdTKDXaStrIGl3wAqo4N9y7fw4 EjX1XtZVBIorGZr/CSnMGKYuwWh41HsZDZyW4lQ7l1WeQ7qoodqgHuMdqTudHNGPrnE8 9sykaCz0CJTN2mF2femMImccsZNsoSwCMTS58ChnoA1p/I07lC9zwXtN4VZPjA0I4JsB JNgFKfXOYbB68eYIMjVnBcN+fQ7gJ78Ey95iWXoMQWOO61Appya2HBV6JSKisx2uP8IU xR6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=AySx+87TRNHh7fT2Oht4v5u7cEESnj3F99hVA5n0QCw=; b=iKcIyZ7GeEkGLaE6oZS5VyQ+YC01jtpts8CMx9TW7OSSUY7g/WEeL30WHH5Cn2vf31 uvhVyR+URcACErcGNECKJVWvK1tzoX8908ZL3BGzPyXsmKiD+Exq0qY99BE0w6NVc/TE eEKy9fSjq8WfU91XRFSaeJyEcuQQfsXZFu4Nyn2aBSQ2GyT7m+8XbDZ+b8SVS75hvRLY XkvRC87VycqKW5LvCkn1qjMy3eC5dEGznDW1YWaEyYu7YvznAI8V/l0cdDhAG+IAv+5D 149Mm/JAELTABixo5dOOXOKt2A4PUTgmJgayP9qxuZSsVITZK/J+MB+9j2oCfe9wLhRs QaXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z197si28074605pgz.267.2019.07.29.21.57.59; Mon, 29 Jul 2019 21:58:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731498AbfG3Ctm (ORCPT + 99 others); Mon, 29 Jul 2019 22:49:42 -0400 Received: from mga04.intel.com ([192.55.52.120]:43707 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730760AbfG3Ctl (ORCPT ); Mon, 29 Jul 2019 22:49:41 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2019 19:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,325,1559545200"; d="scan'208";a="346858151" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by orsmga005.jf.intel.com with ESMTP; 29 Jul 2019 19:49:41 -0700 Date: Mon, 29 Jul 2019 19:49:40 -0700 From: Sean Christopherson To: Andy Lutomirski Cc: Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , Borislav Petkov , X86 ML , Jarkko Sakkinen , Joerg Roedel , "H. Peter Anvin" , kvm list , LKML , linux-sgx@vger.kernel.org Subject: Re: [RFC PATCH 08/21] KVM: x86: Add kvm_x86_ops hook to short circuit emulation Message-ID: <20190730024940.GL21120@linux.intel.com> References: <20190727055214.9282-1-sean.j.christopherson@intel.com> <20190727055214.9282-9-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 27, 2019 at 10:38:03AM -0700, Andy Lutomirski wrote: > On Fri, Jul 26, 2019 at 10:52 PM Sean Christopherson > wrote: > > > > Similar to the existing AMD #NPF case where emulation of the current > > instruction is not possible due to lack of information, virtualization > > of Intel SGX will introduce a scenario where emulation is not possible > > due to the VMExit occurring in an SGX enclave. And again similar to > > the AMD case, emulation can be initiated by kvm_mmu_page_fault(), i.e. > > outside of the control of the vendor-specific code. > > > > While the cause and architecturally visible behavior of the two cases > > is different, e.g. Intel SGX will inject a #UD whereas AMD #NPF is a > > clean resume or complete shutdown, the impact on the common emulation > > code is identical: KVM must stop emulation immediately and resume the > > guest. > > > > Replace the exisiting need_emulation_on_page_fault() with a more generic > > is_emulatable() kvm_x86_ops callback, which is called unconditionally > > by x86_emulate_instruction(). > > > > Having recently noticed that emulate_ud() is broken when the guest's > TF is set, I suppose I should ask: does your new code function > sensibly when TF is set? Barring a VMX fault injection interaction I'm not thinking of, yes. The SGX reaction to the #UD VM-Exit is to inject a #UD and resume the guest, pending breakpoints shouldn't be affected in any way (unless some other part of KVM mucks with them, e.g. when guest single-stepping is enabled).