Skip to contentSkip to conversation

KVM: x86/cpuid: Clear XFD for component i if the base feature is missing

PATCH In review Like Xu 2 participants 4 messages Jan 17, 2022 – Jan 18, 2022

Subsystems (3)
lore
Share & tools
lore

Like Xu

author
#0 lore raw

PATCH 1/1 KVM: x86/cpuid: Clear XFD for component i if the base feature is missing

From: Like Xu <[email protected]>

According to Intel extended feature disable (XFD) spec, the sub-function i (i > 1) of CPUID function 0DH enumerates "details for state component i. ECX[2] enumerates support for XFD support for this state component."

If KVM does not report F(XFD) feature (e.g. due to CONFIG_X86_64), then the corresponding XFD support for any state component i should also be removed. Translate this dependency into KVM terms.

Fixes 690a757d610e ("kvm: x86: Add CPUID support for Intel AMX")
---
 arch/x86/kvm/cpuid.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kvm/cpuid.c +3 -0
index c55e57b30e81..e96efef4f048 100644
@@ -886,6 +886,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 				--array->nent;
 				continue;
 			}
+
+			if (!kvm_cpu_cap_has(X86_FEATURE_XFD))
+				entry->ecx &= ~BIT_ULL(2);
 			entry->edx = 0;
 		}
 		break;
Signature · 1 line
2.33.1
maintainer
#1 lore raw
Quoted 21 lines · Like Xu

From: Like Xu <[email protected]>

According to Intel extended feature disable (XFD) spec, the sub-function i (i > 1) of CPUID function 0DH enumerates "details for state component i. ECX[2] enumerates support for XFD support for this state component."

If KVM does not report F(XFD) feature (e.g. due to CONFIG_X86_64), then the corresponding XFD support for any state component i should also be removed. Translate this dependency into KVM terms.

Fixes 690a757d610e ("kvm: x86: Add CPUID support for Intel AMX")
---
  arch/x86/kvm/cpuid.c | 3 +++
  1 file changed, 3 insertions(+)
arch/x86/kvm/cpuid.c +0 -0
index c55e57b30e81..e96efef4f048 100644

arch/x86/kvm/cpuid.c static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) · line 894

Quoted 9 lines
arch/x86/kvm/cpuid.c +3 -0
@@ -886,6 +886,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
  				--array->nent;
  				continue;
  			}
+
+			if (!kvm_cpu_cap_has(X86_FEATURE_XFD))
+				entry->ecx &= ~BIT_ULL(2);
  			entry->edx = 0;
  		}
  		break;

Generally this is something that is left to userspace. Apart from the usecase of "call KVM_GET_SUPPORTED_CPUID and pass it to KVM_SET_CPUID2", userspace should know what any changed bits mean.

Paolo

author
#2 lore raw
Quoted 35 lines · Paolo Bonzini
Quoted 30 lines · Like Xu

From: Like Xu <[email protected]>

According to Intel extended feature disable (XFD) spec, the sub-function i (i > 1) of CPUID function 0DH enumerates "details for state component i. ECX[2] enumerates support for XFD support for this state component."

If KVM does not report F(XFD) feature (e.g. due to CONFIG_X86_64), then the corresponding XFD support for any state component i should also be removed. Translate this dependency into KVM terms.

Fixes 690a757d610e ("kvm: x86: Add CPUID support for Intel AMX")

---
  arch/x86/kvm/cpuid.c | 3 +++

  1 file changed, 3 insertions(+)
arch/x86/kvm/cpuid.c +3 -0
index c55e57b30e81..e96efef4f048 100644
@@ -886,6 +886,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array 
 *array, u32 function)
                   --array->nent;
                   continue;
               }
+
+            if (!kvm_cpu_cap_has(X86_FEATURE_XFD))
+                entry->ecx &= ~BIT_ULL(2);
               entry->edx = 0;
           }
Quoted 1 line

          break;

Generally this is something that is left to userspace.  Apart from the usecase of "call KVM_GET_SUPPORTED_CPUID and pass it to KVM_SET_CPUID2", userspace should know what any changed bits mean.

Quoted 2 lines

Paolo

I totally agree that setting the appropriate CPUID bits for a feature is a user space thing.

But this patch is more focused on fixing a different type of problem, which is that the capabilities exposed by KVM should not *contradict each other* :

a user space may be confused with the current code base :
- why KVM does not have F(XFD) feature (MSR_IA32_XFD and XFD_ERR non-exit),
- but KVM reports XFD support for state component i individually;

This is like KVM reporting PEBS when no PMU capacity is reported (due to module param).

Does this clarification help ?

Thanks,
Like Xu

maintainer
#3 lore raw
Quoted 41 lines · Like Xu
Quoted 35 lines · Paolo Bonzini
Quoted 30 lines · Like Xu

From: Like Xu <[email protected]>

According to Intel extended feature disable (XFD) spec, the sub-function i (i > 1) of CPUID function 0DH enumerates "details for state component i. ECX[2] enumerates support for XFD support for this state component."

If KVM does not report F(XFD) feature (e.g. due to CONFIG_X86_64), then the corresponding XFD support for any state component i should also be removed. Translate this dependency into KVM terms.

Fixes 690a757d610e ("kvm: x86: Add CPUID support for Intel AMX")

---
  arch/x86/kvm/cpuid.c | 3 +++

  1 file changed, 3 insertions(+)
arch/x86/kvm/cpuid.c +3 -0
index c55e57b30e81..e96efef4f048 100644
@@ -886,6 +886,9 @@ static inline int __do_cpuid_func(struct 
 kvm_cpuid_array *array, u32 function)
                   --array->nent;
                   continue;
               }
+
+            if (!kvm_cpu_cap_has(X86_FEATURE_XFD))
+                entry->ecx &= ~BIT_ULL(2);
               entry->edx = 0;
           }
Quoted 1 line

          break;

Generally this is something that is left to userspace.  Apart from the usecase of "call KVM_GET_SUPPORTED_CPUID and pass it to KVM_SET_CPUID2", userspace should know what any changed bits mean.

Quoted 2 lines

Paolo

I totally agree that setting the appropriate CPUID bits for a feature is a user space thing.

Quoted 7 lines

But this patch is more focused on fixing a different type of problem, which is that the capabilities exposed by KVM should not *contradict each other* :

    a user space may be confused with the current code base :
    - why KVM does not have F(XFD) feature (MSR_IA32_XFD and XFD_ERR
non-exit),
    - but KVM reports XFD support for state component i individually;

Got it. Yeah, the patch makes sense for the sake of CONFIG_X86_64.

Paolo

Quoted 1 line

This is like KVM reporting PEBS when no PMU capacity is reported (due to module param).