Skip to contentSkip to conversation

Qemu/KVM: Remove x2apic feature from CPU model when kernel_irqchip is off

PATCH In review Lan Tianyu 3 participants 6 messages Feb 25, 2016 – Mar 1, 2016 KVM

lore
Share & tools
lore

Lan Tianyu

author
#0 lore raw

PATCH 1/1 Qemu/KVM: Remove x2apic feature from CPU model when kernel_irqchip is off

x2apic feature is in the kvm_default_props and automatically added to all CPU models when KVM is enabled. But userspace devices don't support x2apic which can't be enabled without the in-kernel irqchip. It will trigger warning of "host doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]" when kernel_irqchip is off. This patch is to fix it via removing x2apic feature when kernel_irqchip is off.

---
 target-i386/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target-i386/cpu.c +4 -0
index c78f824..298fb62 100644
@@ -2125,6 +2125,10 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
     /* Special cases not set in the X86CPUDefinition structs: */
     if (kvm_enabled()) {
+        if (!kvm_irqchip_in_kernel()) {
+            x86_cpu_change_kvm_default("x2apic", "off");
+        }
+
         x86_cpu_apply_props(cpu, kvm_default_props);
     }
 
Signature · 1 line
1.9.3
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Lan Tianyu

x2apic feature is in the kvm_default_props and automatically added to all CPU models when KVM is enabled. But userspace devices don't support x2apic which can't be enabled without the in-kernel irqchip. It will trigger warning of "host doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]" when kernel_irqchip is off. This patch is to fix it via removing x2apic feature when kernel_irqchip is off.

---
 target-i386/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target-i386/cpu.c +0 -0
index c78f824..298fb62 100644

target-i386/cpu.c static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) · line 2134

Quoted 10 lines
target-i386/cpu.c +4 -0
@@ -2125,6 +2125,10 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
     /* Special cases not set in the X86CPUDefinition structs: */
     if (kvm_enabled()) {
+        if (!kvm_irqchip_in_kernel()) {
+            x86_cpu_change_kvm_default("x2apic", "off");
+        }
+
         x86_cpu_apply_props(cpu, kvm_default_props);
     }
 
#2 lore raw
In reply to Lan Tianyu
Quoted 17 lines · Lan Tianyu

x2apic feature is in the kvm_default_props and automatically added to all CPU models when KVM is enabled. But userspace devices don't support x2apic which can't be enabled without the in-kernel irqchip. It will trigger warning of "host doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]" when kernel_irqchip is off. This patch is to fix it via removing x2apic feature when kernel_irqchip is off.

---
 target-i386/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target-i386/cpu.c +0 -0
index c78f824..298fb62 100644

target-i386/cpu.c static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) · line 2129

Quoted 5 lines
target-i386/cpu.c +2 -0
@@ -2125,6 +2125,10 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
     /* Special cases not set in the X86CPUDefinition structs: */
     if (kvm_enabled()) {
+        if (!kvm_irqchip_in_kernel()) {
+            x86_cpu_change_kvm_default("x2apic", "off");

This should be NULL instead of "off". Otherwise, the warning will be disabled if using "-cpu ...,+x2apic".

target-i386/cpu.c static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) · line 2131

Quoted 2 lines
target-i386/cpu.c +2 -0
+        }
+

This function runs multiple times (once for each VCPU being created). Should be harmless, though. Eventually we could move the whole kvm_default_props logic outside cpu.c, to a KVM-x86 accel class or to common PC initialization code.

Quoted 6 lines
target-i386/cpu.c +0 -0
         x86_cpu_apply_props(cpu, kvm_default_props);
     }
 
Signature · 1 line
1.9.3
Signature · 1 line
Eduardo
author
#3 lore raw
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Lan Tianyu

x2apic feature is in the kvm_default_props and automatically added to all CPU models when KVM is enabled. But userspace devices don't support x2apic which can't be enabled without the in-kernel irqchip. It will trigger warning of "host doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]" when kernel_irqchip is off. This patch is to fix it via removing x2apic feature when kernel_irqchip is off.

---
 target-i386/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target-i386/cpu.c +0 -0
index c78f824..298fb62 100644
@@ -2125,6 +2125,10 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
Quoted 6 lines

target-i386/cpu.c static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) · line 2129

Quoted 4 lines
target-i386/cpu.c +2 -0
     /* Special cases not set in the X86CPUDefinition structs: */
     if (kvm_enabled()) {
+        if (!kvm_irqchip_in_kernel()) {
+            x86_cpu_change_kvm_default("x2apic", "off");

This should be NULL instead of "off".

I tried "NULL" before. But some cpus modules(E,G SandyBridge, IvyBridge, haswell) already have x2apic feature in their default features of struct X86CPUDefinition, passing "NULL" is not to add x2apic feature to the cpu module and will not help to remove x2apic feature for these cpu modules. So I changed "NULL" to "off".

Quoted 3 lines

Otherwise, the warning will
be disabled if using "-cpu ...,+x2apic".

kvm_arch_get_supported_cpuid() always returns no x2apic support when kernel_irqchip is off and so it still triggers warning with "-cpu ...,+x2apic".

#qemu-system-x86_64 -cpu qemu64,+x2apic -machine kernel-irqchip=off
warning: TCG doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]

Quoted 7 lines

target-i386/cpu.c static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) · line 2131

