Skip to contentSkip to conversation

SVM feature support for qemu v3

PATCH Applied Joerg Roedel 5 participants 20 messages Sep 27, 2010 – Oct 20, 2010 KVM

lore
Share & tools
lore
#0 lore raw

cover SVM feature support for qemu v3

Hi,

here is the third round of the patches to add svm-features support to qemu. The patches are rebases against latest qemu/master. Other changes since v2:

* Made kvm64 the default model only for qemu-versions >= 0.14.0
* Removed clean-bits from the phenom cpu-model

Feedback and/or merge appreciated :-)

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. This takes only effect for qemu-versions newer or equal to 0.14.0.

---
 hw/boards.h    |    1 +
 hw/pc.c        |   21 ++++++++++++++++-----
 hw/pc_piix.c   |    6 ++++++
 qemu-version.h |   35 +++++++++++++++++++++++++++++++++++
 vl.c           |    4 ++++
 5 files changed, 62 insertions(+), 5 deletions(-)
 create mode 100644 qemu-version.h
hw/boards.h +1 -0
index 6f0f0d7..2d41b2d 100644
@@ -19,6 +19,7 @@ typedef struct QEMUMachine {
     QEMUMachineInitFunc *init;
     int use_scsi;
     int max_cpus;
+    unsigned int compat_version;
     unsigned int no_serial:1,
         no_parallel:1,
         use_virtcon:1,
hw/pc.c +16 -5
index 69b13bf..372ec4c 100644
@@ -40,6 +40,16 @@
 #include "sysbus.h"
 #include "sysemu.h"
 #include "blockdev.h"
+#include "kvm.h"
+#include "qemu-version.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,12 @@ 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() &&
+            qemu_compat_version >= QEMU_COMPAT_VERSION(0, 14, 0)) {
+            cpu_model = DEFAULT_KVM_CPU_MODEL;
+        } else {
+            cpu_model = DEFAULT_QEMU_CPU_MODEL;
+        }
     }
 
     for(i = 0; i < smp_cpus; i++) {
hw/pc_piix.c +6 -0
index 12359a7..9e46b71 100644
@@ -35,6 +35,7 @@
 #include "sysemu.h"
 #include "sysbus.h"
 #include "blockdev.h"
+#include "qemu-version.h"
 
 #define MAX_IDE_BUS 2
 
@@ -217,6 +218,7 @@ static QEMUMachine pc_machine = {
     .desc = "Standard PC",
     .init = pc_init_pci,
     .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 13, 0),
     .is_default = 1,
 };
 
