[Qemu-devel] [PATCH v18 10/14] numa: add -numa node, memdev= option

2014-02-19 Thread Hu Tao
From: Paolo Bonzini pbonz...@redhat.com

This option provides the infrastructure for binding guest NUMA nodes
to host NUMA nodes.  For example:

 -object memory-ram,size=1024M,policy=membind,host-nodes=0,id=ram-node0 \
 -numa node,nodeid=0,cpus=0,memdev=ram-node0 \
 -object memory-ram,size=1024M,policy=interleave,host-nodes=1-3,id=ram-node1 \
 -numa node,nodeid=1,cpus=1,memdev=ram-node1

The option replaces -numa mem.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com

Conflicts:
include/sysemu/sysemu.h
numa.c

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 include/sysemu/sysemu.h |  2 ++
 numa.c  | 64 +++--
 qapi-schema.json|  6 -
 3 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index e9da760..acfc0c7 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -12,6 +12,7 @@
 #include qemu/bitmap.h
 #include qom/object.h
 #include hw/boards.h
+#include sysemu/hostmem.h
 
 /* vl.c */
 
@@ -140,6 +141,7 @@ extern int nb_numa_nodes;
 typedef struct node_info {
 uint64_t node_mem;
 DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
+HostMemoryBackend *node_memdev;
 } NodeInfo;
 extern NodeInfo numa_info[MAX_NODES];
 void set_numa_nodes(void);
diff --git a/numa.c b/numa.c
index 403b08b..ca55ad7 100644
--- a/numa.c
+++ b/numa.c
@@ -27,6 +27,8 @@
 #include qapi-visit.h
 #include qapi/opts-visitor.h
 #include qapi/dealloc-visitor.h
+#include qapi/qmp/qerror.h
+
 QemuOptsList qemu_numa_opts = {
 .name = numa,
 .implied_opt_name = type,
@@ -34,10 +36,13 @@ QemuOptsList qemu_numa_opts = {
 .desc = { { 0 } } /* validated with OptsVisitor */
 };
 
+static int have_memdevs = -1;
+
 static int numa_node_parse(NumaNodeOptions *opts)
 {
 uint16_t nodenr;
 uint16List *cpus = NULL;
+Error *local_err = NULL;
 
 if (opts-has_nodeid) {
 nodenr = opts-nodeid;
@@ -60,6 +65,19 @@ static int numa_node_parse(NumaNodeOptions *opts)
 bitmap_set(numa_info[nodenr].node_cpu, cpus-value, 1);
 }
 
+if (opts-has_mem  opts-has_memdev) {
+fprintf(stderr, qemu: cannot specify both mem= and memdev=\n);
+return -1;
+}
+
+if (have_memdevs == -1) {
+have_memdevs = opts-has_memdev;
+}
+if (opts-has_memdev != have_memdevs) {
+fprintf(stderr, qemu: memdev option must be specified for either 
+all or no nodes\n);
+}
+
 if (opts-has_mem) {
 int64_t mem_size;
 char *endptr;
@@ -70,7 +88,19 @@ static int numa_node_parse(NumaNodeOptions *opts)
 }
 numa_info[nodenr].node_mem = mem_size;
 }
+if (opts-has_memdev) {
+Object *o;
+o = object_resolve_path_type(opts-memdev, TYPE_MEMORY_BACKEND, NULL);
+if (!o) {
+error_setg(local_err, memdev=%s is ambiguous, opts-memdev);
+qerror_report_err(local_err);
+return -1;
+}
 
+object_ref(o);
+numa_info[nodenr].node_mem = object_property_get_int(o, size, NULL);
+numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
+}
 return 0;
 }
 
@@ -189,12 +219,42 @@ void set_numa_modes(void)
 }
 }
 
+static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
+   const char *name,
+   QEMUMachineInitArgs *args)
+{
+uint64_t ram_size = args-ram_size;
+
+memory_region_init_ram(mr, owner, name, ram_size);
+vmstate_register_ram_global(mr);
+}
+
 void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
   const char *name,
   QEMUMachineInitArgs *args)
 {
 uint64_t ram_size = args-ram_size;
+uint64_t addr = 0;
+int i;
 
-memory_region_init_ram(mr, owner, name, ram_size);
-vmstate_register_ram_global(mr);
+if (nb_numa_nodes == 0 || !have_memdevs) {
+allocate_system_memory_nonnuma(mr, owner, name, args);
+return;
+}
+
+memory_region_init(mr, owner, name, ram_size);
+for (i = 0; i  nb_numa_nodes; i++) {
+Error *local_err = NULL;
+uint64_t size = numa_info[i].node_mem;
+HostMemoryBackend *backend = numa_info[i].node_memdev;
+MemoryRegion *seg = host_memory_backend_get_memory(backend, 
local_err);
+if (local_err) {
+qerror_report_err(local_err);
+exit(1);
+}
+
+memory_region_add_subregion(mr, addr, seg);
+vmstate_register_ram_global(seg);
+addr += size;
+}
 }
diff --git a/qapi-schema.json b/qapi-schema.json
index a2839b8..498ea9b 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4441,7 +4441,10 @@
 #
 # @cpus: #optional VCPUs belong to this node
 #
-# @mem: #optional memory size of this node
+# @memdev: #optional memory backend object.  If specified for 

[Qemu-devel] [PATCH v18 04/14] NUMA: convert -numa option to use OptsVisitor

2014-02-19 Thread Hu Tao
From: Wanlong Gao gaowanl...@cn.fujitsu.com

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 include/sysemu/sysemu.h |   3 +-
 numa.c  | 148 +++-
 qapi-schema.json|  30 ++
 vl.c|  11 +++-
 4 files changed, 114 insertions(+), 78 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d873b42..20b05a3 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -140,9 +140,10 @@ typedef struct node_info {
 DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
 } NodeInfo;
 extern NodeInfo numa_info[MAX_NODES];
-void numa_add(const char *optarg);
 void set_numa_nodes(void);
 void set_numa_modes(void);
+extern QemuOptsList qemu_numa_opts;
+int numa_init_func(QemuOpts *opts, void *opaque);
 
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
diff --git a/numa.c b/numa.c
index 1f413a0..827c76f 100644
--- a/numa.c
+++ b/numa.c
@@ -24,101 +24,97 @@
  */
 
 #include sysemu/sysemu.h
