diff mbox series

[5/6] KVM: x86: Mask off reserved bits in CPUID.8000001EH

Message ID 20220929225203.2234702-5-jmattson@google.com (mailing list archive)
State New, archived
Headers show
Series [1/6] KVM: x86: Mask off reserved bits in CPUID.80000001H | expand

Commit Message

Jim Mattson Sept. 29, 2022, 10:52 p.m. UTC
KVM_GET_SUPPORTED_CPUID should only enumerate features that KVM
actually supports. The following ranges of CPUID.8000001EH are reserved
and should be masked off:
    EBX[31:16]
    ECX[31:11]
    EDX[31:0]

Fixes: 382409b4c43e ("kvm: x86: Include CPUID leaf 0x8000001e in kvm's supported CPUID")
Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/cpuid.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Sean Christopherson Oct. 19, 2022, 10:53 p.m. UTC | #1
On Thu, Sep 29, 2022, Jim Mattson wrote:
> KVM_GET_SUPPORTED_CPUID should only enumerate features that KVM
> actually supports. The following ranges of CPUID.8000001EH are reserved
> and should be masked off:
>     EBX[31:16]
>     ECX[31:11]

LOL, APM is buggy, it says all bits in ECX are reserved.

  31:0  -                Reserved.
  10:8 NodesPerProcessor
  7:0  NodeId

Advertising NodeId seems all kinds of wrong :-(

>     EDX[31:0]
> 
> Fixes: 382409b4c43e ("kvm: x86: Include CPUID leaf 0x8000001e in kvm's supported CPUID")
> Signed-off-by: Jim Mattson <jmattson@google.com>
> ---
>  arch/x86/kvm/cpuid.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 5d1ec390aa45..576cbcf489ce 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -1179,6 +1179,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
>  		entry->ebx = entry->ecx = entry->edx = 0;
>  		break;
>  	case 0x8000001e:
> +		entry->ebx &= ~GENMASK(31, 16);
> +		entry->ecx &= ~GENMASK(31, 11);
> +		entry->edx = 0;
>  		break;
>  	case 0x8000001F:
>  		if (!kvm_cpu_cap_has(X86_FEATURE_SEV)) {
> -- 
> 2.38.0.rc1.362.ged0d419d3c-goog
>
Paolo Bonzini Oct. 22, 2022, 8:26 a.m. UTC | #2
On 10/20/22 00:53, Sean Christopherson wrote:
> On Thu, Sep 29, 2022, Jim Mattson wrote:
>> KVM_GET_SUPPORTED_CPUID should only enumerate features that KVM
>> actually supports. The following ranges of CPUID.8000001EH are reserved
>> and should be masked off:
>>      EBX[31:16]
>>      ECX[31:11]
> LOL, APM is buggy, it says all bits in ECX are reserved.
> 
>    31:0  -                Reserved.
>    10:8 NodesPerProcessor
>    7:0  NodeId
> 
> Advertising NodeId seems all kinds of wrong 
diff mbox series

Patch

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 5d1ec390aa45..576cbcf489ce 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1179,6 +1179,9 @@  static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 		entry->ebx = entry->ecx = entry->edx = 0;
 		break;
 	case 0x8000001e:
+		entry->ebx &= ~GENMASK(31, 16);
+		entry->ecx &= ~GENMASK(31, 11);
+		entry->edx = 0;
 		break;
 	case 0x8000001F:
 		if (!kvm_cpu_cap_has(X86_FEATURE_SEV)) {