All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lewis <aaronlewis@google.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com,
	like.xu.linux@gmail.com, Aaron Lewis <aaronlewis@google.com>
Subject: [PATCH 1/3] KVM: x86: Clear XTILE_CFG if XTILE_DATA is clear
Date: Tue, 27 Dec 2022 18:37:13 +0000	[thread overview]
Message-ID: <20221227183713.29140-2-aaronlewis@google.com> (raw)
In-Reply-To: <20221227183713.29140-1-aaronlewis@google.com>

Be good citizens by clearing both
CPUID.(EAX=0DH,ECX=0):EAX.XTILECFG[bit-17] and
CPUID.(EAX=0DH,ECX=0):EAX.XTILEDATA[bit-18] if they are both not set.
That way userspace or a guest doesn't fail if it attempts to set XCR0
with the user xfeature bits, i.e. EDX:EAX of CPUID.(EAX=0DH,ECX=0).

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Aaron Lewis <aaronlewis@google.com>
---
 arch/x86/kvm/cpuid.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 0b5bf013fcb8e..2d9910847786a 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -977,6 +977,10 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 		u64 permitted_xcr0 = kvm_caps.supported_xcr0 & xstate_get_guest_group_perm();
 		u64 permitted_xss = kvm_caps.supported_xss;
 
+		if (!(permitted_xcr0 & XFEATURE_MASK_XTILE_CFG) ||
+		    !(permitted_xcr0 & XFEATURE_MASK_XTILE_DATA))
+			permitted_xcr0 &= ~XFEATURE_MASK_XTILE;
+
 		entry->eax &= permitted_xcr0;
 		entry->ebx = xstate_required_size(permitted_xcr0, false);
 		entry->ecx = entry->ebx;
-- 
2.39.0.314.g84b9a713c41-goog


  reply	other threads:[~2022-12-27 18:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-27 18:37 [PATCH 0/3] Clean up AMX cpuid bits XTILE_CFG and XTILE_DATA Aaron Lewis
2022-12-27 18:37 ` Aaron Lewis [this message]
2022-12-27 19:56   ` [PATCH 1/3] KVM: x86: Clear XTILE_CFG if XTILE_DATA is clear Jim Mattson
2022-12-27 20:43     ` Aaron Lewis
2022-12-27 21:14       ` Jim Mattson
2022-12-27 21:36         ` Jim Mattson
2022-12-27 18:37 ` [PATCH 2/3] KVM: selftests: Hoist XGETBV and XSETBV to make them more accessible Aaron Lewis
2022-12-27 21:23   ` Jim Mattson
2022-12-27 18:37 ` [PATCH 3/3] KVM: selftests: Add XCR0 Test Aaron Lewis
2022-12-27 22:07   ` Jim Mattson
2022-12-28  0:15     ` Aaron Lewis
2022-12-27 20:00 ` [PATCH 0/3] Clean up AMX cpuid bits XTILE_CFG and XTILE_DATA Jim Mattson
2022-12-27 20:40   ` Aaron Lewis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221227183713.29140-2-aaronlewis@google.com \
    --to=aaronlewis@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=like.xu.linux@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.