Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp201925pxb; Wed, 3 Feb 2021 03:29:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpWdmy4Y24r0LXq4aIyk3aMBxWSO6bGyyavleyyQz9Q/PoaHIMFvHQzRC2y+5qYh3OvHtq X-Received: by 2002:a05:6402:254b:: with SMTP id l11mr2402284edb.202.1612351782348; Wed, 03 Feb 2021 03:29:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612351782; cv=none; d=google.com; s=arc-20160816; b=QVBG0X8hYLrr7XTLdF8HTK/j0dh7stZ2hkW47vS93IA6TaiNT0wiIyYQk5riCfwp4K d020CuBOmuJjvGhNLCPesI/KQoFTo5WYAzzqaEChfvmlvfihQQbRdwm4IYeGg1C9IomY /30ixgIF44HopMuyLidaT69sOqrpVtEESwDG4qqoEV5nR3/q/oKVWkRSN1QA8vatt9/4 9I8PvnDMFn2U3FoiteTeL7wF9lt/kMK5yV9JB73+CMqUqoM6SXava4A8PO6I/JyKx8vB /hhUfSMkne4MN29bkujxguHhrXu3tpHwTxcO77GXWDW2qBxUlYZlwpHqZyPn00tqqrGp gv9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=1rvXVG7LsYZWVyy+gm/7csM5zRuq7mudK4CIuHqlA64=; b=XlqDsLAJP8QszWhVAyWpBz0cjmvzSJrGyFaKx83EWVYIRN1YW6E/AumCccKjxvVec1 aBWcFH6faBwtfkcbg5zSCzaTQMvyPPBFCb9ksY1W1PZou0zxzl7M4J0Kf+iiAO8v0xcs tF5+9SQTW8YCBv5r7FLlUBjBDpzqf/wfxJrVS9ed4G0IEZAkj9WTeWiOJ19AQzla+hq7 Ef7MiVpdkcqlHdD/jKzM2k5Ny8ozxnA6doqYhJ+gNej+xjB8x+UO5dWzTHaN+ALIrh8p ygzrzLZdmg/Mx5BPx+WqUU8foT3FSD/n31rZfShXBzUFOI4tzqedl8E++qhsg/3K8ZLA YLzw== 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 by17si226172ejb.604.2021.02.03.03.29.18; Wed, 03 Feb 2021 03:29:42 -0800 (PST) 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 S234393AbhBCL0i (ORCPT + 99 others); Wed, 3 Feb 2021 06:26:38 -0500 Received: from mga01.intel.com ([192.55.52.88]:28325 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234103AbhBCLYL (ORCPT ); Wed, 3 Feb 2021 06:24:11 -0500 IronPort-SDR: bnH/wJZkB9qH5/Qmdw0ZsOw7AgOftPGCzTSsyBlR/oVwk0Kf+NU9X2qUQqfcMfBbCtjw6okil2 FKox9qV6PaMQ== X-IronPort-AV: E=McAfee;i="6000,8403,9883"; a="199981321" X-IronPort-AV: E=Sophos;i="5.79,398,1602572400"; d="scan'208";a="199981321" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 03:22:29 -0800 IronPort-SDR: MDaR4lSE2oYPbm+4nf74lh8jOiLsoJWHDdWqyJ7qCCWsJWaO7Rq7Dq2SCMxTmiPN81OKlYvKx/ q19vyVHIz7eg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,398,1602572400"; d="scan'208";a="480311213" Received: from unknown (HELO local-michael-cet-test.sh.intel.com) ([10.239.159.166]) by fmsmga001.fm.intel.com with ESMTP; 03 Feb 2021 03:22:27 -0800 From: Yang Weijiang To: pbonzini@redhat.com, seanjc@google.com, jmattson@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yu.c.zhang@linux.intel.com, Yang Weijiang Subject: [PATCH v15 12/14] KVM: nVMX: Add helper to check the vmcs01 MSR bitmap for MSR pass-through Date: Wed, 3 Feb 2021 19:34:19 +0800 Message-Id: <20210203113421.5759-13-weijiang.yang@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20210203113421.5759-1-weijiang.yang@intel.com> References: <20210203113421.5759-1-weijiang.yang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a helper to perform the check on the vmcs01/l01 MSR bitmap when disabling interception of an MSR for L2. This reduces the boilerplate for the existing cases, and will be used heavily in a future patch for CET MSRs. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Yang Weijiang --- arch/x86/kvm/vmx/nested.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index f2b9bfb58206..3b405ebabb6e 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -544,6 +544,17 @@ static void nested_vmx_disable_intercept_for_msr(unsigned long *msr_bitmap_l1, } } +static void nested_vmx_cond_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, + unsigned long *bitmap_12, + unsigned long *bitmap_02, + int type) +{ + if (msr_write_intercepted_l01(vcpu, msr)) + return; + + nested_vmx_disable_intercept_for_msr(bitmap_12, bitmap_02, msr, type); +} + static inline void enable_x2apic_msr_intercepts(unsigned long *msr_bitmap) { int msr; @@ -640,17 +651,13 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu, * updated to reflect this when L1 (or its L2s) actually write to * the MSR. */ - if (!msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL)) - nested_vmx_disable_intercept_for_msr( - msr_bitmap_l1, msr_bitmap_l0, - MSR_IA32_SPEC_CTRL, - MSR_TYPE_R | MSR_TYPE_W); + nested_vmx_cond_disable_intercept_for_msr(vcpu, MSR_IA32_SPEC_CTRL, + msr_bitmap_l1, msr_bitmap_l0, + MSR_TYPE_R | MSR_TYPE_W); - if (!msr_write_intercepted_l01(vcpu, MSR_IA32_PRED_CMD)) - nested_vmx_disable_intercept_for_msr( - msr_bitmap_l1, msr_bitmap_l0, - MSR_IA32_PRED_CMD, - MSR_TYPE_W); + nested_vmx_cond_disable_intercept_for_msr(vcpu, MSR_IA32_PRED_CMD, + msr_bitmap_l1, msr_bitmap_l0, + MSR_TYPE_W); kvm_vcpu_unmap(vcpu, &to_vmx(vcpu)->nested.msr_bitmap_map, false); -- 2.26.2