Skip to contentSkip to conversation

Trivial patches for 5 to 11 January 2013

GIT PULL In review Stefan Hajnoczi 4 participants 12 messages Jan 11, 2013 Block layer

lore
Share & tools
lore
#0 lore raw

The following changes since commit 8e4a424b305e29dc0e454f52df3b35577f342975:

Revert "virtio-pci: replace byte swap hack" (2013-01-06 18:30:17 +0000)

are available in the git repository at:

git://github.com/stefanha/qemu.git trivial-patches

for you to fetch changes up to c02e1eac887b1b0aee7361b1fcf889e7d47fed9d:

hw/pc.c: Fix converting of ioport_register* to MemoryRegion (2013-01-11 09:49:44 +0100)

----------------------------------------------------------------
Julien Grall (1):
hw/pc.c: Fix converting of ioport_register* to MemoryRegion

Nickolai Zeldovich (1):
readline: avoid memcpy() of overlapping regions

Peter Maydell (1):
qga/channel-posix.c: Explicitly include string.h

Stefan Weil (3):
configure: Fix comment (copy+paste bug)
savevm: Remove MinGW specific code which is no longer needed Replace remaining gmtime, localtime by gmtime_r, localtime_r

 block.c             | 10 ----------
 block/vvfat.c       |  4 ----
 configure           |  2 +-
 hw/omap1.c          |  2 +-
 hw/pc.c             | 12 ++++++++++++
 qga/channel-posix.c |  1 +
 readline.c          |  4 ++--
 savevm.c            | 30 ++----------------------------
 vl.c                |  9 +++------
 9 files changed, 22 insertions(+), 52 deletions(-)
Signature · 1 line
1.8.0.2
#1 lore raw

PATCH 1/6 readline: avoid memcpy() of overlapping regions

From: Nickolai Zeldovich <[email protected]>

memcpy() for overlapping regions is undefined behavior; use memmove() instead in readline_hist_add().

[Keep tab characters since surrounding code still uses them -- Stefan]

---
 readline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
readline.c +2 -2
index 5fc9643..a0c9638 100644
@@ -248,8 +248,8 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
     if (idx == READLINE_MAX_CMDS) {
 	/* Need to get one free slot */
 	free(rs->history[0]);
-	memcpy(rs->history, &rs->history[1],
-	       (READLINE_MAX_CMDS - 1) * sizeof(char *));
+	memmove(rs->history, &rs->history[1],
+	        (READLINE_MAX_CMDS - 1) * sizeof(char *));
 	rs->history[READLINE_MAX_CMDS - 1] = NULL;
 	idx = READLINE_MAX_CMDS - 1;
     }
Signature · 1 line
1.8.0.2
#2 lore raw

PATCH 2/6 configure: Fix comment (copy+paste bug)

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -1
index fe18ed2..148d5aa 100755
@@ -2705,7 +2705,7 @@ if compile_prog "" "" ; then
   byteswap_h=yes
 fi
 
-# Search for bswap_32 function
+# Search for bswap32 function
 bswap_h=no
 cat > $TMPC << EOF
 #include <sys/endian.h>
Signature · 1 line
1.8.0.2
#3 lore raw

PATCH 3/6 qga/channel-posix.c: Explicitly include string.h

In reply to Stefan Hajnoczi

From: Peter Maydell <[email protected]>

Explicitly include string.h to avoid warnings under MacOS X/clang about implicit declarations of strerror() and strlen().

---
 qga/channel-posix.c | 1 +
 1 file changed, 1 insertion(+)
qga/channel-posix.c +1 -0
index d4fd628..ca9e4aa 100644
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdlib.h>
+#include <string.h>
 #include "qemu/osdep.h"
 #include "qemu/sockets.h"
 #include "qga/channel.h"
Signature · 1 line
1.8.0.2
#4 lore raw

PATCH 4/6 savevm: Remove MinGW specific code which is no longer needed

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

QEMU provides a portable function qemu_gettimeofday instead of gettimeofday and also an implementation of localtime_r for MinGW.

---
 savevm.c | 30 ++----------------------------
 1 file changed, 2 insertions(+), 28 deletions(-)
savevm.c +2 -28
index 529d60e..4e970ca 100644
@@ -23,15 +23,6 @@
  */
 
 #include "config-host.h"
-
-#ifndef _WIN32
-#include <arpa/inet.h>
-#endif
-
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
 #include "qemu-common.h"
 #include "hw/hw.h"
 #include "hw/qdev.h"
@@ -2093,13 +2084,8 @@ void do_savevm(Monitor *mon, const QDict *qdict)
     QEMUFile *f;
     int saved_vm_running;
     uint64_t vm_state_size;
