Skip to contentSkip to conversation

i386: extended the cpuid level when Intel PT is enabled

PATCH Superseded Luwei Kang 2 participants 7 messages Jan 24, 2019 – Jan 29, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Luwei Kang

author
#0 lore raw

PATCH 1/1 i386: extended the cpuid level when Intel PT is enabled

Intel Processor Trace required CPUID[0x14] but the cpuid level is 0xd when create a kvm guest with e.g. "-cpu qemu64,+intel-pt".

---
 target/i386/cpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
target/i386/cpu.c +7 -0
index 2f54125..da477b3 100644
@@ -5023,6 +5023,13 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);
         x86_cpu_adjust_feat_level(cpu, FEAT_SVM);
         x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);
+
+        /* Intel Processor Trace requires CPUID[0x14] */
+        if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
+             kvm_enabled()) {
+            x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
+        }
+
         /* SVM requires CPUID[0x8000000A] */
         if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
             x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000000A);
Signature · 1 line
1.8.3.1
#1 lore raw

Hi,

Thanks for the patch. Comment below:

Quoted 13 lines · Luwei Kang

Intel Processor Trace required CPUID[0x14] but the cpuid level is 0xd when create a kvm guest with e.g. "-cpu qemu64,+intel-pt".

---
 target/i386/cpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
target/i386/cpu.c +0 -0
index 2f54125..da477b3 100644

target/i386/cpu.c static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) · line 5031

Quoted 9 lines
target/i386/cpu.c +6 -0
@@ -5023,6 +5023,13 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);
         x86_cpu_adjust_feat_level(cpu, FEAT_SVM);
         x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);
+
+        /* Intel Processor Trace requires CPUID[0x14] */
+        if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
+             kvm_enabled()) {
+            x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
+        }

This will require a new machine-type compatibility flag to enable the new behavior, so we don't change CPUID data under the guest feet during live migration.

Quoted 7 lines
target/i386/cpu.c +1 -0
+
         /* SVM requires CPUID[0x8000000A] */
         if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
             x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000000A);
Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
#2 lore raw
Quoted 8 lines
Quoted 8 lines

Intel Processor Trace required CPUID[0x14] but the cpuid level is 0xd when create a kvm guest with e.g. "-cpu qemu64,+intel-pt".

---
 target/i386/cpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 16 lines
Quoted 5 lines
target/i386/cpu.c index renamed from target/i386/cpu.c +0 -0

2f54125..da477b3 100644

target/i386/cpu.c static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) · line 5031

Quoted 9 lines
target/i386/cpu.c +6 -0
@@ -5023,6 +5023,13 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);
         x86_cpu_adjust_feat_level(cpu, FEAT_SVM);
         x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);
+
+        /* Intel Processor Trace requires CPUID[0x14] */
+        if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
+             kvm_enabled()) {
+            x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
+        }

This will require a new machine-type compatibility flag to enable the new behavior, so we don't change CPUID data under the guest feet during live migration.

Hi Eduardo,
Thanks for your reply. I have some question on your comments.
The cpuid level come from specific machine-type (e.g. qemu64, Skylake-Server) and they are all 0xd, but Intel PT required 0x14 so I extend the cpuid level.
I don't fully understand what is the "require a new machine-type compatibility flag" mean, I need to add a new flag in each machine-type?
I try to do live migration with "-cpu qemu64,+intel-pt" and "-cpu host" are all passed test. We didn't change the cpuid data during live migration just initialize the cpuid data when create a new vcpu. Please correct me if anything wrong.

Thanks,
Luwei Kang

Quoted 12 lines
Quoted 9 lines
target/i386/cpu.c +1 -0
+
         /* SVM requires CPUID[0x8000000A] */
         if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
             x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel,

0x8000000A);
--
1.8.3.1

--
Eduardo

#3 lore raw
Quoted 25 lines · Luwei
Quoted 8 lines
Quoted 8 lines

Intel Processor Trace required CPUID[0x14] but the cpuid level is 0xd when create a kvm guest with e.g. "-cpu qemu64,+intel-pt".

---
 target/i386/cpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 16 lines
Quoted 5 lines
target/i386/cpu.c index renamed from target/i386/cpu.c +0 -0

2f54125..da477b3 100644

target/i386/cpu.c static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) · line 5031

Quoted 9 lines
target/i386/cpu.c +6 -0
@@ -5023,6 +5023,13 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);
         x86_cpu_adjust_feat_level(cpu, FEAT_SVM);
         x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);
