Skip to contentSkip to conversation

machine: Add kvm-type property

PATCH In review Eduardo Habkost 5 participants 7 messages May 30, 2014 – Jun 2, 2014 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 machine: Add kvm-type property

The kvm-type machine option was left out when MachineState was introduced, preventing the kvm-type option from being used. Add the missing property.

Cc Andreas Färber <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Marcel Apfelbaum <[email protected]>

---
Tested in a x86 machine only. Help would be welcome to test it on a PPC machine using -machine spapr and KVM.

Before this patch:

    $ qemu-system-x86_64 -machine pc,kvm-type=hv,accel=kvm
    qemu-system-x86_64: Property '.kvm-type' not found

(This means the option won't work even for sPAPR machines.)

After applying this patch:

    $ qemu-system-x86_64 -machine pc,kvm-type=hv,accel=kvm
    Invalid argument kvm-type=hv

(This means the x86 KVM init code is seeing (and rejecting) the option, and the sPAPR code can use it.)

Note that qemu-system-x86_64 will segfault with the above command-line unless an additional fix (submitted today) is applied (kvm: Ensure negative return value on kvm_init() error handling path).

---
 hw/core/machine.c   | 17 +++++++++++++++++
 include/hw/boards.h |  1 +
 2 files changed, 18 insertions(+)
hw/core/machine.c +17 -0
index cbba679..ed47b3a 100644
@@ -235,6 +235,21 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)
     ms->firmware = g_strdup(value);
 }
 
