Skip to contentSkip to conversation

SVM feature support for qemu

PATCH In review Joerg Roedel 3 participants 16 messages Sep 14, 2010 – Sep 16, 2010 KVM

lore
Share & tools
lore
#0 lore raw

cover SVM feature support for qemu

Hi,

here is the next round of the svm feature support patches for qemu. Key change in this version is that it now makes kvm{64|32} the default cpu definition for qemu when kvm is enabled (as requested by Alex). Otherwise I removed the NRIP_SAVE feature from the phenom definition and set svm_features per default to -1 for -cpu host to support all svm features that kvm can emulate. I appreciate your comments.

Joerg

#1 lore raw

PATCH 1/3 Make kvm64 the default cpu model when kvm_enabled()

As requested by Alex this patch makes kvm64 the default CPU model when qemu is started with -enable-kvm.

---
 hw/pc.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
hw/pc.c +14 -5
index 69b13bf..f531d0d 100644
@@ -40,6 +40,16 @@
 #include "sysbus.h"
 #include "sysemu.h"
 #include "blockdev.h"
+#include "kvm.h"
+
+
+#ifdef TARGET_X86_64
+#define DEFAULT_KVM_CPU_MODEL "kvm64"
+#define DEFAULT_QEMU_CPU_MODEL "qemu64"
+#else
+#define DEFAULT_KVM_CPU_MODEL "kvm32"
+#define DEFAULT_QEMU_CPU_MODEL "qemu32"
+#endif
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -867,11 +877,10 @@ void pc_cpus_init(const char *cpu_model)
 
     /* init CPUs */
     if (cpu_model == NULL) {
-#ifdef TARGET_X86_64
-        cpu_model = "qemu64";
-#else
-        cpu_model = "qemu32";
-#endif
+        if (kvm_enabled())
+            cpu_model = DEFAULT_KVM_CPU_MODEL;
+        else
+            cpu_model = DEFAULT_QEMU_CPU_MODEL;
     }
 
     for(i = 0; i < smp_cpus; i++) {
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 1/3] Make kvm64 the default cpu model when kvm_enabled()

Quoted 33 lines · Joerg Roedel

As requested by Alex this patch makes kvm64 the default CPU model when qemu is started with -enable-kvm.

---
 hw/pc.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
hw/pc.c +10 -0
index 69b13bf..f531d0d 100644
@@ -40,6 +40,16 @@
 #include "sysbus.h"
 #include "sysemu.h"
 #include "blockdev.h"