Quoted 2 lines
target-i386/cpu.c +2 -0
+        }
+

This function runs multiple times (once for each VCPU being created). Should be harmless, though. Eventually we could move the whole kvm_default_props logic outside cpu.c, to a KVM-x86 accel class or to common PC initialization code.

Good suggestion and we can try that later.

Quoted 9 lines
Quoted 8 lines
target-i386/cpu.c +0 -0
         x86_cpu_apply_props(cpu, kvm_default_props);
     }
 
Signature · 1 line
1.9.3
Signature · 2 lines
Best regards
Tianyu Lan
Reviewed-by
#4 lore raw
Quoted 27 lines · Lan Tianyu
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Lan Tianyu

x2apic feature is in the kvm_default_props and automatically added to all CPU models when KVM is enabled. But userspace devices don't support x2apic which can't be enabled without the in-kernel irqchip. It will trigger warning of "host doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]" when kernel_irqchip is off. This patch is to fix it via removing x2apic feature when kernel_irqchip is off.

---
 target-i386/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target-i386/cpu.c +0 -0
index c78f824..298fb62 100644
@@ -2125,6 +2125,10 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
Quoted 6 lines

target-i386/cpu.c static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) · line 2129

Quoted 4 lines
target-i386/cpu.c +2 -0
     /* Special cases not set in the X86CPUDefinition structs: */
     if (kvm_enabled()) {
+        if (!kvm_irqchip_in_kernel()) {
+            x86_cpu_change_kvm_default("x2apic", "off");

This should be NULL instead of "off".

Quoted 5 lines

I tried "NULL" before. But some cpus modules(E,G SandyBridge, IvyBridge, haswell) already have x2apic feature in their default features of struct X86CPUDefinition, passing "NULL" is not to add x2apic feature to the cpu module and will not help to remove x2apic feature for these cpu modules. So I changed "NULL" to "off".

In this case, I suggest we remove x2apic from these CPU models to avoid confusion, as the presence of the flag in the table makes no difference at all (this can be done in a separate patch).

If we do that, NULL and "off" would have the same results, but NULL is clearer, IMO. NULL simply disables the KVM-specific hack (so we don't touch the property anymore), but "off" adds a new TCG-specific hack. I will submit that as a follow-up patch.

Quoted 5 lines
Quoted 4 lines

Otherwise, the warning will
be disabled if using "-cpu ...,+x2apic".

Quoted 7 lines

kvm_arch_get_supported_cpuid() always returns no x2apic support when kernel_irqchip is off and so it still triggers warning with "-cpu ...,+x2apic".

#qemu-system-x86_64 -cpu qemu64,+x2apic -machine kernel-irqchip=off
warning: TCG doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]

You are right. The +x2apic flag is applied after
x86_cpu_load_def() runs. My mistake.

Signature · 1 line
Eduardo
#5 lore raw
Quoted 34 lines · Eduardo Habkost
Quoted 27 lines · Lan Tianyu
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Lan Tianyu

x2apic feature is in the kvm_default_props and automatically added to all CPU models when KVM is enabled. But userspace devices don't support x2apic which can't be enabled without the in-kernel irqchip. It will trigger warning of "host doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]" when kernel_irqchip is off. This patch is to fix it via removing x2apic feature when kernel_irqchip is off.

---
  target-i386/cpu.c | 4 ++++
  1 file changed, 4 insertions(+)
target-i386/cpu.c +0 -0
index c78f824..298fb62 100644
@@ -2125,6 +2125,10 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
Quoted 6 lines

target-i386/cpu.c static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) · line 2129

Quoted 4 lines
target-i386/cpu.c +2 -0
      /* Special cases not set in the X86CPUDefinition structs: */
      if (kvm_enabled()) {
+        if (!kvm_irqchip_in_kernel()) {
+            x86_cpu_change_kvm_default("x2apic", "off");

This should be NULL instead of "off".

Quoted 5 lines

I tried "NULL" before. But some cpus modules(E,G SandyBridge, IvyBridge, haswell) already have x2apic feature in their default features of struct X86CPUDefinition, passing "NULL" is not to add x2apic feature to the cpu module and will not help to remove x2apic feature for these cpu modules. So I changed "NULL" to "off".

Quoted 8 lines

In this case, I suggest we remove x2apic from these CPU models to avoid confusion, as the presence of the flag in the table makes no difference at all (this can be done in a separate patch).

If we do that, NULL and "off" would have the same results, but NULL is clearer, IMO. NULL simply disables the KVM-specific hack (so we don't touch the property anymore), but "off" adds a new TCG-specific hack. I will submit that as a follow-up patch.

Yes, that sounds reasonable. Thanks for your review.

Quoted 19 lines
Quoted 5 lines
Quoted 4 lines

Otherwise, the warning will
be disabled if using "-cpu ...,+x2apic".

Quoted 7 lines

kvm_arch_get_supported_cpuid() always returns no x2apic support when kernel_irqchip is off and so it still triggers warning with "-cpu ...,+x2apic".

#qemu-system-x86_64 -cpu qemu64,+x2apic -machine kernel-irqchip=off
warning: TCG doesn't support requested feature: CPUID.01H:ECX.x2apic [bit 21]

You are right. The +x2apic flag is applied after
x86_cpu_load_def() runs. My mistake.