+static char *machine_get_kvm_type(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->kvm_type);
+}
+
+static void machine_set_kvm_type(Object *obj, const char *value, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->kvm_type);
+    ms->kvm_type = g_strdup(value);
+}
+
 static void machine_initfn(Object *obj)
 {
     object_property_add_str(obj, "accel",
@@ -274,6 +289,8 @@ static void machine_initfn(Object *obj)
     object_property_add_bool(obj, "usb", machine_get_usb, machine_set_usb, NULL);
     object_property_add_str(obj, "firmware",
                             machine_get_firmware, machine_set_firmware, NULL);
+    object_property_add_str(obj, "kvm-type",
+                            machine_get_kvm_type, machine_set_kvm_type, NULL);
 }
 
 static void machine_finalize(Object *obj)
include/hw/boards.h +1 -0
index 2d2e2be..44956d6 100644
@@ -111,6 +111,7 @@ struct MachineState {
     bool mem_merge;
     bool usb;
     char *firmware;
+    char *kvm_type;
 
     ram_addr_t ram_size;
     const char *boot_order;
Signature · 1 line
1.9.0
maintainer
#1 lore raw

Il 30/05/2014 22:41, Eduardo Habkost ha scritto:

include/hw/boards.h struct MachineState { · line 117

Quoted 13 lines
include/hw/boards.h +1 -0
index 2d2e2be..44956d6 100644
@@ -111,6 +111,7 @@ struct MachineState {
     bool mem_merge;
     bool usb;
     char *firmware;
+    char *kvm_type;
 
     ram_addr_t ram_size;
     const char *boot_order;

Can you add it only to the pseries machine instead? This is one of the first reasons why I wanted to have per-machine properties. :)

Thanks!

Paolo

#2 lore raw
Quoted 11 lines · Paolo Bonzini

Il 30/05/2014 22:41, Eduardo Habkost ha scritto:

Quoted 10 lines
include/hw/boards.h +1 -0
index 2d2e2be..44956d6 100644
@@ -111,6 +111,7 @@ struct MachineState {
    bool mem_merge;
    bool usb;
    char *firmware;
+    char *kvm_type;
 
Quoted 6 lines

include/hw/boards.h struct MachineState { · line 117

Quoted 3 lines
include/hw/boards.h +0 -0
    ram_addr_t ram_size;
    const char *boot_order;

Can you add it only to the pseries machine instead? This is one of the first reasons why I wanted to have per-machine properties. :)

Yes, it makes sense (I didn't notice we already had explicit class registration code for sPAPR). I might need some help to test it, though.

Signature · 1 line
Eduardo
#3 lore raw
Quoted 16 lines

Am 30.05.2014 um 22:57 schrieb Eduardo Habkost <[email protected]>:

Quoted 12 lines · Paolo Bonzini

Il 30/05/2014 22:41, Eduardo Habkost ha scritto:

Quoted 10 lines
include/hw/boards.h +1 -0
index 2d2e2be..44956d6 100644
@@ -111,6 +111,7 @@ struct MachineState {
   bool mem_merge;
   bool usb;
   char *firmware;
+    char *kvm_type;
 
Quoted 8 lines
Quoted 5 lines

include/hw/boards.h struct MachineState { · line 117

Quoted 2 lines
include/hw/boards.h +0 -0
   ram_addr_t ram_size;
   const char *boot_order;

Can you add it only to the pseries machine instead? This is one of the first reasons why I wanted to have per-machine properties. :)

Yes, it makes sense (I didn't notice we already had explicit class registration code for sPAPR). I might need some help to test it, though.

That part should be easy ;)

Alex

Quoted 3 lines
Signature · 2 lines
-- 
Eduardo
#4 lore raw
In reply to Eduardo Habkost
Quoted 3 lines · Eduardo Habkost

The kvm-type machine option was left out when MachineState was introduced, preventing the kvm-type option from being used. Add the missing property.

Very interesting how did I miss that.
Thanks!
Marcel

Quoted 80 lines
Cc Andreas Färber <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Marcel Apfelbaum <[email protected]>

---
Tested in a x86 machine only. Help would be welcome to test it on a PPC machine using -machine spapr and KVM.

Before this patch:

    $ qemu-system-x86_64 -machine pc,kvm-type=hv,accel=kvm
    qemu-system-x86_64: Property '.kvm-type' not found

(This means the option won't work even for sPAPR machines.)

After applying this patch:

    $ qemu-system-x86_64 -machine pc,kvm-type=hv,accel=kvm
    Invalid argument kvm-type=hv

(This means the x86 KVM init code is seeing (and rejecting) the option, and the sPAPR code can use it.)

Note that qemu-system-x86_64 will segfault with the above command-line unless an additional fix (submitted today) is applied (kvm: Ensure negative return value on kvm_init() error handling path).

---
 hw/core/machine.c   | 17 +++++++++++++++++
 include/hw/boards.h |  1 +
 2 files changed, 18 insertions(+)
hw/core/machine.c +17 -0
index cbba679..ed47b3a 100644
@@ -235,6 +235,21 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)
     ms->firmware = g_strdup(value);
 }
 
+static char *machine_get_kvm_type(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->kvm_type);
+}
+
+static void machine_set_kvm_type(Object *obj, const char *value, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->kvm_type);
+    ms->kvm_type = g_strdup(value);
+}
+
 static void machine_initfn(Object *obj)
 {
     object_property_add_str(obj, "accel",
@@ -274,6 +289,8 @@ static void machine_initfn(Object *obj)
     object_property_add_bool(obj, "usb", machine_get_usb, machine_set_usb, NULL);
     object_property_add_str(obj, "firmware",
                             machine_get_firmware, machine_set_firmware, NULL);
+    object_property_add_str(obj, "kvm-type",
+                            machine_get_kvm_type, machine_set_kvm_type, NULL);
 }
 
 static void machine_finalize(Object *obj)
include/hw/boards.h +1 -0
index 2d2e2be..44956d6 100644
@@ -111,6 +111,7 @@ struct MachineState {
     bool mem_merge;
     bool usb;
     char *firmware;
+    char *kvm_type;
 
     ram_addr_t ram_size;
     const char *boot_order;
#5 lore raw
Quoted 49 lines · Marcel Apfelbaum
Quoted 3 lines · Eduardo Habkost

The kvm-type machine option was left out when MachineState was introduced, preventing the kvm-type option from being used. Add the missing property.

Very interesting how did I miss that.
Thanks!
Marcel

Quoted 41 lines
Cc Andreas Färber <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Marcel Apfelbaum <[email protected]>

---
Tested in a x86 machine only. Help would be welcome to test it on a PPC machine using -machine spapr and KVM.

Before this patch:

    $ qemu-system-x86_64 -machine pc,kvm-type=hv,accel=kvm
    qemu-system-x86_64: Property '.kvm-type' not found

(This means the option won't work even for sPAPR machines.)

After applying this patch:

    $ qemu-system-x86_64 -machine pc,kvm-type=hv,accel=kvm
    Invalid argument kvm-type=hv

(This means the x86 KVM init code is seeing (and rejecting) the option, and the sPAPR code can use it.)

Note that qemu-system-x86_64 will segfault with the above command-line unless an additional fix (submitted today) is applied (kvm: Ensure negative return value on kvm_init() error handling path).

---
 hw/core/machine.c   | 17 +++++++++++++++++
 include/hw/boards.h |  1 +
 2 files changed, 18 insertions(+)
hw/core/machine.c +0 -0
index cbba679..ed47b3a 100644
@@ -235,6 +235,21 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)
     ms->firmware = g_strdup(value);
 }
 
Quoted 12 lines

hw/core/machine.c static void machine_set_firmware(Object *obj, const char *value, Error **errp) · line 249

Quoted 12 lines
hw/core/machine.c +12 -0
+static char *machine_get_kvm_type(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->kvm_type);
+}
+
+static void machine_set_kvm_type(Object *obj, const char *value, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->kvm_type);

Hi,

Here also, like in my other replies, I think it should be the caller responsibility to free the string. A set method should not touch its parameter.

Thanks,
Marcel

Quoted 31 lines
Quoted 27 lines
hw/core/machine.c +5 -0
+    ms->kvm_type = g_strdup(value);
+}
+
 static void machine_initfn(Object *obj)
 {
     object_property_add_str(obj, "accel",
@@ -274,6 +289,8 @@ static void machine_initfn(Object *obj)
     object_property_add_bool(obj, "usb", machine_get_usb, machine_set_usb, NULL);
     object_property_add_str(obj, "firmware",
                             machine_get_firmware, machine_set_firmware, NULL);
+    object_property_add_str(obj, "kvm-type",
+                            machine_get_kvm_type, machine_set_kvm_type, NULL);
 }
 
 static void machine_finalize(Object *obj)
include/hw/boards.h +1 -0
index 2d2e2be..44956d6 100644
@@ -111,6 +111,7 @@ struct MachineState {
     bool mem_merge;
     bool usb;
     char *firmware;
+    char *kvm_type;
 
     ram_addr_t ram_size;
     const char *boot_order;
#6 lore raw
Quoted 64 lines · Marcel Apfelbaum
Quoted 49 lines · Marcel Apfelbaum
Quoted 3 lines · Eduardo Habkost

The kvm-type machine option was left out when MachineState was introduced, preventing the kvm-type option from being used. Add the missing property.

Very interesting how did I miss that.
Thanks!
Marcel

Quoted 41 lines
Cc Andreas Färber <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Marcel Apfelbaum <[email protected]>

---
Tested in a x86 machine only. Help would be welcome to test it on a PPC machine using -machine spapr and KVM.

Before this patch:

    $ qemu-system-x86_64 -machine pc,kvm-type=hv,accel=kvm
    qemu-system-x86_64: Property '.kvm-type' not found

(This means the option won't work even for sPAPR machines.)

After applying this patch:

    $ qemu-system-x86_64 -machine pc,kvm-type=hv,accel=kvm
    Invalid argument kvm-type=hv

(This means the x86 KVM init code is seeing (and rejecting) the option, and the sPAPR code can use it.)

Note that qemu-system-x86_64 will segfault with the above command-line unless an additional fix (submitted today) is applied (kvm: Ensure negative return value on kvm_init() error handling path).

---
 hw/core/machine.c   | 17 +++++++++++++++++
 include/hw/boards.h |  1 +
 2 files changed, 18 insertions(+)
hw/core/machine.c +0 -0
index cbba679..ed47b3a 100644
@@ -235,6 +235,21 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)
     ms->firmware = g_strdup(value);
 }
 
Quoted 12 lines

hw/core/machine.c static void machine_set_firmware(Object *obj, const char *value, Error **errp) · line 249

Quoted 12 lines
hw/core/machine.c +12 -0
+static char *machine_get_kvm_type(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->kvm_type);
+}
+
+static void machine_set_kvm_type(Object *obj, const char *value, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->kvm_type);

Hi,

Quoted 3 lines

Here also, like in my other replies, I think it should be the caller responsibility to free the string. A set method should not touch its parameter.

We are not freeing the parameter, we are freeing ms->kvm_type, which was allocated previously by the setter method itself (using g_strdup()). The caller doesn't even have access to ms->kvm_type directly.

The fact that ms->kvm_type is a strdup()ed string is an internal implementation detail. We even have setter methods that do _not_ use strdup(), and just copy the data to a static buffer (see target-i386/cpu.c).

Signature · 1 line
Eduardo