+
+        /* Intel Processor Trace requires CPUID[0x14] */
+        if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
+             kvm_enabled()) {
+            x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
+        }

This will require a new machine-type compatibility flag to enable the new behavior, so we don't change CPUID data under the guest feet during live migration.

Quoted 5 lines

Hi Eduardo,
Thanks for your reply. I have some question on your comments.
The cpuid level come from specific machine-type (e.g. qemu64, Skylake-Server) and they are all 0xd, but Intel PT required 0x14 so I extend the cpuid level.
I don't fully understand what is the "require a new machine-type compatibility flag" mean, I need to add a new flag in each machine-type?
I try to do live migration with "-cpu qemu64,+intel-pt" and "-cpu host" are all passed test. We didn't change the cpuid data during live migration just initialize the cpuid data when create a new vcpu. Please correct me if anything wrong.

CPUID data is not sent as part of the migration stream (it is recreated on the migration destination), so if "-cpu qemu,+intel-pt" results in different CPUID data, migration between QEMU 4.0 and 3.1 will make CPUID level change during live migration.

This is not a serious issue, but it might confuse software running on the guest.

We can fix that doing this:

target/i386/cpu.c:

static Property x86_cpu_properties[] = {
    ...
    DEFINE_PROP_BOOL("x-intel-pt-auto-level", X86CPU, intel_pt_auto_level, true),
    ....
}
...
static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
{
    ...
        /* Intel Processor Trace requires CPUID[0x14] */
        if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) && cpu->intel_pt_auto_level) {
            x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
        }
    ...
}

hw/i386/pc.c:

GlobalProperty pc_compat_3_1[] = {
    ...
    { TYPE_X86_CPU, "x-intel-pt-auto-leevl", "off" },
};
Quoted 15 lines

Thanks,
Luwei Kang

Quoted 12 lines
Quoted 9 lines
target/i386/cpu.c +1 -0
+
         /* SVM requires CPUID[0x8000000A] */
         if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
             x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel,

0x8000000A);
--
1.8.3.1

--
Eduardo

Signature · 1 line
Eduardo
#4 lore raw
Quoted 30 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Intel Processor Trace required CPUID[0x14] but the cpuid level is 0xd when create a kvm guest with e.g. "-cpu qemu64,+intel-pt".

---
 target/i386/cpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
target/i386/cpu.c index renamed from target/i386/cpu.c +0 -0

2f54125..da477b3 100644

target/i386/cpu.c +0 -0
@@ -5023,6 +5023,13 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);
         x86_cpu_adjust_feat_level(cpu, FEAT_SVM);
         x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);
Quoted 8 lines

target/i386/cpu.c static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) · line 5031

Quoted 6 lines
target/i386/cpu.c +6 -0
+
+        /* Intel Processor Trace requires CPUID[0x14] */
+        if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
+             kvm_enabled()) {
+            x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
+        }

This will require a new machine-type compatibility flag to enable the new behavior, so we don't change CPUID data under the guest feet

during live migration.

Quoted 4 lines

Hi Eduardo,
Thanks for your reply. I have some question on your comments.
The cpuid level come from specific machine-type (e.g. qemu64, Skylake-Server) and they are all 0xd, but Intel PT required 0x14 so I

extend the cpuid level.

Quoted 8 lines
Quoted 1 line

I don't fully understand what is the "require a new machine-type compatibility flag" mean, I need to add a new flag in each machine-

type?

Quoted 1 line

I try to do live migration with "-cpu qemu64,+intel-pt" and "-cpu host" are all passed test. We didn't change the cpuid data during live

migration just initialize the cpuid data when create a new vcpu. Please correct me if anything wrong.

CPUID data is not sent as part of the migration stream (it is recreated on the migration destination), so if "-cpu qemu,+intel-pt" results in different CPUID data, migration between QEMU 4.0 and
3.1 will make CPUID level change during live migration.

Yes, CPUID data is not sent as part of migration stream. But when will the "-cpu qemu,+intel-pt" result different results? I think CPU type include some specific features and CPUID data of Intel PT are constant value, so I think the CPUID data should not change as well.

Thanks,
Luwei Kang

#5 lore raw
Quoted 39 lines · Luwei
Quoted 30 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Intel Processor Trace required CPUID[0x14] but the cpuid level is 0xd when create a kvm guest with e.g. "-cpu qemu64,+intel-pt".

---
 target/i386/cpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
target/i386/cpu.c index renamed from target/i386/cpu.c +0 -0

2f54125..da477b3 100644

