Skip to contentSkip to conversation

Don't require hw_version to be set on every machine

PATCH In review Eduardo Habkost 2 participants 5 messages Nov 12, 2015 – Nov 23, 2015

lore
Share & tools
lore
#0 lore raw

cover Don't require hw_version to be set on every machine

This changes the qemu_hw_version() default to "2.5+" so we don't make every machine class broken by default unless they set hw_version.

For reference, these are the current users of qemu_hw_version():

hw/arm/nseries.c:    pstrcat((void *) w, 12, qemu_hw_version()); /* char version[12] */
hw/ide/core.c:        pstrcpy(s->version, sizeof(s->version), qemu_hw_version());
hw/scsi/megasas.c:    snprintf(info.package_version, 0x60, "%s-QEMU", qemu_hw_version());
hw/scsi/scsi-bus.c:        pstrcpy((char *) &r->buf[32], 4, qemu_hw_version());
hw/scsi/scsi-disk.c:        s->version = g_strdup(qemu_hw_version());
target-i386/cpu.c:                        qemu_hw_version());
Cc Andrzej Zaborowski <[email protected]>
Cc John Snow <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Richard Henderson <[email protected]>

Eduardo Habkost (2):
osdep: Change default value of qemu_hw_version() to "2.5+"
pc: Don't set hw_version on pc-*-2.5

 hw/i386/pc_piix.c    | 1 -
 hw/i386/pc_q35.c     | 1 -
 include/hw/boards.h  | 5 +++++
 include/qemu/osdep.h | 4 ++++
 util/osdep.c         | 9 ++++++++-
 5 files changed, 17 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/2 osdep: Change default value of qemu_hw_version() to "2.5+"

There are two issues with qemu_hw_version() today:

1) If a machine has hw_version set, the value returned by it is not very useful, because it is not the actual QEMU version.
2) If a machine does't set hw_version, the return value of qemu_hw_version() is broken, because it will change when upgrading QEMU.

For those reasons, using qemu_hw_version() is strongly discouraged, and should be used only in code that used QEMU_VERSION in the past and needs to keep compatibility.

To fix (2), instead of making every machine broken by default unless they set hw_version, make qemu_hw_version() simply return "2.5+" if qemu_set_hw_version() is not called.

---
 include/hw/boards.h  | 5 +++++
 include/qemu/osdep.h | 4 ++++
 util/osdep.c         | 9 ++++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)
include/hw/boards.h +5 -0
index 3e9a92c..51906af 100644
@@ -52,6 +52,11 @@ bool machine_mem_merge(MachineState *machine);
  *    used to provide @cpu_index to socket number mapping, allowing
  *    a machine to group CPU threads belonging to the same socket/package
  *    Returns: socket number given cpu_index belongs to.
