Skip to contentSkip to conversation

i386: Minor fixes for building CPUIDs

PATCH New Xiaoyao Li 1 participant 4 messages Jan 25, 2024 KVM

lore
Share & tools
lore

Xiaoyao Li

author
#0 lore raw

v3 cover i386: Minor fixes for building CPUIDs

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.

Patch 3 fix the build of CPUID leaf 7.

Changes in v3:
- collect Reviewed-by tags;
- rebase to latest master branch
4a4efae44f19 ("Merge tag 'pull-hex-20240121' of https://github.com/quic/qemu into staging")

v2:
https://lore.kernel.org/qemu-devel/[email protected]/
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(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/3 i386/cpuid: Decrease cpuid_i when skipping CPUID leaf 1F

Existing code misses a decrement of cpuid_i when skip leaf 0x1F. There's a blank CPUID entry(with leaf, subleaf as 0, and all fields stuffed 0s) left in the CPUID array.

It conflicts with correct CPUID leaf 0.

---
 target/i386/kvm/kvm.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/kvm/kvm.c +1 -0
index 76a66246eb72..dff9dedbd761 100644
@@ -1914,6 +1914,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
author
#2 lore raw

PATCH v3 2/3 i386/cpuid: Remove subleaf constraint on CPUID leaf 1F

In reply to Xiaoyao Li

No 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
index dff9dedbd761..9758c83693ec 100644
@@ -1926,10 +1926,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
author
#3 lore raw

PATCH v3 3/3 i386/cpuid: Move leaf 7 to correct group

In reply to Xiaoyao Li

CPUID 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.

Fixes b9edbadefb9e ("i386: Propagate SGX CPUID sub-leafs to KVM")
---
 target/i386/kvm/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/kvm/kvm.c +1 -1
index 9758c83693ec..42970ab046fa 100644
@@ -1951,7 +1951,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;
@@ -1971,6 +1970,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