+#include "kvm.h"
+
+
+#ifdef TARGET_X86_64
+#define DEFAULT_KVM_CPU_MODEL "kvm64"
+#define DEFAULT_QEMU_CPU_MODEL "qemu64"
+#else
+#define DEFAULT_KVM_CPU_MODEL "kvm32"
+#define DEFAULT_QEMU_CPU_MODEL "qemu32"
+#endif
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -867,11 +877,10 @@ void pc_cpus_init(const char *cpu_model)
 
     /* init CPUs */
     if (cpu_model == NULL) {

hw/pc.c void pc_cpus_init(const char *cpu_model) · line 884

Quoted 10 lines
hw/pc.c +4 -5
-#ifdef TARGET_X86_64
-        cpu_model = "qemu64";
-#else
-        cpu_model = "qemu32";
-#endif
+        if (kvm_enabled())
+            cpu_model = DEFAULT_KVM_CPU_MODEL;
+        else
+            cpu_model = DEFAULT_QEMU_CPU_MODEL;
 

Braces :(.

Alex

#3 lore raw

Re: [PATCH 1/3] Make kvm64 the default cpu model when kvm_enabled()

Quoted 7 lines · Alexander Graf

Review

Quoted 5 lines
(quoted diff) +4 -0
+        if (kvm_enabled())
+            cpu_model = DEFAULT_KVM_CPU_MODEL;
+        else
+            cpu_model = DEFAULT_QEMU_CPU_MODEL;

Braces :(.

Okay, here is the new patch:

Quoted 1 line

From f49e78edbd4143d05128228d9cc24bd5abc3abf1 Mon Sep 17 00:00:00 2001

From: Joerg Roedel <[email protected]>
Date: Tue, 14 Sep 2010 16:52:11 +0200
Subject: [PATCH 1/3] Make kvm64 the default cpu model when kvm_enabled()

As requested by Alex this patch makes kvm64 the default CPU model when qemu is started with -enable-kvm.

---
 hw/pc.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)
hw/pc.c +15 -5
index 69b13bf..a6355f3 100644
@@ -40,6 +40,16 @@
 #include "sysbus.h"
 #include "sysemu.h"
 #include "blockdev.h"
+#include "kvm.h"
+
+
+#ifdef TARGET_X86_64
+#define DEFAULT_KVM_CPU_MODEL "kvm64"
+#define DEFAULT_QEMU_CPU_MODEL "qemu64"
+#else
+#define DEFAULT_KVM_CPU_MODEL "kvm32"
+#define DEFAULT_QEMU_CPU_MODEL "qemu32"
+#endif
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -867,11 +877,11 @@ void pc_cpus_init(const char *cpu_model)
 
     /* init CPUs */
     if (cpu_model == NULL) {
-#ifdef TARGET_X86_64
-        cpu_model = "qemu64";
-#else
-        cpu_model = "qemu32";
-#endif
+        if (kvm_enabled()) {
+            cpu_model = DEFAULT_KVM_CPU_MODEL;
+        } else {
+            cpu_model = DEFAULT_QEMU_CPU_MODEL;
+        }
     }
 
     for(i = 0; i < smp_cpus; i++) {
Signature · 9 lines
1.7.0.4


-- 
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
#4 lore raw

Re: [PATCH 1/3] Make kvm64 the default cpu model when kvm_enabled()

In reply to Joerg Roedel
Quoted 4 lines · Joerg Roedel

As requested by Alex this patch makes kvm64 the default CPU model when qemu is started with -enable-kvm.

This breaks compatiblity; if started with -M 0.13 or prior we should default to qemu64.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw

Re: [PATCH 1/3] Make kvm64 the default cpu model when kvm_enabled()

Quoted 8 lines · Avi Kivity
Quoted 4 lines · Joerg Roedel

As requested by Alex this patch makes kvm64 the default CPU model when qemu is started with -enable-kvm.

This breaks compatiblity; if started with -M 0.13 or prior we should default to qemu64.

Ok, I can change that. But its ok to make kvm64 the default for anything > 0.13?

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
#6 lore raw

Re: [PATCH 1/3] Make kvm64 the default cpu model when kvm_enabled()

Quoted 7 lines · Joerg
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Joerg Roedel

As requested by Alex this patch makes kvm64 the default CPU model when qemu is started with -enable-kvm.

Quoted 6 lines
Quoted 2 lines

This breaks compatiblity; if started with -M 0.13 or prior we should default to qemu64.

Ok, I can change that. But its ok to make kvm64 the default for anything> 0.13?

Sure.

Signature · 1 line
error compiling committee.c: too many arguments to function
#7 lore raw

PATCH 2/3 Set cpuid definition to 0 before initializing it

In reply to Joerg Roedel

This patch cleans the (stack-allocated) cpuid definition to 0 before actually initializing it.

---
 target-i386/cpuid.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
target-i386/cpuid.c +2 -0
index 04ba8d5..3fcf78f 100644
@@ -788,6 +788,8 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model)
 {
     x86_def_t def1, *def = &def1;
 
+    memset(def, 0, sizeof(*def));
+
     if (cpu_x86_find_by_name(def, cpu_model) < 0)
         return -1;
     if (def->vendor1) {
Signature · 1 line
1.7.0.4
#8 lore raw

PATCH 3/3 Add svm cpuid features

In reply to Joerg Roedel

This patch adds the svm cpuid feature flags to the qemu intialization path. It also adds the svm features available on phenom to its cpu-definition and extends the host cpu type to support all svm features KVM can provide.

---
 target-i386/cpu.h   |   12 ++++++++
 target-i386/cpuid.c |   77 +++++++++++++++++++++++++++++++++++++++-----------
 target-i386/kvm.c   |    3 ++
 3 files changed, 75 insertions(+), 17 deletions(-)
target-i386/cpu.h +12 -0
index 1144d4e..77eeab1 100644
@@ -405,6 +405,17 @@
 #define CPUID_EXT3_IBS     (1 << 10)
 #define CPUID_EXT3_SKINIT  (1 << 12)
 
+#define CPUID_SVM_NPT          (1 << 0)
+#define CPUID_SVM_LBRV         (1 << 1)
+#define CPUID_SVM_SVMLOCK      (1 << 2)
+#define CPUID_SVM_NRIPSAVE     (1 << 3)
+#define CPUID_SVM_TSCSCALE     (1 << 4)
+#define CPUID_SVM_VMCBCLEAN    (1 << 5)
+#define CPUID_SVM_FLUSHASID    (1 << 6)
+#define CPUID_SVM_DECODEASSIST (1 << 7)
+#define CPUID_SVM_PAUSEFILTER  (1 << 10)
+#define CPUID_SVM_PFTHRESHOLD  (1 << 12)
+
 #define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */
 #define CPUID_VENDOR_INTEL_2 0x49656e69 /* "ineI" */
 #define CPUID_VENDOR_INTEL_3 0x6c65746e /* "ntel" */
@@ -702,6 +713,7 @@ typedef struct CPUX86State {
     uint8_t has_error_code;
     uint32_t sipi_vector;
     uint32_t cpuid_kvm_features;
+    uint32_t cpuid_svm_features;
     
     /* in order to simplify APIC support, we leave this pointer to the
        user */
target-i386/cpuid.c +60 -17

172 lines not on this page · raw message

target-i386/kvm.c +3 -0
index a33d2fa..74e7b4f 100644
@@ -192,6 +192,9 @@ int kvm_arch_init_vcpu(CPUState *env)
                                                              0, R_EDX);
     env->cpuid_ext3_features &= kvm_arch_get_supported_cpuid(env, 0x80000001,
                                                              0, R_ECX);
+    env->cpuid_svm_features  &= kvm_arch_get_supported_cpuid(env, 0x8000000A,
+                                                             0, R_EDX);
+
 
     cpuid_i = 0;
 
Signature · 1 line
1.7.0.4
#9 lore raw

Re: [PATCH 3/3] Add svm cpuid features

Quoted 6 lines · Joerg Roedel

This patch adds the svm cpuid feature flags to the qemu intialization path. It also adds the svm features available on phenom to its cpu-definition and extends the host cpu type to support all svm features KVM can provide.

Does phenom really have vmcbclean? I thought it was a really new feature.

Signature · 1 line
error compiling committee.c: too many arguments to function
#10 lore raw

Re: [PATCH 3/3] Add svm cpuid features

Quoted 9 lines · Avi Kivity
Quoted 6 lines · Joerg Roedel

This patch adds the svm cpuid feature flags to the qemu intialization path. It also adds the svm features available on phenom to its cpu-definition and extends the host cpu type to support all svm features KVM can provide.

Does phenom really have vmcbclean? I thought it was a really new feature.

No, but we could emulate it on almost all hardware that has SVM. Its basically the same as with x2apic.

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
#11 lore raw

Re: [PATCH 3/3] Add svm cpuid features

Quoted 11 lines · Joerg
Quoted 9 lines · Avi Kivity
Quoted 7 lines · Joerg Roedel

This patch adds the svm cpuid feature flags to the qemu intialization path. It also adds the svm features available on phenom to its cpu-definition and extends the host cpu type to support all svm features KVM can provide.

Quoted 6 lines
Quoted 2 lines

Does phenom really have vmcbclean? I thought it was a really new feature.

No, but we could emulate it on almost all hardware that has SVM. Its basically the same as with x2apic.

-cpu <non-host> is not about what we could emulate, but what the hardware really is. Features not supported by the particular CPU do not belong there.

Alex

#12 lore raw

Re: [PATCH 3/3] Add svm cpuid features

Quoted 15 lines · Alexander Graf
Quoted 14 lines · Joerg
Quoted 11 lines · Avi Kivity
Quoted 7 lines · Joerg Roedel

This patch adds the svm cpuid feature flags to the qemu intialization path. It also adds the svm features available on phenom to its cpu-definition and extends the host cpu type to support all svm features KVM can provide.

Does phenom really have vmcbclean? I thought it was a really new feature.

Quoted 7 lines
Quoted 3 lines

No, but we could emulate it on almost all hardware that has SVM. Its basically the same as with x2apic.

-cpu <non-host> is not about what we could emulate, but what the hardware really is. Features not supported by the particular CPU do not belong there.

I'll remove it then. It would have been nice to have it there because it will improve performance of svm emulation. But if it is about emulating the real cpu then I'll just drop it.

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
#13 lore raw

Re: [PATCH 3/3] Add svm cpuid features

Quoted 25 lines · Joerg
Quoted 23 lines · Alexander Graf
Quoted 21 lines · Joerg
Quoted 11 lines · Avi Kivity
Quoted 8 lines · Joerg Roedel

This patch adds the svm cpuid feature flags to the qemu intialization path. It also adds the svm features available on phenom to its cpu-definition and extends the host cpu type to support all svm features KVM can provide.

Quoted 3 lines

Does phenom really have vmcbclean? I thought it was a really new feature.

No, but we could emulate it on almost all hardware that has SVM. Its basically the same as with x2apic.

Quoted 9 lines
Quoted 4 lines

-cpu <non-host> is not about what we could emulate, but what the hardware really is. Features not supported by the particular CPU do not belong there.

I'll remove it then. It would have been nice to have it there because it will improve performance of svm emulation. But if it is about emulating the real cpu then I'll just drop it.

speed == -cpu host :). If the performance increase is significant, we can always add a new cpu type for a cpu that does support those flags so people can use it there and still be migration safe. In fact, that would even benefit you guys as you'd sell more new machines for speed ;).

Alex

#14 lore raw

Re: [PATCH 3/3] Add svm cpuid features

Quoted 9 lines · Alexander Graf
Quoted 3 lines · Joerg

I'll remove it then. It would have been nice to have it there because it will improve performance of svm emulation. But if it is about emulating the real cpu then I'll just drop it.

speed == -cpu host :). If the performance increase is significant, we can always add a new cpu type for a cpu that does support those flags so people can use it there and still be migration safe. In fact, that would even benefit you guys as you'd sell more new machines for speed ;).

Well, since its emulated completly in software it would be available on all hosts that start with -cpu phenom (at least if they use the same kvm version). So this would not break migration.

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
Acked-by on the v1 series
#15 lore raw
In reply to Joerg Roedel
Quoted 8 lines · Joerg Roedel

Hi,

here is the next round of the svm feature support patches for qemu. Key change in this version is that it now makes kvm{64|32} the default cpu definition for qemu when kvm is enabled (as requested by Alex). Otherwise I removed the NRIP_SAVE feature from the phenom definition and set svm_features per default to -1 for -cpu host to support all svm features that kvm can emulate. I appreciate your comments.

With the updated 1/3 patch, it looks really good to me.