-#ifdef _WIN32
-    struct _timeb tb;
-    struct tm *ptm;
-#else
-    struct timeval tv;
+    qemu_timeval tv;
     struct tm tm;
-#endif
     const char *name = qdict_get_try_str(qdict, "name");
 
     /* Verify if there is a device that doesn't support snapshots and is writable */
@@ -2129,15 +2115,9 @@ void do_savevm(Monitor *mon, const QDict *qdict)
     memset(sn, 0, sizeof(*sn));
 
     /* fill auxiliary fields */
-#ifdef _WIN32
-    _ftime(&tb);
-    sn->date_sec = tb.time;
-    sn->date_nsec = tb.millitm * 1000000;
-#else
-    gettimeofday(&tv, NULL);
+    qemu_gettimeofday(&tv);
     sn->date_sec = tv.tv_sec;
     sn->date_nsec = tv.tv_usec * 1000;
-#endif
     sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock);
 
     if (name) {
@@ -2149,15 +2129,9 @@ void do_savevm(Monitor *mon, const QDict *qdict)
             pstrcpy(sn->name, sizeof(sn->name), name);
         }
     } else {
-#ifdef _WIN32
-        time_t t = tb.time;
-        ptm = localtime(&t);
-        strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", ptm);
-#else
         /* cast below needed for OpenBSD where tv_sec is still 'long' */
         localtime_r((const time_t *)&tv.tv_sec, &tm);
         strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
-#endif
     }
 
     /* Delete old snapshots of the same name */
Signature · 1 line
1.8.0.2
#5 lore raw

PATCH 5/6 Replace remaining gmtime, localtime by gmtime_r, localtime_r

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

This allows removing of MinGW specific code and improves reentrancy for POSIX hosts.

[Removed unused ret variable in qemu_get_timedate() to fix warning:
vl.c: In function ‘qemu_get_timedate’:
vl.c:451:16: error: variable ‘ret’ set but not used [-Werror=unused-but-set-variable] -- Stefan Hajnoczi]

---
 block.c       | 10 ----------
 block/vvfat.c |  4 ----
 hw/omap1.c    |  2 +-
 vl.c          |  9 +++------
 4 files changed, 4 insertions(+), 21 deletions(-)
