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 From patchwork Mon Apr 10 12:50:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 81505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1875835vqo; Mon, 10 Apr 2023 05:59:47 -0700 (PDT) X-Google-Smtp-Source: AKy350ZIaLM5AQowKCJE2GFJuChcRjhjPYFYoe8G6mzFsXyZq4ZGN0MtLaj1boUdvjqBgtPunYWV X-Received: by 2002:a17:907:c21:b0:94d:de69:287b with SMTP id ga33-20020a1709070c2100b0094dde69287bmr272304ejc.22.1681131587224; Mon, 10 Apr 2023 05:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681131587; cv=none; d=google.com; s=arc-20160816; b=zkCwrO0i+VxwuiKt2ylmUMcqj1PHm0xCUns4lCd+2F21Qp438wlolcFcZyBXIj1T0Z VGqeIxJbiT8jcGFRqM5TeX7QEeDVB4MmVDi+cu3wawdyixm6Nss8eJaIifNv6Pwtomto RRTCLi+06hoDiykylmp3k5+piBA4mAaZXcmffIdm1WWc9R2zH3iukyGtHKamBoQxB63J V98NXDfGEBNd4FKHGt1ETuRWWqbwNgM0ujnsyV9MyKvWARokVAfDt2fsAvv5h4LeONUF SwTPV1p2MympYyupdAvrFPQetGaP2nCjQcWVyNgzjngRdlSB78JiGCaUQlQvimbOPGPS B4Zg== 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=+xFIn9YMT4rzDPbPDP2UR94+EUSaQ2d/Qq9qQZQjNrc=; b=pdGqiaCdYb2kfqDxxcy/A2IlXH6Foxy+RzPonrh2+nZsuT0u2ZVZz2dqjYYsFJsMGM 9yYGlNSW1CPqpqJflYKX9CMnk1Chf0mA3RBylZI7lJklRHL7pAn1WnjDQQNeB0gGY0vO 2YItZrCVu0z7cQgkwqgAdCQ7y9h7aoEVxukAyA3Z8/vUbbtn80q/cR2onExrAkRdE1M+ rie7CkUJO4MCY8G1GPT1Q9rI2konuSQYB5fxEV+vQVRsfMd7rZMGkACB3a2dlsX8bfYH Ndvw2QQ+aeLDZJnAI8UVZmOuoo3lS3EEvkjKqQ9gssfFnejxPTiCtWPUJBxPm18RHwB9 Gacw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=irS6TBhc; 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 ec20-20020a170906b6d400b00948aae5e39fsi570048ejb.750.2023.04.10.05.59.21; Mon, 10 Apr 2023 05:59:47 -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=irS6TBhc; 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 S229734AbjDJMug (ORCPT + 99 others); Mon, 10 Apr 2023 08:50:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbjDJMu1 (ORCPT ); Mon, 10 Apr 2023 08:50:27 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5D227D84; Mon, 10 Apr 2023 05:50:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681131025; x=1712667025; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g+1+1pWWmsug5/Dns9GEoG9llMqB6VBF1AwE2jD44ss=; b=irS6TBhcIYUFJ2f/gS77b1PP7tfwu8GbiYgPszHm1ObxxlZyotweUocV 8MpInpGZcSQauSl2w6SfBu+biVo83hayVNcy0v77qrfdzYjAtk6jWoPil gSRx42mybz2uVaLlu/G5D2VgSMDhvFGvqMocqb/RCi7ex4BdQQS3pHSJV Ou/sovGmffEYBqrVNrOzKvrmgP6S+B1WtMPJb5o/SVc+fpm6Suasn7qDb tjKIvT0XRpzA0NPo69CK8MyAD8Vob1SSa30+Ujr3MwbeUbvz5RNEufg4J coKg2dZkRBA548pil6Lk2IUDTTaq4JN4sv0+Ym56XYEjKJguYb5GW+tzg w==; X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="371183499" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="371183499" 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:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="638455270" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="638455270" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.46]) by orsmga003.jf.intel.com with ESMTP; 10 Apr 2023 05:50:23 -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 2/2] KVM: VMX: Move the comment of CR4.MCE handling right above the code Date: Mon, 10 Apr 2023 08:50:17 -0400 Message-Id: <20230410125017.1305238-3-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?1762794235181322144?= X-GMAIL-MSGID: =?utf-8?q?1762794235181322144?= ... to improve the code readability. No functional change indented. Signed-off-by: Xiaoyao Li --- arch/x86/kvm/vmx/vmx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index befa2486836b..c9421eb25666 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3433,13 +3433,13 @@ void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) { unsigned long old_cr4 = kvm_read_cr4(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu); + unsigned long hw_cr4; + /* * Pass through host's Machine Check Enable value to hw_cr4, which * is in force while we are in guest mode. Do not let guests control * this bit, even if host CR4.MCE == 0. */ - unsigned long hw_cr4; - hw_cr4 = (cr4_read_shadow() & X86_CR4_MCE) | (cr4 & ~X86_CR4_MCE); if (is_unrestricted_guest(vcpu)) hw_cr4 |= KVM_VM_CR4_ALWAYS_ON_UNRESTRICTED_GUEST;