-
-static void numa_node_parse_cpus(int nodenr, const char *cpus)
+#include qapi-visit.h
+#include qapi/opts-visitor.h
+#include qapi/dealloc-visitor.h
+QemuOptsList qemu_numa_opts = {
+.name = numa,
+.implied_opt_name = type,
+.head = QTAILQ_HEAD_INITIALIZER(qemu_numa_opts.head),
+.desc = { { 0 } } /* validated with OptsVisitor */
+};
+
+static int numa_node_parse(NumaNodeOptions *opts)
 {
-char *endptr;
-unsigned long long value, endvalue;
-
-/* Empty CPU range strings will be considered valid, they will simply
- * not set any bit in the CPU bitmap.
- */
-if (!*cpus) {
-return;
-}
+uint16_t nodenr;
+uint16List *cpus = NULL;
 
-if (parse_uint(cpus, value, endptr, 10)  0) {
-goto error;
-}
-if (*endptr == '-') {
-if (parse_uint_full(endptr + 1, endvalue, 10)  0) {
-goto error;
-}
-} else if (*endptr == '\0') {
-endvalue = value;
+if (opts-has_nodeid) {
+nodenr = opts-nodeid;
 } else {
-goto error;
+nodenr = nb_numa_nodes;
 }
 
-if (endvalue = MAX_CPUMASK_BITS) {
-endvalue = MAX_CPUMASK_BITS - 1;
-fprintf(stderr,
-qemu: NUMA: A max of %d VCPUs are supported\n,
- MAX_CPUMASK_BITS);
+if (nodenr = MAX_NODES) {
+fprintf(stderr, qemu: Max number of NUMA nodes reached: %
+PRIu16 \n, nodenr);
+return -1;
 }
 
-if (endvalue  value) {
-goto error;
+for (cpus = opts-cpus; cpus; cpus = cpus-next) {
+if (cpus-value  MAX_CPUMASK_BITS) {
+fprintf(stderr, qemu: cpu number % PRIu16  is bigger than %d,
+cpus-value, MAX_CPUMASK_BITS);
+continue;
+}
+bitmap_set(numa_info[nodenr].node_cpu, cpus-value, 1);
 }
 
-bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1);
-return;
+if (opts-has_mem) {
+int64_t mem_size;
+char *endptr;
+mem_size = strtosz(opts-mem, endptr);
+if (mem_size  0 || *endptr) {
+fprintf(stderr, qemu: invalid numa mem size: %s\n, opts-mem);
+return -1;
+}
+numa_info[nodenr].node_mem = mem_size;
+}
 
-error:
-fprintf(stderr, qemu: Invalid NUMA CPU range: %s\n, cpus);
-exit(1);
+return 0;
 }
 
-void numa_add(const char *optarg)
+int numa_init_func(QemuOpts *opts, void *opaque)
 {
-char option[128];
-char *endptr;
-unsigned long long nodenr;
-
-optarg = get_opt_name(option, 128, optarg, ',');
-if (*optarg == ',') {
-optarg++;
+NumaOptions *object = NULL;
+Error *err = NULL;
+int ret = 0;
+
+{
+OptsVisitor *ov = opts_visitor_new(opts);
+visit_type_NumaOptions(opts_get_visitor(ov), object, NULL, err);
+opts_visitor_cleanup(ov);
 }
-if (!strcmp(option, node)) {
-
-if (nb_numa_nodes = MAX_NODES) {
-fprintf(stderr, qemu: too many NUMA nodes\n);
-exit(1);
-}
 
-if (get_param_value(option, 128, nodeid, optarg) == 0) {
-nodenr = nb_numa_nodes;
-} else {
-if (parse_uint_full(option, nodenr, 10)  0) {
-fprintf(stderr, qemu: Invalid NUMA nodeid: %s\n, option);
-exit(1);
-}
-}
-
-if (nodenr = MAX_NODES) {
-fprintf(stderr, qemu: invalid NUMA nodeid: %llu\n, nodenr);
-exit(1);
-}
+if (error_is_set(err)) {
+fprintf(stderr, qemu: %s\n, error_get_pretty(err));
+error_free(err);
+ret = -1;
+goto error;
+}
 
-if (get_param_value(option, 128, mem, optarg) == 0) {
-numa_info[nodenr].node_mem = 0;
-} else {
-int64_t sval;
-sval = strtosz(option, endptr);
-

[Qemu-devel] [PATCH v18 09/14] numa: introduce memory_region_allocate_system_memory

2014-02-19 Thread Hu Tao
From: Paolo Bonzini pbonz...@redhat.com

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 hw/i386/pc.c|  4 +---
 include/sysemu/sysemu.h |  5 +
 numa.c  | 10 ++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 17d4820..ff078fb 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1165,9 +1165,7 @@ FWCfgState *pc_memory_init(QEMUMachineInitArgs *args,
  * with older qemus that used qemu_ram_alloc().
  */
 ram = g_malloc(sizeof(*ram));
-memory_region_init_ram(ram, NULL, pc.ram,
-   below_4g_mem_size + above_4g_mem_size);
-vmstate_register_ram_global(ram);
+memory_region_allocate_system_memory(ram, NULL, pc.ram, args);
 *ram_memory = ram;
 ram_below_4g = g_malloc(sizeof(*ram_below_4g));
 memory_region_init_alias(ram_below_4g, NULL, ram-below-4g, ram,
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 4c94cf5..e9da760 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -10,6 +10,8 @@
 #include qemu/notify.h
 #include qemu/main-loop.h
 #include qemu/bitmap.h
+#include qom/object.h
+#include hw/boards.h
 
 /* vl.c */
 
@@ -144,6 +146,9 @@ void set_numa_nodes(void);
 void set_numa_modes(void);
 extern QemuOptsList qemu_numa_opts;
 int numa_init_func(QemuOpts *opts, void *opaque);
+void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
+  const char *name,
+  QEMUMachineInitArgs *args);
 
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
diff --git a/numa.c b/numa.c
index 827c76f..403b08b 100644
--- a/numa.c
+++ b/numa.c
@@ -188,3 +188,13 @@ void set_numa_modes(void)
 }
 }
 }
+
+void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
+  const char *name,
+  QEMUMachineInitArgs *args)
+{
+uint64_t ram_size = args-ram_size;
+
+memory_region_init_ram(mr, owner, name, ram_size);
+vmstate_register_ram_global(mr);
+}
-- 
1.8.5.2.229.g4448466




[Qemu-devel] [PATCH v18 02/14] NUMA: check if the total numa memory size is equal to ram_size

2014-02-19 Thread Hu Tao
From: Wanlong Gao gaowanl...@cn.fujitsu.com

If the total number of the assigned numa nodes memory is not
equal to the assigned ram size, it will write the wrong data
to ACPI talb, then the guest will ignore the wrong ACPI table
and recognize all memory to one node. It's buggy, we should
check it to ensure that we write the right data to ACPI table.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 numa.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/numa.c b/numa.c
index 7845036..a06e2d1 100644
--- a/numa.c
+++ b/numa.c
@@ -151,6 +151,16 @@ void set_numa_nodes(void)
 node_mem[i] = ram_size - usedmem;
 }
 
+uint64_t numa_total = 0;
+for (i = 0; i  nb_numa_nodes; i++) {
+numa_total += node_mem[i];
+}
+if (numa_total != ram_size) {
+fprintf(stderr, qemu: numa nodes total memory size 
+should equal to ram_size\n);
+exit(1);
+}
+
 for (i = 0; i  nb_numa_nodes; i++) {
 if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
 break;
-- 
1.8.5.2.229.g4448466




[Qemu-devel] [PATCH v18 08/14] pc: pass QEMUMachineInitArgs to pc_memory_init

2014-02-19 Thread Hu Tao
From: Paolo Bonzini pbonz...@redhat.com

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 hw/i386/pc.c | 11 +--
 hw/i386/pc_piix.c|  8 +++-
 hw/i386/pc_q35.c |  4 +---
 include/hw/i386/pc.h |  7 +++
 4 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index a464e48..17d4820 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1145,10 +1145,8 @@ void pc_acpi_init(const char *default_dsdt)
 }
 }
 
-FWCfgState *pc_memory_init(MemoryRegion *system_memory,
-   const char *kernel_filename,
-   const char *kernel_cmdline,
-   const char *initrd_filename,
+FWCfgState *pc_memory_init(QEMUMachineInitArgs *args,
+   MemoryRegion *system_memory,
ram_addr_t below_4g_mem_size,
ram_addr_t above_4g_mem_size,
MemoryRegion *rom_memory,
@@ -1160,7 +1158,7 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
 MemoryRegion *ram_below_4g, *ram_above_4g;
 FWCfgState *fw_cfg;
 
-linux_boot = (kernel_filename != NULL);
+linux_boot = (args-kernel_filename != NULL);
 
 /* Allocate RAM.  We allocate it as a single memory region and use
  * aliases to address portions of it, mostly for backwards compatibility
@@ -1201,7 +1199,8 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
 rom_set_fw(fw_cfg);
 
 if (linux_boot) {
-load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, 
below_4g_mem_size);
+load_linux(fw_cfg, args-kernel_filename, args-initrd_filename,
+   args-kernel_cmdline, below_4g_mem_size);
 }
 
 for (i = 0; i  nb_option_roms; i++) {
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 1acd2b2..670d417 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -151,11 +151,9 @@ static void pc_init1(QEMUMachineInitArgs *args,
 
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
-fw_cfg = pc_memory_init(system_memory,
-   args-kernel_filename, args-kernel_cmdline,
-   args-initrd_filename,
-   below_4g_mem_size, above_4g_mem_size,
-   rom_memory, ram_memory, guest_info);
+fw_cfg = pc_memory_init(args, system_memory,
+below_4g_mem_size, above_4g_mem_size,
+rom_memory, ram_memory, guest_info);
 }
 
 gsi_state = g_malloc0(sizeof(*gsi_state));
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index a7f6260..95fa01fc 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -138,9 +138,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
-pc_memory_init(get_system_memory(),
-   args-kernel_filename, args-kernel_cmdline,
-   args-initrd_filename,
+pc_memory_init(args, get_system_memory(),
below_4g_mem_size, above_4g_mem_size,
rom_memory, ram_memory, guest_info);
 }
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 3e1e81b..699d93d 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -3,6 +3,7 @@
 
 #include qemu-common.h
 #include exec/memory.h
+#include hw/boards.h
 #include hw/isa/isa.h
 #include hw/block/fdc.h
 #include net/net.h
@@ -134,10 +135,8 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t 
below_4g_mem_size,
 void pc_pci_as_mapping_init(Object *owner, MemoryRegion *system_memory,
 MemoryRegion *pci_address_space);
 
-FWCfgState *pc_memory_init(MemoryRegion *system_memory,
-   const char *kernel_filename,
-   const char *kernel_cmdline,
-   const char *initrd_filename,
+FWCfgState *pc_memory_init(QEMUMachineInitArgs *args,
+   MemoryRegion *system_memory,
ram_addr_t below_4g_mem_size,
ram_addr_t above_4g_mem_size,
MemoryRegion *rom_memory,
-- 
1.8.5.2.229.g4448466




[Qemu-devel] [PATCH v18 07/14] add memdev backend infrastructure

2014-02-19 Thread Hu Tao
Provides framework for splitting host RAM allocation/
policies into a separate backend that could be used
by devices.

Initially only legacy RAM backend is provided, which
uses memory_region_init_ram() allocator and compatible
with every CLI option that affects memory_region_init_ram().

Signed-off-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Hu Tao hu...@cn.fujitsu.com

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 backends/Makefile.objs   |   2 +
 backends/hostmem-ram.c   |  48 ++
 backends/hostmem.c   | 125 +++
 include/sysemu/hostmem.h |  63 
 4 files changed, 238 insertions(+)
 create mode 100644 backends/hostmem-ram.c
 create mode 100644 backends/hostmem.c
 create mode 100644 include/sysemu/hostmem.h

diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index 42557d5..e6bdc11 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -6,3 +6,5 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
 $(obj)/baum.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
 
 common-obj-$(CONFIG_TPM) += tpm.o
+
+common-obj-y += hostmem.o hostmem-ram.o
diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
new file mode 100644
index 000..a496dbd
--- /dev/null
+++ b/backends/hostmem-ram.c
@@ -0,0 +1,48 @@
+/*
+ * QEMU Host Memory Backend
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov imamm...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include sysemu/hostmem.h
+
+#define TYPE_MEMORY_BACKEND_RAM memory-ram
+
+
+static int
+ram_backend_memory_init(HostMemoryBackend *backend, Error **errp)
+{
+if (!memory_region_size(backend-mr)) {
+memory_region_init_ram(backend-mr, OBJECT(backend),
+   object_get_canonical_path(OBJECT(backend)),
+   backend-size);
+}
+
+return 0;
+}
+
+static void
+ram_backend_class_init(ObjectClass *oc, void *data)
+{
+HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
+
+bc-memory_init = ram_backend_memory_init;
+}
+
+static const TypeInfo ram_backend_info = {
+.name = TYPE_MEMORY_BACKEND_RAM,
+.parent = TYPE_MEMORY_BACKEND,
+.class_init = ram_backend_class_init,
+};
+
+static void register_types(void)
+{
+type_register_static(ram_backend_info);
+}
+
+type_init(register_types);
diff --git a/backends/hostmem.c b/backends/hostmem.c
new file mode 100644
index 000..4b8fd8d
--- /dev/null
+++ b/backends/hostmem.c
@@ -0,0 +1,125 @@
+/*
+ * QEMU Host Memory Backend
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov imamm...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include sysemu/hostmem.h
+#include sysemu/sysemu.h
+#include qapi/visitor.h
+#include qapi/qmp/qerror.h
+#include qemu/config-file.h
+#include qom/object_interfaces.h
+
+static void
+hostmemory_backend_get_size(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+uint64_t value = backend-size;
+
+visit_type_size(v, value, name, errp);
+}
+
+static void
+hostmemory_backend_set_size(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+uint64_t value;
+
+if (memory_region_size(backend-mr)) {
+error_setg(errp, cannot change property value\n);
+return;
+}
+
+visit_type_size(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+if (!value) {
+error_setg(errp, Property '%s.%s' doesn't take value '% PRIu64 ',
+   object_get_typename(obj), name , value);
+return;
+}
+backend-size = value;
+}
+
+static void hostmemory_backend_initfn(Object *obj)
+{
+object_property_add(obj, size, int,
+hostmemory_backend_get_size,
+hostmemory_backend_set_size, NULL, NULL, NULL);
+}
+
+static void hostmemory_backend_finalize(Object *obj)
+{
+HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+if (memory_region_size(backend-mr)) {
+memory_region_destroy(backend-mr);
+}
+}
+
+static int
+hostmemory_backend_memory_init(HostMemoryBackend *backend, Error **errp)
+{
+error_setg(errp, memory_init is not implemented for type [%s],
+   object_get_typename(OBJECT(backend)));
+
+return -1;
+}
+
+MemoryRegion *
+host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp)
+{
+HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(backend);
+Object *obj = OBJECT(backend);
+
+if (!backend-size) {
+error_setg(errp, Invalid property 

[Qemu-devel] [PATCH v18 05/14] NUMA: expand MAX_NODES from 64 to 128

2014-02-19 Thread Hu Tao
From: Wanlong Gao gaowanl...@cn.fujitsu.com

libnuma choosed 128 for MAX_NODES, so we follow libnuma here.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 include/sysemu/sysemu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 20b05a3..4c94cf5 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -132,7 +132,7 @@ extern size_t boot_splash_filedata_size;
 extern uint8_t qemu_extra_params_fw[2];
 extern QEMUClockType rtc_clock;
 
-#define MAX_NODES 64
+#define MAX_NODES 128
 #define MAX_CPUMASK_BITS 255
 extern int nb_numa_nodes;
 typedef struct node_info {
-- 
1.8.5.2.229.g4448466




[Qemu-devel] [PATCH v18 12/14] qapi: add HostMemPolicy enum type

2014-02-19 Thread Hu Tao
From: Wanlong Gao gaowanl...@cn.fujitsu.com

This new enum type will be used to set host memory policy of
backend host memory.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 qapi-schema.json | 20 
 1 file changed, 20 insertions(+)

diff --git a/qapi-schema.json b/qapi-schema.json
index 498ea9b..9d6370f 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4454,3 +4454,23 @@
'*cpus':   ['uint16'],
'*memdev': 'str',
'*mem':'str' }}
+
+##
+# @HostMemPolicy
+#
+# Host memory policy types
+#
+# @default: restore default policy, remove any nondefault policy
+#
+# @preferred: set the preferred host node for allocation
+#
+# @membind: a strict policy that restricts memory allocation to the
+#   host nodes specified
+#
+# @interleave: the page allocations is interleaved across the set
+#  of host nodes specified
+#
+# Since 2.0
+##
+{ 'enum': 'HostMemPolicy',
+  'data': [ 'default', 'preferred', 'membind', 'interleave' ] }
-- 
1.8.5.2.229.g4448466




[Qemu-devel] [PATCH v18 14/14] amp: add query-memdev

2014-02-19 Thread Hu Tao
Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 backends/hostmem-ram.c | 71 --
 qapi-schema.json   | 31 ++
 qmp-commands.hx| 30 +
 3 files changed, 124 insertions(+), 8 deletions(-)

diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index 2da9341..9f19ab8 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -15,6 +15,7 @@
 #include qapi-visit.h
 #include qemu/config-file.h
 #include qapi/opts-visitor.h
+#include qmp-commands.h
 
 #define TYPE_MEMORY_BACKEND_RAM memory-ram
 #define MEMORY_BACKEND_RAM(obj) \
@@ -37,8 +38,66 @@ struct HostMemoryBackendRam {
 DECLARE_BITMAP(host_nodes, MAX_NODES);
 HostMemPolicy policy;
 bool relative;
+
+QTAILQ_ENTRY(HostMemoryBackendRam) next;
+};
+
+static const char *policies[HOST_MEM_POLICY_MAX + 1] = {
+[HOST_MEM_POLICY_DEFAULT] = default,
+[HOST_MEM_POLICY_PREFERRED] = preferred,
+[HOST_MEM_POLICY_MEMBIND] = membind,
+[HOST_MEM_POLICY_INTERLEAVE] = interleave,
+[HOST_MEM_POLICY_MAX] = NULL,
 };
 
+static GSList *memdevs;
+
+static void func(gpointer data, gpointer user_data)
+{
+HostMemoryBackendRam *backend = data;
+MemdevList **list = user_data;
+MemdevList *m;
+uint16List **node;
+unsigned long value;
+
+m = g_malloc0(sizeof(*m));
+m-value = g_malloc0(sizeof(*m-value));
+m-value-policy = g_strdup(policies[backend-policy]);
+m-value-relative = backend-relative;
+
+node = m-value-host_nodes;
+
+value = find_first_bit(backend-host_nodes, MAX_NODES);
+if (value  MAX_NODES) {
+*node = g_malloc0(sizeof(**node));
+(*node)-value = value;
+node = (*node)-next;
+
+do {
+value = find_next_bit(backend-host_nodes, MAX_NODES, value + 1);
+if (value == MAX_NODES) {
+break;
+}
+
+*node = g_malloc0(sizeof(**node));
+(*node)-value = value;
+node = (*node)-next;
+} while (true);
+}
+
+m-next = *list;
+*list = m;
+}
+
+MemdevList *qmp_query_memdev(Error **errp)
+{
+MemdevList *list = NULL;
+
+g_slist_foreach(memdevs, func, list);
+
+return list;
+}
+
 static void
 get_host_nodes(Object *obj, Visitor *v, void *opaque, const char *name,
Error **errp)
@@ -86,14 +145,6 @@ set_host_nodes(Object *obj, Visitor *v, void *opaque, const 
char *name,
 }
 }
 
-static const char *policies[HOST_MEM_POLICY_MAX + 1] = {
-[HOST_MEM_POLICY_DEFAULT] = default,
-[HOST_MEM_POLICY_PREFERRED] = preferred,
-[HOST_MEM_POLICY_MEMBIND] = membind,
-[HOST_MEM_POLICY_INTERLEAVE] = interleave,
-[HOST_MEM_POLICY_MAX] = NULL,
-};
-
 static void
 get_policy(Object *obj, Visitor *v, void *opaque, const char *name,
Error **errp)
@@ -172,6 +223,8 @@ ram_backend_memory_init(HostMemoryBackend *backend, Error 
**errp)
 static void
 ram_backend_initfn(Object *obj)
 {
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
+
 object_property_add(obj, host-nodes, int,
 get_host_nodes,
 set_host_nodes, NULL, NULL, NULL);
@@ -180,6 +233,8 @@ ram_backend_initfn(Object *obj)
 set_policy, NULL, NULL, NULL);
 object_property_add_bool(obj, relative,
  get_relative, set_relative, NULL);
+
+memdevs = g_slist_append(memdevs, ram_backend);
 }
 
 static void
diff --git a/qapi-schema.json b/qapi-schema.json
index 9d6370f..7b5027d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4474,3 +4474,34 @@
 ##
 { 'enum': 'HostMemPolicy',
   'data': [ 'default', 'preferred', 'membind', 'interleave' ] }
+
+##
+# @Memdev:
+#
+# Information of memory device
+#
+# @id: memory device id
+#
+# @host-nodes: host nodes for its memory policy
+#
+# @policy: memory policy of memory device
+#
+# Since: 2.0
+##
+
+{ 'type': 'Memdev',
+  'data': {
+'host-nodes': ['uint16'],
+'policy': 'str',
+'relative': 'bool' }}
+
+##
+# @query-memdev:
+#
+# Returns information for all memory devices.
+#
+# Returns: a list of @Memdev.
+#
+# Since: 2.0
+##
+{ 'command': 'query-memdev', 'returns': ['Memdev'] }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index cce6b81..20368f7 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3457,3 +3457,33 @@ Example:
} } ] }
 
 EQMP
+
+{
+.name   = query-memdev,
+.args_type  = ,
+.mhandler.cmd_new = qmp_marshal_input_query_memdev,
+},
+
+SQMP
+query-memdev
+
+
+Show memory devices information.
+
+
+Example (1):
+
+- { execute: query-memdev }
+- { return: [
+   {
+ host-nodes: [0, 1],
+ policy: bind
+   },
+   {
+ host-nodes: [2, 3],
+ policy: preferred
+   }
+ ]
+   }
+
+EQMP
-- 
1.8.5.2.229.g4448466




Re: [Qemu-devel] MSI interrupt support with vioscsi.c miniport driver

2014-02-19 Thread Vadim Rozenfeld
On Tue, 2014-02-18 at 13:00 -0800, Nicholas A. Bellinger wrote:
 On Mon, 2014-02-10 at 11:05 -0800, Nicholas A. Bellinger wrote:
 
 SNIP
 
 Hi Yan,
 
 So recently I've been doing some KVM guest performance comparisons
 between the scsi-mq prototype using virtio-scsi + vhost-scsi, and
 Windows Server 2012 with vioscsi.sys (virtio-win-0.1-74.iso) +
 vhost-scsi using PCIe flash backend devices.
 
 I've noticed that small block random performance for the MSFT guest is
 at around ~80K IOPs with multiple vioscsi LUNs + adapters, which ends 
 up
 being well below what the Linux guest with scsi-mq + virtio-scsi is
 capable of (~500K).
 
 After searching through the various vioscsi registry settings, it
 appears that MSIEnabled is being explicitly disabled (0x), 
 that
 is different from what vioscsi.inx is currently defining:
 
 [pnpsafe_pci_addreg_msix]
 HKR, Interrupt Management,, 0x0010
 HKR, Interrupt Management\MessageSignaledInterruptProperties,, 
 0x0010
 HKR, Interrupt Management\MessageSignaledInterruptProperties, 
 MSISupported, 0x00010001, 0
 HKR, Interrupt Management\MessageSignaledInterruptProperties, 
 MessageNumberLimit, 0x00010001, 4
 
 Looking deeper at vioscsi.c code, I've noticed that MSI_SUPPORTED=0 is
 explicitly disabled at build time in SOURCES + vioscsi.vcxproj, as 
 well
 as VioScsiFindAdapter() code always ends setting msix_enabled = FALSE
 here, regardless of MSI_SUPPORTED:
 
  
 https://github.com/YanVugenfirer/kvm-guest-drivers-windows/blob/master/vioscsi/vioscsi.c#L340
 
 Also looking at virtio_stor.c for the raw block driver, 
 MSI_SUPPORTED=1
 appears to be the default setting for the driver included in the 
 offical
 virtio-win iso builds, right..?
 
 Sooo, I'd like to try enabling MSI_SUPPORTED=1 in a test vioscsi.sys
 build of my own, but before going down the WDK development rabbit 
 whole,
 I'd like to better understand why you've explicitly disabled this 
 logic
 within vioscsi.c code to start..?
 
 Is there anything that needs to be addressed / carried over from
 virtio_stor.c in order to get MSI_SUPPORTED=1 to work with vioscsi.c
 miniport code..?
   
   Hi Nicholas,
   
   I was thinking about enabling MSI in RHEL 6.6 (build 74) but for some
   reasons decided to keep it disabled until adding mq support.
   
   
   You definitely should be able to turn on MSI_SUPPORTED, rebuild the
   driver, and switch MSISupported to 1 to make vioscsi driver working in
   MSI mode.
  
  
  Thanks for the quick response.  We'll give MSI_SUPPORTED=1 a shot over
  the next days with a test build on Server 2012 / Server 2008 R2 and see
  how things go..
  
 
 Just a quick update on progress.
 
 I've been able to successfully build + load a unsigned vioscsi.sys
 driver on Server 2012 with WDK 8.0.
 
 Running with MSI_SUPPORTED=1 against vhost-scsi results in a significant
 performance and efficiency gain, on the order of 100K to 225K IOPs for
 4K block random I/O workload, depending on read/write mix.
 
 Below is a simple patch to enable MSI operation by default.  Any chance
 to apply this separate from future mq efforts..?

Yes, we differently can enable MSI and rebuild vioscsi.
But then we need to re-spin WHQL testing for this particular
driver. This process requires a lot of resources, and I doubt that
it will be initiated soon, unless we have some significant amount of
bug-fixes.

Best regards,
Vadim. 

 
 Thanks,
 
 --nab
 
 From 89adb6d5800386d44b36737d1587e0ffc09c4902 Mon Sep 17 00:00:00 2001
 From: Nicholas Bellinger n...@linux-iscsi.org
 Date: Fri, 14 Feb 2014 10:26:04 -0800
 Subject: [PATCH] vioscsi: Set MSI_SUPPORTED=1 by default
 
 Signed-off-by: Nicholas Bellinger n...@linux-iscsi.org
 ---
  vioscsi/SOURCES | 2 +-
  vioscsi/vioscsi.c   | 2 --
  vioscsi/vioscsi.inx | 2 +-
  vioscsi/vioscsi.vcxproj | 6 +++---
  4 files changed, 5 insertions(+), 7 deletions(-)
 
 diff --git a/vioscsi/SOURCES b/vioscsi/SOURCES
 index f2083de..f631bd2 100644
 --- a/vioscsi/SOURCES
 +++ b/vioscsi/SOURCES
 @@ -6,7 +6,7 @@ C_DEFINES = -D_MINORVERSION_=$(_BUILD_MINOR_VERSION_) 
 $(C_DEFINES)
  C_DEFINES = -D_NT_TARGET_MAJ=$(_NT_TARGET_MAJ) $(C_DEFINES)
  C_DEFINES = -D_NT_TARGET_MIN=$(_RHEL_RELEASE_VERSION_) $(C_DEFINES)
  
 -C_DEFINES = -DMSI_SUPPORTED=0 $(C_DEFINES)
 +C_DEFINES = -DMSI_SUPPORTED=1 $(C_DEFINES)
  C_DEFINES = -DINDIRECT_SUPPORTED=1 $(C_DEFINES)
  TARGETLIBS=$(SDK_LIB_PATH)\storport.lib ..\VirtIO\$(O)\virtiolib.lib
  
 diff --git a/vioscsi/vioscsi.c b/vioscsi/vioscsi.c
 index 77c0e46..70b9bb4 100644
 --- a/vioscsi/vioscsi.c
 +++ b/vioscsi/vioscsi.c
 @@ -337,8 +337,6 @@ ENTER_FN();
  adaptExt-queue_depth = pageNum / ConfigInfo-NumberOfPhysicalBreaks 
 - 1;
  }
  
 -adaptExt-msix_enabled = FALSE;
 -
  

Re: [Qemu-devel] [PATCH v18 14/14] amp: add query-memdev

2014-02-19 Thread Hu Tao
...

 +static void func(gpointer data, gpointer user_data)

maybe a better name.

 +{
 +HostMemoryBackendRam *backend = data;
 +MemdevList **list = user_data;
 +MemdevList *m;
 +uint16List **node;
 +unsigned long value;
 +
 +m = g_malloc0(sizeof(*m));
 +m-value = g_malloc0(sizeof(*m-value));
 +m-value-policy = g_strdup(policies[backend-policy]);
 +m-value-relative = backend-relative;
 +
 +node = m-value-host_nodes;
 +
 +value = find_first_bit(backend-host_nodes, MAX_NODES);
 +if (value  MAX_NODES) {
 +*node = g_malloc0(sizeof(**node));
 +(*node)-value = value;
 +node = (*node)-next;
 +
 +do {
 +value = find_next_bit(backend-host_nodes, MAX_NODES, value + 1);
 +if (value == MAX_NODES) {
 +break;
 +}
 +
 +*node = g_malloc0(sizeof(**node));
 +(*node)-value = value;
 +node = (*node)-next;
 +} while (true);
 +}

It is useful to query also the size property. But it's a member of
parent class(HostMemoryBackend). I'm not sure what is the common
solution, but maybe we can add size to Memdev(see below) and fill it
with HostMemoryBackend::size?

 +
 +m-next = *list;
 +*list = m;
 +}
 +

...

 +
 +##
 +# @Memdev:
 +#
 +# Information of memory device
 +#
 +# @id: memory device id
 +#
 +# @host-nodes: host nodes for its memory policy
 +#
 +# @policy: memory policy of memory device
 +#
 +# Since: 2.0
 +##
 +
 +{ 'type': 'Memdev',
 +  'data': {
 +'host-nodes': ['uint16'],
 +'policy': 'str',
 +'relative': 'bool' }}

add size to qeury HostMemoryBackend::size?




Re: [Qemu-devel] [PATCH v18 11/14] qapi: make string input visitor parse int list

2014-02-19 Thread Hu Tao
On Wed, Feb 19, 2014 at 03:54:02PM +0800, Hu Tao wrote:
 Cc: Laszlo Ersek ler...@redhat.com
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
  qapi/string-input-visitor.c   | 160 
 --
  tests/test-string-input-visitor.c |  22 ++
  2 files changed, 176 insertions(+), 6 deletions(-)
 
 diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
 index a152f5d..4540ca3 100644
 --- a/qapi/string-input-visitor.c
 +++ b/qapi/string-input-visitor.c
 @@ -15,30 +15,175 @@
  #include qapi/visitor-impl.h
  #include qapi/qmp/qerror.h
  
 +enum ListMode {
 +LM_NONE, /* not traversing a list of repeated options */
 +LM_STARTED,  /* start_list() succeeded */
 +
 +LM_IN_PROGRESS,  /* next_list() has been called.
 +  *
 +  * Generating the next list link will consume the 
 most
 +  * recently parsed QemuOpt instance of the repeated
 +  * option.
 +  *
 +  * Parsing a value into the list link will examine 
 the
 +  * next QemuOpt instance of the repeated option, and
 +  * possibly enter LM_SIGNED_INTERVAL or
 +  * LM_UNSIGNED_INTERVAL.
 +  */
 +
 +LM_SIGNED_INTERVAL,  /* next_list() has been called.
 +  *
 +  * Generating the next list link will consume the 
 most
 +  * recently stored element from the signed interval,
 +  * parsed from the most recent QemuOpt instance of 
 the
 +  * repeated option. This may consume QemuOpt itself
 +  * and return to LM_IN_PROGRESS.
 +  *
 +  * Parsing a value into the list link will store the
 +  * next element of the signed interval.
 +  */
 +
 +LM_UNSIGNED_INTERVAL,/* Same as above, only for an unsigned interval. */
 +
 +LM_END
 +};
 +
 +typedef enum ListMode ListMode;
 +
  struct StringInputVisitor
  {
  Visitor visitor;
 +
 +ListMode list_mode;
 +
 +/* When parsing a list of repeating options as integers, values of the 
 form
 + * a-b, representing a closed interval, are allowed. Elements in the
 + * range are generated individually.
 + */
 +union {
 +int64_t s;
 +uint64_t u;
 +} range_next, range_limit;
 +
  const char *string;
  };
  
 +static void
 +start_list(Visitor *v, const char *name, Error **errp)
 +{
 +StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
 +
 +/* we can't traverse a list in a list */
 +assert(siv-list_mode == LM_NONE);
 +siv-list_mode = LM_STARTED;
 +}
 +
 +static GenericList *
 +next_list(Visitor *v, GenericList **list, Error **errp)
 +{
 +StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
 +GenericList **link;
 +
 +switch (siv-list_mode) {
 +case LM_STARTED:
 +siv-list_mode = LM_IN_PROGRESS;
 +link = list;
 +break;
 +
 +case LM_SIGNED_INTERVAL:
 +case LM_UNSIGNED_INTERVAL:
 +link = (*list)-next;
 +
 +if (siv-list_mode == LM_SIGNED_INTERVAL) {
 +if (siv-range_next.s  siv-range_limit.s) {
 +++siv-range_next.s;
 +break;
 +}
 +} else if (siv-range_next.u  siv-range_limit.u) {
 +++siv-range_next.u;
 +break;
 +}
 +siv-list_mode = LM_END;
 +/* range has been completed, fall through */
 +
 +case LM_END:
 +return NULL;
 +
 +case LM_IN_PROGRESS:
 +link = (*list)-next;
 +break;
 +
 +default:
 +abort();
 +}
 +
 +*link = g_malloc0(sizeof **link);
 +return *link;
 +}
 +
 +static void
 +end_list(Visitor *v, Error **errp)
 +{
 +StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
 +
 +assert(siv-list_mode == LM_STARTED ||
 +   siv-list_mode == LM_END ||
 +   siv-list_mode == LM_IN_PROGRESS ||
 +   siv-list_mode == LM_SIGNED_INTERVAL ||
 +   siv-list_mode == LM_UNSIGNED_INTERVAL);
 +siv-list_mode = LM_NONE;
 +}
 +
  static void parse_type_int(Visitor *v, int64_t *obj, const char *name,
 Error **errp)
  {
  StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
 -char *endp = (char *) siv-string;
 +char *str = (char *) siv-string;
  long long val;
 +char *endptr;
  
 -errno = 0;
 -if (siv-string) {
 -val = strtoll(siv-string, endp, 0);
 +if (siv-list_mode == LM_SIGNED_INTERVAL) {
 +*obj = siv-range_next.s;
 +return;
  }
 -if (!siv-string || errno || endp == siv-string || *endp) {
 +
 +if (!siv-string) {
 

Re: [Qemu-devel] [PATCH v18 11/14] qapi: make string input visitor parse int list

2014-02-19 Thread Paolo Bonzini

Il 19/02/2014 09:17, Hu Tao ha scritto:

Two problems:

1. the code is mostly copied from OptsVisitor. maybe we can share the
   code?


I think it's not a huge problem.  Maybe OptsVisitor could be made to use 
a StringInputVisitor internally.



2. int list is not implemented in string outout visitor. but there is
   currently no user of it. Should we implement it or not?


Yes, please.  We probably will add sooner or later a qom-get/qom-set 
pair of HMP commands and these will use the string output visitor.


Paolo



Re: [Qemu-devel] [RFC 0/9] generate dynamic _CRS for motherboard resources

2014-02-19 Thread Igor Mammedov
On Tue, 18 Feb 2014 23:04:13 +0100
Laszlo Ersek ler...@redhat.com wrote:

 On 02/18/14 17:36, Igor Mammedov wrote:
  On Mon, 17 Feb 2014 09:32:35 +0100
  Gerd Hoffmann kra...@redhat.com wrote:
  
  On So, 2014-02-16 at 17:53 +0200, Michael S. Tsirkin wrote:
  On Fri, Feb 07, 2014 at 01:51:27PM +0100, Igor Mammedov wrote:
  Since introduction of PCIHP, it became problematic to
  punch hole in PCI0._CRS statically since PCI hotplug
  region size became runtime changeable.
 
  What makes it runtime changeable?
 
  machine type.  q35 / piix map them at different locations.
 
  Also we might want to this also for devices which are
  runtime-configurable (isa-debugcon, pvpanic, ...).
  I'd convert simple devices that conditionally enabled at
  startup time, from static definition + patching into
  completely dynamically generated when device present.
  For example pvpanic falls in to this category.
  
  That would result in smaller ACPI tables guest has to deal with.
 
 I could be mistaken, but AFAIR this caused the windows device manager to
 pop up in windows? Ie. if you have a windows guest and cold-boot it
 twice, once with the device present (generated into ACPI) and once with
 the device absent (not generated into ACPI), then you get hardware
 changes. Whereas, if the device is always present and you only patch
 _STA, then windows doesn't perceive it as a hw change.

Is is irrelevant whether device is statically or dynamically created,
user will face the same issue and has a choice to install driver or tell
windows to ignore device forever.

 Do I recall it right?...
Device manager pop-ups only once when new device is added to install driver.
If later, the device in the same location with the same id appears/disappears,
Device manager handles it silently.

 
 You could argue that a new device indeed warrants a device manager
 popup, but esp. for isa-debugcon and pvpanic, you might want to enable
 those opportunistically, without triggering a new hw dialog. Pvpanic
 triggering the device manager was exactly what drew frowns, for its
 original implementation. IIRC.
the above applies to these cases as well, i.e. if you install driver for
it then there won't be any pop-ups later. If there is no driver
(which is the case) one needs to tell to Device manager to ignore
this device, and then there shouldn't be an additional pop-ups later.

 Anyway pls. feel free to ignore this comment, it just crossed my mind.
 (And of course it's not related to your series.)
 
 Thanks
 Laszlo
 




Re: [Qemu-devel] [PATCH v18 13/14] memory backend: fill memory backend ram fields

2014-02-19 Thread Paolo Bonzini

 19/02/2014 08:54, Hu Tao ha scritto:

Thus makes user control how to allocate memory for ram backend.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 backends/hostmem-ram.c  | 158 
 include/sysemu/sysemu.h |   2 +
 2 files changed, 160 insertions(+)

diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index a496dbd..2da9341 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -10,23 +10,179 @@
  * See the COPYING file in the top-level directory.
  */
 #include sysemu/hostmem.h
+#include sysemu/sysemu.h
+#include qemu/bitmap.h
+#include qapi-visit.h
+#include qemu/config-file.h
+#include qapi/opts-visitor.h

 #define TYPE_MEMORY_BACKEND_RAM memory-ram
+#define MEMORY_BACKEND_RAM(obj) \
+OBJECT_CHECK(HostMemoryBackendRam, (obj), TYPE_MEMORY_BACKEND_RAM)

+typedef struct HostMemoryBackendRam HostMemoryBackendRam;
+
+/**
+ * @HostMemoryBackendRam
+ *
+ * @parent: opaque parent object container
+ * @host_nodes: host nodes bitmap used for memory policy
+ * @policy: host memory policy
+ * @relative: if the host nodes bitmap is relative
+ */
+struct HostMemoryBackendRam {
+/* private */
+HostMemoryBackend parent;
+
+DECLARE_BITMAP(host_nodes, MAX_NODES);
+HostMemPolicy policy;
+bool relative;
+};
+
+static void
+get_host_nodes(Object *obj, Visitor *v, void *opaque, const char *name,
+   Error **errp)
+{
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
+uint16List *host_nodes = NULL;
+uint16List **node = host_nodes;
+unsigned long value;
+
+value = find_first_bit(ram_backend-host_nodes, MAX_NODES);
+if (value == MAX_NODES) {
+return;
+}
+
+*node = g_malloc0(sizeof(**node));
+(*node)-value = value;
+node = (*node)-next;
+
+do {
+value = find_next_bit(ram_backend-host_nodes, MAX_NODES, value + 1);
+if (value == MAX_NODES) {
+break;
+}
+
+*node = g_malloc0(sizeof(**node));
+(*node)-value = value;
+node = (*node)-next;
+} while (true);
+
+visit_type_uint16List(v, host_nodes, name, errp);
+}
+
+static void
+set_host_nodes(Object *obj, Visitor *v, void *opaque, const char *name,
+   Error **errp)
+{
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
+uint16List *l = NULL;
+
+visit_type_uint16List(v, l, name, errp);
+
+while (l) {
+bitmap_set(ram_backend-host_nodes, l-value, 1);
+l = l-next;
+}
+}
+
+static const char *policies[HOST_MEM_POLICY_MAX + 1] = {
+[HOST_MEM_POLICY_DEFAULT] = default,
+[HOST_MEM_POLICY_PREFERRED] = preferred,
+[HOST_MEM_POLICY_MEMBIND] = membind,
+[HOST_MEM_POLICY_INTERLEAVE] = interleave,
+[HOST_MEM_POLICY_MAX] = NULL,
+};


This is already available in qapi-types.c as HostMemPolicy_lookup.


+static void
+get_policy(Object *obj, Visitor *v, void *opaque, const char *name,
+   Error **errp)
+{
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
+int policy = ram_backend-policy;
+
+visit_type_enum(v, policy, policies, NULL, name, errp);
+}
+
+static void
+set_policy(Object *obj, Visitor *v, void *opaque, const char *name,
+   Error **errp)
+{
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
+int policy;
+
+visit_type_enum(v, policy, policies, NULL, name, errp);
+ram_backend-policy = policy;


I think you need to set an error if backend-mr != NULL.


+}
+
+
+static bool get_relative(Object *obj, Error **errp)
+{
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
+
+return ram_backend-relative;
+}
+
+static void set_relative(Object *obj, bool value, Error **errp)
+{
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
+
+ram_backend-relative = value;
+}


Do we need relative vs. static?  Also, the default right now is static, 
while in Linux kernel this is a tri-state: relative, static, default.


I think that for now we should just omit this and only allow the default 
setting.  We can introduce an enum later without make the API 
backwards-incompatible.



+#include sys/syscall.h
+#ifndef MPOL_F_RELATIVE_NODES
+#define MPOL_F_RELATIVE_NODES (1  14)
+#define MPOL_F_STATIC_NODES   (1  15)
+#endif

 static int
 ram_backend_memory_init(HostMemoryBackend *backend, Error **errp)
 {
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(backend);
+int mode = ram_backend-policy;
+void *p;
+unsigned long maxnode;
+
 if (!memory_region_size(backend-mr)) {
 memory_region_init_ram(backend-mr, OBJECT(backend),
object_get_canonical_path(OBJECT(backend)),
backend-size);
+
+p = memory_region_get_ram_ptr(backend-mr);
+maxnode = find_last_bit(ram_backend-host_nodes, MAX_NODES);
+
+mode |= ram_backend-relative ? MPOL_F_RELATIVE_NODES :
+MPOL_F_STATIC_NODES;
+/* 

Re: [Qemu-devel] [PULL 00/20] acpi,pc,pci fixes and enhancements

2014-02-19 Thread Michael S. Tsirkin
On Tue, Feb 18, 2014 at 05:10:00PM +, Stefano Stabellini wrote:
 On Tue, 18 Feb 2014, Paolo Bonzini wrote:
  Il 18/02/2014 15:25, Stefano Stabellini ha scritto:
   On Tue, 18 Feb 2014, Paolo Bonzini wrote:
Il 18/02/2014 13:45, Stefano Stabellini ha scritto:
 Disk unplug: hw/ide/piix.c:pci_piix3_xen_ide_unplug (see the beginning
 of the email :-P).
 It is called by hw/xen/xen_platform.c:platform_fixed_ioport_writew, in
 response to the guest writing to a magic ioport specifically to unplug
 the emulated disk.
 With this patch after the guest boots I can still access both xvda and
 sda for the same disk, leading to fs corruptions.

Ok, the last paragraph is what I was missing.

So this is dc-unplug for the PIIX3 IDE device.  Because PCI declares a
hotplug handler, dc-unplug is not called anymore.

But unlike other dc-unplug callbacks, pci_piix3_xen_ide_unplug doesn't
free
the device, it just drops the disks underneath.  I think the simplest
solution
is to _not_ make it a dc-unplug callback at all, and call
pci_piix3_xen_ide_unplug from unplug_disks instead of qdev_unplug.
qdev_unplug means ask guest to start unplug, which is not what Xen 
wants
to
do here.
   
   Yes, you are right, pci_piix3_xen_ide_unplug is not called anymore.
   Calling it directly from unplug_disks fixes the issue:
   
   
   ---
   
   Call pci_piix3_xen_ide_unplug from unplug_disks
   
   Signed-off-by: Stefano Stabellini stefano.stabell...@eu.citrix.com
   
   diff --git a/hw/ide/piix.c b/hw/ide/piix.c
   index 0eda301..40757eb 100644
   --- a/hw/ide/piix.c
   +++ b/hw/ide/piix.c
   @@ -167,7 +167,7 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
return 0;
}
   
   -static int pci_piix3_xen_ide_unplug(DeviceState *dev)
   +int pci_piix3_xen_ide_unplug(DeviceState *dev)
{
PCIIDEState *pci_ide;
DriveInfo *di;
   @@ -266,7 +266,6 @@ static void piix3_ide_xen_class_init(ObjectClass 
   *klass,
   void *data)
k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
k-class_id = PCI_CLASS_STORAGE_IDE;
set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
   -dc-unplug = pci_piix3_xen_ide_unplug;
}
   
static const TypeInfo piix3_ide_xen_info = {
   diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c
   index 70875e4..1d9d0e9 100644
   --- a/hw/xen/xen_platform.c
   +++ b/hw/xen/xen_platform.c
   @@ -27,6 +27,7 @@
   
#include hw/hw.h
#include hw/i386/pc.h
   +#include hw/ide.h
#include hw/pci/pci.h
#include hw/irq.h
#include hw/xen/xen_common.h
   @@ -110,7 +111,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void
   *o)
if (pci_get_word(d-config + PCI_CLASS_DEVICE) ==
PCI_CLASS_STORAGE_IDE
 strcmp(d-name, xen-pci-passthrough) != 0) {
   -qdev_unplug(DEVICE(d), NULL);
   +pci_piix3_xen_ide_unplug(DEVICE(d));
}
}
   
   diff --git a/include/hw/ide.h b/include/hw/ide.h
   index 507e6d3..bc8bd32 100644
   --- a/include/hw/ide.h
   +++ b/include/hw/ide.h
   @@ -17,6 +17,7 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo
   **hd_table,
PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, int
   devfn);
PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int
   devfn);
PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int
   devfn);
   +int pci_piix3_xen_ide_unplug(DeviceState *dev);
void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
   
/* ide-mmio.c */
   
  
  Acked-by: Paolo Bonzini pbonz...@redhat.com
 
 Thanks. Should I send it to Peter via the xen tree or anybody else wants
 to pick this up?

I'll rebase my tree on top of this, to avoid bisect failures.




[Qemu-devel] [PATCHv3 2/2] sun4m: Add Sun CG3 framebuffer initialisation function

2014-02-19 Thread Mark Cave-Ayland
In order to allow the user to choose the framebuffer for sparc-softmmu, add
-vga tcx and -vga cg3 options to the QEMU command line. If no option is
specified, the default TCX framebuffer is used.

Since proprietary FCode ROMs use a resolution of 1152x900, slightly relax the
validation rules to allow both displays to be initiated at the higher
resolution used by these ROMs upon request (OpenBIOS FCode ROMs default to
the normal QEMU sun4m default resolution of 1024x768).

Finally move any fprintf(stderr ...) statements in the areas affected by this
patch over to the new error_report() function.

Signed-off-by: Mark Cave-Ayland mark.cave-ayl...@ilande.co.uk
CC: Blue Swirl blauwir...@gmail.com
CC: Anthony Liguori aligu...@amazon.com
CC: Peter Maydell peter.mayd...@linaro.org
CC: Bob Breuer breu...@mc.net
CC: Artyom Tarasenko atar4q...@gmail.com
---
 hw/sparc/sun4m.c|   62 ---
 include/sysemu/sysemu.h |1 +
 vl.c|   24 ++
 3 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 2957d90..65ea07b 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include hw/sysbus.h
+#include qemu/error-report.h
 #include qemu/timer.h
 #include hw/sparc/sun4m.h
 #include hw/timer/m48t59.h
@@ -561,6 +562,31 @@ static void tcx_init(hwaddr addr, int vram_size, int width,
 }
 }
 
+static void cg3_init(hwaddr addr, qemu_irq irq, int vram_size, int width,
+ int height, int depth)
+{
+DeviceState *dev;
+SysBusDevice *s;
+
+dev = qdev_create(NULL, cgthree);
+qdev_prop_set_uint32(dev, vram_size, vram_size);
+qdev_prop_set_uint16(dev, width, width);
+qdev_prop_set_uint16(dev, height, height);
+qdev_prop_set_uint16(dev, depth, depth);
+qdev_prop_set_uint64(dev, prom_addr, addr);
+qdev_init_nofail(dev);
+s = SYS_BUS_DEVICE(dev);
+
+/* FCode ROM */
+sysbus_mmio_map(s, 0, addr);
+/* DAC */
+sysbus_mmio_map(s, 1, addr + 0x40ULL);
+/* 8-bit plane */
+sysbus_mmio_map(s, 2, addr + 0x80ULL);
+
+sysbus_connect_irq(s, 0, irq);
+}
+
 /* NCR89C100/MACIO Internal ID register */
 
 #define TYPE_MACIO_ID_REGISTER macio_idreg
@@ -914,13 +940,43 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
  slavio_irq[16], iommu, ledma_irq, 1);
 
 if (graphic_depth != 8  graphic_depth != 24) {
-fprintf(stderr, qemu: Unsupported depth: %d\n, graphic_depth);
+error_report(Unsupported depth: %d, graphic_depth);
 exit (1);
 }
 num_vsimms = 0;
 if (num_vsimms == 0) {
-tcx_init(hwdef-tcx_base, 0x0010, graphic_width, graphic_height,
- graphic_depth);
+if (vga_interface_type == VGA_CG3) {
+if (graphic_depth != 8) {
+error_report(Unsupported depth: %d, graphic_depth);
+exit(1);
+}
+
+if (!(graphic_width == 1024  graphic_height == 768) 
+!(graphic_width == 1152  graphic_height == 900)) {
+error_report(Unsupported resolution: %d x %d, graphic_width,
+ graphic_height);
+exit(1);
+}
+
+/* sbus irq 5 */
+cg3_init(hwdef-tcx_base, slavio_irq[11], 0x0010,
+ graphic_width, graphic_height, graphic_depth);
+} else {
+/* If no display specified, default to TCX */
+if (graphic_depth != 8  graphic_depth != 24) {
+error_report(Unsupported depth: %d, graphic_depth);
+exit(1);
+}
+
+if (!(graphic_width == 1024  graphic_height == 768)) {
+error_report(Unsupported resolution: %d x %d,
+ graphic_width, graphic_height);
+exit(1);
+}
+
+tcx_init(hwdef-tcx_base, 0x0010, graphic_width, 
graphic_height,
+ graphic_depth);
+}
 }
 
 for (i = num_vsimms; i  MAX_VSIMMS; i++) {
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 495dae8..b90df9a 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -104,6 +104,7 @@ extern int autostart;
 
 typedef enum {
 VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL,
+VGA_TCX, VGA_CG3,
 } VGAInterfaceType;
 
 extern int vga_interface_type;
diff --git a/vl.c b/vl.c
index 316de54..10aca2b 100644
--- a/vl.c
+++ b/vl.c
@@ -2031,6 +2031,16 @@ static bool qxl_vga_available(void)
 return object_class_by_name(qxl-vga);
 }
 
+static bool tcx_vga_available(void)
+{
+return object_class_by_name(SUNW,tcx);
+}
+
+static bool cg3_vga_available(void)
+{
+return object_class_by_name(cgthree);
+}
+
 static void select_vgahw (const char *p)
 {
 const char *opts;
@@ -2066,6 +2076,20 @@ static void select_vgahw 

[Qemu-devel] [PATCHv3 0/2] sun4m: Implement Sun CG3 framebuffer for QEMU

2014-02-19 Thread Mark Cave-Ayland
This patchset provides QEMU with an implementation of the Sun CG3 8-bit
framebuffer. It is based upon Bob Breuer's original work which has been
rebased onto git master, and is now capable of running with an OpenBIOS CG3 
FCode ROM instead of requiring copies of proprietary Sun ROMs.

The motivation behind this patch is that older operating systems such as
Debian Woody and Solaris (running OpenWindows) do not contain drivers for the
TCX framebuffer and as a result currently cannot run in graphical mode. The
screenshots linked below show qemu-system-sparc successfully running both 
Debian Woody and the Solaris 8 installer in graphical mode during testing:

http://www.ilande.co.uk/tmp/debian-woody.png
http://www.ilande.co.uk/tmp/sol8-1.png
http://www.ilande.co.uk/tmp/sol8-2.png

The CG3 framebuffer is selected by passing -vga cg3 on the command line to
qemu-system-sparc. If either -vga tcx is specified (or the -vga argument is
omitted) then qemu-system-sparc defaults to using the existing TCX
framebuffer to maintain compatibility.

v3:
- Rebased to git master
- Fix DEBUG_CG3 macro
- Use register constants based upon Linux/BSD drivers
- Use qemu_log(LOG_UNIMP ... ) to capture unrecognised register accesses
- Rename device type from SUNW,cgthree to cgthree (matches OBP)
- Use error_report() instead of fprintf(stderr ... )
- Convert from init to realizefn

v2:
- Rebased to git master
- Updated QEMU,cgthree.bin ROM to latest OpenBIOS version
- Added Peter Maydell to CC


Mark Cave-Ayland (2):
  sun4m: Add Sun CG3 framebuffer and corresponding OpenBIOS FCode ROM
  sun4m: Add Sun CG3 framebuffer initialisation function

 Makefile  |2 +-
 default-configs/sparc-softmmu.mak |1 +
 hw/display/Makefile.objs  |1 +
 hw/display/cg3.c  |  384 +
 hw/sparc/sun4m.c  |   62 +-
 include/sysemu/sysemu.h   |1 +
 pc-bios/QEMU,cgthree.bin  |  Bin 0 - 850 bytes
 pc-bios/README|4 +-
 vl.c  |   24 +++
 9 files changed, 473 insertions(+), 6 deletions(-)
 create mode 100644 hw/display/cg3.c
 create mode 100644 pc-bios/QEMU,cgthree.bin

-- 
1.7.10.4




[Qemu-devel] [PATCHv3 1/2] sun4m: Add Sun CG3 framebuffer and corresponding OpenBIOS FCode ROM

2014-02-19 Thread Mark Cave-Ayland
The CG3 framebuffer is a simple 8-bit framebuffer for use with operating
systems such as early Solaris that do not have drivers for TCX.

Signed-off-by: Mark Cave-Ayland mark.cave-ayl...@ilande.co.uk
CC: Blue Swirl blauwir...@gmail.com
CC: Anthony Liguori aligu...@amazon.com
CC: Peter Maydell peter.mayd...@linaro.org
CC: Bob Breuer breu...@mc.net
CC: Artyom Tarasenko atar4q...@gmail.com
---
 Makefile  |2 +-
 default-configs/sparc-softmmu.mak |1 +
 hw/display/Makefile.objs  |1 +
 hw/display/cg3.c  |  384 +
 pc-bios/QEMU,cgthree.bin  |  Bin 0 - 850 bytes
 pc-bios/README|4 +-
 6 files changed, 389 insertions(+), 3 deletions(-)
 create mode 100644 hw/display/cg3.c
 create mode 100644 pc-bios/QEMU,cgthree.bin

diff --git a/Makefile b/Makefile
index 807054b..c3c7ccc 100644
--- a/Makefile
+++ b/Makefile
@@ -293,7 +293,7 @@ ifdef INSTALL_BLOBS
 BLOBS=bios.bin bios-256k.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
 vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin \
 acpi-dsdt.aml q35-acpi-dsdt.aml \
-ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin \
+ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin 
QEMU,cgthree.bin \
 pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
 pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \
 efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \
diff --git a/default-configs/sparc-softmmu.mak 
b/default-configs/sparc-softmmu.mak
index 8fc93dd..ab796b3 100644
--- a/default-configs/sparc-softmmu.mak
+++ b/default-configs/sparc-softmmu.mak
@@ -10,6 +10,7 @@ CONFIG_EMPTY_SLOT=y
 CONFIG_PCNET_COMMON=y
 CONFIG_LANCE=y
 CONFIG_TCX=y
+CONFIG_CG3=y
 CONFIG_SLAVIO=y
 CONFIG_CS4231=y
 CONFIG_GRLIB=y
diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
index 540df82..7ed76a9 100644
--- a/hw/display/Makefile.objs
+++ b/hw/display/Makefile.objs
@@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP) += omap_lcdc.o
 obj-$(CONFIG_PXA2XX) += pxa2xx_lcd.o
 obj-$(CONFIG_SM501) += sm501.o
 obj-$(CONFIG_TCX) += tcx.o
+obj-$(CONFIG_CG3) += cg3.o
 
 obj-$(CONFIG_VGA) += vga.o
 
diff --git a/hw/display/cg3.c b/hw/display/cg3.c
new file mode 100644
index 000..b6bc0c2
--- /dev/null
+++ b/hw/display/cg3.c
@@ -0,0 +1,384 @@
+/*
+ * QEMU CG3 Frame buffer
+ *
+ * Copyright (c) 2012 Bob Breuer
+ * Copyright (c) 2013 Mark Cave-Ayland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include qemu-common.h
+#include qemu/error-report.h
+#include ui/console.h
+#include hw/sysbus.h
+#include hw/loader.h
+
+/* Change to 1 to enable debugging */
+#define DEBUG_CG3 0
+
+#define CG3_ROM_FILE  QEMU,cgthree.bin
+#define FCODE_MAX_ROM_SIZE 0x1
+
+#define CG3_REG_SIZE0x20
+
+#define CG3_REG_BT458_ADDR  0x0
+#define CG3_REG_BT458_COLMAP0x4
+#define CG3_REG_FBC_CTRL0x10
+#define CG3_REG_FBC_STATUS  0x11
+#define CG3_REG_FBC_CURSTART0x12
+#define CG3_REG_FBC_CUREND  0x13
+#define CG3_REG_FBC_VCTRL   0x14
+
+/* Control register flags */
+#define CG3_CR_ENABLE_INTS  0x80
+
+/* Status register flags */
+#define CG3_SR_PENDING_INT  0x80
+#define CG3_SR_1152_900_76_B0x60
+#define CG3_SR_ID_COLOR 0x01
+
+#define CG3_VRAM_SIZE 0x10
+#define CG3_VRAM_OFFSET 0x80
+
+#define DPRINTF(fmt, ...) do { \
+if (DEBUG_CG3) { \
+printf(CG3:  fmt , ## __VA_ARGS__); \
+} \
+} while (0);
+
+#define TYPE_CG3 cgthree
+#define CG3(obj) OBJECT_CHECK(CG3State, (obj), TYPE_CG3)
+
+typedef struct CG3State {
+SysBusDevice parent_obj;
+
+QemuConsole *con;
+qemu_irq irq;
+hwaddr prom_addr;
+MemoryRegion vram_mem;
+MemoryRegion rom;
+MemoryRegion reg;
+uint32_t vram_size;
+int full_update;
+uint8_t regs[16];
+uint8_t r[256], g[256], b[256];
+uint16_t width, height, depth;
+uint8_t dac_index, dac_state;
+} CG3State;
+
+static 

Re: [Qemu-devel] [PATCH v18 12/14] qapi: add HostMemPolicy enum type

2014-02-19 Thread Paolo Bonzini

Il 19/02/2014 08:54, Hu Tao ha scritto:

From: Wanlong Gao gaowanl...@cn.fujitsu.com

This new enum type will be used to set host memory policy of
backend host memory.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 qapi-schema.json | 20 
 1 file changed, 20 insertions(+)

diff --git a/qapi-schema.json b/qapi-schema.json
index 498ea9b..9d6370f 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4454,3 +4454,23 @@
'*cpus':   ['uint16'],
'*memdev': 'str',
'*mem':'str' }}
+
+##
+# @HostMemPolicy
+#
+# Host memory policy types
+#
+# @default: restore default policy, remove any nondefault policy
+#
+# @preferred: set the preferred host node for allocation


host nodes


+#
+# @membind: a strict policy that restricts memory allocation to the
+#   host nodes specified
+#
+# @interleave: the page allocations is interleaved across the set


@interleave: memory allocations are interleaved across ...


+#  of host nodes specified
+#
+# Since 2.0
+##
+{ 'enum': 'HostMemPolicy',
+  'data': [ 'default', 'preferred', 'membind', 'interleave' ] }



Paolo



Re: [Qemu-devel] [PATCH v18 14/14] amp: add query-memdev

2014-02-19 Thread Paolo Bonzini

Il 19/02/2014 08:54, Hu Tao ha scritto:

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 backends/hostmem-ram.c | 71 --
 qapi-schema.json   | 31 ++
 qmp-commands.hx| 30 +
 3 files changed, 124 insertions(+), 8 deletions(-)


This is in principle not necessary, because we can query everything via 
qom-get/qom-set; but I can see that it is useful.  If you want this:


(1) please put it in numa.c and code it in a way that does not use 
internal information of HostMemoryBackend; for example, you can walk 
numa_info[...].node_memdev and use object_property_get/set on the object 
to fill in the result.


This will also eliminate all duplicate code between func and the 
property visitors.


(2) please add an HMP variant info memdev.

Paolo


diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index 2da9341..9f19ab8 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -15,6 +15,7 @@
 #include qapi-visit.h
 #include qemu/config-file.h
 #include qapi/opts-visitor.h
+#include qmp-commands.h

 #define TYPE_MEMORY_BACKEND_RAM memory-ram
 #define MEMORY_BACKEND_RAM(obj) \
@@ -37,8 +38,66 @@ struct HostMemoryBackendRam {
 DECLARE_BITMAP(host_nodes, MAX_NODES);
 HostMemPolicy policy;
 bool relative;
+
+QTAILQ_ENTRY(HostMemoryBackendRam) next;
+};
+
+static const char *policies[HOST_MEM_POLICY_MAX + 1] = {
+[HOST_MEM_POLICY_DEFAULT] = default,
+[HOST_MEM_POLICY_PREFERRED] = preferred,
+[HOST_MEM_POLICY_MEMBIND] = membind,
+[HOST_MEM_POLICY_INTERLEAVE] = interleave,
+[HOST_MEM_POLICY_MAX] = NULL,
 };

+static GSList *memdevs;
+
+static void func(gpointer data, gpointer user_data)
+{
+HostMemoryBackendRam *backend = data;
+MemdevList **list = user_data;
+MemdevList *m;
+uint16List **node;
+unsigned long value;
+
+m = g_malloc0(sizeof(*m));
+m-value = g_malloc0(sizeof(*m-value));
+m-value-policy = g_strdup(policies[backend-policy]);
+m-value-relative = backend-relative;
+
+node = m-value-host_nodes;
+
+value = find_first_bit(backend-host_nodes, MAX_NODES);
+if (value  MAX_NODES) {
+*node = g_malloc0(sizeof(**node));
+(*node)-value = value;
+node = (*node)-next;
+
+do {
+value = find_next_bit(backend-host_nodes, MAX_NODES, value + 1);
+if (value == MAX_NODES) {
+break;
+}
+
+*node = g_malloc0(sizeof(**node));
+(*node)-value = value;
+node = (*node)-next;
+} while (true);
+}
+
+m-next = *list;
+*list = m;
+}
+
+MemdevList *qmp_query_memdev(Error **errp)
+{
+MemdevList *list = NULL;
+
+g_slist_foreach(memdevs, func, list);
+
+return list;
+}
+
 static void
 get_host_nodes(Object *obj, Visitor *v, void *opaque, const char *name,
Error **errp)
@@ -86,14 +145,6 @@ set_host_nodes(Object *obj, Visitor *v, void *opaque, const 
char *name,
 }
 }

-static const char *policies[HOST_MEM_POLICY_MAX + 1] = {
-[HOST_MEM_POLICY_DEFAULT] = default,
-[HOST_MEM_POLICY_PREFERRED] = preferred,
-[HOST_MEM_POLICY_MEMBIND] = membind,
-[HOST_MEM_POLICY_INTERLEAVE] = interleave,
-[HOST_MEM_POLICY_MAX] = NULL,
-};
-
 static void
 get_policy(Object *obj, Visitor *v, void *opaque, const char *name,
Error **errp)
@@ -172,6 +223,8 @@ ram_backend_memory_init(HostMemoryBackend *backend, Error 
**errp)
 static void
 ram_backend_initfn(Object *obj)
 {
+HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
+
 object_property_add(obj, host-nodes, int,
 get_host_nodes,
 set_host_nodes, NULL, NULL, NULL);
@@ -180,6 +233,8 @@ ram_backend_initfn(Object *obj)
 set_policy, NULL, NULL, NULL);
 object_property_add_bool(obj, relative,
  get_relative, set_relative, NULL);
+
+memdevs = g_slist_append(memdevs, ram_backend);
 }

 static void
diff --git a/qapi-schema.json b/qapi-schema.json
index 9d6370f..7b5027d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4474,3 +4474,34 @@
 ##
 { 'enum': 'HostMemPolicy',
   'data': [ 'default', 'preferred', 'membind', 'interleave' ] }
+
+##
+# @Memdev:
+#
+# Information of memory device
+#
+# @id: memory device id
+#
+# @host-nodes: host nodes for its memory policy
+#
+# @policy: memory policy of memory device
+#
+# Since: 2.0
+##
+
+{ 'type': 'Memdev',
+  'data': {
+'host-nodes': ['uint16'],
+'policy': 'str',
+'relative': 'bool' }}
+
+##
+# @query-memdev:
+#
+# Returns information for all memory devices.
+#
+# Returns: a list of @Memdev.
+#
+# Since: 2.0
+##
+{ 'command': 'query-memdev', 'returns': ['Memdev'] }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index cce6b81..20368f7 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3457,3 +3457,33 @@ Example:
} } ] }