block.c +0 -10
index 4e28c55..60873ea 100644
@@ -3338,11 +3338,7 @@ char *get_human_readable_size(char *buf, int buf_size, int64_t size)
 char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
 {
     char buf1[128], date_buf[128], clock_buf[128];
-#ifdef _WIN32
-    struct tm *ptm;
-#else
     struct tm tm;
-#endif
     time_t ti;
     int64_t secs;
 
@@ -3352,15 +3348,9 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
                  "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
     } else {
         ti = sn->date_sec;
-#ifdef _WIN32
-        ptm = localtime(&ti);
-        strftime(date_buf, sizeof(date_buf),
-                 "%Y-%m-%d %H:%M:%S", ptm);
-#else
         localtime_r(&ti, &tm);
         strftime(date_buf, sizeof(date_buf),
                  "%Y-%m-%d %H:%M:%S", &tm);
-#endif
         secs = sn->vm_clock_nsec / 1000000000;
         snprintf(clock_buf, sizeof(clock_buf),
                  "%02d:%02d:%02d.%03d",
block/vvfat.c +0 -4
index 83706ce..06e6654 100644
@@ -529,13 +529,9 @@ static inline uint8_t fat_chksum(const direntry_t* entry)
 /* if return_time==0, this returns the fat_date, else the fat_time */
 static uint16_t fat_datetime(time_t time,int return_time) {
     struct tm* t;
-#ifdef _WIN32
-    t=localtime(&time); /* this is not thread safe */
-#else
     struct tm t1;
     t = &t1;
     localtime_r(&time,t);
-#endif
     if(return_time)
 	return cpu_to_le16((t->tm_sec/2)|(t->tm_min<<5)|(t->tm_hour<<11));
     return cpu_to_le16((t->tm_mday)|((t->tm_mon+1)<<5)|((t->tm_year-80)<<9));
hw/omap1.c +1 -1
index 8536e96..e85f2e2 100644
@@ -2830,7 +2830,7 @@ static void omap_rtc_tick(void *opaque)
         s->round = 0;
     }
 
-    memcpy(&s->current_tm, localtime(&s->ti), sizeof(s->current_tm));
+    localtime_r(&s->ti, &s->current_tm);
 
     if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) {
         s->status |= 0x40;
vl.c +3 -6
index f056c95..aed4182 100644
@@ -448,21 +448,18 @@ StatusInfo *qmp_query_status(Error **errp)
 void qemu_get_timedate(struct tm *tm, int offset)
 {
     time_t ti;
-    struct tm *ret;
 
     time(&ti);
     ti += offset;
     if (rtc_date_offset == -1) {
         if (rtc_utc)
-            ret = gmtime(&ti);
+            gmtime_r(&ti, tm);
         else
-            ret = localtime(&ti);
+            localtime_r(&ti, tm);
     } else {
         ti -= rtc_date_offset;
-        ret = gmtime(&ti);
+        gmtime_r(&ti, tm);
     }
-
-    memcpy(tm, ret, sizeof(struct tm));
 }
 
 int qemu_timedate_diff(struct tm *tm)
Signature · 1 line
1.8.0.2
#6 lore raw

PATCH 6/6 hw/pc.c: Fix converting of ioport_register* to MemoryRegion

In reply to Stefan Hajnoczi

From: Julien Grall <[email protected]>

The commit 258711 introduced MemoryRegion to replace ioport_region* for ioport 80h and F0h.
A MemoryRegion needs to have both read and write callback otherwise a segfault will occur when an access is made.

The previous behaviour of this both ioport is to return 0xffffffffffffffff. So keep this behaviour.

---
 hw/pc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/pc.c +12 -0
index df0c48e..90b1bf7 100644
@@ -103,6 +103,11 @@ static void ioport80_write(void *opaque, hwaddr addr, uint64_t data,
 {
 }
 
+static uint64_t ioport80_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffff;
+}
+
 /* MSDOS compatibility mode FPU exception support */
 static qemu_irq ferr_irq;
 
@@ -123,6 +128,11 @@ static void ioportF0_write(void *opaque, hwaddr addr, uint64_t data,
     qemu_irq_lower(ferr_irq);
 }
 
+static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffff;
+}
+
 /* TSC handling */
 uint64_t cpu_get_tsc(CPUX86State *env)
 {
@@ -960,6 +970,7 @@ static void cpu_request_exit(void *opaque, int irq, int level)
 
 static const MemoryRegionOps ioport80_io_ops = {
     .write = ioport80_write,
+    .read = ioport80_read,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
@@ -969,6 +980,7 @@ static const MemoryRegionOps ioport80_io_ops = {
 
 static const MemoryRegionOps ioportF0_io_ops = {
     .write = ioportF0_write,
+    .read = ioportF0_read,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
Signature · 1 line
1.8.0.2
#7 lore raw

Re: [Qemu-devel] [PATCH 6/6] hw/pc.c: Fix converting of ioport_register* to MemoryRegion

Am 11.01.2013 10:18, schrieb Stefan Hajnoczi:

Quoted 23 lines

From: Julien Grall <[email protected]>

The commit 258711 introduced MemoryRegion to replace ioport_region* for ioport 80h and F0h.
A MemoryRegion needs to have both read and write callback otherwise a segfault will occur when an access is made.

The previous behaviour of this both ioport is to return 0xffffffffffffffff. So keep this behaviour.

---
 hw/pc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/pc.c +0 -0
index df0c48e..90b1bf7 100644

hw/pc.c static void ioport80_write(void *opaque, hwaddr addr, uint64_t data, · line 108

Quoted 6 lines
hw/pc.c +3 -0
@@ -103,6 +103,11 @@ static void ioport80_write(void *opaque, hwaddr addr, uint64_t data,
 {
 }
 
+static uint64_t ioport80_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffff;

Might these require ULL for i386?

Andreas

Quoted 33 lines
hw/pc.c +9 -0
+}
+
 /* MSDOS compatibility mode FPU exception support */
 static qemu_irq ferr_irq;
 
@@ -123,6 +128,11 @@ static void ioportF0_write(void *opaque, hwaddr addr, uint64_t data,
     qemu_irq_lower(ferr_irq);
 }
 
+static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffff;
+}
+
 /* TSC handling */
 uint64_t cpu_get_tsc(CPUX86State *env)
 {
@@ -960,6 +970,7 @@ static void cpu_request_exit(void *opaque, int irq, int level)
 
 static const MemoryRegionOps ioport80_io_ops = {
     .write = ioport80_write,
+    .read = ioport80_read,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
@@ -969,6 +980,7 @@ static const MemoryRegionOps ioport80_io_ops = {
 
 static const MemoryRegionOps ioportF0_io_ops = {
     .write = ioportF0_write,
+    .read = ioportF0_read,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#8 lore raw

Re: [Qemu-devel] [PATCH 6/6] hw/pc.c: Fix converting of ioport_register* to MemoryRegion

Quoted 27 lines · Andreas Färber

Am 11.01.2013 10:18, schrieb Stefan Hajnoczi:

Quoted 26 lines

From: Julien Grall <[email protected]>

The commit 258711 introduced MemoryRegion to replace ioport_region* for ioport 80h and F0h.
A MemoryRegion needs to have both read and write callback otherwise a segfault will occur when an access is made.

The previous behaviour of this both ioport is to return 0xffffffffffffffff. So keep this behaviour.

---
 hw/pc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/pc.c +0 -0
index df0c48e..90b1bf7 100644
@@ -103,6 +103,11 @@ static void ioport80_write(void *opaque, hwaddr addr, uint64_t data,
 {
 }
 
Quoted 5 lines

hw/pc.c static void ioport80_write(void *opaque, hwaddr addr, uint64_t data, · line 108

Quoted 3 lines
hw/pc.c +3 -0
+static uint64_t ioport80_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffff;

Might these require ULL for i386?

Indeed. I will resend a patch with ULL for ioport80_read and ioportF0_read.

Quoted 36 lines
Quoted 35 lines
hw/pc.c +9 -0
+}
+
 /* MSDOS compatibility mode FPU exception support */
 static qemu_irq ferr_irq;
 
@@ -123,6 +128,11 @@ static void ioportF0_write(void *opaque, hwaddr addr, uint64_t data,
     qemu_irq_lower(ferr_irq);
 }
 
+static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffff;
+}
+
 /* TSC handling */
 uint64_t cpu_get_tsc(CPUX86State *env)
 {
@@ -960,6 +970,7 @@ static void cpu_request_exit(void *opaque, int irq, int level)
 
 static const MemoryRegionOps ioport80_io_ops = {
     .write = ioport80_write,
+    .read = ioport80_read,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
@@ -969,6 +980,7 @@ static const MemoryRegionOps ioport80_io_ops = {
 
 static const MemoryRegionOps ioportF0_io_ops = {
     .write = ioportF0_write,
+    .read = ioportF0_read,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
Signature · 1 line
Julien
#9 lore raw

Re: [Qemu-devel] [PATCH 6/6] hw/pc.c: Fix converting of ioport_register* to MemoryRegion

Am 11.01.2013 15:53, schrieb Julien Grall:

Quoted 6 lines · Andreas Färber
Quoted 5 lines

Am 11.01.2013 10:18, schrieb Stefan Hajnoczi:

Quoted 4 lines
(quoted diff) +0 -0
@@ -103,6 +103,11 @@ static void ioport80_write(void *opaque, hwaddr addr, uint64_t data,
 {
 }
 
Quoted 7 lines
Quoted 5 lines

hw/pc.c static void ioport80_write(void *opaque, hwaddr addr, uint64_t data, · line 108

Quoted 3 lines
hw/pc.c +3 -0
+static uint64_t ioport80_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffff;

Might these require ULL for i386?

Indeed. I will resend a patch with ULL for ioport80_read and ioportF0_read.

Since this patch is already in a pull and Anthony indicated it is being processed, can you fix this as a follow-up patch instead?

Thanks,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Tested-by Adam Lackorzynski on v1 6/6
#10 lore raw

Re: [Qemu-devel] [PATCH 6/6] hw/pc.c: Fix converting of ioport_register* to MemoryRegion

In reply to Stefan Hajnoczi

From: Julien Grall <[email protected]>

The commit 258711 introduced MemoryRegion to replace ioport_region* for ioport 80h and F0h.
A MemoryRegion needs to have both read and write callback otherwise a segfault will occur when an access is made.

The previous behaviour of this both ioport is to return 0xffffffffffffffff. So keep this behaviour.

---
 hw/pc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/pc.c +12 -0
index df0c48e..90b1bf7 100644
@@ -103,6 +103,11 @@ static void ioport80_write(void *opaque, hwaddr addr, uint64_t data,
 {
 }
 
+static uint64_t ioport80_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffffULL;
+}
+
 /* MSDOS compatibility mode FPU exception support */
 static qemu_irq ferr_irq;
 
@@ -123,6 +128,11 @@ static void ioportF0_write(void *opaque, hwaddr addr, uint64_t data,
     qemu_irq_lower(ferr_irq);
 }
 
+static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0xffffffffffffffffULL;
+}
+
 /* TSC handling */
 uint64_t cpu_get_tsc(CPUX86State *env)
 {
@@ -960,6 +970,7 @@ static void cpu_request_exit(void *opaque, int irq, int level)
 
 static const MemoryRegionOps ioport80_io_ops = {
     .write = ioport80_write,
+    .read = ioport80_read,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
@@ -969,6 +980,7 @@ static const MemoryRegionOps ioport80_io_ops = {
 
 static const MemoryRegionOps ioportF0_io_ops = {
     .write = ioportF0_write,
+    .read = ioportF0_read,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,

-- 1.8.0.2