From patchwork Mon Apr 10 12:50:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 81504 Return-Path: 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 + 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 ); 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 To: Sean Christopherson , Paolo Bonzini 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 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: 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?= 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 --- 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); struct vcpu_vmx *vmx = to_vmx(vcpu); /* * Pass through host's Machine Check Enable value to hw_cr4, which