Re: [Qemu-devel] [PATCH] object: Report type in error when not user creatable.

2014-02-19 Thread Paolo Bonzini

Il 18/02/2014 23:42, Hani Benhabiles ha scritto:

Signed-off-by: Hani Benhabiles h...@linux.com
---
 qmp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qmp.c b/qmp.c
index d0d98e7..f556a04 100644
--- a/qmp.c
+++ b/qmp.c
@@ -556,8 +556,8 @@ void object_add(const char *type, const char *id, const 
QDict *qdict,
 }

 if (!object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
-error_setg(local_err, object '%s' isn't supported by object-add,
-   id);
+error_setg(local_err, object type '%s' isn't supported by 
object-add,
+   type);
 goto out;
 }




Acked-by: Paolo Bonzini pbonz...@redhat.com

Paolo



Re: [Qemu-devel] [PATCH v18 07/14] add memdev backend infrastructure

2014-02-19 Thread Igor Mammedov
On Wed, 19 Feb 2014 15:53:58 +0800
Hu Tao hu...@cn.fujitsu.com wrote:

 Provides framework for splitting host RAM allocation/
 policies into a separate backend that could be used
 by devices.
 
 Initially only legacy RAM backend is provided, which
 uses memory_region_init_ram() allocator and compatible
 with every CLI option that affects memory_region_init_ram().
 
 Signed-off-by: Igor Mammedov imamm...@redhat.com
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
this doesn't use complete() mathod of user_creatable

pls, pickup more correct patch:

https://github.com/imammedo/qemu/commit/19a4c596f4fab35706335e6dd01e94413195aa30

  backends/Makefile.objs   |   2 +
  backends/hostmem-ram.c   |  48 ++
  backends/hostmem.c   | 125 
 +++
  include/sysemu/hostmem.h |  63 
  4 files changed, 238 insertions(+)
  create mode 100644 backends/hostmem-ram.c
  create mode 100644 backends/hostmem.c
  create mode 100644 include/sysemu/hostmem.h
 
 diff --git a/backends/Makefile.objs b/backends/Makefile.objs
 index 42557d5..e6bdc11 100644
 --- a/backends/Makefile.objs
 +++ b/backends/Makefile.objs
 @@ -6,3 +6,5 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
  $(obj)/baum.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
  
  common-obj-$(CONFIG_TPM) += tpm.o
 +
 +common-obj-y += hostmem.o hostmem-ram.o
 diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
 new file mode 100644
 index 000..a496dbd
 --- /dev/null
 +++ b/backends/hostmem-ram.c
 @@ -0,0 +1,48 @@
 +/*
 + * QEMU Host Memory Backend
 + *
 + * Copyright (C) 2013 Red Hat Inc
 + *
 + * Authors:
 + *   Igor Mammedov imamm...@redhat.com
 + *
 + * This work is licensed under the terms of the GNU GPL, version 2 or later.
 + * See the COPYING file in the top-level directory.
 + */
 +#include sysemu/hostmem.h
 +
 +#define TYPE_MEMORY_BACKEND_RAM memory-ram
 +
 +
 +static int
 +ram_backend_memory_init(HostMemoryBackend *backend, Error **errp)
 +{
 +if (!memory_region_size(backend-mr)) {
 +memory_region_init_ram(backend-mr, OBJECT(backend),
 +   object_get_canonical_path(OBJECT(backend)),
 +   backend-size);
 +}
 +
 +return 0;
 +}
 +
 +static void
 +ram_backend_class_init(ObjectClass *oc, void *data)
 +{
 +HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
 +
 +bc-memory_init = ram_backend_memory_init;
 +}
 +
 +static const TypeInfo ram_backend_info = {
 +.name = TYPE_MEMORY_BACKEND_RAM,
 +.parent = TYPE_MEMORY_BACKEND,
 +.class_init = ram_backend_class_init,
 +};
 +
 +static void register_types(void)
 +{
 +type_register_static(ram_backend_info);
 +}
 +
 +type_init(register_types);
 diff --git a/backends/hostmem.c b/backends/hostmem.c
 new file mode 100644
 index 000..4b8fd8d
 --- /dev/null
 +++ b/backends/hostmem.c
 @@ -0,0 +1,125 @@
 +/*
 + * QEMU Host Memory Backend
 + *
 + * Copyright (C) 2013 Red Hat Inc
 + *
 + * Authors:
 + *   Igor Mammedov imamm...@redhat.com
 + *
 + * This work is licensed under the terms of the GNU GPL, version 2 or later.
 + * See the COPYING file in the top-level directory.
 + */
 +#include sysemu/hostmem.h
 +#include sysemu/sysemu.h
 +#include qapi/visitor.h
 +#include qapi/qmp/qerror.h
 +#include qemu/config-file.h
 +#include qom/object_interfaces.h
 +
 +static void
 +hostmemory_backend_get_size(Object *obj, Visitor *v, void *opaque,
 +const char *name, Error **errp)
 +{
 +HostMemoryBackend *backend = MEMORY_BACKEND(obj);
 +uint64_t value = backend-size;
 +
 +visit_type_size(v, value, name, errp);
 +}
 +
 +static void
 +hostmemory_backend_set_size(Object *obj, Visitor *v, void *opaque,
 +const char *name, Error **errp)
 +{
 +HostMemoryBackend *backend = MEMORY_BACKEND(obj);
 +uint64_t value;
 +
 +if (memory_region_size(backend-mr)) {
 +error_setg(errp, cannot change property value\n);
 +return;
 +}
 +
 +visit_type_size(v, value, name, errp);
 +if (error_is_set(errp)) {
 +return;
 +}
 +if (!value) {
 +error_setg(errp, Property '%s.%s' doesn't take value '% PRIu64 ',
 +   object_get_typename(obj), name , value);
 +return;
 +}
 +backend-size = value;
 +}
 +
 +static void hostmemory_backend_initfn(Object *obj)
 +{
 +object_property_add(obj, size, int,
 +hostmemory_backend_get_size,
 +hostmemory_backend_set_size, NULL, NULL, NULL);
 +}
 +
 +static void hostmemory_backend_finalize(Object *obj)
 +{
 +HostMemoryBackend *backend = MEMORY_BACKEND(obj);
 +
 +if (memory_region_size(backend-mr)) {
 +memory_region_destroy(backend-mr);
 +}
 +}
 +
 +static int
 +hostmemory_backend_memory_init(HostMemoryBackend *backend, Error **errp)
 +{
 +

Re: [Qemu-devel] [PULL 00/20] acpi,pc,pci fixes and enhancements

2014-02-19 Thread Michael S. Tsirkin
On Wed, Feb 19, 2014 at 11:08:25AM +0200, Michael S. Tsirkin wrote:
 On Tue, Feb 18, 2014 at 05:10:00PM +, Stefano Stabellini wrote:
  On Tue, 18 Feb 2014, Paolo Bonzini wrote:
   Il 18/02/2014 15:25, Stefano Stabellini ha scritto:
On Tue, 18 Feb 2014, Paolo Bonzini wrote:
 Il 18/02/2014 13:45, Stefano Stabellini ha scritto:
  Disk unplug: hw/ide/piix.c:pci_piix3_xen_ide_unplug (see the 
  beginning
  of the email :-P).
  It is called by hw/xen/xen_platform.c:platform_fixed_ioport_writew, 
  in
  response to the guest writing to a magic ioport specifically to 
  unplug
  the emulated disk.
  With this patch after the guest boots I can still access both xvda 
  and
  sda for the same disk, leading to fs corruptions.
 
 Ok, the last paragraph is what I was missing.
 
 So this is dc-unplug for the PIIX3 IDE device.  Because PCI declares 
 a
 hotplug handler, dc-unplug is not called anymore.
 
 But unlike other dc-unplug callbacks, pci_piix3_xen_ide_unplug 
 doesn't
 free
 the device, it just drops the disks underneath.  I think the simplest
 solution
 is to _not_ make it a dc-unplug callback at all, and call
 pci_piix3_xen_ide_unplug from unplug_disks instead of qdev_unplug.
 qdev_unplug means ask guest to start unplug, which is not what Xen 
 wants
 to
 do here.

Yes, you are right, pci_piix3_xen_ide_unplug is not called anymore.
Calling it directly from unplug_disks fixes the issue:


---

Call pci_piix3_xen_ide_unplug from unplug_disks

Signed-off-by: Stefano Stabellini stefano.stabell...@eu.citrix.com

diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 0eda301..40757eb 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -167,7 +167,7 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 return 0;
 }

-static int pci_piix3_xen_ide_unplug(DeviceState *dev)
+int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
 PCIIDEState *pci_ide;
 DriveInfo *di;
@@ -266,7 +266,6 @@ static void piix3_ide_xen_class_init(ObjectClass 
*klass,
void *data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-unplug = pci_piix3_xen_ide_unplug;
 }

 static const TypeInfo piix3_ide_xen_info = {
diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c
index 70875e4..1d9d0e9 100644
--- a/hw/xen/xen_platform.c
+++ b/hw/xen/xen_platform.c
@@ -27,6 +27,7 @@

 #include hw/hw.h
 #include hw/i386/pc.h
+#include hw/ide.h
 #include hw/pci/pci.h
 #include hw/irq.h
 #include hw/xen/xen_common.h
@@ -110,7 +111,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, 
void
*o)
 if (pci_get_word(d-config + PCI_CLASS_DEVICE) ==
 PCI_CLASS_STORAGE_IDE
  strcmp(d-name, xen-pci-passthrough) != 0) {
-qdev_unplug(DEVICE(d), NULL);
+pci_piix3_xen_ide_unplug(DEVICE(d));
 }
 }

diff --git a/include/hw/ide.h b/include/hw/ide.h
index 507e6d3..bc8bd32 100644
--- a/include/hw/ide.h
+++ b/include/hw/ide.h
@@ -17,6 +17,7 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo
**hd_table,
 PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, 
int
devfn);
 PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int
devfn);
 PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int
devfn);
+int pci_piix3_xen_ide_unplug(DeviceState *dev);
 void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);

 /* ide-mmio.c */

   
   Acked-by: Paolo Bonzini pbonz...@redhat.com
  
  Thanks. Should I send it to Peter via the xen tree or anybody else wants
  to pick this up?
 
 I'll rebase my tree on top of this, to avoid bisect failures.

Oh sorry, I noticed what broke this is - is merged already.
Pls merge fix through xen tree then, makes more sense.




Re: [Qemu-devel] [PATCH v18 03/14] NUMA: Add numa_info structure to contain numa nodes info

2014-02-19 Thread Igor Mammedov
On Wed, 19 Feb 2014 15:53:54 +0800
Hu Tao hu...@cn.fujitsu.com wrote:

 From: Wanlong Gao gaowanl...@cn.fujitsu.com
 
 Add the numa_info structure to contain the numa nodes memory,
 VCPUs information and the future added numa nodes host memory
 policies.
this is old version that breaks spar build which Wanlong already fixed.

You can replace patches 1-5 with more recent ones posted recently:
http://www.mail-archive.com/qemu-devel@nongnu.org/msg216404.html

 
 Reviewed-by: Eduardo Habkost ehabk...@redhat.com
 Signed-off-by: Andre Przywara andre.przyw...@amd.com
 Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
  hw/i386/pc.c| 12 
  include/sysemu/sysemu.h |  8 ++--
  monitor.c   |  2 +-
  numa.c  | 23 ---
  vl.c|  7 +++
  5 files changed, 30 insertions(+), 22 deletions(-)
 
 diff --git a/hw/i386/pc.c b/hw/i386/pc.c
 index e715a33..a464e48 100644
 --- a/hw/i386/pc.c
 +++ b/hw/i386/pc.c
 @@ -674,14 +674,14 @@ static FWCfgState *bochs_bios_init(void)
  unsigned int apic_id = x86_cpu_apic_id_from_index(i);
  assert(apic_id  apic_id_limit);
  for (j = 0; j  nb_numa_nodes; j++) {
 -if (test_bit(i, node_cpumask[j])) {
 +if (test_bit(i, numa_info[j].node_cpu)) {
  numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
  break;
  }
  }
  }
  for (i = 0; i  nb_numa_nodes; i++) {
 -numa_fw_cfg[apic_id_limit + 1 + i] = cpu_to_le64(node_mem[i]);
 +numa_fw_cfg[apic_id_limit + 1 + i] = 
 cpu_to_le64(numa_info[i].node_mem);
  }
  fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, numa_fw_cfg,
   (1 + apic_id_limit + nb_numa_nodes) *
 @@ -1077,8 +1077,12 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t 
 below_4g_mem_size,
  guest_info-apic_id_limit = pc_apic_id_limit(max_cpus);
  guest_info-apic_xrupt_override = kvm_allows_irq0_override();
  guest_info-numa_nodes = nb_numa_nodes;
 -guest_info-node_mem = g_memdup(node_mem, guest_info-numa_nodes *
 +guest_info-node_mem = g_malloc0(guest_info-numa_nodes *
  sizeof *guest_info-node_mem);
 +for (i = 0; i  nb_numa_nodes; i++) {
 +guest_info-node_mem[i] = numa_info[i].node_mem;
 +}
 +
  guest_info-node_cpu = g_malloc0(guest_info-apic_id_limit *
   sizeof *guest_info-node_cpu);
  
 @@ -1086,7 +1090,7 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t 
 below_4g_mem_size,
  unsigned int apic_id = x86_cpu_apic_id_from_index(i);
  assert(apic_id  guest_info-apic_id_limit);
  for (j = 0; j  nb_numa_nodes; j++) {
 -if (test_bit(i, node_cpumask[j])) {
 +if (test_bit(i, numa_info[j].node_cpu)) {
  guest_info-node_cpu[apic_id] = j;
  break;
  }
 diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
 index 2509649..d873b42 100644
 --- a/include/sysemu/sysemu.h
 +++ b/include/sysemu/sysemu.h
 @@ -9,6 +9,7 @@
  #include qapi-types.h
  #include qemu/notify.h
  #include qemu/main-loop.h
 +#include qemu/bitmap.h
  
  /* vl.c */
  
 @@ -134,8 +135,11 @@ extern QEMUClockType rtc_clock;
  #define MAX_NODES 64
  #define MAX_CPUMASK_BITS 255
  extern int nb_numa_nodes;
 -extern uint64_t node_mem[MAX_NODES];
 -extern unsigned long *node_cpumask[MAX_NODES];
 +typedef struct node_info {
 +uint64_t node_mem;
 +DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
 +} NodeInfo;
 +extern NodeInfo numa_info[MAX_NODES];
  void numa_add(const char *optarg);
  void set_numa_nodes(void);
  void set_numa_modes(void);
 diff --git a/monitor.c b/monitor.c
 index 690c152..0284735 100644
 --- a/monitor.c
 +++ b/monitor.c
 @@ -2004,7 +2004,7 @@ static void do_info_numa(Monitor *mon, const QDict 
 *qdict)
  }
  monitor_printf(mon, \n);
  monitor_printf(mon, node %d size: % PRId64  MB\n, i,
 -node_mem[i]  20);
 +numa_info[i].node_mem  20);
  }
  }
  
 diff --git a/numa.c b/numa.c
 index a06e2d1..1f413a0 100644
 --- a/numa.c
 +++ b/numa.c
 @@ -61,7 +61,7 @@ static void numa_node_parse_cpus(int nodenr, const char 
 *cpus)
  goto error;
  }
  
 -bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
 +bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1);
  return;
  
  error:
 @@ -101,7 +101,7 @@ void numa_add(const char *optarg)
  }
  
  if (get_param_value(option, 128, mem, optarg) == 0) {
 -node_mem[nodenr] = 0;
 +numa_info[nodenr].node_mem = 0;
  } else {
  int64_t sval;
  sval = strtosz(option, endptr);
 @@ -109,7 +109,7 @@ void numa_add(const char *optarg)
  fprintf(stderr, qemu: invalid numa mem size: %s\n, optarg);

Re: [Qemu-devel] [PATCH v3 06/20] iscsi: correctly propagate errors in iscsi_open

2014-02-19 Thread Stefan Hajnoczi
On Mon, Feb 17, 2014 at 02:43:53PM +0100, Paolo Bonzini wrote:
 Before:
 $ ./qemu-io-old
 qemu-io-old open -r -o file.driver=iscsi,file.filename=foo
 Failed to parse URL : foo
 qemu-io-old: can't open device (null): Could not open 'foo': Invalid 
 argument
 
 After:
 $ ./qemu-io
 qemu-io open -r -o file.driver=iscsi,file.filename=foo
 qemu-io: can't open device (null): Failed to parse URL : foo
 
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  block/iscsi.c | 103 
 ++
  1 file changed, 53 insertions(+), 50 deletions(-)

Acked-by: Stefan Hajnoczi stefa...@redhat.com



Re: [Qemu-devel] [PATCH v18 13/14] memory backend: fill memory backend ram fields

2014-02-19 Thread Igor Mammedov
On Wed, 19 Feb 2014 10:03:13 +0100
Paolo Bonzini pbonz...@redhat.com wrote:

   19/02/2014 08:54, Hu Tao ha scritto:
  Thus makes user control how to allocate memory for ram backend.
 
  Signed-off-by: Hu Tao hu...@cn.fujitsu.com
  ---
   backends/hostmem-ram.c  | 158 
  
   include/sysemu/sysemu.h |   2 +
   2 files changed, 160 insertions(+)
 
  diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
[...]

   static int
   ram_backend_memory_init(HostMemoryBackend *backend, Error **errp)
   {
  +HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(backend);
  +int mode = ram_backend-policy;
  +void *p;
  +unsigned long maxnode;
  +
   if (!memory_region_size(backend-mr)) {
   memory_region_init_ram(backend-mr, OBJECT(backend),
  object_get_canonical_path(OBJECT(backend)),
  backend-size);
  +
  +p = memory_region_get_ram_ptr(backend-mr);
  +maxnode = find_last_bit(ram_backend-host_nodes, MAX_NODES);
  +
  +mode |= ram_backend-relative ? MPOL_F_RELATIVE_NODES :
  +MPOL_F_STATIC_NODES;
  +/* This is a workaround for a long standing bug in Linux'
  + * mbind implementation, which cuts off the last specified
  + * node. To stay compatible should this bug be fixed, we
  + * specify one more node and zero this one out.
  + */
  +if (syscall(SYS_mbind, p, backend-size, mode,
  +ram_backend-host_nodes, maxnode + 2, 0)) {
 
 This does not compile on non-Linux; also, does libnuma include the 
 workaround?  If so, this is a hint that we should be using libnuma 
 instead...
 
 Finally, all this code should be in hostmem.c, not hostmem-ram.c, 
 because the same policies can be applied to hugepage-backed memory.
 
 Currently host_memory_backend_get_memory is calling bc-memory_init. 
 Probably the call should be replaced by something like
I've pushed to github updated version of memdev, where
host_memory_backend_get_memory() is just convenience wrapper to get
access to memdev's internal MemoryRegion.

All initialization now is done in user_creatable-complete() method
which calls ram_backend_memory_init() so leaving it as is should be fine.

 
 static void
 host_memory_backend_alloc(HostMemoryBackend *backend, Error **errp)
 {
  Error *local_err = NULL;
  bc-memory_init(backend, local_err);
  if (local_err != NULL) {
  error_propagate(errp, local_err);
  return;
  }
 
  ... set policy ...
 }
 
 ...
 
  Error *local_err = NULL;
  host_memory_backend_alloc(backend, local_err);
  if (local_err != NULL) {
  error_propagate(errp, local_err);
  return NULL;
  }
 
  assert(memory_region_size(backend-mr) != 0);
  return backend-mr;
 }
 
[...]



Re: [Qemu-devel] [PATCH v2, Ping] SMBIOS: Upgrade Type17 to v2.3, add Type2

2014-02-19 Thread Gerd Hoffmann
  Hi,

 In my opinion, generating the entire smbios table in QEMU and using
 the romfile_loader mechanism (see seabios src/fw/romfile_loader.c)
 would be the preferred solution.  I understand that this is more than
 you signed up for.

Yes, this is where we should end up long-term.  For the time being I
think it is fine to use the existing mechanism to switch over table by
table, and once we have the code to generate all tables in qemu we can
switch over to an interface where we simply pass all tables as single
blob.  I think we don't even need the romfile_loader, or do have smbios
tables pointers which need to be fixed up?

cheers,
  Gerd





Re: [Qemu-devel] [PATCH v4 0/8] block: Integrate bdrv_file_open() into bdrv_open()

2014-02-19 Thread Kevin Wolf
Am 18.02.2014 um 18:33 hat Max Reitz geschrieben:
 bdrv_file_open() is now nearly a subset of bdrv_open(), except for the
 fact that bdrv_file_open() is for protocols and bdrv_open() for block
 drivers. It is possible to use bdrv_file_open() with a block driver, but
 in that case that block driver must be explicitly specified.
 
 Due to these great similarities, bdrv_file_open() can be integrated and
 made a special case of bdrv_open(). If the flag BDRV_O_PROTOCOL is
 specified, bdrv_open() will now do what bdrv_file_open() used to do:
 Auto-detecting a protocol instead of a block driver.
 
 This series implements this and changes all calls to bdrv_file_open() to
 bdrv_open() calls with BDRV_O_PROTOCOL specified.
 
 Note that this flag cannot be discerned automatically since it is
 impossible for bdrv_open() to know by itself whether a given file should
 be opened with or without the format layer involved: Both are valid
 alternatives. Therefore, it still has to be specified by the user.

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [PATCH v18 06/14] qapi: add SIZE type parser to string_input_visitor

2014-02-19 Thread Igor Mammedov
On Wed, 19 Feb 2014 15:53:57 +0800
Hu Tao hu...@cn.fujitsu.com wrote:

 From: Igor Mammedov imamm...@redhat.com
 
 Signed-off-by: Igor Mammedov imamm...@redhat.com
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
replace it with a better patch from Paolo that soon
will get merged into master:
http://www.mail-archive.com/qemu-devel@nongnu.org/msg216512.html


 ---
  qapi/string-input-visitor.c | 18 ++
  1 file changed, 18 insertions(+)
 
 diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
 index 8f1bc41..a152f5d 100644
 --- a/qapi/string-input-visitor.c
 +++ b/qapi/string-input-visitor.c
 @@ -97,6 +97,23 @@ static void parse_type_number(Visitor *v, double *obj, 
 const char *name,
  *obj = val;
  }
  
 +static void parse_type_size(Visitor *v, uint64_t *obj, const char *name,
 +Error **errp)
 +{
 +StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
 +int64_t val;
 +char *endp;
 +
 +val = strtosz_suffix(siv-string ? siv-string : , endp,
 + STRTOSZ_DEFSUFFIX_B);
 +if (val  0 || *endp != '\0') {
 +error_set(errp, QERR_INVALID_PARAMETER_VALUE, name,
 +  a size value representible as a non-negative int64);
 +return;
 +}
 +*obj = val;
 +}
 +
  static void parse_start_optional(Visitor *v, bool *present,
   const char *name, Error **errp)
  {
 @@ -131,6 +148,7 @@ StringInputVisitor *string_input_visitor_new(const char 
 *str)
  v-visitor.type_bool = parse_type_bool;
  v-visitor.type_str = parse_type_str;
  v-visitor.type_number = parse_type_number;
 +v-visitor.type_size = parse_type_size;
  v-visitor.start_optional = parse_start_optional;
  
  v-string = str;




Re: [Qemu-devel] [PATCH v2, Ping] SMBIOS: Upgrade Type17 to v2.3, add Type2

2014-02-19 Thread Gerd Hoffmann
  Hi,

 However, when I compare unmodified SMBIOS against what I get when
 supplying the patched binary table via command line, I get this:

As Laszlo already sayed: one table per file.
 
  If seabios finds a table provided by qemu it used it, otherwise it
  (possibly) generates its own.  So we can smoothly switch over to qemu,
  table-by-table.  You can have qemu provide type2+type17 tables, and
  leave everything else as-is.  And when doing it in qemu it is easy to do
  it for new machine types only.
 
 I could try to hack at the QEMU smbios source file to try to find
 where the problem lies (at least why handover to SeaBIOS doesn't work
 as expected), but I'm not sure providing command line flags for
 inputting each record type individually is a scalable way to move
 forward.

Agree.  qemu should simply autogenerate the entries (where it can).
i.e. basically port seabios smbios_init_type_17 function to qemu, then
hook the result into the smbios_entries array.  The code to do that is
in smbios_entry_add().  You probably want to factor that out ino a small
helper function which is then called by both smbios_entry_add() and the
type17 init function.

cheers,
  Gerd





Re: [Qemu-devel] Buildbot failure: MinGW

2014-02-19 Thread Gerd Hoffmann
On Mi, 2014-02-19 at 05:27 +0100, Stefan Weil wrote:
 Hi Gerd, hi Stefan,
 
 we now need a C++ compiler on the buildbots. Currently, it's missing for
 MinGW:
 
 /bin/sh: i686-pc-mingw32-g++: command not found

Installed.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 1/8] virtio_get_byteswap: function for endian-ambivalent targets using virtio.

2014-02-19 Thread Greg Kurz
On Tue, 18 Feb 2014 20:25:15 +0100
Andreas Färber afaer...@suse.de wrote:
 Am 18.02.2014 13:38, schrieb Greg Kurz:
  diff --git a/include/hw/virtio/virtio-access.h
  b/include/hw/virtio/virtio-access.h new file mode 100644
  index 000..2e22a47
  --- /dev/null
  +++ b/include/hw/virtio/virtio-access.h
  @@ -0,0 +1,132 @@
  +/*
  + * Virtio Accessor Support: In case your target can change endian.
  + *
  + * Copyright IBM, Corp. 2013
  + *
  + * Authors:
  + *  Rusty Russell   ru...@au.ibm.com
  + *
  + * This work is licensed under the terms of the GNU GPL, version 2.
  See
  + * the COPYING file in the top-level directory.
 [snip]
 
 I notice that this has been GPL-2.0 from Rusty's first series on. Is
 there a reason not to make the new file GPL-2.0+?
 
 Cf. http://wiki.qemu.org/Relicensing
 
 Thanks,
 Andreas
 

Rusty ? It is your call. :)

-- 
Gregory Kurz kurzg...@fr.ibm.com
 gk...@linux.vnet.ibm.com
Software Engineer @ IBM/Meiosys  http://www.ibm.com
Tel +33 (0)562 165 496

Anarchy is about taking complete responsibility for yourself.
Alan Moore.




[Qemu-devel] Question

2014-02-19 Thread atlas khan
I am working on project in which we have add support of a board in QEMU. We
have to add some virtual devices in QEMU. The question which I want to ask
that what should I do to add virtual device. And after adding that device
in \hw in which file I have to make changes so that program access that
hardware when it need it. Because the device which I have to add is the
device which is already available, but in our board, this device has
different architecture, so we want our program to access that file which we
have made for our board instead of file which is already available in
QEMU


Re: [Qemu-devel] [PATCH] trace-events: Fix typo in offset

2014-02-19 Thread Stefan Hajnoczi
On Mon, Feb 17, 2014 at 10:03:17AM +0100, Kevin Wolf wrote:
 s/offet/offset/
 
 Signed-off-by: Kevin Wolf kw...@redhat.com
 ---
  trace-events | 8 
  1 file changed, 4 insertions(+), 4 deletions(-)

Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan



Re: [Qemu-devel] [PATCH 0/2] bswap: Clean prototypes of st* functions

2014-02-19 Thread Laszlo Ersek
On 02/19/14 06:11, Stefan Weil wrote:
 These modifications avoid type conversions for non optimized code.
 
 ld* function prototypes will follow later.
 
 [PATCH 1/2] bswap: Modify prototype of stb_p (avoid type
 [PATCH 2/2] bswap: Modify prototypes of st[wl]_{le,be}_p (avoid type
 

It probably wouldn't hurt to audit all call sites, but it does look
reasonable.

Reviewed-by: Laszlo Ersek ler...@redhat.com



Re: [Qemu-devel] [PULL 00/15] tcg updates

2014-02-19 Thread Kevin Wolf
Am 18.02.2014 um 02:15 hat Richard Henderson geschrieben:
 Contains two patch sets, recently reviewed.  Plus two other
 unrelated patches that probably weren't going to get in via
 any other tree.

It doesn't seem to contain my target-i386 I/O bitmap fix. Should I send
a separate pull request for that one?

Kevin



Re: [Qemu-devel] [PULL 00/15] tcg updates

2014-02-19 Thread Kevin Wolf
Am 19.02.2014 um 11:21 hat Kevin Wolf geschrieben:
 Am 18.02.2014 um 02:15 hat Richard Henderson geschrieben:
  Contains two patch sets, recently reviewed.  Plus two other
  unrelated patches that probably weren't going to get in via
  any other tree.
 
 It doesn't seem to contain my target-i386 I/O bitmap fix. Should I send
 a separate pull request for that one?

Ah, sorry, I was too quick. This pull request seems to be about TCG
proper and the backends, not the targets (confused tcg/i386 with
target-i386).

Kevin



[Qemu-devel] [PATCH] XBZRLE: Fix qemu crash when resize the xbzrle cache during migration

2014-02-19 Thread Gonglei (Arei)
It is likely to crash qemu when resize the xbzrle cache
during migration. Because the xbzrle cache will be modified
by migration thread and resize thread.

Test scene
step one: set the size of xbzrle cache 1GB.
step two: migrate vm which dirty memory continuously.
step three: set the size of xbzrle cache 0.125GB.

Signed-off-by: ChenLiang chenlian...@huawei.commailto:chenlian...@huawei.com
Signed-off-by: Gonglei arei.gong...@huawei.commailto:arei.gong...@huawei.com
---
arch_init.c|   42 ---
include/migration/page_cache.h |   14 +
page_cache.c   |   13 
3 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 80574a0..e2d2c72 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -164,26 +164,56 @@ static struct {
 uint8_t *encoded_buf;
 /* buffer for storing page content */
 uint8_t *current_buf;
-/* Cache for XBZRLE */
+/* Cache for XBZRLE, Protected by lock. */
 PageCache *cache;
+QemuMutex lock;
} XBZRLE = {
 .encoded_buf = NULL,
 .current_buf = NULL,
 .cache = NULL,
};
+
/* buffer used for XBZRLE decoding */
static uint8_t *xbzrle_decoded_buf;

+static void XBZRLE_cache_lock(void)
+{
+qemu_mutex_lock(XBZRLE.lock);
+}
+
+static void XBZRLE_cache_unlock(void)
+{
+qemu_mutex_unlock(XBZRLE.lock);
+}
+
+
int64_t xbzrle_cache_resize(int64_t new_size)
{
+PageCache *new_cache, *old_cache;
+
 if (new_size  TARGET_PAGE_SIZE) {
 return -1;
 }

 if (XBZRLE.cache != NULL) {
-return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) *
-TARGET_PAGE_SIZE;
+if (pow2floor(new_size) == cache_max_num_items(XBZRLE.cache)
+   *TARGET_PAGE_SIZE) {
+goto ret;
+}
+new_cache = cache_init(new_size / TARGET_PAGE_SIZE,
+  cache_page_size(XBZRLE.cache));
+if (!new_cache) {
+DPRINTF(Error creating cache\n);
+return -1;
+}
+XBZRLE_cache_lock();
+old_cache = XBZRLE.cache;
+XBZRLE.cache = new_cache;
+XBZRLE_cache_unlock();
+cache_fini(old_cache);
+goto ret;
 }
+ret:
 return pow2floor(new_size);
}

@@ -522,6 +552,8 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 ret = ram_control_save_page(f, block-offset,
offset, TARGET_PAGE_SIZE, bytes_sent);

+XBZRLE_cache_lock();
+
 if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
 if (ret != RAM_SAVE_CONTROL_DELAYED) {
 if (bytes_sent  0) {
@@ -553,6 +585,8 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 acct_info.norm_pages++;
 }

+XBZRLE_cache_unlock();
+
 /* if page is unmodified, continue to the next */
 if (bytes_sent  0) {
 last_sent_block = block;
@@ -681,7 +715,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 XBZRLE.encoded_buf = NULL;
 return -1;
 }
-
+qemu_mutex_init(XBZRLE.lock);
 acct_clear();
 }

diff --git a/include/migration/page_cache.h b/include/migration/page_cache.h
index d156f0d..6be0103 100644
--- a/include/migration/page_cache.h
+++ b/include/migration/page_cache.h
@@ -79,4 +79,18 @@ int cache_insert(PageCache *cache, uint64_t addr, uint8_t 
*pdata);
  */
int64_t cache_resize(PageCache *cache, int64_t num_pages);

+/**
+ * cache_max_num_items: return the cache max num items.
+ *
+ * @cache pointer to the PageCache struct
+ */
+int64_t cache_max_num_items(PageCache *cache);
+
+/**
+ * cache_page_size: return the cache page size
+ *
+ * @cache pointer to the PageCache struct
+ */
+unsigned int cache_page_size(PageCache *cache);
+
#endif
diff --git a/page_cache.c b/page_cache.c
index 3ef6ee7..92e401c 100644
--- a/page_cache.c
+++ b/page_cache.c
@@ -234,3 +234,16 @@ int64_t cache_resize(PageCache *cache, int64_t 
new_num_pages)

 return cache-max_num_items;
}
+
+int64_t cache_max_num_items(PageCache *cache)
+{
+g_assert(cache);
+return cache-max_num_items;
+}
+
+unsigned int cache_page_size(PageCache *cache)
+{
+g_assert(cache);
+return cache-page_size;
+}
+
--
1.6.0.2