target/i386/cpu.c +0 -0
@@ -5023,6 +5023,13 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);
         x86_cpu_adjust_feat_level(cpu, FEAT_SVM);
         x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);
Quoted 8 lines

target/i386/cpu.c static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) · line 5031

Quoted 6 lines
target/i386/cpu.c +6 -0
+
+        /* Intel Processor Trace requires CPUID[0x14] */
+        if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
+             kvm_enabled()) {
+            x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
+        }

This will require a new machine-type compatibility flag to enable the new behavior, so we don't change CPUID data under the guest feet

during live migration.

Quoted 4 lines

Hi Eduardo,
Thanks for your reply. I have some question on your comments.
The cpuid level come from specific machine-type (e.g. qemu64, Skylake-Server) and they are all 0xd, but Intel PT required 0x14 so I

extend the cpuid level.

Quoted 8 lines
Quoted 1 line

I don't fully understand what is the "require a new machine-type compatibility flag" mean, I need to add a new flag in each machine-

type?

Quoted 1 line

I try to do live migration with "-cpu qemu64,+intel-pt" and "-cpu host" are all passed test. We didn't change the cpuid data during live

migration just initialize the cpuid data when create a new vcpu. Please correct me if anything wrong.

CPUID data is not sent as part of the migration stream (it is recreated on the migration destination), so if "-cpu qemu,+intel-pt" results in different CPUID data, migration between QEMU 4.0 and
3.1 will make CPUID level change during live migration.

Quoted 5 lines

Yes, CPUID data is not sent as part of migration stream. But when will the "-cpu qemu,+intel-pt" result different results? I think CPU type include some specific features and CPUID data of Intel PT are constant value, so I think the CPUID data should not change as well.

Before your patch, "-cpu qemu64,+intel-pt" has CPUID[0].EAX = 0xD, and guest won't see intel-pt data in CPUID[0x14].

After your patch, "-cpu qemu64,+intel-pt" has CPUID[0].EAX = 0x14, and guest will see intel-pt data in CPUID[0x14].

Signature · 1 line
Eduardo
#6 lore raw
Quoted 47 lines
Quoted 47 lines
Quoted 46 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines

Intel Processor Trace required CPUID[0x14] but the cpuid level is 0xd when create a kvm guest with e.g. "-cpu qemu64,+intel-pt".

---
 target/i386/cpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
target/i386/cpu.c index renamed from target/i386/cpu.c +0 -0

2f54125..da477b3 100644

target/i386/cpu.c +2 -0
@@ -5023,6 +5023,13 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);
         x86_cpu_adjust_feat_level(cpu, FEAT_SVM);
         x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);
+
+        /* Intel Processor Trace requires CPUID[0x14] */
Quoted 8 lines
Quoted 8 lines

target/i386/cpu.c static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) · line 5031

Quoted 4 lines
target/i386/cpu.c +4 -0
+        if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
+             kvm_enabled()) {
+            x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
+        }

This will require a new machine-type compatibility flag to enable the new behavior, so we don't change CPUID data under the guest feet

during live migration.

Quoted 6 lines

Hi Eduardo,
Thanks for your reply. I have some question on your comments. The cpuid level come from specific machine-type (e.g. qemu64,
Skylake-Server) and they are all 0xd, but Intel PT required 0x14 so I

extend the cpuid level.

Quoted 3 lines

I don't fully understand what is the "require a new
machine-type compatibility flag" mean, I need to add a new flag in each machine-

type?

Quoted 3 lines

I try to do live migration with "-cpu qemu64,+intel-pt" and
"-cpu host" are all passed test. We didn't change the cpuid data during live

migration just initialize the cpuid data when create a new vcpu. Please correct me if anything wrong.

CPUID data is not sent as part of the migration stream (it is recreated on the migration destination), so if "-cpu qemu,+intel-pt" results in different CPUID data, migration between QEMU 4.0 and
3.1 will make CPUID level change during live migration.

Quoted 9 lines
Quoted 4 lines

Yes, CPUID data is not sent as part of migration stream. But when will the "-cpu qemu,+intel-pt" result different results? I think CPU type include some specific features and CPUID data of Intel PT are constant value, so I think the CPUID data should not change as well.

Before your patch, "-cpu qemu64,+intel-pt" has CPUID[0].EAX = 0xD, and guest won't see intel-pt data in CPUID[0x14].

After your patch, "-cpu qemu64,+intel-pt" has CPUID[0].EAX = 0x14, and guest will see intel-pt data in CPUID[0x14].

Oh yes, get it. Thanks.

Luwei Kang

Quoted 2 lines

--
Eduardo