Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4194476ybg; Tue, 29 Oct 2019 03:37:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvbtyoVGtVuhNTu2P2aeclzgqlSy8C1TCpGjTnWuCBkAhkiNNy7zarfxmkzR47CV1TyoAS X-Received: by 2002:a50:9555:: with SMTP id v21mr24453123eda.90.1572345464533; Tue, 29 Oct 2019 03:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572345464; cv=none; d=google.com; s=arc-20160816; b=dZP/fO7j+Ys3GyNG7N2r/QCgOtYRrufoo5K8K+BNQMwd+cyhIkjeLDx+axDvyXVDjL LMSajnFBxcUwVRjLHSjMGCge8UREOw6bZ3igSeypOc9iH6sUVAMs3u0mUfdcvy6REde3 4yYMdC2BnTyc/kQB/qk02zury5+A92tWdE2Hg/XJGug+XuCuSC30T3q/XZaf5m6nq7lh YxeRxSt8XZLH4PBM9W/bsksxQnRtyCau6gomA8NnDm6DackfCv42pMqgq979MyEb4aMo NnLMvNBRnJGGb3H6M2jSJI46RNUtlmvxz6HR4LkhnCl4jKZ0W8d4oWMD9Oaxkx/7hKcQ gJ+g== 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=GeWhoNzZEFeiax7fJQO8zefeoDydEjuIWsP+Hc1eVNI=; b=OqVtH7LvhUu4YpUJivq/hRc1tyYBwgPIMtLXgziVi26SqeKA8+FaUstloyAC+T0oK7 qJK43krauRCvFL96/nxa2Swt+GmhEg3aBaIvRD//omk4GcY2oZqH3gejxdNzUVBeQphS Q3VNWMvd0vEpSns1QrhLvPPKFKwYWJjQpQPoGtNhFDXDxz9ukRCT1P+0Lq8+QzypMfcv LtFtqIJu5R9wEnmMgQY74lYztYkcx5U1LWpdExHw+V7YcLcST8kk+4OOfaagS7YWuO7a LtiLEEB5NpfuDJa//GGzbmokPUv4Hqxs93iD6PWfrjYCDXjgUed5ztjhf5zIqh+o1xUu yolg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u24si6474384ejr.220.2019.10.29.03.37.21; Tue, 29 Oct 2019 03:37:44 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728414AbfJ2Jca (ORCPT + 99 others); Tue, 29 Oct 2019 05:32:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:47870 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725791AbfJ2Jc3 (ORCPT ); Tue, 29 Oct 2019 05:32:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E24A2B277; Tue, 29 Oct 2019 09:32:27 +0000 (UTC) Date: Tue, 29 Oct 2019 10:32:26 +0100 From: Joerg Roedel To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] KVM: vmx, svm: always run with EFER.NXE=1 when shadow paging is active Message-ID: <20191029093226.GE838@suse.de> References: <20191027152323.24326-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191027152323.24326-1-pbonzini@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paolo, On Sun, Oct 27, 2019 at 04:23:23PM +0100, Paolo Bonzini wrote: > VMX already does so if the host has SMEP, in order to support the combination of > CR0.WP=1 and CR4.SMEP=1. However, it is perfectly safe to always do so, and in > fact VMX already ends up running with EFER.NXE=1 on old processors that lack the > "load EFER" controls, because it may help avoiding a slow MSR write. Removing > all the conditionals simplifies the code. > > SVM does not have similar code, but it should since recent AMD processors do > support SMEP. So this patch also makes the code for the two vendors more similar > while fixing NPT=0, CR0.WP=1 and CR4.SMEP=1 on AMD processors. > > Cc: stable@vger.kernel.org > Cc: Joerg Roedel > Signed-off-by: Paolo Bonzini Looks good to me. Reviewed-by: Joerg Roedel > --- > arch/x86/kvm/svm.c | 10 ++++++++-- > arch/x86/kvm/vmx/vmx.c | 14 +++----------- > 2 files changed, 11 insertions(+), 13 deletions(-) > > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index b6feb6a11a8d..2c452293c7cc 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -732,8 +732,14 @@ static int get_npt_level(struct kvm_vcpu *vcpu) > static void svm_set_efer(struct kvm_vcpu *vcpu, u64 efer) > { > vcpu->arch.efer = efer; > - if (!npt_enabled && !(efer & EFER_LMA)) > - efer &= ~EFER_LME; > + > + if (!npt_enabled) { > + /* Shadow paging assumes NX to be available. */ > + efer |= EFER_NX; > + > + if (!(efer & EFER_LMA)) > + efer &= ~EFER_LME; > + } > > to_svm(vcpu)->vmcb->save.efer = efer | EFER_SVME; > mark_dirty(to_svm(vcpu)->vmcb, VMCB_CR); > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 2a2ba277c676..e191d41afb34 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -896,17 +896,9 @@ static bool update_transition_efer(struct vcpu_vmx *vmx, int efer_offset) > u64 guest_efer = vmx->vcpu.arch.efer; > u64 ignore_bits = 0; > > - if (!enable_ept) { > - /* > - * NX is needed to handle CR0.WP=1, CR4.SMEP=1. Testing > - * host CPUID is more efficient than testing guest CPUID > - * or CR4. Host SMEP is anyway a requirement for guest SMEP. > - */ > - if (boot_cpu_has(X86_FEATURE_SMEP)) > - guest_efer |= EFER_NX; > - else if (!(guest_efer & EFER_NX)) > - ignore_bits |= EFER_NX; > - } > + /* Shadow paging assumes NX to be available. */ > + if (!enable_ept) > + guest_efer |= EFER_NX; > > /* > * LMA and LME handled by hardware; SCE meaningless outside long mode. > -- > 2.21.0