Best regards,
-Gonglei



[Qemu-devel] [PATCH 4/6] linux-user: Fix error handling in lock_iovec()

2014-02-19 Thread riku . voipio
From: Peter Maydell peter.mayd...@linaro.org

In lock_iovec() if lock_user() failed we were doing an unlock_user
but not a free(vec), which is the wrong way round. We were also
assuming that free() and unlock_user() don't touch errno, which
is not guaranteed. Fix both these problems.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/syscall.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f370087..bb3e4b1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1707,6 +1707,7 @@ static struct iovec *lock_iovec(int type, abi_ulong 
target_addr,
 struct iovec *vec;
 abi_ulong total_len, max_len;
 int i;
+int err = 0;
 
 if (count == 0) {
 errno = 0;
@@ -1726,7 +1727,7 @@ static struct iovec *lock_iovec(int type, abi_ulong 
target_addr,
 target_vec = lock_user(VERIFY_READ, target_addr,
count * sizeof(struct target_iovec), 1);
 if (target_vec == NULL) {
-errno = EFAULT;
+err = EFAULT;
 goto fail2;
 }
 
@@ -1740,7 +1741,7 @@ static struct iovec *lock_iovec(int type, abi_ulong 
target_addr,
 abi_long len = tswapal(target_vec[i].iov_len);
 
 if (len  0) {
-errno = EINVAL;
+err = EINVAL;
 goto fail;
 } else if (len == 0) {
 /* Zero length pointer is ignored.  */
@@ -1748,7 +1749,7 @@ static struct iovec *lock_iovec(int type, abi_ulong 
target_addr,
 } else {
 vec[i].iov_base = lock_user(type, base, len, copy);
 if (!vec[i].iov_base) {
-errno = EFAULT;
+err = EFAULT;
 goto fail;
 }
 if (len  max_len - total_len) {
@@ -1763,9 +1764,10 @@ static struct iovec *lock_iovec(int type, abi_ulong 
target_addr,
 return vec;
 
  fail:
-free(vec);
- fail2:
 unlock_user(target_vec, target_addr, 0);
+ fail2:
+free(vec);
+errno = err;
 return NULL;
 }
 
-- 
1.8.1.2




[Qemu-devel] [PATCH 6/6] linux-user: Fix error handling in target_to_host_semarray()

2014-02-19 Thread riku . voipio
From: Peter Maydell peter.mayd...@linaro.org

Fix two issues in error handling in target_to_host_semarray():
 * don't leak the host_array buffer if lock_user fails
 * return an error if malloc() fails

v2: added missing * -Riku Voipio

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/syscall.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8f5a58e..1407b7a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2430,10 +2430,15 @@ static inline abi_long target_to_host_semarray(int 
semid, unsigned short **host_
 nsems = semid_ds.sem_nsems;
 
 *host_array = malloc(nsems*sizeof(unsigned short));
+if (!*host_array) {
+return -TARGET_ENOMEM;
+}
 array = lock_user(VERIFY_READ, target_addr,
   nsems*sizeof(unsigned short), 1);
-if (!array)
+if (!array) {
+free(*host_array);
 return -TARGET_EFAULT;
+}
 
 for(i=0; insems; i++) {
 __get_user((*host_array)[i], array[i]);
-- 
1.8.1.2




[Qemu-devel] [PATCH 3/6] linux-user/signal.c: Don't pass sigaction uninitialised sa_flags

2014-02-19 Thread riku . voipio
From: Peter Maydell peter.mayd...@linaro.org

When forcing a fatal signal, we weren't initialising the sa_flags
field in the struct sigaction we used to reset the signal handler
to SIG_DFL.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/signal.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 82e8592..04638e2 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -420,6 +420,7 @@ static void QEMU_NORETURN force_sig(int target_sig)
  * it to arrive. */
 sigfillset(act.sa_mask);
 act.sa_handler = SIG_DFL;
+act.sa_flags = 0;
 sigaction(host_sig, act, NULL);
 
 /* For some reason raise(host_sig) doesn't send the signal when
-- 
1.8.1.2




[Qemu-devel] [PATCH 5/6] linux-user: Implement BLKPG ioctl

2014-02-19 Thread riku . voipio
From: Andreas Färber afaer...@suse.de

Signed-off-by: Andreas Färber afaer...@suse.de
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/ioctls.h|  1 +
 linux-user/syscall.c   |  1 +
 linux-user/syscall_defs.h  |  1 +
 linux-user/syscall_types.h | 13 +
 4 files changed, 16 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 7381012..309fb21 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -77,6 +77,7 @@
  IOCTL(BLKRAGET, IOC_R, MK_PTR(TYPE_LONG))
  IOCTL(BLKSSZGET, IOC_R, MK_PTR(TYPE_LONG))
  IOCTL(BLKBSZGET, IOC_R, MK_PTR(TYPE_INT))
+ IOCTL(BLKPG, IOC_W, MK_PTR(MK_STRUCT(STRUCT_blkpg_ioctl_arg)))
 #ifdef FIBMAP
  IOCTL(FIBMAP, IOC_W | IOC_R, MK_PTR(TYPE_LONG))
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bb3e4b1..8f5a58e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -107,6 +107,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include linux/reboot.h
 #include linux/route.h
 #include linux/filter.h
+#include linux/blkpg.h
 #include linux_loop.h
 #include cpu-uname.h
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index ae30476..3c8869e 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -901,6 +901,7 @@ struct target_pollfd {
 #define TARGET_BLKSECTSET TARGET_IO(0x12,102)/* set max sectors per request 
(ll_rw_blk.c) */
 #define TARGET_BLKSECTGET TARGET_IO(0x12,103)/* get max sectors per request 
(ll_rw_blk.c) */
 #define TARGET_BLKSSZGET  TARGET_IO(0x12,104)/* get block device sector size */
+#define TARGET_BLKPG  TARGET_IO(0x12,105)/* Partition table and disk 
geometry handling */
 /* A jump here: 108-111 have been used for various private purposes. */
 #define TARGET_BLKBSZGET  TARGET_IOR(0x12, 112, abi_ulong)
 #define TARGET_BLKBSZSET  TARGET_IOW(0x12, 113, abi_ulong)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 44b6a58..9d0c92d 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -240,3 +240,16 @@ STRUCT(fiemap,
TYPE_INT, /* fm_mapped_extents */
TYPE_INT, /* fm_extent_count */
TYPE_INT) /* fm_reserved */
+
+STRUCT(blkpg_partition,
+   TYPE_LONGLONG, /* start */
+   TYPE_LONGLONG, /* length */
+   TYPE_INT, /* pno */
+   MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */
+   MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
+
+STRUCT(blkpg_ioctl_arg,
+   TYPE_INT, /* op */
+   TYPE_INT, /* flags */
+   TYPE_INT, /* datalen */
+   MK_PTR(MK_STRUCT(STRUCT_blkpg_partition))) /* data */
-- 
1.8.1.2




[Qemu-devel] [PATCH 1/6] linux-user: sync syscall numbers upto 3.13

2014-02-19 Thread riku . voipio
From: Riku Voipio riku.voi...@linaro.org

All others updated except unicore, which doesn't look right to
begin with.

Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/alpha/syscall_nr.h  |  7 +++
 linux-user/arm/syscall_nr.h|  6 ++
 linux-user/cris/syscall_nr.h   |  1 +
 linux-user/i386/syscall_nr.h   |  6 ++
 linux-user/m68k/syscall_nr.h   |  5 +
 linux-user/microblaze/syscall_nr.h |  7 ++-
 linux-user/mips/syscall_nr.h   |  6 ++
 linux-user/mips64/syscall_nr.h | 13 +
 linux-user/openrisc/syscall_nr.h   |  6 +-
 linux-user/ppc/syscall_nr.h|  6 ++
 linux-user/s390x/syscall_nr.h  |  7 ++-
 linux-user/sh4/syscall_nr.h|  6 ++
 linux-user/sparc/syscall_nr.h  |  7 +++
 linux-user/sparc64/syscall_nr.h|  7 +++
 linux-user/x86_64/syscall_nr.h |  7 +++
 15 files changed, 94 insertions(+), 3 deletions(-)

diff --git a/linux-user/alpha/syscall_nr.h b/linux-user/alpha/syscall_nr.h
index d52d76e..625f301 100644
--- a/linux-user/alpha/syscall_nr.h
+++ b/linux-user/alpha/syscall_nr.h
@@ -433,3 +433,10 @@
 #define TARGET_NR_open_by_handle_at 498
 #define TARGET_NR_clock_adjtime 499
 #define TARGET_NR_syncfs500
+#define TARGET_NR_setns 501
+#define TARGET_NR_accept4   502
+#define TARGET_NR_sendmmsg  503
+#define TARGET_NR_process_vm_readv  504
+#define TARGET_NR_process_vm_writev 505
+#define TARGET_NR_kcmp  506
+#define TARGET_NR_finit_module  507
diff --git a/linux-user/arm/syscall_nr.h b/linux-user/arm/syscall_nr.h
index 42d6855..bef847c 100644
--- a/linux-user/arm/syscall_nr.h
+++ b/linux-user/arm/syscall_nr.h
@@ -378,3 +378,9 @@
 #define TARGET_NR_open_by_handle_at(371)
 #define TARGET_NR_clock_adjtime(372)
 #define TARGET_NR_syncfs   (373)
+#define TARGET_NR_sendmmsg (374)
+#define TARGET_NR_setns(375)
+#define TARGET_NR_process_vm_readv (376)
+#define TARGET_NR_process_vm_writev(377)
+#define TARGET_NR_kcmp (378)
+#define TARGET_NR_finit_module (379)
diff --git a/linux-user/cris/syscall_nr.h b/linux-user/cris/syscall_nr.h
index 98f1a0b..694bd02 100644
--- a/linux-user/cris/syscall_nr.h
+++ b/linux-user/cris/syscall_nr.h
@@ -335,3 +335,4 @@
 #define TARGET_NR_inotify_init1  332
 #define TARGET_NR_preadv 333
 #define TARGET_NR_pwritev334
+#define TARGET_NR_setns  335
diff --git a/linux-user/i386/syscall_nr.h b/linux-user/i386/syscall_nr.h
index f080305..c8f7302 100644
--- a/linux-user/i386/syscall_nr.h
+++ b/linux-user/i386/syscall_nr.h
@@ -347,3 +347,9 @@
 #define TARGET_NR_open_by_handle_at 342
 #define TARGET_NR_clock_adjtime 343
 #define TARGET_NR_syncfs344
+#define TARGET_NR_sendmmsg  345
+#define TARGET_NR_setns 346
+#define TARGET_NR_process_vm_readv  347
+#define TARGET_NR_process_vm_writev 348
+#define TARGET_NR_kcmp  349
+#define TARGET_NR_finit_module  350
diff --git a/linux-user/m68k/syscall_nr.h b/linux-user/m68k/syscall_nr.h
index 4d0937e..25f8521 100644
--- a/linux-user/m68k/syscall_nr.h
+++ b/linux-user/m68k/syscall_nr.h
@@ -344,3 +344,8 @@
 #define TARGET_NR_open_by_handle_at 341
 #define TARGET_NR_clock_adjtime 342
 #define TARGET_NR_syncfs343
+#define TARGET_NR_setns 344
+#define TARGET_NR_process_vm_readv  345
+#define TARGET_NR_process_vm_writev 346
+#define TARGET_NR_kcmp  347
+#define TARGET_NR_finit_module  348
diff --git a/linux-user/microblaze/syscall_nr.h 
b/linux-user/microblaze/syscall_nr.h
index f1fe0e7..6f530f9 100644
--- a/linux-user/microblaze/syscall_nr.h
+++ b/linux-user/microblaze/syscall_nr.h
@@ -376,4 +376,9 @@
 #define TARGET_NR_open_by_handle_at 372
 #define TARGET_NR_clock_adjtime 373
 #define TARGET_NR_syncfs374
-
+#define TARGET_NR_setns 375
+#define TARGET_NR_sendmmsg  376
+#define TARGET_NR_process_vm_readv  377
+#define TARGET_NR_process_vm_writev 378
+#define TARGET_NR_kcmp  379
+#define TARGET_NR_finit_module  380
diff --git a/linux-user/mips/syscall_nr.h b/linux-user/mips/syscall_nr.h
index fbdc348..2d1a13e 100644
--- a/linux-user/mips/syscall_nr.h
+++ b/linux-user/mips/syscall_nr.h
@@ -345,3 +345,9 @@
 #define TARGET_NR_open_by_handle_at (TARGET_NR_Linux + 340)
 #define TARGET_NR_clock_adjtime (TARGET_NR_Linux + 341)
 #define TARGET_NR_syncfs(TARGET_NR_Linux + 342)
+#define TARGET_NR_sendmmsg  (TARGET_NR_Linux + 343)
+#define TARGET_NR_setns 

[Qemu-devel] [PATCH 2/6] linux-user/elfload.c: Avoid calling g_free() on uninitialized data

2014-02-19 Thread riku . voipio
From: Peter Maydell peter.mayd...@linaro.org

Avoid calling g_free() on unintialized data in the error-handling
paths in elf_core_dump() by splitting the initialization of the
elf_note_info struct out of fill_note_info() so that it's always
valid to call free_note_info() whether we got to the point of
being able to fill_note_info() or not.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/elfload.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5902f16..c0687e3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2636,6 +2636,16 @@ static void fill_thread_info(struct elf_note_info *info, 
const CPUArchState *env
 info-notes_size += note_size(ets-notes[0]);
 }
 
+static void init_note_info(struct elf_note_info *info)
+{
+/* Initialize the elf_note_info structure so that it is at
+ * least safe to call free_note_info() on it. Must be
+ * called before calling fill_note_info().
+ */
+memset(info, 0, sizeof (*info));
+QTAILQ_INIT(info-thread_list);
+}
+
 static int fill_note_info(struct elf_note_info *info,
   long signr, const CPUArchState *env)
 {
@@ -2644,10 +2654,6 @@ static int fill_note_info(struct elf_note_info *info,
 TaskState *ts = (TaskState *)env-opaque;
 int i;
 
-(void) memset(info, 0, sizeof (*info));
-
-QTAILQ_INIT(info-thread_list);
-
 info-notes = g_malloc0(NUMNOTES * sizeof (struct memelfnote));
 if (info-notes == NULL)
 return (-ENOMEM);
@@ -2781,6 +2787,8 @@ static int elf_core_dump(int signr, const CPUArchState 
*env)
 int segs = 0;
 int fd = -1;
 
+init_note_info(info);
+
 errno = 0;
 getrlimit(RLIMIT_CORE, dumpsize);
 if (dumpsize.rlim_cur == 0)
-- 
1.8.1.2




[Qemu-devel] [PULL 0/6] linux-user updates

2014-02-19 Thread riku . voipio
From: Riku Voipio riku.voi...@linaro.org

The following changes since commit 46eef33b89e936ca793e13c4aeea1414e97e8dbb:

  Fix QEMU build on OpenBSD on x86 archs (2014-02-17 11:44:00 +)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git linux-user-for-upstream

for you to fetch changes up to 69d4c703a549f0630793a67b16a8fc6bc14c8654:

  linux-user: Fix error handling in target_to_host_semarray() (2014-02-19 
12:29:23 +0200)

Andreas Färber (1):
  linux-user: Implement BLKPG ioctl

Peter Maydell (4):
  linux-user/elfload.c: Avoid calling g_free() on uninitialized data
  linux-user/signal.c: Don't pass sigaction uninitialised sa_flags
  linux-user: Fix error handling in lock_iovec()
  linux-user: Fix error handling in target_to_host_semarray()

Riku Voipio (1):
  linux-user: sync syscall numbers upto 3.13

 linux-user/alpha/syscall_nr.h  |  7 +++
 linux-user/arm/syscall_nr.h|  6 ++
 linux-user/cris/syscall_nr.h   |  1 +
 linux-user/elfload.c   | 16 
 linux-user/i386/syscall_nr.h   |  6 ++
 linux-user/ioctls.h|  1 +
 linux-user/m68k/syscall_nr.h   |  5 +
 linux-user/microblaze/syscall_nr.h |  7 ++-
 linux-user/mips/syscall_nr.h   |  6 ++
 linux-user/mips64/syscall_nr.h | 13 +
 linux-user/openrisc/syscall_nr.h   |  6 +-
 linux-user/ppc/syscall_nr.h|  6 ++
 linux-user/s390x/syscall_nr.h  |  7 ++-
 linux-user/sh4/syscall_nr.h|  6 ++
 linux-user/signal.c|  1 +
 linux-user/sparc/syscall_nr.h  |  7 +++
 linux-user/sparc64/syscall_nr.h|  7 +++
 linux-user/syscall.c   | 20 ++--
 linux-user/syscall_defs.h  |  1 +
 linux-user/syscall_types.h | 13 +
 linux-user/x86_64/syscall_nr.h |  7 +++
 21 files changed, 136 insertions(+), 13 deletions(-)

-- 
1.8.1.2




[Qemu-devel] [PATCH] qxl: add sanity check

2014-02-19 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/display/qxl.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 1471cc0..2a559eb 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1429,7 +1429,7 @@ static int qxl_destroy_primary(PCIQXLDevice *d, 
qxl_async_io async)
 return 1;
 }
 
-static void qxl_set_mode(PCIQXLDevice *d, int modenr, int loadvm)
+static void qxl_set_mode(PCIQXLDevice *d, unsigned int modenr, int loadvm)
 {
 pcibus_t start = d-pci.io_regions[QXL_RAM_RANGE_INDEX].addr;
 pcibus_t end   = d-pci.io_regions[QXL_RAM_RANGE_INDEX].size + start;
@@ -1439,6 +1439,12 @@ static void qxl_set_mode(PCIQXLDevice *d, int modenr, 
int loadvm)
 .mem_start = start,
 .mem_end = end
 };
+
+if (modenr = d-modes-n_modes) {
+qxl_set_guest_bug(d, mode number out of range);
+return;
+}
+
 QXLSurfaceCreate surface = {
 .width  = mode-x_res,
 .height = mode-y_res,
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v18 10/14] numa: add -numa node, memdev= option

2014-02-19 Thread Igor Mammedov
On Wed, 19 Feb 2014 15:54:01 +0800
Hu Tao hu...@cn.fujitsu.com wrote:

 From: Paolo Bonzini pbonz...@redhat.com
 
 This option provides the infrastructure for binding guest NUMA nodes
 to host NUMA nodes.  For example:
 
  -object memory-ram,size=1024M,policy=membind,host-nodes=0,id=ram-node0 \
  -numa node,nodeid=0,cpus=0,memdev=ram-node0 \
  -object memory-ram,size=1024M,policy=interleave,host-nodes=1-3,id=ram-node1 \
  -numa node,nodeid=1,cpus=1,memdev=ram-node1
 
 The option replaces -numa mem.
 
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 
 Conflicts:
   include/sysemu/sysemu.h
   numa.c
 
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
  include/sysemu/sysemu.h |  2 ++
  numa.c  | 64 
 +++--
  qapi-schema.json|  6 -
  3 files changed, 69 insertions(+), 3 deletions(-)
 
 diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
 index e9da760..acfc0c7 100644
 --- a/include/sysemu/sysemu.h
 +++ b/include/sysemu/sysemu.h
 @@ -12,6 +12,7 @@
  #include qemu/bitmap.h
  #include qom/object.h
  #include hw/boards.h
 +#include sysemu/hostmem.h
  
  /* vl.c */
  
 @@ -140,6 +141,7 @@ extern int nb_numa_nodes;
  typedef struct node_info {
  uint64_t node_mem;
  DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
 +HostMemoryBackend *node_memdev;
  } NodeInfo;
  extern NodeInfo numa_info[MAX_NODES];
  void set_numa_nodes(void);
 diff --git a/numa.c b/numa.c
 index 403b08b..ca55ad7 100644
 --- a/numa.c
 +++ b/numa.c
 @@ -27,6 +27,8 @@
  #include qapi-visit.h
  #include qapi/opts-visitor.h
  #include qapi/dealloc-visitor.h
 +#include qapi/qmp/qerror.h
 +
  QemuOptsList qemu_numa_opts = {
  .name = numa,
  .implied_opt_name = type,
 @@ -34,10 +36,13 @@ QemuOptsList qemu_numa_opts = {
  .desc = { { 0 } } /* validated with OptsVisitor */
  };
  
 +static int have_memdevs = -1;
 +
  static int numa_node_parse(NumaNodeOptions *opts)
  {
  uint16_t nodenr;
  uint16List *cpus = NULL;
 +Error *local_err = NULL;
  
  if (opts-has_nodeid) {
  nodenr = opts-nodeid;
 @@ -60,6 +65,19 @@ static int numa_node_parse(NumaNodeOptions *opts)
  bitmap_set(numa_info[nodenr].node_cpu, cpus-value, 1);
  }
  
 +if (opts-has_mem  opts-has_memdev) {
 +fprintf(stderr, qemu: cannot specify both mem= and memdev=\n);
 +return -1;
 +}
 +
 +if (have_memdevs == -1) {
 +have_memdevs = opts-has_memdev;
 +}
 +if (opts-has_memdev != have_memdevs) {
 +fprintf(stderr, qemu: memdev option must be specified for either 
 +all or no nodes\n);
 +}
 +
  if (opts-has_mem) {
  int64_t mem_size;
  char *endptr;
 @@ -70,7 +88,19 @@ static int numa_node_parse(NumaNodeOptions *opts)
  }
  numa_info[nodenr].node_mem = mem_size;
  }
 +if (opts-has_memdev) {
 +Object *o;
 +o = object_resolve_path_type(opts-memdev, TYPE_MEMORY_BACKEND, 
 NULL);
 +if (!o) {
 +error_setg(local_err, memdev=%s is ambiguous, opts-memdev);
 +qerror_report_err(local_err);
 +return -1;
 +}
  
 +object_ref(o);
 +numa_info[nodenr].node_mem = object_property_get_int(o, size, 
 NULL);
 +numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
if you make numa_info  QOM object node_memdev link property,
then above hunk could be replaced with just setting link.
And node_mem could be replaced with readonly property that reads size
directly from memdev avoiding data duplication.

As side-effect it numa_info will also become accessible for introspection
using QOM interface. Something like:
 qom-list /machine/memory-node[X]
 qom-get /machine/memory-node[X]/memory_size


 +}
  return 0;
  }
  
 @@ -189,12 +219,42 @@ void set_numa_modes(void)
  }
  }
  
 +static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
 +   const char *name,
 +   QEMUMachineInitArgs *args)
 +{
 +uint64_t ram_size = args-ram_size;
 +
 +memory_region_init_ram(mr, owner, name, ram_size);
 +vmstate_register_ram_global(mr);
 +}
 +
  void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
const char *name,
QEMUMachineInitArgs *args)
  {
  uint64_t ram_size = args-ram_size;
 +uint64_t addr = 0;
 +int i;
  
 -memory_region_init_ram(mr, owner, name, ram_size);
 -vmstate_register_ram_global(mr);
 +if (nb_numa_nodes == 0 || !have_memdevs) {
 +allocate_system_memory_nonnuma(mr, owner, name, args);
 +return;
 +}
 +
 +memory_region_init(mr, owner, name, ram_size);
 +for (i = 0; i  nb_numa_nodes; i++) {
 +Error *local_err = NULL;
 +uint64_t size = numa_info[i].node_mem;
 +HostMemoryBackend *backend = 

Re: [Qemu-devel] [PATCH] XBZRLE: Fix qemu crash when resize the xbzrle cache during migration

2014-02-19 Thread Dr. David Alan Gilbert
* Gonglei (Arei) (arei.gong...@huawei.com) wrote:

Hi Arei,

 It is likely to crash qemu when resize the xbzrle cache
 during migration. Because the xbzrle cache will be modified
 by migration thread and resize thread.

Thanks - we was just thinking about this last night after 
we hit it.

I was thinking about doing it by just moving the resize
into the ram save loop; but I think your lock looks about right.

 Test scene
 step one: set the size of xbzrle cache 1GB.
 step two: migrate vm which dirty memory continuously.
 step three: set the size of xbzrle cache 0.125GB.
 
 Signed-off-by: ChenLiang 
 chenlian...@huawei.commailto:chenlian...@huawei.com
 Signed-off-by: Gonglei 
 arei.gong...@huawei.commailto:arei.gong...@huawei.com
 ---
 arch_init.c|   42 ---
 include/migration/page_cache.h |   14 +
 page_cache.c   |   13 
 3 files changed, 65 insertions(+), 4 deletions(-)
 
 diff --git a/arch_init.c b/arch_init.c
 index 80574a0..e2d2c72 100644
 --- a/arch_init.c
 +++ b/arch_init.c
 @@ -164,26 +164,56 @@ static struct {
  uint8_t *encoded_buf;
  /* buffer for storing page content */
  uint8_t *current_buf;
 -/* Cache for XBZRLE */
 +/* Cache for XBZRLE, Protected by lock. */
  PageCache *cache;
 +QemuMutex lock;
 } XBZRLE = {
  .encoded_buf = NULL,
  .current_buf = NULL,
  .cache = NULL,
 };
 +
 /* buffer used for XBZRLE decoding */
 static uint8_t *xbzrle_decoded_buf;
 
 +static void XBZRLE_cache_lock(void)
 +{
 +qemu_mutex_lock(XBZRLE.lock);
 +}
 +
 +static void XBZRLE_cache_unlock(void)
 +{
 +qemu_mutex_unlock(XBZRLE.lock);
 +}
 +
 +
 int64_t xbzrle_cache_resize(int64_t new_size)
 {
 +PageCache *new_cache, *old_cache;
 +
  if (new_size  TARGET_PAGE_SIZE) {
  return -1;
  }
 
  if (XBZRLE.cache != NULL) {
 -return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) *
 -TARGET_PAGE_SIZE;
 +if (pow2floor(new_size) == cache_max_num_items(XBZRLE.cache)
 +   *TARGET_PAGE_SIZE) {
 +goto ret;
 +}
 +new_cache = cache_init(new_size / TARGET_PAGE_SIZE,
 +  cache_page_size(XBZRLE.cache));

I wonder whether it's safe to even check the size of the XBZRLE.cache here;
it's a short race, but I think if you're unlucky and migration completes
between the NULL check and here then it would break.
Also 'migration_end' calls cache_fini, so it probably also needs to have
the lock around it.

 +if (!new_cache) {
 +DPRINTF(Error creating cache\n);
 +return -1;
 +}
 +XBZRLE_cache_lock();
 +old_cache = XBZRLE.cache;
 +XBZRLE.cache = new_cache;
 +XBZRLE_cache_unlock();
 +cache_fini(old_cache);
 +goto ret;
  }
 +ret:
  return pow2floor(new_size);
 }
 
 @@ -522,6 +552,8 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
  ret = ram_control_save_page(f, block-offset,
 offset, TARGET_PAGE_SIZE, bytes_sent);
 
 +XBZRLE_cache_lock();
 +
  if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
  if (ret != RAM_SAVE_CONTROL_DELAYED) {
  if (bytes_sent  0) {
 @@ -553,6 +585,8 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
  acct_info.norm_pages++;
  }
 
 +XBZRLE_cache_unlock();
 +
  /* if page is unmodified, continue to the next */
  if (bytes_sent  0) {
  last_sent_block = block;
 @@ -681,7 +715,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
  XBZRLE.encoded_buf = NULL;
  return -1;
  }
 -
 +qemu_mutex_init(XBZRLE.lock);
  acct_clear();
  }
 
 diff --git a/include/migration/page_cache.h b/include/migration/page_cache.h
 index d156f0d..6be0103 100644
 --- a/include/migration/page_cache.h
 +++ b/include/migration/page_cache.h
 @@ -79,4 +79,18 @@ int cache_insert(PageCache *cache, uint64_t addr, uint8_t 
 *pdata);
   */
 int64_t cache_resize(PageCache *cache, int64_t num_pages);
 
 +/**
 + * cache_max_num_items: return the cache max num items.
 + *
 + * @cache pointer to the PageCache struct
 + */
 +int64_t cache_max_num_items(PageCache *cache);
 +
 +/**
 + * cache_page_size: return the cache page size
 + *
 + * @cache pointer to the PageCache struct
 + */
 +unsigned int cache_page_size(PageCache *cache);
 +
 #endif
 diff --git a/page_cache.c b/page_cache.c
 index 3ef6ee7..92e401c 100644
 --- a/page_cache.c
 +++ b/page_cache.c
 @@ -234,3 +234,16 @@ int64_t cache_resize(PageCache *cache, int64_t 
 new_num_pages)
 
  return cache-max_num_items;
 }
 +
 +int64_t cache_max_num_items(PageCache *cache)
 +{
 +g_assert(cache);
 +return cache-max_num_items;
 +}
 +
 +unsigned int 

Re: [Qemu-devel] [PATCH v18 12/14] qapi: add HostMemPolicy enum type

2014-02-19 Thread Igor Mammedov
On Wed, 19 Feb 2014 15:54:03 +0800
Hu Tao hu...@cn.fujitsu.com wrote:

 From: Wanlong Gao gaowanl...@cn.fujitsu.com
 
 This new enum type will be used to set host memory policy of
 backend host memory.
perhaps squashing it into the next path would be better.

 
 Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
  qapi-schema.json | 20 
  1 file changed, 20 insertions(+)
 
 diff --git a/qapi-schema.json b/qapi-schema.json
 index 498ea9b..9d6370f 100644
 --- a/qapi-schema.json
 +++ b/qapi-schema.json
 @@ -4454,3 +4454,23 @@
 '*cpus':   ['uint16'],
 '*memdev': 'str',
 '*mem':'str' }}
 +
 +##
 +# @HostMemPolicy
 +#
 +# Host memory policy types
 +#
 +# @default: restore default policy, remove any nondefault policy
 +#
 +# @preferred: set the preferred host node for allocation
 +#
 +# @membind: a strict policy that restricts memory allocation to the
 +#   host nodes specified
 +#
 +# @interleave: the page allocations is interleaved across the set
 +#  of host nodes specified
 +#
 +# Since 2.0
 +##
 +{ 'enum': 'HostMemPolicy',
 +  'data': [ 'default', 'preferred', 'membind', 'interleave' ] }




Re: [Qemu-devel] [RFC PATCH v2 01/12] mc: add documentation for micro-checkpointing

2014-02-19 Thread Dr. David Alan Gilbert
* Michael R. Hines (mrhi...@linux.vnet.ibm.com) wrote:
 On 02/18/2014 08:45 PM, Dr. David Alan Gilbert wrote:
 +The Micro-Checkpointing Process
 +Basic Algorithm
 +Micro-Checkpoints (MC) work against the existing live migration path in 
 QEMU, and can effectively be understood as a live migration that never 
 ends. As such, iteration rounds happen at the granularity of 10s of 
 milliseconds and perform the following steps:
 +
 +1. After N milliseconds, stop the VM.
 +3. Generate a MC by invoking the live migration software path to identify 
 and copy dirty memory into a local staging area inside QEMU.
 +4. Resume the VM immediately so that it can make forward progress.
 +5. Transmit the checkpoint to the destination.
 +6. Repeat
 +Upon failure, load the contents of the last MC at the destination back 
 into memory and run the VM normally.
 Later you talk about the memory allocation and how you grow the memory as 
 needed
 to fit the checkpoint, have you tried going the other way and triggering the
 checkpoints sooner if they're taking too much memory?
 
 There is a 'knob' in this patch called mc-set-delay which was designed
 to solve exactly that problem. It allows policy or management software
 to make an independent decision about what the frequency of the
 checkpoints should be.
 
 I wasn't comfortable implementing policy directly inside the patch as
 that seemed less likely to get accepted by the community sooner.

I was just wondering if a separate 'max buffer size' knob would allow
you to more reasonably bound memory without setting policy; I don't think
people like having potentially x2 memory.

 +1. MC over TCP/IP: Once the socket connection breaks, we assume
 failure. This happens very early in the loss of the latest MC not only
 because a very large amount of bytes is typically being sequenced in a
 TCP stream but perhaps also because of the timeout in acknowledgement
 of the receipt of a commit message by the destination.
 +
 +2. MC over RDMA: Since Infiniband does not provide any underlying
 timeout mechanisms, this implementation enhances QEMU's RDMA migration
 protocol to include a simple keep-alive. Upon the loss of multiple
 keep-alive messages, the sender is deemed to have failed.
 +
 +In both cases, either due to a failed TCP socket connection or lost RDMA 
 keep-alive group, both the sender or the receiver can be deemed to have 
 failed.
 +
 +If the sender is deemed to have failed, the destination takes over 
 immediately using the contents of the last checkpoint.
 +
 +If the destination is deemed to be lost, we perform the same action
 as a live migration: resume the sender normally and wait for management
 software to make a policy decision about whether or not to re-protect
 the VM, which may involve a third-party to identify a new destination
 host again to use as a backup for the VM.
 In this world what is making the decision about whether the 
 sender/destination
 should win - how do you avoid a split brain situation where both
 VMs are running but the only thing that failed is the comms between them?
 Is there any guarantee that you'll have received knowledge of the comms
 failure before you pull the plug out and enable the corked packets to be
 sent on the sender side?
 
 Good question in general - I'll add it to the FAQ. The patch implements
 a basic 'transaction' mechanism in coordination with an outbound I/O
 buffer (documented further down). With these two things in
 places, split-brain is not possible because the destination is not running.
 We don't allow the destination to resume execution until a committed
 transaction has been acknowledged by the destination and only until
 then do we allow any outbound network traffic to be release to the
 outside world.

Yeh I see the IO buffer, what I've not figured out is how:
  1) MC over TCP/IP gets an acknowledge on the source to know when
 it can unplug it's buffer.
  2) Lets say the MC connection fails, so that ack never arrives,
 the source must assume the destination has failed and release it's
 packets and carry on.
 The destination must assume the source has failed and take over.

 Now they're both running - and that's bad and it's standard
 split brain.
  3) If we're relying on TCP/IP timeout that's quite long.

 +RDMA is used for two different reasons:
 +
 +1. Checkpoint generation (RDMA-based memcpy):
 +2. Checkpoint transmission
 +Checkpoint generation must be done while the VM is paused. In the
 worst case, the size of the checkpoint can be equal in size to the amount
 of memory in total use by the VM. In order to resume VM execution as
 fast as possible, the checkpoint is copied consistently locally into
 a staging area before transmission. A standard memcpy() of potentially
 such a large amount of memory not only gets no use out of the CPU cache
 but also potentially clogs up the CPU pipeline which would otherwise
 be useful by other neighbor VMs on the same physical node that could be
 

Re: [Qemu-devel] [PATCH] qxl: add sanity check

2014-02-19 Thread Laszlo Ersek
On 02/19/14 11:40, Gerd Hoffmann wrote:
 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  hw/display/qxl.c | 8 +++-
  1 file changed, 7 insertions(+), 1 deletion(-)
 
 diff --git a/hw/display/qxl.c b/hw/display/qxl.c
 index 1471cc0..2a559eb 100644
 --- a/hw/display/qxl.c
 +++ b/hw/display/qxl.c
 @@ -1429,7 +1429,7 @@ static int qxl_destroy_primary(PCIQXLDevice *d, 
 qxl_async_io async)
  return 1;
  }
  
 -static void qxl_set_mode(PCIQXLDevice *d, int modenr, int loadvm)
 +static void qxl_set_mode(PCIQXLDevice *d, unsigned int modenr, int loadvm)
  {
  pcibus_t start = d-pci.io_regions[QXL_RAM_RANGE_INDEX].addr;
  pcibus_t end   = d-pci.io_regions[QXL_RAM_RANGE_INDEX].size + start;
 @@ -1439,6 +1439,12 @@ static void qxl_set_mode(PCIQXLDevice *d, int modenr, 
 int loadvm)
  .mem_start = start,
  .mem_end = end
  };
 +
 +if (modenr = d-modes-n_modes) {
 +qxl_set_guest_bug(d, mode number out of range);
 +return;
 +}
 +
  QXLSurfaceCreate surface = {
  .width  = mode-x_res,
  .height = mode-y_res,
 

Well, if I want to obsess about standards conformance, this is too late,
because the initialization of the mode pointer a bit higher up:

QXLMode *mode = d-modes-modes + modenr;

already invokes undefined behavior, when modenr is out of range.

In practice, meh -- the check is done early enough to prevent
dereferencing the (already undefined) pointer.

I also guess gcc is *not* smart enough to derive the undefined-ness as
soon as we do the wrong initialization. (Because if it were smart enough
to see that, then it would compile the check you're adding into
constant false.)

Also, isn't this CVE material?...

Reviewed-by: Laszlo Ersek ler...@redhat.com




Re: [Qemu-devel] Buildbot failure: MinGW

2014-02-19 Thread Peter Maydell
On 19 February 2014 04:27, Stefan Weil s...@weilnetz.de wrote:
 Hi Gerd, hi Stefan,

 we now need a C++ compiler on the buildbots. Currently, it's missing for
 MinGW:

 /bin/sh: i686-pc-mingw32-g++: command not found

Don't we successfully fall back to don't build C++ things if
configure doesn't detect the C++ compiler?

thanks
-- PMM



Re: [Qemu-devel] [PULL 00/20] acpi,pc,pci fixes and enhancements

2014-02-19 Thread Stefano Stabellini
On Wed, 19 Feb 2014, Michael S. Tsirkin wrote:
 On Wed, Feb 19, 2014 at 11:08:25AM +0200, Michael S. Tsirkin wrote:
  On Tue, Feb 18, 2014 at 05:10:00PM +, Stefano Stabellini wrote:
   On Tue, 18 Feb 2014, Paolo Bonzini wrote:
Il 18/02/2014 15:25, Stefano Stabellini ha scritto:
 On Tue, 18 Feb 2014, Paolo Bonzini wrote:
  Il 18/02/2014 13:45, Stefano Stabellini ha scritto:
   Disk unplug: hw/ide/piix.c:pci_piix3_xen_ide_unplug (see the 
   beginning
   of the email :-P).
   It is called by 
   hw/xen/xen_platform.c:platform_fixed_ioport_writew, in
   response to the guest writing to a magic ioport specifically to 
   unplug
   the emulated disk.
   With this patch after the guest boots I can still access both 
   xvda and
   sda for the same disk, leading to fs corruptions.
  
  Ok, the last paragraph is what I was missing.
  
  So this is dc-unplug for the PIIX3 IDE device.  Because PCI 
  declares a
  hotplug handler, dc-unplug is not called anymore.
  
  But unlike other dc-unplug callbacks, pci_piix3_xen_ide_unplug 
  doesn't
  free
  the device, it just drops the disks underneath.  I think the 
  simplest
  solution
  is to _not_ make it a dc-unplug callback at all, and call
  pci_piix3_xen_ide_unplug from unplug_disks instead of qdev_unplug.
  qdev_unplug means ask guest to start unplug, which is not what 
  Xen wants
  to
  do here.
 
 Yes, you are right, pci_piix3_xen_ide_unplug is not called anymore.
 Calling it directly from unplug_disks fixes the issue:
 
 
 ---
 
 Call pci_piix3_xen_ide_unplug from unplug_disks
 
 Signed-off-by: Stefano Stabellini stefano.stabell...@eu.citrix.com
 
 diff --git a/hw/ide/piix.c b/hw/ide/piix.c
 index 0eda301..40757eb 100644
 --- a/hw/ide/piix.c
 +++ b/hw/ide/piix.c
 @@ -167,7 +167,7 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
  return 0;
  }
 
 -static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 +int pci_piix3_xen_ide_unplug(DeviceState *dev)
  {
  PCIIDEState *pci_ide;
  DriveInfo *di;
 @@ -266,7 +266,6 @@ static void piix3_ide_xen_class_init(ObjectClass 
 *klass,
 void *data)
  k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
  k-class_id = PCI_CLASS_STORAGE_IDE;
  set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
 -dc-unplug = pci_piix3_xen_ide_unplug;
  }
 
  static const TypeInfo piix3_ide_xen_info = {
 diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c
 index 70875e4..1d9d0e9 100644
 --- a/hw/xen/xen_platform.c
 +++ b/hw/xen/xen_platform.c
 @@ -27,6 +27,7 @@
 
  #include hw/hw.h
  #include hw/i386/pc.h
 +#include hw/ide.h
  #include hw/pci/pci.h
  #include hw/irq.h
  #include hw/xen/xen_common.h
 @@ -110,7 +111,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, 
 void
 *o)
  if (pci_get_word(d-config + PCI_CLASS_DEVICE) ==
  PCI_CLASS_STORAGE_IDE
   strcmp(d-name, xen-pci-passthrough) != 0) {
 -qdev_unplug(DEVICE(d), NULL);
 +pci_piix3_xen_ide_unplug(DEVICE(d));
  }
  }
 
 diff --git a/include/hw/ide.h b/include/hw/ide.h
 index 507e6d3..bc8bd32 100644
 --- a/include/hw/ide.h
 +++ b/include/hw/ide.h
 @@ -17,6 +17,7 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo
 **hd_table,
  PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, 
 int
 devfn);
  PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int
 devfn);
  PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int
 devfn);
 +int pci_piix3_xen_ide_unplug(DeviceState *dev);
  void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int 
 devfn);
 
  /* ide-mmio.c */
 

