From: Paolo Bonzini <pbonzini@redhat.com>
To: Like Xu <like.xu.linux@gmail.com>
Cc: Tian Kevin <kevin.tian@intel.com>,
Jim Mattson <jmattson@google.com>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/cpuid: Exclude unpermitted xfeatures sizes at KVM_GET_SUPPORTED_CPUID
Date: Mon, 24 Jan 2022 15:00:05 +0100 [thread overview]
Message-ID: <f4ddcedc-4a81-4f4e-f3f4-8388120a0776@redhat.com> (raw)
In-Reply-To: <20220124080251.60558-1-likexu@tencent.com>
On 1/24/22 09:02, Like Xu wrote:
> case 0xd: {
> - u64 guest_perm = xstate_get_guest_group_perm();
> + u64 supported_xcr0 = supported_xcr0 & xstate_get_guest_group_perm();
>
> - entry->eax &= supported_xcr0 & guest_perm;
> + entry->eax &= supported_xcr0;
> entry->ebx = xstate_required_size(supported_xcr0, false);
> entry->ecx = entry->ebx;
> - entry->edx &= (supported_xcr0 & guest_perm) >> 32;
> + entry->edx &= supported_xcr0 >> 32;
> if (!supported_xcr0)
> break;
>
No, please don't use this kind of shadowing. I'm not even sure it
works, and one would have to read the C standard or look at the
disassembly to be sure. Perhaps this instead could be an idea:
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 3dcd58a138a9..03deb51d8d18 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -887,13 +887,14 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
}
break;
case 0xd: {
- u64 supported_xcr0 = supported_xcr0 & xstate_get_guest_group_perm();
+ u64 permitted_xcr0 = supported_xcr0 & xstate_get_guest_group_perm();
- entry->eax &= supported_xcr0;
- entry->ebx = xstate_required_size(supported_xcr0, false);
+#define supported_xcr0 DO_NOT_USE_ME
+ entry->eax &= permitted_xcr0;
+ entry->ebx = xstate_required_size(permitted_xcr0, false);
entry->ecx = entry->ebx;
- entry->edx &= supported_xcr0 >> 32;
- if (!supported_xcr0)
+ entry->edx &= permitted_xcr0 >> 32;
+ if (!permitted_xcr0)
break;
entry = do_host_cpuid(array, function, 1);
@@ -902,7 +903,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
cpuid_entry_override(entry, CPUID_D_1_EAX);
if (entry->eax & (F(XSAVES)|F(XSAVEC)))
- entry->ebx = xstate_required_size(supported_xcr0 | supported_xss,
+ entry->ebx = xstate_required_size(permitted_xcr0 | supported_xss,
true);
else {
WARN_ON_ONCE(supported_xss != 0);
@@ -913,7 +914,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
for (i = 2; i < 64; ++i) {
bool s_state;
- if (supported_xcr0 & BIT_ULL(i))
+ if (permitted_xcr0 & BIT_ULL(i))
s_state = false;
else if (supported_xss & BIT_ULL(i))
s_state = true;
@@ -942,6 +943,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
entry->edx = 0;
}
break;
+#undef supported_xcr0
}
case 0x12:
/* Intel SGX */
or alternatively add
u64 permitted_xss = supported_xss;
so that you use "permitted" consistently. Anybody can vote on what they
prefer (including "permitted_xcr0" and no #define/#undef).
Paolo
next prev parent reply other threads:[~2022-01-24 14:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 8:02 Like Xu
2022-01-24 14:00 ` Paolo Bonzini [this message]
2022-01-25 1:26 ` Tian, Kevin
2022-01-24 14:40 ` kernel test robot
2022-01-25 3:48 ` kernel test robot
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=f4ddcedc-4a81-4f4e-f3f4-8388120a0776@redhat.com \
--to=pbonzini@redhat.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®