+ * @hw_version:
+ *    Value of QEMU_VERSION when the machine was added to QEMU.
+ *    Set only by old machines because they need to keep
+ *    compatibility on code that exposed QEMU_VERSION to guests in
+ *    the past (and now use qemu_hw_version()).
  */
 struct MachineClass {
     /*< private >*/
include/qemu/osdep.h +4 -0
index 861d84b..84e84ac 100644
@@ -256,6 +256,10 @@ static inline void qemu_timersub(const struct timeval *val1,
 
 void qemu_set_cloexec(int fd);
 
+/* QEMU "hardware version" setting. Used to replace code that exposed
+ * QEMU_VERSION to guests in the past and need to keep compatibilty.
+ * Do not use qemu_hw_version() in new code.
+ */
 void qemu_set_hw_version(const char *);
 const char *qemu_hw_version(void);
 
util/osdep.c +8 -1
index 80c6bfe..534b511 100644
@@ -52,7 +52,14 @@ extern int madvise(caddr_t, size_t, int);
 
 static bool fips_enabled = false;
 
-static const char *hw_version = QEMU_VERSION;
+/* Starting on QEMU 2.5, qemu_hw_version() returns "2.5+" by default
+ * instead of QEMU_VERSION, so setting hw_version on MachineClass
+ * is no longer mandatory.
+ *
+ * Do NOT change this string, or it will break compatibility on all
+ * machine classes that don't set hw_version.
+ */
+static const char *hw_version = "2.5+";
 
 int socket_set_cork(int fd, int v)
 {
Signature · 1 line
2.1.0
#2 lore raw

PATCH 2/2 pc: Don't set hw_version on pc-*-2.5

In reply to Eduardo Habkost

Now that qemu_hw_version() returns a fixed "2.5+" string instead of QEMU_VERSION, we don't need to set hw_version on pc-*-2.5 explicitly.

---
 hw/i386/pc_piix.c | 1 -
 hw/i386/pc_q35.c  | 1 -
 2 files changed, 2 deletions(-)
hw/i386/pc_piix.c +0 -1
index 07d0baa..2e41efe 100644
@@ -472,7 +472,6 @@ static void pc_i440fx_machine_options(MachineClass *m)
 static void pc_i440fx_2_5_machine_options(MachineClass *m)
 {
     pc_i440fx_machine_options(m);
-    m->hw_version = QEMU_VERSION;
     m->alias = "pc";
     m->is_default = 1;
 }
hw/i386/pc_q35.c +0 -1
index 0fdae09..133bc68 100644
@@ -373,7 +373,6 @@ static void pc_q35_machine_options(MachineClass *m)
 static void pc_q35_2_5_machine_options(MachineClass *m)
 {
     pc_q35_machine_options(m);
-    m->hw_version = QEMU_VERSION;
     m->alias = "q35";
 }
 
Signature · 1 line
2.1.0
#3 lore raw
In reply to Eduardo Habkost

Ping? Any thoughts on this approach?

-rc2 is too late for this kind of change, maybe?

Quoted 34 lines · Eduardo Habkost

This changes the qemu_hw_version() default to "2.5+" so we don't make every machine class broken by default unless they set hw_version.

For reference, these are the current users of qemu_hw_version():

hw/arm/nseries.c:    pstrcat((void *) w, 12, qemu_hw_version()); /* char version[12] */
hw/ide/core.c:        pstrcpy(s->version, sizeof(s->version), qemu_hw_version());
hw/scsi/megasas.c:    snprintf(info.package_version, 0x60, "%s-QEMU", qemu_hw_version());
hw/scsi/scsi-bus.c:        pstrcpy((char *) &r->buf[32], 4, qemu_hw_version());
hw/scsi/scsi-disk.c:        s->version = g_strdup(qemu_hw_version());
target-i386/cpu.c:                        qemu_hw_version());
Cc Andrzej Zaborowski <[email protected]>
Cc John Snow <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Richard Henderson <[email protected]>

Eduardo Habkost (2):
osdep: Change default value of qemu_hw_version() to "2.5+"
pc: Don't set hw_version on pc-*-2.5

 hw/i386/pc_piix.c    | 1 -
 hw/i386/pc_q35.c     | 1 -
 include/hw/boards.h  | 5 +++++
 include/qemu/osdep.h | 4 ++++
 util/osdep.c         | 9 ++++++++-
 5 files changed, 17 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
Signature · 1 line
Eduardo
#4 lore raw
Quoted 5 lines · Eduardo Habkost

Ping? Any thoughts on this approach?

-rc2 is too late for this kind of change, maybe?

I queued this up for 2.5, will merge later this week unless anyone objects.

Quoted 38 lines · Eduardo Habkost
Quoted 34 lines

This changes the qemu_hw_version() default to "2.5+" so we don't make every machine class broken by default unless they set hw_version.

For reference, these are the current users of qemu_hw_version():

hw/arm/nseries.c:    pstrcat((void *) w, 12, qemu_hw_version()); /* char version[12] */
hw/ide/core.c:        pstrcpy(s->version, sizeof(s->version), qemu_hw_version());
hw/scsi/megasas.c:    snprintf(info.package_version, 0x60, "%s-QEMU", qemu_hw_version());
hw/scsi/scsi-bus.c:        pstrcpy((char *) &r->buf[32], 4, qemu_hw_version());
hw/scsi/scsi-disk.c:        s->version = g_strdup(qemu_hw_version());
target-i386/cpu.c:                        qemu_hw_version());
Cc Andrzej Zaborowski <[email protected]>
Cc John Snow <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Richard Henderson <[email protected]>

Eduardo Habkost (2):
osdep: Change default value of qemu_hw_version() to "2.5+"
pc: Don't set hw_version on pc-*-2.5

 hw/i386/pc_piix.c    | 1 -
 hw/i386/pc_q35.c     | 1 -
 include/hw/boards.h  | 5 +++++
 include/qemu/osdep.h | 4 ++++
 util/osdep.c         | 9 ++++++++-
 5 files changed, 17 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
Signature · 1 line
Eduardo