Acked-by: Paolo Bonzini pbonz...@redhat.com
   
   Thanks. Should I send it to Peter via the xen tree or anybody else wants
   to pick this up?
  
  I'll rebase my tree on top of this, to avoid bisect failures.
 
 Oh sorry, I noticed what broke this is - is merged already.
 Pls merge fix through xen tree then, makes more sense.

All right, thanks.



Re: [Qemu-devel] [PATCH v18 10/14] numa: add -numa node, memdev= option

2014-02-19 Thread Paolo Bonzini

Il 19/02/2014 10:50, Igor Mammedov ha scritto:

 +numa_info[nodenr].node_mem = object_property_get_int(o, size, 
NULL);
 +numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);

if you make numa_info  QOM object node_memdev link property,
then above hunk could be replaced with just setting link.
And node_mem could be replaced with readonly property that reads size
directly from memdev avoiding data duplication.

As side-effect it numa_info will also become accessible for introspection
using QOM interface. Something like:
 qom-list /machine/memory-node[X]
 qom-get /machine/memory-node[X]/memory_size


I agree, but I think we can do it on top.

Paolo




Re: [Qemu-devel] Buildbot failure: MinGW

2014-02-19 Thread Thomas Huth
On Wed, 19 Feb 2014 11:53:09 +
Peter Maydell peter.mayd...@linaro.org wrote:

 On 19 February 2014 04:27, Stefan Weil s...@weilnetz.de wrote:
  Hi Gerd, hi Stefan,
 
  we now need a C++ compiler on the buildbots. Currently, it's missing for
  MinGW:
 
  /bin/sh: i686-pc-mingw32-g++: command not found
 
 Don't we successfully fall back to don't build C++ things if
 configure doesn't detect the C++ compiler?

I recently had a similar problem compiling QEMU on a freshly installed
system, where I only had a normal C compiler, but no C++ installed yet.

In rules.mak, you can find these lines:

 # If we have a CXX we might have some C++ objects, in which case we
 # must link with the C++ compiler, not the plain C compiler.
 LINKPROG = $(or $(CXX),$(CC))

So that's ok, it sets LINKPROG to the c++ compiler if the variable is
set, and to the C compiler if not.

But now have a look at the configure script:

 if test -z ${CXX}${cross_prefix}; then
   cxx=c++
 else
   cxx=${CXX-${cross_prefix}g++}
 fi

 [...]

 echo CXX=$cxx  $config_host_mak

That seems to always set the CXX variable! I think the above
if-statement is wrong, it should set cxx only if the c++ program is
really available.

 Thomas




Re: [Qemu-devel] [Qemu-ppc] qemu for aix

2014-02-19 Thread Andreas Färber
Hello,

Am 18.02.2014 06:00, schrieb sh.hu...@venusource.com:
 
 hello guys
 
 is somebody install qemu on AIX? is qemu can install on AIX?

It's supposed to install, but I don't personally have an AIX
installation to test whether there are any issues. Have you tried?

Regards,
Andreas

P.S. Best post such questions to or at least CC qemu-devel.

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCHv3 0/2] sun4m: Implement Sun CG3 framebuffer for QEMU

2014-02-19 Thread Andreas Färber
Am 19.02.2014 10:05, schrieb Mark Cave-Ayland:
 This patchset provides QEMU with an implementation of the Sun CG3 8-bit
 framebuffer. It is based upon Bob Breuer's original work which has been
 rebased onto git master, and is now capable of running with an OpenBIOS CG3 
 FCode ROM instead of requiring copies of proprietary Sun ROMs.
 
 The motivation behind this patch is that older operating systems such as
 Debian Woody and Solaris (running OpenWindows) do not contain drivers for the
 TCX framebuffer and as a result currently cannot run in graphical mode. The
 screenshots linked below show qemu-system-sparc successfully running both 
 Debian Woody and the Solaris 8 installer in graphical mode during testing:
 
 http://www.ilande.co.uk/tmp/debian-woody.png
 http://www.ilande.co.uk/tmp/sol8-1.png
 http://www.ilande.co.uk/tmp/sol8-2.png
 
 The CG3 framebuffer is selected by passing -vga cg3 on the command line to
 qemu-system-sparc. If either -vga tcx is specified (or the -vga argument is
 omitted) then qemu-system-sparc defaults to using the existing TCX
 framebuffer to maintain compatibility.
 
 v3:
 - Rebased to git master
 - Fix DEBUG_CG3 macro
 - Use register constants based upon Linux/BSD drivers
 - Use qemu_log(LOG_UNIMP ... ) to capture unrecognised register accesses
 - Rename device type from SUNW,cgthree to cgthree (matches OBP)
 - Use error_report() instead of fprintf(stderr ... )
 - Convert from init to realizefn
 
 v2:
 - Rebased to git master
 - Updated QEMU,cgthree.bin ROM to latest OpenBIOS version
 - Added Peter Maydell to CC
 
 
 Mark Cave-Ayland (2):
   sun4m: Add Sun CG3 framebuffer and corresponding OpenBIOS FCode ROM
   sun4m: Add Sun CG3 framebuffer initialisation function

Reviewed-by: Andreas Färber afaer...@suse.de

There's some lines we could extract from the realizefn into an
instance_init, but can be done as follow-up when needed.

Two small questions, are vram_size and prom_addr for compatibility? New
convention for QOM properties would be dashes.

Regards,
Andreas

 
  Makefile  |2 +-
  default-configs/sparc-softmmu.mak |1 +
  hw/display/Makefile.objs  |1 +
  hw/display/cg3.c  |  384 
 +
  hw/sparc/sun4m.c  |   62 +-
  include/sysemu/sysemu.h   |1 +
  pc-bios/QEMU,cgthree.bin  |  Bin 0 - 850 bytes
  pc-bios/README|4 +-
  vl.c  |   24 +++
  9 files changed, 473 insertions(+), 6 deletions(-)
  create mode 100644 hw/display/cg3.c
  create mode 100644 pc-bios/QEMU,cgthree.bin
 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] Buildbot failure: MinGW

2014-02-19 Thread Peter Maydell
On 19 February 2014 12:18, Thomas Huth th...@linux.vnet.ibm.com wrote:
 I recently had a similar problem compiling QEMU on a freshly installed
 system, where I only had a normal C compiler, but no C++ installed yet.

 In rules.mak, you can find these lines:

  # If we have a CXX we might have some C++ objects, in which case we
  # must link with the C++ compiler, not the plain C compiler.
  LINKPROG = $(or $(CXX),$(CC))

 So that's ok, it sets LINKPROG to the c++ compiler if the variable is
 set, and to the C compiler if not.

 But now have a look at the configure script:

  if test -z ${CXX}${cross_prefix}; then
cxx=c++
  else
cxx=${CXX-${cross_prefix}g++}
  fi

  [...]

  echo CXX=$cxx  $config_host_mak

 That seems to always set the CXX variable! I think the above
 if-statement is wrong, it should set cxx only if the c++ program is
 really available.

Yes, you're right. Certainly my intention with the vixl changes
was to only build with C++ if a C++ compiler was present; I
must have misread this bit of configure. I'll put together a patch.

thanks
-- PMM



Re: [Qemu-devel] [PATCHv3 1/2] sun4m: Add Sun CG3 framebuffer and corresponding OpenBIOS FCode ROM

2014-02-19 Thread Leandro Dorileo
Hi Mark,

