From patchwork Wed Feb 7 17:26:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 198003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2406571dyb; Wed, 7 Feb 2024 10:03:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUz0OtJn8uEdurvJH7kmur/qqmnhLMep9DBL/5HB9yO+vyg+ODsK0BTJzpbTp6AXi89PtDk4TxkGuAzeqmCdzBWkZpXbg== X-Google-Smtp-Source: AGHT+IFydbZSPEbAeX3iJuSJ2hXibSvfAgOICabWeKoW0MKw8DcasdzlFQZfsai353/9Jhr940cI X-Received: by 2002:ac8:542:0:b0:429:9e63:57f4 with SMTP id c2-20020ac80542000000b004299e6357f4mr6464722qth.56.1707328986944; Wed, 07 Feb 2024 10:03:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707328986; cv=pass; d=google.com; s=arc-20160816; b=07W5Py1B5eYxCJiaRtO3wbD/uvu1RmDsWeiwggb+HYC+B5QrdwLV27rRScRA9ORpKX lGv0KY9O3PZqUAvhNASKqOmEIkSf/1tQv9h6uYP8ydDg4PgCTuVvrmQEa6kL03YQUmRg eTKB/0U0ewqV7ugDRF2tJ+B7WhuzqSq2kstj2ZkmWAUoS6GKHIkMCaxdb/7HUgoI6w6z 2X0+cxbQxBvHv5b97nWgvt979Z8OQXQjIV4Dfo7C+aCYDOy91y3JpxCwL0TheoQedAZS 6YUDV0SBEtnlGpgq4yuoKY6wqCEttdVZPLd4HO+3MLQ/TLBR3ntXYLcmzLpXWX+eq1OY DxVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tF7RVysBd6lAEodH3QjrqNTupaS3tEaU/TUvYeAgucA=; fh=cq+X9hvayPEIXBZJNHTSCn7NeciPYJgmsnmj+YCunvw=; b=npvJPwz+/FONFn+cxYKZW0E3LOanBPweMnghlzFWEoD1JXOeXAZh8q7lye1dyQxdgy 10u+Bv1QQ1hcCzmWhC7Cp+Q1+SrSXoUovYuhanNyPgvMJZPsaOTO867tIwYb9Rvu/6XN FfQ9t5hAIByJlbgQAieLKsIdrZEawZVoE+RlNlWIu95Is+PLa6DjLURU6lvzuDznXuTe 2XxMneMtlVRfyVUUt2l5LnVGOs7IERo0hUHIsvBlJsetVx+T2XoeiHs+6XVl/PzvCP0w dZ9J15971/dWes700IpYqk0KpVpZvHOU/Pm9u8YjHwMS6nHvQI0MsvX/CjNhVf2OKEzL rS5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Yf1TkA9I; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-56861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56861-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWDP1J1gepnSveCVqFJ3I8PKgMaps9J2klqLd4+Nc4h3dna5RLIeTk0jAA2WML/s4nbUAp3TFGVUe0NexhhEBXnyFS0qA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f13-20020ac859cd000000b0042c39f13f93si1534540qtf.656.2024.02.07.10.03.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 10:03:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Yf1TkA9I; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-56861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56861-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AC0611C20FC6 for ; Wed, 7 Feb 2024 18:03:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B202D12AAC2; Wed, 7 Feb 2024 17:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Yf1TkA9I" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63DC585959; Wed, 7 Feb 2024 17:59:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707328748; cv=none; b=JXmMnVtx0NFQNtnTTJ5qVAPrWn4Hf//37ye+t3bxfDHZvm2noKm4Kgq4lPq1UyFMQVZc9kFvnweiXOUMAS/luOtkN7pNW7hHRwMmEIcqHli8xjrvnj+WkwLr87EBUsvceo24pqUpUXpvBVWO4gZ1Aq9prWsjYLKPUXshN0jM6Mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707328748; c=relaxed/simple; bh=d3GcbZGq1+iZzuECARn9elrUw2PwCYl4eSLifsdjifc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S01aD9mLRwXyLCeucwdE/Dq+6j0RWCQUQJwK6VyRn0a3AkD2EtGWg1rX3YbxCD9qrqRDy1fhlDjdpGmQTqxiBC3xreIrwSJOx1Ot/HGroIExlSyJEaPvSm99+2/cdhKe6c0uICY+pifIkrVF5KpDenFFAJR7hh6m8URAZdEd1og= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Yf1TkA9I; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707328747; x=1738864747; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d3GcbZGq1+iZzuECARn9elrUw2PwCYl4eSLifsdjifc=; b=Yf1TkA9Iu3Hq/O4aec0aUdDb1I64fB37U1BcNpPNrJf7ScJKd3y/Wk46 +1QDP2aBZYY7kHi3FnEgJEEwOqm9gsSenLlcVHdRBLxKzrAovjdFIHSPc hpb3fdW12L0zjBbBif41x7R9lWMewO+E3UMCyIfofCwvHX/vGFrVyddrz UHHkrkj17OwV0tbC6kb7QzAZ5EeNW1vSyqVmkDne7mUf8EEjme9i2wPG2 hs2ahsdqAt1anaEwZ4JqrbzmeV0amp7Rr8PybF/9c+RGB8YNV+2y7i8TT 4XyOe1HdjAF3q4KdiBJaCbAO0fYH/tCfQgbJV1gCSs64gHEUiLzLggG1l g==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="11622538" X-IronPort-AV: E=Sophos;i="6.05,251,1701158400"; d="scan'208";a="11622538" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 09:58:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,251,1701158400"; d="scan'208";a="6020714" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmviesa004.fm.intel.com with ESMTP; 07 Feb 2024 09:58:55 -0800 From: Xin Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: seanjc@google.com, pbonzini@redhat.com, corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, shuah@kernel.org, vkuznets@redhat.com, peterz@infradead.org, ravi.v.shankar@intel.com, xin@zytor.com Subject: [PATCH v2 07/25] KVM: VMX: Set intercept for FRED MSRs Date: Wed, 7 Feb 2024 09:26:27 -0800 Message-ID: <20240207172646.3981-8-xin3.li@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207172646.3981-1-xin3.li@intel.com> References: <20240207172646.3981-1-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790264199939802656 X-GMAIL-MSGID: 1790264199939802656 Add FRED MSRs to the valid passthrough MSR list and set FRED MSRs intercept based on FRED enumeration. Signed-off-by: Xin Li Tested-by: Shan Kang --- Change since v1: * Enable FRED MSRs intercept if FRED is no longer enumerated in CPUID (Chao Gao). --- arch/x86/kvm/vmx/vmx.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 34b6676f60d8..d58ed2d3d379 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -693,6 +693,9 @@ static bool is_valid_passthrough_msr(u32 msr) case MSR_LBR_CORE_TO ... MSR_LBR_CORE_TO + 8: /* LBR MSRs. These are handled in vmx_update_intercept_for_lbr_msrs() */ return true; + case MSR_IA32_FRED_RSP0 ... MSR_IA32_FRED_CONFIG: + /* FRED MSRs should be passthrough to FRED guests only */ + return true; } r = possible_passthrough_msr_slot(msr) != -ENOENT; @@ -7774,10 +7777,12 @@ static void update_intel_pt_cfg(struct kvm_vcpu *vcpu) static void vmx_vcpu_config_fred_after_set_cpuid(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); + bool fred_enumerated; kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_FRED); + fred_enumerated = guest_can_use(vcpu, X86_FEATURE_FRED); - if (guest_can_use(vcpu, X86_FEATURE_FRED)) { + if (fred_enumerated) { vm_entry_controls_setbit(vmx, VM_ENTRY_LOAD_IA32_FRED); secondary_vm_exit_controls_setbit(vmx, SECONDARY_VM_EXIT_SAVE_IA32_FRED | @@ -7788,6 +7793,16 @@ static void vmx_vcpu_config_fred_after_set_cpuid(struct kvm_vcpu *vcpu) SECONDARY_VM_EXIT_SAVE_IA32_FRED | SECONDARY_VM_EXIT_LOAD_IA32_FRED); } + + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_RSP0, MSR_TYPE_RW, !fred_enumerated); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_RSP1, MSR_TYPE_RW, !fred_enumerated); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_RSP2, MSR_TYPE_RW, !fred_enumerated); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_RSP3, MSR_TYPE_RW, !fred_enumerated); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_STKLVLS, MSR_TYPE_RW, !fred_enumerated); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_SSP1, MSR_TYPE_RW, !fred_enumerated); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_SSP2, MSR_TYPE_RW, !fred_enumerated); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_SSP3, MSR_TYPE_RW, !fred_enumerated); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_CONFIG, MSR_TYPE_RW, !fred_enumerated); } static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)