Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp865693rdb; Tue, 23 Jan 2024 18:54:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHSnQndnaVhPHRLftuWqOCgYd2TuMGDw0BbCZvTV5fQbcQy1eriSyRgNN3xGyDv88eJ+ao X-Received: by 2002:a17:902:76c2:b0:1d7:1b61:57a7 with SMTP id j2-20020a17090276c200b001d71b6157a7mr118637plt.117.1706064893990; Tue, 23 Jan 2024 18:54:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706064893; cv=pass; d=google.com; s=arc-20160816; b=aMYHt1ESQXloW9vXtR4ir0X9QQsCH8217sqBBCllwCGF1fFUWE/hPlYIhFNXH5APJc zf/MwRbKLSO85bSb7vCs8xJ+BTz7uzKRr5AuSXcqw+m2mCgjePqoaz3IGJrNka2A/njz LIOr5uxA9xDQixSM+v/5NwJfg+aVC5gCb6/ydj8dIUa15ZBIYEyRV0ZMSebqavUxr5RM AQBE4Ds27lymU+mWuOARbJZj883+kA4b5zxYy6XJN9k1mp7CmJVBwwhtR1imwLTF2K8H TTf/F90C9wnH7YxP1tgcmeDQlfPJMQec54iq4MJMtBpNiKvPN+OZTi1d27RqAKXA6vBk jrbA== 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=JNCb7nNQ/BSHNgUXwg7W/Xr+UXiq7Cw77wzBKtaIHsA=; fh=D+u40KSnYgjUYLGDRdXdD62xsMHg3nFDmpf3sEnyojA=; b=RR7Roq6NsHk0J2LPiZryo4GZR+uzRH3jL2j48YlBGy4ya4Yphnt4Gno8Gln7kWAVuE akAluxvWhWHEYQFBXHR8t2ykEI5iqxfj+VubxsnwiCEcdzgKvEPKfOdvMlAnDzwLtZc9 xN4jf2RXSTV6YI0yw4KdKtlClpn1Vjk8cdpFlW7JPjz2JqvjFeYL3iC32e8gMXc4sGmc ANNDmwAaeDH/Y3MIJyoRH5emVUt//U5VlGoP+2I0X8BA1+nyTrr3jsKqi9yykjlwkDyI EbI/u4a8SrJo+T1/uJvFfVZwvFI1B1cGInVXo/08u+LkwhHxn+AugNK455D0WF1rJz3D 9F7Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XRchG6Oe; 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-36335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36335-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id jw13-20020a170903278d00b001d7313150c5si6472492plb.595.2024.01.23.18.54.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 18:54:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XRchG6Oe; 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-36335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36335-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8E432B295C4 for ; Wed, 24 Jan 2024 02:47:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AF20182BF; Wed, 24 Jan 2024 02:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XRchG6Oe" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 A4B3A1775A; Wed, 24 Jan 2024 02:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064164; cv=none; b=HlYrl/tfHcJf5MEO/yWIUoQjzvcJBGaScDplS27kIdxJcOtLGEO6haXL7gSsDWEaEKjou79MPrW7kswUYoim9fYOiGe2j5TbBeKNFBKDmHImc/ExquROEx6VsJu5HYKpfLj3Z/VlpE0pr5KJJs/CHDU/F4DVg5n52zdvJmJTHyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064164; c=relaxed/simple; bh=0UE5IUCUA6slej5/EM6zfvBhsHMVYZs9Yfo7sj2LfOU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kPr4wQ+NSPNbk4GBuGfYmKCQSS6l0R9RuFujCBYdUw1O1L4GxtJrQ+GIHpHhLO4lL+JC+tPSIKwOttuPCW0Tahi9odavG6i8VE1fZt8+O4zo+VdBn6qB5joIBpn587NNkgHcQ/KsOO9PreBeULAJYLxfyDE0U21mVPFU5BIzpNU= 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=XRchG6Oe; arc=none smtp.client-ip=192.55.52.120 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=1706064162; x=1737600162; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0UE5IUCUA6slej5/EM6zfvBhsHMVYZs9Yfo7sj2LfOU=; b=XRchG6OeN4qO7/YgppHEaV6KSn10R7WErRL81IN6tTF3RDJ0crXWGG3e O2ysLyzIBA94qrq28Tu4qczlwor6YnOT6wpMWJ1EjdwOZuW/4UT8m4NyM Zoc9vqmHdLko97K/bsD0BPq137kwp5viCs0xREyOX76ABGpzhVdG3Ip3S 4bM6FCinbB8jwvcpBRMzrQebq4Otg9q+kwNMzElflVddnuJ7naGGHTnHt eC9HiRrRzF/JEazvqHLaTy47ay5Wi/KmUe+972AKXpaGf86u7YT3uheIQ H/XiQ8EN3cyT/CcCsp5XrtLDtsop/g8QLZjY/ISnZ82H7OPGTEozLk+4U w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="400586513" X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="400586513" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 18:42:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="1825873" Received: from 984fee00a5ca.jf.intel.com ([10.165.9.183]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 18:42:38 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, yuan.yao@linux.intel.com Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, weijiang.yang@intel.com Subject: [PATCH v9 14/27] KVM: x86: Initialize kvm_caps.supported_xss Date: Tue, 23 Jan 2024 18:41:47 -0800 Message-Id: <20240124024200.102792-15-weijiang.yang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240124024200.102792-1-weijiang.yang@intel.com> References: <20240124024200.102792-1-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Set original kvm_caps.supported_xss to (host_xss & KVM_SUPPORTED_XSS) if XSAVES is supported. host_xss contains the host supported xstate feature bits for thread FPU context switch, KVM_SUPPORTED_XSS includes all KVM enabled XSS feature bits, the resulting value represents the supervisor xstates that are available to guest and are backed by host FPU framework for swapping {guest,host} XSAVE-managed registers/MSRs. Signed-off-by: Yang Weijiang Reviewed-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7b7a15aab3aa..f50c5a523b92 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -226,6 +226,8 @@ static struct kvm_user_return_msrs __percpu *user_return_msrs; | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ | XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE) +#define KVM_SUPPORTED_XSS 0 + u64 __read_mostly host_efer; EXPORT_SYMBOL_GPL(host_efer); @@ -9715,12 +9717,13 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) host_xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK); kvm_caps.supported_xcr0 = host_xcr0 & KVM_SUPPORTED_XCR0; } + if (boot_cpu_has(X86_FEATURE_XSAVES)) { + rdmsrl(MSR_IA32_XSS, host_xss); + kvm_caps.supported_xss = host_xss & KVM_SUPPORTED_XSS; + } rdmsrl_safe(MSR_EFER, &host_efer); - if (boot_cpu_has(X86_FEATURE_XSAVES)) - rdmsrl(MSR_IA32_XSS, host_xss); - kvm_init_pmu_capability(ops->pmu_ops); if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) -- 2.39.3