On Wed, Feb 19, 2014 at 09:05:19AM +, Mark Cave-Ayland wrote:
 The CG3 framebuffer is a simple 8-bit framebuffer for use with operating
 systems such as early Solaris that do not have drivers for TCX.
 
 Signed-off-by: Mark Cave-Ayland mark.cave-ayl...@ilande.co.uk
 CC: Blue Swirl blauwir...@gmail.com
 CC: Anthony Liguori aligu...@amazon.com
 CC: Peter Maydell peter.mayd...@linaro.org
 CC: Bob Breuer breu...@mc.net
 CC: Artyom Tarasenko atar4q...@gmail.com
 ---
  Makefile  |2 +-
  default-configs/sparc-softmmu.mak |1 +
  hw/display/Makefile.objs  |1 +
  hw/display/cg3.c  |  384 
 +
  pc-bios/QEMU,cgthree.bin  |  Bin 0 - 850 bytes
  pc-bios/README|4 +-
  6 files changed, 389 insertions(+), 3 deletions(-)
  create mode 100644 hw/display/cg3.c
  create mode 100644 pc-bios/QEMU,cgthree.bin
 
 diff --git a/Makefile b/Makefile
 index 807054b..c3c7ccc 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -293,7 +293,7 @@ ifdef INSTALL_BLOBS
  BLOBS=bios.bin bios-256k.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
  vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin \
  acpi-dsdt.aml q35-acpi-dsdt.aml \
 -ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin \
 +ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin 
 QEMU,cgthree.bin \
  pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
  pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \
  efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \
 diff --git a/default-configs/sparc-softmmu.mak 
 b/default-configs/sparc-softmmu.mak
 index 8fc93dd..ab796b3 100644
 --- a/default-configs/sparc-softmmu.mak
 +++ b/default-configs/sparc-softmmu.mak
 @@ -10,6 +10,7 @@ CONFIG_EMPTY_SLOT=y
  CONFIG_PCNET_COMMON=y
  CONFIG_LANCE=y
  CONFIG_TCX=y
 +CONFIG_CG3=y
  CONFIG_SLAVIO=y
  CONFIG_CS4231=y
  CONFIG_GRLIB=y
 diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
 index 540df82..7ed76a9 100644
 --- a/hw/display/Makefile.objs
 +++ b/hw/display/Makefile.objs
 @@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP) += omap_lcdc.o
  obj-$(CONFIG_PXA2XX) += pxa2xx_lcd.o
  obj-$(CONFIG_SM501) += sm501.o
  obj-$(CONFIG_TCX) += tcx.o
 +obj-$(CONFIG_CG3) += cg3.o
  
  obj-$(CONFIG_VGA) += vga.o
  
 diff --git a/hw/display/cg3.c b/hw/display/cg3.c
 new file mode 100644
 index 000..b6bc0c2
 --- /dev/null
 +++ b/hw/display/cg3.c
 @@ -0,0 +1,384 @@
 +/*
 + * QEMU CG3 Frame buffer
 + *
 + * Copyright (c) 2012 Bob Breuer
 + * Copyright (c) 2013 Mark Cave-Ayland
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a 
 copy
 + * of this software and associated documentation files (the Software), to 
 deal
 + * in the Software without restriction, including without limitation the 
 rights
 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 + * copies of the Software, and to permit persons to whom the Software is
 + * furnished to do so, subject to the following conditions:
 + *
 + * The above copyright notice and this permission notice shall be included in
 + * all copies or substantial portions of the Software.
 + *
 + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 FROM,
 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 + * THE SOFTWARE.
 + */
 +
 +#include qemu-common.h
 +#include qemu/error-report.h
 +#include ui/console.h
 +#include hw/sysbus.h
 +#include hw/loader.h
 +
 +/* Change to 1 to enable debugging */
 +#define DEBUG_CG3 0
 +
 +#define CG3_ROM_FILE  QEMU,cgthree.bin
 +#define FCODE_MAX_ROM_SIZE 0x1
 +
 +#define CG3_REG_SIZE0x20
 +
 +#define CG3_REG_BT458_ADDR  0x0
 +#define CG3_REG_BT458_COLMAP0x4
 +#define CG3_REG_FBC_CTRL0x10
 +#define CG3_REG_FBC_STATUS  0x11
 +#define CG3_REG_FBC_CURSTART0x12
 +#define CG3_REG_FBC_CUREND  0x13
 +#define CG3_REG_FBC_VCTRL   0x14
 +
 +/* Control register flags */
 +#define CG3_CR_ENABLE_INTS  0x80
 +
 +/* Status register flags */
 +#define CG3_SR_PENDING_INT  0x80
 +#define CG3_SR_1152_900_76_B0x60
 +#define CG3_SR_ID_COLOR 0x01
 +
 +#define CG3_VRAM_SIZE 0x10
 +#define CG3_VRAM_OFFSET 0x80
 +
 +#define DPRINTF(fmt, ...) do { \
 +if (DEBUG_CG3) { \
 +printf(CG3:  fmt , ## __VA_ARGS__); \
 +} \
 +} while (0);
 +
 +#define TYPE_CG3 cgthree
 +#define CG3(obj) OBJECT_CHECK(CG3State, (obj), TYPE_CG3)
 +
 +typedef struct CG3State {
 +SysBusDevice parent_obj;
 +
 +QemuConsole *con;
 +qemu_irq irq;
 +hwaddr prom_addr;
 +MemoryRegion vram_mem;
 +MemoryRegion rom;
 

Re: [Qemu-devel] [PATCH 4/4] trace: [tracetool] Minimize the amount of per-backend code

2014-02-19 Thread Stefan Hajnoczi
On Mon, Feb 17, 2014 at 08:36:41PM +0100, Lluís Vilanova wrote:
 Backends now only contain the essential backend-specific code, and most of 
 the work is moved to frontend code.
 
 Signed-off-by: Lluís Vilanova vilan...@ac.upc.edu
 ---
  scripts/simpletrace.py|6 --
  scripts/tracetool/__init__.py |   24 ++
  scripts/tracetool/backend/__init__.py |   72 --
  scripts/tracetool/backend/dtrace.py   |   79 ++--
  scripts/tracetool/backend/events.py   |   23 --
  scripts/tracetool/backend/ftrace.py   |   56 ++
  scripts/tracetool/backend/simple.py   |  130 
 -
  scripts/tracetool/backend/stderr.py   |   42 ---
  scripts/tracetool/backend/ust.py  |   44 +--
  scripts/tracetool/format/__init__.py  |   46 
  scripts/tracetool/format/c.py |9 ++
  scripts/tracetool/format/d.py |   23 +-
  scripts/tracetool/format/events_c.py  |   11 +--
  scripts/tracetool/format/events_h.py  |   11 +--
  scripts/tracetool/format/h.py |   24 --
  scripts/tracetool/format/stap.py  |   37 +
  trace/Makefile.objs   |4 +
  17 files changed, 274 insertions(+), 367 deletions(-)
  delete mode 100644 scripts/tracetool/backend/events.py

Please split the coding style changes into a separate commit (e.g.
removing trailing commas).

 diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
 index 8bbcb42..03d032e 100755
 --- a/scripts/simpletrace.py
 +++ b/scripts/simpletrace.py
 @@ -109,14 +109,10 @@ def process(events, log, analyzer):
  if isinstance(log, str):
  log = open(log, 'rb')
  
 -enabled_events = []
  dropped_event = Event.build(Dropped_Event(uint64_t num_events_dropped))
  edict = {dropped_event_id: dropped_event}
  
 -for e in events:
 -if 'disable' not in e.properties:
 -enabled_events.append(e)
 -for num, event in enumerate(enabled_events):
 +for num, event in enumerate(events):
  edict[num] = event
  
  def build_fn(analyzer, event):

This patch breaks existing simpletrace files.  Imagine you are
developing code and use simpletrace.  Then you decide to rebase onto the
latest qemu.git/master.  This patch changes the semantics - now
simpletrace.py outputs junk when analyzing the existing file.

We can't break the file format for convenience.  Either bump the file
format version number or don't change the semantics.



[Qemu-devel] [PATCH v14 00/14] Drop in_use from BlockDriverState and enable point-in-time snapshot exporting over NBD

2014-02-19 Thread Fam Zheng
This series adds for point-in-time snapshot NBD exporting based on
blockdev-backup (variant of drive-backup with existing device as target).

We get a thin point-in-time snapshot by COW mechanism of drive-backup, and
export it through built in NBD server. The steps are as below:

 1. (SHELL) qemu-img create -f qcow2 BACKUP.qcow2 source size here

(Alternatively we can use -o backing_file=RUNNING-VM.img to omit explicitly
providing the size by ourselves, but it's risky because RUNNING-VM.qcow2 is
used r/w by guest. Whether or not setting backing file in the image file
doesn't matter, as we are going to override the backing hd in the next
step)

 2. (QMP) blockdev-add backing=source-drive file.driver=file 
file.filename=BACKUP.qcow2 id=target0 if=none driver=qcow2

(where source-drive is the running BlockDriverState name for
RUNNING-VM.img. This patch implements backing= option to override
backing_hd for added drive)

 3. (QMP) blockdev-backup device=source-drive sync=none target=target0

(this is the QMP command introduced by this series, which use a named
device as target of drive-backup)

 4. (QMP) nbd-server-add device=target0

When image fleecing done:

 1. (QMP) block-job-cancel device=source-drive

 2. (HMP) drive_del target0

 3. (SHELL) rm BACKUP.qcow2

v14: Address Benoit's comments and rebase to kevin's block tree:

02: Explicit initialize op_blockers with QLIST_INIT.
05: Fix sizeof(bs-backing_format) passed to pstrcpy().


Fam Zheng (14):
  block: Add BlockOpType enum
  block: Introduce op_blockers to BlockDriverState
  block: Replace in_use with operation blocker
  block: Move op_blocker check from block_job_create to its caller
  block: Add bdrv_set_backing_hd()
  block: Add backing_blocker in BlockDriverState
  block: Parse backing option to reference existing BDS
  block: Support dropping active in bdrv_drop_intermediate
  stream: Use bdrv_drop_intermediate and drop close_unused_images
  qmp: Add command 'blockdev-backup'
  block: Allow backup on referenced named BlockDriverState
  block: Add blockdev-backup to transaction
  qemu-iotests: Test blockdev-backup in 055
  qemu-iotests: Image fleecing test case 081

 block-migration.c   |   7 +-
 block.c | 310 +++-
 block/backup.c  |  26 
 block/commit.c  |   1 +
 block/stream.c  |  30 +---
 blockdev.c  | 118 +--
 blockjob.c  |  14 +-
 hw/block/dataplane/virtio-blk.c |  19 ++-
 include/block/block.h   |  29 +++-
 include/block/block_int.h   |   9 +-
 include/block/blockjob.h|   3 +
 qapi-schema.json|  50 +++
 qmp-commands.hx |  44 ++
 tests/qemu-iotests/055  | 275 +--
 tests/qemu-iotests/055.out  |   4 +-
 tests/qemu-iotests/081  |  99 +
 tests/qemu-iotests/081.out  |   5 +
 tests/qemu-iotests/group|   1 +
 18 files changed, 842 insertions(+), 202 deletions(-)
 create mode 100755 tests/qemu-iotests/081
 create mode 100644 tests/qemu-iotests/081.out

-- 
1.8.5.4




[Qemu-devel] [PATCH v14 04/14] block: Move op_blocker check from block_job_create to its caller

2014-02-19 Thread Fam Zheng
It makes no sense to check for any blocker on bs, we are here only
because of the mechanical conversion from in_use to op_blockers. Remove
it now, and let the callers check specific operation types. Backup and
mirror already have it, add checker to stream and commit.

Signed-off-by: Fam Zheng f...@redhat.com
---
 blockdev.c | 8 
 blockjob.c | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index 53dce70..306aad5 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1840,6 +1840,10 @@ void qmp_block_stream(const char *device, bool has_base,
 return;
 }
 
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_STREAM, errp)) {
+return;
+}
+
 if (base) {
 base_bs = bdrv_find_backing_image(bs, base);
 if (base_bs == NULL) {
@@ -1880,6 +1884,10 @@ void qmp_block_commit(const char *device,
 return;
 }
 
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT, errp)) {
+return;
+}
+
 /* default top_bs is the active layer */
 top_bs = bs;
 
diff --git a/blockjob.c b/blockjob.c
index f1ff036..21e21c0 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -41,7 +41,7 @@ void *block_job_create(const BlockJobDriver *driver, 
BlockDriverState *bs,
 {
 BlockJob *job;
 
-if (bs-job || !bdrv_op_blocker_is_empty(bs)) {
+if (bs-job) {
 error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
 return NULL;
 }
-- 
1.8.5.4




[Qemu-devel] [PATCH v14 01/14] block: Add BlockOpType enum

2014-02-19 Thread Fam Zheng
This adds the enum of all the operations that can be taken on a block
device.

Signed-off-by: Fam Zheng f...@redhat.com
---
 include/block/block.h | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/include/block/block.h b/include/block/block.h
index 780f48b..8820735 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -154,6 +154,25 @@ typedef struct BDRVReopenState {
 void *opaque;
 } BDRVReopenState;
 
+/*
+ * Block operation types
+ */
+typedef enum BlockOpType {
+BLOCK_OP_TYPE_BACKUP_SOURCE,
+BLOCK_OP_TYPE_BACKUP_TARGET,
+BLOCK_OP_TYPE_CHANGE,
+BLOCK_OP_TYPE_COMMIT,
+BLOCK_OP_TYPE_DATAPLANE,
+BLOCK_OP_TYPE_DRIVE_DEL,
+BLOCK_OP_TYPE_EJECT,
+BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT,
+BLOCK_OP_TYPE_INTERNAL_SNAPSHOT,
+BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE,
+BLOCK_OP_TYPE_MIRROR,
+BLOCK_OP_TYPE_RESIZE,
+BLOCK_OP_TYPE_STREAM,
+BLOCK_OP_TYPE_MAX,
+} BlockOpType;
 
 void bdrv_iostatus_enable(BlockDriverState *bs);
 void bdrv_iostatus_reset(BlockDriverState *bs);
-- 
1.8.5.4




[Qemu-devel] [PATCH v14 10/14] qmp: Add command 'blockdev-backup'

2014-02-19 Thread Fam Zheng
Similar to drive-backup, but this command uses a device id as target
instead of creating/opening an image file.

Also add blocker on target bs, since the target is also a named device
now.

Add check and report error for bs == target which became possible but is
an illegal case with introduction of blockdev-backup.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/backup.c   | 26 ++
 blockdev.c   | 47 +++
 qapi-schema.json | 49 +
 qmp-commands.hx  | 44 
 4 files changed, 166 insertions(+)

diff --git a/block/backup.c b/block/backup.c
index 15a2e55..ea46340 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -344,6 +344,7 @@ static void coroutine_fn backup_run(void *opaque)
 hbitmap_free(job-bitmap);
 
 bdrv_iostatus_disable(target);
+bdrv_op_unblock_all(target, job-common.blocker);
 bdrv_unref(target);
 
 block_job_completed(job-common, ret);
@@ -362,6 +363,11 @@ void backup_start(BlockDriverState *bs, BlockDriverState 
*target,
 assert(target);
 assert(cb);
 
+if (bs == target) {
+error_setg(errp, Source and target cannot be the same);
+return;
+}
+
 if ((on_source_error == BLOCKDEV_ON_ERROR_STOP ||
  on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) 
 !bdrv_iostatus_is_enabled(bs)) {
@@ -369,6 +375,24 @@ void backup_start(BlockDriverState *bs, BlockDriverState 
*target,
 return;
 }
 
+if (!bdrv_is_inserted(bs)) {
+error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, bs-device_name);
+return;
+}
+
+if (!bdrv_is_inserted(target)) {
+error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, target-device_name);
+return;
+}
+
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
+return;
+}
+
+if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) {
+return;
+}
+
 len = bdrv_getlength(bs);
 if (len  0) {
 error_setg_errno(errp, -len, unable to get length for '%s',
@@ -382,6 +406,8 @@ void backup_start(BlockDriverState *bs, BlockDriverState 
*target,
 return;
 }
 
+bdrv_op_block_all(target, job-common.blocker);
+
 job-on_source_error = on_source_error;
 job-on_target_error = on_target_error;
 job-target = target;
diff --git a/blockdev.c b/blockdev.c
index 306aad5..890cfea 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1963,6 +1963,8 @@ void qmp_drive_backup(const char *device, const char 
*target,
 return;
 }
 
+/* Although backup_run has this check too, we need to use bs-drv below, so
+ * do an early check redundantly. */
 if (!bdrv_is_inserted(bs)) {
 error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
 return;
@@ -1979,6 +1981,7 @@ void qmp_drive_backup(const char *device, const char 
*target,
 }
 }
 
+/* Early check to avoid creating target */
 if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
 return;
 }
@@ -2041,6 +2044,50 @@ BlockDeviceInfoList *qmp_query_named_block_nodes(Error 
**errp)
 return bdrv_named_nodes_list();
 }
 
+void qmp_blockdev_backup(const char *device, const char *target,
+ enum MirrorSyncMode sync,
+ bool has_speed, int64_t speed,
+ bool has_on_source_error,
+ BlockdevOnError on_source_error,
+ bool has_on_target_error,
+ BlockdevOnError on_target_error,
+ Error **errp)
+{
+BlockDriverState *bs;
+BlockDriverState *target_bs;
+Error *local_err = NULL;
+
+if (!has_speed) {
+speed = 0;
+}
+if (!has_on_source_error) {
+on_source_error = BLOCKDEV_ON_ERROR_REPORT;
+}
+if (!has_on_target_error) {
+on_target_error = BLOCKDEV_ON_ERROR_REPORT;
+}
+
+bs = bdrv_find(device);
+if (!bs) {
+error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+return;
+}
+
+target_bs = bdrv_find(target);
+if (!target_bs) {
+error_set(errp, QERR_DEVICE_NOT_FOUND, target);
+return;
+}
+
+bdrv_ref(target_bs);
+backup_start(bs, target_bs, speed, sync, on_source_error, on_target_error,
+ block_job_cb, bs, local_err);
+if (local_err != NULL) {
+bdrv_unref(target_bs);
+error_propagate(errp, local_err);
+}
+}
+
 #define DEFAULT_MIRROR_BUF_SIZE   (10  20)
 
 void qmp_drive_mirror(const char *device, const char *target,
diff --git a/qapi-schema.json b/qapi-schema.json
index 7cfb5e5..7b0be86 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1840,6 +1840,40 @@
 '*on-target-error': 'BlockdevOnError' } }
 
 ##
+# @BlockdevBackup
+#
+# @device: the name of the device which should be copied.
+#
+# @target: the name of the backup target 

[Qemu-devel] [PATCH v14 02/14] block: Introduce op_blockers to BlockDriverState

2014-02-19 Thread Fam Zheng
BlockDriverState.op_blockers is an array of lists with BLOCK_OP_TYPE_MAX
elements. Each list is a list of blockers of an operation type
(BlockOpType), that marks this BDS as currently blocked for a certain
type of operation with reason errors stored in the list. The rule of
usage is:

 * BDS user who wants to take an operation should check if there's any
   blocker of the type with bdrv_op_is_blocked().

 * BDS user who wants to block certain types of operation, should call
   bdrv_op_block (or bdrv_op_block_all to block all types of operations,
   which is similar to the existing bdrv_set_in_use()).

 * A blocker is only referenced by op_blockers, so the lifecycle is
   managed by caller, and shouldn't be lost until unblock, so typically
   a caller does these:

   - Allocate a blocker with error_setg or similar, call bdrv_op_block()
 to block some operations.
   - Hold the blocker, do his job.
   - Unblock operations that it blocked, with the same reason pointer
 passed to bdrv_op_unblock().
   - Release the blocker with error_free().

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c   | 75 +++
 include/block/block.h |  7 +
 include/block/block_int.h |  5 
 3 files changed, 87 insertions(+)

diff --git a/block.c b/block.c
index 80310fe..485d4f0 100644
--- a/block.c
+++ b/block.c
@@ -335,6 +335,7 @@ void bdrv_register(BlockDriver *bdrv)
 BlockDriverState *bdrv_new(const char *device_name)
 {
 BlockDriverState *bs;
+int i;
 
 bs = g_malloc0(sizeof(BlockDriverState));
 QLIST_INIT(bs-dirty_bitmaps);
@@ -342,6 +343,9 @@ BlockDriverState *bdrv_new(const char *device_name)
 if (device_name[0] != '\0') {
 QTAILQ_INSERT_TAIL(bdrv_states, bs, device_list);
 }
+for (i = 0; i  BLOCK_OP_TYPE_MAX; i++) {
+QLIST_INIT(bs-op_blockers[i]);
+}
 bdrv_iostatus_disable(bs);
 notifier_list_init(bs-close_notifiers);
 notifier_with_return_list_init(bs-before_write_notifiers);
@@ -1851,6 +1855,8 @@ static void bdrv_move_feature_fields(BlockDriverState 
*bs_dest,
  * We do want to swap name but don't want to swap linked list entries
  */
 bs_dest-node_list   = bs_src-node_list;
+memcpy(bs_dest-op_blockers, bs_src-op_blockers,
+   sizeof(bs_dest-op_blockers));
 }
 
 /*
@@ -5130,6 +5136,75 @@ void bdrv_unref(BlockDriverState *bs)
 }
 }
 
+struct BdrvOpBlocker {
+Error *reason;
+QLIST_ENTRY(BdrvOpBlocker) list;
+};
+
+bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp)
+{
+BdrvOpBlocker *blocker;
+assert((int) op = 0  op  BLOCK_OP_TYPE_MAX);
+if (!QLIST_EMPTY(bs-op_blockers[op])) {
+blocker = QLIST_FIRST(bs-op_blockers[op]);
+if (errp) {
+*errp = error_copy(blocker-reason);
+}
+return true;
+}
+return false;
+}
+
+void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason)
+{
+BdrvOpBlocker *blocker;
+assert((int) op = 0  op  BLOCK_OP_TYPE_MAX);
+
+blocker = g_malloc0(sizeof(BdrvOpBlocker));
+blocker-reason = reason;
+QLIST_INSERT_HEAD(bs-op_blockers[op], blocker, list);
+}
+
+void bdrv_op_unblock(BlockDriverState *bs, BlockOpType op, Error *reason)
+{
+BdrvOpBlocker *blocker, *next;
+assert((int) op = 0  op  BLOCK_OP_TYPE_MAX);
+QLIST_FOREACH_SAFE(blocker, bs-op_blockers[op], list, next) {
+if (blocker-reason == reason) {
+QLIST_REMOVE(blocker, list);
+g_free(blocker);
+}
+}
+}
+
+void bdrv_op_block_all(BlockDriverState *bs, Error *reason)
+{
+int i;
+for (i = 0; i  BLOCK_OP_TYPE_MAX; i++) {
+bdrv_op_block(bs, i, reason);
+}
+}
+
+void bdrv_op_unblock_all(BlockDriverState *bs, Error *reason)
+{
+int i;
+for (i = 0; i  BLOCK_OP_TYPE_MAX; i++) {
+bdrv_op_unblock(bs, i, reason);
+}
+}
+
+bool bdrv_op_blocker_is_empty(BlockDriverState *bs)
+{
+int i;
+
+for (i = 0; i  BLOCK_OP_TYPE_MAX; i++) {
+if (!QLIST_EMPTY(bs-op_blockers[i])) {
+return false;
+}
+}
+return true;
+}
+
 void bdrv_set_in_use(BlockDriverState *bs, int in_use)
 {
 assert(bs-in_use != in_use);
diff --git a/include/block/block.h b/include/block/block.h
index 8820735..4874e2a 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -474,6 +474,13 @@ void bdrv_unref(BlockDriverState *bs);
 void bdrv_set_in_use(BlockDriverState *bs, int in_use);
 int bdrv_in_use(BlockDriverState *bs);
 
+bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
+void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason);
+void bdrv_op_unblock(BlockDriverState *bs, BlockOpType op, Error *reason);
+void bdrv_op_block_all(BlockDriverState *bs, Error *reason);
+void bdrv_op_unblock_all(BlockDriverState *bs, Error *reason);
+bool bdrv_op_blocker_is_empty(BlockDriverState *bs);
+
 #ifdef CONFIG_LINUX_AIO
 int 

[Qemu-devel] [PATCH v14 06/14] block: Add backing_blocker in BlockDriverState

2014-02-19 Thread Fam Zheng
This makes use of op_blocker and blocks all the operations except for
commit target, on each BlockDriverState-backing_hd.

The asserts for op_blocker in bdrv_swap are removed because with this
change, the target of block commit has at least the backing blocker of
its child, so the assertion is not true. Callers should do their check.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c   | 19 +++
 include/block/block_int.h |  3 +++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/block.c b/block.c
index dec44d4..95d8c1f 100644
--- a/block.c
+++ b/block.c
@@ -1044,19 +1044,33 @@ fail:
 void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
 {
 if (bs-backing_hd) {
+assert(error_is_set(bs-backing_blocker));
+bdrv_op_unblock_all(bs-backing_hd, bs-backing_blocker);
 bdrv_unref(bs-backing_hd);
+} else if (backing_hd) {
+error_setg(bs-backing_blocker,
+   device is used as backing hd of '%s',
+   bs-device_name);
 }
 
 bs-backing_hd = backing_hd;
 if (!backing_hd) {
 bs-backing_file[0] = '\0';
 bs-backing_format[0] = '\0';
+if (error_is_set(bs-backing_blocker)) {
+error_free(bs-backing_blocker);
+}
 goto out;
 }
 pstrcpy(bs-backing_file, sizeof(bs-backing_file), backing_hd-filename);
 pstrcpy(bs-backing_format, sizeof(bs-backing_format),
 backing_hd-drv ? backing_hd-drv-format_name : );
 bdrv_ref(bs-backing_hd);
+
+bdrv_op_block_all(bs-backing_hd, bs-backing_blocker);
+/* Otherwise we won't be able to commit due to check in bdrv_commit */
+bdrv_op_unblock(bs-backing_hd, BLOCK_OP_TYPE_COMMIT,
+bs-backing_blocker);
 out:
 bdrv_refresh_limits(bs);
 }
@@ -1696,8 +1710,7 @@ void bdrv_close(BlockDriverState *bs)
 
 if (bs-drv) {
 if (bs-backing_hd) {
-bdrv_unref(bs-backing_hd);
-bs-backing_hd = NULL;
+bdrv_set_backing_hd(bs, NULL);
 }
 bs-drv-bdrv_close(bs);
 g_free(bs-opaque);
@@ -1899,7 +1912,6 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState 
*bs_old)
 assert(QLIST_EMPTY(bs_new-dirty_bitmaps));
 assert(bs_new-job == NULL);
 assert(bs_new-dev == NULL);
-assert(bdrv_op_blocker_is_empty(bs_new));
 assert(bs_new-io_limits_enabled == false);
 assert(!throttle_have_timer(bs_new-throttle_state));
 
@@ -1918,7 +1930,6 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState 
*bs_old)
 /* Check a few fields that should remain attached to the device */
 assert(bs_new-dev == NULL);
 assert(bs_new-job == NULL);
-assert(bdrv_op_blocker_is_empty(bs_new));
 assert(bs_new-io_limits_enabled == false);
 assert(!throttle_have_timer(bs_new-throttle_state));
 
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 1d3f76f..1f4f78b 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -369,6 +369,9 @@ struct BlockDriverState {
 BlockJob *job;
 
 QDict *options;
+
+/* The error object in use for blocking operations on backing_hd */
+Error *backing_blocker;
 };
 
 int get_tmp_filename(char *filename, int size);
-- 
1.8.5.4




[Qemu-devel] [PATCH v14 05/14] block: Add bdrv_set_backing_hd()

2014-02-19 Thread Fam Zheng
This is the common but non-trivial steps to assign or change the
backing_hd of BDS.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c   | 34 +++---
 include/block/block.h |  1 +
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/block.c b/block.c
index b5cb0c7..dec44d4 100644
--- a/block.c
+++ b/block.c
@@ -1041,6 +1041,26 @@ fail:
 return ret;
 }
 
+void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
+{
+if (bs-backing_hd) {
+bdrv_unref(bs-backing_hd);
+}
+
+bs-backing_hd = backing_hd;
+if (!backing_hd) {
+bs-backing_file[0] = '\0';
+bs-backing_format[0] = '\0';
+goto out;
+}
+pstrcpy(bs-backing_file, sizeof(bs-backing_file), backing_hd-filename);
+pstrcpy(bs-backing_format, sizeof(bs-backing_format),
+backing_hd-drv ? backing_hd-drv-format_name : );
+bdrv_ref(bs-backing_hd);
+out:
+bdrv_refresh_limits(bs);
+}
+
 /*
  * Opens the backing file for a BlockDriverState if not yet open
  *
@@ -1054,6 +1074,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
 char backing_filename[PATH_MAX];
 int back_flags, ret;
 BlockDriver *back_drv = NULL;
+BlockDriverState *backing_hd;
 Error *local_err = NULL;
 
 if (bs-backing_hd != NULL) {
@@ -1077,6 +1098,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
sizeof(backing_filename));
 }
 
+backing_hd = bdrv_new();
+
 if (bs-backing_format[0] != '\0') {
 back_drv = bdrv_find_format(bs-backing_format);
 }
@@ -1085,23 +1108,20 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
 back_flags = bs-open_flags  ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT |
 BDRV_O_COPY_ON_READ);
 
-assert(bs-backing_hd == NULL);
-ret = bdrv_open(bs-backing_hd,
+ret = bdrv_open(backing_hd,
 *backing_filename ? backing_filename : NULL, NULL, options,
 back_flags, back_drv, local_err);
 if (ret  0) {
 bs-backing_hd = NULL;
+bdrv_unref(backing_hd);
+backing_hd = NULL;
 bs-open_flags |= BDRV_O_NO_BACKING;
 error_setg(errp, Could not open backing file: %s,
error_get_pretty(local_err));
 error_free(local_err);
 return ret;
 }
-
-if (bs-backing_hd-file) {
-pstrcpy(bs-backing_file, sizeof(bs-backing_file),
-bs-backing_hd-file-filename);
-}
+bdrv_set_backing_hd(bs, backing_hd);
 
 /* Recalculate the BlockLimits with the backing file */
 bdrv_refresh_limits(bs);
diff --git a/include/block/block.h b/include/block/block.h
index a46f70a..ee1582d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -208,6 +208,7 @@ int bdrv_parse_discard_flags(const char *mode, int *flags);
 int bdrv_open_image(BlockDriverState **pbs, const char *filename,
 QDict *options, const char *bdref_key, int flags,
 bool allow_none, Error **errp);
+void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
 int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
 int bdrv_open(BlockDriverState **pbs, const char *filename,
   const char *reference, QDict *options, int flags,
-- 
1.8.5.4




[Qemu-devel] [PATCH v14 09/14] stream: Use bdrv_drop_intermediate and drop close_unused_images

2014-02-19 Thread Fam Zheng
This reuses the new bdrv_drop_intermediate.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/stream.c | 30 +-
 1 file changed, 1 insertion(+), 29 deletions(-)

diff --git a/block/stream.c b/block/stream.c
index dd0b4ac..9cdcf0e 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -51,34 +51,6 @@ static int coroutine_fn stream_populate(BlockDriverState *bs,
 return bdrv_co_copy_on_readv(bs, sector_num, nb_sectors, qiov);
 }
 
-static void close_unused_images(BlockDriverState *top, BlockDriverState *base,
-const char *base_id)
-{
-BlockDriverState *intermediate;
-intermediate = top-backing_hd;
-
-/* Must assign before bdrv_delete() to prevent traversing dangling pointer
- * while we delete backing image instances.
- */
-top-backing_hd = base;
-
-while (intermediate) {
-BlockDriverState *unused;
-
-/* reached base */
-if (intermediate == base) {
-break;
-}
-
-unused = intermediate;
-intermediate = intermediate-backing_hd;
-unused-backing_hd = NULL;
-bdrv_unref(unused);
-}
-
-bdrv_refresh_limits(top);
-}
-
 static void coroutine_fn stream_run(void *opaque)
 {
 StreamBlockJob *s = opaque;
@@ -192,7 +164,7 @@ wait:
 }
 }
 ret = bdrv_change_backing_file(bs, base_id, base_fmt);
-close_unused_images(bs, base, base_id);
+bdrv_drop_intermediate(bs, bs-backing_hd, base);
 }
 
 qemu_vfree(buf);
-- 
1.8.5.4




[Qemu-devel] [PATCH v14 03/14] block: Replace in_use with operation blocker

2014-02-19 Thread Fam Zheng
This drops BlockDriverState.in_use with op_blockers:

  - Call bdrv_op_block_all in place of bdrv_set_in_use(bs, 1).
  - Call bdrv_op_unblock_all in place of bdrv_set_in_use(bs, 0).
  - Check bdrv_op_is_blocked() in place of bdrv_in_use(bs).
The specific types are used, e.g. in place of starting block backup,
bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP, ...).
  - Check bdrv_op_blocker_is_empty() in place of assert(!bs-in_use).

Note: there is only bdrv_op_block_all and bdrv_op_unblock_all callers at
this moment. So although the checks are specific to op types, this
changes can still be seen as identical logic with previously with
in_use. The difference is error message are improved because of blocker
error info.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block-migration.c   |  7 +--
 block.c | 24 +++-
 blockdev.c  | 15 ++-
 blockjob.c  | 14 +-
 hw/block/dataplane/virtio-blk.c | 19 ---
 include/block/block.h   |  2 --
 include/block/block_int.h   |  1 -
 include/block/blockjob.h|  3 +++
 8 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/block-migration.c b/block-migration.c
index 897fdba..bf9a25f 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -59,6 +59,7 @@ typedef struct BlkMigDevState {
 unsigned long *aio_bitmap;
 int64_t completed_sectors;
 BdrvDirtyBitmap *dirty_bitmap;
+Error *blocker;
 } BlkMigDevState;
 
 typedef struct BlkMigBlock {
@@ -346,7 +347,8 @@ static void init_blk_migration_it(void *opaque, 
BlockDriverState *bs)
 bmds-completed_sectors = 0;
 bmds-shared_base = block_mig_state.shared_base;
 alloc_aio_bitmap(bmds);
-bdrv_set_in_use(bs, 1);
+error_setg(bmds-blocker, block device is in use by migration);
+bdrv_op_block_all(bs, bmds-blocker);
 bdrv_ref(bs);
 
 block_mig_state.total_sector_sum += sectors;
@@ -584,7 +586,8 @@ static void blk_mig_cleanup(void)
 blk_mig_lock();
 while ((bmds = QSIMPLEQ_FIRST(block_mig_state.bmds_list)) != NULL) {
 QSIMPLEQ_REMOVE_HEAD(block_mig_state.bmds_list, entry);
-bdrv_set_in_use(bmds-bs, 0);
+bdrv_op_unblock_all(bmds-bs, bmds-blocker);
+error_free(bmds-blocker);
 bdrv_unref(bmds-bs);
 g_free(bmds-aio_bitmap);
 g_free(bmds);
diff --git a/block.c b/block.c
index 485d4f0..b5cb0c7 100644
--- a/block.c
+++ b/block.c
@@ -1843,7 +1843,6 @@ static void bdrv_move_feature_fields(BlockDriverState 
*bs_dest,
 bs_dest-refcnt = bs_src-refcnt;
 
 /* job */
-bs_dest-in_use = bs_src-in_use;
 bs_dest-job= bs_src-job;
 
 /* keep the same entry in bdrv_states */
@@ -1880,7 +1879,7 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState 
*bs_old)
 assert(QLIST_EMPTY(bs_new-dirty_bitmaps));
 assert(bs_new-job == NULL);
 assert(bs_new-dev == NULL);
-assert(bs_new-in_use == 0);
+assert(bdrv_op_blocker_is_empty(bs_new));
 assert(bs_new-io_limits_enabled == false);
 assert(!throttle_have_timer(bs_new-throttle_state));
 
@@ -1899,7 +1898,7 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState 
*bs_old)
 /* Check a few fields that should remain attached to the device */
 assert(bs_new-dev == NULL);
 assert(bs_new-job == NULL);
-assert(bs_new-in_use == 0);
+assert(bdrv_op_blocker_is_empty(bs_new));
 assert(bs_new-io_limits_enabled == false);
 assert(!throttle_have_timer(bs_new-throttle_state));
 
@@ -1936,7 +1935,7 @@ static void bdrv_delete(BlockDriverState *bs)
 {
 assert(!bs-dev);
 assert(!bs-job);
-assert(!bs-in_use);
+assert(bdrv_op_blocker_is_empty(bs));
 assert(!bs-refcnt);
 assert(QLIST_EMPTY(bs-dirty_bitmaps));
 
@@ -2118,7 +2117,8 @@ int bdrv_commit(BlockDriverState *bs)
 return -ENOTSUP;
 }
 
-if (bdrv_in_use(bs) || bdrv_in_use(bs-backing_hd)) {
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT, NULL) ||
+bdrv_op_is_blocked(bs-backing_hd, BLOCK_OP_TYPE_COMMIT, NULL)) {
 return -EBUSY;
 }
 
@@ -3353,8 +3353,9 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
 return -ENOTSUP;
 if (bs-read_only)
 return -EACCES;
-if (bdrv_in_use(bs))
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_RESIZE, NULL)) {
 return -EBUSY;
+}
 ret = drv-bdrv_truncate(bs, offset);
 if (ret == 0) {
 ret = refresh_total_sectors(bs, offset  BDRV_SECTOR_BITS);
@@ -5205,17 +5206,6 @@ bool bdrv_op_blocker_is_empty(BlockDriverState *bs)
 return true;
 }
 