@@ -225,6 +227,7 @@ static QEMUMachine pc_machine_v0_12 = {
     .desc = "Standard PC",
     .init = pc_init_pci,
     .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 12, 0),
     .compat_props = (GlobalProperty[]) {
         {
             .driver   = "virtio-serial-pci",
@@ -244,6 +247,7 @@ static QEMUMachine pc_machine_v0_11 = {
     .desc = "Standard PC, qemu 0.11",
     .init = pc_init_pci,
     .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 11, 0),
     .compat_props = (GlobalProperty[]) {
         {
             .driver   = "virtio-blk-pci",
@@ -279,6 +283,7 @@ static QEMUMachine pc_machine_v0_10 = {
     .desc = "Standard PC, qemu 0.10",
     .init = pc_init_pci,
     .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 10, 0),
     .compat_props = (GlobalProperty[]) {
         {
             .driver   = "virtio-blk-pci",
@@ -325,6 +330,7 @@ static QEMUMachine isapc_machine = {
     .name = "isapc",
     .desc = "ISA-only PC",
     .init = pc_init_isa,
+    .compat_version = QEMU_COMPAT_VERSION(0, 10, 0),
     .max_cpus = 1,
 };
 
qemu-version.h new file +35 -0
new file mode 100644
index 0000000..b4bfe48
@@ -0,0 +1,35 @@
+/*
+ * qemu-version.h
+ *
+ * Defines needed for handling QEMU version compatibility
+ *
+ * Copyright (c) 2010 Joerg Roedel <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _QEMU_VERSION_H_
+#define _QEMU_VERSION_H_
+
+extern unsigned int qemu_compat_version;
+
+#define QEMU_COMPAT_VERSION(major, minor, patchlevel) \
+        ((unsigned int)(major << 16) | (minor << 8) | (patchlevel))
+
+#endif
vl.c +4 -0
index d352d18..37727f3 100644
@@ -161,6 +161,7 @@ int main(int argc, char **argv)
 #include "qemu-queue.h"
 #include "cpus.h"
 #include "arch_init.h"
+#include "qemu-version.h"
 
 //#define DEBUG_NET
 //#define DEBUG_SLIRP
@@ -169,6 +170,7 @@ int main(int argc, char **argv)
 
 #define MAX_VIRTIO_CONSOLES 1
 
+unsigned int qemu_compat_version;
 static const char *data_dir;
 const char *bios_name = NULL;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
@@ -2696,6 +2698,8 @@ int main(int argc, char **argv, char **envp)
         default_sdcard = 0;
     }
 
+    qemu_compat_version = machine->compat_version;
+
     if (display_type == DT_NOGRAPHIC) {
         if (default_parallel)
             add_device_config(DEV_PARALLEL, "null");
Signature · 1 line
1.7.0.4
#2 lore raw

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

Quoted 189 lines · Joerg Roedel

As requested by Alex this patch makes kvm64 the default CPU model when qemu is started with -enable-kvm. This takes only effect for qemu-versions newer or equal to 0.14.0.

---
 hw/boards.h    |    1 +
 hw/pc.c        |   21 ++++++++++++++++-----
 hw/pc_piix.c   |    6 ++++++
 qemu-version.h |   35 +++++++++++++++++++++++++++++++++++
 vl.c           |    4 ++++
 5 files changed, 62 insertions(+), 5 deletions(-)
 create mode 100644 qemu-version.h
hw/boards.h +1 -0
index 6f0f0d7..2d41b2d 100644
@@ -19,6 +19,7 @@ typedef struct QEMUMachine {
     QEMUMachineInitFunc *init;
     int use_scsi;
     int max_cpus;
+    unsigned int compat_version;
     unsigned int no_serial:1,
         no_parallel:1,
         use_virtcon:1,
hw/pc.c +16 -5
index 69b13bf..372ec4c 100644
@@ -40,6 +40,16 @@
 #include "sysbus.h"
 #include "sysemu.h"
 #include "blockdev.h"
+#include "kvm.h"
+#include "qemu-version.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,12 @@ 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() &&
+            qemu_compat_version >= QEMU_COMPAT_VERSION(0, 14, 0)) {
+            cpu_model = DEFAULT_KVM_CPU_MODEL;
+        } else {
+            cpu_model = DEFAULT_QEMU_CPU_MODEL;
+        }
     }
 
     for(i = 0; i < smp_cpus; i++) {
hw/pc_piix.c +6 -0
index 12359a7..9e46b71 100644
@@ -35,6 +35,7 @@
 #include "sysemu.h"
 #include "sysbus.h"
 #include "blockdev.h"
+#include "qemu-version.h"
 
 #define MAX_IDE_BUS 2
 
@@ -217,6 +218,7 @@ static QEMUMachine pc_machine = {
     .desc = "Standard PC",
     .init = pc_init_pci,
     .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 13, 0),
     .is_default = 1,
 };
 
@@ -225,6 +227,7 @@ static QEMUMachine pc_machine_v0_12 = {
     .desc = "Standard PC",
     .init = pc_init_pci,
     .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 12, 0),
     .compat_props = (GlobalProperty[]) {
         {
             .driver   = "virtio-serial-pci",
@@ -244,6 +247,7 @@ static QEMUMachine pc_machine_v0_11 = {
     .desc = "Standard PC, qemu 0.11",
     .init = pc_init_pci,
     .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 11, 0),
     .compat_props = (GlobalProperty[]) {
         {
             .driver   = "virtio-blk-pci",
@@ -279,6 +283,7 @@ static QEMUMachine pc_machine_v0_10 = {
     .desc = "Standard PC, qemu 0.10",
     .init = pc_init_pci,
     .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 10, 0),
     .compat_props = (GlobalProperty[]) {
         {
             .driver   = "virtio-blk-pci",
@@ -325,6 +330,7 @@ static QEMUMachine isapc_machine = {
     .name = "isapc",
     .desc = "ISA-only PC",
     .init = pc_init_isa,
+    .compat_version = QEMU_COMPAT_VERSION(0, 10, 0),
     .max_cpus = 1,
 };
 
qemu-version.h new file +35 -0
new file mode 100644
index 0000000..b4bfe48
@@ -0,0 +1,35 @@
+/*
+ * qemu-version.h
+ *
+ * Defines needed for handling QEMU version compatibility
+ *
+ * Copyright (c) 2010 Joerg Roedel <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _QEMU_VERSION_H_
+#define _QEMU_VERSION_H_
+
+extern unsigned int qemu_compat_version;
+
+#define QEMU_COMPAT_VERSION(major, minor, patchlevel) \
+        ((unsigned int)(major << 16) | (minor << 8) | (patchlevel))
+
+#endif
vl.c +4 -0
index d352d18..37727f3 100644
@@ -161,6 +161,7 @@ int main(int argc, char **argv)
 #include "qemu-queue.h"
 #include "cpus.h"
 #include "arch_init.h"
+#include "qemu-version.h"
 
 //#define DEBUG_NET
 //#define DEBUG_SLIRP
@@ -169,6 +170,7 @@ int main(int argc, char **argv)
 
 #define MAX_VIRTIO_CONSOLES 1
 
+unsigned int qemu_compat_version;
 static const char *data_dir;
 const char *bios_name = NULL;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
@@ -2696,6 +2698,8 @@ int main(int argc, char **argv, char **envp)
         default_sdcard = 0;
     }
 
+    qemu_compat_version = machine->compat_version;
+
     if (display_type == DT_NOGRAPHIC) {
         if (default_parallel)
             add_device_config(DEV_PARALLEL, "null");
Signature · 1 line
1.7.0.4

Looks fine to me, given CPUs are not in qdev. Anthony?

#3 lore raw

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

Quoted 184 lines · Marcelo Tosatti
Quoted 182 lines · Joerg Roedel

As requested by Alex this patch makes kvm64 the default CPU model when qemu is started with -enable-kvm. This takes only effect for qemu-versions newer or equal to 0.14.0.

---
  hw/boards.h    |    1 +
  hw/pc.c        |   21 ++++++++++++++++-----
  hw/pc_piix.c   |    6 ++++++
  qemu-version.h |   35 +++++++++++++++++++++++++++++++++++
  vl.c           |    4 ++++
  5 files changed, 62 insertions(+), 5 deletions(-)

create mode 100644 qemu-version.h

hw/boards.h +1 -0
index 6f0f0d7..2d41b2d 100644
@@ -19,6 +19,7 @@ typedef struct QEMUMachine {
      QEMUMachineInitFunc *init;
      int use_scsi;
      int max_cpus;
+    unsigned int compat_version;
      unsigned int no_serial:1,
          no_parallel:1,
          use_virtcon:1,
hw/pc.c +16 -5
index 69b13bf..372ec4c 100644
@@ -40,6 +40,16 @@
  #include "sysbus.h"
  #include "sysemu.h"
  #include "blockdev.h"
+#include "kvm.h"
+#include "qemu-version.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,12 @@ 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()&&
+            qemu_compat_version>= QEMU_COMPAT_VERSION(0, 14, 0)) {
+            cpu_model = DEFAULT_KVM_CPU_MODEL;
+        } else {
+            cpu_model = DEFAULT_QEMU_CPU_MODEL;
+        }
      }
 
      for(i = 0; i<  smp_cpus; i++) {
hw/pc_piix.c +6 -0
index 12359a7..9e46b71 100644
@@ -35,6 +35,7 @@
  #include "sysemu.h"
  #include "sysbus.h"
  #include "blockdev.h"
+#include "qemu-version.h"
 
  #define MAX_IDE_BUS 2
 
@@ -217,6 +218,7 @@ static QEMUMachine pc_machine = {
      .desc = "Standard PC",
      .init = pc_init_pci,
      .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 13, 0),
      .is_default = 1,
  };
 
@@ -225,6 +227,7 @@ static QEMUMachine pc_machine_v0_12 = {
      .desc = "Standard PC",
      .init = pc_init_pci,
      .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 12, 0),
      .compat_props = (GlobalProperty[]) {
          {
              .driver   = "virtio-serial-pci",
@@ -244,6 +247,7 @@ static QEMUMachine pc_machine_v0_11 = {
      .desc = "Standard PC, qemu 0.11",
      .init = pc_init_pci,
      .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 11, 0),
      .compat_props = (GlobalProperty[]) {
          {
              .driver   = "virtio-blk-pci",
@@ -279,6 +283,7 @@ static QEMUMachine pc_machine_v0_10 = {
      .desc = "Standard PC, qemu 0.10",
      .init = pc_init_pci,
      .max_cpus = 255,
+    .compat_version = QEMU_COMPAT_VERSION(0, 10, 0),
      .compat_props = (GlobalProperty[]) {
          {
              .driver   = "virtio-blk-pci",
@@ -325,6 +330,7 @@ static QEMUMachine isapc_machine = {
      .name = "isapc",
      .desc = "ISA-only PC",
      .init = pc_init_isa,
+    .compat_version = QEMU_COMPAT_VERSION(0, 10, 0),
      .max_cpus = 1,
  };
 
qemu-version.h new file +35 -0
new file mode 100644
index 0000000..b4bfe48
@@ -0,0 +1,35 @@
+/*
+ * qemu-version.h
+ *
+ * Defines needed for handling QEMU version compatibility
+ *
+ * Copyright (c) 2010 Joerg Roedel<[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _QEMU_VERSION_H_
+#define _QEMU_VERSION_H_
+
+extern unsigned int qemu_compat_version;
+
+#define QEMU_COMPAT_VERSION(major, minor, patchlevel) \
+        ((unsigned int)(major<<  16) | (minor<<  8) | (patchlevel))
+
+#endif
vl.c +2 -0
index d352d18..37727f3 100644
@@ -161,6 +161,7 @@ int main(int argc, char **argv)
  #include "qemu-queue.h"
  #include "cpus.h"
  #include "arch_init.h"
+#include "qemu-version.h"
 
  //#define DEBUG_NET
  //#define DEBUG_SLIRP
@@ -169,6 +170,7 @@ int main(int argc, char **argv)
 
  #define MAX_VIRTIO_CONSOLES 1
 
+unsigned int qemu_compat_version;
  static const char *data_dir;
  const char *bios_name = NULL;
  enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
@@ -2696,6 +2698,8 @@ int main(int argc, char **argv, char **envp)
          default_sdcard = 0;
      }
 
Quoted 10 lines
Quoted 8 lines
vl.c +2 -0
+    qemu_compat_version = machine->compat_version;
+
      if (display_type == DT_NOGRAPHIC) {
          if (default_parallel)
              add_device_config(DEV_PARALLEL, "null");
Signature · 1 line
1.7.0.4

Looks fine to me, given CPUs are not in qdev. Anthony?

The idea is fine, but why not just add the default CPU to the machine description?

Regards,

Anthony Liguori

#4 lore raw

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

Quoted 8 lines · Anthony Liguori
Quoted 8 lines
Quoted 8 lines
vl.c +2 -0
+    qemu_compat_version = machine->compat_version;
+
      if (display_type == DT_NOGRAPHIC) {
          if (default_parallel)
              add_device_config(DEV_PARALLEL, "null");
Signature · 1 line
1.7.0.4
Quoted 5 lines
Quoted 2 lines

Looks fine to me, given CPUs are not in qdev. Anthony?

The idea is fine, but why not just add the default CPU to the machine description?

If I remember correctly the reason was that the machine description was not accessible in the cpuid initialization path because it is a function local variable. I could have made it a global variable but considered the compat_version approach simpler. The qemu_compat_version might also be useful at other places.

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
#5 lore raw

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

Quoted 14 lines · Joerg
Quoted 12 lines · Anthony Liguori
Quoted 12 lines
Quoted 9 lines
(quoted diff) +2 -0
+    qemu_compat_version = machine->compat_version;
+
       if (display_type == DT_NOGRAPHIC) {
           if (default_parallel)
               add_device_config(DEV_PARALLEL, "null");
Signature · 1 line
1.7.0.4

Looks fine to me, given CPUs are not in qdev. Anthony?

Quoted 6 lines
Quoted 3 lines

The idea is fine, but why not just add the default CPU to the machine description?

If I remember correctly the reason was that the machine description was not accessible in the cpuid initialization path because it is a function local variable.

Not tested at all but I think the attached patch addresses it in a pretty nice way.

There's a couple ways you could support your patch on top of this. You could add a kvm_cpu_model to the machine structure that gets defaulted too if kvm_enabled(). You could also introduce a new KVM machine type that gets defaulted to if no explicit machine is specified.

Quoted 4 lines

I could have made it a global variable but considered
the compat_version approach simpler. The qemu_compat_version might also be useful at other places.

The reason we've avoided having a builtin notion of versions is that we have many downstreams where versioning would get very complicated. If we stick to features it makes it much easier for downstreams.

Regards,

Anthony Liguori

Quoted 5 lines

Joerg

From d2370c88cef4b07d48ba3c4804e35ae2db8db7c0 Mon Sep 17 00:00:00 2001

From: Anthony Liguori <[email protected]>
Date: Thu, 7 Oct 2010 07:43:42 -0500
Subject: [PATCH] machine: make default cpu model part of machine structure

hw/boards.h +1 -0
index 6f0f0d7..8c6ef27 100644
@@ -16,6 +16,7 @@ typedef struct QEMUMachine {
     const char *name;
     const char *alias;
     const char *desc;
+    const char *cpu_model;
     QEMUMachineInitFunc *init;
     int use_scsi;
     int max_cpus;
hw/pc.c +0 -8
index 69b13bf..0826107 100644
@@ -866,14 +866,6 @@ void pc_cpus_init(const char *cpu_model)
     int i;
 
     /* init CPUs */
-    if (cpu_model == NULL) {
-#ifdef TARGET_X86_64
-        cpu_model = "qemu64";
-#else
-        cpu_model = "qemu32";
-#endif
-    }
-
     for(i = 0; i < smp_cpus; i++) {
         pc_new_cpu(cpu_model);
     }
hw/pc_piix.c +11 -2
index 12359a7..919b4d6 100644
@@ -204,17 +204,22 @@ static void pc_init_isa(ram_addr_t ram_size,
                         const char *initrd_filename,
                         const char *cpu_model)
 {
-    if (cpu_model == NULL)
-        cpu_model = "486";
     pc_init1(ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 0);
 }
 
+#ifdef TARGET_X86_64
+#define DEF_CPU_MODEL "qemu64"
+#else
+#define DEF_CPU_MODEL "qemu32"
+#endif
+
 static QEMUMachine pc_machine = {
     .name = "pc-0.13",
     .alias = "pc",
     .desc = "Standard PC",
+    .cpu_model = DEF_CPU_MODEL,
     .init = pc_init_pci,
     .max_cpus = 255,
     .is_default = 1,
@@ -223,6 +228,7 @@ static QEMUMachine pc_machine = {
 static QEMUMachine pc_machine_v0_12 = {
     .name = "pc-0.12",
     .desc = "Standard PC",
+    .cpu_model = DEF_CPU_MODEL,
     .init = pc_init_pci,
     .max_cpus = 255,
     .compat_props = (GlobalProperty[]) {
@@ -242,6 +248,7 @@ static QEMUMachine pc_machine_v0_12 = {
 static QEMUMachine pc_machine_v0_11 = {
     .name = "pc-0.11",
     .desc = "Standard PC, qemu 0.11",
+    .cpu_model = DEF_CPU_MODEL,
     .init = pc_init_pci,
     .max_cpus = 255,
     .compat_props = (GlobalProperty[]) {
@@ -277,6 +284,7 @@ static QEMUMachine pc_machine_v0_11 = {
 static QEMUMachine pc_machine_v0_10 = {
     .name = "pc-0.10",
     .desc = "Standard PC, qemu 0.10",
+    .cpu_model = DEF_CPU_MODEL,
     .init = pc_init_pci,
     .max_cpus = 255,
     .compat_props = (GlobalProperty[]) {
@@ -324,6 +332,7 @@ static QEMUMachine pc_machine_v0_10 = {
 static QEMUMachine isapc_machine = {
     .name = "isapc",
     .desc = "ISA-only PC",
+    .cpu_model = "486",
     .init = pc_init_isa,
     .max_cpus = 1,
 };
vl.c +4 -0
index df414ef..3a55cc8 100644
@@ -2904,6 +2904,10 @@ int main(int argc, char **argv, char **envp)
     }
     qemu_add_globals();
 
+    if (cpu_model == NULL) {
+        cpu_model = machine->cpu_model;
+    }
+
     machine->init(ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
Signature · 1 line
1.7.0.4
#6 lore raw

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

(Sorry for the late reply)

Quoted 22 lines · Anthony Liguori
Quoted 14 lines · Joerg
Quoted 12 lines · Anthony Liguori
Quoted 12 lines
Quoted 9 lines
(quoted diff) +2 -0
+    qemu_compat_version = machine->compat_version;
+
       if (display_type == DT_NOGRAPHIC) {
           if (default_parallel)
               add_device_config(DEV_PARALLEL, "null");
Signature · 1 line
1.7.0.4

Looks fine to me, given CPUs are not in qdev. Anthony?

Quoted 6 lines
Quoted 3 lines

The idea is fine, but why not just add the default CPU to the machine description?

If I remember correctly the reason was that the machine description was not accessible in the cpuid initialization path because it is a function local variable.

Quoted 7 lines

Not tested at all but I think the attached patch addresses it in a pretty nice way.

There's a couple ways you could support your patch on top of this. You could add a kvm_cpu_model to the machine structure that gets defaulted too if kvm_enabled(). You could also introduce a new KVM machine type that gets defaulted to if no explicit machine is specified.

I had something similar in mind but then I realized that we need at least a cpu_model and a cpu_model_kvm to distinguish between the TCG and the KVM case.
Further the QEMUMachine data structure is used for all architectures in QEMU and the model-names only make sense for x86. So I decided for the comapt-version way (which doesn't mean I object against this one ;-) )

Joerg

Quoted 117 lines

From d2370c88cef4b07d48ba3c4804e35ae2db8db7c0 Mon Sep 17 00:00:00 2001
From: Anthony Liguori <[email protected]>
Date: Thu, 7 Oct 2010 07:43:42 -0500
Subject: [PATCH] machine: make default cpu model part of machine structure

hw/boards.h +1 -0
index 6f0f0d7..8c6ef27 100644
@@ -16,6 +16,7 @@ typedef struct QEMUMachine {
     const char *name;
     const char *alias;
     const char *desc;
+    const char *cpu_model;
     QEMUMachineInitFunc *init;
     int use_scsi;
     int max_cpus;
hw/pc.c +0 -8
index 69b13bf..0826107 100644
@@ -866,14 +866,6 @@ void pc_cpus_init(const char *cpu_model)
     int i;
 
     /* init CPUs */
-    if (cpu_model == NULL) {
-#ifdef TARGET_X86_64
-        cpu_model = "qemu64";
-#else
-        cpu_model = "qemu32";
-#endif
-    }
-
     for(i = 0; i < smp_cpus; i++) {
         pc_new_cpu(cpu_model);
     }
hw/pc_piix.c +11 -2
index 12359a7..919b4d6 100644
@@ -204,17 +204,22 @@ static void pc_init_isa(ram_addr_t ram_size,
                         const char *initrd_filename,
                         const char *cpu_model)
 {
-    if (cpu_model == NULL)
-        cpu_model = "486";
     pc_init1(ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 0);
 }
 
+#ifdef TARGET_X86_64
+#define DEF_CPU_MODEL "qemu64"
+#else
+#define DEF_CPU_MODEL "qemu32"
+#endif
+
 static QEMUMachine pc_machine = {
     .name = "pc-0.13",
     .alias = "pc",
     .desc = "Standard PC",
+    .cpu_model = DEF_CPU_MODEL,
     .init = pc_init_pci,
     .max_cpus = 255,
     .is_default = 1,
@@ -223,6 +228,7 @@ static QEMUMachine pc_machine = {
 static QEMUMachine pc_machine_v0_12 = {
     .name = "pc-0.12",
     .desc = "Standard PC",
+    .cpu_model = DEF_CPU_MODEL,
     .init = pc_init_pci,
     .max_cpus = 255,
     .compat_props = (GlobalProperty[]) {
@@ -242,6 +248,7 @@ static QEMUMachine pc_machine_v0_12 = {
 static QEMUMachine pc_machine_v0_11 = {
     .name = "pc-0.11",
     .desc = "Standard PC, qemu 0.11",
+    .cpu_model = DEF_CPU_MODEL,
     .init = pc_init_pci,
     .max_cpus = 255,
     .compat_props = (GlobalProperty[]) {
@@ -277,6 +284,7 @@ static QEMUMachine pc_machine_v0_11 = {
 static QEMUMachine pc_machine_v0_10 = {
     .name = "pc-0.10",
     .desc = "Standard PC, qemu 0.10",
+    .cpu_model = DEF_CPU_MODEL,
     .init = pc_init_pci,
     .max_cpus = 255,
     .compat_props = (GlobalProperty[]) {
@@ -324,6 +332,7 @@ static QEMUMachine pc_machine_v0_10 = {
 static QEMUMachine isapc_machine = {
     .name = "isapc",
     .desc = "ISA-only PC",
+    .cpu_model = "486",
     .init = pc_init_isa,
     .max_cpus = 1,
 };
vl.c +4 -0
index df414ef..3a55cc8 100644
@@ -2904,6 +2904,10 @@ int main(int argc, char **argv, char **envp)
     }
     qemu_add_globals();
 
+    if (cpu_model == NULL) {
+        cpu_model = machine->cpu_model;
+    }
+
     machine->init(ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
Signature · 1 line
1.7.0.4
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
#7 lore raw

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

Quoted 34 lines · Joerg

(Sorry for the late reply)

Quoted 30 lines · Anthony Liguori
Quoted 17 lines · Joerg
Quoted 14 lines · Anthony Liguori
Quoted 14 lines
Quoted 10 lines
(quoted diff) +2 -0
+    qemu_compat_version = machine->compat_version;
+
        if (display_type == DT_NOGRAPHIC) {
            if (default_parallel)
                add_device_config(DEV_PARALLEL, "null");
Signature · 1 line
1.7.0.4

Looks fine to me, given CPUs are not in qdev. Anthony?

Quoted 8 lines
Quoted 4 lines

The idea is fine, but why not just add the default CPU to the machine description?

If I remember correctly the reason was that the machine description was not accessible in the cpuid initialization path because it is a function local variable.

Not tested at all but I think the attached patch addresses it in a pretty nice way.

Quoted 9 lines
Quoted 5 lines

There's a couple ways you could support your patch on top of this. You could add a kvm_cpu_model to the machine structure that gets defaulted too if kvm_enabled(). You could also introduce a new KVM machine type that gets defaulted to if no explicit machine is specified.

I had something similar in mind but then I realized that we need at least a cpu_model and a cpu_model_kvm to distinguish between the TCG and the KVM case.

I would think that having different default machines for KVM and TCG would be a better solution.

Quoted 2 lines

Further the QEMUMachine data structure is used for all architectures in QEMU and the model-names only make sense for x86.

SPARC uses cpu_model too FWIW. I believe Blue Swirl has even discussed using a feature-format similar to how x86 does it for SPARC CPUs.

Regards,

Anthony Liguori

Quoted 126 lines

So I decided for the
comapt-version way (which doesn't mean I object against this one ;-) )

Joerg

Quoted 118 lines

From d2370c88cef4b07d48ba3c4804e35ae2db8db7c0 Mon Sep 17 00:00:00 2001
From: Anthony Liguori<[email protected]>
Date: Thu, 7 Oct 2010 07:43:42 -0500
Subject: [PATCH] machine: make default cpu model part of machine structure

hw/boards.h +1 -0
index 6f0f0d7..8c6ef27 100644
@@ -16,6 +16,7 @@ typedef struct QEMUMachine {
      const char *name;
      const char *alias;
      const char *desc;
+    const char *cpu_model;
      QEMUMachineInitFunc *init;
      int use_scsi;
      int max_cpus;
hw/pc.c +0 -8
index 69b13bf..0826107 100644
@@ -866,14 +866,6 @@ void pc_cpus_init(const char *cpu_model)
      int i;
 
      /* init CPUs */
-    if (cpu_model == NULL) {
-#ifdef TARGET_X86_64
-        cpu_model = "qemu64";
-#else
-        cpu_model = "qemu32";
-#endif
-    }
-
      for(i = 0; i<  smp_cpus; i++) {
          pc_new_cpu(cpu_model);
      }
hw/pc_piix.c +11 -2
index 12359a7..919b4d6 100644
@@ -204,17 +204,22 @@ static void pc_init_isa(ram_addr_t ram_size,
                          const char *initrd_filename,
                          const char *cpu_model)
  {
-    if (cpu_model == NULL)
-        cpu_model = "486";
      pc_init1(ram_size, boot_device,
               kernel_filename, kernel_cmdline,
               initrd_filename, cpu_model, 0);
  }
 
+#ifdef TARGET_X86_64
+#define DEF_CPU_MODEL "qemu64"
+#else
+#define DEF_CPU_MODEL "qemu32"
+#endif
+
  static QEMUMachine pc_machine = {
      .name = "pc-0.13",
      .alias = "pc",
      .desc = "Standard PC",
+    .cpu_model = DEF_CPU_MODEL,
      .init = pc_init_pci,
      .max_cpus = 255,
      .is_default = 1,
@@ -223,6 +228,7 @@ static QEMUMachine pc_machine = {
  static QEMUMachine pc_machine_v0_12 = {
      .name = "pc-0.12",
      .desc = "Standard PC",
+    .cpu_model = DEF_CPU_MODEL,
      .init = pc_init_pci,
      .max_cpus = 255,
      .compat_props = (GlobalProperty[]) {
@@ -242,6 +248,7 @@ static QEMUMachine pc_machine_v0_12 = {
  static QEMUMachine pc_machine_v0_11 = {
      .name = "pc-0.11",
      .desc = "Standard PC, qemu 0.11",
+    .cpu_model = DEF_CPU_MODEL,
      .init = pc_init_pci,
      .max_cpus = 255,
      .compat_props = (GlobalProperty[]) {
@@ -277,6 +284,7 @@ static QEMUMachine pc_machine_v0_11 = {
  static QEMUMachine pc_machine_v0_10 = {
      .name = "pc-0.10",
      .desc = "Standard PC, qemu 0.10",
+    .cpu_model = DEF_CPU_MODEL,
      .init = pc_init_pci,
      .max_cpus = 255,
      .compat_props = (GlobalProperty[]) {
@@ -324,6 +332,7 @@ static QEMUMachine pc_machine_v0_10 = {
  static QEMUMachine isapc_machine = {
      .name = "isapc",
      .desc = "ISA-only PC",
+    .cpu_model = "486",
      .init = pc_init_isa,
      .max_cpus = 1,
  };
vl.c +4 -0
index df414ef..3a55cc8 100644
@@ -2904,6 +2904,10 @@ int main(int argc, char **argv, char **envp)
      }
      qemu_add_globals();
 
+    if (cpu_model == NULL) {
+        cpu_model = machine->cpu_model;
+    }
+
      machine->init(ram_size, boot_devices,
                    kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
Signature · 1 line
1.7.0.4
#8 lore raw

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

Quoted 54 lines · Anthony Liguori
Quoted 48 lines · Joerg

(Sorry for the late reply)

Quoted 34 lines · Anthony Liguori
Quoted 21 lines · Joerg
Quoted 17 lines · Anthony Liguori
Quoted 16 lines
Quoted 11 lines

+    qemu_compat_version = machine->compat_version; +
       if (display_type == DT_NOGRAPHIC) {
           if (default_parallel) add_device_config(DEV_PARALLEL, "null"); --
1.7.0.4

Looks fine to me, given CPUs are not in qdev. Anthony?

Quoted 9 lines
Quoted 4 lines

The idea is fine, but why not just add the default CPU to the machine description?

If I remember correctly the reason was that the machine description was not accessible in the cpuid initialization path because it is a function local variable.

Quoted 8 lines

Not tested at all but I think the attached patch addresses it in a pretty nice way.

There's a couple ways you could support your patch on top of this.  You could add a kvm_cpu_model to the machine structure that gets defaulted too if kvm_enabled().  You could also introduce a new KVM machine type that gets defaulted to if no explicit machine is specified.

Quoted 4 lines

I had something similar in mind but then I realized that we need at least a cpu_model and a cpu_model_kvm to distinguish between the TCG and the KVM case.

Quoted 8 lines

I would think that having different default machines for KVM and TCG would be a better solution.

Quoted 2 lines

Further the QEMUMachine data structure is used for all architectures in QEMU and the model-names only make sense for x86.

SPARC uses cpu_model too FWIW.  I believe Blue Swirl has even discussed using a feature-format similar to how x86 does it for SPARC CPUs.

Actually I copied Sparc feature support from x86. Generic feature support would be nice.

#9 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
#10 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
#11 lore raw

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

Quoted 5 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.

This should really be "all svm features" since we'll later mask them with kvm capabilities. This way, if we later add more capabilities, we automatically gain support in userspace.

(or rather, all svm features that don't need save/restore support in userspace; I don't think any do, beyond svm itself)

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

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

Quoted 11 lines · Avi Kivity
Quoted 5 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.

This should really be "all svm features" since we'll later mask them with kvm capabilities. This way, if we later add more capabilities, we automatically gain support in userspace.

(or rather, all svm features that don't need save/restore support in userspace; I don't think any do, beyond svm itself)

I applied 2 and 3 (to branch uq/master). If you want to add more svm features, please send a patch. For patch 1, I'd like a review by someone who understands the compat code.

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

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

Quoted 11 lines · Avi Kivity
Quoted 10 lines · Avi Kivity
Quoted 5 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.

This should really be "all svm features" since we'll later mask them with kvm capabilities. This way, if we later add more capabilities, we automatically gain support in userspace.

Yes, that is what -cpu host does with these patches applied. The svm_features variable is set to -1 in this case and masked out later with the KVM capabilities.

Quoted 8 lines
Quoted 4 lines

(or rather, all svm features that don't need save/restore support in userspace; I don't think any do, beyond svm itself)

I applied 2 and 3 (to branch uq/master). If you want to add more svm features, please send a patch. For patch 1, I'd like a review by someone who understands the compat code.

Great, thanks.

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
#14 lore raw

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

Quoted 9 lines · Joerg
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 5 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 8 lines
Quoted 3 lines
Quoted 3 lines

This should really be "all svm features" since we'll later mask them with kvm capabilities. This way, if we later add more capabilities, we automatically gain support in userspace.

Yes, that is what -cpu host does with these patches applied. The svm_features variable is set to -1 in this case and masked out later with the KVM capabilities.

Well, running current uq/master I get:

has_svm: can't execute cpuid 0x8000000a
kvm: no hardware support

?

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

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

Quoted 19 lines · Avi Kivity
Quoted 9 lines · Joerg
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 5 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 8 lines
Quoted 3 lines
Quoted 3 lines

This should really be "all svm features" since we'll later mask them with kvm capabilities. This way, if we later add more capabilities, we automatically gain support in userspace.

Yes, that is what -cpu host does with these patches applied. The svm_features variable is set to -1 in this case and masked out later with the KVM capabilities.

Quoted 6 lines

Well, running current uq/master I get:

has_svm: can't execute cpuid 0x8000000a
kvm: no hardware support

?

Weird, it worked here as I tested it. I had it on qemu/master and with all three patches. But patch 1 should not make the difference. I take a look, have you pushed the failing uq/master? What was your command line?

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
#16 lore raw

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

Quoted 22 lines · Joerg
Quoted 21 lines · Avi Kivity
Quoted 9 lines · Joerg
Quoted 8 lines · Avi Kivity
    On 09/27/2010 04:58 PM, Avi Kivity wrote:
Quoted 7 lines · Joerg Roedel
Quoted 5 lines

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 8 lines
Quoted 3 lines
Quoted 3 lines

This should really be "all svm features" since we'll later mask them with kvm capabilities. This way, if we later add more capabilities, we automatically gain support in userspace.

Yes, that is what -cpu host does with these patches applied. The svm_features variable is set to -1 in this case and masked out later with the KVM capabilities.

Well, running current uq/master I get:

Quoted 8 lines
Quoted 4 lines

has_svm: can't execute cpuid 0x8000000a
kvm: no hardware support

?

Weird, it worked here as I tested it. I had it on qemu/master and with all three patches. But patch 1 should not make the difference. I take a look, have you pushed the failing uq/master?

Yes, 8fe6a21c76.

Quoted 1 line

What was your command line?

qemu-system-x86_64 -m 2G -cpu kvm64,+svm,+npt -enable-kvm ...

Note this is qemu.git, so -enable-kvm is needed.

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

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

Quoted 6 lines · Avi Kivity
Quoted 3 lines · Joerg

Weird, it worked here as I tested it. I had it on qemu/master and with all three patches. But patch 1 should not make the difference. I take a look, have you pushed the failing uq/master?

Quoted 7 lines

Yes, 8fe6a21c76.

Quoted 1 line

What was your command line?

qemu-system-x86_64 -m 2G -cpu kvm64,+svm,+npt -enable-kvm ...

Note this is qemu.git, so -enable-kvm is needed.

Ok, I apparently forgot to force the CPUID xlevel to be 0x8000000A when SVM is enabled, probably because I only tested CPUID models where xlevel already defaults to 0x8000000A. Attached is a fix, thanks for catching this.

Joerg

Quoted 1 line

From d18d973d037f1af1869e114aea1f076ea3a1ee7a Mon Sep 17 00:00:00 2001

From: Joerg Roedel <[email protected]>
Date: Tue, 28 Sep 2010 11:58:49 +0200
Subject: [PATCH 1/1] qemu: Force xlevel to at least 0x8000000A if SVM is enabled

This patch forces the extended CPUID level to be at least 0x8000000A if SVM is enabled in the CPU model.

---
 target-i386/cpuid.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
target-i386/cpuid.c +5 -0
index 0e0bf60..0630fe1 100644
@@ -714,6 +714,11 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
     x86_cpu_def->ext3_features &= ~minus_ext3_features;
     x86_cpu_def->kvm_features &= ~minus_kvm_features;
     x86_cpu_def->svm_features &= ~minus_svm_features;
+    if ((x86_cpu_def->ext3_features & CPUID_EXT3_SVM) &&
+        (x86_cpu_def->xlevel < 0x8000000A)) {
+        /* Force xlevel to at least 0x8000000A if SVM enabled */
+        x86_cpu_def->xlevel = 0x8000000A;
+    }
     if (check_cpuid) {
         if (check_features_against_host(x86_cpu_def) && enforce_cpuid)
             goto error;
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
#18 lore raw

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

Quoted 42 lines · Joerg
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Joerg

Weird, it worked here as I tested it. I had it on qemu/master and with all three patches. But patch 1 should not make the difference. I take a look, have you pushed the failing uq/master?

Quoted 7 lines

Yes, 8fe6a21c76.

Quoted 1 line

What was your command line?

qemu-system-x86_64 -m 2G -cpu kvm64,+svm,+npt -enable-kvm ...

Note this is qemu.git, so -enable-kvm is needed.

Ok, I apparently forgot to force the CPUID xlevel to be 0x8000000A when SVM is enabled, probably because I only tested CPUID models where xlevel already defaults to 0x8000000A. Attached is a fix, thanks for catching this.

Joerg

From d18d973d037f1af1869e114aea1f076ea3a1ee7a Mon Sep 17 00:00:00 2001
From: Joerg Roedel<[email protected]>
Date: Tue, 28 Sep 2010 11:58:49 +0200
Subject: [PATCH 1/1] qemu: Force xlevel to at least 0x8000000A if SVM is enabled

This patch forces the extended CPUID level to be at least 0x8000000A if SVM is enabled in the CPU model.

---
  target-i386/cpuid.c |    5 +++++
  1 files changed, 5 insertions(+), 0 deletions(-)
target-i386/cpuid.c +0 -0
index 0e0bf60..0630fe1 100644
@@ -714,6 +714,11 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
      x86_cpu_def->ext3_features&= ~minus_ext3_features;

target-i386/cpuid.c static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) · line 724

Quoted 10 lines
target-i386/cpuid.c +5 -0
      x86_cpu_def->kvm_features&= ~minus_kvm_features;
      x86_cpu_def->svm_features&= ~minus_svm_features;
+    if ((x86_cpu_def->ext3_features&  CPUID_EXT3_SVM)&&
+        (x86_cpu_def->xlevel<  0x8000000A)) {
+        /* Force xlevel to at least 0x8000000A if SVM enabled */
+        x86_cpu_def->xlevel = 0x8000000A;
+    }
      if (check_cpuid) {
          if (check_features_against_host(x86_cpu_def)&&  enforce_cpuid)
              goto error;

I can't say I like the interdependency, but saying something like -cpu kvm64,+svm,xlevel=0x8000000a is much worse.

If no one has a better idea, I'll apply the patch.

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

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

In reply to Roedel, Joerg
Quoted 13 lines · Joerg
Quoted 12 lines · Avi Kivity
Quoted 3 lines · Joerg

Weird, it worked here as I tested it. I had it on qemu/master and with all three patches. But patch 1 should not make the difference. I take a look, have you pushed the failing uq/master?

Yes, 8fe6a21c76.

Quoted 1 line

What was your command line?

qemu-system-x86_64 -m 2G -cpu kvm64,+svm,+npt -enable-kvm ...

Quoted 8 lines
Quoted 1 line

Note this is qemu.git, so -enable-kvm is needed.

Ok, I apparently forgot to force the CPUID xlevel to be 0x8000000A when SVM is enabled, probably because I only tested CPUID models where xlevel already defaults to 0x8000000A. Attached is a fix, thanks for catching this.

Joerg

Applied, thanks.