Skip to contentSkip to conversation

target/i386: kvm: Enable KVM_FEATURE_PCI_GO_MMCONFIG CPUID bit

RFC PATCH In review Julia Suvorova 2 participants 2 messages Jul 31, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 target/i386: kvm: Enable KVM_FEATURE_PCI_GO_MMCONFIG CPUID bit

This feature allows MMCONFIG to be used even to access the base PCI config space [1]. This means increased performance: one access to MMCONFIG instead of two conventional accesses to I/O ports.

Q35 makes no distinction in base or extended PCI config access to MMCONFIG, MMCONFIG is always on, and in case it is is not initialized, probing of PCI devices will fall back to normal process and use type1 access.

Enable the feature unconditionally.

[1]: https://lore.kernel.org/kvm/[email protected]/

---
The feature is in the review phase.

 include/standard-headers/asm-x86/kvm_para.h | 1 +
 target/i386/cpu.c                           | 3 ++-
 target/i386/kvm.c                           | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)
include/standard-headers/asm-x86/kvm_para.h +1 -0
index 07877d3295..52eeba9067 100644
@@ -32,6 +32,7 @@
 #define KVM_FEATURE_POLL_CONTROL	12
 #define KVM_FEATURE_PV_SCHED_YIELD	13
 #define KVM_FEATURE_ASYNC_PF_INT	14
+#define KVM_FEATURE_PCI_GO_MMCONFIG	15
 
 #define KVM_HINTS_REALTIME      0
 
target/i386/cpu.c +2 -1
index 588f32e136..5509523bb3 100644
@@ -810,7 +810,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
             "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
             "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
             NULL, "kvm-pv-tlb-flush", NULL, "kvm-pv-ipi",
-            "kvm-poll-control", "kvm-pv-sched-yield", NULL, NULL,
+            "kvm-poll-control", "kvm-pv-sched-yield", NULL, "kvm-pci-go-mmconfig",
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
             "kvmclock-stable-bit", NULL, NULL, NULL,
@@ -4141,6 +4141,7 @@ static PropValue kvm_default_props[] = {
     { "acpi", "off" },
     { "monitor", "off" },
     { "svm", "off" },
+    { "kvm-pci-go-mmconfig", "on" },
     { NULL, NULL },
 };
 
target/i386/kvm.c +1 -0
index 6f18d940a5..0069e945e6 100644
@@ -440,6 +440,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
         if (!kvm_irqchip_in_kernel()) {
             ret &= ~(1U << KVM_FEATURE_PV_UNHALT);
         }
+        ret |= 1U << KVM_FEATURE_PCI_GO_MMCONFIG;
     } else if (function == KVM_CPUID_FEATURES && reg == R_EDX) {
         ret |= 1U << KVM_HINTS_REALTIME;
         found = 1;
Signature · 1 line
2.25.4
#1 lore raw
Quoted 48 lines · Julia Suvorova

This feature allows MMCONFIG to be used even to access the base PCI config space [1]. This means increased performance: one access to MMCONFIG instead of two conventional accesses to I/O ports.

Q35 makes no distinction in base or extended PCI config access to MMCONFIG, MMCONFIG is always on, and in case it is is not initialized, probing of PCI devices will fall back to normal process and use type1 access.

Enable the feature unconditionally.

[1]: https://lore.kernel.org/kvm/[email protected]/

---
The feature is in the review phase.

 include/standard-headers/asm-x86/kvm_para.h | 1 +
 target/i386/cpu.c                           | 3 ++-
 target/i386/kvm.c                           | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)
include/standard-headers/asm-x86/kvm_para.h +1 -0
index 07877d3295..52eeba9067 100644
@@ -32,6 +32,7 @@
 #define KVM_FEATURE_POLL_CONTROL	12
 #define KVM_FEATURE_PV_SCHED_YIELD	13
 #define KVM_FEATURE_ASYNC_PF_INT	14
+#define KVM_FEATURE_PCI_GO_MMCONFIG	15
 
 #define KVM_HINTS_REALTIME      0
 
target/i386/cpu.c +1 -1
index 588f32e136..5509523bb3 100644
@@ -810,7 +810,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
             "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
             "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
             NULL, "kvm-pv-tlb-flush", NULL, "kvm-pv-ipi",
-            "kvm-poll-control", "kvm-pv-sched-yield", NULL, NULL,
+            "kvm-poll-control", "kvm-pv-sched-yield", NULL, "kvm-pci-go-mmconfig",
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
             "kvmclock-stable-bit", NULL, NULL, NULL,

target/i386/cpu.c static PropValue kvm_default_props[] = { · line 4144

Quoted 4 lines
target/i386/cpu.c +1 -0
@@ -4141,6 +4141,7 @@ static PropValue kvm_default_props[] = {
     { "acpi", "off" },
     { "monitor", "off" },
     { "svm", "off" },
+    { "kvm-pci-go-mmconfig", "on" },

You'll need a TYPE_X86_CPU.kvm-pci-go-mmconfig=off entry in pc_compat_5_1 to keep guest ABI compatibility on older machine types.

pc_compat_5_1 is introduced by
https://lore.kernel.org/qemu-devel/[email protected]/
("hw: add compat machines for 5.2").

target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 443

Quoted 12 lines
target/i386/cpu.c +0 -0
     { NULL, NULL },
 };
 
target/i386/kvm.c +1 -0
index 6f18d940a5..0069e945e6 100644
@@ -440,6 +440,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
         if (!kvm_irqchip_in_kernel()) {
             ret &= ~(1U << KVM_FEATURE_PV_UNHALT);
         }
+        ret |= 1U << KVM_FEATURE_PCI_GO_MMCONFIG;

On most cases, enabling a feature unconditionally on kvm_arch_get_supported_cpuid() would be a mistake, but this flag seems to be an exception to the rule.

A comment here explaining why it is really safe to enable it unconditionally would be welcome.

Quoted 6 lines
target/i386/kvm.c +0 -0
     } else if (function == KVM_CPUID_FEATURES && reg == R_EDX) {
         ret |= 1U << KVM_HINTS_REALTIME;
         found = 1;
Signature · 1 line
2.25.4
Signature · 1 line
Eduardo