From nobody Sun Feb 8 23:04:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 A39B42D627; Mon, 19 Feb 2024 07:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328873; cv=none; b=ZAy7ESdqaH7f8QapLJ9xDfjmfljR87KdUWbhH3y10okPLGsLbGGucRP9OeuznpND3tWB8anoBx2l9o/ryxe8S0KFuxDX0k2PH4phX5wENDIQYf3VjQGGN5EtjqqYl4yHshTybwwkbDN2opOEvHUJDmyk6H5rRH58oVzRdcfs4j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328873; c=relaxed/simple; bh=sWkl7Z3XxOiuJFtnFAhcpB/qRiA1y0PFYes31RKezFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QKjFdkUMbMlzWc7252S2qVg0sZ/DHwubi1vjir2ytd+rCScaY1SyWdl07Un3WKJPEci9Bc/aWnQ4v5whNYB62S0K2QkozaH2CFZB0q4kQHQasxIyaGfqolIAP1MoBkH6+hC3LP2NfFm4QxSob2/OyY4QUwnchrv+EyQBcLxoNw0= 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=lTH9M97n; arc=none smtp.client-ip=198.175.65.16 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="lTH9M97n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708328871; x=1739864871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sWkl7Z3XxOiuJFtnFAhcpB/qRiA1y0PFYes31RKezFo=; b=lTH9M97n9BU2W5/5FNjSZFQ+Fq5DK0ssFnfmMXcpBh2p2OoLxE2uSsGp oKpZzpk0N0WRpf3kmC44QoS1G8YEgXa4Fqr7CKXsTNNiYRohrInr8skn5 2xKHsoy7hzF9mi094PhAGnciJv434/y3TE3e7/29kDG+BlW8Jnw3rNJWt ZAGLRrjOvPjwJn8++J4Tq1gqXTrNjM2oNKXFlPiNM4iUqCv/gd4mKum77 pw/lLoWpcw/TuxAgtF/owZXHFQllGmPwC0+n8EhuEgSzuFnqs1elN7lYb oV4MBdY/XVphfI8vxU7wYtRu/uuMLaCScI9Oeax1cCjEw9cwk6kqRtLZm g==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="2535101" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="2535101" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2024 23:47:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="826966098" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="826966098" Received: from jf.jf.intel.com (HELO jf.intel.com) ([10.165.9.183]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2024 23:47:43 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, x86@kernel.org, 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 v10 14/27] KVM: x86: Initialize kvm_caps.supported_xss Date: Sun, 18 Feb 2024 23:47:20 -0800 Message-ID: <20240219074733.122080-15-weijiang.yang@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240219074733.122080-1-weijiang.yang@intel.com> References: <20240219074733.122080-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 b502d68a2576..60b574fc04d1 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_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 @@ -9737,12 +9739,13 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *op= s) host_xcr0 =3D xgetbv(XCR_XFEATURE_ENABLED_MASK); kvm_caps.supported_xcr0 =3D host_xcr0 & KVM_SUPPORTED_XCR0; } + if (boot_cpu_has(X86_FEATURE_XSAVES)) { + rdmsrl(MSR_IA32_XSS, host_xss); + kvm_caps.supported_xss =3D host_xss & KVM_SUPPORTED_XSS; + } =20 rdmsrl_safe(MSR_EFER, &host_efer); =20 - if (boot_cpu_has(X86_FEATURE_XSAVES)) - rdmsrl(MSR_IA32_XSS, host_xss); - kvm_init_pmu_capability(ops->pmu_ops); =20 if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) --=20 2.43.0