Message ID | 20230410125017.1305238-2-xiaoyao.li@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1872745vqo; Mon, 10 Apr 2023 05:52:30 -0700 (PDT) X-Google-Smtp-Source: AKy350atYmhcFQtrf8rPViU8KWu360riyyGyVwx68s9gre/9/Njw0LMf8f71fLNEyx54hSRogotD X-Received: by 2002:a17:906:710e:b0:94a:5a9e:9da0 with SMTP id x14-20020a170906710e00b0094a5a9e9da0mr5140843ejj.77.1681131150050; Mon, 10 Apr 2023 05:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681131150; cv=none; d=google.com; s=arc-20160816; b=kRmb9vLO2LdEDOAGbKdB6Ag/slEFgCu79pkniMi3ac9VVLs3r6cjjEMrufoJx6qfkb nl7P7ulxAzuSQ+5X+ybIRbhcq6s/+hoT0wpZcGTKNNzP9RNYqzAGtEwMSwTmWkVHU268 ENNDqm6o7wxAdTHh+lxncifek1uI+gqIrwFdmRDQBAmMYp+jA5ffG2lfXZEBjTUAQTrG kogluh000WCS+BhcjRN9B2TUoqdfaxP7UqbdtYyO137ZAkZrzaaSdDUqzGY3hLETpHWX SLxk45jBytu4AMI3mxVetXlZd23gUYGqytIW4dV7AmnRyjrFADB2wxW0cEjS388IDzSm Pakw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T7A9FU6mwwM8o24ty9UWeaH2bFU0TgTq4Ox3ehoS2yk=; b=kpGwfbl7PNr0Z8TdjLmgPX707soQ91PZYD3/kATrXnE3TCzfAlD2RkVoiPSOgMRuEU 6ZXvWPQgrhUgVoWUUmXaKI1NF4zeQVRlfYIEACUVcqMxwxJFysTpjbqiY+9ZWDlgZeSY Wnc9t6bZCNT+RKGPFhpFqePPxoMGo9gphISGkAssOfg1+t5xoglde7NB5HFybL2hyC+s gehJCcWPq0rYjowjwEztO/JmxMRq1N0VvYQH8ffvRGgiNrpuAd1saTfjszlhgosQiDFo VGh4BM3KOVfXumpTZwKPP7PHqWhoBd3bhX4x4i6qXccxPs5Uoz++DuBPuTHisFwN4XAy Bx9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RC9Udjbv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020aa7d8cd000000b005047f88dbbfsi1059745eds.420.2023.04.10.05.52.06; Mon, 10 Apr 2023 05:52:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RC9Udjbv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbjDJMud (ORCPT <rfc822;yuanzuo1009@gmail.com> + 99 others); Mon, 10 Apr 2023 08:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjDJMu0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 10 Apr 2023 08:50:26 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B2E761B1; Mon, 10 Apr 2023 05:50:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681131023; x=1712667023; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ff+CccVwXXrczPNnTRbmV+x1z43wLG9Logfb8NFVoXs=; b=RC9Udjbv8bSVSlzdFcUHcb+7aJlwa/zwEeyCBv7iSiXF1/SDqUpafwEe v70iYJcGcmkos0AGXpU1fZjEZZQ9otsXSIhoeMTEalFCqaRsAIRkpRT/m 1ylo68Xyo42tKP3U1IcZsHzep4cZ4HY9PjfeaayrlHbgq1HHhmPlL/ZQZ oHJ5QrLHO28R7Y8BWtkrUGzqMYeFk9hWicukrMQqgXdspuYIMtgeXXZLF mg/BIhKKqnzLJae3v4WwBWx/y/mzt4Er+vEjlLX6qNx1p1NKrAP6wma/Z TcsxaPYTwX+Zf3NqJImtfcFQxgrcMWR5GEgR/kRcr+7f9+3jUPnEySkyb A==; X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="371183495" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="371183495" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 05:50:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="638455267" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="638455267" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.46]) by orsmga003.jf.intel.com with ESMTP; 10 Apr 2023 05:50:21 -0700 From: Xiaoyao Li <xiaoyao.li@intel.com> To: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com> Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, xiaoyao.li@intel.com Subject: [PATCH 1/2] KVM: VMX: Use kvm_read_cr4() to get cr4 value Date: Mon, 10 Apr 2023 08:50:16 -0400 Message-Id: <20230410125017.1305238-2-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410125017.1305238-1-xiaoyao.li@intel.com> References: <20230410125017.1305238-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762793776770871771?= X-GMAIL-MSGID: =?utf-8?q?1762793776770871771?= |
Series |
KVM: VMX: Clean up of vmx_set_cr4()
|
|
Commit Message
Xiaoyao Li
April 10, 2023, 12:50 p.m. UTC
Directly use vcpu->arch.cr4 is not recommended since it gets stale value
if the cr4 is not available.
Use kvm_read_cr4() instead to ensure correct value.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Mon, Apr 10, 2023, Xiaoyao Li wrote: > Directly use vcpu->arch.cr4 is not recommended since it gets stale value > if the cr4 is not available. > > Use kvm_read_cr4() instead to ensure correct value. > > Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> > --- > arch/x86/kvm/vmx/vmx.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index d7bf14abdba1..befa2486836b 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -3431,7 +3431,7 @@ static bool vmx_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) > > void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) > { > - unsigned long old_cr4 = vcpu->arch.cr4; > + unsigned long old_cr4 = kvm_read_cr4(vcpu); Ha! I've been tempted to change this multiple times, but always thought I was just being a bit obsessive :-) Patches look good, but I'm going to hold them for 6.5 just in case this somehow causes a problem, e.g. if there's a bizzaro nested path that "works" because KVM _doesn't_ decache info from the current VMCS.
On 4/11/2023 1:11 AM, Sean Christopherson wrote: > On Mon, Apr 10, 2023, Xiaoyao Li wrote: >> Directly use vcpu->arch.cr4 is not recommended since it gets stale value >> if the cr4 is not available. >> >> Use kvm_read_cr4() instead to ensure correct value. >> >> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> >> --- >> arch/x86/kvm/vmx/vmx.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c >> index d7bf14abdba1..befa2486836b 100644 >> --- a/arch/x86/kvm/vmx/vmx.c >> +++ b/arch/x86/kvm/vmx/vmx.c >> @@ -3431,7 +3431,7 @@ static bool vmx_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) >> >> void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) >> { >> - unsigned long old_cr4 = vcpu->arch.cr4; >> + unsigned long old_cr4 = kvm_read_cr4(vcpu); > > Ha! I've been tempted to change this multiple times, but always thought I was > just being a bit obsessive :-) > > Patches look good, but I'm going to hold them for 6.5 just in case this somehow > causes a problem, e.g. if there's a bizzaro nested path that "works" because KVM > _doesn't_ decache info from the current VMCS. so you will put it in kvm-next after 6.4 merge windows?
On Wed, Apr 12, 2023, Xiaoyao Li wrote: > On 4/11/2023 1:11 AM, Sean Christopherson wrote: > > On Mon, Apr 10, 2023, Xiaoyao Li wrote: > > > Directly use vcpu->arch.cr4 is not recommended since it gets stale value > > > if the cr4 is not available. > > > > > > Use kvm_read_cr4() instead to ensure correct value. > > > > > > Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> > > > --- > > > arch/x86/kvm/vmx/vmx.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > > > index d7bf14abdba1..befa2486836b 100644 > > > --- a/arch/x86/kvm/vmx/vmx.c > > > +++ b/arch/x86/kvm/vmx/vmx.c > > > @@ -3431,7 +3431,7 @@ static bool vmx_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) > > > void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) > > > { > > > - unsigned long old_cr4 = vcpu->arch.cr4; > > > + unsigned long old_cr4 = kvm_read_cr4(vcpu); > > > > Ha! I've been tempted to change this multiple times, but always thought I was > > just being a bit obsessive :-) > > > > Patches look good, but I'm going to hold them for 6.5 just in case this somehow > > causes a problem, e.g. if there's a bizzaro nested path that "works" because KVM > > _doesn't_ decache info from the current VMCS. > > so you will put it in kvm-next after 6.4 merge windows? The likely candidate is "kvm-x86 vmx", and I probably won't apply the patches until after v6.4-rc2 (rc2 being my preferred base for the next cycle). But yes, the plan is to apply the patches after the 6.4 merge window. Are you asking because you want to know if you need to resend for 6.5? Or does the timing/location matter for some other reason, e.g. a dependency from another patch/series?
On 4/12/2023 11:03 PM, Sean Christopherson wrote: > On Wed, Apr 12, 2023, Xiaoyao Li wrote: >> On 4/11/2023 1:11 AM, Sean Christopherson wrote: >>> On Mon, Apr 10, 2023, Xiaoyao Li wrote: >>>> Directly use vcpu->arch.cr4 is not recommended since it gets stale value >>>> if the cr4 is not available. >>>> >>>> Use kvm_read_cr4() instead to ensure correct value. >>>> >>>> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> >>>> --- >>>> arch/x86/kvm/vmx/vmx.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c >>>> index d7bf14abdba1..befa2486836b 100644 >>>> --- a/arch/x86/kvm/vmx/vmx.c >>>> +++ b/arch/x86/kvm/vmx/vmx.c >>>> @@ -3431,7 +3431,7 @@ static bool vmx_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) >>>> void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) >>>> { >>>> - unsigned long old_cr4 = vcpu->arch.cr4; >>>> + unsigned long old_cr4 = kvm_read_cr4(vcpu); >>> >>> Ha! I've been tempted to change this multiple times, but always thought I was >>> just being a bit obsessive :-) >>> >>> Patches look good, but I'm going to hold them for 6.5 just in case this somehow >>> causes a problem, e.g. if there's a bizzaro nested path that "works" because KVM >>> _doesn't_ decache info from the current VMCS. >> >> so you will put it in kvm-next after 6.4 merge windows? > > The likely candidate is "kvm-x86 vmx", and I probably won't apply the patches until > after v6.4-rc2 (rc2 being my preferred base for the next cycle). But yes, the plan > is to apply the patches after the 6.4 merge window. > > Are you asking because you want to know if you need to resend for 6.5? Or does > the timing/location matter for some other reason, e.g. a dependency from another > patch/series? none of it. Just to confirm I get it. :)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index d7bf14abdba1..befa2486836b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3431,7 +3431,7 @@ static bool vmx_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) { - unsigned long old_cr4 = vcpu->arch.cr4; + unsigned long old_cr4 = kvm_read_cr4(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu); /* * Pass through host's Machine Check Enable value to hw_cr4, which