Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp694133pxk; Wed, 23 Sep 2020 13:34:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWK7iL64/383r4Iu0KRWC+CBJ8M2GTgE2I0u/STmxviOpVK6oqQvD0t0ZpefxdwK0c6dML X-Received: by 2002:a05:6402:1b0f:: with SMTP id by15mr1088262edb.289.1600893255894; Wed, 23 Sep 2020 13:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600893255; cv=none; d=google.com; s=arc-20160816; b=WdVxRMT3HytQ5eSsRITBINNfKcd/eFbAuJe9aAyG/Clg9ZDaNFq4knDyDBqM4cu0Jk S3YHMg0TLzAQwuzUiRgIf3Z9SNz8fXjKraZ6+31IjHBng6aPdZguodBxnyAVgBpqtj3W xRGQeave8TGZldbdhjEn3BbfYNg6Nm78gal/lRDq/wHcF4fvUJqzzNFEuf2Z/NgLIdMp 5iGfn3sWbjnD5VKvjwqCQx1lJGG/KMpgo4L/1kfexWUdSRppK+eKmHiqKw/ZC6dMaK6Z rD1QfqzirDncbsooOdhiCD/5ejNDV1GEPaNor60aV3f5JNywkqKYo4KVCZ3lf2W85dGr YCrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=dHAn3ZLZCuGSQvyk8I3YofuxQ8MpoY8hX/DhK3mic18=; b=nFHlgOGb2+IYrk5/uYtgRezDY90huhm3XfjR2/zGaO0BXOCfSjHgTGplWhu/ZfGbhZ jhNTB6ASiaNfeRc7Z5SqyvdiFVCYyXojY/WBNppfXoNAs0s9TEPVHr3P24lRDnBh3jEJ tQjhK9DH/XTKa0sMSDtWjJiEJrk3a2sbWmZjaXIfjIbleYBr7KOIeCd8yERyAsyS8OL3 q4E2+8y2ThZ7OzCZ7OPxRxJ2WhryzBAziFxiOeFfdkAzHcIBrRy9UOZv2/C7teBt61ZQ Yi0ZJ/2OAgR3UE94bkK8t7GRVvTMUq5ze/2wRlRA3m7WqG+sHx5Ou6G3DYtmw/ajXy05 9fSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id o18si613713ejg.313.2020.09.23.13.33.52; Wed, 23 Sep 2020 13:34:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726687AbgIWUcn (ORCPT + 99 others); Wed, 23 Sep 2020 16:32:43 -0400 Received: from mga02.intel.com ([134.134.136.20]:29989 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726199AbgIWUcn (ORCPT ); Wed, 23 Sep 2020 16:32:43 -0400 IronPort-SDR: 9e2y1rgsCX8jCW7Na5+RcQr51AIIejnc8gZNR+ea6Jt1HfbGlDMxsKHlrB6y1OJy7x0/QRxmnW W+iwdGhmuAnw== X-IronPort-AV: E=McAfee;i="6000,8403,9753"; a="148671925" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="148671925" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 13:32:42 -0700 IronPort-SDR: fxOz/CIz2/QbwXtGn/prqnou9Y8Rak3zk58kOA1JAX1tCFC73+wy3UHL0WhFU83zgOqaLviSgr YpwoC4tuUNNw== X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="486593724" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.160]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 13:32:42 -0700 Date: Wed, 23 Sep 2020 13:32:41 -0700 From: Sean Christopherson To: Tom Lendacky Cc: kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Brijesh Singh , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: Re: [PATCH] KVM: SVM: Add a dedicated INVD intercept routine Message-ID: <20200923203241.GB15101@linux.intel.com> References: <16f36f9a51608758211c54564cd17c8b909372f1.1600892859.git.thomas.lendacky@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16f36f9a51608758211c54564cd17c8b909372f1.1600892859.git.thomas.lendacky@amd.com> User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 23, 2020 at 03:27:39PM -0500, Tom Lendacky wrote: > From: Tom Lendacky > > The INVD instruction intercept performs emulation. Emulation can't be done > on an SEV guest because the guest memory is encrypted. > > Provide a dedicated intercept routine for the INVD intercept. Within this > intercept routine just skip the instruction for an SEV guest, since it is > emulated as a NOP anyway. > > Fixes: 1654efcbc431 ("KVM: SVM: Add KVM_SEV_INIT command") > Signed-off-by: Tom Lendacky > --- > arch/x86/kvm/svm/svm.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index c91acabf18d0..332ec4425d89 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -2183,6 +2183,17 @@ static int iret_interception(struct vcpu_svm *svm) > return 1; > } > > +static int invd_interception(struct vcpu_svm *svm) > +{ > + /* > + * Can't do emulation on an SEV guest and INVD is emulated > + * as a NOP, so just skip the instruction. > + */ > + return (sev_guest(svm->vcpu.kvm)) > + ? kvm_skip_emulated_instruction(&svm->vcpu) > + : kvm_emulate_instruction(&svm->vcpu, 0); Is there any reason not to do kvm_skip_emulated_instruction() for both SEV and legacy? VMX has the same odd kvm_emulate_instruction() call, but AFAICT that's completely unecessary, i.e. VMX can also convert to a straight skip. > +} > + > static int invlpg_interception(struct vcpu_svm *svm) > { > if (!static_cpu_has(X86_FEATURE_DECODEASSISTS)) > @@ -2774,7 +2785,7 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { > [SVM_EXIT_RDPMC] = rdpmc_interception, > [SVM_EXIT_CPUID] = cpuid_interception, > [SVM_EXIT_IRET] = iret_interception, > - [SVM_EXIT_INVD] = emulate_on_interception, > + [SVM_EXIT_INVD] = invd_interception, > [SVM_EXIT_PAUSE] = pause_interception, > [SVM_EXIT_HLT] = halt_interception, > [SVM_EXIT_INVLPG] = invlpg_interception, > -- > 2.28.0 >