-void bdrv_set_in_use(BlockDriverState *bs, int in_use)
-{
-assert(bs-in_use != in_use);
-bs-in_use = in_use;
-}
-
-int bdrv_in_use(BlockDriverState *bs)
-{
-return bs-in_use;
-}
-
 void bdrv_iostatus_enable(BlockDriverState *bs)
 {
 bs-iostatus_enabled = 

Re: [Qemu-devel] [PATCH 0/4] Tracetool cleanup

2014-02-19 Thread Stefan Hajnoczi
On Mon, Feb 17, 2014 at 08:36:19PM +0100, Lluís Vilanova wrote:
 Minimizes the amount of backend code, making it simpler to add new/different
 backends.
 
 Also performs other cleanups all around.
 
 Signed-off-by: Lluís Vilanova vilan...@ac.upc.edu
 ---
 
 Lluís Vilanova (4):
   trace: [tracetool] Add method 'Event.api' to build event names
   trace: [tracetool,trivial] Style changes
   trace: [tracetool] Identify formats directly used by QEMU
   trace: [tracetool] Minimize the amount of per-backend code

I think we stretched the concepts of backends and formats too far.
There are formats that only work with one backend (like 'stap').  And
there are backends that behave differently from all other backends.

As a result we're trying to abstract and make common a bunch of stuff
that isn't really common.  This problem existed before this patch
series, but I feel we're going further down a direction that
increasingly seems to be wrong.

It's simpler if we turn the design inside-out.  Instead of making
backends export all sorts of interfaces and flags, tracetool should just
parse trace-events and hand the list over to the backend.

Let the backend do whatever it wants.  The format option simply becomes
an option telling the backend which type of output to generate
(events.h, events.c, .stp, etc).

Common behavior should live in plain old Python modules/functions.

TL;DR moving to a library design would simplify and clean up more than
trying to improve the current framework design

What do you think?

Stefan



[Qemu-devel] [PATCH v14 07/14] block: Parse backing option to reference existing BDS

2014-02-19 Thread Fam Zheng
Now it's safe to allow reference for backing_hd in the interface.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c | 26 --
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 95d8c1f..a2bf24c 100644
--- a/block.c
+++ b/block.c
@@ -1395,12 +1395,34 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename,
 /* If there is a backing file, use it */
 if ((flags  BDRV_O_NO_BACKING) == 0) {
 QDict *backing_options;
+const char *backing_name;
+BlockDriverState *backing_hd;
 
+backing_name = qdict_get_try_str(options, backing);
 qdict_extract_subqdict(options, backing_options, backing.);
-ret = bdrv_open_backing_file(bs, backing_options, local_err);
-if (ret  0) {
+
+if (backing_name  qdict_size(backing_options)) {
+error_setg(local_err,
+   Option \backing\ and \backing.*\ cannot be 
+   used together);
+ret = -EINVAL;
 goto close_and_fail;
 }
+if (backing_name) {
+backing_hd = bdrv_find(backing_name);
+if (!backing_hd) {
+error_set(local_err, QERR_DEVICE_NOT_FOUND, backing_name);
+ret = -ENOENT;
+goto close_and_fail;
+}
+qdict_del(options, backing);
+bdrv_set_backing_hd(bs, backing_hd);
+} else {
+ret = bdrv_open_backing_file(bs, backing_options, local_err);
+if (ret  0) {
+goto close_and_fail;
+}
+}
 }
 
 done:
-- 
1.8.5.4




[Qemu-devel] [PATCH v14 11/14] block: Allow backup on referenced named BlockDriverState

2014-02-19 Thread Fam Zheng
Drive backup is a read only operation on source bs. We want to allow
this specific case to enable image-fleecing. Note that when
image-fleecing job starts, the job still add its blocker to source bs,
and any other operation on it will be blocked by that.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/block.c b/block.c
index cf41f3d..1af43b9 100644
--- a/block.c
+++ b/block.c
@@ -1071,6 +1071,8 @@ void bdrv_set_backing_hd(BlockDriverState *bs, 
BlockDriverState *backing_hd)
 /* Otherwise we won't be able to commit due to check in bdrv_commit */
 bdrv_op_unblock(bs-backing_hd, BLOCK_OP_TYPE_COMMIT,
 bs-backing_blocker);
+bdrv_op_unblock(bs-backing_hd, BLOCK_OP_TYPE_BACKUP_SOURCE,
+bs-backing_blocker);
 out:
 bdrv_refresh_limits(bs);
 }
-- 
1.8.5.4




Re: [Qemu-devel] [PULL 1/5] acpi-build: append description for non-hotplug

2014-02-19 Thread Michael S. Tsirkin
On Mon, Feb 17, 2014 at 09:51:39AM -0500, Gabriel L. Somlo wrote:
 Michael,
 
 On Mon, Feb 17, 2014 at 04:25:26PM +0200, Michael S. Tsirkin wrote:
  As reported in
  http://article.gmane.org/gmane.comp.emulators.qemu/253987
  Mac OSX actually requires describing all occupied slots
  in ACPI - even if hotplug isn't enabled.
  
  I didn't expect this so I dropped description of all
  non hotpluggable slots from ACPI.
  As a result: before
  commit 99fd437dee468609de8218f0eb3b16621fb6a9c9 (enable
  hotplug for pci bridges), PCI cards show up in the device tree of OS X
  (System Information). E.g., on MountainLion users have:
  
  ...
  
  Ethernet still works, but it's not showing up on the PCI bus, and it
  no longer thinks it's plugged in to slot #2, as it used to before the
  change.
  
  To fix, append description for all occupied non hotpluggable PCI slots.
  
  One need to be careful when doing this: VGA and ISA device were already
  described, so we need to drop description from DSDT.
  
  Reported-by: Gabriel L. Somlo gso...@gmail.com
  Signed-off-by: Michael S. Tsirkin m...@redhat.com
  ---
  ...
 
 With this latest version of your patch, I crash during OS X boot with
 unable to find driver for this 
 platform:\ACPI\.\n@/SourceCache/xnu/xnu-2050.48.12/iokit/Kernel/IOPlatformExpert.cpp:1514
 
 Your original patch (slightly doctored since it no longer applies cleanly
 to the current qemu git master) is included below, and still works for me.
 
 Thanks,
 --Gabriel

Any chance below helps on top?
Another alternative is that DSDT referencing
SSDT does not work for apple.
I hope it's not that, that would be annoying...

commit 12b48c660b8316b1e8ff633eb9f3f34bd4b78284
Author: Michael S. Tsirkin m...@redhat.com
Date:   Wed Feb 19 15:47:03 2014 +0200

acpi-build: drop _SUN for non hotpluggable slots

Not needed there, let's not add it.

Signed-off-by: Michael S. Tsirkin m...@redhat.com

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 5b0bb5a..226e59e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -644,19 +644,16 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
 
 #define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
-#define ACPI_PCINOHP_OFFSET_ID (*ssdt_pcinohp_id - *ssdt_pcinohp_start)
 #define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
 #define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
 #define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
 
 #define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
-#define ACPI_PCIVGA_OFFSET_ID (*ssdt_pcivga_id - *ssdt_pcivga_start)
 #define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
 #define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
 #define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
 
 #define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
-#define ACPI_PCIQXL_OFFSET_ID (*ssdt_pciqxl_id - *ssdt_pciqxl_start)
 #define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
 #define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
 #define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
@@ -701,7 +698,6 @@ static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
 
 ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn  4);
 ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCINOHP_OFFSET_ID] = slot;
 ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
 }
 
@@ -711,7 +707,6 @@ static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
 
 ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn  4);
 ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCIVGA_OFFSET_ID] = slot;
 ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
 }
 
@@ -721,7 +716,6 @@ static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
 
 ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn  4);
 ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCIQXL_OFFSET_ID] = slot;
 ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
 }
 
diff --git a/hw/i386/ssdt-pcihp.dsl b/hw/i386/ssdt-pcihp.dsl
index 69a0228..ac91c05 100644
--- a/hw/i386/ssdt-pcihp.dsl
+++ b/hw/i386/ssdt-pcihp.dsl
@@ -53,8 +53,6 @@ DefinitionBlock (ssdt-pcihp.aml, SSDT, 0x01, BXPC, 
BXSSDTPCIHP, 0x1)
 // Extract the offsets of the device name, address dword and the slot
 // name byte - we fill them in for each device.
 Device(SBB) {
-ACPI_EXTRACT_NAME_BYTE_CONST ssdt_pcinohp_id
-Name(_SUN, 0xAA)
 ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcinohp_adr
 Name(_ADR, 0xAA)
 }
@@ -66,8 +64,6 @@ DefinitionBlock (ssdt-pcihp.aml, SSDT, 0x01, BXPC, 
BXSSDTPCIHP, 0x1)
 // Extract the offsets of the device name, address dword and the slot
 // name byte - we fill them in for 

Re: [Qemu-devel] [PULL 00/15] tcg updates

2014-02-19 Thread Richard Henderson
On 02/19/2014 04:21 AM, Kevin Wolf wrote:
 Am 18.02.2014 um 02:15 hat Richard Henderson geschrieben:
 Contains two patch sets, recently reviewed.  Plus two other
 unrelated patches that probably weren't going to get in via
 any other tree.
 
 It doesn't seem to contain my target-i386 I/O bitmap fix. Should I send
 a separate pull request for that one?

That would probably be best, since you have it handy.


r~




Re: [Qemu-devel] [PULL 1/5] acpi-build: append description for non-hotplug

2014-02-19 Thread Peter Maydell
On 17 February 2014 16:44, Michael S. Tsirkin m...@redhat.com wrote:
 Peter, if not too late, pls don't pull until we figure it out.

If you want a pull request to not be applied you need to follow
up to the 00/nn cover letter for the pull request to say so.
Otherwise I am likely to either miss the request or not to
remember it when I'm going through the folder of pull
requests to be applied.

thanks
-- PMM



[Qemu-devel] [PATCH v14 08/14] block: Support dropping active in bdrv_drop_intermediate

2014-02-19 Thread Fam Zheng
Dropping intermediate could be useful both for commit and stream, and
BDS refcnt plus bdrv_swap could do most of the job nicely. It also needs
to work with op blockers.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c| 146 +
 block/commit.c |   1 +
 2 files changed, 66 insertions(+), 81 deletions(-)

diff --git a/block.c b/block.c
index a2bf24c..cf41f3d 100644
--- a/block.c
+++ b/block.c
@@ -2485,115 +2485,99 @@ BlockDriverState *bdrv_find_overlay(BlockDriverState 
*active,
 return overlay;
 }
 
-typedef struct BlkIntermediateStates {
-BlockDriverState *bs;
-QSIMPLEQ_ENTRY(BlkIntermediateStates) entry;
-} BlkIntermediateStates;
-
-
 /*
- * Drops images above 'base' up to and including 'top', and sets the image
- * above 'top' to have base as its backing file.
+ * Drops images above 'base' up to and including 'top', and sets new 'base'
+ * as backing_hd of top_overlay (the image orignally has 'top' as backing
+ * file). top_overlay may be NULL if 'top' is active, no such update needed.
+ * Requires that the top_overlay to 'top' is opened r/w.
  *
- * Requires that the overlay to 'top' is opened r/w, so that the backing file
- * information in 'bs' can be properly updated.
+ * 1) This will convert the following chain:
  *
- * E.g., this will convert the following chain:
- * bottom - base - intermediate - top - active
+ * ... - base - ... - top - overlay -... - active
  *
  * to
  *
- * bottom - base - active
+ * ... - base - overlay - active
  *
- * It is allowed for bottom==base, in which case it converts:
+ * 2) It is allowed for bottom==base, in which case it converts:
  *
- * base - intermediate - top - active
+ * base - ... - top - overlay - ... - active
  *
  * to
  *
- * base - active
+ * base - overlay - active
+ *
+ * 2) It also allows active==top, in which case it converts:
+ *
+ * ... - base - ... - top (active)
+ *
+ * to
+ *
+ * ... - base == active == top
+ *
+ * i.e. only base and lower remains: *top == *base when return.
+ *
+ * 3) If base==NULL, it will drop all the BDS below overlay and set its
+ * backing_hd to NULL. I.e.:
+ *
+ * base(NULL) - ... - overlay - ... - active
+ *
+ * to
  *
- * Error conditions:
- *  if active == top, that is considered an error
+ * overlay - ... - active
  *
  */
 int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
BlockDriverState *base)
 {
-BlockDriverState *intermediate;
-BlockDriverState *base_bs = NULL;
-BlockDriverState *new_top_bs = NULL;
-BlkIntermediateStates *intermediate_state, *next;
-int ret = -EIO;
-
-QSIMPLEQ_HEAD(states_to_delete, BlkIntermediateStates) states_to_delete;
-QSIMPLEQ_INIT(states_to_delete);
-
-if (!top-drv || !base-drv) {
-goto exit;
-}
-
-new_top_bs = bdrv_find_overlay(active, top);
+BlockDriverState *drop_start, *overlay;
+int ret = -EINVAL;
 
-if (new_top_bs == NULL) {
-/* we could not find the image above 'top', this is an error */
+if (!top-drv || (base  !base-drv)) {
 goto exit;
 }
-
-/* special case of new_top_bs-backing_hd already pointing to base - 
nothing
- * to do, no intermediate images */
-if (new_top_bs-backing_hd == base) {
+if (top == base) {
 ret = 0;
-goto exit;
-}
-
-intermediate = top;
-
-/* now we will go down through the list, and add each BDS we find
- * into our deletion queue, until we hit the 'base'
- */
-while (intermediate) {
-intermediate_state = g_malloc0(sizeof(BlkIntermediateStates));
-intermediate_state-bs = intermediate;
-QSIMPLEQ_INSERT_TAIL(states_to_delete, intermediate_state, entry);
-
-if (intermediate-backing_hd == base) {
-base_bs = intermediate-backing_hd;
-break;
+} else if (top == active) {
+assert(base);
+drop_start = active-backing_hd;
+bdrv_swap(active, base);
+base-backing_hd = NULL;
+bdrv_unref(drop_start);
+ret = 0;
+} else {
+/* If there's an overlay, its backing_hd points to top's BDS now,
+ * the top image is dropped but this BDS structure is kept and swapped
+ * with base, this way we keep the pointers valid after dropping top */
+overlay = bdrv_find_overlay(active, top);
+if (!overlay) {
+goto exit;
+}
+if (base) {
+ret = bdrv_change_backing_file(overlay, base-filename,
+   base-drv-format_name);
+} else {
+ret = bdrv_change_backing_file(overlay, NULL, NULL);
+}
+if (ret) {
+goto exit;
+}
+if (base) {
+drop_start = top-backing_hd;
+bdrv_swap(top, base);
+/* Break the loop formed by bdrv_swap */
+bdrv_set_backing_hd(base, NULL);
+

[Qemu-devel] [PATCH v14 13/14] qemu-iotests: Test blockdev-backup in 055

2014-02-19 Thread Fam Zheng
This applies cases on drive-backup on blockdev-backup, except cases with
target format and mode.

Also add a case to check source == target.

Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/055 | 275 ++---
 tests/qemu-iotests/055.out |   4 +-
 2 files changed, 235 insertions(+), 44 deletions(-)

diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
index 451b67d..1fab088 100755
--- a/tests/qemu-iotests/055
+++ b/tests/qemu-iotests/055
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Tests for drive-backup
+# Tests for drive-backup and blockdev-backup
 #
 # Copyright (C) 2013 Red Hat, Inc.
 #
@@ -27,6 +27,7 @@ from iotests import qemu_img, qemu_io
 
 test_img = os.path.join(iotests.test_dir, 'test.img')
 target_img = os.path.join(iotests.test_dir, 'target.img')
+blockdev_target_img = os.path.join(iotests.test_dir, 'blockdev-target.img')
 
 class TestSingleDrive(iotests.QMPTestCase):
 image_len = 64 * 1024 * 1024 # MB
@@ -38,34 +39,48 @@ class TestSingleDrive(iotests.QMPTestCase):
 qemu_io('-c', 'write -P0xd5 1M 32k', test_img)
 qemu_io('-c', 'write -P0xdc 32M 124k', test_img)
 qemu_io('-c', 'write -P0xdc 67043328 64k', test_img)
+qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, 
str(TestSingleDrive.image_len))
 
-self.vm = iotests.VM().add_drive(test_img)
+self.vm = 
iotests.VM().add_drive(test_img).add_drive(blockdev_target_img)
 self.vm.launch()
 
 def tearDown(self):
 self.vm.shutdown()
 os.remove(test_img)
+os.remove(blockdev_target_img)
 try:
 os.remove(target_img)
 except OSError:
 pass
 
-def test_cancel(self):
+def do_test_cancel(self, test_drive_backup):
 self.assert_no_active_block_jobs()
 
-result = self.vm.qmp('drive-backup', device='drive0',
- target=target_img, sync='full')
+if test_drive_backup:
+result = self.vm.qmp('drive-backup', device='drive0',
+ target=target_img, sync='full')
+else:
+result = self.vm.qmp('blockdev-backup', device='drive0',
+ target='drive1', sync='full')
 self.assert_qmp(result, 'return', {})
 
 event = self.cancel_and_wait()
 self.assert_qmp(event, 'data/type', 'backup')
 
-def test_pause(self):
+def test_cancel(self):
+self.do_test_cancel(True)
+self.do_test_cancel(False)
+
+def do_test_pause(self, test_drive_backup):
 self.assert_no_active_block_jobs()
 
 self.vm.pause_drive('drive0')
-result = self.vm.qmp('drive-backup', device='drive0',
- target=target_img, sync='full')
+if test_drive_backup:
+result = self.vm.qmp('drive-backup', device='drive0',
+ target=target_img, sync='full')
+else:
+result = self.vm.qmp('blockdev-backup', device='drive0',
+ target='drive1', sync='full')
 self.assert_qmp(result, 'return', {})
 
 result = self.vm.qmp('block-job-pause', device='drive0')
@@ -86,14 +101,28 @@ class TestSingleDrive(iotests.QMPTestCase):
 self.wait_until_completed()
 
 self.vm.shutdown()
-self.assertTrue(iotests.compare_images(test_img, target_img),
-'target image does not match source after backup')
+if test_drive_backup:
+self.assertTrue(iotests.compare_images(test_img, target_img),
+'target image does not match source after backup')
+else:
+self.assertTrue(iotests.compare_images(test_img, 
blockdev_target_img),
+'target image does not match source after backup')
+
+def test_pause_drive_backup(self):
+self.do_test_pause(True)
+
+def test_pause_blockdev_backup(self):
+self.do_test_pause(False)
 
 def test_medium_not_found(self):
 result = self.vm.qmp('drive-backup', device='ide1-cd0',
  target=target_img, sync='full')
 self.assert_qmp(result, 'error/class', 'GenericError')
 
+result = self.vm.qmp('blockdev-backup', device='ide1-cd0',
+ target='drive1', sync='full')
+self.assert_qmp(result, 'error/class', 'GenericError')
+
 def test_image_not_found(self):
 result = self.vm.qmp('drive-backup', device='drive0',
  target=target_img, sync='full', mode='existing')
@@ -110,26 +139,56 @@ class TestSingleDrive(iotests.QMPTestCase):
  target=target_img, sync='full')
 self.assert_qmp(result, 'error/class', 'DeviceNotFound')
 
+result = self.vm.qmp('blockdev-backup', device='nonexistent',
+ target='drive0', sync='full')
+

[Qemu-devel] [PATCH v14 12/14] block: Add blockdev-backup to transaction

2014-02-19 Thread Fam Zheng
Signed-off-by: Fam Zheng f...@redhat.com
---
 blockdev.c   | 48 
 qapi-schema.json |  1 +
 2 files changed, 49 insertions(+)

diff --git a/blockdev.c b/blockdev.c
index 890cfea..81446f5 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1405,6 +1405,49 @@ static void drive_backup_abort(BlkTransactionState 
*common)
 }
 }
 
+typedef struct BlockdevBackupState {
+BlkTransactionState common;
+BlockDriverState *bs;
+BlockJob *job;
+} BlockdevBackupState;
+
+static void blockdev_backup_prepare(BlkTransactionState *common, Error **errp)
+{
+BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, 
common);
+BlockdevBackup *backup;
+Error *local_err = NULL;
+
+assert(common-action-kind == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP);
+backup = common-action-blockdev_backup;
+
+qmp_blockdev_backup(backup-device, backup-target,
+backup-sync,
+backup-has_speed, backup-speed,
+backup-has_on_source_error, backup-on_source_error,
+backup-has_on_target_error, backup-on_target_error,
+local_err);
+if (error_is_set(local_err)) {
+error_propagate(errp, local_err);
+state-bs = NULL;
+state-job = NULL;
+return;
+}
+
+state-bs = bdrv_find(backup-device);
+state-job = state-bs-job;
+}
+
+static void blockdev_backup_abort(BlkTransactionState *common)
+{
+BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, 
common);
+BlockDriverState *bs = state-bs;
+
+/* Only cancel if it's the job we started */
+if (bs  bs-job  bs-job == state-job) {
+block_job_cancel_sync(bs-job);
+}
+}
+
 static void abort_prepare(BlkTransactionState *common, Error **errp)
 {
 error_setg(errp, Transaction aborted using Abort action);
@@ -1427,6 +1470,11 @@ static const BdrvActionOps actions[] = {
 .prepare = drive_backup_prepare,
 .abort = drive_backup_abort,
 },
+[TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP] = {
+.instance_size = sizeof(BlockdevBackupState),
+.prepare = blockdev_backup_prepare,
+.abort = blockdev_backup_abort,
+},
 [TRANSACTION_ACTION_KIND_ABORT] = {
 .instance_size = sizeof(BlkTransactionState),
 .prepare = abort_prepare,
diff --git a/qapi-schema.json b/qapi-schema.json
index 7b0be86..a00f4d5 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1893,6 +1893,7 @@
   'data': {
'blockdev-snapshot-sync': 'BlockdevSnapshot',
'drive-backup': 'DriveBackup',
+   'blockdev-backup': 'BlockdevBackup',
'abort': 'Abort',
'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternal'
} }
-- 
1.8.5.4




Re: [Qemu-devel] [PULL 1/5] acpi-build: append description for non-hotplug

2014-02-19 Thread Michael S. Tsirkin
On Wed, Feb 19, 2014 at 01:52:20PM +, Peter Maydell wrote:
 On 17 February 2014 16:44, Michael S. Tsirkin m...@redhat.com wrote:
  Peter, if not too late, pls don't pull until we figure it out.
 
 If you want a pull request to not be applied you need to follow
 up to the 00/nn cover letter for the pull request to say so.
 Otherwise I am likely to either miss the request or not to
 remember it when I'm going through the folder of pull
 requests to be applied.
 
 thanks
 -- PMM

Good thing you noticed this time :)
Good to know, will do so in the future.

Thanks,

-- 
MST



[Qemu-devel] [PATCH v14 14/14] qemu-iotests: Image fleecing test case 081

2014-02-19 Thread Fam Zheng
This tests the workflow of creating a lightweight point-in-time snapshot
with blockdev-backup command and export it with built-in NBD server.

It's tested that after the snapshot it created, writing to the original
device doesn't change data that can be read from target with NBD.

Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/081 | 99 ++
 tests/qemu-iotests/081.out |  5 +++
 tests/qemu-iotests/group   |  1 +
 3 files changed, 105 insertions(+)
 create mode 100755 tests/qemu-iotests/081
 create mode 100644 tests/qemu-iotests/081.out

diff --git a/tests/qemu-iotests/081 b/tests/qemu-iotests/081
new file mode 100755
index 000..8be32d7
--- /dev/null
+++ b/tests/qemu-iotests/081
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+#
+# Tests for image fleecing (point in time snapshot export to NBD)
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# Based on 055.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see http://www.gnu.org/licenses/.
+#
+
+import time
+import os
+import iotests
+from iotests import qemu_img, qemu_io
+
+test_img = os.path.join(iotests.test_dir, 'test.img')
+target_img = os.path.join(iotests.test_dir, 'target.img')
+nbd_sock = os.path.join(iotests.test_dir, 'nbd.sock')
+
+class TestImageFleecing(iotests.QMPTestCase):
+image_len = 64 * 1024 * 1024 # MB
+
+def setUp(self):
+# Write data to the image so we can compare later
+qemu_img('create', '-f', iotests.imgfmt, test_img, 
str(TestImageFleecing.image_len))
+self.patterns = [
+(0x5d, 0, 64k),
+(0xd5, 1M, 64k),
+(0xdc, 32M, 64k),
+(0xdc, 67043328, 64k)]
+
+for p in self.patterns:
+qemu_io('-c', 'write -P%s %s %s' % p, test_img)
+
+qemu_img('create', '-f', iotests.imgfmt, target_img, 
str(TestImageFleecing.image_len))
+
+self.vm = iotests.VM().add_drive(test_img)
+self.vm.launch()
+
+self.overwrite_patterns = [
+(0xa0, 0, 64k),
+(0x0a, 1M, 64k),
+(0x55, 32M, 64k),
+(0x56, 67043328, 64k)]
+
+self.nbd_uri = nbd+unix:///drive1?socket=%s % nbd_sock
+
+def tearDown(self):
+self.vm.shutdown()
+os.remove(test_img)
+os.remove(target_img)
+
+def verify_patterns(self):
+for p in self.patterns:
+self.assertEqual(-1, qemu_io(self.nbd_uri, '-c', 'read -P%s %s %s' 
% p).find(verification failed),
+ Failed to verify pattern: %s %s %s % p)
+
+def test_image_fleecing(self):
+result = self.vm.qmp(blockdev-add, **{options: {
+driver: qcow2,
+id: drive1,
+file: {
+driver: file,
+filename: target_img,
+},
+backing: drive0,
+}})
+self.assert_qmp(result, 'return', {})
+result = self.vm.qmp(nbd-server-start, **{addr: { type: unix, 
data: { path: nbd_sock } } })
+self.assert_qmp(result, 'return', {})
+result = self.vm.qmp(blockdev-backup, device=drive0, 
target=drive1, sync=none)
+self.assert_qmp(result, 'return', {})
+result = self.vm.qmp(nbd-server-add, device=drive1)
+self.assert_qmp(result, 'return', {})
+
+self.verify_patterns()
+
+for p in self.overwrite_patterns:
+self.vm.hmp_qemu_io(drive0, write -P%s %s %s % p)
+
+self.verify_patterns()
+
+self.cancel_and_wait(resume=True)
+self.assert_no_active_block_jobs()
+
+if __name__ == '__main__':
+iotests.main(supported_fmts=['raw', 'qcow2'])
diff --git a/tests/qemu-iotests/081.out b/tests/qemu-iotests/081.out
new file mode 100644
index 000..ae1213e
--- /dev/null
+++ b/tests/qemu-iotests/081.out
@@ -0,0 +1,5 @@
+.
+--
+Ran 1 tests
+
+OK
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index d8be74a..fe5d764 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -83,3 +83,4 @@
 074 rw auto
 077 rw auto
 079 rw auto
+081 rw auto
-- 
1.8.5.4




Re: [Qemu-devel] [PULL 0/5] acpi,pc,pci,virtio,memory bug fixes

2014-02-19 Thread Peter Maydell
On 17 February 2014 14:25, Michael S. Tsirkin m...@redhat.com wrote:
 The following changes since commit 417c45ab2f847c0a47b1232f611aa886df6a97d5:

   ACPI: Remove commented-out code from HPET._CRS (2014-02-10 11:09:33 +0200)

 are available in the git repository at:

   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

 for you to fetch changes up to 0217598857eaf0ceae137cdd71445118af2284cf:

   PCIE: fix regression with coldplugged multifunction device (2014-02-17 
 16:17:31 +0200)

Not applying this pullreq as per conversation in the other thread.
Ping me if you want it applied later, or submit a fresh one.

thanks
-- PMM



Re: [Qemu-devel] [PATCH v3 00/20] Improve bdrv_open error messages

2014-02-19 Thread Kevin Wolf
Am 17.02.2014 um 14:43 hat Paolo Bonzini geschrieben:
 Most of the block drivers are not using the Error** argument to bdrv_open,
 and instead just printing errors to stderr.  This series improves that,
 and as a consequence it also avoids abuse of errno numbers.
 
 The only hurdle (caught by qemu-iotests, too) is VMDK, where we currently
 parse a file first as image, and second as a descriptor.  This makes
 it hard to pick a good error message, because you do not know which
 attempt gave the most reasonable error message.  For this reason patches
 15-17 modify this approach and push up the detection of vmdk image file
 magic numbers.
 
 Apart from this, and from a segfault fixed by patch 7, the series consists
 of mostly trivial patches.

Thanks, applied to the block branch.

Kevin



[Qemu-devel] [PULL 3/3] qtest: kill QEMU process on g_assert() failure

2014-02-19 Thread Stefan Hajnoczi
The QEMU process stays running if the test case fails.  This patch fixes
the leak by installing a SIGABRT signal handler which invokes
qtest_end().

Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Paolo Bonzini pbonz...@redhat.com
---
 tests/libqtest.c | 31 +--
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 8b2b2d7..f587d36 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -44,6 +44,7 @@ struct QTestState
 bool irq_level[MAX_IRQ];
 GString *rx;
 pid_t qemu_pid;  /* our child QEMU process */
+struct sigaction sigact_old; /* restored on exit */
 };
 
 #define g_assert_no_errno(ret) do { \
@@ -88,6 +89,19 @@ static int socket_accept(int sock)
 return ret;
 }
 
+static void kill_qemu(QTestState *s)
+{
+if (s-qemu_pid != -1) {
+kill(s-qemu_pid, SIGTERM);
+waitpid(s-qemu_pid, NULL, 0);
+}
+}
+
+static void sigabrt_handler(int signo)
+{
+kill_qemu(global_qtest);
+}
+
 QTestState *qtest_init(const char *extra_args)
 {
 QTestState *s;
@@ -96,6 +110,7 @@ QTestState *qtest_init(const char *extra_args)
 gchar *qmp_socket_path;
 gchar *command;
 const char *qemu_binary;
+struct sigaction sigact;
 
 qemu_binary = getenv(QTEST_QEMU_BINARY);
 g_assert(qemu_binary != NULL);
@@ -108,6 +123,14 @@ QTestState *qtest_init(const char *extra_args)
 sock = init_socket(socket_path);
 qmpsock = init_socket(qmp_socket_path);
 
+/* Catch SIGABRT to clean up on g_assert() failure */
+sigact = (struct sigaction){
+.sa_handler = sigabrt_handler,
+.sa_flags = SA_RESETHAND,
+};
+sigemptyset(sigact.sa_mask);
+sigaction(SIGABRT, sigact, s-sigact_old);
+
 s-qemu_pid = fork();
 if (s-qemu_pid == 0) {
 command = g_strdup_printf(exec %s 
@@ -148,13 +171,9 @@ QTestState *qtest_init(const char *extra_args)
 
 void qtest_quit(QTestState *s)
 {
-int status;
-
-if (s-qemu_pid != -1) {
-kill(s-qemu_pid, SIGTERM);
-waitpid(s-qemu_pid, status, 0);
-}
+sigaction(SIGABRT, s-sigact_old, NULL);
 
+kill_qemu(s);
 close(s-fd);
 close(s-qmp_fd);
 g_string_free(s-rx, true);
-- 
1.8.5.3




[Qemu-devel] [PULL 0/3] qtest: avoid pidfile and QEMU process leaks

2014-02-19 Thread Stefan Hajnoczi
Reviewed by Paolo and Markus.  Here is the pull request.

v2:
 * Don't call qtest_end() from SIGABRT handler to avoid reentrancy [Paolo]
 * Use sigemptyset() to avoid assumption about signal mask [Markus]
 * if (fd != -1) close(fd) is no longer necessary [Markus]

This series prevents the following qtest issues:

1. Leaking the pidfile if QEMU startup fails, as discovered by Andreas Färber.
2. Leaking the QEMU process when a test case aborts.

Applying this series should make buildbots and manual make check users have a
more pleasant and less leaky experience :).

The following changes since commit 46eef33b89e936ca793e13c4aeea1414e97e8dbb:

  Fix QEMU build on OpenBSD on x86 archs (2014-02-17 11:44:00 +)

are available in the git repository at:

  git://github.com/stefanha/qemu.git tags/qtest-monitor-process-pull-request

for you to fetch changes up to b15d422a23a3e4cf1b4195af209211eccdb88d51:

  qtest: kill QEMU process on g_assert() failure (2014-02-19 15:45:51 +0100)


qtest resource cleanup pull request


Stefan Hajnoczi (3):
  qtest: drop unused child_pid field
  qtest: make QEMU our direct child process
  qtest: kill QEMU process on g_assert() failure

 tests/libqtest.c | 59 +---
 1 file changed, 26 insertions(+), 33 deletions(-)

-- 
1.8.5.3




[Qemu-devel] [PULL 1/3] qtest: drop unused child_pid field

2014-02-19 Thread Stefan Hajnoczi
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
---
 tests/libqtest.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index c9a4f89..2876ce4 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -43,7 +43,6 @@ struct QTestState
 int qmp_fd;
 bool irq_level[MAX_IRQ];
 GString *rx;
-int child_pid;   /* Child process created to execute QEMU */
 pid_t qemu_pid;  /* QEMU process spawned by our child */
 };
 
@@ -152,7 +151,6 @@ QTestState *qtest_init(const char *extra_args)
 g_free(qmp_socket_path);
 
 s-rx = g_string_new();
-s-child_pid = pid;
 for (i = 0; i  MAX_IRQ; i++) {
 s-irq_level[i] = false;
 }
-- 
1.8.5.3




[Qemu-devel] [PULL 2/3] qtest: make QEMU our direct child process

2014-02-19 Thread Stefan Hajnoczi
qtest_init() cannot use exec*p() to launch QEMU since the exec*p()
functions take an argument array while qtest_init() takes char
*extra_args.  Therefore we execute /bin/sh -c command-line and let the
shell parse the argument string.

This left /bin/sh as our child process and our child's child was QEMU.
We still want QEMU's pid so the -pidfile option was used to let QEMU
report its pid.

The pidfile needs to be unlinked when the test case exits or fails.  In
other words, the pidfile creates a new problem for us!

Simplify all this using the shell 'exec' command.  It allows us to
replace the /bin/sh process with QEMU.  Then we no longer need to use
-pidfile because we already know our fork child's pid.

Note: Yes, it seems silly to exec /bin/sh when we could just exec QEMU
directly.  But remember qtest_init() takes a single char *extra_args
command-line fragment instead of a real argv[] array, so we need
/bin/sh's argument parsing behavior.

Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
---
 tests/libqtest.c | 34 +-
 1 file changed, 5 insertions(+), 29 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 2876ce4..8b2b2d7 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -43,7 +43,7 @@ struct QTestState
 int qmp_fd;
 bool irq_level[MAX_IRQ];
 GString *rx;
-pid_t qemu_pid;  /* QEMU process spawned by our child */
+pid_t qemu_pid;  /* our child QEMU process */
 };
 
 #define g_assert_no_errno(ret) do { \
@@ -88,32 +88,14 @@ static int socket_accept(int sock)
 return ret;
 }
 
