* [PATCH 1/3] KVM: x86: Insert "AMD" in KVM_X86_FEATURE_PSFD
@ 2022-08-26 21:00 Jim Mattson
2022-08-26 21:00 ` [PATCH 2/3] KVM: x86: Report CPUID.7.1 support on CPUs with CPUID.7 indices > 1 Jim Mattson
2022-08-26 21:00 ` [PATCH 3/3] KVM: x86: Expose Predictive Store Forwarding Disable on Intel parts Jim Mattson
0 siblings, 2 replies; 5+ messages in thread
From: Jim Mattson @ 2022-08-26 21:00 UTC (permalink / raw)
To: kvm, pbonzini; +Cc: Jim Mattson, Babu Moger
Intel and AMD have separate CPUID bits for each SPEC_CTRL bit. In the
case of every bit other than PFSD, the Intel CPUID bit has no vendor
name qualifier, but the AMD CPUID bit does. For consistency, rename
KVM_X86_FEATURE_PSFD to KVM_X86_FEATURE_AMD_PSFD.
No functional change intended.
Signed-off-by: Jim Mattson <jmattson@google.com>
Cc: Babu Moger <Babu.Moger@amd.com>
---
arch/x86/kvm/cpuid.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 75dcf7a72605..07be45c5bb93 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -62,7 +62,7 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted)
* This one is tied to SSB in the user API, and not
* visible in /proc/cpuinfo.
*/
-#define KVM_X86_FEATURE_PSFD (13*32+28) /* Predictive Store Forwarding Disable */
+#define KVM_X86_FEATURE_AMD_PSFD (13*32+28) /* Predictive Store Forwarding Disable */
#define F feature_bit
#define SF(name) (boot_cpu_has(X86_FEATURE_##name) ? F(name) : 0)
@@ -673,7 +673,7 @@ void kvm_set_cpu_caps(void)
F(CLZERO) | F(XSAVEERPTR) |
F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) |
F(AMD_SSB_NO) | F(AMD_STIBP) | F(AMD_STIBP_ALWAYS_ON) |
- __feature_bit(KVM_X86_FEATURE_PSFD)
+ __feature_bit(KVM_X86_FEATURE_AMD_PSFD)
);
/*
--
2.37.2.672.g94769d06f0-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] KVM: x86: Report CPUID.7.1 support on CPUs with CPUID.7 indices > 1
2022-08-26 21:00 [PATCH 1/3] KVM: x86: Insert "AMD" in KVM_X86_FEATURE_PSFD Jim Mattson
@ 2022-08-26 21:00 ` Jim Mattson
2022-08-26 23:54 ` Sean Christopherson
2022-08-26 21:00 ` [PATCH 3/3] KVM: x86: Expose Predictive Store Forwarding Disable on Intel parts Jim Mattson
1 sibling, 1 reply; 5+ messages in thread
From: Jim Mattson @ 2022-08-26 21:00 UTC (permalink / raw)
To: kvm, pbonzini; +Cc: Jim Mattson, Sean Christopherson
Previously, KVM reported support for CPUID.(EAX=7,ECX=1) only if the
maximum leaf 7 index on the host was exactly 1. A recent microcode
patch for Ice Lake raised the maximum leaf 7 index from 0 to 2,
skipping right over 1. Though that patch left CPUID.(EAX=7,ECX=1)
filled with zeros on Ice Lake, it nonetheless exposed this bug.
Report CPUID.(EAX=7,ECX=1) support if the maximum leaf 7 index on the
host is at least 1.
Cc: Sean Christopherson <seanjc@google.com>
Fixes: bcf600ca8d21 ("KVM: x86: Remove the unnecessary loop on CPUID 0x7 sub-leafs")
Signed-off-by: Jim Mattson <jmattson@google.com>
---
arch/x86/kvm/cpuid.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 07be45c5bb93..64cdabb3cb2c 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -886,7 +886,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
cpuid_entry_override(entry, CPUID_7_EDX);
/* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */
- if (entry->eax == 1) {
+ if (entry->eax >= 1) {
entry = do_host_cpuid(array, function, 1);
if (!entry)
goto out;
--
2.37.2.672.g94769d06f0-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] KVM: x86: Expose Predictive Store Forwarding Disable on Intel parts
2022-08-26 21:00 [PATCH 1/3] KVM: x86: Insert "AMD" in KVM_X86_FEATURE_PSFD Jim Mattson
2022-08-26 21:00 ` [PATCH 2/3] KVM: x86: Report CPUID.7.1 support on CPUs with CPUID.7 indices > 1 Jim Mattson
@ 2022-08-26 21:00 ` Jim Mattson
1 sibling, 0 replies; 5+ messages in thread
From: Jim Mattson @ 2022-08-26 21:00 UTC (permalink / raw)
To: kvm, pbonzini; +Cc: Jim Mattson
Intel enumerates support for PSFD in CPUID.(EAX=7,ECX=2):EDX.PSFD[bit
0]. Report support for this feature in KVM if it is available on the
host.
Presumably, this feature bit, like its AMD counterpart, is not welcome
in cpufeatures.h, so add a local definition of this feature in KVM.
Signed-off-by: Jim Mattson <jmattson@google.com>
---
arch/x86/kvm/cpuid.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 64cdabb3cb2c..b5af9e451bef 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -62,6 +62,7 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted)
* This one is tied to SSB in the user API, and not
* visible in /proc/cpuinfo.
*/
+#define KVM_X86_FEATURE_PSFD 0 /* Predictive Store Forwarding Disable */
#define KVM_X86_FEATURE_AMD_PSFD (13*32+28) /* Predictive Store Forwarding Disable */
#define F feature_bit
@@ -677,9 +678,9 @@ void kvm_set_cpu_caps(void)
);
/*
- * AMD has separate bits for each SPEC_CTRL bit.
- * arch/x86/kernel/cpu/bugs.c is kind enough to
- * record that in cpufeatures so use them.
+ * AMD has separate bits for each SPEC_CTRL bit. Except for
+ * PSFD, arch/x86/kernel/cpu/bugs.c is kind enough to record
+ * that in cpufeatures so use them.
*/
if (boot_cpu_has(X86_FEATURE_IBPB))
kvm_cpu_cap_set(X86_FEATURE_AMD_IBPB);
@@ -880,13 +881,13 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
break;
/* function 7 has additional index. */
case 7:
- entry->eax = min(entry->eax, 1u);
+ /* KVM only supports leaf 7 indices 0 through 2. */
+ max_idx = entry->eax = min(entry->eax, 2u);
cpuid_entry_override(entry, CPUID_7_0_EBX);
cpuid_entry_override(entry, CPUID_7_ECX);
cpuid_entry_override(entry, CPUID_7_EDX);
- /* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */
- if (entry->eax >= 1) {
+ if (max_idx >= 1) {
entry = do_host_cpuid(array, function, 1);
if (!entry)
goto out;
@@ -896,6 +897,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
entry->ecx = 0;
entry->edx = 0;
}
+ if (max_idx >= 2) {
+ entry = do_host_cpuid(array, function, 2);
+ if (!entry)
+ goto out;
+
+ entry->eax = 0;
+ entry->ebx = 0;
+ entry->ecx = 0;
+ entry->edx &= BIT(KVM_X86_FEATURE_PSFD);
+ }
break;
case 9:
break;
--
2.37.2.672.g94769d06f0-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] KVM: x86: Report CPUID.7.1 support on CPUs with CPUID.7 indices > 1
2022-08-26 21:00 ` [PATCH 2/3] KVM: x86: Report CPUID.7.1 support on CPUs with CPUID.7 indices > 1 Jim Mattson
@ 2022-08-26 23:54 ` Sean Christopherson
2022-08-27 16:51 ` Jim Mattson
0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2022-08-26 23:54 UTC (permalink / raw)
To: Jim Mattson; +Cc: kvm, pbonzini
On Fri, Aug 26, 2022, Jim Mattson wrote:
> Previously, KVM reported support for CPUID.(EAX=7,ECX=1) only if the
> maximum leaf 7 index on the host was exactly 1. A recent microcode
> patch for Ice Lake raised the maximum leaf 7 index from 0 to 2,
> skipping right over 1. Though that patch left CPUID.(EAX=7,ECX=1)
> filled with zeros on Ice Lake, it nonetheless exposed this bug.
>
> Report CPUID.(EAX=7,ECX=1) support if the maximum leaf 7 index on the
> host is at least 1.
>
> Cc: Sean Christopherson <seanjc@google.com>
> Fixes: bcf600ca8d21 ("KVM: x86: Remove the unnecessary loop on CPUID 0x7 sub-leafs")
> Signed-off-by: Jim Mattson <jmattson@google.com>
> ---
> arch/x86/kvm/cpuid.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 07be45c5bb93..64cdabb3cb2c 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -886,7 +886,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
> cpuid_entry_override(entry, CPUID_7_EDX);
>
> /* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */
> - if (entry->eax == 1) {
> + if (entry->eax >= 1) {
But as the comment says, above this is:
entry->eax = min(entry->eax, 1u);
...
/* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */
if (entry->eax == 1) {
What am I missing?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] KVM: x86: Report CPUID.7.1 support on CPUs with CPUID.7 indices > 1
2022-08-26 23:54 ` Sean Christopherson
@ 2022-08-27 16:51 ` Jim Mattson
0 siblings, 0 replies; 5+ messages in thread
From: Jim Mattson @ 2022-08-27 16:51 UTC (permalink / raw)
To: Sean Christopherson; +Cc: kvm, pbonzini
On Fri, Aug 26, 2022 at 4:54 PM Sean Christopherson <seanjc@google.com> wrote:
>
> On Fri, Aug 26, 2022, Jim Mattson wrote:
> > Previously, KVM reported support for CPUID.(EAX=7,ECX=1) only if the
> > maximum leaf 7 index on the host was exactly 1. A recent microcode
> > patch for Ice Lake raised the maximum leaf 7 index from 0 to 2,
> > skipping right over 1. Though that patch left CPUID.(EAX=7,ECX=1)
> > filled with zeros on Ice Lake, it nonetheless exposed this bug.
> >
> > Report CPUID.(EAX=7,ECX=1) support if the maximum leaf 7 index on the
> > host is at least 1.
> >
> > Cc: Sean Christopherson <seanjc@google.com>
> > Fixes: bcf600ca8d21 ("KVM: x86: Remove the unnecessary loop on CPUID 0x7 sub-leafs")
> > Signed-off-by: Jim Mattson <jmattson@google.com>
> > ---
> > arch/x86/kvm/cpuid.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> > index 07be45c5bb93..64cdabb3cb2c 100644
> > --- a/arch/x86/kvm/cpuid.c
> > +++ b/arch/x86/kvm/cpuid.c
> > @@ -886,7 +886,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
> > cpuid_entry_override(entry, CPUID_7_EDX);
> >
> > /* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */
> > - if (entry->eax == 1) {
> > + if (entry->eax >= 1) {
>
> But as the comment says, above this is:
>
> entry->eax = min(entry->eax, 1u);
>
> ...
>
> /* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */
> if (entry->eax == 1) {
>
> What am I missing?
It's not you; it's me. There's no bug here.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-27 16:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-26 21:00 [PATCH 1/3] KVM: x86: Insert "AMD" in KVM_X86_FEATURE_PSFD Jim Mattson
2022-08-26 21:00 ` [PATCH 2/3] KVM: x86: Report CPUID.7.1 support on CPUs with CPUID.7 indices > 1 Jim Mattson
2022-08-26 23:54 ` Sean Christopherson
2022-08-27 16:51 ` Jim Mattson
2022-08-26 21:00 ` [PATCH 3/3] KVM: x86: Expose Predictive Store Forwarding Disable on Intel parts Jim Mattson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox