Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp19088rdb; Thu, 21 Dec 2023 01:15:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaeqfIofWwxUUeY/0NLUmlbNvJRf009YG1dgzHZ1HNll56Dm3byCNB6N32q1bWfg7NyaCv X-Received: by 2002:a05:6214:1c6:b0:67e:e37c:6f73 with SMTP id c6-20020a05621401c600b0067ee37c6f73mr16570340qvt.54.1703150121408; Thu, 21 Dec 2023 01:15:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703150121; cv=none; d=google.com; s=arc-20160816; b=Xj+B5qFFabC2gPSU84CXT0+ObsjgPnrH8iEEMJwNtYmzP7LuHy1jvmhaw31iOpdSrg QXmuQJpFXpNXkETVffG+mL8+xz7xKfhjsZGUmNNWp3mMaTlFHGu2/4pQIKUz5V8hNVys WQdxIP+Nw0YdWSLm/DwjfxTg7pHzKxQ6c/CR22/EWl17t2+keS9hmRMODWYI/a48KzEk SdAeU/79GXMEmTF3e9sCtvkpx+uWPEC07lfh5c/ZJjKMN5LbXsZg4xSbdX7bZEmyMgLz q/OE3QJxiENRyVMWuDfnqY/JC04BSQTqde5Bt1ITkFJYw7+caHl0ZgDzUCdOXOHxRJRh bt+Q== ARC-Message-Signature: i=1; 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=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=OYFeXSRsQchtUToozMn4/gSwqOi7LdVLtukOApBilMAhJWtIq3pr/H+XCKprH2FTCy Qpd2NDhgYI9MsdbkPYnAuPxVXwoH2svKOP76u9fzWxvyiVA+2isi63Ozg2H3MlOhsFJ6 JgWQIpQWjAbSZGn5Uu+93NNT41aCuRWkkfz7gwBRp+nEltgj5LMEfs2cTx6ixsVY8fKG rUecigO4vUd0q/rndflHV8lxldYI6uwRO/HaWw26yTCIBoM/TyMABDLAGMrM+OerxxTB EDM8q30D3R6xhr20XsK370VVcqA4gOV8FRt0T3tooQa5cjCCIsjJB6TPaftKcwxRGHlp mIeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Glfp35Nz; spf=pass (google.com: domain of linux-kernel+bounces-8071-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8071-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bj16-20020a05620a191000b007758f31d28fsi1855113qkb.301.2023.12.21.01.15.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:15:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8071-linux.lists.archive=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=Glfp35Nz; spf=pass (google.com: domain of linux-kernel+bounces-8071-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8071-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2C5941C21C42 for ; Thu, 21 Dec 2023 09:15:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CF9356383; Thu, 21 Dec 2023 09:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Glfp35Nz" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) (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 22E7E53E04; Thu, 21 Dec 2023 09:03:51 +0000 (UTC) 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=1703149431; x=1734685431; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0UE5IUCUA6slej5/EM6zfvBhsHMVYZs9Yfo7sj2LfOU=; b=Glfp35NzN1ho94K2H/gU1v3xKJJ0feXY3Bx04leO5r3CgN5u3g4G3RvS tyKpOxg3/OQ2u1NGoh37WHyxwO7fAZOWuv0CaaSLykibF+etPTN83+x+K e3+sZyJX4lfaVgjIaYswm2IrB34Ibh+TuhEOJtt/jqLhubeUAG2rJ60+0 C3vySkDhL2OvGitbPyV11EToSR3OloSyDqpMoP2wQZHDa6lTef22cQx9m tmcbuK4b3zhwrbjDibHUTq84kym1w3/9pj5JyQfBKSO/t6S9sttR0Wt7t r/pHBiBb30ESlw6N8NeTEshw/qXi21zRJYVIwgIKQwIEM0pIuwe7iVVw8 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="398729657" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="398729657" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="900028603" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="900028603" Received: from 984fee00a5ca.jf.intel.com (HELO embargo.jf.intel.com) ([10.165.9.183]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:11 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org 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 v8 14/26] KVM: x86: Initialize kvm_caps.supported_xss Date: Thu, 21 Dec 2023 09:02:27 -0500 Message-Id: <20231221140239.4349-15-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231221140239.4349-1-weijiang.yang@intel.com> References: <20231221140239.4349-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