-static pid_t read_pid_file(const char *pid_file)
-{
-FILE *f;
-char buffer[1024];
-pid_t pid = -1;
-
-f = fopen(pid_file, r);
-if (f) {
-if (fgets(buffer, sizeof(buffer), f)) {
-pid = atoi(buffer);
-}
-fclose(f);
-}
-return pid;
-}
-
 QTestState *qtest_init(const char *extra_args)
 {
 QTestState *s;
 int sock, qmpsock, i;
 gchar *socket_path;
 gchar *qmp_socket_path;
-gchar *pid_file;
 gchar *command;
 const char *qemu_binary;
-pid_t pid;
 
 qemu_binary = getenv(QTEST_QEMU_BINARY);
 g_assert(qemu_binary != NULL);
@@ -122,22 +104,20 @@ QTestState *qtest_init(const char *extra_args)
 
 socket_path = g_strdup_printf(/tmp/qtest-%d.sock, getpid());
 qmp_socket_path = g_strdup_printf(/tmp/qtest-%d.qmp, getpid());
-pid_file = g_strdup_printf(/tmp/qtest-%d.pid, getpid());
 
 sock = init_socket(socket_path);
 qmpsock = init_socket(qmp_socket_path);
 
-pid = fork();
-if (pid == 0) {
-command = g_strdup_printf(%s 
+s-qemu_pid = fork();
+if (s-qemu_pid == 0) {
+command = g_strdup_printf(exec %s 
   -qtest unix:%s,nowait 
   -qtest-log /dev/null 
   -qmp unix:%s,nowait 
-  -pidfile %s 
   -machine accel=qtest 
   -display none 
   %s, qemu_binary, socket_path,
-  qmp_socket_path, pid_file,
+  qmp_socket_path,
   extra_args ?: );
 execlp(/bin/sh, sh, -c, command, NULL);
 exit(1);
@@ -159,10 +139,6 @@ QTestState *qtest_init(const char *extra_args)
 qtest_qmp_discard_response(s, );
 qtest_qmp_discard_response(s, { 'execute': 'qmp_capabilities' });
 
-s-qemu_pid = read_pid_file(pid_file);
-unlink(pid_file);
-g_free(pid_file);
-
 if (getenv(QTEST_STOP)) {
 kill(s-qemu_pid, SIGSTOP);
 }
-- 
1.8.5.3




[Qemu-devel] [PATCH 1/3] target-i386: Make kvm_default_features an array

2014-02-19 Thread Eduardo Habkost
We will later make the KVM-specific code affect other feature words,
too.

Signed-off-by: Eduardo Habkost ehabk...@redhat.com
---
 target-i386/cpu.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 5a530b5..ee9dff1 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -358,17 +358,22 @@ typedef struct model_features_t {
 FeatureWord feat_word;
 } model_features_t;
 
-static uint32_t kvm_default_features = (1  KVM_FEATURE_CLOCKSOURCE) |
+/* KVM-specific features that are automatically added to all CPU models
+ * when KVM is enabled.
+ */
+static uint32_t kvm_default_features[FEATURE_WORDS] = {
+[FEAT_KVM] = (1  KVM_FEATURE_CLOCKSOURCE) |
 (1  KVM_FEATURE_NOP_IO_DELAY) |
 (1  KVM_FEATURE_CLOCKSOURCE2) |
 (1  KVM_FEATURE_ASYNC_PF) |
 (1  KVM_FEATURE_STEAL_TIME) |
 (1  KVM_FEATURE_PV_EOI) |
-(1  KVM_FEATURE_CLOCKSOURCE_STABLE_BIT);
+(1  KVM_FEATURE_CLOCKSOURCE_STABLE_BIT),
+};
 
 void disable_kvm_pv_eoi(void)
 {
-kvm_default_features = ~(1UL  KVM_FEATURE_PV_EOI);
+kvm_default_features[FEAT_KVM] = ~(1UL  KVM_FEATURE_PV_EOI);
 }
 
 void host_cpuid(uint32_t function, uint32_t count,
@@ -1851,8 +1856,12 @@ static void x86_cpu_load_def(X86CPU *cpu, const char 
*name, Error **errp)
 
 /* Special cases not set in the X86CPUDefinition structs: */
 if (kvm_enabled()) {
-env-features[FEAT_KVM] |= kvm_default_features;
+FeatureWord w;
+for (w = 0; w  FEATURE_WORDS; w++) {
+env-features[w] |= kvm_default_features[w];
+}
 }
+
 env-features[FEAT_1_ECX] |= CPUID_EXT_HYPERVISOR;
 
 /* sysenter isn't supported in compatibility mode on AMD,
-- 
1.8.5.3




[Qemu-devel] [PATCH 2/3] target-i386: Introduce x86_cpu_compat_disable_kvm_features()

2014-02-19 Thread Eduardo Habkost
Instead of the feature-specific disable_kvm_pv_eoi() function, create a
more general function that can be used to disable other feature bits in
machine-type compat code.

Signed-off-by: Eduardo Habkost ehabk...@redhat.com
---
 hw/i386/pc_piix.c | 6 +++---
 target-i386/cpu.c | 4 ++--
 target-i386/cpu.h | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 1acd2b2..dab0c78 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -292,7 +292,7 @@ static void pc_compat_1_3(QEMUMachineInitArgs *args)
 static void pc_compat_1_2(QEMUMachineInitArgs *args)
 {
 pc_compat_1_3(args);
-disable_kvm_pv_eoi();
+x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
 }
 
 static void pc_init_pci_1_7(QEMUMachineInitArgs *args)
@@ -338,7 +338,7 @@ static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs 
*args)
 has_pci_info = false;
 has_acpi_build = false;
 smbios_type1_defaults = false;
-disable_kvm_pv_eoi();
+x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
 enable_compat_apic_id_mode();
 pc_init1(args, 1, 0);
 }
@@ -351,7 +351,7 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 if (!args-cpu_model) {
 args-cpu_model = 486;
 }
-disable_kvm_pv_eoi();
+x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
 enable_compat_apic_id_mode();
 pc_init1(args, 0, 1);
 }
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index ee9dff1..d65ca26 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -371,9 +371,9 @@ static uint32_t kvm_default_features[FEATURE_WORDS] = {
 (1  KVM_FEATURE_CLOCKSOURCE_STABLE_BIT),
 };
 
-void disable_kvm_pv_eoi(void)
+void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features)
 {
-kvm_default_features[FEAT_KVM] = ~(1UL  KVM_FEATURE_PV_EOI);
+kvm_default_features[w] = ~features;
 }
 
 void host_cpuid(uint32_t function, uint32_t count,
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 9989216..d6eb97d 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1257,11 +1257,11 @@ void do_smm_enter(X86CPU *cpu);
 
 void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);
 
-void disable_kvm_pv_eoi(void);
-
 void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
  uint32_t feat_add, uint32_t feat_remove);
 
+void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features);
+
 
 /* Return name of 32-bit register, from a R_* constant */
 const char *get_register_name_32(unsigned int reg);
-- 
1.8.5.3




[Qemu-devel] [PATCH 0/3] Enable x2apic by default on KVM

2014-02-19 Thread Eduardo Habkost
This is the approach I believe was agreed upon during the last QEMU developers
conf call (sorry I didn't join, the meeting timezone change confused me).

Some may notice that representing this new behavior using solely default values
on CPU properties may be a little difficult. Making it possible to replace
x86_cpu_compat_disable_kvm_features() with compat_props entries may be an
interesting problem, too.


Eduardo Habkost (3):
  target-i386: Make kvm_default_features an array
  target-i386: Introduce x86_cpu_compat_disable_kvm_features()
  target-i386: Enable x2apic by default on KVM

 hw/i386/pc_piix.c |  7 ---
 hw/i386/pc_q35.c  |  2 ++
 target-i386/cpu.c | 20 +++-
 target-i386/cpu.h |  4 ++--
 4 files changed, 23 insertions(+), 10 deletions(-)

-- 
1.8.5.3




[Qemu-devel] [PATCH 3/3] target-i386: Enable x2apic by default on KVM

2014-02-19 Thread Eduardo Habkost
When on KVM mode, enable x2apic by default on all CPU models.

Normally we try to keep the CPU model definitions as close as the real
CPUs as possible, but x2apic can be emulated by KVM without host CPU
support for x2apic, and it improves performance by reducing APIC access
overhead. x2apic emulation is available on KVM since 2009 (Linux
2.6.32-rc1), there's no reason for not enabling x2apic by default when
running KVM.

Signed-off-by: Eduardo Habkost ehabk...@redhat.com
---
 hw/i386/pc_piix.c | 1 +
 hw/i386/pc_q35.c  | 2 ++
 target-i386/cpu.c | 1 +
 3 files changed, 4 insertions(+)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index dab0c78..cf12873 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -260,6 +260,7 @@ static void pc_compat_1_7(QEMUMachineInitArgs *args)
 {
 smbios_type1_defaults = false;
 gigabyte_align = false;
+x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
 }
 
 static void pc_compat_1_6(QEMUMachineInitArgs *args)
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index a7f6260..71b05f1 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -244,6 +244,8 @@ static void pc_compat_1_7(QEMUMachineInitArgs *args)
 {
 smbios_type1_defaults = false;
 gigabyte_align = false;
+x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
+
 }
 
 static void pc_compat_1_6(QEMUMachineInitArgs *args)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d65ca26..089328e 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -369,6 +369,7 @@ static uint32_t kvm_default_features[FEATURE_WORDS] = {
 (1  KVM_FEATURE_STEAL_TIME) |
 (1  KVM_FEATURE_PV_EOI) |
 (1  KVM_FEATURE_CLOCKSOURCE_STABLE_BIT),
+[FEAT_1_ECX] = CPUID_EXT_X2APIC,
 };
 
 void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features)
-- 
1.8.5.3




[Qemu-devel] [PATCH 2/7] qemu-img convert: Detect options specified more than once

2014-02-19 Thread Kevin Wolf
Instead of ignoring all option values but the last one, error out if an
option is set multiple times.

Again, the only exception is a -o help option, which may be added to any
valid qemu-img convert command and ignores all other options.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-img.c | 49 +
 1 file changed, 45 insertions(+), 4 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 6a64fe1..55c2c75 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1170,6 +1170,7 @@ static int img_convert(int argc, char **argv)
 QEMUOptionParameter *param = NULL, *create_options = NULL;
 QEMUOptionParameter *out_baseimg_param;
 char *options = NULL;
+bool options_help = false;
 const char *snapshot_name = NULL;
 int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
 bool quiet = false;
@@ -1177,8 +1178,8 @@ static int img_convert(int argc, char **argv)
 QemuOpts *sn_opts = NULL;
 
 fmt = NULL;
-out_fmt = raw;
-cache = unsafe;
+out_fmt = NULL;
+cache = NULL;
 out_baseimg = NULL;
 compress = 0;
 skip_create = 0;
@@ -1193,12 +1194,24 @@ static int img_convert(int argc, char **argv)
 help();
 break;
 case 'f':
+if (fmt) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt = optarg;
 break;
 case 'O':
+if (out_fmt) {
+error_report(-O may only be specified once);
+return 1;
+}
 out_fmt = optarg;
 break;
 case 'B':
+if (out_baseimg) {
+error_report(-B may only be specified once);
+return 1;
+}
 out_baseimg = optarg;
 break;
 case 'c':
@@ -1213,12 +1226,29 @@ static int img_convert(int argc, char **argv)
   compat6\' instead!);
 return 1;
 case 'o':
-options = optarg;
+if (is_help_option(optarg)) {
+options_help = true;
+} else if (!options) {
+options = optarg;
+} else {
+error_report(-o cannot be used multiple times. Please use a 
+ single -o option with comma-separated settings 
+ instead.);
+return 1;
+}
 break;
 case 's':
+if (sn_opts || snapshot_name) {
+error_report(-l/-s may only be specified once);
+return 1;
+}
 snapshot_name = optarg;
 break;
 case 'l':
+if (sn_opts || snapshot_name) {
+error_report(-l/-s may only be specified once);
+return 1;
+}
 if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) {
 sn_opts = qemu_opts_parse(internal_snapshot_opts, optarg, 0);
 if (!sn_opts) {
@@ -1247,6 +1277,10 @@ static int img_convert(int argc, char **argv)
 progress = 1;
 break;
 case 't':
+if (cache) {
+error_report(-t may only be specified once);
+return 1;
+}
 cache = optarg;
 break;
 case 'q':
@@ -1258,6 +1292,13 @@ static int img_convert(int argc, char **argv)
 }
 }
 
+if (!out_fmt) {
+out_fmt = raw;
+}
+if (!cache) {
+cache = unsafe;
+}
+
 if (quiet) {
 progress = 0;
 }
@@ -1272,7 +1313,7 @@ static int img_convert(int argc, char **argv)
 /* Initialize before goto out */
 qemu_progress_init(progress, 1.0);
 
-if (options  is_help_option(options)) {
+if (options_help) {
 ret = print_block_option_help(out_filename, out_fmt);
 goto out;
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH 4/7] qemu-img: Detect options specified more than once

2014-02-19 Thread Kevin Wolf
Instead of ignoring all option values but the last one, error out if an
option is set multiple times. These are the simpler subcommands without
-o, so the patch becomes a bit easier and we can fix the remaining
subcommands in a single patch.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-img.c | 66 +-
 1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/qemu-img.c b/qemu-img.c
index 247987d..a889c84 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -594,6 +594,10 @@ static int img_check(int argc, char **argv)
 help();
 break;
 case 'f':
+if (fmt) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt = optarg;
 break;
 case 'r':
@@ -608,6 +612,10 @@ static int img_check(int argc, char **argv)
 }
 break;
 case OPTION_OUTPUT:
+if (output) {
+error_report(--output may only be specified once);
+return 1;
+}
 output = optarg;
 break;
 case 'q':
@@ -716,9 +724,17 @@ static int img_commit(int argc, char **argv)
 help();
 break;
 case 'f':
+if (fmt) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt = optarg;
 break;
 case 't':
+if (cache) {
+error_report(-t may only be specified once);
+return 1;
+}
 cache = optarg;
 break;
 case 'q':
@@ -949,9 +965,17 @@ static int img_compare(int argc, char **argv)
 help();
 break;
 case 'f':
+if (fmt1) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt1 = optarg;
 break;
 case 'F':
+if (fmt2) {
+error_report(-F may only be specified once);
+return 1;
+}
 fmt2 = optarg;
 break;
 case 'p':
@@ -1906,9 +1930,17 @@ static int img_info(int argc, char **argv)
 help();
 break;
 case 'f':
+if (fmt) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt = optarg;
 break;
 case OPTION_OUTPUT:
+if (output) {
+error_report(--output may only be specified once);
+return 1;
+}
 output = optarg;
 break;
 case OPTION_BACKING_CHAIN:
@@ -2074,9 +2106,17 @@ static int img_map(int argc, char **argv)
 help();
 break;
 case 'f':
+if (fmt) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt = optarg;
 break;
 case OPTION_OUTPUT:
+if (output) {
+error_report(--output may only be specified once);
+return 1;
+}
 output = optarg;
 break;
 }
@@ -2282,7 +2322,7 @@ static int img_rebase(int argc, char **argv)
 
 /* Parse commandline parameters */
 fmt = NULL;
-cache = BDRV_DEFAULT_CACHE;
+cache = NULL;
 out_baseimg = NULL;
 out_basefmt = NULL;
 for(;;) {
@@ -2296,12 +2336,24 @@ static int img_rebase(int argc, char **argv)
 help();
 return 0;
 case 'f':
+if (fmt) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt = optarg;
 break;
 case 'F':
+if (out_basefmt) {
+error_report(-F may only be specified once);
+return 1;
+}
 out_basefmt = optarg;
 break;
 case 'b':
+if (out_baseimg) {
+error_report(-b may only be specified once);
+return 1;
+}
 out_baseimg = optarg;
 break;
 case 'u':
@@ -2311,6 +2363,10 @@ static int img_rebase(int argc, char **argv)
 progress = 1;
 break;
 case 't':
+if (cache) {
+error_report(-t may only be specified once);
+return 1;
+}
 cache = optarg;
 break;
 case 'q':
@@ -2319,6 +2375,10 @@ static int img_rebase(int argc, char **argv)
 }
 }
 
+if (!cache) {
+cache = BDRV_DEFAULT_CACHE;
+}
+
 if (quiet) {
 progress = 0;
 }
@@ -2603,6 +2663,10 @@ static int img_resize(int argc, char **argv)
 help();
 break;
 case 'f':
+if (fmt) {
+error_report(-f 

[Qemu-devel] [PATCH 0/7] qemu-img: Fix handling of multiply specified options

2014-02-19 Thread Kevin Wolf
If you specify the same option more than once (e.g. -o cluster_size=4k
-o lazy_refcounts=on), qemu-img silently ignores all but the last one. This
series fixes it to either consider all options or to give an error message.

Boolean option can still be given more than once as they aren't problematic
in this respect (ten times -q is still quiet).

Kevin Wolf (7):
  qemu-img create: Detect options specified more than once
  qemu-img convert: Detect options specified more than once
  qemu-img amend: Detect options specified more than once
  qemu-img: Detect options specified more than once
  qemu-img create: Support multiple -o options
  qemu-img convert: Support multiple -o options
  qemu-img amend: Support multiple -o options

 qemu-img.c | 198 ++---
 1 file changed, 177 insertions(+), 21 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH 7/7] qemu-img amend: Support multiple -o options

2014-02-19 Thread Kevin Wolf
Multiple -o options has the same meaning as having a single option with
all settings in the order of their respective -o options.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-img.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index e0d19f8..1a98926 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2783,18 +2783,16 @@ static int img_amend(int argc, char **argv)
 if (is_help_option(optarg)) {
 options_help = true;
 } else if (!options) {
-options = optarg;
+options = g_strdup(optarg);
 } else {
-error_report(-o cannot be used multiple times. Please use 
a 
- single -o option with comma-separated 
settings 
- instead.);
-return 1;
+options = g_strdup_printf(%s,%s, options, optarg);
 }
 break;
 case 'f':
 if (fmt) {
 error_report(-f may only be specified once);
-return 1;
+ret = -1;
+goto out;
 }
 fmt = optarg;
 break;
@@ -2850,6 +2848,8 @@ out:
 }
 free_option_parameters(create_options);
 free_option_parameters(options_param);
+g_free(options);
+
 if (ret) {
 return 1;
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH 1/7] qemu-img create: Detect options specified more than once

2014-02-19 Thread Kevin Wolf
If you specified multiple -o options for qemu-img create, it would
silently ignore all but the last one. Similarly, for other options the
last occurence wins (which is at least a bit less surprising). Error out
instead.

The only exception is a -o help option, which may be added to any valid
qemu-img create command and ignores all other options.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-img.c | 32 +---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index c989850..6a64fe1 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -341,13 +341,14 @@ static int img_create(int argc, char **argv)
 {
 int c;
 uint64_t img_size = -1;
-const char *fmt = raw;
+const char *fmt = NULL;
 const char *base_fmt = NULL;
 const char *filename;
 const char *base_filename = NULL;
 char *options = NULL;
 Error *local_err = NULL;
 bool quiet = false;
+bool options_help = false;
 
 for(;;) {
 c = getopt(argc, argv, F:b:f:he6o:q);
@@ -360,12 +361,24 @@ static int img_create(int argc, char **argv)
 help();
 break;
 case 'F':
+if (base_fmt) {
+error_report(-F may only be specified once);
+return 1;
+}
 base_fmt = optarg;
 break;
 case 'b':
+if (base_filename) {
+error_report(-b may only be specified once);
+return 1;
+}
 base_filename = optarg;
 break;
 case 'f':
+if (fmt) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt = optarg;
 break;
 case 'e':
@@ -377,7 +390,16 @@ static int img_create(int argc, char **argv)
   compat6\' instead!);
 return 1;
 case 'o':
-options = optarg;
+if (is_help_option(optarg)) {
+options_help = true;
+} else if (!options) {
+options = optarg;
+} else {
+error_report(-o cannot be used multiple times. Please use a 
+ single -o option with comma-separated settings 
+ instead.);
+return 1;
+}
 break;
 case 'q':
 quiet = true;
@@ -385,6 +407,10 @@ static int img_create(int argc, char **argv)
 }
 }
 
+if (!fmt) {
+fmt = raw;
+}
+
 /* Get the filename */
 if (optind = argc) {
 help();
@@ -413,7 +439,7 @@ static int img_create(int argc, char **argv)
 help();
 }
 
-if (options  is_help_option(options)) {
+if (options_help) {
 return print_block_option_help(filename, fmt);
 }
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 6/7] qemu-img convert: Support multiple -o options

2014-02-19 Thread Kevin Wolf
Multiple -o options has the same meaning as having a single option with
all settings in the order of their respective -o options.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-img.c | 44 ++--
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 30273ad..e0d19f8 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1204,6 +1204,9 @@ static int img_convert(int argc, char **argv)
 Error *local_err = NULL;
 QemuOpts *sn_opts = NULL;
 
+/* Initialize before goto out */
+qemu_progress_init(progress, 1.0);
+
 fmt = NULL;
 out_fmt = NULL;
 cache = NULL;
@@ -1223,21 +1226,24 @@ static int img_convert(int argc, char **argv)
 case 'f':
 if (fmt) {
 error_report(-f may only be specified once);
-return 1;
+ret = -1;
+goto out;
 }
 fmt = optarg;
 break;
 case 'O':
 if (out_fmt) {
 error_report(-O may only be specified once);
-return 1;
+ret = -1;
+goto out;
 }
 out_fmt = optarg;
 break;
 case 'B':
 if (out_baseimg) {
 error_report(-B may only be specified once);
-return 1;
+ret = -1;
+goto out;
 }
 out_baseimg = optarg;
 break;
@@ -1247,41 +1253,43 @@ static int img_convert(int argc, char **argv)
 case 'e':
 error_report(option -e is deprecated, please use \'-o 
   encryption\' instead!);
-return 1;
+ret = -1;
+goto out;
 case '6':
 error_report(option -6 is deprecated, please use \'-o 
   compat6\' instead!);
-return 1;
+ret = -1;
+goto out;
 case 'o':
 if (is_help_option(optarg)) {
 options_help = true;
 } else if (!options) {
-options = optarg;
+options = g_strdup(optarg);
 } else {
-error_report(-o cannot be used multiple times. Please use a 
- single -o option with comma-separated settings 
- instead.);
-return 1;
+options = g_strdup_printf(%s,%s, options, optarg);
 }
 break;
 case 's':
 if (sn_opts || snapshot_name) {
 error_report(-l/-s may only be specified once);
-return 1;
+ret = -1;
+goto out;
 }
 snapshot_name = optarg;
 break;
 case 'l':
 if (sn_opts || snapshot_name) {
 error_report(-l/-s may only be specified once);
-return 1;
+ret = -1;
+goto out;
 }
 if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) {
 sn_opts = qemu_opts_parse(internal_snapshot_opts, optarg, 0);
 if (!sn_opts) {
 error_report(Failed in parsing snapshot param '%s',
  optarg);
-return 1;
+ret = -1;
+goto out;
 }
 } else {
 snapshot_name = optarg;
@@ -1294,7 +1302,8 @@ static int img_convert(int argc, char **argv)
 sval = strtosz_suffix(optarg, end, STRTOSZ_DEFSUFFIX_B);
 if (sval  0 || *end) {
 error_report(Invalid minimum zero buffer size for sparse 
output specified);
-return 1;
+ret = -1;
+goto out;
 }
 
 min_sparse = sval / BDRV_SECTOR_SIZE;
@@ -1306,7 +1315,8 @@ static int img_convert(int argc, char **argv)
 case 't':
 if (cache) {
 error_report(-t may only be specified once);
-return 1;
+ret = -1;
+goto out;
 }
 cache = optarg;
 break;
@@ -1337,9 +1347,6 @@ static int img_convert(int argc, char **argv)
 
 out_filename = argv[argc - 1];
 
-/* Initialize before goto out */
-qemu_progress_init(progress, 1.0);
-
 if (options_help) {
 ret = print_block_option_help(out_filename, out_fmt);
 goto out;
@@ -1733,6 +1740,7 @@ out:
 free_option_parameters(create_options);
 free_option_parameters(param);
 qemu_vfree(buf);
+g_free(options);
 if (sn_opts) {
 qemu_opts_del(sn_opts);
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH 3/7] qemu-img amend: Detect options specified more than once

2014-02-19 Thread Kevin Wolf
Instead of ignoring all option values but the last one, error out if an
option is set multiple times.

Again, the only exception is a -o help option, which may be added to any
valid qemu-img amend command and ignores all other options.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-img.c | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 55c2c75..247987d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2687,6 +2687,7 @@ static int img_amend(int argc, char **argv)
 {
 int c, ret = 0;
 char *options = NULL;
+bool options_help = false;
 QEMUOptionParameter *create_options = NULL, *options_param = NULL;
 const char *fmt = NULL, *filename;
 bool quiet = false;
@@ -2704,9 +2705,22 @@ static int img_amend(int argc, char **argv)
 help();
 break;
 case 'o':
-options = optarg;
+if (is_help_option(optarg)) {
+options_help = true;
+} else if (!options) {
+options = optarg;
+} else {
+error_report(-o cannot be used multiple times. Please use 
a 
+ single -o option with comma-separated 
settings 
+ instead.);
+return 1;
+}
 break;
 case 'f':
+if (fmt) {
+error_report(-f may only be specified once);
+return 1;
+}
 fmt = optarg;
 break;
 case 'q':
@@ -2734,7 +2748,7 @@ static int img_amend(int argc, char **argv)
 
 fmt = bs-drv-format_name;
 
-if (is_help_option(options)) {
+if (options_help) {
 ret = print_block_option_help(filename, fmt);
 goto out;
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH 5/7] qemu-img create: Support multiple -o options

2014-02-19 Thread Kevin Wolf
Multiple -o options has the same meaning as having a single option with
all settings in the order of their respective -o options.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-img.c | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index a889c84..30273ad 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -384,21 +384,18 @@ static int img_create(int argc, char **argv)
 case 'e':
 error_report(option -e is deprecated, please use \'-o 
   encryption\' instead!);
-return 1;
+goto fail;
 case '6':
 error_report(option -6 is deprecated, please use \'-o 
   compat6\' instead!);
-return 1;
+goto fail;
 case 'o':
 if (is_help_option(optarg)) {
 options_help = true;
 } else if (!options) {
-options = optarg;
+options = g_strdup(optarg);
 } else {
-error_report(-o cannot be used multiple times. Please use a 
- single -o option with comma-separated settings 
- instead.);
-return 1;
+options = g_strdup_printf(%s,%s, options, optarg);
 }
 break;
 case 'q':
@@ -431,7 +428,7 @@ static int img_create(int argc, char **argv)
 error_report(kilobytes, megabytes, gigabytes, terabytes, 
  petabytes and exabytes.);
 }
-return 1;
+goto fail;
 }
 img_size = (uint64_t)sval;
 }
@@ -440,6 +437,7 @@ static int img_create(int argc, char **argv)
 }
 
 if (options_help) {
+g_free(options);
 return print_block_option_help(filename, fmt);
 }
 
@@ -448,10 +446,15 @@ static int img_create(int argc, char **argv)
 if (error_is_set(local_err)) {
 error_report(%s: %s, filename, error_get_pretty(local_err));
 error_free(local_err);
-return 1;
+goto fail;
 }
 
+g_free(options);
 return 0;
+
+fail:
+g_free(options);
+return 1;
 }
 
 static void dump_json_image_check(ImageCheck *check, bool quiet)
-- 
1.8.1.4




Re: [Qemu-devel] [PATCH 0/4] Tracetool cleanup

2014-02-19 Thread Lluís Vilanova
Stefan Hajnoczi writes:

 On Mon, Feb 17, 2014 at 08:36:19PM +0100, Lluís Vilanova wrote:
 Minimizes the amount of backend code, making it simpler to add new/different
 backends.
 
 Also performs other cleanups all around.
 
 Signed-off-by: Lluís Vilanova vilan...@ac.upc.edu
 ---
 
 Lluís Vilanova (4):
 trace: [tracetool] Add method 'Event.api' to build event names
 trace: [tracetool,trivial] Style changes
 trace: [tracetool] Identify formats directly used by QEMU
 trace: [tracetool] Minimize the amount of per-backend code

 I think we stretched the concepts of backends and formats too far.
 There are formats that only work with one backend (like 'stap').  And
 there are backends that behave differently from all other backends.

 As a result we're trying to abstract and make common a bunch of stuff
 that isn't really common.  This problem existed before this patch
 series, but I feel we're going further down a direction that
 increasingly seems to be wrong.

 It's simpler if we turn the design inside-out.  Instead of making
 backends export all sorts of interfaces and flags, tracetool should just
 parse trace-events and hand the list over to the backend.

 Let the backend do whatever it wants.  The format option simply becomes
 an option telling the backend which type of output to generate
 (events.h, events.c, .stp, etc).

 Common behavior should live in plain old Python modules/functions.

 TL;DR moving to a library design would simplify and clean up more than
 trying to improve the current framework design

 What do you think?

This series moves into that direction; some of the formats are simply not
handled by backends. For example, the stap, events_c and events_h formats
have no backend-specific contents.

Also, having common code for the format, and then relying on backends for a
small piece of the contents simplifies later patches like the multi-backend
tracing.

The thing here is that maybe we should change format to file, since it
actually refers to a specific output file.


Thanks,
  Lluis

-- 
 And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer.
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth



  1   2   >