From nobody Sun Oct 5 00:09:22 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 3F1C32E54BE; Tue, 12 Aug 2025 02:56:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754967394; cv=none; b=CxR91Kby1v/FLs9EN88z8T7FtMuw4IrHUVH6Q8aJlxOBgL92NhDJhaF/kFPn6K324S6CwW22A5Xf8sWHWmrYDL+n0lQY7qQcNPebsh8uMXKQcPupWJBXlgozEI13CZuQ8jT4BEVrAluph1fEwII5Bk4EcRQbVTOLT+LEes0WpA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754967394; c=relaxed/simple; bh=fb9MNzqI9AYMQgj0Sy+jl5waBqpWeSu18aiJ0OmUcPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qhwEk9uaQoyufo01o1uSVOvC07qxMQbZhrFSX4Ip4lhMQtclix8jh+Mj/nE03tIT32wslHG0DEnK/C7DBhb4oa2+KHQqmFXFsw2I7CuhsEjr6IkOt5RxArjEpWO61mTb/f68VeYupWBHSzV1rS8l6UsGocl7lcCTS2/38cnFWPQ= 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=fQXXuNbt; arc=none smtp.client-ip=198.175.65.19 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fQXXuNbt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1754967393; x=1786503393; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fb9MNzqI9AYMQgj0Sy+jl5waBqpWeSu18aiJ0OmUcPI=; b=fQXXuNbtP24DZOlW/4MIBvjMdxAqxqSSLmg8IpKdNAPIsujUBkFIaWSH vhrMGyNpMXpr8HcfQhqAUpnbtBDCzxt0WFcGFuJ9XY/aqH+/iv7sSN49T OGUsC1HcP2SzIW24o3sOasEIj/BFu9zx8P5WuSGFEV/ivFGfc5JjKJKH4 szL3eRbJTTaBN1P9wuZSJcWjNWp6SPY46QTAVSmtoAxiZpzH1IHze14cN SKy+at/6ZzJPvUs1e2t2HZtMblQqKxjnPd3mIsdBt+JS79VS1qePKMl3o uvnPOlKXTmy/X8oklVgxex0/4K7WRs/w068hePvJjsJoacn/kQHjxk7SW A==; X-CSE-ConnectionGUID: /IleTJDoQyqZKvJcCCLBIw== X-CSE-MsgGUID: WdcvRvBWSDqR+D1Kfg29dg== X-IronPort-AV: E=McAfee;i="6800,10657,11518"; a="57100511" X-IronPort-AV: E=Sophos;i="6.17,284,1747724400"; d="scan'208";a="57100511" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2025 19:56:29 -0700 X-CSE-ConnectionGUID: DgCd/eGJR4WYbfaKiQQcXw== X-CSE-MsgGUID: 5eo/vqaiQOWKxhV5cHf1zg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,284,1747724400"; d="scan'208";a="171321274" Received: from 984fee019967.jf.intel.com ([10.165.54.94]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2025 19:56:29 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: mlevitsk@redhat.com, rick.p.edgecombe@intel.com, weijiang.yang@intel.com, xin@zytor.com, Chao Gao , Mathias Krause , John Allen , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v12 09/24] KVM: x86: Initialize kvm_caps.supported_xss Date: Mon, 11 Aug 2025 19:55:17 -0700 Message-ID: <20250812025606.74625-10-chao.gao@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250812025606.74625-1-chao.gao@intel.com> References: <20250812025606.74625-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yang Weijiang 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 Reviewed-by: Chao Gao Tested-by: Mathias Krause Tested-by: John Allen Signed-off-by: Chao Gao --- arch/x86/kvm/x86.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c91472d36717..235a5de66e68 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -220,6 +220,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 + bool __read_mostly allow_smaller_maxphyaddr =3D 0; EXPORT_SYMBOL_GPL(allow_smaller_maxphyaddr); =20 @@ -9762,14 +9764,17 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *op= s) kvm_host.xcr0 =3D xgetbv(XCR_XFEATURE_ENABLED_MASK); kvm_caps.supported_xcr0 =3D kvm_host.xcr0 & KVM_SUPPORTED_XCR0; } + + if (boot_cpu_has(X86_FEATURE_XSAVES)) { + rdmsrq(MSR_IA32_XSS, kvm_host.xss); + kvm_caps.supported_xss =3D kvm_host.xss & KVM_SUPPORTED_XSS; + } + kvm_caps.supported_quirks =3D KVM_X86_VALID_QUIRKS; kvm_caps.inapplicable_quirks =3D KVM_X86_CONDITIONAL_QUIRKS; =20 rdmsrq_safe(MSR_EFER, &kvm_host.efer); =20 - if (boot_cpu_has(X86_FEATURE_XSAVES)) - rdmsrq(MSR_IA32_XSS, kvm_host.xss); - kvm_init_pmu_capability(ops->pmu_ops); =20 if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) --=20 2.47.1