[Qemu-devel] [PATCH v2 01/15] Add dependency of JSON unit tests on config-host.h

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

Signed-off-by: Jan Kiszka 
---
 Makefile |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index 110698e..aa81d9b 100644
--- a/Makefile
+++ b/Makefile
@@ -144,6 +144,8 @@ qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o 
$(block-obj-y) $(qobj
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $@")
 
+check-qint.o check-qstring.o check-qdict.o check-qlist.o check-qfloat.o 
check-qjson.o: $(GENERATED_HEADERS)
+
 check-qint: check-qint.o qint.o qemu-malloc.o
 check-qstring: check-qstring.o qstring.o qemu-malloc.o
 check-qdict: check-qdict.o qdict.o qfloat.o qint.o qstring.o qbool.o 
qemu-malloc.o qlist.o
-- 
1.6.0.2




[Qemu-devel] [PATCH v2 02/15] qdev: Fix scanning across single-bus devices

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

As long as we allow /dev.1 as shortcut for /dev1/bus1, we also have to
make sure that /dev1/dev2 works for /dev1/bus1/dev2/bus2 - as long as
there is only one child bus per device.

Signed-off-by: Jan Kiszka 
---
 docs/qdev-device-use.txt |4 
 hw/qdev.c|   12 +++-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index f252c8e..9ac1fa1 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -20,6 +20,10 @@ bus named pci.0.  To put a FOO device into its slot 4, use 
-device
 FOO,bus=/i440FX-pcihost/pci.0,addr=4.  The abbreviated form bus=pci.0
 also works as long as the bus name is unique.
 
+Furthermore, if a device only hosts a single bus, the bus name can be
+omitted in the path.  Example: /i440FX-pcihost/PIIX3 abbreviates
+/i440FX-pcihost/pci.0/PIIX3/isa.0 as none of the buses has siblings.
+
 Note: the USB device address can't be controlled at this time.
 
 === Block Devices ===
diff --git a/hw/qdev.c b/hw/qdev.c
index aa2ce01..2e50531 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -557,7 +557,7 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
 
 static BusState *qbus_find(const char *path)
 {
-DeviceState *dev;
+DeviceState *dev, *next_dev;
 BusState *bus;
 char elem[128];
 int pos, len;
@@ -603,6 +603,7 @@ static BusState *qbus_find(const char *path)
 return NULL;
 }
 
+search_dev_bus:
 assert(path[pos] == '/' || !path[pos]);
 while (path[pos] == '/') {
 pos++;
@@ -633,6 +634,15 @@ static BusState *qbus_find(const char *path)
 pos += len;
 bus = qbus_find_bus(dev, elem);
 if (!bus) {
+if (dev->num_child_bus == 1) {
+/* Last element might have been a short-cut to a device on
+ * the single child bus of the parent device. */
+next_dev = qbus_find_dev(QTAILQ_FIRST(&dev->child_bus), elem);
+if (next_dev) {
+dev = next_dev;
+goto search_dev_bus;
+}
+}
 qerror_report(QERR_BUS_NOT_FOUND, elem);
 if (!monitor_cur_is_qmp()) {
 qbus_list_bus(dev);
-- 
1.6.0.2




[Qemu-devel] [PATCH v2 04/15] qdev: Convert device and bus lists to QTAILQ

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

Cosmetic change to align the instance number assignment with bus
ordering. The current ordering due to QLIST_INSERT_HEAD is a bit
annoying when you dump the qtree or address devices via
'driver.instance'.

Signed-off-by: Jan Kiszka 
---
 hw/acpi_piix4.c  |2 +-
 hw/i2c.c |2 +-
 hw/pci-hotplug.c |2 +-
 hw/qdev.c|   43 ++-
 hw/qdev.h|8 
 hw/ssi.c |6 +++---
 6 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 0fce958..3cb3d11 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -536,7 +536,7 @@ static void pciej_write(void *opaque, uint32_t addr, 
uint32_t val)
 PCIDevice *dev;
 int slot = ffs(val) - 1;
 
-QLIST_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
+QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
 dev = DO_UPCAST(PCIDevice, qdev, qdev);
 if (PCI_SLOT(dev->devfn) == slot) {
 qdev_free(qdev);
diff --git a/hw/i2c.c b/hw/i2c.c
index bee8e88..61ab6fa 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -84,7 +84,7 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int 
recv)
 DeviceState *qdev;
 i2c_slave *slave = NULL;
 
-QLIST_FOREACH(qdev, &bus->qbus.children, sibling) {
+QTAILQ_FOREACH(qdev, &bus->qbus.children, sibling) {
 i2c_slave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
 if (candidate->address == address) {
 slave = candidate;
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index cc45c50..a226d3c 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -77,7 +77,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
 SCSIBus *scsibus;
 SCSIDevice *scsidev;
 
-scsibus = DO_UPCAST(SCSIBus, qbus, QLIST_FIRST(&adapter->child_bus));
+scsibus = DO_UPCAST(SCSIBus, qbus, QTAILQ_FIRST(&adapter->child_bus));
 if (!scsibus || strcmp(scsibus->qbus.info->name, "SCSI") != 0) {
 error_report("Device is not a SCSI adapter");
 return -1;
diff --git a/hw/qdev.c b/hw/qdev.c
index 6b4a629..6d55e50 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -85,10 +85,11 @@ static DeviceState *qdev_create_from_info(BusState *bus, 
DeviceInfo *info)
 dev = qemu_mallocz(info->size);
 dev->info = info;
 dev->parent_bus = bus;
+QTAILQ_INIT(&dev->child_bus);
 qdev_prop_set_defaults(dev, dev->info->props);
 qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
 qdev_prop_set_globals(dev);
-QLIST_INSERT_HEAD(&bus->children, dev, sibling);
+QTAILQ_INSERT_TAIL(&bus->children, dev, sibling);
 if (qdev_hotplug) {
 assert(bus->allow_hotplug);
 dev->hotplugged = 1;
@@ -337,7 +338,7 @@ void qdev_free(DeviceState *dev)
 
 if (dev->state == DEV_STATE_INITIALIZED) {
 while (dev->num_child_bus) {
-bus = QLIST_FIRST(&dev->child_bus);
+bus = QTAILQ_FIRST(&dev->child_bus);
 qbus_free(bus);
 }
 if (dev->info->vmsd)
@@ -348,7 +349,7 @@ void qdev_free(DeviceState *dev)
 qemu_opts_del(dev->opts);
 }
 qemu_unregister_reset(qdev_reset, dev);
-QLIST_REMOVE(dev, sibling);
+QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
 qemu_free(dev);
 }
 
@@ -432,7 +433,7 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char 
*name)
 {
 BusState *bus;
 
-QLIST_FOREACH(bus, &dev->child_bus, sibling) {
+QTAILQ_FOREACH(bus, &dev->child_bus, sibling) {
 if (strcmp(name, bus->name) == 0) {
 return bus;
 }
@@ -457,8 +458,8 @@ static BusState *qbus_find_recursive(BusState *bus, const 
char *name,
 return bus;
 }
 
-QLIST_FOREACH(dev, &bus->children, sibling) {
-QLIST_FOREACH(child, &dev->child_bus, sibling) {
+QTAILQ_FOREACH(dev, &bus->children, sibling) {
+QTAILQ_FOREACH(child, &dev->child_bus, sibling) {
 ret = qbus_find_recursive(child, name, info);
 if (ret) {
 return ret;
@@ -473,10 +474,10 @@ static DeviceState *qdev_find_recursive(BusState *bus, 
const char *id)
 DeviceState *dev, *ret;
 BusState *child;
 
-QLIST_FOREACH(dev, &bus->children, sibling) {
+QTAILQ_FOREACH(dev, &bus->children, sibling) {
 if (dev->id && strcmp(dev->id, id) == 0)
 return dev;
-QLIST_FOREACH(child, &dev->child_bus, sibling) {
+QTAILQ_FOREACH(child, &dev->child_bus, sibling) {
 ret = qdev_find_recursive(child, id);
 if (ret) {
 return ret;
@@ -493,7 +494,7 @@ static void qbus_list_bus(DeviceState *dev)
 
 error_printf("child busses at \"%s\":",
  dev->id ? dev->id : dev->info->name);
-QLIST_FOREACH(child, &dev->child_bus, sibling) {
+QTAILQ_FOREACH(child, &dev->child_bus, sibling) {
 error_printf("%s\"%s\"", sep, child->name);
 sep = ", ";
 }
@@ -506,7 +507,7 @@ static voi

[Qemu-devel] [PATCH v2 10/15] Add QBuffer

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

This introduces a buffer object for use with QMP. As a buffer is not
natively encodable in JSON, we encode it as a base64 string and
encapsulate the result in the new QMP object class "buffer".

The first use case for this is pushing the content of buffers that are
part of a device state into a qdict.

Signed-off-by: Jan Kiszka 
---
 Makefile |5 +-
 Makefile.objs|2 +-
 QMP/qmp-spec.txt |   10 +++-
 check-qbuffer.c  |  172 ++
 configure|2 +-
 qbuffer.c|  116 
 qbuffer.h|   33 ++
 qjson.c  |   15 +
 qobject.h|1 +
 9 files changed, 351 insertions(+), 5 deletions(-)
 create mode 100644 check-qbuffer.c
 create mode 100644 qbuffer.c
 create mode 100644 qbuffer.h

diff --git a/Makefile b/Makefile
index aa81d9b..9c226ae 100644
--- a/Makefile
+++ b/Makefile
@@ -144,14 +144,15 @@ qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o 
qemu-error.o $(block-obj-y) $(qobj
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $@")
 
-check-qint.o check-qstring.o check-qdict.o check-qlist.o check-qfloat.o 
check-qjson.o: $(GENERATED_HEADERS)
+check-qint.o check-qstring.o check-qdict.o check-qlist.o check-qfloat.o 
check-qjson.o check-qbuffer: $(GENERATED_HEADERS)
 
 check-qint: check-qint.o qint.o qemu-malloc.o
 check-qstring: check-qstring.o qstring.o qemu-malloc.o
 check-qdict: check-qdict.o qdict.o qfloat.o qint.o qstring.o qbool.o 
qemu-malloc.o qlist.o
 check-qlist: check-qlist.o qlist.o qint.o qemu-malloc.o
 check-qfloat: check-qfloat.o qfloat.o qemu-malloc.o
-check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o 
qjson.o json-streamer.o json-lexer.o json-parser.o qemu-malloc.o
+check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o 
qbuffer.o base64.o qjson.o json-streamer.o json-lexer.o json-parser.o 
qemu-malloc.o
+check-qbuffer: check-qbuffer.o qbuffer.o base64.o qstring.o qemu-malloc.o
 
 clean:
 # avoid old build problems by removing potentially incorrect old files
diff --git a/Makefile.objs b/Makefile.objs
index 2c603b2..d556806 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -1,6 +1,6 @@
 ###
 # QObject
-qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
+qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o qbuffer.o
 qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
 qobject-obj-y += qerror.o base64.o
 
diff --git a/QMP/qmp-spec.txt b/QMP/qmp-spec.txt
index fa1dd62..820e39d 100644
--- a/QMP/qmp-spec.txt
+++ b/QMP/qmp-spec.txt
@@ -153,7 +153,15 @@ JSON objects that contain the key-value pair '"__class__": 
json-string' are
 reserved for QMP-specific complex object classes that. QMP specifies which
 further keys each of these objects include and how they are encoded.
 
-So far, no complex object class is specified.
+2.6.1 Buffer class
+--
+
+This QMP object class allows to transport binary data. A buffer object
+consists of the following keys:
+
+{ "__class__": "buffer", "data": json-string }
+
+The data string is base64 encoded according to RFC 4648.
 
 3. QMP Examples
 ===
diff --git a/check-qbuffer.c b/check-qbuffer.c
new file mode 100644
index 000..b490230
--- /dev/null
+++ b/check-qbuffer.c
@@ -0,0 +1,172 @@
+/*
+ * QBuffer unit-tests.
+ *
+ * Copyright (C) 2010 Siemens AG
+ *
+ * Authors:
+ *  Jan Kiszka 
+ *
+ * This work is licensed under the terms of the GNU GPL version 2.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include 
+
+#include "qbuffer.h"
+#include "qemu-common.h"
+
+const char data[] = "some data";
+
+START_TEST(qbuffer_from_data_test)
+{
+QBuffer *qbuffer;
+
+qbuffer = qbuffer_from_data(data, sizeof(data));
+fail_unless(qbuffer != NULL);
+fail_unless(qbuffer->base.refcnt == 1);
+fail_unless(memcmp(data, qbuffer->data, sizeof(data)) == 0);
+fail_unless(qbuffer->size == sizeof(data));
+fail_unless(qobject_type(QOBJECT(qbuffer)) == QTYPE_QBUFFER);
+
+/* destroy doesn't exit yet */
+qemu_free(qbuffer->data);
+qemu_free(qbuffer);
+}
+END_TEST
+
+START_TEST(qbuffer_destroy_test)
+{
+QBuffer *qbuffer = qbuffer_from_data(data, sizeof(data));
+
+QDECREF(qbuffer);
+}
+END_TEST
+
+START_TEST(qbuffer_get_data_test)
+{
+QBuffer *qbuffer;
+const void *ret_data;
+
+qbuffer = qbuffer_from_data(data, sizeof(data));
+ret_data = qbuffer_get_data(qbuffer);
+fail_unless(memcmp(ret_data, data, sizeof(data)) == 0);
+
+QDECREF(qbuffer);
+}
+END_TEST
+
+START_TEST(qbuffer_get_size_test)
+{
+QBuffer *qbuffer;
+
+qbuffer = qbuffer_from_data(data, sizeof(data));
+fail_unless(qbuffer_get_size(qbuffer) == sizeof(data));
+
+QDECREF(qbuffer);
+}
+END_TEST
+
+START_TEST(qbuffer_from_qs

[Qemu-devel] [PATCH v2 08/15] Add base64 encoder/decoder

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

Will be used by QBuffer.

Signed-off-by: Jan Kiszka 
---
 Makefile.objs |2 +-
 base64.c  |  202 +
 base64.h  |   18 +
 3 files changed, 221 insertions(+), 1 deletions(-)
 create mode 100644 base64.c
 create mode 100644 base64.h

diff --git a/Makefile.objs b/Makefile.objs
index acbaf22..2c603b2 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -2,7 +2,7 @@
 # QObject
 qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
 qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
-qobject-obj-y += qerror.o
+qobject-obj-y += qerror.o base64.o
 
 ###
 # block-obj-y is code used by both qemu system emulation and qemu-img
diff --git a/base64.c b/base64.c
new file mode 100644
index 000..543e8c6
--- /dev/null
+++ b/base64.c
@@ -0,0 +1,202 @@
+/*
+ * Base64 encoder/decoder conforming to RFC 4648
+ * (based on Mozilla's nsprpub/lib/libc/src/base64.c)
+ *
+ * Copyright (C) 2010 Siemens AG
+ *
+ * Authors:
+ *  Jan Kiszka 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "inttypes.h"
+#include "base64.h"
+
+static const char base[] =
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static void encode3to4(const char *src, char *dest)
+{
+uint32_t b32 = 0;
+int i, j = 18;
+
+for (i = 0; i < 3; i++) {
+b32 <<= 8;
+b32 |= src[i];
+}
+for (i = 0; i < 4; i++) {
+dest[i] = base[(b32 >> j) & 0x3F];
+j -= 6;
+}
+}
+
+static void encode2to4(const char *src, char *dest)
+{
+dest[0] = base[(src[0] >> 2) & 0x3F];
+dest[1] = base[((src[0] & 0x03) << 4) | ((src[1] >> 4) & 0x0F)];
+dest[2] = base[(src[1] & 0x0F) << 2];
+dest[3] = '=';
+}
+
+static void encode1to4(const char *src, char *dest)
+{
+dest[0] = base[(src[0] >> 2) & 0x3F];
+dest[1] = base[(src[0] & 0x03) << 4];
+dest[2] = '=';
+dest[3] = '=';
+}
+
+/*
+ * Encode data in 'src' of length 'srclen' to a base64 string, saving the
+ * null-terminated result in 'dest'. The size of the destition buffer must be
+ * at least ((srclen + 2) / 3) * 4 + 1.
+ */
+void base64_encode(const void *src, size_t srclen, char *dest)
+{
+while (srclen >= 3) {
+encode3to4(src, dest);
+src += 3;
+dest += 4;
+srclen -= 3;
+}
+switch (srclen) {
+case 2:
+encode2to4(src, dest);
+dest += 4;
+break;
+case 1:
+encode1to4(src, dest);
+dest += 4;
+break;
+case 0:
+break;
+}
+dest[0] = 0;
+}
+
+static int32_t codetovalue(char c)
+{
+if (c >= 'A' && c <= 'Z') {
+return c - 'A';
+} else if (c >= 'a' && c <= 'z') {
+return c - 'a' + 26;
+} else if (c >= '0' && c <= '9') {
+return c - '0' + 52;
+} else if (c == '+') {
+return 62;
+} else if ( c == '/') {
+return 63;
+} else {
+return -1;
+}
+}
+
+static int decode4to3 (const char *src, char *dest)
+{
+uint32_t b32 = 0;
+int32_t bits;
+int i;
+
+for (i = 0; i < 4; i++) {
+bits = codetovalue(src[i]);
+if (bits < 0) {
+return bits;
+}
+b32 <<= 6;
+b32 |= bits;
+}
+dest[0] = (b32 >> 16) & 0xFF;
+dest[1] = (b32 >> 8) & 0xFF;
+dest[2] = b32 & 0xFF;
+
+return 0;
+}
+
+static int decode3to2(const char *src, char *dest)
+{
+uint32_t b32 = 0;
+int32_t bits;
+
+bits = codetovalue(src[0]);
+if (bits < 0) {
+return bits;
+}
+b32 = (uint32_t)bits;
+b32 <<= 6;
+
+bits = codetovalue(src[1]);
+if (bits < 0) {
+return bits;
+}
+b32 |= (uint32_t)bits;
+b32 <<= 4;
+
+bits = codetovalue(src[2]);
+if (bits < 0) {
+return bits;
+}
+b32 |= ((uint32_t)bits) >> 2;
+
+dest[0] = (b32 >> 8) & 0xFF;
+dest[1] = b32 & 0xFF;
+
+return 0;
+}
+
+static int decode2to1(const char *src, char *dest)
+{
+uint32_t b32;
+int32_t bits;
+
+bits = codetovalue(src[0]);
+if (bits < 0) {
+return bits;
+}
+b32 = (uint32_t)bits << 2;
+
+bits = codetovalue(src[1]);
+if (bits < 0) {
+return bits;
+}
+b32 |= ((uint32_t)bits) >> 4;
+
+dest[0] = b32;
+
+return 0;
+}
+
+/*
+ * Convert string 'src' of length 'srclen' from base64 to binary form,
+ * saving the result in 'dest'. The size of the destination buffer must be at
+ * least srclen * 3 / 4.
+ *
+ * Returns 0 on success, -1 on conversion error.
+ */
+int base64_decode(const char *src, size_t srclen, void *dest)
+{
+int ret;
+
+while (srclen >= 4) {
+ret = decode4to3(src, dest);
+if (ret < 0) {
+return ret;
+}
+src += 4;
+dest += 3;
+srclen -= 4;
+   

[Qemu-devel] [PATCH v2 05/15] qdev: Allow device specification by qtree path for device_del

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

Allow to specify the device to be removed via device_del not only by ID
but also by its full or abbreviated qtree path. For this purpose,
qdev_find is introduced which combines searching for device IDs with
walking the qtree when required.

Signed-off-by: Jan Kiszka 
---
 hw/qdev.c   |   46 ++
 qemu-monitor.hx |   10 +-
 2 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 6d55e50..fa611a1 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -666,6 +666,44 @@ search_dev_bus:
 }
 }
 
+static DeviceState *qdev_find(const char *path)
+{
+const char *dev_name;
+DeviceState *dev;
+char *bus_path;
+BusState *bus;
+
+dev_name = strrchr(path, '/');
+if (!dev_name) {
+bus = main_system_bus;
+dev = qdev_find_recursive(bus, path);
+if (dev) {
+return dev;
+}
+dev_name = path;
+} else {
+dev_name++;
+bus_path = qemu_strdup(path);
+bus_path[dev_name - path] = 0;
+
+bus = qbus_find(bus_path);
+qemu_free(bus_path);
+
+if (!bus) {
+/* qbus_find already reported the error */
+return NULL;
+}
+}
+dev = qbus_find_dev(bus, dev_name);
+if (!dev) {
+qerror_report(QERR_DEVICE_NOT_FOUND, dev_name);
+if (!monitor_cur_is_qmp()) {
+qbus_list_dev(bus);
+}
+}
+return dev;
+}
+
 void qbus_create_inplace(BusState *bus, BusInfo *info,
  DeviceState *parent, const char *name)
 {
@@ -824,12 +862,12 @@ int do_device_add(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 
 int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-const char *id = qdict_get_str(qdict, "id");
+const char *path = qdict_get_str(qdict, "path");
 DeviceState *dev;
 
-dev = qdev_find_recursive(main_system_bus, id);
-if (NULL == dev) {
-qerror_report(QERR_DEVICE_NOT_FOUND, id);
+dev = qdev_find(path);
+if (!dev) {
+qerror_report(QERR_DEVICE_NOT_FOUND, path);
 return -1;
 }
 return qdev_unplug(dev);
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index c8f1789..754d71e 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -703,7 +703,7 @@ EQMP
 
 {
 .name   = "device_del",
-.args_type  = "id:s",
+.args_type  = "path:s",
 .params = "device",
 .help   = "remove device",
 .user_print = monitor_user_noop,
@@ -711,10 +711,10 @@ EQMP
 },
 
 STEXI
-...@item device_del @var{id}
+...@item device_del @var{path}
 @findex device_del
 
-Remove device @var{id}.
+Remove device @var{path}.
 ETEXI
 SQMP
 device_del
@@ -724,11 +724,11 @@ Remove a device.
 
 Arguments:
 
-- "id": the device's ID (json-string)
+- "path": the device's qtree path or unique ID (json-string)
 
 Example:
 
--> { "execute": "device_del", "arguments": { "id": "net1" } }
+-> { "execute": "device_del", "arguments": { "path": "net1" } }
 <- { "return": {} }
 
 EQMP
-- 
1.6.0.2




[Qemu-devel] [PATCH v2 06/15] qdev: Push QMP mode checks into qbus_list_bus/dev

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

Simplifies the usage.

Signed-off-by: Jan Kiszka 
---
 hw/qdev.c |   22 ++
 1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index fa611a1..db005ce 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -492,6 +492,9 @@ static void qbus_list_bus(DeviceState *dev)
 BusState *child;
 const char *sep = " ";
 
+if (monitor_cur_is_qmp()) {
+return;
+}
 error_printf("child busses at \"%s\":",
  dev->id ? dev->id : dev->info->name);
 QTAILQ_FOREACH(child, &dev->child_bus, sibling) {
@@ -506,6 +509,9 @@ static void qbus_list_dev(BusState *bus)
 DeviceState *dev;
 const char *sep = " ";
 
+if (monitor_cur_is_qmp()) {
+return;
+}
 error_printf("devices at \"%s\":", bus->name);
 QTAILQ_FOREACH(dev, &bus->children, sibling) {
 error_printf("%s\"%s\"", sep, dev->info->name);
@@ -611,9 +617,7 @@ static BusState *qbus_find(const char *path)
 dev = qbus_find_dev(bus, elem);
 if (!dev) {
 qerror_report(QERR_DEVICE_NOT_FOUND, elem);
-if (!monitor_cur_is_qmp()) {
-qbus_list_dev(bus);
-}
+qbus_list_dev(bus);
 return NULL;
 }
 
@@ -633,9 +637,7 @@ search_dev_bus:
 return QTAILQ_FIRST(&dev->child_bus);
 default:
 qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, elem);
-if (!monitor_cur_is_qmp()) {
-qbus_list_bus(dev);
-}
+qbus_list_bus(dev);
 return NULL;
 }
 }
@@ -658,9 +660,7 @@ search_dev_bus:
 }
 }
 qerror_report(QERR_BUS_NOT_FOUND, elem);
-if (!monitor_cur_is_qmp()) {
-qbus_list_bus(dev);
-}
+qbus_list_bus(dev);
 return NULL;
 }
 }
@@ -697,9 +697,7 @@ static DeviceState *qdev_find(const char *path)
 dev = qbus_find_dev(bus, dev_name);
 if (!dev) {
 qerror_report(QERR_DEVICE_NOT_FOUND, dev_name);
-if (!monitor_cur_is_qmp()) {
-qbus_list_dev(bus);
-}
+qbus_list_dev(bus);
 }
 return dev;
 }
-- 
1.6.0.2




[Qemu-devel] [PATCH v2 03/15] qdev: Allow device addressing via 'driver.instance'

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

Extend qbus_find_dev to allow addressing of devices without an unique id
via an optional per-bus instance number. The new formats are
'driver.instance' and 'alias.instance'.

Signed-off-by: Jan Kiszka 
---
 docs/qdev-device-use.txt |   12 +++-
 hw/qdev.c|   23 ++-
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index 9ac1fa1..5939481 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -1,6 +1,6 @@
 = How to convert to -device & friends =
 
-=== Specifying Bus and Address on Bus ===
+=== Specifying Bus, Address on Bus, and Devices ===
 
 In qdev, each device has a parent bus.  Some devices provide one or
 more buses for children.  You can specify a device's parent bus with
@@ -24,6 +24,16 @@ Furthermore, if a device only hosts a single bus, the bus 
name can be
 omitted in the path.  Example: /i440FX-pcihost/PIIX3 abbreviates
 /i440FX-pcihost/pci.0/PIIX3/isa.0 as none of the buses has siblings.
 
+Existing devices can be addressed either via a unique ID if it was
+assigned during creation or via the device tree path:
+
+/full_bus_address/driver_name[.instance_number]
+or
+abbreviated_bus_address/driver_name[.instance_number]
+
+Example: /i440FX-pcihost/pci.0/e1000.2 addresses the second e1000
+adapter on the bus 'pci.0'.
+
 Note: the USB device address can't be controlled at this time.
 
 === Block Devices ===
diff --git a/hw/qdev.c b/hw/qdev.c
index 2e50531..6b4a629 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -527,28 +527,41 @@ static BusState *qbus_find_bus(DeviceState *dev, char 
*elem)
 return NULL;
 }
 
-static DeviceState *qbus_find_dev(BusState *bus, char *elem)
+static DeviceState *qbus_find_dev(BusState *bus, const char *elem)
 {
 DeviceState *dev;
+int instance, n;
+char buf[128];
 
 /*
  * try to match in order:
  *   (1) instance id, if present
- *   (2) driver name
- *   (3) driver alias, if present
+ *   (2) driver name [.instance]
+ *   (3) driver alias [.instance], if present
  */
 QLIST_FOREACH(dev, &bus->children, sibling) {
 if (dev->id  &&  strcmp(dev->id, elem) == 0) {
 return dev;
 }
 }
+
+if (sscanf(elem, "%127[^.].%u", buf, &instance) == 2) {
+elem = buf;
+} else {
+instance = 0;
+}
+
+n = 0;
 QLIST_FOREACH(dev, &bus->children, sibling) {
-if (strcmp(dev->info->name, elem) == 0) {
+if (strcmp(dev->info->name, elem) == 0 && n++ == instance) {
 return dev;
 }
 }
+
+n = 0;
 QLIST_FOREACH(dev, &bus->children, sibling) {
-if (dev->info->alias && strcmp(dev->info->alias, elem) == 0) {
+if (dev->info->alias && strcmp(dev->info->alias, elem) == 0 &&
+n++ == instance) {
 return dev;
 }
 }
-- 
1.6.0.2




[Qemu-devel] [PATCH v2 00/15] Basic device state visualization

2010-05-22 Thread Jan Kiszka
Here is version 2 of the device_show patch series. It currently has some
dependencies on recently posted doc changes / enhancements, namely:
 - http://thread.gmane.org/gmane.comp.emulators.qemu/70673
   ([PATCH v3 0/3]: QMP: Commands doc)
 - http://thread.gmane.org/gmane.comp.emulators.qemu/70756
   ([PATCH 1/7] QMP: Add "Downstream extension of QMP" to spec)

Major changes in v2 are:
 - command line completion for device tree paths
 - introduced complex object classes ("__class__") and applied that on
   buffers
 - documentation
 - applied new qdev path specification also on device_del
 - proper qdev device/bus sorting via QTAILQ (instead of QLIST_INSERT_TAIL)
 - added QERR_DEVICE_NO_STATE
 - fixed various bugs
 - 

For reference, the series is also available at

git://git.kiszka.org/qemu.git queues/device-show

Thanks for all comments so far!

Jan Kiszka (15):
  Add dependency of JSON unit tests on config-host.h
  qdev: Fix scanning across single-bus devices
  qdev: Allow device addressing via 'driver.instance'
  qdev: Convert device and bus lists to QTAILQ
  qdev: Allow device specification by qtree path for device_del
  qdev: Push QMP mode checks into qbus_list_bus/dev
  monitor: Add completion for qdev paths
  Add base64 encoder/decoder
  QMP: Reserve namespace for complex object classes
  Add QBuffer
  monitor: return length of printed string via monitor_[v]printf
  monitor: Add basic device state visualization
  QMP: Teach basic capability negotiation to python example
  QMP: Fix python helper /wrt long return strings
  QMP: Add support for buffer class to qmp python helper

 Makefile |5 +-
 Makefile.objs|4 +-
 QMP/qmp-shell|1 +
 QMP/qmp-spec.txt |   24 +++-
 QMP/qmp.py   |   29 +++-
 QMP/vm-info  |1 +
 base64.c |  202 +++
 base64.h |   18 ++
 check-qbuffer.c  |  172 +++
 configure|2 +-
 docs/qdev-device-use.txt |   16 ++-
 hw/acpi_piix4.c  |2 +-
 hw/hw.h  |2 +
 hw/i2c.c |2 +-
 hw/pci-hotplug.c |2 +-
 hw/qdev.c|  408 +-
 hw/qdev.h|   12 +-
 hw/ssi.c |6 +-
 monitor.c|  108 +++-
 monitor.h|4 +-
 qbuffer.c|  116 +
 qbuffer.h|   33 
 qemu-monitor.hx  |   74 -
 qemu-tool.c  |6 +-
 qerror.c |4 +
 qerror.h |3 +
 qjson.c  |   15 ++
 qobject.h|1 +
 28 files changed, 1193 insertions(+), 79 deletions(-)
 create mode 100644 base64.c
 create mode 100644 base64.h
 create mode 100644 check-qbuffer.c
 create mode 100644 qbuffer.c
 create mode 100644 qbuffer.h




[Qemu-devel] [PATCH v2 12/15] monitor: Add basic device state visualization

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

This introduces device_show, a monitor command that saves the vmstate of
a qdev device and visualizes it. QMP is also supported. Buffers are cut
after 16 byte by default, but the full content can be requested via
'-f'. To pretty-print sub-arrays, vmstate is extended to store the start
index name. A new qerror is introduced to signal a missing vmstate. And
it comes with documentation.

Signed-off-by: Jan Kiszka 
---
 hw/hw.h |2 +
 hw/qdev.c   |  244 +++
 hw/qdev.h   |2 +
 qemu-monitor.hx |   64 +++
 qerror.c|4 +
 qerror.h|3 +
 6 files changed, 319 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index fc2d184..cc4bd5f 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -299,6 +299,7 @@ enum VMStateFlags {
 
 typedef struct {
 const char *name;
+const char *start_index;
 size_t offset;
 size_t size;
 size_t start;
@@ -413,6 +414,7 @@ extern const VMStateInfo vmstate_info_unused_buffer;
 .size   = sizeof(_type), \
 .flags  = VMS_ARRAY, \
 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
+.start_index = (stringify(_start)),  \
 }
 
 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, 
_type) {\
diff --git a/hw/qdev.c b/hw/qdev.c
index 7db839f..a30ac56 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -29,6 +29,9 @@
 #include "qdev.h"
 #include "sysemu.h"
 #include "monitor.h"
+#include "qjson.h"
+#include "qint.h"
+#include "qbuffer.h"
 
 static int qdev_hotplug = 0;
 
@@ -890,3 +893,244 @@ int do_device_del(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 }
 return qdev_unplug(dev);
 }
+
+#define NAME_COLUMN_WIDTH 23
+
+static void print_field(Monitor *mon, const QDict *qfield, int indent);
+
+static void print_elem(Monitor *mon, const QObject *qelem, size_t size,
+   int column_pos, int indent)
+{
+int64_t data_size;
+const void *data;
+int n;
+
+if (qobject_type(qelem) == QTYPE_QDICT) {
+if (column_pos >= 0) {
+monitor_printf(mon, ".\n");
+}
+} else {
+monitor_printf(mon, ":");
+column_pos++;
+if (column_pos < NAME_COLUMN_WIDTH) {
+monitor_printf(mon, "%*c", NAME_COLUMN_WIDTH - column_pos, ' ');
+}
+}
+
+switch (qobject_type(qelem)) {
+case QTYPE_QDICT:
+print_field(mon, qobject_to_qdict(qelem), indent + 2);
+break;
+case QTYPE_QBUFFER:
+data = qbuffer_get_data(qobject_to_qbuffer(qelem));
+data_size = qbuffer_get_size(qobject_to_qbuffer(qelem));
+for (n = 0; n < data_size; ) {
+monitor_printf(mon, " %02x", *((uint8_t *)data+n));
+if (++n < size) {
+if (n % 16 == 0) {
+monitor_printf(mon, "\n%*c", NAME_COLUMN_WIDTH, ' ');
+} else if (n % 8 == 0) {
+monitor_printf(mon, " -");
+}
+}
+}
+if (data_size < size) {
+monitor_printf(mon, " ...");
+}
+monitor_printf(mon, "\n");
+break;
+case QTYPE_QINT:
+monitor_printf(mon, " %0*" PRIx64 "\n", (int)size * 2,
+   qint_get_int(qobject_to_qint(qelem)));
+break;
+default:
+assert(0);
+}
+}
+
+static void print_field(Monitor *mon, const QDict *qfield, int indent)
+{
+const char *name = qdict_get_str(qfield, "name");
+const char *start = qdict_get_try_str(qfield, "start");
+int64_t size = qdict_get_int(qfield, "size");
+QList *qlist = qdict_get_qlist(qfield, "elems");
+QListEntry *entry, *sub_entry;
+QList *sub_list;
+int elem_no = 0;
+
+QLIST_FOREACH_ENTRY(qlist, entry) {
+QObject *qelem = qlist_entry_obj(entry);
+int pos = indent + strlen(name);
+
+if (qobject_type(qelem) == QTYPE_QLIST) {
+monitor_printf(mon, "%*c%s", indent, ' ', name);
+if (start) {
+pos += monitor_printf(mon, "[%s+%02x]", start, elem_no);
+} else {
+pos += monitor_printf(mon, "[%02x]", elem_no);
+}
+sub_list = qobject_to_qlist(qelem);
+QLIST_FOREACH_ENTRY(sub_list, sub_entry) {
+print_elem(mon, qlist_entry_obj(sub_entry), size, pos,
+   indent + 2);
+pos = -1;
+}
+} else {
+if (elem_no == 0) {
+monitor_printf(mon, "%*c%s", indent, ' ', name);
+} else {
+pos = -1;
+}
+print_elem(mon, qelem, size, pos, indent);
+}
+elem_no++;
+}
+}
+
+void device_user_print(Monitor *mon, const QObject *data)
+{
+QDict *qdict = qobject_to_qdict(data);
+QList *qlist =

[Qemu-devel] [PATCH v2 09/15] QMP: Reserve namespace for complex object classes

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

This reserves JSON objects that contain the key '__class__' for QMP-specific
complex objects. First user will be the buffer class.

Signed-off-by: Jan Kiszka 
---
 QMP/qmp-spec.txt |   16 +---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/QMP/qmp-spec.txt b/QMP/qmp-spec.txt
index 9d30a8c..fa1dd62 100644
--- a/QMP/qmp-spec.txt
+++ b/QMP/qmp-spec.txt
@@ -146,6 +146,15 @@ The format is:
 For a listing of supported asynchronous events, please, refer to the
 qmp-events.txt file.
 
+2.6 Complex object classes
+--
+
+JSON objects that contain the key-value pair '"__class__": json-string' are
+reserved for QMP-specific complex object classes that. QMP specifies which
+further keys each of these objects include and how they are encoded.
+
+So far, no complex object class is specified.
+
 3. QMP Examples
 ===
 
@@ -229,9 +238,10 @@ avoid modifying QMP.  Both upstream and downstream need to 
take care to
 preserve long-term compatibility and interoperability.
 
 To help with that, QMP reserves JSON object member names beginning with
-'__' (double underscore) for downstream use ("downstream names").  This
-means upstream will never use any downstream names for its commands,
-arguments, errors, asynchronous events, and so forth.
+'__' (double underscore) for downstream use ("downstream names").  Downstream
+names MUST NOT end with '__' as this pattern is reserved for QMP-defined JSON
+object classes.  Upstream will never use any downstream names for its
+commands, arguments, errors, asynchronous events, and so forth.
 
 Any new names downstream wishes to add must begin with '__'.  To
 ensure compatibility with other downstreams, it is strongly
-- 
1.6.0.2




[Qemu-devel] [PATCH v2 07/15] monitor: Add completion for qdev paths

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

Implement monitor command line completion for device tree paths. The
first user is device_del.

Signed-off-by: Jan Kiszka 
---
 hw/qdev.c   |   50 ++--
 hw/qdev.h   |2 +
 monitor.c   |   85 +++
 qemu-monitor.hx |2 +-
 4 files changed, 123 insertions(+), 16 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index db005ce..7db839f 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -39,7 +39,7 @@ DeviceInfo *device_info_list;
 
 static BusState *qbus_find_recursive(BusState *bus, const char *name,
  const BusInfo *info);
-static BusState *qbus_find(const char *path);
+static BusState *qbus_find_internal(const char *path, bool report_errors);
 
 /* Register a new device type.  */
 void qdev_register(DeviceInfo *info)
@@ -217,7 +217,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 /* find bus */
 path = qemu_opt_get(opts, "bus");
 if (path != NULL) {
-bus = qbus_find(path);
+bus = qbus_find_internal(path, true);
 if (!bus) {
 return NULL;
 }
@@ -575,7 +575,7 @@ static DeviceState *qbus_find_dev(BusState *bus, const char 
*elem)
 return NULL;
 }
 
-static BusState *qbus_find(const char *path)
+static BusState *qbus_find_internal(const char *path, bool report_errors)
 {
 DeviceState *dev, *next_dev;
 BusState *bus;
@@ -593,7 +593,9 @@ static BusState *qbus_find(const char *path)
 }
 bus = qbus_find_recursive(main_system_bus, elem, NULL);
 if (!bus) {
-qerror_report(QERR_BUS_NOT_FOUND, elem);
+if (report_errors) {
+qerror_report(QERR_BUS_NOT_FOUND, elem);
+}
 return NULL;
 }
 pos = len;
@@ -616,8 +618,10 @@ static BusState *qbus_find(const char *path)
 pos += len;
 dev = qbus_find_dev(bus, elem);
 if (!dev) {
-qerror_report(QERR_DEVICE_NOT_FOUND, elem);
-qbus_list_dev(bus);
+if (report_errors) {
+qerror_report(QERR_DEVICE_NOT_FOUND, elem);
+qbus_list_dev(bus);
+}
 return NULL;
 }
 
@@ -631,13 +635,17 @@ search_dev_bus:
  * one child bus accept it nevertheless */
 switch (dev->num_child_bus) {
 case 0:
-qerror_report(QERR_DEVICE_NO_BUS, elem);
+if (report_errors) {
+qerror_report(QERR_DEVICE_NO_BUS, elem);
+}
 return NULL;
 case 1:
 return QTAILQ_FIRST(&dev->child_bus);
 default:
-qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, elem);
-qbus_list_bus(dev);
+if (report_errors) {
+qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, elem);
+qbus_list_bus(dev);
+}
 return NULL;
 }
 }
@@ -659,14 +667,21 @@ search_dev_bus:
 goto search_dev_bus;
 }
 }
-qerror_report(QERR_BUS_NOT_FOUND, elem);
-qbus_list_bus(dev);
+if (report_errors) {
+qerror_report(QERR_BUS_NOT_FOUND, elem);
+qbus_list_bus(dev);
+}
 return NULL;
 }
 }
 }
 
-static DeviceState *qdev_find(const char *path)
+BusState *qbus_find(const char *path)
+{
+return qbus_find_internal(path, false);
+}
+
+static DeviceState *qdev_find_internal(const char *path, bool report_errors)
 {
 const char *dev_name;
 DeviceState *dev;
@@ -686,7 +701,7 @@ static DeviceState *qdev_find(const char *path)
 bus_path = qemu_strdup(path);
 bus_path[dev_name - path] = 0;
 
-bus = qbus_find(bus_path);
+bus = qbus_find_internal(bus_path, report_errors);
 qemu_free(bus_path);
 
 if (!bus) {
@@ -695,13 +710,18 @@ static DeviceState *qdev_find(const char *path)
 }
 }
 dev = qbus_find_dev(bus, dev_name);
-if (!dev) {
+if (!dev && report_errors) {
 qerror_report(QERR_DEVICE_NOT_FOUND, dev_name);
 qbus_list_dev(bus);
 }
 return dev;
 }
 
+DeviceState *qdev_find(const char *path)
+{
+return qdev_find_internal(path, false);
+}
+
 void qbus_create_inplace(BusState *bus, BusInfo *info,
  DeviceState *parent, const char *name)
 {
@@ -863,7 +883,7 @@ int do_device_del(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 const char *path = qdict_get_str(qdict, "path");
 DeviceState *dev;
 
-dev = qdev_find(path);
+dev = qdev_find_internal(path, true);
 if (!dev) {
 qerror_report(QERR_DEVICE_NOT_FOUND, path);
 return -1;
diff --git a/hw/qdev.h b/hw/qdev.h
index 53f5565..b27d33b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -165,6 +165,7 @@ void qdev_init_gpio_out(DeviceSt

[Qemu-devel] [PATCH v2 14/15] QMP: Fix python helper /wrt long return strings

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

Remove the arbitrary limitation of 1024 characters per return string and
read complete lines instead. Required for device_show.

Signed-off-by: Jan Kiszka 
---
 QMP/qmp.py |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/QMP/qmp.py b/QMP/qmp.py
index d9da603..4062f84 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -63,10 +63,14 @@ class QEMUMonitorProtocol:
 
 def __json_read(self):
 try:
-return json.loads(self.sock.recv(1024))
+while True:
+line = json.loads(self.sockfile.readline())
+if not 'event' in line:
+return line
 except ValueError:
 return
 
 def __init__(self, filename):
 self.filename = filename
 self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+self.sockfile = self.sock.makefile()
-- 
1.6.0.2




[Qemu-devel] [PATCH v2 15/15] QMP: Add support for buffer class to qmp python helper

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

This demonstrates the conversion of QMP buffer objects and does some
minimalistic pretty-printing.

Signed-off-by: Jan Kiszka 
---
 QMP/qmp.py |   25 +++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/QMP/qmp.py b/QMP/qmp.py
index 4062f84..67ca8b9 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -8,7 +8,7 @@
 # This work is licensed under the terms of the GNU GPL, version 2.  See
 # the COPYING file in the top-level directory.
 
-import socket, json
+import socket, json, binascii
 
 class QMPError(Exception):
 pass
@@ -16,6 +16,18 @@ class QMPError(Exception):
 class QMPConnectError(QMPError):
 pass
 
+class QMPBuffer:
+def __init__(self, data):
+self.data = binascii.a2b_base64(data)
+
+def __repr__(self):
+str = ''
+for i in range(0, len(self.data) - 1):
+if i > 0:
+str += ' '
+str += binascii.b2a_hex(self.data[i])
+return str
+
 class QEMUMonitorProtocol:
 def connect(self):
 self.sock.connect(self.filename)
@@ -61,10 +73,19 @@ class QEMUMonitorProtocol:
 # the Server won't read our input
 self.sock.send(json.dumps(cmd) + ' ')
 
+def __json_obj_hook(self, dct):
+if '__class__' in dct:
+if dct['__class__'] == 'buffer':
+return QMPBuffer(dct['data'])
+else:
+return
+return dct
+
 def __json_read(self):
 try:
 while True:
-line = json.loads(self.sockfile.readline())
+line = json.loads(self.sockfile.readline(),
+  object_hook=self.__json_obj_hook)
 if not 'event' in line:
 return line
 except ValueError:
-- 
1.6.0.2




[Qemu-devel] [PATCH v2 11/15] monitor: return length of printed string via monitor_[v]printf

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

This simply forwards the result of the internal vsnprintf to the callers
of monitor_printf and monitor_vprintf. When invoked over a QMP session
or in absence of an active monitor, -1 is returned.

Signed-off-by: Jan Kiszka 
---
 monitor.c   |   23 +++
 monitor.h   |4 ++--
 qemu-tool.c |6 --
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/monitor.c b/monitor.c
index 64de10a..6766e49 100644
--- a/monitor.c
+++ b/monitor.c
@@ -258,29 +258,36 @@ static void monitor_puts(Monitor *mon, const char *str)
 }
 }
 
-void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
+int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
 char buf[4096];
+int ret;
 
-if (!mon)
-return;
-
+if (!mon) {
+return -1;
+}
 mon_print_count_inc(mon);
 
 if (monitor_ctrl_mode(mon)) {
-return;
+return -1;
 }
 
-vsnprintf(buf, sizeof(buf), fmt, ap);
+ret = vsnprintf(buf, sizeof(buf), fmt, ap);
 monitor_puts(mon, buf);
+
+return ret;
 }
 
-void monitor_printf(Monitor *mon, const char *fmt, ...)
+int monitor_printf(Monitor *mon, const char *fmt, ...)
 {
 va_list ap;
+int ret;
+
 va_start(ap, fmt);
-monitor_vprintf(mon, fmt, ap);
+ret = monitor_vprintf(mon, fmt, ap);
 va_end(ap);
+
+return ret;
 }
 
 void monitor_print_filename(Monitor *mon, const char *filename)
diff --git a/monitor.h b/monitor.h
index ea15469..32c0170 100644
--- a/monitor.h
+++ b/monitor.h
@@ -45,8 +45,8 @@ int monitor_read_bdrv_key_start(Monitor *mon, 
BlockDriverState *bs,
 
 int monitor_get_fd(Monitor *mon, const char *fdname);
 
-void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap);
-void monitor_printf(Monitor *mon, const char *fmt, ...)
+int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap);
+int monitor_printf(Monitor *mon, const char *fmt, ...)
 __attribute__ ((__format__ (__printf__, 2, 3)));
 void monitor_print_filename(Monitor *mon, const char *filename);
 void monitor_flush(Monitor *mon);
diff --git a/qemu-tool.c b/qemu-tool.c
index b39af86..f6ce6cd 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -43,12 +43,14 @@ void monitor_set_error(Monitor *mon, QError *qerror)
 {
 }
 
-void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
+int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
+return -1;
 }
 
-void monitor_printf(Monitor *mon, const char *fmt, ...)
+int monitor_printf(Monitor *mon, const char *fmt, ...)
 {
+return -1;
 }
 
 void monitor_print_filename(Monitor *mon, const char *filename)
-- 
1.6.0.2




[Qemu-devel] Re: [PATCH] sparc32 protect read-only bits in DMA CSR registers

2010-05-22 Thread Artyom Tarasenko
2010/5/22 Blue Swirl :
> On Fri, May 21, 2010 at 9:53 PM, Artyom Tarasenko
>  wrote:
>> On a real hardware changing read-only bits has no effect
>> Use a mask common for SCSI and Ethernet registers. The crucial
>> bit is DMA_INTR, because setting or clearing it may produce
>> spurious interrupts.
>>
>> This patch allows booting Solaris 2.3
>
> Great!
>
>> Signed-off-by: Artyom Tarasenko 
>> ---
>>  hw/sparc32_dma.c |   11 +++
>>  1 files changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/sparc32_dma.c b/hw/sparc32_dma.c
>> index 3ceb851..d54e165 100644
>> --- a/hw/sparc32_dma.c
>> +++ b/hw/sparc32_dma.c
>> @@ -62,6 +62,9 @@
>>  #define DMA_DRAIN_FIFO 0x40
>>  #define DMA_RESET 0x80
>>
>> +/* XXX SCSI and ethernet should have different read-only bit masks */
>> +#define DMA_CSR_RO_MASK 0xfe07
>
> I'm preparing (again) some generic DMA patches, it looks like I have
> to make Lance and ESP DMA controllers separate.

Good idea! They are too different. And also if we remember that there
is a parallel port dma too...
Are you splitting them just to improve the design, or are you adding
some features too?
A Test CSR register in the Lance would be great: it would allow
network boot with OBP (which is the default when it's used with qemu)
and hence automated Solaris boot tests.

> Your patch highlights
> yet another problem with the current shared design. This part of the
> patch is fine.
>
>> +
>>  typedef struct DMAState DMAState;
>>
>>  struct DMAState {
>> @@ -187,7 +190,7 @@ static void dma_mem_writel(void *opaque, 
>> target_phys_addr_t addr, uint32_t val)
>>     switch (saddr) {
>>     case 0:
>>         if (val & DMA_INTREN) {
>> -            if (val & DMA_INTR) {
>> +            if (s->dmaregs[0] & DMA_INTR) {
>
> Doesn't this change the way irqs are raised so that a pending irq is
> only generated on the write access _after_ the access that enables the
> irq. Currently we check for pending irqs immediately when the irq is
> enabled.

No, we still check for _pending_ irqs immediately, but don't allow
making a spurious interrupt by writing 1 to the DMA_INTR bit.

And frankly speaking I don't think timing can be a problem here:  the
real hardware would have some latency too.

Unless you have a test case which I broke...

>>                 DPRINTF("Raise IRQ\n");
>>                 qemu_irq_raise(s->irq);
>>             }
>> @@ -204,16 +207,16 @@ static void dma_mem_writel(void *opaque, 
>> target_phys_addr_t addr, uint32_t val)
>>             val &= ~DMA_DRAIN_FIFO;
>>         } else if (val == 0)
>>             val = DMA_DRAIN_FIFO;
>> -        val &= 0x0fff;
>> +        val &= ~DMA_CSR_RO_MASK;
>>         val |= DMA_VER;
>> +        s->dmaregs[0] = (s->dmaregs[0] & DMA_CSR_RO_MASK) | val;
>>         break;
>>     case 1:
>>         s->dmaregs[0] |= DMA_LOADED;
>> -        break;
>
> A comment about fall through should be added.

ok.

>>     default:
>> +        s->dmaregs[saddr] = val;
>>         break;
>>     }
>> -    s->dmaregs[saddr] = val;
>>  }
>>
>>  static CPUReadMemoryFunc * const dma_mem_read[3] = {
>> --
>> 1.6.2.5
>>
>>
>



-- 
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/



[Qemu-devel] [PATCH v2 13/15] QMP: Teach basic capability negotiation to python example

2010-05-22 Thread Jan Kiszka
From: Jan Kiszka 

As sending "qmp_capabilities" on session start became mandatory, both
python examples were broken.

Signed-off-by: Jan Kiszka 
---
 QMP/qmp-shell |1 +
 QMP/vm-info   |1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/QMP/qmp-shell b/QMP/qmp-shell
index f89b9af..a5b72d1 100755
--- a/QMP/qmp-shell
+++ b/QMP/qmp-shell
@@ -42,6 +42,7 @@ def main():
 
 qemu = qmp.QEMUMonitorProtocol(argv[1])
 qemu.connect()
+qemu.send("qmp_capabilities")
 
 print 'Connected!'
 
diff --git a/QMP/vm-info b/QMP/vm-info
index b150d82..d29e7f5 100755
--- a/QMP/vm-info
+++ b/QMP/vm-info
@@ -24,6 +24,7 @@ def main():
 
 qemu = qmp.QEMUMonitorProtocol(argv[1])
 qemu.connect()
+qemu.send("qmp_capabilities")
 
 for cmd in [ 'version', 'hpet', 'kvm', 'status', 'uuid', 'balloon' ]:
 print cmd + ': ' + str(qemu.send('query-' + cmd))
-- 
1.6.0.2




[Qemu-devel] Re: [PATCH] sparc32 protect read-only bits in DMA CSR registers

2010-05-22 Thread Blue Swirl
On Fri, May 21, 2010 at 9:53 PM, Artyom Tarasenko
 wrote:
> On a real hardware changing read-only bits has no effect
> Use a mask common for SCSI and Ethernet registers. The crucial
> bit is DMA_INTR, because setting or clearing it may produce
> spurious interrupts.
>
> This patch allows booting Solaris 2.3

Great!

> Signed-off-by: Artyom Tarasenko 
> ---
>  hw/sparc32_dma.c |   11 +++
>  1 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/hw/sparc32_dma.c b/hw/sparc32_dma.c
> index 3ceb851..d54e165 100644
> --- a/hw/sparc32_dma.c
> +++ b/hw/sparc32_dma.c
> @@ -62,6 +62,9 @@
>  #define DMA_DRAIN_FIFO 0x40
>  #define DMA_RESET 0x80
>
> +/* XXX SCSI and ethernet should have different read-only bit masks */
> +#define DMA_CSR_RO_MASK 0xfe07

I'm preparing (again) some generic DMA patches, it looks like I have
to make Lance and ESP DMA controllers separate. Your patch highlights
yet another problem with the current shared design. This part of the
patch is fine.

> +
>  typedef struct DMAState DMAState;
>
>  struct DMAState {
> @@ -187,7 +190,7 @@ static void dma_mem_writel(void *opaque, 
> target_phys_addr_t addr, uint32_t val)
>     switch (saddr) {
>     case 0:
>         if (val & DMA_INTREN) {
> -            if (val & DMA_INTR) {
> +            if (s->dmaregs[0] & DMA_INTR) {

Doesn't this change the way irqs are raised so that a pending irq is
only generated on the write access _after_ the access that enables the
irq. Currently we check for pending irqs immediately when the irq is
enabled.

>                 DPRINTF("Raise IRQ\n");
>                 qemu_irq_raise(s->irq);
>             }
> @@ -204,16 +207,16 @@ static void dma_mem_writel(void *opaque, 
> target_phys_addr_t addr, uint32_t val)
>             val &= ~DMA_DRAIN_FIFO;
>         } else if (val == 0)
>             val = DMA_DRAIN_FIFO;
> -        val &= 0x0fff;
> +        val &= ~DMA_CSR_RO_MASK;
>         val |= DMA_VER;
> +        s->dmaregs[0] = (s->dmaregs[0] & DMA_CSR_RO_MASK) | val;
>         break;
>     case 1:
>         s->dmaregs[0] |= DMA_LOADED;
> -        break;

A comment about fall through should be added.

>     default:
> +        s->dmaregs[saddr] = val;
>         break;
>     }
> -    s->dmaregs[saddr] = val;
>  }
>
>  static CPUReadMemoryFunc * const dma_mem_read[3] = {
> --
> 1.6.2.5
>
>



[Qemu-devel] [Bug 584121] [NEW] migration always fails on 32bit qemu-kvm-0.12+ (sigsegv)

2010-05-22 Thread Michael Tokarev
Public bug reported:

On a 32bit host (or when running 32bit userspace on 64bit host), migration 
always fails with a crash of qemu-kvm process.
See http://marc.info/?l=kvm&m=127351472231666 for more information.

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
migration always fails on 32bit qemu-kvm-0.12+ (sigsegv)
https://bugs.launchpad.net/bugs/584121
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
On a 32bit host (or when running 32bit userspace on 64bit host), migration 
always fails with a crash of qemu-kvm process.
See http://marc.info/?l=kvm&m=127351472231666 for more information.





[Qemu-devel] [PATCH] sparc32 protect read-only bits in DMA CSR registers

2010-05-22 Thread Artyom Tarasenko
On a real hardware changing read-only bits has no effect
Use a mask common for SCSI and Ethernet registers. The crucial
bit is DMA_INTR, because setting or clearing it may produce
spurious interrupts.

This patch allows booting Solaris 2.3
---
 hw/sparc32_dma.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/sparc32_dma.c b/hw/sparc32_dma.c
index 3ceb851..b521707 100644
--- a/hw/sparc32_dma.c
+++ b/hw/sparc32_dma.c
@@ -62,6 +62,9 @@
 #define DMA_DRAIN_FIFO 0x40
 #define DMA_RESET 0x80
 
+/* XXX SCSI and ethernet should have different read-only bit masks */
+#define DMA_CSR_RO_MASK 0xfe07
+
 typedef struct DMAState DMAState;
 
 struct DMAState {
@@ -187,7 +190,7 @@ static void dma_mem_writel(void *opaque, target_phys_addr_t 
addr, uint32_t val)
 switch (saddr) {
 case 0:
 if (val & DMA_INTREN) {
-if (val & DMA_INTR) {
+if (s->dmaregs[0] & DMA_INTR) {
 DPRINTF("Raise IRQ\n");
 qemu_irq_raise(s->irq);
 }
@@ -204,16 +207,17 @@ static void dma_mem_writel(void *opaque, 
target_phys_addr_t addr, uint32_t val)
 val &= ~DMA_DRAIN_FIFO;
 } else if (val == 0)
 val = DMA_DRAIN_FIFO;
-val &= 0x0fff;
+val &= ~DMA_CSR_RO_MASK;
 val |= DMA_VER;
+s->dmaregs[0] = (s->dmaregs[0] & DMA_CSR_RO_MASK) | val;
 break;
 case 1:
 s->dmaregs[0] |= DMA_LOADED;
-break;
+/* fall through */
 default:
+s->dmaregs[saddr] = val;
 break;
 }
-s->dmaregs[saddr] = val;
 }
 
 static CPUReadMemoryFunc * const dma_mem_read[3] = {
-- 
1.6.2.5




[Qemu-devel] [Bug 584131] [NEW] some guests hangs after migration (qemu-kvm-0.12)

2010-05-22 Thread Michael Tokarev
Public bug reported:

There's a quite good bugreport in Debian BTS about this, #580649:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=580649

This is not the same as lp#341682, since it's now 0.12.

Full initial message from #580649:


From: Apollon Oikonomopoulos 
To: Debian Bug Tracking System 
Subject: qemu-kvm: Guests hang after live migration
Date: Fri, 07 May 2010 16:29:10 +0300

Package: qemu-kvm
Version: 0.12.3+dfsg-4
Severity: important

Hi,

qemu-kvm 0.12.3 causes guests to hang after a live migration. The crash seems
to be related to the guest's virtio subsystem, as per the following backtrace
obtained _in the guest_:

May  7 14:17:32 kot kernel: [  285.035681] irq 11: nobody cared (try booting 
with the "irqpoll" option)
May  7 14:17:32 kot kernel: [  285.035681] Pid: 0, comm: swapper Not tainted 
2.6.26-2-amd64 #1
May  7 14:17:32 kot kernel: [  285.035681]
May  7 14:17:32 kot kernel: [  285.035681] Call Trace:
May  7 14:17:32 kot kernel: [  285.035681][] 
:virtio_pci:vp_interrupt+0x27/0xb8
May  7 14:17:32 kot kernel: [  285.035681]  [] 
__report_bad_irq+0x30/0x72
May  7 14:17:32 kot kernel: [  285.035681]  [] 
note_interrupt+0x1fd/0x23b
May  7 14:17:32 kot kernel: [  285.035681]  [] 
handle_fasteoi_irq+0xa5/0xc8
May  7 14:17:32 kot kernel: [  285.035681]  [] 
do_IRQ+0x6d/0xd9
May  7 14:17:32 kot kernel: [  285.035681]  [] 
default_idle+0x0/0x49
May  7 14:17:32 kot kernel: [  285.035681]  [] 
ret_from_intr+0x0/0x19
May  7 14:17:32 kot kernel: [  285.035681][] 
lapic_next_event+0x0/0x13
May  7 14:17:32 kot kernel: [  285.035681]  [] 
native_safe_halt+0x2/0x3
May  7 14:17:32 kot kernel: [  285.035681]  [] 
native_safe_halt+0x2/0x3
May  7 14:17:32 kot kernel: [  285.035681]  [] 
default_idle+0x2a/0x49
May  7 14:17:32 kot kernel: [  285.035681]  [] 
cpu_idle+0x8e/0xb8
May  7 14:17:32 kot kernel: [  285.035681]
May  7 14:17:32 kot kernel: [  285.035681] handlers:
May  7 14:17:32 kot kernel: [  285.035681] [] 
(usb_hcd_irq+0x0/0x78)
May  7 14:17:32 kot kernel: [  285.035681] [] 
(vp_interrupt+0x0/0xb8 [virtio_pci])
May  7 14:17:32 kot kernel: [  285.035681] Disabling IRQ #11

This happens in a reproducible fashion on a guest with the following
setup:

  * Virtio net + block devices
  * 8 CPU SMP
  * 521 MB RAM
  * Debian Lenny with 2.6.26-2-amd64

Just migrating the guest a couple of times with a bit of I/O activity will
cause it to freeze completely.

It does *not* seem to impact the following:
  * Guests with no virtio devices
  * Guests running 2.6.32-4-amd64 
  * Guests running under qemu-kvm-0.11.1

Thus, it seems to be virtio-specific and possibly related to the guest kernel,
but since qemu-kvm-0.11.1 works fine, I'm filing it as a qemu-kvm regression
and not a kernel bug.

Thank you

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
some guests hangs after migration (qemu-kvm-0.12)
https://bugs.launchpad.net/bugs/584131
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
There's a quite good bugreport in Debian BTS about this, #580649: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=580649

This is not the same as lp#341682, since it's now 0.12.

Full initial message from #580649:


From: Apollon Oikonomopoulos 
To: Debian Bug Tracking System 
Subject: qemu-kvm: Guests hang after live migration
Date: Fri, 07 May 2010 16:29:10 +0300

Package: qemu-kvm
Version: 0.12.3+dfsg-4
Severity: important

Hi,

qemu-kvm 0.12.3 causes guests to hang after a live migration. The crash seems
to be related to the guest's virtio subsystem, as per the following backtrace
obtained _in the guest_:

May  7 14:17:32 kot kernel: [  285.035681] irq 11: nobody cared (try booting 
with the "irqpoll" option)
May  7 14:17:32 kot kernel: [  285.035681] Pid: 0, comm: swapper Not tainted 
2.6.26-2-amd64 #1
May  7 14:17:32 kot kernel: [  285.035681]
May  7 14:17:32 kot kernel: [  285.035681] Call Trace:
May  7 14:17:32 kot kernel: [  285.035681][] 
:virtio_pci:vp_interrupt+0x27/0xb8
May  7 14:17:32 kot kernel: [  285.035681]  [] 
__report_bad_irq+0x30/0x72
May  7 14:17:32 kot kernel: [  285.035681]  [] 
note_interrupt+0x1fd/0x23b
May  7 14:17:32 kot kernel: [  285.035681]  [] 
handle_fasteoi_irq+0xa5/0xc8
May  7 14:17:32 kot kernel: [  285.035681]  [] 
do_IRQ+0x6d/0xd9
May  7 14:17:32 kot kernel: [  285.035681]  [] 
default_idle+0x0/0x49
May  7 14:17:32 kot kernel: [  285.035681]  [] 
ret_from_intr+0x0/0x19
May  7 14:17:32 kot kernel: [  285.035681][] 
lapic_next_event+0x0/0x13
May  7 14:17:32 kot kernel: [  285.035681]  [] 
native_safe_halt+0x2/0x3
May  7 14:17:32 kot kernel: [  285.035681]  [] 
native_safe_halt+0x2/0x3
May  7 14:17:32 kot kernel: [  285.035681]  [] 
default_idle+0x2a/0x49
May  7 14:17:32 kot kernel: [  285.035681]  [] 
cpu_idle+0x8e/0xb8
May  7 14:17:32 kot kernel: [  285.035681]
May  7 14:17:32 kot kernel: [  285.035681] handlers:
May  7 14:17:32 kot kernel: [  285.

[Qemu-devel] Re: [PATCH] sparc32 protect read-only bits in DMA CSR registers

2010-05-22 Thread Blue Swirl
Thanks, applied. You forgot SoB-line, I copied it from the previous version.

On Sat, May 22, 2010 at 8:38 AM, Artyom Tarasenko
 wrote:
> On a real hardware changing read-only bits has no effect
> Use a mask common for SCSI and Ethernet registers. The crucial
> bit is DMA_INTR, because setting or clearing it may produce
> spurious interrupts.
>
> This patch allows booting Solaris 2.3
> ---
>  hw/sparc32_dma.c |   12 
>  1 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/hw/sparc32_dma.c b/hw/sparc32_dma.c
> index 3ceb851..b521707 100644
> --- a/hw/sparc32_dma.c
> +++ b/hw/sparc32_dma.c
> @@ -62,6 +62,9 @@
>  #define DMA_DRAIN_FIFO 0x40
>  #define DMA_RESET 0x80
>
> +/* XXX SCSI and ethernet should have different read-only bit masks */
> +#define DMA_CSR_RO_MASK 0xfe07
> +
>  typedef struct DMAState DMAState;
>
>  struct DMAState {
> @@ -187,7 +190,7 @@ static void dma_mem_writel(void *opaque, 
> target_phys_addr_t addr, uint32_t val)
>     switch (saddr) {
>     case 0:
>         if (val & DMA_INTREN) {
> -            if (val & DMA_INTR) {
> +            if (s->dmaregs[0] & DMA_INTR) {
>                 DPRINTF("Raise IRQ\n");
>                 qemu_irq_raise(s->irq);
>             }
> @@ -204,16 +207,17 @@ static void dma_mem_writel(void *opaque, 
> target_phys_addr_t addr, uint32_t val)
>             val &= ~DMA_DRAIN_FIFO;
>         } else if (val == 0)
>             val = DMA_DRAIN_FIFO;
> -        val &= 0x0fff;
> +        val &= ~DMA_CSR_RO_MASK;
>         val |= DMA_VER;
> +        s->dmaregs[0] = (s->dmaregs[0] & DMA_CSR_RO_MASK) | val;
>         break;
>     case 1:
>         s->dmaregs[0] |= DMA_LOADED;
> -        break;
> +        /* fall through */
>     default:
> +        s->dmaregs[saddr] = val;
>         break;
>     }
> -    s->dmaregs[saddr] = val;
>  }
>
>  static CPUReadMemoryFunc * const dma_mem_read[3] = {
> --
> 1.6.2.5
>
>



[Qemu-devel] [Bug 584139] [NEW] keymapping error for usb keyboard (windows/menu keys)

2010-05-22 Thread Michael Tokarev
Public bug reported:

The windows and menu keys for usb keyboard in qemu are wrong.  They're
correct for "ps/2" keyboard emulation however.  See Debian bug#578846:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578846.

Here's the proposed fix:

--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -399,3 +399,3 @@
 0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: patch

** Tags added: patch

-- 
keymapping error for usb keyboard (windows/menu keys)
https://bugs.launchpad.net/bugs/584139
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
The windows and menu keys for usb keyboard in qemu are wrong.  They're correct 
for "ps/2" keyboard emulation however.  See Debian bug#578846: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578846.

Here's the proposed fix:

--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -399,3 +399,3 @@
 0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,





[Qemu-devel] Re: [PATCH] sparc32 protect read-only bits in DMA CSR registers

2010-05-22 Thread Blue Swirl
On Sat, May 22, 2010 at 8:32 AM, Artyom Tarasenko
 wrote:
> 2010/5/22 Blue Swirl :
>> On Fri, May 21, 2010 at 9:53 PM, Artyom Tarasenko
>>  wrote:
>>> On a real hardware changing read-only bits has no effect
>>> Use a mask common for SCSI and Ethernet registers. The crucial
>>> bit is DMA_INTR, because setting or clearing it may produce
>>> spurious interrupts.
>>>
>>> This patch allows booting Solaris 2.3
>>
>> Great!
>>
>>> Signed-off-by: Artyom Tarasenko 
>>> ---
>>>  hw/sparc32_dma.c |   11 +++
>>>  1 files changed, 7 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/hw/sparc32_dma.c b/hw/sparc32_dma.c
>>> index 3ceb851..d54e165 100644
>>> --- a/hw/sparc32_dma.c
>>> +++ b/hw/sparc32_dma.c
>>> @@ -62,6 +62,9 @@
>>>  #define DMA_DRAIN_FIFO 0x40
>>>  #define DMA_RESET 0x80
>>>
>>> +/* XXX SCSI and ethernet should have different read-only bit masks */
>>> +#define DMA_CSR_RO_MASK 0xfe07
>>
>> I'm preparing (again) some generic DMA patches, it looks like I have
>> to make Lance and ESP DMA controllers separate.
>
> Good idea! They are too different. And also if we remember that there
> is a parallel port dma too...

Also cs4231.

> Are you splitting them just to improve the design, or are you adding
> some features too?

No new features, it's just needed by the overall design.

> A Test CSR register in the Lance would be great: it would allow
> network boot with OBP (which is the default when it's used with qemu)
> and hence automated Solaris boot tests.
>
>> Your patch highlights
>> yet another problem with the current shared design. This part of the
>> patch is fine.
>>
>>> +
>>>  typedef struct DMAState DMAState;
>>>
>>>  struct DMAState {
>>> @@ -187,7 +190,7 @@ static void dma_mem_writel(void *opaque, 
>>> target_phys_addr_t addr, uint32_t val)
>>>     switch (saddr) {
>>>     case 0:
>>>         if (val & DMA_INTREN) {
>>> -            if (val & DMA_INTR) {
>>> +            if (s->dmaregs[0] & DMA_INTR) {
>>
>> Doesn't this change the way irqs are raised so that a pending irq is
>> only generated on the write access _after_ the access that enables the
>> irq. Currently we check for pending irqs immediately when the irq is
>> enabled.
>
> No, we still check for _pending_ irqs immediately, but don't allow
> making a spurious interrupt by writing 1 to the DMA_INTR bit.
>
> And frankly speaking I don't think timing can be a problem here:  the
> real hardware would have some latency too.
>
> Unless you have a test case which I broke...
>
>>>                 DPRINTF("Raise IRQ\n");
>>>                 qemu_irq_raise(s->irq);
>>>             }
>>> @@ -204,16 +207,16 @@ static void dma_mem_writel(void *opaque, 
>>> target_phys_addr_t addr, uint32_t val)
>>>             val &= ~DMA_DRAIN_FIFO;
>>>         } else if (val == 0)
>>>             val = DMA_DRAIN_FIFO;
>>> -        val &= 0x0fff;
>>> +        val &= ~DMA_CSR_RO_MASK;
>>>         val |= DMA_VER;
>>> +        s->dmaregs[0] = (s->dmaregs[0] & DMA_CSR_RO_MASK) | val;
>>>         break;
>>>     case 1:
>>>         s->dmaregs[0] |= DMA_LOADED;
>>> -        break;
>>
>> A comment about fall through should be added.
>
> ok.
>
>>>     default:
>>> +        s->dmaregs[saddr] = val;
>>>         break;
>>>     }
>>> -    s->dmaregs[saddr] = val;
>>>  }
>>>
>>>  static CPUReadMemoryFunc * const dma_mem_read[3] = {
>>> --
>>> 1.6.2.5
>>>
>>>
>>
>
>
>
> --
> Regards,
> Artyom Tarasenko
>
> solaris/sparc under qemu blog: http://tyom.blogspot.com/
>



Re: [Qemu-devel] [PATCH 2/2] hxtool: Add syntax error detection

2010-05-22 Thread Blue Swirl
Thanks, applied.

On Thu, May 20, 2010 at 7:16 AM, Jan Kiszka  wrote:
> From: Jan Kiszka 
>
> Add basic imbalance detection for STEXT/ETEXI.
>
> Signed-off-by: Jan Kiszka 
> ---
>  hxtool |   16 +++-
>  1 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/hxtool b/hxtool
> index 0fdbc64..8f65532 100644
> --- a/hxtool
> +++ b/hxtool
> @@ -19,11 +19,24 @@ hxtoh()
>  hxtotexi()
>  {
>     flag=0
> +    line=1
>     while read -r str; do
>         case "$str" in
>             HXCOMM*)
>             ;;
> -            STEXI*|ETEXI*) flag=$(($flag^1))
> +            STEXI*)
> +            if test $flag -eq 1 ; then
> +                echo "line $line: syntax error: expected ETEXI, found $str" 
> >&2
> +                exit 1
> +            fi
> +            flag=1
> +            ;;
> +            ETEXI*)
> +            if test $flag -ne 1 ; then
> +                echo "line $line: syntax error: expected STEXI, found $str" 
> >&2
> +                exit 1
> +            fi
> +            flag=0
>             ;;
>             DEFHEADING*)
>             echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
> @@ -32,6 +45,7 @@ hxtotexi()
>             test $flag -eq 1 && echo "$str"
>             ;;
>         esac
> +        line=$((line+1))
>     done
>  }
>
> --
> 1.6.0.2
>
>


Re: [Qemu-devel] [PATCH] Clean libhw subdirs as well

2010-05-22 Thread Blue Swirl
Thanks, applied.

On Sat, May 15, 2010 at 11:03 AM, Jan Kiszka  wrote:
> From: Jan Kiszka 
>
> Signed-off-by: Jan Kiszka 
> ---
>  Makefile.hw |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/Makefile.hw b/Makefile.hw
> index be35359..b9181ab 100644
> --- a/Makefile.hw
> +++ b/Makefile.hw
> @@ -18,7 +18,7 @@ all: $(hw-obj-y)
>       �...@true
>
>  clean:
> -       rm -f *.o *.d *.a *~
> +       rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~
>
>  # Include automatically generated dependency files
>  -include $(wildcard *.d */*.d)
> --
> 1.6.0.2
>
>



Re: [Qemu-devel] [PATCH 1/2] Fix TEXI section mark imbalance in qemu-img-cmd.hx

2010-05-22 Thread Blue Swirl
Thanks, applied.

On Thu, May 20, 2010 at 7:16 AM, Jan Kiszka  wrote:
> From: Jan Kiszka 
>
> Signed-off-by: Jan Kiszka 
> ---
>  qemu-img-cmds.hx |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
> index c079019..c4cf3e7 100644
> --- a/qemu-img-cmds.hx
> +++ b/qemu-img-cmds.hx
> @@ -7,7 +7,7 @@ HXCOMM HXCOMM can be used for comments, discarded from
> both texi and C
>
>  STEXI
> �...@table @option
> -STEXI
> +ETEXI
>
>  DEF("check", img_check,
>     "check [-f fmt] filename")
> --
> 1.6.0.2
>
>



Re: [Qemu-devel] [PATCH] Put dependency files in proper subdir

2010-05-22 Thread Blue Swirl
Thanks, applied.

On Sat, May 15, 2010 at 11:03 AM, Jan Kiszka  wrote:
> From: Jan Kiszka 
>
> This seems to resolve subtle breakages of our build system:
>
> Dependency files generated for targets like 'dir/foo.o' were saved as
> 'foo.d'. Now, if there was also a target 'foo.o', one of the dependency
> file was overwritten. Concrete example: libhw*/macio.o vs.
> libhw*/ide/macio.o. And this often left a segfaulting build result
> behind when changing the "wrong" data structures".
>
> Fix it by generating proper 'dir/foo.d'.
>
> Signed-off-by: Jan Kiszka 
> ---
>  rules.mak |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/rules.mak b/rules.mak
> index 7e10432..c843a13 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -12,7 +12,7 @@ MAKEFLAGS += -rR
>  %.mak:
>
>  # Flags for dependency generation
> -QEMU_DGFLAGS += -MMD -MP -MT $@
> +QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
>
>  %.o: %.c
>        $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c
> -o $@ $<,"  CC    $(TARGET_DIR)$@")
> --
> 1.6.0.2
>
>



Re: [Qemu-devel] [PATCH v2] Fix -device help and documentation

2010-05-22 Thread Blue Swirl
Thanks, applied.

On Tue, May 11, 2010 at 12:02 PM, Markus Armbruster  wrote:
> Commit 6616b2ad reverted commit 40ea285c.  Looks like a mismerge to
> me.
>
> Signed-off-by: Markus Armbruster 
> ---
> v2: rebased (v1 fell through the cracks apparently)
>
>  qemu-options.hx |   15 ++-
>  1 files changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 12f6b51..03e95fd 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -464,18 +464,15 @@ DEF("device", HAS_ARG, QEMU_OPTION_device,
>     "                add device (based on driver)\n"
>     "                prop=value,... sets driver properties\n"
>     "                use -device ? to print all possible drivers\n"
> -    "                use -device driver,? to print all possible options\n"
> -    "                use -device driver,option=? to print a help for 
> value\n",
> +    "                use -device driver,? to print all possible 
> properties\n",
>     QEMU_ARCH_ALL)
>  STEXI
> -...@item -device @var{driver}[,@var{option...@var{value}][,...]]
> +...@item -device @var{driver}[,@var{prop...@var{value}][,...]]
> �...@findex -device
> -Add device @var{driver}. Depending on the device type,
> -...@var{option} (with default or given @var{value}) may be useful.
> -To get a help on possible @var{driver}s, @var{option}s or @var{value}s, use
> -...@code{-device ?},
> -...@code{-device @var{driver},?} or
> -...@code{-device @var{driver},@var{option}=?}.
> +Add device @var{driver}. �...@var{prop}=@var{value} sets driver
> +properties.  Valid properties depend on the driver.  To get help on
> +possible drivers and properties, use @code{-device ?} and
> +...@code{-device @var{driver},?}.
>  ETEXI
>
>  #ifdef CONFIG_LINUX
> --
> 1.6.6.1
>
>
>



Re: [Qemu-devel] [PATCH] Fix tarbin Makefile rule

2010-05-22 Thread Blue Swirl
Thanks, applied.

On Wed, May 12, 2010 at 7:42 PM, Stuart Brady  wrote:
> The 'tarbin' Makefile rule doesn't include qemu-system-sparc64, but
> should do, now that sparc64-softmmu is in the default target list.
>
> The rule attempts to tar up binaries that were not built if a target
> list was passed to the configure script -- in which case, it will
> either fail, or otherwise include binaries from previous builds.
>
> Fix both problems once and for all by building a list of binaries to
> include in the tarball, using the list of targets to be built.
>
> Signed-off-by: Stuart Brady 
> ---
> diff --git a/Makefile b/Makefile
> index eb9e02b..25c825c 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -298,43 +298,22 @@ tar:
>        cd /tmp && tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS --exclude 
> .git --exclude .svn
>        rm -rf /tmp/$(FILE)
>
> +SYSTEM_TARGETS=$(filter %-softmmu,$(TARGET_DIRS))
> +SYSTEM_PROGS=$(patsubst qemu-system-i386,qemu, \
> +             $(patsubst %-softmmu,qemu-system-%, \
> +             $(SYSTEM_TARGETS)))
> +
> +USER_TARGETS=$(filter %-user,$(TARGET_DIRS))
> +USER_PROGS=$(patsubst %-bsd-user,qemu-%, \
> +           $(patsubst %-darwin-user,qemu-%, \
> +           $(patsubst %-linux-user,qemu-%, \
> +           $(USER_TARGETS
> +
>  # generate a binary distribution
>  tarbin:
>        cd / && tar zcvf ~/qemu-$(VERSION)-$(ARCH).tar.gz \
> -       $(bindir)/qemu \
> -       $(bindir)/qemu-system-x86_64 \
> -       $(bindir)/qemu-system-arm \
> -       $(bindir)/qemu-system-cris \
> -       $(bindir)/qemu-system-m68k \
> -       $(bindir)/qemu-system-microblaze \
> -       $(bindir)/qemu-system-mips \
> -       $(bindir)/qemu-system-mipsel \
> -       $(bindir)/qemu-system-mips64 \
> -       $(bindir)/qemu-system-mips64el \
> -       $(bindir)/qemu-system-ppc \
> -       $(bindir)/qemu-system-ppcemb \
> -       $(bindir)/qemu-system-ppc64 \
> -       $(bindir)/qemu-system-sh4 \
> -       $(bindir)/qemu-system-sh4eb \
> -       $(bindir)/qemu-system-sparc \
> -       $(bindir)/qemu-i386 \
> -       $(bindir)/qemu-x86_64 \
> -       $(bindir)/qemu-alpha \
> -       $(bindir)/qemu-arm \
> -       $(bindir)/qemu-armeb \
> -       $(bindir)/qemu-cris \
> -       $(bindir)/qemu-m68k \
> -       $(bindir)/qemu-microblaze \
> -       $(bindir)/qemu-mips \
> -       $(bindir)/qemu-mipsel \
> -       $(bindir)/qemu-ppc \
> -       $(bindir)/qemu-ppc64 \
> -       $(bindir)/qemu-ppc64abi32 \
> -       $(bindir)/qemu-sh4 \
> -       $(bindir)/qemu-sh4eb \
> -       $(bindir)/qemu-sparc \
> -       $(bindir)/qemu-sparc64 \
> -       $(bindir)/qemu-sparc32plus \
> +       $(patsubst %,$(bindir)/%, $(SYSTEM_PROGS)) \
> +       $(patsubst %,$(bindir)/%, $(USER_PROGS)) \
>        $(bindir)/qemu-img \
>        $(bindir)/qemu-nbd \
>        $(datadir)/bios.bin \
>
>
>



[Qemu-devel] Re: [PATCH] sparc32 protect read-only bits in DMA CSR registers

2010-05-22 Thread Artyom Tarasenko
2010/5/22 Blue Swirl :
> Thanks, applied. You forgot SoB-line, I copied it from the previous version.

Sorry. Btw, is there a way to tell 'format-patch' to always include it?
Can't find it in the git docs. Otherwise I'll define an alias so I won't
need to remember about the '-s' switch.

> On Sat, May 22, 2010 at 8:38 AM, Artyom Tarasenko
>  wrote:
>> On a real hardware changing read-only bits has no effect
>> Use a mask common for SCSI and Ethernet registers. The crucial
>> bit is DMA_INTR, because setting or clearing it may produce
>> spurious interrupts.
>>
>> This patch allows booting Solaris 2.3
>> ---
>>  hw/sparc32_dma.c |   12 
>>  1 files changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/sparc32_dma.c b/hw/sparc32_dma.c
>> index 3ceb851..b521707 100644
>> --- a/hw/sparc32_dma.c
>> +++ b/hw/sparc32_dma.c
>> @@ -62,6 +62,9 @@
>>  #define DMA_DRAIN_FIFO 0x40
>>  #define DMA_RESET 0x80
>>
>> +/* XXX SCSI and ethernet should have different read-only bit masks */
>> +#define DMA_CSR_RO_MASK 0xfe07
>> +
>>  typedef struct DMAState DMAState;
>>
>>  struct DMAState {
>> @@ -187,7 +190,7 @@ static void dma_mem_writel(void *opaque, 
>> target_phys_addr_t addr, uint32_t val)
>>     switch (saddr) {
>>     case 0:
>>         if (val & DMA_INTREN) {
>> -            if (val & DMA_INTR) {
>> +            if (s->dmaregs[0] & DMA_INTR) {
>>                 DPRINTF("Raise IRQ\n");
>>                 qemu_irq_raise(s->irq);
>>             }
>> @@ -204,16 +207,17 @@ static void dma_mem_writel(void *opaque, 
>> target_phys_addr_t addr, uint32_t val)
>>             val &= ~DMA_DRAIN_FIFO;
>>         } else if (val == 0)
>>             val = DMA_DRAIN_FIFO;
>> -        val &= 0x0fff;
>> +        val &= ~DMA_CSR_RO_MASK;
>>         val |= DMA_VER;
>> +        s->dmaregs[0] = (s->dmaregs[0] & DMA_CSR_RO_MASK) | val;
>>         break;
>>     case 1:
>>         s->dmaregs[0] |= DMA_LOADED;
>> -        break;
>> +        /* fall through */
>>     default:
>> +        s->dmaregs[saddr] = val;
>>         break;
>>     }
>> -    s->dmaregs[saddr] = val;
>>  }
>>
>>  static CPUReadMemoryFunc * const dma_mem_read[3] = {
>> --
>> 1.6.2.5
>>
>>
>



-- 
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/



[Qemu-devel] [Bug 584143] [NEW] qemu fails to set hdd serial number

2010-05-22 Thread Michael Tokarev
Public bug reported:

The -drive ...,serial=xyz option is broken, at least in 0.12.  See
Debian bug#573439, http://bugs.debian.org/cgi-
bin/bugreport.cgi?bug=573439 for details.

The proposed fix from the original reporter:

--- qemu-kvm-0.12.3+dfsg/vl.c   2010-02-26 11:34:00.0 +0900
+++ qemu-kvm-0.12.3+dfsg.old/vl.c   2010-03-11 02:26:00.134217787 +0900
@@ -2397,7 +2397,7 @@
 dinfo->on_write_error = on_write_error;
 dinfo->opts = opts;
 if (serial)
-strncpy(dinfo->serial, serial, sizeof(serial));
+strncpy(dinfo->serial, serial, sizeof(dinfo->serial));
 QTAILQ_INSERT_TAIL(&drives, dinfo, next);
 if (is_extboot) {
 extboot_drive = dinfo;

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: patch

-- 
qemu fails to set hdd serial number
https://bugs.launchpad.net/bugs/584143
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
The -drive ...,serial=xyz option is broken, at least in 0.12.  See Debian 
bug#573439, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=573439 for details.

The proposed fix from the original reporter:

--- qemu-kvm-0.12.3+dfsg/vl.c   2010-02-26 11:34:00.0 +0900
+++ qemu-kvm-0.12.3+dfsg.old/vl.c   2010-03-11 02:26:00.134217787 +0900
@@ -2397,7 +2397,7 @@
 dinfo->on_write_error = on_write_error;
 dinfo->opts = opts;
 if (serial)
-strncpy(dinfo->serial, serial, sizeof(serial));
+strncpy(dinfo->serial, serial, sizeof(dinfo->serial));
 QTAILQ_INSERT_TAIL(&drives, dinfo, next);
 if (is_extboot) {
 extboot_drive = dinfo;





[Qemu-devel] Re: [PATCH] sparc32 protect read-only bits in DMA CSR registers

2010-05-22 Thread Blue Swirl
On Sat, May 22, 2010 at 9:29 AM, Artyom Tarasenko
 wrote:
> 2010/5/22 Blue Swirl :
>> Thanks, applied. You forgot SoB-line, I copied it from the previous version.
>
> Sorry. Btw, is there a way to tell 'format-patch' to always include it?
> Can't find it in the git docs. Otherwise I'll define an alias so I won't
> need to remember about the '-s' switch.

[format]
thread = true
signoff = true

Though format.thread (adds reference headers to the messages, so
patches reference the cover letter) does not seem to work with git
1.6.2.4.

>> On Sat, May 22, 2010 at 8:38 AM, Artyom Tarasenko
>>  wrote:
>>> On a real hardware changing read-only bits has no effect
>>> Use a mask common for SCSI and Ethernet registers. The crucial
>>> bit is DMA_INTR, because setting or clearing it may produce
>>> spurious interrupts.
>>>
>>> This patch allows booting Solaris 2.3
>>> ---
>>>  hw/sparc32_dma.c |   12 
>>>  1 files changed, 8 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/hw/sparc32_dma.c b/hw/sparc32_dma.c
>>> index 3ceb851..b521707 100644
>>> --- a/hw/sparc32_dma.c
>>> +++ b/hw/sparc32_dma.c
>>> @@ -62,6 +62,9 @@
>>>  #define DMA_DRAIN_FIFO 0x40
>>>  #define DMA_RESET 0x80
>>>
>>> +/* XXX SCSI and ethernet should have different read-only bit masks */
>>> +#define DMA_CSR_RO_MASK 0xfe07
>>> +
>>>  typedef struct DMAState DMAState;
>>>
>>>  struct DMAState {
>>> @@ -187,7 +190,7 @@ static void dma_mem_writel(void *opaque, 
>>> target_phys_addr_t addr, uint32_t val)
>>>     switch (saddr) {
>>>     case 0:
>>>         if (val & DMA_INTREN) {
>>> -            if (val & DMA_INTR) {
>>> +            if (s->dmaregs[0] & DMA_INTR) {
>>>                 DPRINTF("Raise IRQ\n");
>>>                 qemu_irq_raise(s->irq);
>>>             }
>>> @@ -204,16 +207,17 @@ static void dma_mem_writel(void *opaque, 
>>> target_phys_addr_t addr, uint32_t val)
>>>             val &= ~DMA_DRAIN_FIFO;
>>>         } else if (val == 0)
>>>             val = DMA_DRAIN_FIFO;
>>> -        val &= 0x0fff;
>>> +        val &= ~DMA_CSR_RO_MASK;
>>>         val |= DMA_VER;
>>> +        s->dmaregs[0] = (s->dmaregs[0] & DMA_CSR_RO_MASK) | val;
>>>         break;
>>>     case 1:
>>>         s->dmaregs[0] |= DMA_LOADED;
>>> -        break;
>>> +        /* fall through */
>>>     default:
>>> +        s->dmaregs[saddr] = val;
>>>         break;
>>>     }
>>> -    s->dmaregs[saddr] = val;
>>>  }
>>>
>>>  static CPUReadMemoryFunc * const dma_mem_read[3] = {
>>> --
>>> 1.6.2.5
>>>
>>>
>>
>
>
>
> --
> Regards,
> Artyom Tarasenko
>
> solaris/sparc under qemu blog: http://tyom.blogspot.com/
>



Re: [Qemu-devel] [PATCH][RESEND] vmstate: fix breakage by 7e72abc382b700a72549e8147bdea413534eeedc

2010-05-22 Thread Blue Swirl
Thanks, applied.

On Wed, May 12, 2010 at 2:28 AM, TeLeMan  wrote:
> cirrus_post_load() will be executed twice when loading vm states and then the
> wrong physical memory will be registered. This issue may lead to crash qemu.
>
> Signed-off-by: TeLeMan 
> ---
>  hw/cirrus_vga.c |    1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
>
> diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
> index 9dfe76a..262ba9c 100644
> --- a/hw/cirrus_vga.c
> +++ b/hw/cirrus_vga.c
> @@ -3017,7 +3017,6 @@ static const VMStateDescription vmstate_pci_cirrus_vga
> = {
>     .version_id = 2,
>     .minimum_version_id = 2,
>     .minimum_version_id_old = 2,
> -    .post_load = cirrus_post_load,
>     .fields      = (VMStateField []) {
>         VMSTATE_PCI_DEVICE(dev, PCICirrusVGAState),
>         VMSTATE_STRUCT(cirrus_vga, PCICirrusVGAState, 0,
> --
> SUN OF A BEACH
>
>



[Qemu-devel] [Bug 584146] [NEW] Virtual fat breaks with -snapshot

2010-05-22 Thread Michael Tokarev
Public bug reported:

When using fat emulation together with snapshot, qemu fails to find the
directory for the fat "filesystem".

See Debian bug#504049, http://bugs.debian.org/cgi-
bin/bugreport.cgi?bug=504049 and discussion on qemu-devel with Kevin
Wolf, http://marc.info/?t=12685080281 for details.

There's a workaround for this bug: when using full path for
fat:/dir/name it works.

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
Virtual fat breaks with -snapshot
https://bugs.launchpad.net/bugs/584146
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
When using fat emulation together with snapshot, qemu fails to find the 
directory for the fat "filesystem".

See Debian bug#504049, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504049 
and discussion on qemu-devel with Kevin Wolf, 
http://marc.info/?t=12685080281 for details.

There's a workaround for this bug: when using full path for fat:/dir/name it 
works.





[Qemu-devel] [Bug 584153] [NEW] no useful error message when tap device open fails

2010-05-22 Thread Michael Tokarev
Public bug reported:

When using tap network devices and it fails, qemu gives no information
about what the problem is (permission denied, device busy or other),
making debugging of such situations, especially for newbies, very
difficult.  The proposed patch just adds strerror() around the place,
making it more friendly.

See also Debian bug#578154, http://bugs.debian.org/cgi-
bin/bugreport.cgi?bug=578154 and a discussion on qemu-devel at
http://marc.info/?t=12719287523 .

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: patch

-- 
no useful error message when tap device open fails
https://bugs.launchpad.net/bugs/584153
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
When using tap network devices and it fails, qemu gives no information about 
what the problem is (permission denied, device busy or other), making debugging 
of such situations, especially for newbies, very difficult.  The proposed patch 
just adds strerror() around the place, making it more friendly.

See also Debian bug#578154, 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578154 and a discussion on 
qemu-devel at http://marc.info/?t=12719287523 .





[Qemu-devel] [Bug 584153] Re: no useful error message when tap device open fails

2010-05-22 Thread Michael Tokarev

** Attachment added: "tap-open-give-useful-error-messages.diff"
   
http://launchpadlibrarian.net/48914447/tap-open-give-useful-error-messages.diff

-- 
no useful error message when tap device open fails
https://bugs.launchpad.net/bugs/584153
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
When using tap network devices and it fails, qemu gives no information about 
what the problem is (permission denied, device busy or other), making debugging 
of such situations, especially for newbies, very difficult.  The proposed patch 
just adds strerror() around the place, making it more friendly.

See also Debian bug#578154, 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578154 and a discussion on 
qemu-devel at http://marc.info/?t=12719287523 .





[Qemu-devel] [Bug 584155] [NEW] support horisontal mouse wheel

2010-05-22 Thread Michael Tokarev
Public bug reported:

Brad Jorsch provided a series of patches to support horisontal mouse scrolling 
in qemu-emulated mouse.
See Debian bug#579968 -- 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579968 and submission to 
qemu-devel list at 
http://www.mail-archive.com/qemu-devel@nongnu.org/msg30991.html .

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: patch

-- 
support horisontal mouse wheel
https://bugs.launchpad.net/bugs/584155
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
Brad Jorsch provided a series of patches to support horisontal mouse scrolling 
in qemu-emulated mouse.
See Debian bug#579968 -- 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579968 and submission to 
qemu-devel list at 
http://www.mail-archive.com/qemu-devel@nongnu.org/msg30991.html .





[Qemu-devel] [PATCH 0/5] allow HelenOS to start userspace tasks under qemu-system-sparc64

2010-05-22 Thread Igor V. Kovalenko
The following series addresses a few issues found in current sparc64 mmu
implementation.

With these changes HelenOS-0.4.2-sparc64-us2.iso can progress to executing
userspace tasks (verified by looking for 40b0 addresses in in_asm debug trace)

---

Igor V. Kovalenko (5):
  sparc64: generate data access exception on RW violation
  sparc64: fix pstate privilege bits
  sparc64: fix dump_mmu to look for global bit in tte value instead of tag
  sparc64: fix mmu context at trap levels above zero
  sparc64: flush translations on mmu context change


 target-sparc/cpu.h   |   73 +++
 target-sparc/helper.c|  126 +++---
 target-sparc/op_helper.c |   30 ++-
 target-sparc/translate.c |   14 +++--
 4 files changed, 161 insertions(+), 82 deletions(-)

-- 



[Qemu-devel] [PATCH 1/5] sparc64: generate data access exception on RW violation

2010-05-22 Thread Igor V. Kovalenko
From: Igor V. Kovalenko 

- separate PRIV and PROT handling
- DPRINTF_MMU macro to clean up debug code
- dump mmu_idx, trap level and mmu context registers
  along with address translation values

Signed-off-by: Igor V. Kovalenko 
---
 target-sparc/helper.c |   99 +++--
 1 files changed, 62 insertions(+), 37 deletions(-)

diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index 2ff..4a494de 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -30,6 +30,13 @@
 //#define DEBUG_MMU
 //#define DEBUG_FEATURES
 
+#ifdef DEBUG_MMU
+#define DPRINTF_MMU(fmt, ...) \
+do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF_MMU(fmt, ...) do {} while (0)
+#endif
+
 static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model);
 
 /* Sparc MMU emulation */
@@ -451,42 +458,50 @@ static int get_physical_address_data(CPUState *env,
 
 for (i = 0; i < 64; i++) {
 // ctx match, vaddr match, valid?
-if (ultrasparc_tag_match(&env->dtlb[i],
- address, context, physical)) {
+if (ultrasparc_tag_match(&env->dtlb[i], address, context, physical)) {
+
+uint8_t fault_type = 0;
+
 // access ok?
-if (((env->dtlb[i].tte & 0x4) && is_user) ||
-(!(env->dtlb[i].tte & 0x2) && (rw == 1))) {
-uint8_t fault_type = 0;
+if ((env->dtlb[i].tte & 0x4) && is_user) {
+fault_type |= 1; /* privilege violation */
+env->exception_index = TT_DFAULT;
 
-if ((env->dtlb[i].tte & 0x4) && is_user) {
-fault_type |= 1; /* privilege violation */
-}
+DPRINTF_MMU("DFAULT at %" PRIx64 " context %" PRIx64
+" mmu_idx=%d tl=%d\n",
+address, context, mmu_idx, env->tl);
+} else if (!(env->dtlb[i].tte & 0x2) && (rw == 1)) {
+env->exception_index = TT_DPROT;
 
-if (env->dmmu.sfsr & 1) /* Fault status register */
-env->dmmu.sfsr = 2; /* overflow (not read before
+DPRINTF_MMU("DPROT at %" PRIx64 " context %" PRIx64
+" mmu_idx=%d tl=%d\n",
+address, context, mmu_idx, env->tl);
+} else {
+*prot = PAGE_READ;
+if (env->dtlb[i].tte & 0x2)
+*prot |= PAGE_WRITE;
+
+TTE_SET_USED(env->dtlb[i].tte);
+
+return 0;
+}
+
+if (env->dmmu.sfsr & 1) /* Fault status register */
+env->dmmu.sfsr = 2; /* overflow (not read before
  another fault) */
 
-env->dmmu.sfsr |= (is_user << 3) | ((rw == 1) << 2) | 1;
+env->dmmu.sfsr |= (is_user << 3) | ((rw == 1) << 2) | 1;
 
-env->dmmu.sfsr |= (fault_type << 7);
+env->dmmu.sfsr |= (fault_type << 7);
 
-env->dmmu.sfar = address; /* Fault address register */
-env->exception_index = TT_DFAULT;
-#ifdef DEBUG_MMU
-printf("DFAULT at 0x%" PRIx64 "\n", address);
-#endif
-return 1;
-}
-*prot = PAGE_READ;
-if (env->dtlb[i].tte & 0x2)
-*prot |= PAGE_WRITE;
-TTE_SET_USED(env->dtlb[i].tte);
-return 0;
+env->dmmu.sfar = address; /* Fault address register */
+return 1;
 }
 }
-#ifdef DEBUG_MMU
-printf("DMISS at 0x%" PRIx64 "\n", address);
-#endif
+
+DPRINTF_MMU("DMISS at %" PRIx64 " context %" PRIx64 "\n",
+address, context);
+
 env->dmmu.tag_access = (address & ~0x1fffULL) | context;
 env->exception_index = TT_DMISS;
 return 1;
@@ -528,9 +543,10 @@ static int get_physical_address_code(CPUState *env,
  another fault) */
 env->immu.sfsr |= (is_user << 3) | 1;
 env->exception_index = TT_TFAULT;
-#ifdef DEBUG_MMU
-printf("TFAULT at 0x%" PRIx64 "\n", address);
-#endif
+
+DPRINTF_MMU("TFAULT at %" PRIx64 " context %" PRIx64 "\n",
+address, context);
+
 return 1;
 }
 *prot = PAGE_EXEC;
@@ -538,9 +554,10 @@ static int get_physical_address_code(CPUState *env,
 return 0;
 }
 }
-#ifdef DEBUG_MMU
-printf("TMISS at 0x%" PRIx64 "\n", address);
-#endif
+
+DPRINTF_MMU("TMISS at %" PRIx64 " context %" PRIx64 "\n",
+address, context);
+
 /* Context is stored in DMMU (dmmuregs[1]) also for IMMU */
 env->immu.tag_access = (address & ~0x1fffULL) | context;
 env->exception_index = TT_TMISS;
@@ -578,10 +595,18 @@ int cpu_sparc_handle_mmu_fault (CPUState *env, 
target_ulong address, int r

[Qemu-devel] [PATCH 4/5] sparc64: fix mmu context at trap levels above zero

2010-05-22 Thread Igor V. Kovalenko
From: Igor V. Kovalenko 

- cpu_mmu_index return MMU_NUCLEUS_IDX if trap level is not zero
- cpu_get_tb_cpu_state: store trap level and primary context in flags
  this allows to restart code translation when address translation is changed
- stop translation block after writing to pstate and tl registers
- stop translation block after writing to alternate space
  this can be optimized to stop only if address translation can be changed
  by write operation (e.g. by comparing with MMU ASI values)

Signed-off-by: Igor V. Kovalenko 
---
 target-sparc/cpu.h   |   14 ++
 target-sparc/helper.c|   19 ++-
 target-sparc/translate.c |   10 +++---
 3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index 4fd58e9..8f0484b 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -556,7 +556,9 @@ static inline int cpu_mmu_index(CPUState *env1)
 #elif !defined(TARGET_SPARC64)
 return env1->psrs;
 #else
-if (cpu_hypervisor_mode(env1)) {
+if (env1->tl > 0) {
+return MMU_NUCLEUS_IDX;
+} else if (cpu_hypervisor_mode(env1)) {
 return MMU_HYPV_IDX;
 } else if (cpu_supervisor_mode(env1)) {
 return MMU_KERNEL_IDX;
@@ -636,9 +638,13 @@ static inline void cpu_get_tb_cpu_state(CPUState *env, 
target_ulong *pc,
 *cs_base = env->npc;
 #ifdef TARGET_SPARC64
 // AM . Combined FPU enable bits . PRIV . DMMU enabled . IMMU enabled
-*flags = ((env->pstate & PS_AM) << 2)
-| (((env->pstate & PS_PEF) >> 1) | ((env->fprs & FPRS_FEF) << 2))
-| (env->pstate & PS_PRIV) | ((env->lsu & (DMMU_E | IMMU_E)) >> 2);
+*flags = ((env->pstate & PS_AM) << 2)  /* 5 */
+| (((env->pstate & PS_PEF) >> 1)   /* 3 */
+| ((env->fprs & FPRS_FEF) << 2))   /* 4 */
+| (env->pstate & PS_PRIV)  /* 2 */
+| ((env->lsu & (DMMU_E | IMMU_E)) >> 2)/* 1, 0 */
+| ((env->tl & 0xff) << 8)
+| (env->dmmu.mmu_primary_context << 16);   /* 16... */
 #else
 // FPU enable . Supervisor
 *flags = (env->psref << 4) | env->psrs;
diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index 1045c31..96a22f3 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -572,6 +572,23 @@ static int get_physical_address(CPUState *env, 
target_phys_addr_t *physical,
 /* ??? We treat everything as a small page, then explicitly flush
everything when an entry is evicted.  */
 *page_size = TARGET_PAGE_SIZE;
+
+#if defined (DEBUG_MMU)
+/* safety net to catch wrong softmmu index use from dynamic code */
+if (env->tl > 0 && mmu_idx != MMU_NUCLEUS_IDX) {
+DPRINTF_MMU("get_physical_address %s tl=%d mmu_idx=%d"
+" primary context=%" PRIx64
+" secondary context=%" PRIx64
+" address=%" PRIx64
+"\n",
+(rw == 2 ? "CODE" : "DATA"),
+env->tl, mmu_idx,
+env->dmmu.mmu_primary_context,
+env->dmmu.mmu_secondary_context,
+address);
+}
+#endif
+
 if (rw == 2)
 return get_physical_address_code(env, physical, prot, address,
  mmu_idx);
@@ -718,7 +735,7 @@ target_phys_addr_t cpu_get_phys_page_nofault(CPUState *env, 
target_ulong addr,
 
 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
 {
-return cpu_get_phys_page_nofault(env, addr, MMU_KERNEL_IDX);
+return cpu_get_phys_page_nofault(env, addr, cpu_mmu_index(env));
 }
 #endif
 
diff --git a/target-sparc/translate.c b/target-sparc/translate.c
index 86096d2..72ca0b4 100644
--- a/target-sparc/translate.c
+++ b/target-sparc/translate.c
@@ -3484,14 +3484,14 @@ static void disas_sparc_insn(DisasContext * dc)
 case 6: // pstate
 save_state(dc, cpu_cond);
 gen_helper_wrpstate(cpu_tmp0);
-gen_op_next_insn();
-tcg_gen_exit_tb(0);
-dc->is_br = 1;
+dc->npc = DYNAMIC_PC;
 break;
 case 7: // tl
+save_state(dc, cpu_cond);
 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
 tcg_gen_st_i32(cpu_tmp32, cpu_env,
offsetof(CPUSPARCState, tl));
+dc->npc = DYNAMIC_PC;
 break;
 case 8: // pil
 gen_helper_wrpil(cpu_tmp0);
@@ -4550,6 +4550,7 @@ static void disas_sparc_insn(DisasContext * dc)
 #endif
 save_state(dc, cpu_cond);
 gen_st_asi(cpu_val, cpu_addr, insn, 4);
+   

[Qemu-devel] [PATCH 2/5] sparc64: fix pstate privilege bits

2010-05-22 Thread Igor V. Kovalenko
From: Igor V. Kovalenko 

- refactor code to handle hpstate only if available for current cpu
- conditionally set hypervisor bit in hpstate register
- reorder softmmu indices so user accessable ones go first, translation context
  macros supervisor() and hypervisor() adjusted as well
- disable sparcv8 registers for TARGET_SPARC64
- fix cpu_mmu_index to use sparcv9 bits only

Signed-off-by: Igor V. Kovalenko 
---
 target-sparc/cpu.h   |   61 --
 target-sparc/helper.c|4 ++-
 target-sparc/op_helper.c |   24 --
 target-sparc/translate.c |4 ++-
 4 files changed, 57 insertions(+), 36 deletions(-)

diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index 27b020b..4fd58e9 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -92,12 +92,14 @@
 #define PSR_CARRY_SHIFT 20
 #define PSR_CARRY (1 << PSR_CARRY_SHIFT)
 #define PSR_ICC   (PSR_NEG|PSR_ZERO|PSR_OVF|PSR_CARRY)
+#if !defined(TARGET_SPARC64)
 #define PSR_EF(1<<12)
 #define PSR_PIL   0xf00
 #define PSR_S (1<<7)
 #define PSR_PS(1<<6)
 #define PSR_ET(1<<5)
 #define PSR_CWP   0x1f
+#endif
 
 #define CC_SRC (env->cc_src)
 #define CC_SRC2 (env->cc_src2)
@@ -341,14 +343,16 @@ typedef struct CPUSPARCState {
 uint32_t wim;  /* window invalid mask */
 #endif
 target_ulong tbr;  /* trap base register */
+#if !defined(TARGET_SPARC64)
 int  psrs; /* supervisor mode (extracted from PSR) */
 int  psrps;/* previous supervisor mode */
-#if !defined(TARGET_SPARC64)
 int  psret;/* enable traps */
 #endif
 uint32_t psrpil;   /* interrupt blocking level */
 uint32_t pil_in;   /* incoming interrupt level bitmap */
+#if !defined(TARGET_SPARC64)
 int  psref;/* enable fpu */
+#endif
 target_ulong version;
 int interrupt_index;
 uint32_t nwindows;
@@ -508,21 +512,41 @@ int cpu_sparc_signal_handler(int host_signum, void 
*pinfo, void *puc);
 #define CPU_SAVE_VERSION 6
 
 /* MMU modes definitions */
+#if defined (TARGET_SPARC64)
+#define MMU_USER_IDX   0
 #define MMU_MODE0_SUFFIX _user
-#define MMU_MODE1_SUFFIX _kernel
-#ifdef TARGET_SPARC64
-#define MMU_MODE2_SUFFIX _hypv
-#define MMU_MODE3_SUFFIX _nucleus
-#define MMU_MODE4_SUFFIX _user_secondary
-#define MMU_MODE5_SUFFIX _kernel_secondary
-#endif
+#define MMU_USER_SECONDARY_IDX   1
+#define MMU_MODE1_SUFFIX _user_secondary
+#define MMU_KERNEL_IDX 2
+#define MMU_MODE2_SUFFIX _kernel
+#define MMU_KERNEL_SECONDARY_IDX 3
+#define MMU_MODE3_SUFFIX _kernel_secondary
+#define MMU_NUCLEUS_IDX 4
+#define MMU_MODE4_SUFFIX _nucleus
+#define MMU_HYPV_IDX   5
+#define MMU_MODE5_SUFFIX _hypv
+#else
 #define MMU_USER_IDX   0
+#define MMU_MODE0_SUFFIX _user
 #define MMU_KERNEL_IDX 1
-#define MMU_HYPV_IDX   2
-#ifdef TARGET_SPARC64
-#define MMU_NUCLEUS_IDX 3
-#define MMU_USER_SECONDARY_IDX   4
-#define MMU_KERNEL_SECONDARY_IDX 5
+#define MMU_MODE1_SUFFIX _kernel
+#endif
+
+#if defined (TARGET_SPARC64)
+static inline int cpu_has_hypervisor(CPUState *env1)
+{
+return env1->def->features & CPU_FEATURE_HYPV;
+}
+
+static inline int cpu_hypervisor_mode(CPUState *env1)
+{
+return cpu_has_hypervisor(env1) && (env1->hpstate & HS_PRIV);
+}
+
+static inline int cpu_supervisor_mode(CPUState *env1)
+{
+return env1->pstate & PS_PRIV;
+}
 #endif
 
 static inline int cpu_mmu_index(CPUState *env1)
@@ -532,12 +556,13 @@ static inline int cpu_mmu_index(CPUState *env1)
 #elif !defined(TARGET_SPARC64)
 return env1->psrs;
 #else
-if (!env1->psrs)
-return MMU_USER_IDX;
-else if ((env1->hpstate & HS_PRIV) == 0)
-return MMU_KERNEL_IDX;
-else
+if (cpu_hypervisor_mode(env1)) {
 return MMU_HYPV_IDX;
+} else if (cpu_supervisor_mode(env1)) {
+return MMU_KERNEL_IDX;
+} else {
+return MMU_USER_IDX;
+}
 #endif
 }
 
diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index 4a494de..538795f 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -746,12 +746,12 @@ void cpu_reset(CPUSPARCState *env)
 #else
 #if !defined(TARGET_SPARC64)
 env->psret = 0;
-#endif
 env->psrs = 1;
 env->psrps = 1;
+#endif
 #ifdef TARGET_SPARC64
 env->pstate = PS_PRIV|PS_RED|PS_PEF|PS_AG;
-env->hpstate = HS_PRIV;
+env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0;
 env->tl = env->maxtl;
 cpu_tsptr(env)->tt = TT_POWER_ON_RESET;
 env->lsu = 0;
diff --git a/target-sparc/op_helper.c b/target-sparc/op_helper.c
index d0bc277..28224b2 100644
--- a/target-sparc/op_helper.c
+++ b/target-sparc/op_helper.c
@@ -1404,11 +1404,7 @@ static target_ulong get_psr(void)
 (env->psrps? PSR_PS : 0) |
 (env->psret? PSR_ET : 0) | env->cwp;
 #else
-return env->version | (env->psr & PSR_ICC) |
-(env->psref? PSR_EF : 0) |
-(env->psrpil << 8) |
-(env->psrs? PSR_S : 0) |
-(env->psrps? PSR_PS : 0) | env->cwp;
+return env->psr & PSR_ICC;
 #endif
 }
 
@@ -1427,17 +1423,19

[Qemu-devel] [PATCH 3/5] sparc64: fix dump_mmu to look for global bit in tte value instead of tag

2010-05-22 Thread Igor V. Kovalenko
From: Igor V. Kovalenko 

Signed-off-by: Igor V. Kovalenko 
---
 target-sparc/helper.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index 538795f..1045c31 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -653,7 +653,7 @@ void dump_mmu(CPUState *env)
env->dtlb[i].tte & 0x2? "RW": "RO",
env->dtlb[i].tte & 0x40? "locked": "unlocked",
env->dtlb[i].tag & (uint64_t)0x1fffULL,
-   TTE_IS_GLOBAL(env->dtlb[i].tag)? "global" : "local");
+   TTE_IS_GLOBAL(env->dtlb[i].tte)? "global" : "local");
 }
 }
 }
@@ -687,7 +687,7 @@ void dump_mmu(CPUState *env)
env->itlb[i].tte & 0x4? "priv": "user",
env->itlb[i].tte & 0x40? "locked": "unlocked",
env->itlb[i].tag & (uint64_t)0x1fffULL,
-   TTE_IS_GLOBAL(env->itlb[i].tag)? "global" : "local");
+   TTE_IS_GLOBAL(env->itlb[i].tte)? "global" : "local");
 }
 }
 }




[Qemu-devel] [PATCH 5/5] sparc64: flush translations on mmu context change

2010-05-22 Thread Igor V. Kovalenko
From: Igor V. Kovalenko 

- two pairs of softmmu indexes bind softmmu tlb to cpu tlb in fault handlers
  using value of DMMU primary and secondary context registers, so we need to
  flush softmmu translations when context registers are changed

Signed-off-by: Igor V. Kovalenko 
---
 target-sparc/op_helper.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/target-sparc/op_helper.c b/target-sparc/op_helper.c
index 28224b2..edeeb44 100644
--- a/target-sparc/op_helper.c
+++ b/target-sparc/op_helper.c
@@ -2959,9 +2959,15 @@ void helper_st_asi(target_ulong addr, target_ulong val, 
int asi, int size)
 break;
 case 1: // Primary context
 env->dmmu.mmu_primary_context = val;
+/* can be optimized to only flush MMU_USER_IDX
+   and MMU_KERNEL_IDX entries */
+tlb_flush(env, 1);
 break;
 case 2: // Secondary context
 env->dmmu.mmu_secondary_context = val;
+/* can be optimized to only flush MMU_USER_SECONDARY_IDX
+   and MMU_KERNEL_SECONDARY_IDX entries */
+tlb_flush(env, 1);
 break;
 case 5: // TSB access
 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64 " -> 0x%016"




Re: [Qemu-devel] [PATCH 0/5] allow HelenOS to start userspace tasks under qemu-system-sparc64

2010-05-22 Thread Blue Swirl
Thanks, applied all.

On Sat, May 22, 2010 at 10:52 AM, Igor V. Kovalenko
 wrote:
> The following series addresses a few issues found in current sparc64 mmu
> implementation.
>
> With these changes HelenOS-0.4.2-sparc64-us2.iso can progress to executing
> userspace tasks (verified by looking for 40b0 addresses in in_asm debug trace)
>
> ---
>
> Igor V. Kovalenko (5):
>      sparc64: generate data access exception on RW violation
>      sparc64: fix pstate privilege bits
>      sparc64: fix dump_mmu to look for global bit in tte value instead of tag
>      sparc64: fix mmu context at trap levels above zero
>      sparc64: flush translations on mmu context change
>
>
>  target-sparc/cpu.h       |   73 +++
>  target-sparc/helper.c    |  126 
> +++---
>  target-sparc/op_helper.c |   30 ++-
>  target-sparc/translate.c |   14 +++--
>  4 files changed, 161 insertions(+), 82 deletions(-)
>
> --
>
>



Re: [Qemu-devel] [PATCH v2 08/15] Add base64 encoder/decoder

2010-05-22 Thread Blue Swirl
On Sat, May 22, 2010 at 8:18 AM, Jan Kiszka  wrote:
> From: Jan Kiszka 
>
> Will be used by QBuffer.
>
> Signed-off-by: Jan Kiszka 
> ---
>  Makefile.objs |    2 +-
>  base64.c      |  202 
> +
>  base64.h      |   18 +
>  3 files changed, 221 insertions(+), 1 deletions(-)
>  create mode 100644 base64.c
>  create mode 100644 base64.h
>
> diff --git a/Makefile.objs b/Makefile.objs
> index acbaf22..2c603b2 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -2,7 +2,7 @@
>  # QObject
>  qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
>  qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
> -qobject-obj-y += qerror.o
> +qobject-obj-y += qerror.o base64.o
>
>  ###
>  # block-obj-y is code used by both qemu system emulation and qemu-img
> diff --git a/base64.c b/base64.c
> new file mode 100644
> index 000..543e8c6
> --- /dev/null
> +++ b/base64.c
> @@ -0,0 +1,202 @@
> +/*
> + * Base64 encoder/decoder conforming to RFC 4648
> + * (based on Mozilla's nsprpub/lib/libc/src/base64.c)
> + *
> + * Copyright (C) 2010 Siemens AG
> + *
> + * Authors:
> + *  Jan Kiszka 
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#include "inttypes.h"

Why not ?

> +#include "base64.h"
> +
> +static const char base[] =
> +    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
> +
> +static void encode3to4(const char *src, char *dest)
> +{
> +    uint32_t b32 = 0;
> +    int i, j = 18;
> +
> +    for (i = 0; i < 3; i++) {
> +        b32 <<= 8;
> +        b32 |= src[i];
> +    }
> +    for (i = 0; i < 4; i++) {
> +        dest[i] = base[(b32 >> j) & 0x3F];
> +        j -= 6;
> +    }
> +}
> +
> +static void encode2to4(const char *src, char *dest)
> +{
> +    dest[0] = base[(src[0] >> 2) & 0x3F];
> +    dest[1] = base[((src[0] & 0x03) << 4) | ((src[1] >> 4) & 0x0F)];
> +    dest[2] = base[(src[1] & 0x0F) << 2];
> +    dest[3] = '=';
> +}
> +
> +static void encode1to4(const char *src, char *dest)
> +{
> +    dest[0] = base[(src[0] >> 2) & 0x3F];
> +    dest[1] = base[(src[0] & 0x03) << 4];
> +    dest[2] = '=';
> +    dest[3] = '=';
> +}
> +
> +/*
> + * Encode data in 'src' of length 'srclen' to a base64 string, saving the
> + * null-terminated result in 'dest'. The size of the destition buffer must be
> + * at least ((srclen + 2) / 3) * 4 + 1.
> + */
> +void base64_encode(const void *src, size_t srclen, char *dest)
> +{
> +    while (srclen >= 3) {
> +        encode3to4(src, dest);
> +        src += 3;
> +        dest += 4;
> +        srclen -= 3;
> +    }
> +    switch (srclen) {
> +    case 2:
> +        encode2to4(src, dest);
> +        dest += 4;
> +        break;
> +    case 1:
> +        encode1to4(src, dest);
> +        dest += 4;
> +        break;
> +    case 0:
> +        break;
> +    }
> +    dest[0] = 0;
> +}
> +
> +static int32_t codetovalue(char c)
> +{
> +    if (c >= 'A' && c <= 'Z') {
> +        return c - 'A';
> +    } else if (c >= 'a' && c <= 'z') {
> +        return c - 'a' + 26;
> +    } else if (c >= '0' && c <= '9') {
> +        return c - '0' + 52;
> +    } else if (c == '+') {
> +        return 62;
> +    } else if ( c == '/') {
> +        return 63;
> +    } else {
> +        return -1;
> +    }
> +}
> +
> +static int decode4to3 (const char *src, char *dest)
> +{
> +    uint32_t b32 = 0;
> +    int32_t bits;
> +    int i;
> +
> +    for (i = 0; i < 4; i++) {
> +        bits = codetovalue(src[i]);
> +        if (bits < 0) {
> +            return bits;
> +        }
> +        b32 <<= 6;
> +        b32 |= bits;
> +    }
> +    dest[0] = (b32 >> 16) & 0xFF;
> +    dest[1] = (b32 >> 8) & 0xFF;
> +    dest[2] = b32 & 0xFF;
> +
> +    return 0;
> +}
> +
> +static int decode3to2(const char *src, char *dest)
> +{
> +    uint32_t b32 = 0;
> +    int32_t bits;
> +
> +    bits = codetovalue(src[0]);
> +    if (bits < 0) {
> +        return bits;
> +    }
> +    b32 = (uint32_t)bits;
> +    b32 <<= 6;
> +
> +    bits = codetovalue(src[1]);
> +    if (bits < 0) {
> +        return bits;
> +    }
> +    b32 |= (uint32_t)bits;
> +    b32 <<= 4;
> +
> +    bits = codetovalue(src[2]);
> +    if (bits < 0) {
> +        return bits;
> +    }
> +    b32 |= ((uint32_t)bits) >> 2;
> +
> +    dest[0] = (b32 >> 8) & 0xFF;
> +    dest[1] = b32 & 0xFF;
> +
> +    return 0;
> +}
> +
> +static int decode2to1(const char *src, char *dest)
> +{
> +    uint32_t b32;
> +    int32_t bits;
> +
> +    bits = codetovalue(src[0]);
> +    if (bits < 0) {
> +        return bits;
> +    }
> +    b32 = (uint32_t)bits << 2;
> +
> +    bits = codetovalue(src[1]);
> +    if (bits < 0) {
> +        return bits;
> +    }
> +    b32 |= ((uint32_t)bits) >> 4;
> +
> +    dest[0] = b32;
> +
> +    return 0;
> +}
> +
> +/*
> + * Convert string 'src' of length 

Re: [Qemu-devel] [PATCH v2 00/15] Basic device state visualization

2010-05-22 Thread Blue Swirl
On Sat, May 22, 2010 at 8:17 AM, Jan Kiszka  wrote:
> Here is version 2 of the device_show patch series. It currently has some
> dependencies on recently posted doc changes / enhancements, namely:
>  - http://thread.gmane.org/gmane.comp.emulators.qemu/70673
>   ([PATCH v3 0/3]: QMP: Commands doc)
>  - http://thread.gmane.org/gmane.comp.emulators.qemu/70756
>   ([PATCH 1/7] QMP: Add "Downstream extension of QMP" to spec)

I had minor comments to 8/15, otherwise looks good.

>
> Major changes in v2 are:
>  - command line completion for device tree paths
>  - introduced complex object classes ("__class__") and applied that on
>   buffers
>  - documentation
>  - applied new qdev path specification also on device_del
>  - proper qdev device/bus sorting via QTAILQ (instead of QLIST_INSERT_TAIL)
>  - added QERR_DEVICE_NO_STATE
>  - fixed various bugs
>  - 
>
> For reference, the series is also available at
>
>        git://git.kiszka.org/qemu.git queues/device-show
>
> Thanks for all comments so far!
>
> Jan Kiszka (15):
>  Add dependency of JSON unit tests on config-host.h
>  qdev: Fix scanning across single-bus devices
>  qdev: Allow device addressing via 'driver.instance'
>  qdev: Convert device and bus lists to QTAILQ
>  qdev: Allow device specification by qtree path for device_del
>  qdev: Push QMP mode checks into qbus_list_bus/dev
>  monitor: Add completion for qdev paths
>  Add base64 encoder/decoder
>  QMP: Reserve namespace for complex object classes
>  Add QBuffer
>  monitor: return length of printed string via monitor_[v]printf
>  monitor: Add basic device state visualization
>  QMP: Teach basic capability negotiation to python example
>  QMP: Fix python helper /wrt long return strings
>  QMP: Add support for buffer class to qmp python helper
>
>  Makefile                 |    5 +-
>  Makefile.objs            |    4 +-
>  QMP/qmp-shell            |    1 +
>  QMP/qmp-spec.txt         |   24 +++-
>  QMP/qmp.py               |   29 +++-
>  QMP/vm-info              |    1 +
>  base64.c                 |  202 +++
>  base64.h                 |   18 ++
>  check-qbuffer.c          |  172 +++
>  configure                |    2 +-
>  docs/qdev-device-use.txt |   16 ++-
>  hw/acpi_piix4.c          |    2 +-
>  hw/hw.h                  |    2 +
>  hw/i2c.c                 |    2 +-
>  hw/pci-hotplug.c         |    2 +-
>  hw/qdev.c                |  408 
> +-
>  hw/qdev.h                |   12 +-
>  hw/ssi.c                 |    6 +-
>  monitor.c                |  108 +++-
>  monitor.h                |    4 +-
>  qbuffer.c                |  116 +
>  qbuffer.h                |   33 
>  qemu-monitor.hx          |   74 -
>  qemu-tool.c              |    6 +-
>  qerror.c                 |    4 +
>  qerror.h                 |    3 +
>  qjson.c                  |   15 ++
>  qobject.h                |    1 +
>  28 files changed, 1193 insertions(+), 79 deletions(-)
>  create mode 100644 base64.c
>  create mode 100644 base64.h
>  create mode 100644 check-qbuffer.c
>  create mode 100644 qbuffer.c
>  create mode 100644 qbuffer.h
>
>
>



Re: [Qemu-devel] [PATCH] lsi: Fix value overflow in request tag processing

2010-05-22 Thread Aurelien Jarno
On Fri, May 21, 2010 at 06:44:59PM +0200, Jan Kiszka wrote:
> This fixes a mismerge of 64d564094cac5f72eeaeb950c442b773a00d3586 (wrong
> patch version): We need to mask the tag value properly to obtain its
> device ID.
> 
> Signed-off-by: Jan Kiszka 

Thanks for the quick patch, I have applied it.

> ---
>  hw/lsi53c895a.c |4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
> index 9d3c44d..f5a91ba 100644
> --- a/hw/lsi53c895a.c
> +++ b/hw/lsi53c895a.c
> @@ -543,7 +543,7 @@ static void lsi_do_dma(LSIState *s, int out)
>  return;
>  }
>  
> -id = s->current->tag >> 8;
> +id = (s->current->tag >> 8) & 0xf;
>  dev = s->bus.devs[id];
>  if (!dev) {
>  lsi_bad_selection(s, id);
> @@ -745,7 +745,7 @@ static void lsi_do_command(LSIState *s)
>  s->sfbr = buf[0];
>  s->command_complete = 0;
>  
> -id = s->select_tag >> 8;
> +id = (s->select_tag >> 8) & 0xf;
>  dev = s->bus.devs[id];
>  if (!dev) {
>  lsi_bad_selection(s, id);
> -- 
> 1.6.0.2
> 
> 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



[Qemu-devel] [Bug 584121] Re: migration always fails on 32bit qemu-kvm-0.12+ (sigsegv)

2010-05-22 Thread Loïc Minier
Hi

You're filing bugs against the QEMU project, which is used to track
upstream issues (issues in the tarballs released by the QEMU project, or
in their git tree).

I think you intended to file these against the Ubuntu package of qemu,
"qemu-kvm".

AFAIK, QEMU doesn't have any upstream bug tracker, they just discuss
issues on the mailing-list.

Could you please file future bugs using "ubuntu-bug qemu-kvm"?

Thanks,

-- 
migration always fails on 32bit qemu-kvm-0.12+ (sigsegv)
https://bugs.launchpad.net/bugs/584121
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
On a 32bit host (or when running 32bit userspace on 64bit host), migration 
always fails with a crash of qemu-kvm process.
See http://marc.info/?l=kvm&m=127351472231666 for more information.





[Qemu-devel] [Bug 584143] Re: qemu fails to set hdd serial number

2010-05-22 Thread Loïc Minier
Patch still applies on top of qemu-kvm.git and qemu.git

** Bug watch added: Debian Bug tracker #573439
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=573439

** Also affects: qemu-kvm (Debian) via
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=573439
   Importance: Unknown
   Status: Unknown

** Also affects: qemu-kvm (Ubuntu)
   Importance: Undecided
   Status: New

-- 
qemu fails to set hdd serial number
https://bugs.launchpad.net/bugs/584143
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Ubuntu: New
Status in “qemu-kvm” package in Debian: Unknown

Bug description:
The -drive ...,serial=xyz option is broken, at least in 0.12.  See Debian 
bug#573439, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=573439 for details.

The proposed fix from the original reporter:

--- qemu-kvm-0.12.3+dfsg/vl.c   2010-02-26 11:34:00.0 +0900
+++ qemu-kvm-0.12.3+dfsg.old/vl.c   2010-03-11 02:26:00.134217787 +0900
@@ -2397,7 +2397,7 @@
 dinfo->on_write_error = on_write_error;
 dinfo->opts = opts;
 if (serial)
-strncpy(dinfo->serial, serial, sizeof(serial));
+strncpy(dinfo->serial, serial, sizeof(dinfo->serial));
 QTAILQ_INSERT_TAIL(&drives, dinfo, next);
 if (is_extboot) {
 extboot_drive = dinfo;





[Qemu-devel] [Bug 584153] Re: no useful error message when tap device open fails

2010-05-22 Thread Loïc Minier
** Bug watch added: Debian Bug tracker #578154
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578154

** Also affects: qemu-kvm (Debian) via
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578154
   Importance: Unknown
   Status: Unknown

-- 
no useful error message when tap device open fails
https://bugs.launchpad.net/bugs/584153
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Debian: Unknown

Bug description:
When using tap network devices and it fails, qemu gives no information about 
what the problem is (permission denied, device busy or other), making debugging 
of such situations, especially for newbies, very difficult.  The proposed patch 
just adds strerror() around the place, making it more friendly.

See also Debian bug#578154, 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578154 and a discussion on 
qemu-devel at http://marc.info/?t=12719287523 .





[Qemu-devel] [Bug 584139] Re: keymapping error for usb keyboard (windows/menu keys)

2010-05-22 Thread Loïc Minier
** Bug watch added: Debian Bug tracker #578846
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578846

** Also affects: qemu-kvm (Debian) via
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578846
   Importance: Unknown
   Status: Unknown

-- 
keymapping error for usb keyboard (windows/menu keys)
https://bugs.launchpad.net/bugs/584139
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Debian: Unknown

Bug description:
The windows and menu keys for usb keyboard in qemu are wrong.  They're correct 
for "ps/2" keyboard emulation however.  See Debian bug#578846: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578846.

Here's the proposed fix:

--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -399,3 +399,3 @@
 0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,





[Qemu-devel] [Bug 584146] Re: Virtual fat breaks with -snapshot

2010-05-22 Thread Loïc Minier
** Bug watch added: Debian Bug tracker #504049
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504049

** Also affects: qemu-kvm (Debian) via
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504049
   Importance: Unknown
   Status: Unknown

-- 
Virtual fat breaks with -snapshot
https://bugs.launchpad.net/bugs/584146
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Debian: Unknown

Bug description:
When using fat emulation together with snapshot, qemu fails to find the 
directory for the fat "filesystem".

See Debian bug#504049, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504049 
and discussion on qemu-devel with Kevin Wolf, 
http://marc.info/?t=12685080281 for details.

There's a workaround for this bug: when using full path for fat:/dir/name it 
works.





[Qemu-devel] [Bug 584155] Re: support horisontal mouse wheel

2010-05-22 Thread Loïc Minier
** Bug watch added: Debian Bug tracker #579968
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579968

** Also affects: qemu-kvm (Debian) via
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579968
   Importance: Unknown
   Status: Unknown

-- 
support horisontal mouse wheel
https://bugs.launchpad.net/bugs/584155
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Debian: Unknown

Bug description:
Brad Jorsch provided a series of patches to support horisontal mouse scrolling 
in qemu-emulated mouse.
See Debian bug#579968 -- 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579968 and submission to 
qemu-devel list at 
http://www.mail-archive.com/qemu-devel@nongnu.org/msg30991.html .





[Qemu-devel] [Bug 584121] Re: migration always fails on 32bit qemu-kvm-0.12+ (sigsegv)

2010-05-22 Thread Loïc Minier
Sorry, I failed to realize that qemu-kvm uses the qemu project in
launchpad to track bugs; so this is the right place to file these.

Thanks!

-- 
migration always fails on 32bit qemu-kvm-0.12+ (sigsegv)
https://bugs.launchpad.net/bugs/584121
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
On a 32bit host (or when running 32bit userspace on 64bit host), migration 
always fails with a crash of qemu-kvm process.
See http://marc.info/?l=kvm&m=127351472231666 for more information.





[Qemu-devel] [Bug 584131] Re: some guests hangs after migration (qemu-kvm-0.12)

2010-05-22 Thread Loïc Minier
** Bug watch added: Debian Bug tracker #580649
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=580649

** Also affects: debian via
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=580649
   Importance: Unknown
   Status: Unknown

-- 
some guests hangs after migration (qemu-kvm-0.12)
https://bugs.launchpad.net/bugs/584131
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in Debian GNU/Linux: Unknown

Bug description:
There's a quite good bugreport in Debian BTS about this, #580649: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=580649

This is not the same as lp#341682, since it's now 0.12.

Full initial message from #580649:


From: Apollon Oikonomopoulos 
To: Debian Bug Tracking System 
Subject: qemu-kvm: Guests hang after live migration
Date: Fri, 07 May 2010 16:29:10 +0300

Package: qemu-kvm
Version: 0.12.3+dfsg-4
Severity: important

Hi,

qemu-kvm 0.12.3 causes guests to hang after a live migration. The crash seems
to be related to the guest's virtio subsystem, as per the following backtrace
obtained _in the guest_:

May  7 14:17:32 kot kernel: [  285.035681] irq 11: nobody cared (try booting 
with the "irqpoll" option)
May  7 14:17:32 kot kernel: [  285.035681] Pid: 0, comm: swapper Not tainted 
2.6.26-2-amd64 #1
May  7 14:17:32 kot kernel: [  285.035681]
May  7 14:17:32 kot kernel: [  285.035681] Call Trace:
May  7 14:17:32 kot kernel: [  285.035681][] 
:virtio_pci:vp_interrupt+0x27/0xb8
May  7 14:17:32 kot kernel: [  285.035681]  [] 
__report_bad_irq+0x30/0x72
May  7 14:17:32 kot kernel: [  285.035681]  [] 
note_interrupt+0x1fd/0x23b
May  7 14:17:32 kot kernel: [  285.035681]  [] 
handle_fasteoi_irq+0xa5/0xc8
May  7 14:17:32 kot kernel: [  285.035681]  [] 
do_IRQ+0x6d/0xd9
May  7 14:17:32 kot kernel: [  285.035681]  [] 
default_idle+0x0/0x49
May  7 14:17:32 kot kernel: [  285.035681]  [] 
ret_from_intr+0x0/0x19
May  7 14:17:32 kot kernel: [  285.035681][] 
lapic_next_event+0x0/0x13
May  7 14:17:32 kot kernel: [  285.035681]  [] 
native_safe_halt+0x2/0x3
May  7 14:17:32 kot kernel: [  285.035681]  [] 
native_safe_halt+0x2/0x3
May  7 14:17:32 kot kernel: [  285.035681]  [] 
default_idle+0x2a/0x49
May  7 14:17:32 kot kernel: [  285.035681]  [] 
cpu_idle+0x8e/0xb8
May  7 14:17:32 kot kernel: [  285.035681]
May  7 14:17:32 kot kernel: [  285.035681] handlers:
May  7 14:17:32 kot kernel: [  285.035681] [] 
(usb_hcd_irq+0x0/0x78)
May  7 14:17:32 kot kernel: [  285.035681] [] 
(vp_interrupt+0x0/0xb8 [virtio_pci])
May  7 14:17:32 kot kernel: [  285.035681] Disabling IRQ #11

This happens in a reproducible fashion on a guest with the following setup:

  * Virtio net + block devices
  * 8 CPU SMP
  * 521 MB RAM
  * Debian Lenny with 2.6.26-2-amd64

Just migrating the guest a couple of times with a bit of I/O activity will
cause it to freeze completely.

It does *not* seem to impact the following:
  * Guests with no virtio devices
  * Guests running 2.6.32-4-amd64 
  * Guests running under qemu-kvm-0.11.1

Thus, it seems to be virtio-specific and possibly related to the guest kernel,
but since qemu-kvm-0.11.1 works fine, I'm filing it as a qemu-kvm regression
and not a kernel bug.

Thank you





[Qemu-devel] Graphics Device Passthrough

2010-05-22 Thread Adhyas Avasthi
Hello

(newbie hacker to qemu community, so please excuse novice ignorances)



I wish to pass-through a graphics controller to my Windows 7 VM running on
qemu-kvm. I would like it to be PCI-Express (if that works, that is). Are
there any recommended devices that I should purchase for this experiment?

I would like the device to also be accessible from my Fedora Core 10 host.



Basically, I wish to have the device pass-through when I run the VM, I then
wish to eject the device out of the VM (hot-remove), and then give it back
to Fedora Core 10 to use. This is how my experiment is defined. I am looking
for suggestions on graphics controllers I should think of purchasing for
this experiment. Any help would be appreciated.



Thanks,
Adhyas


[Qemu-devel] [Bug 584153] Re: no useful error message when tap device open fails

2010-05-22 Thread Bug Watch Updater
** Changed in: qemu-kvm (Debian)
   Status: Unknown => Fix Released

-- 
no useful error message when tap device open fails
https://bugs.launchpad.net/bugs/584153
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Debian: Fix Released

Bug description:
When using tap network devices and it fails, qemu gives no information about 
what the problem is (permission denied, device busy or other), making debugging 
of such situations, especially for newbies, very difficult.  The proposed patch 
just adds strerror() around the place, making it more friendly.

See also Debian bug#578154, 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578154 and a discussion on 
qemu-devel at http://marc.info/?t=12719287523 .





[Qemu-devel] [Bug 584146] Re: Virtual fat breaks with -snapshot

2010-05-22 Thread Bug Watch Updater
** Changed in: qemu-kvm (Debian)
   Status: Unknown => Confirmed

-- 
Virtual fat breaks with -snapshot
https://bugs.launchpad.net/bugs/584146
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Debian: Confirmed

Bug description:
When using fat emulation together with snapshot, qemu fails to find the 
directory for the fat "filesystem".

See Debian bug#504049, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504049 
and discussion on qemu-devel with Kevin Wolf, 
http://marc.info/?t=12685080281 for details.

There's a workaround for this bug: when using full path for fat:/dir/name it 
works.





[Qemu-devel] [Bug 584139] Re: keymapping error for usb keyboard (windows/menu keys)

2010-05-22 Thread Bug Watch Updater
** Changed in: qemu-kvm (Debian)
   Status: Unknown => Fix Released

-- 
keymapping error for usb keyboard (windows/menu keys)
https://bugs.launchpad.net/bugs/584139
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Debian: Fix Released

Bug description:
The windows and menu keys for usb keyboard in qemu are wrong.  They're correct 
for "ps/2" keyboard emulation however.  See Debian bug#578846: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578846.

Here's the proposed fix:

--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -399,3 +399,3 @@
 0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,





[Qemu-devel] [Bug 584155] Re: support horisontal mouse wheel

2010-05-22 Thread Bug Watch Updater
** Changed in: qemu-kvm (Debian)
   Status: Unknown => Confirmed

-- 
support horisontal mouse wheel
https://bugs.launchpad.net/bugs/584155
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in “qemu-kvm” package in Debian: Confirmed

Bug description:
Brad Jorsch provided a series of patches to support horisontal mouse scrolling 
in qemu-emulated mouse.
See Debian bug#579968 -- 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579968 and submission to 
qemu-devel list at 
http://www.mail-archive.com/qemu-devel@nongnu.org/msg30991.html .





[Qemu-devel] [Bug 584131] Re: some guests hangs after migration (qemu-kvm-0.12)

2010-05-22 Thread Bug Watch Updater
** Changed in: debian
   Status: Unknown => New

-- 
some guests hangs after migration (qemu-kvm-0.12)
https://bugs.launchpad.net/bugs/584131
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New
Status in Debian GNU/Linux: New

Bug description:
There's a quite good bugreport in Debian BTS about this, #580649: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=580649

This is not the same as lp#341682, since it's now 0.12.

Full initial message from #580649:


From: Apollon Oikonomopoulos 
To: Debian Bug Tracking System 
Subject: qemu-kvm: Guests hang after live migration
Date: Fri, 07 May 2010 16:29:10 +0300

Package: qemu-kvm
Version: 0.12.3+dfsg-4
Severity: important

Hi,

qemu-kvm 0.12.3 causes guests to hang after a live migration. The crash seems
to be related to the guest's virtio subsystem, as per the following backtrace
obtained _in the guest_:

May  7 14:17:32 kot kernel: [  285.035681] irq 11: nobody cared (try booting 
with the "irqpoll" option)
May  7 14:17:32 kot kernel: [  285.035681] Pid: 0, comm: swapper Not tainted 
2.6.26-2-amd64 #1
May  7 14:17:32 kot kernel: [  285.035681]
May  7 14:17:32 kot kernel: [  285.035681] Call Trace:
May  7 14:17:32 kot kernel: [  285.035681][] 
:virtio_pci:vp_interrupt+0x27/0xb8
May  7 14:17:32 kot kernel: [  285.035681]  [] 
__report_bad_irq+0x30/0x72
May  7 14:17:32 kot kernel: [  285.035681]  [] 
note_interrupt+0x1fd/0x23b
May  7 14:17:32 kot kernel: [  285.035681]  [] 
handle_fasteoi_irq+0xa5/0xc8
May  7 14:17:32 kot kernel: [  285.035681]  [] 
do_IRQ+0x6d/0xd9
May  7 14:17:32 kot kernel: [  285.035681]  [] 
default_idle+0x0/0x49
May  7 14:17:32 kot kernel: [  285.035681]  [] 
ret_from_intr+0x0/0x19
May  7 14:17:32 kot kernel: [  285.035681][] 
lapic_next_event+0x0/0x13
May  7 14:17:32 kot kernel: [  285.035681]  [] 
native_safe_halt+0x2/0x3
May  7 14:17:32 kot kernel: [  285.035681]  [] 
native_safe_halt+0x2/0x3
May  7 14:17:32 kot kernel: [  285.035681]  [] 
default_idle+0x2a/0x49
May  7 14:17:32 kot kernel: [  285.035681]  [] 
cpu_idle+0x8e/0xb8
May  7 14:17:32 kot kernel: [  285.035681]
May  7 14:17:32 kot kernel: [  285.035681] handlers:
May  7 14:17:32 kot kernel: [  285.035681] [] 
(usb_hcd_irq+0x0/0x78)
May  7 14:17:32 kot kernel: [  285.035681] [] 
(vp_interrupt+0x0/0xb8 [virtio_pci])
May  7 14:17:32 kot kernel: [  285.035681] Disabling IRQ #11

This happens in a reproducible fashion on a guest with the following setup:

  * Virtio net + block devices
  * 8 CPU SMP
  * 521 MB RAM
  * Debian Lenny with 2.6.26-2-amd64

Just migrating the guest a couple of times with a bit of I/O activity will
cause it to freeze completely.

It does *not* seem to impact the following:
  * Guests with no virtio devices
  * Guests running 2.6.32-4-amd64 
  * Guests running under qemu-kvm-0.11.1

Thus, it seems to be virtio-specific and possibly related to the guest kernel,
but since qemu-kvm-0.11.1 works fine, I'm filing it as a qemu-kvm regression
and not a kernel bug.

Thank you





[Qemu-devel] [Bug 583462] Re: qemu disables screensaver

2010-05-22 Thread Jaap Versteegh
When I run 
$xtrace qemu

I get:
001:<:00xx:  4: Request(115): ForceScreenSaver mode=Reset(0x00)

every 4 seconds, which explains things I suppose.
Why is that??

-- 
qemu disables screensaver
https://bugs.launchpad.net/bugs/583462
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
lucid, with compiz and fglrx:

Screensaver on host will not kick in when qemu is running (kvm or no kvm). It 
seems to be related to the fact that the idle time reported by libXss.so on the 
host is being reset every four seconds or so when qemu is running, eventhough 
there is no activity on either guest or host.





[Qemu-devel] Re: [PATCH v2 12/15] monitor: Add basic device state visualization

2010-05-22 Thread Avi Kivity

On 05/22/2010 11:18 AM, Jan Kiszka wrote:

From: Jan Kiszka

This introduces device_show, a monitor command that saves the vmstate of
a qdev device and visualizes it. QMP is also supported. Buffers are cut
after 16 byte by default, but the full content can be requested via
'-f'. To pretty-print sub-arrays, vmstate is extended to store the start
index name. A new qerror is introduced to signal a missing vmstate. And
it comes with documentation.

+
+Dump a snapshot of the device state. Buffers are cut after 16 bytes unless
+a full dump is requested.
+
+Arguments:
+
+- "path": the device's qtree path or unique ID (json-string)
   


This may be ambiguous.


+- "full": report full state (json-bool, optional)
   


Is this needed for QMP?  The client can always truncate it to any length.


+
+Schema of returned object:
+
+{ "device": json-string, "id": json-string, "fields" : [ field-objects ] }
+
+The field object array may be empty, otherwise it consists of
+
+{ "name": json-string, "size": json-int, "elems": [ element-objects ] }
+
+"size" describes the real number of bytes required for a binary representation
+of a single field element in the array. The actually transfered amount may be
+smaller unless a full dump was requested.
   


This converts the entire qdev tree into an undocumented stable protocol 
(the qdev paths were already in this state I believe).  This really 
worries me.



+
+The element object array may be empty, otherwise it can contain
+
+- json-int objects
+- QMP buffer objects
+- field objects
+- arrays of json-ints, QMP buffers, or field objects
+
+Example:
+
+->  { "execute": "device_show", "arguments": { "path": "isa.0/i8042" } }
+<- { "return": { "device": "i8042", "id": "", "fields":
+ [ { "name": "kbd", "size": 4, "elems":
+ [ { "name": "write_cmd", "size": 1, "elems": [0] },
+   { "name": "status", "size": 1, "elems": [25] },
+   { "name": "mode", "size": 1, "elems": [3] },
+   { "name": "pending", "size": 1, "elems": [1] }
+ ] }
+ ]
+   }
+   }
+
+EQMP
   


Looks good.  I am only worried about long term stability and documentation.

--
Do not meddle in the internals of kernels, for they are subtle and quick to 
panic.




[Qemu-devel] [PATCH 0/2] virtio-9p changes

2010-05-22 Thread Blue Swirl
With minor changes, I got virtio-9p compiled also on OpenBSD host.

Blue Swirl (2):
  virtio-9p: make virtio-9p available to all POSIX systems
  virtio-9p: fix OpenBSD linker warnings

 Makefile.objs   |8 
 Makefile.target |2 +-
 hw/virtio-9p.c  |4 ++--
 hw/virtio-pci.c |6 +++---
 hw/virtio.h |4 ++--
 qemu-config.c   |4 ++--
 qemu-config.h   |2 +-
 qemu-options.hx |8 
 vl.c|   22 +++---
 9 files changed, 30 insertions(+), 30 deletions(-)



[Qemu-devel] [PATCH 1/2] virtio-9p: make virtio-9p available to all POSIX systems

2010-05-22 Thread Blue Swirl
Field d_off in struct dirent is Linux specific.

Signed-off-by: Blue Swirl 
---
 Makefile.objs   |8 
 Makefile.target |2 +-
 hw/virtio-9p.c  |2 +-
 hw/virtio-pci.c |6 +++---
 hw/virtio.h |4 ++--
 qemu-config.c   |4 ++--
 qemu-config.h   |2 +-
 qemu-options.hx |8 
 vl.c|8 
 9 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 1585101..b1a6e01 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -35,8 +35,8 @@ net-nested-$(CONFIG_SLIRP) += slirp.o
 net-nested-$(CONFIG_VDE) += vde.o
 net-obj-y += $(addprefix net/, $(net-nested-y))

-fsdev-nested-$(CONFIG_LINUX) = qemu-fsdev.o
-fsdev-obj-$(CONFIG_LINUX) += $(addprefix fsdev/, $(fsdev-nested-y))
+fsdev-nested-$(CONFIG_POSIX) = qemu-fsdev.o
+fsdev-obj-$(CONFIG_POSIX) += $(addprefix fsdev/, $(fsdev-nested-y))

 ##
 # libqemu_common.a: Target independent part of system emulation. The
@@ -47,7 +47,7 @@ fsdev-obj-$(CONFIG_LINUX) += $(addprefix fsdev/,
$(fsdev-nested-y))
 common-obj-y = $(block-obj-y)
 common-obj-y += $(net-obj-y)
 common-obj-y += $(qobject-obj-y)
-common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
+common-obj-$(CONFIG_POSIX) += $(fsdev-obj-$(CONFIG_POSIX))
 common-obj-y += readline.o console.o async.o qemu-error.o
 common-obj-y += tcg-runtime.o host-utils.o
 common-obj-y += irq.o ioport.o input.o
@@ -229,7 +229,7 @@ sound-obj-$(CONFIG_CS4231A) += cs4231a.o
 adlib.o fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0
 hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)

-hw-obj-$(CONFIG_LINUX) += virtio-9p-debug.o virtio-9p-local.o
+hw-obj-$(CONFIG_POSIX) += virtio-9p-debug.o virtio-9p-local.o

 ##
 # libdis
diff --git a/Makefile.target b/Makefile.target
index fda5bf3..00e140f 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -168,7 +168,7 @@ obj-y += virtio-blk.o virtio-balloon.o
virtio-net.o virtio-serial-bus.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 obj-y += vhost_net.o
 obj-$(CONFIG_VHOST_NET) += vhost.o
-obj-$(CONFIG_LINUX) += virtio-9p.o
+obj-$(CONFIG_POSIX) += virtio-9p.o
 obj-y += rwhandler.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index e5d0112..68b0696 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1447,8 +1447,8 @@ static void v9fs_read_post_dir_lstat(V9fsState
*s, V9fsReadState *vs,
 vs->count += vs->len;
 v9fs_stat_free(&vs->v9stat);
 v9fs_string_free(&vs->name);
-vs->dir_pos = vs->dent->d_off;
 vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+vs->dir_pos = v9fs_do_telldir(s, vs->fidp->dir);
 v9fs_read_post_readdir(s, vs, err);
 return;
 out:
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 7ddf612..0a74781 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -102,7 +102,7 @@ typedef struct {
 BlockConf block;
 NICConf nic;
 uint32_t host_features;
-#ifdef CONFIG_LINUX
+#ifdef CONFIG_POSIX
 V9fsConf fsconf;
 #endif
 /* Max. number of ports we can have for a the virtio-serial device */
@@ -642,7 +642,7 @@ static int virtio_balloon_init_pci(PCIDevice *pci_dev)
 return 0;
 }

-#ifdef CONFIG_LINUX
+#ifdef CONFIG_POSIX
 static int virtio_9p_init_pci(PCIDevice *pci_dev)
 {
 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -713,7 +713,7 @@ static PCIDeviceInfo virtio_info[] = {
 },
 .qdev.reset = virtio_pci_reset,
 },{
-#ifdef CONFIG_LINUX
+#ifdef CONFIG_POSIX
 .qdev.name = "virtio-9p-pci",
 .qdev.size = sizeof(VirtIOPCIProxy),
 .init  = virtio_9p_init_pci,
diff --git a/hw/virtio.h b/hw/virtio.h
index e4306cd..e77af13 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -20,7 +20,7 @@
 #include "sysemu.h"
 #include "block_int.h"
 #include "event_notifier.h"
-#ifdef CONFIG_LINUX
+#ifdef CONFIG_POSIX
 #include "9p.h"
 #endif

@@ -188,7 +188,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev,
BlockConf *conf);
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf);
 VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports);
 VirtIODevice *virtio_balloon_init(DeviceState *dev);
-#ifdef CONFIG_LINUX
+#ifdef CONFIG_POSIX
 VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf);
 #endif

diff --git a/qemu-config.c b/qemu-config.c
index d500885..78e80e3 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -151,7 +151,7 @@ QemuOptsList qemu_chardev_opts = {
 },
 };

-#ifdef CONFIG_LINUX
+#ifdef CONFIG_POSIX
 QemuOptsList qemu_fsdev_opts = {
 .name = "fsdev",
 .implied_opt_name = "fstype",
@@ -169,7 +169,7 @@ QemuOptsList qemu_fsdev_opts = {
 };
 #endif

-#ifdef CONFIG_LINUX
+#ifdef CONFIG_POSIX
 QemuOptsList qemu_virtfs_opts = {
 .name = "virtfs",
 .implied_opt_name = "fstype",
diff --git a/qemu-config.h b/qemu-config.h
index dca69d4..5376935 100644
--

[Qemu-devel] [PATCH 2/2] virtio-9p: fix OpenBSD linker warnings

2010-05-22 Thread Blue Swirl
virtio-9p.o(.text+0x13c0): In function `v9fs_string_alloc_printf':
/src/qemu/hw/virtio-9p.c:270: warning: vsprintf() is often misused,
please use vsnprintf()

../libhw32/vl.o(.text+0x757c): In function `main':
/src/qemu/vl.c:3124: warning: sprintf() is often misused, please use snprintf()

Signed-off-by: Blue Swirl 
---
 hw/virtio-9p.c |2 +-
 vl.c   |   14 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 68b0696..ee81a7a 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -267,7 +267,7 @@ static int v9fs_string_alloc_printf(char **strp,
const char *fmt, va_list ap)
 alloc_print:
 *strp = qemu_malloc((len + 1) * sizeof(**strp));

-return vsprintf(*strp, fmt, ap);
+return vsnprintf(*strp, len + 1, fmt, ap);
 }

 static void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
diff --git a/vl.c b/vl.c
index d5c1e34..d66b94f 100644
--- a/vl.c
+++ b/vl.c
@@ -3121,10 +3121,10 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }

-sprintf(arg_fsdev, "%s,id=%s,path=%s",
-qemu_opt_get(opts, "fstype"),
-qemu_opt_get(opts, "mount_tag"),
-qemu_opt_get(opts, "path"));
+snprintf(arg_fsdev, len + 1, "%s,id=%s,path=%s",
+ qemu_opt_get(opts, "fstype"),
+ qemu_opt_get(opts, "mount_tag"),
+ qemu_opt_get(opts, "path"));

 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
@@ -3136,9 +3136,9 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }

-sprintf(arg_9p, "virtio-9p-pci,fsdev=%s,mount_tag=%s",
-qemu_opt_get(opts, "mount_tag"),
-qemu_opt_get(opts, "mount_tag"));
+snprintf(arg_9p, len + 1,
"virtio-9p-pci,fsdev=%s,mount_tag=%s",
+ qemu_opt_get(opts, "mount_tag"),
+ qemu_opt_get(opts, "mount_tag"));

 if (!qemu_opts_parse(&qemu_fsdev_opts, arg_fsdev, 1)) {
 fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
-- 
1.6.2.4



Re: [Qemu-devel] Graphics Device Passthrough

2010-05-22 Thread Blue Swirl
On Sat, May 22, 2010 at 4:49 PM, Adhyas Avasthi  wrote:
> Hello
>
> (newbie hacker to qemu community, so please excuse novice ignorances)
>
>
>
> I wish to pass-through a graphics controller to my Windows 7 VM running on
> qemu-kvm. I would like it to be PCI-Express (if that works, that is). Are
> there any recommended devices that I should purchase for this experiment?
>
> I would like the device to also be accessible from my Fedora Core 10 host.
>
>
>
> Basically, I wish to have the device pass-through when I run the VM, I then
> wish to eject the device out of the VM (hot-remove), and then give it back
> to Fedora Core 10 to use. This is how my experiment is defined. I am looking
> for suggestions on graphics controllers I should think of purchasing for
> this experiment. Any help would be appreciated.

I don't think PCI pass-through is implemented yet. If there are no
interrupts, it could be made to work.

QEMU only emulates basic VGA, Cirrus CLGD 54xx, VMWare and XenFB
devices. Only VGA or Cirrus are physically available and these should
not be expensive if they can be found.

For accelerated 2D or 3D, new emulated devices would be needed to be
added to QEMU, so this would make your experiment much bigger. It
could be interesting to emulate some very recent devices, like NVidia
or Radeon cards with a GPU. It's obvious that emulation with only host
CPU support would be very slow but in your pass-through setting that
would not matter. The reverse, using host GPU devices to emulate for
example x86, could also be useful, though the processing power of a
single unit in a GPU is not that much.

If OGP is still alive, that may be another alternative, free emulator
for a "graphics cards with Free-licensed specifications and Free
Software drivers".

The general trend is to virtualize the display, see for example Spice efforts.



[Qemu-devel] [PATCH] ahci: handle writes to generic host control registers

2010-05-22 Thread Sebastian Herbszt
Handle writes to Generic Host Control registers.

Signed-off-by: Sebastian Herbszt 

diff --git a/hw/ahci.c b/hw/ahci.c
index f8e198c..178f9ea 100644
--- a/hw/ahci.c
+++ b/hw/ahci.c
@@ -425,7 +425,6 @@ static uint32_t ahci_mem_readl(void *ptr, 
target_phys_addr_t addr)
 static void ahci_mem_writel(void *ptr, target_phys_addr_t addr, uint32_t val)
 {
AHCIState *s = ptr;
-   uint32_t *p;
addr=addr&0xfff;
 
/* Only aligned reads are allowed on OHCI */
@@ -435,17 +434,30 @@ static void ahci_mem_writel(void *ptr, target_phys_addr_t 
addr, uint32_t val)
return;
}
 
-   if(addr<0x20)
-   {
-   switch(addr)
-   {
-   case HOST_IRQ_STAT:
+   if (addr < 0x20) { /* Generic Host Control */
+   switch(addr) {
+   case HOST_CAP: /* R/WO, RO */
+   /* FIXME handle R/WO */
+   break;
+   case HOST_CTL: /* R/W */
+   if (val & HOST_RESET) {
+   DPRINTF("HBA Reset\n");
+   /* FIXME reset? */
+   } else
+   s->control_regs.ghc = val;
+   break;
+   case HOST_IRQ_STAT: /* R/WC, RO */
s->control_regs.irqstatus &= ~val; 
ahci_check_irq(s);
break;
+   case HOST_PORTS_IMPL: /* R/WO, RO */
+   /* FIXME handle R/WO */
+   break;
+   case HOST_VERSION: /* RO */
+   /* FIXME report write? */
+   break;
default:
-   /* genernal host control */
-   p=(uint32_t *)&s->control_regs;
+   DPRINTF("write to unknown register 0x%x\n", 
(unsigned)addr);
}
}
else if(addr>=0x100 && addr<0x300)




[Qemu-devel] [PATCH] ahci: fix global hba control default value

2010-05-22 Thread Sebastian Herbszt
Global HBA Control default value should be zero.

Signed-off-by: Sebastian Herbszt 

diff --git a/hw/ahci.c b/hw/ahci.c
index 178f9ea..ce87cbe 100644
--- a/hw/ahci.c
+++ b/hw/ahci.c
@@ -485,7 +485,6 @@ static void ahci_reg_init(AHCIState *s)
 {
int i;
s->control_regs.cap = 3 | (0x1f << 8) | (1 << 20) ; /* 4 ports, 32 
command slots, 1.5 Gb/s */
-   s->control_regs.ghc = 1 << 31; /* AHCI Enable */
s->control_regs.impl = 15; /* Ports 0-3 implemented */
s->control_regs.version = 0x1;
for(i=0;i

[Qemu-devel] [RFC 0/5] Tracing backends

2010-05-22 Thread Stefan Hajnoczi
The following patches against qemu.git allow static trace events to be declared
in QEMU.  Trace events use a lightweight syntax and are independent of the
backend tracing system (e.g. LTTng UST).

Supported backends are:
 * my trivial tracer ("simple")
 * LTTng Userspace Tracer ("ust")
 * no tracer ("nop", the default)

The ./configure option to choose a backend is --trace-backend=.

Main point of this patchset: adding new trace events is easy and we can switch
between backends without modifying the code.

Prerna: Would you like to add your tracing system as a backend?  This would be
similar to my patches to add "simple" and "ust" backend support.

Jan: Adding kernel marker backend support should be straightforward if you are
interested.

These patches are also available at:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing




[Qemu-devel] [PATCH 2/5] trace: Add simple built-in tracing backend

2010-05-22 Thread Stefan Hajnoczi
This patch adds a simple tracer which produces binary trace files and is
built into QEMU.  The main purpose of this patch is to show how new
tracing backends can be added to tracetool.

To try out the simple backend:

./configure --trace-backend=simple
make

After running QEMU you can pretty-print the trace:

./tracetool --simple --py events.py  # first time only
./simpletrace.py /tmp/trace.log

Signed-off-by: Stefan Hajnoczi 
---
This is the same trivial tracer that I posted previously.

 .gitignore |2 +
 Makefile.objs  |3 +
 configure  |2 +-
 simpletrace.c  |   64 
 simpletrace.py |   38 +
 tracetool  |  127 ++-
 6 files changed, 232 insertions(+), 4 deletions(-)
 create mode 100644 simpletrace.c
 create mode 100755 simpletrace.py

diff --git a/.gitignore b/.gitignore
index 4644557..68fb21d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ config-host.*
 config-target.*
 trace.h
 trace.c
+events.py
 *-softmmu
 *-darwin-user
 *-linux-user
@@ -39,6 +40,7 @@ qemu-monitor.texi
 *.log
 *.pdf
 *.pg
+*.pyc
 *.toc
 *.tp
 *.vr
diff --git a/Makefile.objs b/Makefile.objs
index 9bbdf6f..d870767 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -252,6 +252,9 @@ libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o
 # trace
 
 trace-obj-y = trace.o
+ifeq ($(TRACE_BACKEND),simple)
+trace-obj-y += simpletrace.o
+endif
 
 vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
diff --git a/configure b/configure
index 5e66f3a..d599879 100755
--- a/configure
+++ b/configure
@@ -829,7 +829,7 @@ echo "  --enable-docsenable documentation build"
 echo "  --disable-docs   disable documentation build"
 echo "  --disable-vhost-net  disable vhost-net acceleration support"
 echo "  --enable-vhost-net   enable vhost-net acceleration support"
-echo "  --trace-backend=BTrace backend nop"
+echo "  --trace-backend=BTrace backend nop simple"
 echo ""
 echo "NOTE: The object files are built at the place where configure is 
launched"
 exit 1
diff --git a/simpletrace.c b/simpletrace.c
new file mode 100644
index 000..2fec4d3
--- /dev/null
+++ b/simpletrace.c
@@ -0,0 +1,64 @@
+#include 
+#include 
+#include "trace.h"
+
+typedef struct {
+unsigned long event;
+unsigned long x1;
+unsigned long x2;
+unsigned long x3;
+unsigned long x4;
+unsigned long x5;
+} TraceRecord;
+
+enum {
+TRACE_BUF_LEN = 64 * 1024 / sizeof(TraceRecord),
+};
+
+static TraceRecord trace_buf[TRACE_BUF_LEN];
+static unsigned int trace_idx;
+static FILE *trace_fp;
+
+static void trace(TraceEvent event, unsigned long x1,
+  unsigned long x2, unsigned long x3,
+  unsigned long x4, unsigned long x5) {
+TraceRecord *rec = &trace_buf[trace_idx];
+rec->event = event;
+rec->x1 = x1;
+rec->x2 = x2;
+rec->x3 = x3;
+rec->x4 = x4;
+rec->x5 = x5;
+
+if (++trace_idx == TRACE_BUF_LEN) {
+trace_idx = 0;
+
+if (!trace_fp) {
+trace_fp = fopen("/tmp/trace.log", "w");
+}
+if (trace_fp) {
+size_t result = fwrite(trace_buf, sizeof trace_buf, 1, trace_fp);
+result = result;
+}
+}
+}
+
+void trace1(TraceEvent event, unsigned long x1) {
+trace(event, x1, 0, 0, 0, 0);
+}
+
+void trace2(TraceEvent event, unsigned long x1, unsigned long x2) {
+trace(event, x1, x2, 0, 0, 0);
+}
+
+void trace3(TraceEvent event, unsigned long x1, unsigned long x2, unsigned 
long x3) {
+trace(event, x1, x2, x3, 0, 0);
+}
+
+void trace4(TraceEvent event, unsigned long x1, unsigned long x2, unsigned 
long x3, unsigned long x4) {
+trace(event, x1, x2, x3, x4, 0);
+}
+
+void trace5(TraceEvent event, unsigned long x1, unsigned long x2, unsigned 
long x3, unsigned long x4, unsigned long x5) {
+trace(event, x1, x2, x3, x4, x5);
+}
diff --git a/simpletrace.py b/simpletrace.py
new file mode 100755
index 000..70609cf
--- /dev/null
+++ b/simpletrace.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+import sys
+import struct
+
+try:
+from events import events
+except ImportError:
+sys.stderr.write('''Unable to import trace events from current working 
directory.  Please run:
+tracetool --simple --py events.py\n''')
+sys.exit(1)
+
+trace_fmt = 'LL'
+trace_len = struct.calcsize(trace_fmt)
+
+def read_record(fobj):
+s = fobj.read(trace_len)
+if len(s) != trace_len:
+return None
+return struct.unpack(trace_fmt, s)
+
+def format_record(rec):
+event = events[rec[0]]
+fields = [event[0]]
+for i in xrange(1, len(event)):
+fields.append('%s=0x%x' % (event[i], rec[i]))
+return ' '.join(fields)
+
+if len(sys.argv) != 2:
+sys.stderr.write('usage: %s \n' % sys.argv[0])
+sys.exit(1)
+
+f = open(sys.argv[1], 'rb')
+while True:
+rec = read_record(f)
+if rec is None:
+break
+
+print format_record(rec)
diff --git a/tracetool b/tracetool

[Qemu-devel] [PATCH 4/5] trace: Trace qemu_malloc() and qemu_vmalloc()

2010-05-22 Thread Stefan Hajnoczi
It is often useful to instrument memory management functions in order to
find leaks or performance problems.  This patch adds trace events for
the memory allocation primitives.

Signed-off-by: Stefan Hajnoczi 
---
An example of adding trace events.

 osdep.c   |9 +
 qemu-malloc.c |4 
 trace-events  |   10 ++
 3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/osdep.c b/osdep.c
index abbc8a2..8e4b8ea 100644
--- a/osdep.c
+++ b/osdep.c
@@ -50,6 +50,7 @@
 #endif
 
 #include "qemu-common.h"
+#include "trace.h"
 #include "sysemu.h"
 #include "qemu_socket.h"
 
@@ -71,6 +72,8 @@ static void *oom_check(void *ptr)
 #if defined(_WIN32)
 void *qemu_memalign(size_t alignment, size_t size)
 {
+trace_qemu_memalign(alignment, size);
+
 if (!size) {
 abort();
 }
@@ -79,6 +82,8 @@ void *qemu_memalign(size_t alignment, size_t size)
 
 void *qemu_vmalloc(size_t size)
 {
+trace_qemu_vmalloc(size);
+
 /* FIXME: this is not exactly optimal solution since VirtualAlloc
has 64Kb granularity, but at least it guarantees us that the
memory is page aligned. */
@@ -90,6 +95,7 @@ void *qemu_vmalloc(size_t size)
 
 void qemu_vfree(void *ptr)
 {
+trace_qemu_vfree(ptr);
 VirtualFree(ptr, 0, MEM_RELEASE);
 }
 
@@ -97,6 +103,8 @@ void qemu_vfree(void *ptr)
 
 void *qemu_memalign(size_t alignment, size_t size)
 {
+trace_qemu_memalign(alignment, size);
+
 #if defined(_POSIX_C_SOURCE) && !defined(__sun__)
 int ret;
 void *ptr;
@@ -122,6 +130,7 @@ void *qemu_vmalloc(size_t size)
 
 void qemu_vfree(void *ptr)
 {
+trace_qemu_vfree(ptr);
 free(ptr);
 }
 
diff --git a/qemu-malloc.c b/qemu-malloc.c
index 6cdc5de..69fc3cf 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
+#include "trace.h"
 #include 
 
 static void *oom_check(void *ptr)
@@ -39,6 +40,7 @@ void *get_mmap_addr(unsigned long size)
 
 void qemu_free(void *ptr)
 {
+trace_qemu_free(ptr);
 free(ptr);
 }
 
@@ -53,6 +55,7 @@ static int allow_zero_malloc(void)
 
 void *qemu_malloc(size_t size)
 {
+trace_qemu_malloc(size);
 if (!size && !allow_zero_malloc()) {
 abort();
 }
@@ -61,6 +64,7 @@ void *qemu_malloc(size_t size)
 
 void *qemu_realloc(void *ptr, size_t size)
 {
+trace_qemu_realloc(ptr, size);
 if (!size && !allow_zero_malloc()) {
 abort();
 }
diff --git a/trace-events b/trace-events
index a37d3cc..a93ea29 100644
--- a/trace-events
+++ b/trace-events
@@ -22,3 +22,13 @@
 # system may not have the necessary headers included.
 #
 # The  should be a sprintf()-compatible format string.
+
+# qemu-malloc.c
+qemu_malloc(size_t size) "size %zu"
+qemu_realloc(void *ptr, size_t size) "ptr %p size %zu"
+qemu_free(void *ptr) "ptr %p"
+
+# osdep.c
+qemu_memalign(size_t alignment, size_t size) "alignment %zu size %zu"
+qemu_valloc(size_t size) "size %zu"
+qemu_vfree(void *ptr) "ptr %p"
-- 
1.7.1




[Qemu-devel] [PATCH 3/5] trace: Add LTTng Userspace Tracer backend

2010-05-22 Thread Stefan Hajnoczi
This patch adds LTTng Userspace Tracer (UST) backend support.  The UST
system requires no kernel support but libust and liburcu must be
installed.

$ ./configure --trace-backend ust
$ make

Start the UST daemon:
$ ustd &

List available tracepoints and enable some:
$ ustctl --list-markers $(pgrep qemu)
[...]
{PID: 5458, channel/marker: ust/paio_submit, state: 0, fmt: "acb %p
opaque %p sector_num %lu nb_sectors %lu type %lu" 0x4b32ba}
$ ustctl --enable-marker "ust/paio_submit" $(pgrep qemu)

Run the trace:
$ ustctl --create-trace $(pgrep qemu)
$ ustctl --start-trace $(pgrep qemu)
[...]
$ ustctl --stop-trace $(pgrep qemu)
$ ustctl --destroy-trace $(pgrep qemu)

Trace results can be viewed using lttv-gui.

More information about UST:
http://lttng.org/ust

Signed-off-by: Stefan Hajnoczi 
---
I wrote this as part of trying out UST.  Although UST is promising, the
usability is poor at the moment.

The dependencies include the lttv trace viewer which I had to build from source
(and it required a makefile tweak to build).  Luckily libust, liburcu, and
ust-bin are packaged on my distro.

Error messages are periodically printed by the UST code when running QEMU.  I
haven't investigated but this is may be due to signals interrupting UST's
thread in poll().

Finally, the UST header files include some userspace ported kernel
infrastructure and pollute the namespace.  I had to add some #undefs to get
QEMU to build after including UST headers.

I don't see LTTng UST as a default option at the moment.  Hopefully this will
change in the future.

 configure |5 +++-
 tracetool |   77 +++-
 2 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index d599879..307dbcb 100755
--- a/configure
+++ b/configure
@@ -829,7 +829,7 @@ echo "  --enable-docsenable documentation build"
 echo "  --disable-docs   disable documentation build"
 echo "  --disable-vhost-net  disable vhost-net acceleration support"
 echo "  --enable-vhost-net   enable vhost-net acceleration support"
-echo "  --trace-backend=BTrace backend nop simple"
+echo "  --trace-backend=BTrace backend nop simple ust"
 echo ""
 echo "NOTE: The object files are built at the place where configure is 
launched"
 exit 1
@@ -2302,6 +2302,9 @@ bsd)
 esac
 
 echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak
+if test "$trace_backend" = "ust"; then
+  LIBS="-lust $LIBS"
+fi
 
 tools=
 if test `expr "$target_list" : ".*softmmu.*"` != 0 ; then
diff --git a/tracetool b/tracetool
index bcd163e..72beb20 100755
--- a/tracetool
+++ b/tracetool
@@ -3,12 +3,13 @@
 usage()
 {
 cat >&2 <"
+}
+
+linetoh_ust()
+{
+local name args argnames
+name=$(get_name "$1")
+args=$(get_args "$1")
+argnames=$(get_argnames "$1")
+
+cat <
+#include "trace.h"
+EOF
+}
+
+linetoc_ust()
+{
+local name args argnames fmt
+name=$(get_name "$1")
+args=$(get_args "$1")
+argnames=$(get_argnames "$1")
+fmt=$(get_fmt "$1")
+
+cat <

[Qemu-devel] [PATCH 5/5] trace: Trace virtio-blk, multiwrite, and paio_submit

2010-05-22 Thread Stefan Hajnoczi
This patch adds trace events that make it possible to observe
virtio-blk.

Signed-off-by: Stefan Hajnoczi 
---
 block.c|7 +++
 hw/virtio-blk.c|7 +++
 posix-aio-compat.c |2 ++
 trace-events   |   14 ++
 4 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index bfe46e3..86fe7f5 100644
--- a/block.c
+++ b/block.c
@@ -23,6 +23,7 @@
  */
 #include "config-host.h"
 #include "qemu-common.h"
+#include "trace.h"
 #include "monitor.h"
 #include "block_int.h"
 #include "module.h"
@@ -1913,6 +1914,8 @@ static void multiwrite_cb(void *opaque, int ret)
 {
 MultiwriteCB *mcb = opaque;
 
+trace_multiwrite_cb(mcb, ret);
+
 if (ret < 0 && !mcb->error) {
 mcb->error = ret;
 multiwrite_user_cb(mcb);
@@ -2044,6 +2047,8 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, 
BlockRequest *reqs, int num_reqs)
 // Check for mergable requests
 num_reqs = multiwrite_merge(bs, reqs, num_reqs, mcb);
 
+trace_bdrv_aio_multiwrite(mcb, mcb->num_callbacks, num_reqs);
+
 // Run the aio requests
 for (i = 0; i < num_reqs; i++) {
 acb = bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov,
@@ -2054,9 +2059,11 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, 
BlockRequest *reqs, int num_reqs)
 // submitted yet. Otherwise we'll wait for the submitted AIOs to
 // complete and report the error in the callback.
 if (mcb->num_requests == 0) {
+trace_bdrv_aio_multiwrite_earlyfail(mcb);
 reqs[i].error = -EIO;
 goto fail;
 } else {
+trace_bdrv_aio_multiwrite_latefail(mcb, i);
 mcb->num_requests++;
 multiwrite_cb(mcb, -EIO);
 break;
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index b05d15e..ef384e0 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -13,6 +13,7 @@
 
 #include 
 #include 
+#include "trace.h"
 #include "virtio-blk.h"
 #include "block_int.h"
 #ifdef __linux__
@@ -50,6 +51,8 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, int 
status)
 {
 VirtIOBlock *s = req->dev;
 
+trace_virtio_blk_req_complete(req, status);
+
 req->in->status = status;
 virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
 virtio_notify(&s->vdev, s->vq);
@@ -87,6 +90,8 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
 {
 VirtIOBlockReq *req = opaque;
 
+trace_virtio_blk_rw_complete(req, ret);
+
 if (ret) {
 int is_read = !(req->out->type & VIRTIO_BLK_T_OUT);
 if (virtio_blk_handle_rw_error(req, -ret, is_read))
@@ -251,6 +256,8 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req)
 static void virtio_blk_handle_write(BlockRequest *blkreq, int *num_writes,
 VirtIOBlockReq *req, BlockDriverState **old_bs)
 {
+trace_virtio_blk_handle_write(req, req->out->sector, req->qiov.size / 512);
+
 if (req->out->sector & req->dev->sector_mask) {
 virtio_blk_rw_complete(req, -EIO);
 return;
diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index b43c531..c2200fe 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -25,6 +25,7 @@
 #include "qemu-queue.h"
 #include "osdep.h"
 #include "qemu-common.h"
+#include "trace.h"
 #include "block_int.h"
 
 #include "block/raw-posix-aio.h"
@@ -583,6 +584,7 @@ BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
 acb->next = posix_aio_state->first_aio;
 posix_aio_state->first_aio = acb;
 
+trace_paio_submit(acb, opaque, sector_num, nb_sectors, type);
 qemu_paio_submit(acb);
 return &acb->common;
 }
diff --git a/trace-events b/trace-events
index a93ea29..4d96b8e 100644
--- a/trace-events
+++ b/trace-events
@@ -32,3 +32,17 @@ qemu_free(void *ptr) "ptr %p"
 qemu_memalign(size_t alignment, size_t size) "alignment %zu size %zu"
 qemu_valloc(size_t size) "size %zu"
 qemu_vfree(void *ptr) "ptr %p"
+
+# block.c
+multiwrite_cb(void *mcb, int ret) "mcb %p ret %d"
+bdrv_aio_multiwrite(void *mcb, int num_callbacks, int num_reqs) "mcb %p 
num_callbacks %d num_reqs %d"
+bdrv_aio_multiwrite_earlyfail(void *mcb) "mcb %p"
+bdrv_aio_multiwrite_latefail(void *mcb, int i) "mcb %p i %d"
+
+# hw/virtio-blk.c
+virtio_blk_req_complete(void *req, int status) "req %p status %d"
+virtio_blk_rw_complete(void *req, int ret) "req %p ret %d"
+virtio_blk_handle_write(void *req, unsigned long sector, unsigned long 
nsectors) "req %p sector %lu nsectors %lu"
+
+# posix-aio-compat.c
+paio_submit(void *acb, void *opaque, unsigned long sector_num, unsigned long 
nb_sectors, unsigned long type) "acb %p opaque %p sector_num %lu nb_sectors %lu 
type %lu"
-- 
1.7.1




[Qemu-devel] [PATCH 1/5] trace: Add trace-events file for declaring trace events

2010-05-22 Thread Stefan Hajnoczi
This patch introduces the trace-events file where trace events can be
declared like so:

qemu_malloc(size_t size) "size %zu"
qemu_free(void *ptr) "ptr %p"

These trace event declarations are processed by a new tool called
tracetool to generate code for the trace events.  Trace event
declarations are independent of the backend tracing system (LTTng User
Space Tracing, kernel markers, DTrace).

The default "nop" backend generates empty trace event functions.
Therefore trace events are disabled by default.

The trace-events file serves to purposes:

1. Adding trace events is easy.  It is not necessary to understand the
   details of a backend tracing system.  The trace-events file is a
   single location where trace events can be declared without code
   duplication.

2. QEMU is not tightly coupled to one particular backend tracing system.
   In order to support tracing across QEMU host platforms and to
   anticipate new backend tracing systems that are currently maturing,
   it is important to be flexible and not tied to one system.

Signed-off-by: Stefan Hajnoczi 
---
 .gitignore  |2 +
 Makefile|   17 +--
 Makefile.objs   |5 ++
 Makefile.target |1 +
 configure   |   19 +++
 trace-events|   24 
 tracetool   |  162 +++
 7 files changed, 226 insertions(+), 4 deletions(-)
 create mode 100644 trace-events
 create mode 100755 tracetool

diff --git a/.gitignore b/.gitignore
index fdfe2f0..4644557 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,8 @@ config-devices.*
 config-all-devices.*
 config-host.*
 config-target.*
+trace.h
+trace.c
 *-softmmu
 *-darwin-user
 *-linux-user
diff --git a/Makefile b/Makefile
index 306a1a4..ff57845 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 # Makefile for QEMU.
 
-GENERATED_HEADERS = config-host.h
+GENERATED_HEADERS = config-host.h trace.h
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -130,16 +130,24 @@ bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
 
 iov.o: iov.c iov.h
 
+trace.h: trace-events
+   $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -h < 
$< > $@,"  GEN   $@")
+
+trace.c: trace-events
+   $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -c < 
$< > $@,"  GEN   $@")
+
+trace.o: trace.c
+
 ##
 
 qemu-img.o: qemu-img-cmds.h
 qemu-img.o qemu-tool.o qemu-nbd.o qemu-io.o: $(GENERATED_HEADERS)
 
-qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(block-obj-y) 
$(qobject-obj-y)
+qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(trace-obj-y) 
$(block-obj-y) $(qobject-obj-y)
 
-qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(block-obj-y) 
$(qobject-obj-y)
+qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(trace-obj-y) 
$(block-obj-y) $(qobject-obj-y)
 
-qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(block-obj-y) 
$(qobject-obj-y)
+qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(trace-obj-y) 
$(block-obj-y) $(qobject-obj-y)
 
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $@")
@@ -157,6 +165,7 @@ clean:
rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~
rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d 
net/*.o net/*.d
rm -f qemu-img-cmds.h
+   rm -f trace.c trace.h
$(MAKE) -C tests clean
for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
diff --git a/Makefile.objs b/Makefile.objs
index acbaf22..9bbdf6f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -248,6 +248,11 @@ libdis-$(CONFIG_S390_DIS) += s390-dis.o
 libdis-$(CONFIG_SH4_DIS) += sh4-dis.o
 libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o
 
+##
+# trace
+
+trace-obj-y = trace.o
+
 vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
diff --git a/Makefile.target b/Makefile.target
index a22484e..4e63c02 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -294,6 +294,7 @@ $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
 obj-y += $(addprefix ../, $(common-obj-y))
 obj-y += $(addprefix ../libdis/, $(libdis-y))
+obj-y += $(addprefix ../, $(trace-obj-y))
 obj-y += $(libobj-y)
 obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y))
 
diff --git a/configure b/configure
index 3cd2c5f..5e66f3a 100755
--- a/configure
+++ b/configure
@@ -299,6 +299,7 @@ pkgversion=""
 check_utests="no"
 user_pie="no"
 zero_malloc=""
+trace_backend="nop"
 
 # OS specific
 if check_define __linux__ ; then
@@ -494,6 +495,8 @@ for opt do
   ;;
   --target-list=*) target_list="$optarg"
   ;;
+  --trace-backend=*) trace_backend="$optarg"
+  ;;
   --enable-gprof) gprof="yes"
   ;;
   --static)
@@ -826,6 +829,7 @

[Qemu-devel] [Bug 583462] Re: qemu disables screensaver

2010-05-22 Thread Jaap Versteegh
Looks like it is SDL related, because setting
SDL_VIDEO_ALLOW_SCREENSAVER=1 
fixes it. 

I understand disabling the screensaver is the default in SDL so the
screensaver won't activate while watching a movie or playing a game.
http://www.libsdl.org/faq.php?action=listentries&category=9#90

Since I don't think this behaviour is desirable for qemu, I guess it
would be useful to prevent the disabling of the screensaver in code.

-- 
qemu disables screensaver
https://bugs.launchpad.net/bugs/583462
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
lucid, with compiz and fglrx:

Screensaver on host will not kick in when qemu is running (kvm or no kvm). It 
seems to be related to the fact that the idle time reported by libXss.so on the 
host is being reset every four seconds or so when qemu is running, eventhough 
there is no activity on either guest or host.





RE: [Qemu-devel] Graphics Device Passthrough

2010-05-22 Thread adhyas.avasthi
In the options for qemu, I did see an option that allowed me to define a host 
bus:dev:fn number to be accessible to the guest. This was not one of the USB 
options I believe. So I assumed some kind of pass-through support is present.

For a PCI pass-through, we probably would not need to emulate the device 
completely (or else what is the need of pass-through). We can emulate just a 
few of the capabilities, and the command/INT registers that are needed to be 
emulated. Even VMware pass-throughs the rest AFAIK. I didn’t realize qemu-kvm 
did not have this support yet.

PS: I have read papers that read about similar experiments people have carried 
on qemu. Didn't realize no code was checked back in the source tree. Thanks for 
letting me know.

Thanks,
Adhyas

-Original Message-
From: qemu-devel-bounces+adhyas.avasthi=nokia@nongnu.org 
[mailto:qemu-devel-bounces+adhyas.avasthi=nokia@nongnu.org] On Behalf Of 
ext Blue Swirl
Sent: Saturday, May 22, 2010 12:58 PM
To: Adhyas Avasthi
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Graphics Device Passthrough

On Sat, May 22, 2010 at 4:49 PM, Adhyas Avasthi  wrote:
> Hello
>
> (newbie hacker to qemu community, so please excuse novice ignorances)
>
>
>
> I wish to pass-through a graphics controller to my Windows 7 VM running on
> qemu-kvm. I would like it to be PCI-Express (if that works, that is). Are
> there any recommended devices that I should purchase for this experiment?
>
> I would like the device to also be accessible from my Fedora Core 10 host.
>
>
>
> Basically, I wish to have the device pass-through when I run the VM, I then
> wish to eject the device out of the VM (hot-remove), and then give it back
> to Fedora Core 10 to use. This is how my experiment is defined. I am looking
> for suggestions on graphics controllers I should think of purchasing for
> this experiment. Any help would be appreciated.

I don't think PCI pass-through is implemented yet. If there are no
interrupts, it could be made to work.

QEMU only emulates basic VGA, Cirrus CLGD 54xx, VMWare and XenFB
devices. Only VGA or Cirrus are physically available and these should
not be expensive if they can be found.

For accelerated 2D or 3D, new emulated devices would be needed to be
added to QEMU, so this would make your experiment much bigger. It
could be interesting to emulate some very recent devices, like NVidia
or Radeon cards with a GPU. It's obvious that emulation with only host
CPU support would be very slow but in your pass-through setting that
would not matter. The reverse, using host GPU devices to emulate for
example x86, could also be useful, though the processing power of a
single unit in a GPU is not that much.

If OGP is still alive, that may be another alternative, free emulator
for a "graphics cards with Free-licensed specifications and Free
Software drivers".

The general trend is to virtualize the display, see for example Spice efforts.



[Qemu-devel] [PATCH] Virtio-net: Replace the hardcode 6 with defined ETN_ALEN

2010-05-22 Thread akong
From: Amos Kong 

hw/virtio-net.h:
#define ETH_ALEN6
ETH_ALEN was defined by commit 7967406801aa897fae83caad3278ac85a342adaa

Signed-off-by: Amos Kong 
---
 hw/virtio-net.h |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index e55119b..235f1a9 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -54,8 +54,8 @@
 
 struct virtio_net_config
 {
-/* The config defining mac address (6 bytes) */
-uint8_t mac[6];
+/* The config defining mac address ($ETH_ALEN bytes) */
+uint8_t mac[ETH_ALEN];
 /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
 uint16_t status;
 } __attribute__((packed));
-- 
1.7.0.4




[Qemu-devel] Inquiry about qemu for Motorola 68360

2010-05-22 Thread hadi motamedi
Dear All
Do you have qemu emulator for Motorola 68360 emulation on x86 Windows
platform?
Thank you in advance