i386: Minor fixes of building CPUIDs
v2 cover i386: Minor fixes of building CPUIDs
This v2 adds patch 3 to fix the build of CPUID leaf 7.
The issue that fixed by Patch 1 looks fatal though it doesn't appear on KVM because KVM always searches with assending order and hit with the correct cpuid leaf 0.
Patch 2 removes the wrong constraint on CPUID leaf 1f.
Changes in v2:
- Add Patch 3;
- rebase to latest master branch
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Xiaoyao Li (3):
i386/cpuid: Decrease cpuid_i when skipping CPUID leaf 1F i386/cpuid: Remove subleaf constraint on CPUID leaf 1F i386/cpuid: Move leaf 7 to correct group
target/i386/kvm/kvm.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
base-commit: fdd0df5340a8ebc8de88078387ebc85c5af7b40f
Signature · 1 line
2.34.1
PATCH v2 1/3 i386/cpuid: Decrease cpuid_i when skipping CPUID leaf 1F
Decrease array index cpuid_i when CPUID leaf 1F is skipped, otherwise it will get an all zero'ed CPUID entry with leaf 0 and subleaf 0. It conflicts with correct leaf 0.
--- target/i386/kvm/kvm.c | 1 + 1 file changed, 1 insertion(+)
target/i386/kvm/kvm.c +1 -0
@@ -1956,6 +1956,7 @@ int kvm_arch_init_vcpu(CPUState *cs) }case 0x1f :if (env->nr_dies <2 ) { + cpuid_i--;break ; }/* fallthrough */
Signature · 1 line
2.34.1
Re: [PATCH v2 1/3] i386/cpuid: Decrease cpuid_i when skipping CPUID leaf 1F
Quoted 3 lines · Xiaoyao Li
Decrease array index
cpuid_iwhen CPUID leaf 1F is skipped, otherwise it will get an all zero'ed CPUID entry with leaf 0 and subleaf 0. It conflicts with correct leaf 0.
Maybe change the commit log like this:
Exiting code misses a decrement of cpuid_i when skip left 0x1F, so there's a blank CPUID
entry(with all fields stuffed 0s) left in the CPUID array. Fix the issue to avoid the blank slot.
Quoted 18 lines
Signed-off-by Xiaoyao Li <[email protected]>--- target/i386/kvm/kvm.c | 1 + 1 file changed, 1 insertion(+)target/i386/kvm/kvm.c +1
-0@@ -1956,6 +1956,7 @@ int kvm_arch_init_vcpu(CPUState *cs) }case 0x1f :if (env->nr_dies <2 ) { + cpuid_i--;break ; }/* fallthrough */
PATCH v2 2/3 i386/cpuid: Remove subleaf constraint on CPUID leaf 1F
In reply to Xiaoyao LiNo such constraint that subleaf index needs to be less than 64.
--- target/i386/kvm/kvm.c | 4 ---- 1 file changed, 4 deletions(-)
target/i386/kvm/kvm.c +0 -4
@@ -1968,10 +1968,6 @@ int kvm_arch_init_vcpu(CPUState *cs)break ; } -if (i ==0x1f && j ==64 ) { -break ; - } - c->function = i; c->flags =KVM_CPUID_FLAG_SIGNIFCANT_INDEX ; c->index = j;
Signature · 1 line
2.34.1
Re: [PATCH v2 2/3] i386/cpuid: Remove subleaf constraint on CPUID leaf 1F
Quoted 12 lines · Xiaoyao Li
No such constraint that subleaf index needs to be less than 64.
Signed-off-by Xiaoyao Li <[email protected]>--- target/i386/kvm/kvm.c | 4 ---- 1 file changed, 4 deletions(-)target/i386/kvm/kvm.c +0
-0
target/i386/kvm/kvm.c int kvm_arch_init_vcpu(CPUState *cs) · line 1973
Quoted 10 lines
target/i386/kvm/kvm.c +0
-4@@ -1968,10 +1968,6 @@ int kvm_arch_init_vcpu(CPUState *cs)break ; } -if (i ==0x1f && j ==64 ) { -break ; - } - c->function = i; c->flags =KVM_CPUID_FLAG_SIGNIFCANT_INDEX ; c->index = j;
PATCH v2 3/3 i386/cpuid: Move leaf 7 to correct group
In reply to Xiaoyao LiCPUID leaf 7 was grouped together with SGX leaf 0x12 by commit b9edbadefb9e ("i386: Propagate SGX CPUID sub-leafs to KVM") by mistake.
SGX leaf 0x12 has its specific logic to check if subleaf (starting from 2) is valid or not by checking the bit 0:3 of corresponding EAX is 1 or not.
Leaf 7 follows the logic that EAX of subleaf 0 enumerates the maximum valid subleaf.
--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/kvm/kvm.c +1 -1
@@ -1993,7 +1993,6 @@ int kvm_arch_init_vcpu(CPUState *cs) c = &cpuid_data.entries[cpuid_i++]; }break ; -case 0x7 :case 0x12 :for (j =0 ; ; j++) { c->function = i;
@@ -2013,6 +2012,7 @@ int kvm_arch_init_vcpu(CPUState *cs) c = &cpuid_data.entries[cpuid_i++]; }break ; +case 0x7 :case 0x14 :case 0x1d :case 0x1e : {
Signature · 1 line
2.34.1
Re: [PATCH v2 3/3] i386/cpuid: Move leaf 7 to correct group
Quoted 29 lines · Xiaoyao Li
CPUID leaf 7 was grouped together with SGX leaf
0x12by commitb9edbadefb9e("i386: Propagate SGX CPUID sub-leafs to KVM") by mistake.SGX leaf
0x12has its specific logic to check if subleaf (starting from 2) is valid or not by checking the bit 0:3 of corresponding EAX is 1 or not.Leaf 7 follows the logic that EAX of subleaf 0 enumerates the maximum valid subleaf.
Fixes b9edbadefb9e ("i386: Propagate SGX CPUID sub-leafs to KVM")Signed-off-by Xiaoyao Li <[email protected]>--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/kvm/kvm.c +0
-1@@ -1993,7 +1993,6 @@ int kvm_arch_init_vcpu(CPUState *cs) c = &cpuid_data.entries[cpuid_i++]; }break ; -case 0x7 :case 0x12 :for (j =0 ; ; j++) { c->function = i;
target/i386/kvm/kvm.c int kvm_arch_init_vcpu(CPUState *cs) · line 2018
Quoted 7 lines
target/i386/kvm/kvm.c +1
-0@@ -2013,6 +2012,7 @@ int kvm_arch_init_vcpu(CPUState *cs) c = &cpuid_data.entries[cpuid_i++]; }break ; +case 0x7 :case 0x14 :case 0x1d :case 0x1e : {