Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp121330rwe; Thu, 13 Apr 2023 23:30:17 -0700 (PDT) X-Google-Smtp-Source: AKy350YwaT5EbTyY03QBMnc+wUcfS+k4DxzogNGhzOqLigiFCDSpD7hSOf3Zx9PrTkhPW8Y1FyIq X-Received: by 2002:a17:902:e5c8:b0:1a5:5927:2232 with SMTP id u8-20020a170902e5c800b001a559272232mr2034477plf.53.1681453816839; Thu, 13 Apr 2023 23:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681453816; cv=none; d=google.com; s=arc-20160816; b=WBoYNDVYmSE/37E1NJ4zdyX4W6D7VIvGIUn8OC7uH2RF8neghCX+liQ0XUccSF454R 3H/ag0sXVwx5uonvgF+AXY+WxzZJ6IgXZ3uEReVrLByssdy7SsvM3dXU+QlOx7EIfVO+ 1SFgsmdzRMwJlVrlkuJiM86+Ve+Mzr8ZCrvn9wmVBfW0n8ydciEbVOb5+xsLcXj7w0Rm wuPmnilGVer96yd2NGzzdkbb3Jd9iK5ONRKSZm0FulBQzJjTTMFN3txfEo7OaZlOMviu lZRYDXx4QTfVNbXfl2Z2UJFxg4StOwo+T4HQJ7CrcayhrnnHNjzHm0ios3J2ckJBXbpl CRCg== 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=9AI1u6spvgvk2t6d7G+VME2soKIiLDS1VFqCgHHe+cY=; b=zBnjHam0egnz9+u4kBcFSTnJFozzd7MlKeiTZWe/LekgVqahWpVtUOnITfmuru2XMv 3Ru7PSbRjv2kY5sS3D4qmpI2bcBzU0QZ77T+q2KsE/WeuEawD58XEogmx90qJ5V+3s+8 8Do/yrlcksWc//nPIA+Xb4VDRnct0je7IEu8j1bhIy+MdugNMsuywrC5xrFsSkOU1Buh 5Hzapa991qPFERlMgp8isj/p4EhRcbVnXmCs2Tl/JjCZAzJRzBxriSepZYb/DUzy23Uv jQk7kATnt5mEVZlckwy7jB6lewcHIjGomi6V+wtRkJfSWlGmEEJu158DAefsWW+1vz8m cUaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YmxcJp97; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a18-20020a170902b59200b001a50dcd10c2si2940957pls.247.2023.04.13.23.30.05; Thu, 13 Apr 2023 23:30:16 -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=YmxcJp97; 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 S230097AbjDNG3W (ORCPT + 99 others); Fri, 14 Apr 2023 02:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230131AbjDNG3Q (ORCPT ); Fri, 14 Apr 2023 02:29:16 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1EDC7ECB; Thu, 13 Apr 2023 23:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681453726; x=1712989726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yxXdxmEirAw6zmyoyfst+wvzy0+xFYrOs9/OP2pUIng=; b=YmxcJp97W9N9l3VB9Z5ZHiIRsJAlZsO5bG2oSky39hvNZirnoGsJ3Z2q pTCJGWhWnpqh6TEgynRLVyi68WQdIRm7VYGXsV/MbDtiR5NhrBwX+KS55 EDV7yiR8kPAE/GvykKzH4WZaAjlhIOZEXqBmQPE1ipxcgYaB/hIog6aS/ 1QcEqHceraH9la6YRNvWUTDzLkHAjYnTN7syOZFQj6GREKPwGF3XeFWXF dBAT2Yp5T/tAzfzd3CHOegi4eFqb7FeAoB7826xqoULzdOvxdhi+6vAVc bzgXuxkRyM9RtBrKXdTSyCRDVN7T73nKDZZSojMZxDNo7cwwDhK8Yzx/4 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="341892877" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="341892877" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 23:26:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="935885975" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="935885975" Received: from spr.sh.intel.com ([10.239.53.106]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 23:26:40 -0700 From: Chao Gao To: kvm@vger.kernel.org Cc: Jiaan Lu , Zhang Chen , Chao Gao , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 09/11] KVM: VMX: Advertise MITI_CTRL_BHB_CLEAR_SEQ_S_SUPPORT Date: Fri, 14 Apr 2023 14:25:30 +0800 Message-Id: <20230414062545.270178-10-chao.gao@intel.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230414062545.270178-1-chao.gao@intel.com> References: <20230414062545.270178-1-chao.gao@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 From: Zhang Chen Allow guest to query if the underying VMM understands BHB-clearing sequence and report the statue of BHB-clearing sequence in suprevisor mode i.e. CPL < 3 via MSR_VIRTUAL_MITIGATION_ENUM/CTRL. Enable BHI_DIS_S for guest if guest is using BHI-clearing sequence and the sequence isn't effective on the processor. Signed-off-by: Zhang Chen Signed-off-by: Chao Gao Tested-by: Jiaan Lu --- arch/x86/kvm/vmx/vmx.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 25afb4c3e55e..abbbf8e66b53 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1944,8 +1944,10 @@ static inline bool is_vmx_feature_control_msr_valid(struct vcpu_vmx *vmx, } #define VIRTUAL_ENUMERATION_VALID_BITS VIRT_ENUM_MITIGATION_CTRL_SUPPORT -#define MITI_ENUM_VALID_BITS MITI_ENUM_RETPOLINE_S_SUPPORT -#define MITI_CTRL_VALID_BITS MITI_CTRL_RETPOLINE_S_USED +#define MITI_ENUM_VALID_BITS (MITI_ENUM_RETPOLINE_S_SUPPORT | \ + MITI_ENUM_BHB_CLEAR_SEQ_S_SUPPORT) +#define MITI_CTRL_VALID_BITS (MITI_CTRL_RETPOLINE_S_USED | \ + MITI_CTRL_BHB_CLEAR_SEQ_S_USED) static int vmx_get_msr_feature(struct kvm_msr_entry *msr) { @@ -2496,6 +2498,11 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) arch_msr & ARCH_CAP_RRSBA) spec_ctrl_mask |= SPEC_CTRL_RRSBA_DIS_S; + if (data & MITI_CTRL_BHB_CLEAR_SEQ_S_USED && + kvm_cpu_cap_has(X86_FEATURE_BHI_CTRL) && + !(arch_msr & ARCH_CAP_BHI_NO)) + spec_ctrl_mask |= SPEC_CTRL_BHI_DIS_S; + /* * Intercept IA32_SPEC_CTRL to disallow guest from changing * certain bits. -- 2.40.0