Skip to contentSkip to conversation

qemu-kvm fixes (+userspace support for gbpages)

RFC PATCH New Joerg Roedel 1 participant 4 messages Jun 17, 2009 KVM

lore
Share & tools
lore
#0 lore raw

cover qemu-kvm fixes (+userspace support for gbpages)

Hi,

this patchset contains two "fixes" to qemu-kvm userspace and the patch to make gbpages working with qemu-kvm. I am not really sure if this is the right way to do it or if I missed something. Therefore this patchset is RFC.

Thanks,

Joerg

#1 lore raw

PATCH 1/3 qemu-kvm: fix cpuid bitmask in kvm_setup_cpuid()

Fix the bitmask in kvm_setup_cpuid() to a value which represents only the common bits between cpuid function 0x00000001 and 0x80000001.

---
 target-i386/libkvm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-i386/libkvm.c +1 -1
index 0f4e009..6391caf 100644
@@ -644,7 +644,7 @@ uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg)
 				 */
 				if (function == 0x80000001) {
 					cpuid_1_edx = kvm_get_supported_cpuid(kvm, 1, R_EDX);
-					ret |= cpuid_1_edx & 0xdfeff7ff;
+					ret |= cpuid_1_edx & 0x0183f3ff;
 				}
 				break;
 			}
Signature · 1 line
1.6.3.1
#2 lore raw

PATCH 2/3 qemu-kvm: align cpu-features with kvm_supported_cpuid

In reply to Joerg Roedel

The cpuid features exposed to the guest are currently not aligned with the bits returned by the supported_cpuid ioctl. This patch fixes it.

---
 qemu-kvm-x86.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)
qemu-kvm-x86.c +17 -11
index 729d600..95774c1 100644
@@ -578,6 +578,13 @@ int kvm_arch_qemu_init_env(CPUState *cenv)
                 if (i == 0xd && copy.regs[R_EAX] == 0)
                     break;
             }
+        } else if (i == 1) {
+            do_cpuid_ent(&cpuid_ent[cpuid_nent], i, 0, &copy);
+            kvm_trim_features(&cpuid_ent[cpuid_nent].edx,
+                              kvm_arch_get_supported_cpuid(cenv, 1, R_EDX));
+            kvm_trim_features(&cpuid_ent[cpuid_nent].ecx,
+                              kvm_arch_get_supported_cpuid(cenv, 1, R_ECX));
+            cpuid_nent++;
         } else
             do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, &copy);
     }
@@ -586,20 +593,19 @@ int kvm_arch_qemu_init_env(CPUState *cenv)
     qemu_kvm_cpuid_on_env(&copy);
     limit = copy.regs[R_EAX];
 
-    for (i = 0x80000000; i <= limit; ++i)
-	do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, &copy);
+    for (i = 0x80000000; i <= limit; ++i) {
+	do_cpuid_ent(&cpuid_ent[cpuid_nent], i, 0, &copy);
+        if (i == 0x80000001) {
+            kvm_trim_features(&cpuid_ent[cpuid_nent].edx,
+                              kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX));
+            kvm_trim_features(&cpuid_ent[cpuid_nent].ecx,
+                              kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX));
+        }
+        ++cpuid_nent;
+    }
 
     kvm_setup_cpuid2(cenv->kvm_cpu_state.vcpu_ctx, cpuid_nent, cpuid_ent);
 
-    kvm_trim_features(&cenv->cpuid_features,
-                      kvm_arch_get_supported_cpuid(cenv, 1, R_EDX));
-    kvm_trim_features(&cenv->cpuid_ext_features,
-                      kvm_arch_get_supported_cpuid(cenv, 1, R_ECX));
-    kvm_trim_features(&cenv->cpuid_ext2_features,
-                      kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX));
-    kvm_trim_features(&cenv->cpuid_ext3_features,
-                      kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX));
-
     return 0;
 }
 
Signature · 1 line
1.6.3.1
#3 lore raw

PATCH 3/3 qemu-kvm: add support for gbpages to kvm userspace

In reply to Joerg Roedel

This patch adds a command line parameter to expose the gbpages cpuid bit to the guest if the kvm kernel module supports it.

---
 qemu-kvm.c           |    1 +
 qemu-kvm.h           |    1 +
 qemu-options.hx      |    2 ++
 target-i386/helper.c |    3 +++
 vl.c                 |    4 ++++
 5 files changed, 11 insertions(+), 0 deletions(-)
qemu-kvm.c +1 -0
index 2aeb17c..01a889d 100644
@@ -33,6 +33,7 @@ int kvm_irqchip = 1;
 int kvm_pit = 1;
 int kvm_pit_reinject = 1;
 int kvm_nested = 0;
+int kvm_gbpages = 0;
 kvm_context_t kvm_context;
 
 pthread_mutex_t qemu_mutex = PTHREAD_MUTEX_INITIALIZER;
qemu-kvm.h +1 -0
index fa40542..fc06b96 100644
@@ -151,6 +151,7 @@ extern int kvm_irqchip;
 extern int kvm_pit;
 extern int kvm_pit_reinject;
 extern int kvm_nested;
+extern int kvm_gbpages;
 extern kvm_context_t kvm_context;
 
 struct ioperm_data {
qemu-options.hx +2 -0
index edd99db..fe9e9d3 100644
@@ -1594,6 +1594,8 @@ DEF("pcidevice", HAS_ARG, QEMU_OPTION_pcidevice,
 #endif
 DEF("enable-nesting", 0, QEMU_OPTION_enable_nesting,
     "-enable-nesting enable support for running a VM inside the VM (AMD only)\n")
+DEF("enable-gbpages", 0, QEMU_OPTION_enable_gbpages,
+    "-enable-gbpages enable support for 1GB pages in the guest (if supported)\n")
 DEF("nvram", HAS_ARG, QEMU_OPTION_nvram,
     "-nvram FILE          provide ia64 nvram contents\n")
 DEF("tdf", 0, QEMU_OPTION_tdf,
target-i386/helper.c +3 -0
index 6dc0111..9fb2ae4 100644
@@ -1607,6 +1607,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
                 *ecx &= ~4UL;
             /* 3dnow */
             *edx &= ~0xc0000000;
+	    /* enable gbpages and let kvm disable it if unsupported */
+	    if (kvm_gbpages)
+		    *edx |= (1UL << 26UL);
         }
         break;
     case 0x80000002:
vl.c +4 -0
index 845ed54..262ff1b 100644
@@ -5621,6 +5621,10 @@ int main(int argc, char **argv, char **envp)
 		kvm_nested = 1;
 		break;
 	    }
+	    case QEMU_OPTION_enable_gbpages: {
+		kvm_gbpages = 1;
+		break;
+	    }
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
             case QEMU_OPTION_pcidevice:
 		if (assigned_devices_index >= MAX_DEV_ASSIGN_CMDLINE) {
Signature · 1 line
1.6.3.1