From nobody Wed Dec 17 10:54:37 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3FACC0015E for ; Thu, 3 Aug 2023 07:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234057AbjHCHhQ (ORCPT ); Thu, 3 Aug 2023 03:37:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbjHCHgG (ORCPT ); Thu, 3 Aug 2023 03:36:06 -0400 Received: from mgamail.intel.com (unknown [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1DAE49D6; Thu, 3 Aug 2023 00:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691047938; x=1722583938; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iob2WlcaBJVHzzN0CVpB4q36QOk92fLy0+YqXdTOxuI=; b=GUkFSN0vSY6S9N7VrY9a9L83bLJqULQzbkZ19i06HBfPahd8xgpDgAcE HP8OJiHviPJ2l463ruiGPu0jslboVn7VWVR9sRXLLTl5/qp9BIuMiR0xG PuSAbUkZH6AHiIPm7AAu07hqq89XZ/aziScj9xPzWSTOJxbrpcONB0RvE phWx5qnjGSB6+XJZKejnLBvfhQUGaE5KWCGOJlTD0AiuxDmqWS196gx0g E7bvNYa0puivYRqfZthDs710DdHtCpMxDxNwD6YpSrU8scjhpaYt8fRVY IEQ20C98adMyf8N96IfWxzYlUu6s2siOyaDCC8fjjpcPLlzFC2OZoVFqX w==; X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="354708104" X-IronPort-AV: E=Sophos;i="6.01,251,1684825200"; d="scan'208";a="354708104" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2023 00:32:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="794888479" X-IronPort-AV: E=Sophos;i="6.01,251,1684825200"; d="scan'208";a="794888479" Received: from embargo.jf.intel.com ([10.165.9.183]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2023 00:32:15 -0700 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, john.allen@amd.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: rick.p.edgecombe@intel.com, chao.gao@intel.com, binbin.wu@linux.intel.com, weijiang.yang@intel.com Subject: [PATCH v5 05/19] KVM:x86: Initialize kvm_caps.supported_xss Date: Thu, 3 Aug 2023 00:27:18 -0400 Message-Id: <20230803042732.88515-6-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230803042732.88515-1-weijiang.yang@intel.com> References: <20230803042732.88515-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Set kvm_caps.supported_xss to host_xss && KVM XSS mask. host_xss contains the host supported xstate feature bits for thread context switch, KVM_SUPPORTED_XSS includes all KVM enabled XSS feature bits, the operation result represents all KVM supported feature bits. Since the result is subset of host_xss, the related XSAVE-managed MSRs are automatically swapped for guest and host when vCPU exits to userspace. Signed-off-by: Yang Weijiang --- arch/x86/kvm/vmx/vmx.c | 1 - arch/x86/kvm/x86.c | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 0ecf4be2c6af..c8d9870cfecb 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7849,7 +7849,6 @@ static __init void vmx_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_UMIP); =20 /* CPUID 0xD.1 */ - kvm_caps.supported_xss =3D 0; if (!cpu_has_vmx_xsaves()) kvm_cpu_cap_clear(X86_FEATURE_XSAVES); =20 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5d6d6fa33e5b..e9f3627d5fdd 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -225,6 +225,8 @@ static struct kvm_user_return_msrs __percpu *user_retur= n_msrs; | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ | XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE) =20 +#define KVM_SUPPORTED_XSS 0 + u64 __read_mostly host_efer; EXPORT_SYMBOL_GPL(host_efer); =20 @@ -9498,8 +9500,10 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init= _ops *ops) =20 rdmsrl_safe(MSR_EFER, &host_efer); =20 - if (boot_cpu_has(X86_FEATURE_XSAVES)) + if (boot_cpu_has(X86_FEATURE_XSAVES)) { rdmsrl(MSR_IA32_XSS, host_xss); + kvm_caps.supported_xss =3D host_xss & KVM_SUPPORTED_XSS; + } =20 kvm_init_pmu_capability(ops->pmu_ops); =20 --=20 2.27.0