[Qemu-devel] [PATCH 40/74] mips_malta: Use cpu_mips_init() to obtain MIPSCPU

2012-06-04 Thread Andreas Färber
Needed for main_cpu_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/mips_malta.c |7 +--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index 4752bb2..d81e8d5 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -788,6 +788,7 @@ void mips_malta_init (ram_addr_t ram_size,
 int64_t kernel_entry;
 PCIBus *pci_bus;
 ISABus *isa_bus;
+MIPSCPU *cpu;
 CPUMIPSState *env;
 qemu_irq *isa_irq;
 qemu_irq *cpu_exit_irq;
@@ -825,11 +826,13 @@ void mips_malta_init (ram_addr_t ram_size,
 }
 
 for (i = 0; i  smp_cpus; i++) {
-env = cpu_init(cpu_model);
-if (!env) {
+cpu = cpu_mips_init(cpu_model);
+if (cpu == NULL) {
 fprintf(stderr, Unable to find CPU definition\n);
 exit(1);
 }
+env = cpu-env;
+
 /* Init internal devices */
 cpu_mips_irq_init_cpu(env);
 cpu_mips_clock_init(env);
-- 
1.7.7




[Qemu-devel] [PATCH 68/74] sun4u: Let cpu_devinit() return SPARCCPU

2012-06-04 Thread Andreas Färber
Needed for main_cpu_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Blue Swirl blauwir...@gmail.com
---
 hw/sun4u.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/sun4u.c b/hw/sun4u.c
index 92b616f..e63ba39 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -752,7 +752,7 @@ static TypeInfo ram_info = {
 .class_init= ram_class_init,
 };
 
-static CPUSPARCState *cpu_devinit(const char *cpu_model, const struct hwdef 
*hwdef)
+static SPARCCPU *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef)
 {
 SPARCCPU *cpu;
 CPUSPARCState *env;
@@ -786,7 +786,7 @@ static CPUSPARCState *cpu_devinit(const char *cpu_model, 
const struct hwdef *hwd
 reset_info-prom_addr = hwdef-prom_addr;
 qemu_register_reset(main_cpu_reset, reset_info);
 
-return env;
+return cpu;
 }
 
 static void sun4uv_init(MemoryRegion *address_space_mem,
@@ -796,6 +796,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
 const char *initrd_filename, const char *cpu_model,
 const struct hwdef *hwdef)
 {
+SPARCCPU *cpu;
 CPUSPARCState *env;
 M48t59State *nvram;
 unsigned int i;
@@ -808,7 +809,8 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
 void *fw_cfg;
 
 /* init CPUs */
-env = cpu_devinit(cpu_model, hwdef);
+cpu = cpu_devinit(cpu_model, hwdef);
+env = cpu-env;
 
 /* set up devices */
 ram_init(0, RAM_size);
-- 
1.7.7




[Qemu-devel] [PATCH 45/74] mips_r4k: Store MIPSCPU in ResetData

2012-06-04 Thread Andreas Färber
Allows us to use cpu_reset() in place of cpu_state_reset() in
main_cpu_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/mips_r4k.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index f89957c..d685999 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -65,7 +65,7 @@ static const MemoryRegionOps mips_qemu_ops = {
 };
 
 typedef struct ResetData {
-CPUMIPSState *env;
+MIPSCPU *cpu;
 uint64_t vector;
 } ResetData;
 
@@ -143,9 +143,9 @@ static int64_t load_kernel(void)
 static void main_cpu_reset(void *opaque)
 {
 ResetData *s = (ResetData *)opaque;
-CPUMIPSState *env = s-env;
+CPUMIPSState *env = s-cpu-env;
 
-cpu_state_reset(env);
+cpu_reset(CPU(s-cpu));
 env-active_tc.PC = s-vector;
 }
 
@@ -188,7 +188,7 @@ void mips_r4k_init (ram_addr_t ram_size,
 env = cpu-env;
 
 reset_info = g_malloc0(sizeof(ResetData));
-reset_info-env = env;
+reset_info-cpu = cpu;
 reset_info-vector = env-active_tc.PC;
 qemu_register_reset(main_cpu_reset, reset_info);
 
-- 
1.7.7




[Qemu-devel] [PATCH 16/74] xtensa_lx60: Pass XtensaCPU to lx60_reset()

2012-06-04 Thread Andreas Färber
Allows us to use cpu_reset() in place of cpu_state_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Max Filippov jcmvb...@gmail.com
---
 hw/xtensa_lx60.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/xtensa_lx60.c b/hw/xtensa_lx60.c
index 31f8adc..b153bfd 100644
--- a/hw/xtensa_lx60.c
+++ b/hw/xtensa_lx60.c
@@ -148,9 +148,9 @@ static uint64_t translate_phys_addr(void *env, uint64_t 
addr)
 
 static void lx60_reset(void *opaque)
 {
-CPUXtensaState *env = opaque;
+XtensaCPU *cpu = opaque;
 
-cpu_state_reset(env);
+cpu_reset(CPU(cpu));
 }
 
 static void lx_init(const LxBoardDesc *board,
@@ -184,7 +184,7 @@ static void lx_init(const LxBoardDesc *board,
 env = cpu-env;
 
 env-sregs[PRID] = n;
-qemu_register_reset(lx60_reset, env);
+qemu_register_reset(lx60_reset, cpu);
 /* Need MMU initialized prior to ELF loading,
  * so that ELF gets loaded into virtual addresses
  */
-- 
1.7.7




[Qemu-devel] [PATCH 31/74] r2d: Use cpu_sh4_init() to obtain SuperHCPU

2012-06-04 Thread Andreas Färber
Needed for main_cpu_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/r2d.c |   10 +++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/hw/r2d.c b/hw/r2d.c
index c55de01..1bd8df6 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -224,6 +224,7 @@ static void r2d_init(ram_addr_t ram_size,
  const char *kernel_filename, const char *kernel_cmdline,
  const char *initrd_filename, const char *cpu_model)
 {
+SuperHCPU *cpu;
 CPUSH4State *env;
 ResetData *reset_info;
 struct SH7750State *s;
@@ -235,14 +236,17 @@ static void r2d_init(ram_addr_t ram_size,
 SysBusDevice *busdev;
 MemoryRegion *address_space_mem = get_system_memory();
 
-if (!cpu_model)
+if (cpu_model == NULL) {
 cpu_model = SH7751R;
+}
 
-env = cpu_init(cpu_model);
-if (!env) {
+cpu = cpu_sh4_init(cpu_model);
+if (cpu == NULL) {
 fprintf(stderr, Unable to find CPU definition\n);
 exit(1);
 }
+env = cpu-env;
+
 reset_info = g_malloc0(sizeof(ResetData));
 reset_info-env = env;
 reset_info-vector = env-pc;
-- 
1.7.7




[Qemu-devel] [PATCH 13/17] rtc: add _version() qidl annotations

2012-06-04 Thread Michael Roth
VMState relies on per-field versioning in some cases. We don't use this
for serialization, but it is needed for proper generation of VMState
field decriptions.

Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
---
 hw/mc146818rtc_state.h |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/mc146818rtc_state.h b/hw/mc146818rtc_state.h
index 9347ee6..3085bed 100644
--- a/hw/mc146818rtc_state.h
+++ b/hw/mc146818rtc_state.h
@@ -20,8 +20,8 @@ qc_declaration typedef struct RTCState {
 /* second update */
 int64_t next_second_time;
 uint16_t _derived irq_reinject_on_ack_count;
-uint32_t irq_coalesced;
-uint32_t period;
+uint32_t _version(2) irq_coalesced;
+uint32_t _version(2) period;
 QEMUTimer _broken *coalesced_timer;
 QEMUTimer *second_timer;
 QEMUTimer *second_timer2;
-- 
1.7.4.1




[Qemu-devel] [PATCH 23/74] petalogix_ml605: Use cpu_mb_init() to obtain MicroBlazeCPU

2012-06-04 Thread Andreas Färber
Needed for microblaze_load_kernel().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Edgar E. Iglesias edgar.igles...@gmail.com
---
 hw/petalogix_ml605_mmu.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/petalogix_ml605_mmu.c b/hw/petalogix_ml605_mmu.c
index 31a4348..6819241 100644
--- a/hw/petalogix_ml605_mmu.c
+++ b/hw/petalogix_ml605_mmu.c
@@ -75,6 +75,7 @@ petalogix_ml605_init(ram_addr_t ram_size,
 {
 MemoryRegion *address_space_mem = get_system_memory();
 DeviceState *dev;
+MicroBlazeCPU *cpu;
 CPUMBState *env;
 DriveInfo *dinfo;
 int i;
@@ -87,7 +88,8 @@ petalogix_ml605_init(ram_addr_t ram_size,
 if (cpu_model == NULL) {
 cpu_model = microblaze;
 }
-env = cpu_init(cpu_model);
+cpu = cpu_mb_init(cpu_model);
+env = cpu-env;
 
 /* Attach emulated BRAM through the LMB.  */
 memory_region_init_ram(phys_lmb_bram, petalogix_ml605.lmb_bram,
-- 
1.7.7




Re: [Qemu-devel] buildbot failure in qemu on default_ppc

2012-06-04 Thread Alexander Graf

On 05.06.2012, at 02:58, Anthony Liguori wrote:

 On 06/05/2012 08:54 AM, Andreas Färber wrote:
 Am 05.06.2012 01:33, schrieb q...@buildbot.b1-systems.de:
 The Buildbot has detected a new failure on builder default_ppc while 
 building qemu.
 Full details are available at:
  http://buildbot.b1-systems.de/qemu/builders/default_ppc/builds/417
 
 Buildbot URL: http://buildbot.b1-systems.de/qemu/
 
 Buildslave for this Build: qemu-ppc.opensuse.org
 
 Build Reason: The Nightly scheduler named 'nightly_default' triggered this 
 build
 Build Source Stamp: [branch master] HEAD
 Blamelist:
 
 BUILD FAILED: failed compile
 
   CCppc-softmmu/kvm-all.o
 /home/build/qemu/default_ppc/build/kvm-all.c:66: error: field 'kroute'
 has incomplete type
 /home/build/qemu/default_ppc/build/kvm-all.c: In function 'kvm_init':
 /home/build/qemu/default_ppc/build/kvm-all.c:1289: error: 'KVMState' has
 no member named 'direct_msi'
 make[1]: *** [kvm-all.o] Error 1
 make: *** [subdir-ppc-softmmu] Error 2
 
 Aren't GSI and even MSI very x86-centric concepts?   Why is this code in 
 kvm-all.c to begin with?

Weren't GSIs a logical APIC map thing? Either way, MSI is not exactly 
x86-centric. You can easily do MSI on ppc as well. I'm not sure if the way it's 
implemented and the way we might one day expose it through an in-kernel 
[X|M]PIC will be identical though.


Alex




[Qemu-devel] [RFC] Use QEMU IDL for device serialization/vmstate

2012-06-04 Thread Michael Roth
These patches are based on qom-next, and can also be obtained from:

git://github.com/mdroth/qemu.git qidl-rfc1

= Overview =

The goal of these patches is to explore how we can leverage an IDL to improve
device serialization/migration.

Patches 1-7 introduce the QIDL compiler and QAPI modification to handle the
QAPI schemas it generates.

Patches 8-12 adds build infrastructure and QIDL annotations to RTC which are
then use to generate visitors which expose RTC's device state via a new QOM
property.

Patches 13-17 adds infrastructure for generating vmstate field descriptions
for RTC using those same annotations.

The procedure for subsequent devices is then, in ideal cases at least, mostly
a matter of moving the device state definitions to header files similar
fashion, adding QIDL annotations, and adding header files to the lists
QIDL_SOURCE and QIDL_SOURCE_VMSTATE lists in Makefile.target.

Non qom-ified devices, or non-devices, can still be handled with open-coded
visitors and legacy registration facilities.

= General/Future Plans =

This is all very much open to discussion, and I only have a general idea of
how we can leverage this to improve migration compatibility/support. That
said:

With everything in place, we'd now have a means to serialize device state into
QObjects (or whatever). We can then perform whatever transformations/mark-up
we need to do (based on capabilities negotation centering around per-device
capabilities, for example), and send the state over the wire for migration.

The wire protocol is then simply a matter of how we encode the transformed
QObject. So a BER protocol could be implemented by creating something analagous
to the JSON-encoding facilities in qjson.c. Or, we could just keep using JSON,
perhaps with compression on top.

Eventually we can extend this approach to send device properties and encode the
actual composition tree in such a way that we can create machine machines on
the target side and avoid the need to duplicate the command-line invocation,
though that will take some substantial re-architecting/removal of the various
factory interfaces and further QOMification.

I'm not planning on incorporating memory migration into this, but it may be
possible to extend this approach to hotplug events/data blocks as well.

Thoughts?

= TODOs =

 - complete QIDL-fication for all common x86 devices
 - make the build system more robust
 - `make check` tests to exercise the automatic detection of device state
   changes (though dirty git trees may be sufficient in-and-of themselves)
 - Work in prototype or considerations for a migration protocol to leverage
   this

 Makefile.objs|6 +
 Makefile.target  |   52 +++-
 hw/mc146818rtc.c |   60 +---
 hw/mc146818rtc_state.h   |   33 ++
 qapi/misc-qapi-visit.c   |   35 ++
 qapi/qapi-visit-core.c   |   25 ++
 qapi/qapi-visit-core.h   |8 +
 qapi/qc.h|   18 +
 qapi/qmp-output-visitor.c|   21 ++
 qidl-generated/mc146818rtc.json  |1 +
 qidl-generated/mc146818rtc_vmstate.h |   20 ++
 scripts/qapi-commands.py |8 +-
 scripts/qapi-types.py|2 +-
 scripts/qapi-visit.py|   90 +-
 scripts/qapi.py  |   10 +-
 scripts/qc.md|  331 +++
 scripts/qc.py|  599 ++
 17 files changed, 1255 insertions(+), 64 deletions(-)




[Qemu-devel] [PATCH 50/74] ppc440_bamboo: Use cpu_ppc_init() to obtain PowerPCCPU

2012-06-04 Thread Andreas Färber
Needed for main_cpu_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Alexander Graf ag...@suse.de
---
 hw/ppc440_bamboo.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index f0a3ae4..1a4e66a 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -172,6 +172,7 @@ static void bamboo_init(ram_addr_t ram_size,
 qemu_irq *pic;
 qemu_irq *irqs;
 PCIBus *pcibus;
+PowerPCCPU *cpu;
 CPUPPCState *env;
 uint64_t elf_entry;
 uint64_t elf_lowaddr;
@@ -185,11 +186,12 @@ static void bamboo_init(ram_addr_t ram_size,
 if (cpu_model == NULL) {
 cpu_model = 440EP;
 }
-env = cpu_init(cpu_model);
-if (!env) {
+cpu = cpu_ppc_init(cpu_model);
+if (cpu == NULL) {
 fprintf(stderr, Unable to initialize CPU!\n);
 exit(1);
 }
+env = cpu-env;
 
 qemu_register_reset(main_cpu_reset, env);
 ppc_booke_timers_init(env, 4, 0);
-- 
1.7.7




[Qemu-devel] [PATCH 53/74] ppc4xx_devs: Pass PowerPCCPU to ppc4xx_reset()

2012-06-04 Thread Andreas Färber
Allows us to use cpu_reset() in place of cpu_state_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Alexander Graf ag...@suse.de
---
 hw/ppc4xx_devs.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/ppc4xx_devs.c b/hw/ppc4xx_devs.c
index 4cefd75..41163e6 100644
--- a/hw/ppc4xx_devs.c
+++ b/hw/ppc4xx_devs.c
@@ -40,9 +40,9 @@
 
 static void ppc4xx_reset(void *opaque)
 {
-CPUPPCState *env = opaque;
+PowerPCCPU *cpu = opaque;
 
-cpu_state_reset(env);
+cpu_reset(CPU(cpu));
 }
 
 /*/
@@ -70,7 +70,7 @@ CPUPPCState *ppc4xx_init (const char *cpu_model,
 tb_clk-opaque = env;
 ppc_dcr_init(env, NULL, NULL);
 /* Register qemu callbacks */
-qemu_register_reset(ppc4xx_reset, env);
+qemu_register_reset(ppc4xx_reset, cpu);
 
 return env;
 }
-- 
1.7.7




[Qemu-devel] [PATCH 03/17] qapi: add visitor interfaces for arrays

2012-06-04 Thread Michael Roth

Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
---
 qapi/qapi-visit-core.c |   25 +
 qapi/qapi-visit-core.h |8 
 scripts/qapi-visit.py  |   26 ++
 3 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 9a29674..482bab6 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -306,3 +306,28 @@ void input_type_enum(Visitor *v, int *obj, const char 
*strings[],
 g_free(enum_str);
 *obj = value;
 }
+
+void visit_start_array(Visitor *v, void **obj, const char *name,
+   size_t elem_count, size_t elem_size, Error **errp)
+{
+g_assert(v-start_array);
+if (!error_is_set(errp)) {
+v-start_array(v, obj, name, elem_count, elem_size, errp);
+}
+}
+
+void visit_next_array(Visitor *v, Error **errp)
+{
+g_assert(v-next_array);
+if (!error_is_set(errp)) {
+v-next_array(v, errp);
+}
+}
+
+void visit_end_array(Visitor *v, Error **errp)
+{
+g_assert(v-end_array);
+if (!error_is_set(errp)) {
+v-end_array(v, errp);
+}
+}
diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h
index a19d70c..19de382 100644
--- a/qapi/qapi-visit-core.h
+++ b/qapi/qapi-visit-core.h
@@ -43,6 +43,10 @@ struct Visitor
 void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
 void (*type_number)(Visitor *v, double *obj, const char *name,
 Error **errp);
+void (*start_array)(Visitor *v, void **obj, const char *name,
+size_t elem_count, size_t elem_size, Error **errp);
+void (*next_array)(Visitor *v, Error **errp);
+void (*end_array)(Visitor *v, Error **errp);
 
 /* May be NULL */
 void (*start_optional)(Visitor *v, bool *present, const char *name,
@@ -88,5 +92,9 @@ void visit_type_int64(Visitor *v, int64_t *obj, const char 
*name, Error **errp);
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
 void visit_type_number(Visitor *v, double *obj, const char *name, Error 
**errp);
+void visit_start_array(Visitor *v, void **obj, const char *name,
+   size_t elem_count, size_t elem_size, Error **errp);
+void visit_next_array(Visitor *v, Error **errp);
+void visit_end_array(Visitor *v, Error **errp);
 
 #endif
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 8d4e94a..3a03537 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -17,6 +17,32 @@ import os
 import getopt
 import errno
 
+def generate_visit_array_body(name, info):
+if info.has_key('array_capacity'):
+array_capacity = info['array_capacity']
+else:
+array_capacity = info['array_size']
+
+if info['array_size'].isdigit():
+array_size = info['array_size']
+else:
+array_size = (*obj)-%s % info['array_size']
+
+ret = mcgen('''
+visit_start_array(m, (void **)obj, %(name)s, %(array_capacity)s, 
sizeof(%(type)s), errp);
+int %(name)s_i;
+for (%(name)s_i = 0; %(name)s_i  %(array_size)s; %(name)s_i++) {
+visit_type_%(type_short)s(m, (*obj)-%(name)s[%(name)s_i], NULL, errp);
+visit_next_array(m, errp);
+}
+visit_end_array(m, errp);
+''',
+name=name, type=c_type(info['type'][0]),
+type_short=info['type'][0],
+array_size=array_size,
+array_capacity=array_capacity)
+return ret
+
 def generate_visit_struct_body(field_prefix, members):
 ret = 
 if len(field_prefix):
-- 
1.7.4.1




[Qemu-devel] [PATCH 51/74] ppc440_bamboo: Pass PowerPCCPU to main_cpu_reset()

2012-06-04 Thread Andreas Färber
Allows us to use cpu_reset() in place of cpu_state_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Alexander Graf ag...@suse.de
---
 hw/ppc440_bamboo.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index 1a4e66a..0dd4dab 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -145,9 +145,10 @@ static void mmubooke_create_initial_mapping(CPUPPCState 
*env,
 
 static void main_cpu_reset(void *opaque)
 {
-CPUPPCState *env = opaque;
+PowerPCCPU *cpu = opaque;
+CPUPPCState *env = cpu-env;
 
-cpu_state_reset(env);
+cpu_reset(CPU(cpu));
 env-gpr[1] = (1620) - 8;
 env-gpr[3] = FDT_ADDR;
 env-nip = entry;
@@ -193,7 +194,7 @@ static void bamboo_init(ram_addr_t ram_size,
 }
 env = cpu-env;
 
-qemu_register_reset(main_cpu_reset, env);
+qemu_register_reset(main_cpu_reset, cpu);
 ppc_booke_timers_init(env, 4, 0);
 ppc_dcr_init(env, NULL, NULL);
 
-- 
1.7.7




[Qemu-devel] [PATCH 22/74] target-microblaze: Let cpu_mb_init() return MicroBlazeCPU

2012-06-04 Thread Andreas Färber
Since qemu_init_vcpu() is no-op for CONFIG_USER_ONLY drop the env
variable that is now unused there.

Turn cpu_init macro into a static inline function returning CPUMBState
for backwards compatibility.

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Edgar E. Iglesias edgar.igles...@gmail.com
---
 target-microblaze/cpu.h   |   12 ++--
 target-microblaze/translate.c |   13 ++---
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/target-microblaze/cpu.h b/target-microblaze/cpu.h
index b0ba9fe..4968c24 100644
--- a/target-microblaze/cpu.h
+++ b/target-microblaze/cpu.h
@@ -272,7 +272,7 @@ struct CPUMBState {
 
 #include cpu-qom.h
 
-CPUMBState *cpu_mb_init(const char *cpu_model);
+MicroBlazeCPU *cpu_mb_init(const char *cpu_model);
 int cpu_mb_exec(CPUMBState *s);
 void cpu_mb_close(CPUMBState *s);
 void do_interrupt(CPUMBState *env);
@@ -295,7 +295,15 @@ enum {
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define cpu_init cpu_mb_init
+static inline CPUMBState *cpu_init(const char *cpu_model)
+{
+MicroBlazeCPU *cpu = cpu_mb_init(cpu_model);
+if (cpu == NULL) {
+return NULL;
+}
+return cpu-env;
+}
+
 #define cpu_exec cpu_mb_exec
 #define cpu_gen_code cpu_mb_gen_code
 #define cpu_signal_handler cpu_mb_signal_handler
diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c
index f0ebd59..3c2936f 100644
--- a/target-microblaze/translate.c
+++ b/target-microblaze/translate.c
@@ -1951,21 +1951,20 @@ void cpu_dump_state (CPUMBState *env, FILE *f, 
fprintf_function cpu_fprintf,
 cpu_fprintf(f, \n\n);
 }
 
-CPUMBState *cpu_mb_init (const char *cpu_model)
+MicroBlazeCPU *cpu_mb_init(const char *cpu_model)
 {
 MicroBlazeCPU *cpu;
-CPUMBState *env;
 static int tcg_initialized = 0;
 int i;
 
 cpu = MICROBLAZE_CPU(object_new(TYPE_MICROBLAZE_CPU));
-env = cpu-env;
 
 cpu_reset(CPU(cpu));
-qemu_init_vcpu(env);
+qemu_init_vcpu(cpu-env);
 
-if (tcg_initialized)
-return env;
+if (tcg_initialized) {
+return cpu;
+}
 
 tcg_initialized = 1;
 
@@ -1999,7 +1998,7 @@ CPUMBState *cpu_mb_init (const char *cpu_model)
 #define GEN_HELPER 2
 #include helper.h
 
-return env;
+return cpu;
 }
 
 void cpu_state_reset(CPUMBState *env)
-- 
1.7.7




[Qemu-devel] [PATCH 60/74] virtex_ml507: Use cpu_ppc_init() to obtain PowerPCCPU

2012-06-04 Thread Andreas Färber
Needed to change ppc440_init_xilinx() return type.

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Alexander Graf ag...@suse.de
---
 hw/virtex_ml507.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/virtex_ml507.c b/hw/virtex_ml507.c
index 4a133b5..3013016 100644
--- a/hw/virtex_ml507.c
+++ b/hw/virtex_ml507.c
@@ -83,14 +83,16 @@ static CPUPPCState *ppc440_init_xilinx(ram_addr_t *ram_size,
 const char *cpu_model,
 uint32_t sysclk)
 {
+PowerPCCPU *cpu;
 CPUPPCState *env;
 qemu_irq *irqs;
 
-env = cpu_init(cpu_model);
-if (!env) {
+cpu = cpu_ppc_init(cpu_model);
+if (cpu == NULL) {
 fprintf(stderr, Unable to initialize CPU!\n);
 exit(1);
 }
+env = cpu-env;
 
 ppc_booke_timers_init(env, sysclk, 0/* no flags */);
 
-- 
1.7.7




[Qemu-devel] [PATCH 04/74] armv7m: Use cpu_arm_init() to obtain ARMCPU

2012-06-04 Thread Andreas Färber
Needed for armv7m_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/armv7m.c |9 ++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/armv7m.c b/hw/armv7m.c
index 4aac076..4e5971c 100644
--- a/hw/armv7m.c
+++ b/hw/armv7m.c
@@ -160,6 +160,7 @@ qemu_irq *armv7m_init(MemoryRegion *address_space_mem,
   int flash_size, int sram_size,
   const char *kernel_filename, const char *cpu_model)
 {
+ARMCPU *cpu;
 CPUARMState *env;
 DeviceState *nvic;
 /* FIXME: make this local state.  */
@@ -177,13 +178,15 @@ qemu_irq *armv7m_init(MemoryRegion *address_space_mem,
 flash_size *= 1024;
 sram_size *= 1024;
 
-if (!cpu_model)
+if (cpu_model == NULL) {
cpu_model = cortex-m3;
-env = cpu_init(cpu_model);
-if (!env) {
+}
+cpu = cpu_arm_init(cpu_model);
+if (cpu == NULL) {
 fprintf(stderr, Unable to find CPU definition\n);
 exit(1);
 }
+env = cpu-env;
 
 #if 0
 /*  32Mb SRAM gets complicated because it overlaps the bitband area.
-- 
1.7.7




[Qemu-devel] [PATCH 28/74] pc: Use cpu_x86_init() to obtain X86CPU

2012-06-04 Thread Andreas Färber
Needed for pc_cpu_reset().

Also change return type to X86CPU.

Signed-off-by: Andreas Färber afaer...@suse.de
Reviewed-by: Igor Mammedov imamm...@redhat.com
---
 hw/pc.c |   10 ++
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index c790bcb..1133921 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -932,21 +932,23 @@ static void pc_cpu_reset(void *opaque)
 env-halted = !cpu_is_bsp(env);
 }
 
-static CPUX86State *pc_new_cpu(const char *cpu_model)
+static X86CPU *pc_new_cpu(const char *cpu_model)
 {
+X86CPU *cpu;
 CPUX86State *env;
 
-env = cpu_init(cpu_model);
-if (!env) {
+cpu = cpu_x86_init(cpu_model);
+if (cpu == NULL) {
 fprintf(stderr, Unable to find x86 CPU definition\n);
 exit(1);
 }
+env = cpu-env;
 if ((env-cpuid_features  CPUID_APIC) || smp_cpus  1) {
 env-apic_state = apic_init(env, env-cpuid_apic_id);
 }
 qemu_register_reset(pc_cpu_reset, env);
 pc_cpu_reset(env);
-return env;
+return cpu;
 }
 
 void pc_cpus_init(const char *cpu_model)
-- 
1.7.7




[Qemu-devel] [PATCH 74/74] Kill off cpu_state_reset()

2012-06-04 Thread Andreas Färber
In commit 1bba0dc932e8826a7d030df3767daf0bc339f9a2 cpu_reset()
was renamed to cpu_state_reset(), to allow introducing a new cpu_reset()
that would operate on QOM objects.

All callers have been updated except for one in target-mips, so drop all
implementations except for the one in target-mips and move the
declaration there until MIPSCPU reset can be fully QOM'ified.

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Michael Walle mich...@walle.cc (for lm32)
Acked-by: Max Filippov jcmvb...@gmail.com (for xtensa)
Acked-by: Edgar E. Iglesias edgar.igles...@gmail.com (for mb + cris)
Acked-by: Alexander Graf ag...@suse.de (for ppc)
Acked-by: Blue Swirl blauwir...@gmail.com
---
 cpu-all.h |1 -
 target-arm/helper.c   |5 -
 target-cris/translate.c   |5 -
 target-i386/helper.c  |6 --
 target-lm32/helper.c  |6 --
 target-m68k/helper.c  |5 -
 target-microblaze/translate.c |5 -
 target-mips/cpu.h |3 +++
 target-ppc/helper.c   |5 -
 target-s390x/helper.c |9 +
 target-sh4/translate.c|5 -
 target-sparc/cpu.c|5 -
 target-xtensa/helper.c|5 -
 13 files changed, 4 insertions(+), 61 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index 028528f..3a93c0c 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -443,7 +443,6 @@ void cpu_watchpoint_remove_all(CPUArchState *env, int mask);
 #define SSTEP_NOTIMER 0x4  /* Do not Timers while single stepping */
 
 void cpu_single_step(CPUArchState *env, int enabled);
-void cpu_state_reset(CPUArchState *s);
 int cpu_is_stopped(CPUArchState *env);
 void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data);
 
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 06ebffc..bbb1d05 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -4,11 +4,6 @@
 #include host-utils.h
 #include sysemu.h
 
-void cpu_state_reset(CPUARMState *env)
-{
-cpu_reset(ENV_GET_CPU(env));
-}
-
 static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg)
 {
 int nregs;
diff --git a/target-cris/translate.c b/target-cris/translate.c
index eed03d3..1ad9ec7 100644
--- a/target-cris/translate.c
+++ b/target-cris/translate.c
@@ -3576,11 +3576,6 @@ CRISCPU *cpu_cris_init(const char *cpu_model)
 return cpu;
 }
 
-void cpu_state_reset(CPUCRISState *env)
-{
-cpu_reset(ENV_GET_CPU(env));
-}
-
 void restore_state_to_opc(CPUCRISState *env, TranslationBlock *tb, int pc_pos)
 {
env-pc = gen_opc_pc[pc_pos];
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 8df109f..2cc8097 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -26,12 +26,6 @@
 
 //#define DEBUG_MMU
 
-/* NOTE: must be called outside the CPU execute loop */
-void cpu_state_reset(CPUX86State *env)
-{
-cpu_reset(ENV_GET_CPU(env));
-}
-
 static void cpu_x86_version(CPUX86State *env, int *family, int *model)
 {
 int cpuver = env-cpuid_version;
diff --git a/target-lm32/helper.c b/target-lm32/helper.c
index 3b1cee7..1ea477f 100644
--- a/target-lm32/helper.c
+++ b/target-lm32/helper.c
@@ -233,9 +233,3 @@ void cpu_lm32_set_phys_msb_ignore(CPULM32State *env, int 
value)
 env-flags = ~LM32_FLAG_IGNORE_MSB;
 }
 }
-
-void cpu_state_reset(CPULM32State *env)
-{
-cpu_reset(ENV_GET_CPU(env));
-}
-
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index f428375..eac0053 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -98,11 +98,6 @@ static int fpu_gdb_set_reg(CPUM68KState *env, uint8_t 
*mem_buf, int n)
 return 0;
 }
 
-void cpu_state_reset(CPUM68KState *env)
-{
-cpu_reset(ENV_GET_CPU(env));
-}
-
 CPUM68KState *cpu_m68k_init(const char *cpu_model)
 {
 M68kCPU *cpu;
diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c
index 3c2936f..02b2dc6 100644
--- a/target-microblaze/translate.c
+++ b/target-microblaze/translate.c
@@ -2001,11 +2001,6 @@ MicroBlazeCPU *cpu_mb_init(const char *cpu_model)
 return cpu;
 }
 
-void cpu_state_reset(CPUMBState *env)
-{
-cpu_reset(ENV_GET_CPU(env));
-}
-
 void restore_state_to_opc(CPUMBState *env, TranslationBlock *tb, int pc_pos)
 {
 env-sregs[SR_PC] = gen_opc_pc[pc_pos];
diff --git a/target-mips/cpu.h b/target-mips/cpu.h
index c7c9cb9..ce3467f 100644
--- a/target-mips/cpu.h
+++ b/target-mips/cpu.h
@@ -637,6 +637,9 @@ static inline CPUMIPSState *cpu_init(const char *cpu_model)
 return cpu-env;
 }
 
+/* TODO QOM'ify CPU reset and remove */
+void cpu_state_reset(CPUMIPSState *s);
+
 /* mips_timer.c */
 uint32_t cpu_mips_get_random (CPUMIPSState *env);
 uint32_t cpu_mips_get_count (CPUMIPSState *env);
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 42f66e8..f556f85 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -3186,11 +3186,6 @@ void cpu_dump_rfi (target_ulong RA, target_ulong msr)
  TARGET_FMT_lx \n, RA, msr);
 }
 
-void 

[Qemu-devel] [PATCH 11/74] milkymist: Store LM32 in ResetInfo

2012-06-04 Thread Andreas Färber
Allows us to use cpu_reset() in place of cpu_state_reset() in
main_cpu_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Michael Walle mich...@walle.cc
---
 hw/milkymist.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/milkymist.c b/hw/milkymist.c
index 59f37b4..2e7235b 100644
--- a/hw/milkymist.c
+++ b/hw/milkymist.c
@@ -37,7 +37,7 @@
 #define KERNEL_LOAD_ADDR 0x4000
 
 typedef struct {
-CPULM32State *env;
+LM32CPU *cpu;
 target_phys_addr_t bootstrap_pc;
 target_phys_addr_t flash_base;
 target_phys_addr_t initrd_base;
@@ -59,9 +59,9 @@ static void cpu_irq_handler(void *opaque, int irq, int level)
 static void main_cpu_reset(void *opaque)
 {
 ResetInfo *reset_info = opaque;
-CPULM32State *env = reset_info-env;
+CPULM32State *env = reset_info-cpu-env;
 
-cpu_state_reset(env);
+cpu_reset(CPU(reset_info-cpu));
 
 /* init defaults */
 env-pc = reset_info-bootstrap_pc;
@@ -108,7 +108,7 @@ milkymist_init(ram_addr_t ram_size_not_used,
 }
 cpu = cpu_lm32_init(cpu_model);
 env = cpu-env;
-reset_info-env = env;
+reset_info-cpu = cpu;
 
 cpu_lm32_set_phys_msb_ignore(env, 1);
 
-- 
1.7.7




[Qemu-devel] [PATCH 08/74] lm32_boards: Use cpu_lm32_init() to obtain LM32CPU

2012-06-04 Thread Andreas Färber
Needed for main_cpu_reset().

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Michael Walle mich...@walle.cc
---
 hw/lm32_boards.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/lm32_boards.c b/hw/lm32_boards.c
index 4dd4f0a..ffb273c 100644
--- a/hw/lm32_boards.c
+++ b/hw/lm32_boards.c
@@ -75,6 +75,7 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used,
   const char *kernel_cmdline,
   const char *initrd_filename, const char *cpu_model)
 {
+LM32CPU *cpu;
 CPULM32State *env;
 DriveInfo *dinfo;
 MemoryRegion *address_space_mem =  get_system_memory();
@@ -101,7 +102,8 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used,
 if (cpu_model == NULL) {
 cpu_model = lm32-full;
 }
-env = cpu_init(cpu_model);
+cpu = cpu_lm32_init(cpu_model);
+env = cpu-env;
 reset_info-env = env;
 
 reset_info-flash_base = flash_base;
@@ -163,6 +165,7 @@ static void lm32_uclinux_init(ram_addr_t ram_size_not_used,
   const char *kernel_cmdline,
   const char *initrd_filename, const char *cpu_model)
 {
+LM32CPU *cpu;
 CPULM32State *env;
 DriveInfo *dinfo;
 MemoryRegion *address_space_mem =  get_system_memory();
@@ -196,7 +199,8 @@ static void lm32_uclinux_init(ram_addr_t ram_size_not_used,
 if (cpu_model == NULL) {
 cpu_model = lm32-full;
 }
-env = cpu_init(cpu_model);
+cpu = cpu_lm32_init(cpu_model);
+env = cpu-env;
 reset_info-env = env;
 
 reset_info-flash_base = flash_base;
-- 
1.7.7




[Qemu-devel] vio-net driver

2012-06-04 Thread Charles . Tsai-蔡清海-研究發展部
We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC driver. 
The VirtIO net driver came from the Ubuntu's default package. The VM we 
installed was configured as a bridge mode. When we ran the Iperf test against 
the VM, the network interface of the VM was fairly unstable. Sometimes, the 
network interface of the VM could not receive the packets and we needed to 
bright the network interface down and up in order to make it work. After we 
replaced the VirtIo Net driver with ne2k driver and it worked quite stably now.



We know that the performance of virtIO is much better than ne2k in virtual 
environment. We would like to use virtio driver instead. If this is the virtio 
driver issue, can you tell us where to get the latest virtIO driver for Ubuntu 
VM? Otherwise, tell us how to make the virtio net driver work in Ubuntu VM if 
you have ever had similar issue before.

The version of Qemu installed in Ubuntu is 1.0


Re: [Qemu-devel] Python problem using MinGW when build QEMU

2012-06-04 Thread Stefan Weil

Am 05.06.2012 01:42, schrieb Arturo CV:

Hello,

Am trying to build the QEMU following this steps:

http://qemu.weilnetz.de/qemu-doc.html#compilation

I got most of the libraries dependencies and followed this other
guides that I found over the net:

http://lassauge.free.fr/qemu/
http://www.gaia-gis.it/spatialite-3.0.0-BETA/mingw_how_to.html

I installed all the libraries that were asking for a good development
environment with the MinGW and MSYS, and then I tried to build the
QEMU image doing:

./configure
make  make install

The configure part went well after the dependencies were fix, but then
I tried the make command and the python error appeared. Apparently
there is missing the python installation in the MinGW environment so I
tried to installed following this steps:

http://www.mingw.org/wiki/FAQ (How do I creat Python extensions?)

It appears that this is the most common way to approach the python
missing error, but it doesn't work for me. I tried using the *.exe
Python installer and also installing it using the source code but
either way there is always errors during the make command, showing
errors like undefined variables and missing Python interpreters.

I don't know what else to try to get the python working with the MinGW
and I needed to finally build the QEMU so can anyone help me out with
this??

Thanks for the time and help :)

Arturo Corrales V.




Hello Arturo,

please try these instructions: http://wiki.qemu.org/Hosts/W32

I use the Python installer from the official Python homepage
and add its installation path to PATH in the MinGW shell.
You will need Python 2.6, not Python 3.

Regards,

Stefan W.







[Qemu-devel] [RFC PATCH 0/5] asynchronous migration state change handlers

2012-06-04 Thread Yonit Halperin
Hi,

I'm sending this patch series again. This time with an additional patch 
for setting a migrate_end notifier completion callback for spice migration
interface. I've also added more detailed commit messages.

This patch series introduces async handlers for notifiers, and integrates them
with migration state change notifications.

Asynchronous migration completion notifier is essential for allowing spice to 
cleanly
complete the src server connection to the client, and transfer the connection 
to the target.
Currently, as soon as the migration completes, the src qemu can be closed by the
management, and spice cannot complete the spice-connection migration.

In order to support spice seamless migration, next to these patches, I plan to 
add:
(1) notifier for switching from the live phase of the migration to the non-live 
phase,
before completing savevm.
Spice will use this notification to finalize the connection to the 
client: send
and receive all in-flight data.
(2) add vmstates for spice data that need to be migrated, e.g., 
usb/agent/smartcard
buffers that were sent from the client and haven't been written to device 
yet.
We would also want to migrate data that will allow us to continue the new 
spice
connection from the same point the old one stopped. Without requiring 
special
treatment in the client side.

Regards,
Yonit.

Yonit Halperin (5):
  notifiers: add support for async notifiers handlers
  migration: moving migration start code to a separated routine
  migration: moving migration completion code to a separated routine
  migration: replace migration state change notifier with async
notifiers
  spice: turn spice migration end handler to be async

 input.c |2 +-
 migration.c |  154 ---
 migration.h |   11 +++-
 notify.c|   78 ++--
 notify.h|   55 ++--
 qemu-timer.c|2 +-
 ui/spice-core.c |   58 +++--
 vl.c|2 +-
 8 files changed, 290 insertions(+), 72 deletions(-)

-- 
1.7.7.6




[Qemu-devel] [RFC PATCH 1/5] notifiers: add support for async notifiers handlers

2012-06-04 Thread Yonit Halperin
This patch defines 2 subtypes of notifiers, sync and async. Both of
them can be added to a notifiers list.
The patch adds optional complete_cb to the notifiers list. complete_cb is called
when all the async notifiers have completed.

Signed-off-by: Yonit Halperin yhalp...@redhat.com
---
 input.c  |2 +-
 migration.c  |2 +-
 notify.c |   78 +++---
 notify.h |   55 +---
 qemu-timer.c |2 +-
 vl.c |2 +-
 6 files changed, 128 insertions(+), 13 deletions(-)

diff --git a/input.c b/input.c
index 6968b31..06f6f9f 100644
--- a/input.c
+++ b/input.c
@@ -274,5 +274,5 @@ void qemu_add_mouse_mode_change_notifier(Notifier *notify)
 
 void qemu_remove_mouse_mode_change_notifier(Notifier *notify)
 {
-notifier_remove(notify);
+notifier_remove(notify-base);
 }
diff --git a/migration.c b/migration.c
index 3f485d3..acaf293 100644
--- a/migration.c
+++ b/migration.c
@@ -320,7 +320,7 @@ void add_migration_state_change_notifier(Notifier *notify)
 
 void remove_migration_state_change_notifier(Notifier *notify)
 {
-notifier_remove(notify);
+notifier_remove(notify-base);
 }
 
 bool migration_is_active(MigrationState *s)
diff --git a/notify.c b/notify.c
index 12282a6..c67e50e 100644
--- a/notify.c
+++ b/notify.c
@@ -19,23 +19,93 @@
 void notifier_list_init(NotifierList *list)
 {
 QLIST_INIT(list-notifiers);
+QLIST_INIT(list-wait_notifiers);
 }
 
 void notifier_list_add(NotifierList *list, Notifier *notifier)
 {
-QLIST_INSERT_HEAD(list-notifiers, notifier, node);
+notifier-base.type = NOTIFIER_TYPE_SYNC;
+QLIST_INSERT_HEAD(list-notifiers, notifier-base, node);
 }
 
-void notifier_remove(Notifier *notifier)
+void notifier_list_add_async(NotifierList *list, AsyncNotifier *notifier)
+{
+notifier-base.type = NOTIFIER_TYPE_ASYNC;
+QLIST_INSERT_HEAD(list-notifiers, notifier-base, node);
+}
+
+void notifier_remove(BaseNotifier *notifier)
 {
 QLIST_REMOVE(notifier, node);
 }
 
+static void notified_complete_cb(AsyncNotifier *notifier, void *opaque)
+{
+NotifierList *list = opaque;
+
+QLIST_REMOVE(notifier, wait_node);
+
+if (QLIST_EMPTY(list-wait_notifiers)  !list-during_notify) {
+if (list-complete_cb) {
+list-complete_cb(list-complete_opaque);
+}
+}
+}
+
 void notifier_list_notify(NotifierList *list, void *data)
 {
-Notifier *notifier, *next;
+BaseNotifier *notifier, *next;
+bool async = false;
+
+if (notifier_list_async_waiting(list)) {
+AsyncNotifier *wait_notifier, *wait_next;
+
+fprintf(stderr, %s: previous notify hasn't completed\n, __func__);
+QLIST_FOREACH_SAFE(wait_notifier, list-wait_notifiers,
+   wait_node, wait_next) {
+QLIST_REMOVE(wait_notifier, wait_node);
+}
+}
+
+list-during_notify = true;
 
 QLIST_FOREACH_SAFE(notifier, list-notifiers, node, next) {
-notifier-notify(notifier, data);
+switch (notifier-type) {
+case NOTIFIER_TYPE_SYNC:
+{
+Notifier *sync_notifier;
+
+sync_notifier = container_of(notifier, Notifier, base);
+sync_notifier-notify(sync_notifier, data);
+break;
+}
+case NOTIFIER_TYPE_ASYNC:
+{
+AsyncNotifier *async_notifier;
+
+async = true;
+async_notifier = container_of(notifier, AsyncNotifier, base);
+QLIST_INSERT_HEAD(list-wait_notifiers,
+  async_notifier,
+  wait_node);
+async_notifier-notify_async(async_notifier, data,
+ notified_complete_cb, list);
+break;
+}
+default:
+fprintf(stderr, %s: invalid notifier type %d\n, __func__,
+notifier-type);
+break;
+}
 }
+
+list-during_notify = false;
+if ((!async || !notifier_list_async_waiting(list))  list-complete_cb) {
+list-complete_cb(list-complete_opaque);
+}
+}
+
+bool notifier_list_async_waiting(NotifierList *list)
+{
+return !QLIST_EMPTY(list-wait_notifiers);
 }
diff --git a/notify.h b/notify.h
index 03cf26c..8660920 100644
--- a/notify.h
+++ b/notify.h
@@ -16,28 +16,73 @@
 
 #include qemu-queue.h
 
+typedef enum NotifierType {
+NOTIFIER_TYPE_NONE,
+NOTIFIER_TYPE_SYNC,
+NOTIFIER_TYPE_ASYNC,
+} NotifierType;
+
+typedef struct BaseNotifier BaseNotifier;
+
+struct BaseNotifier {
+QLIST_ENTRY(BaseNotifier) node;
+NotifierType type;
+};
 typedef struct Notifier Notifier;
 
 struct Notifier
 {
+BaseNotifier base;
 void (*notify)(Notifier *notifier, void *data);
-QLIST_ENTRY(Notifier) node;
 };
 
+typedef struct AsyncNotifier AsyncNotifier;
+typedef void (NotifiedCompletionFunc)(AsyncNotifier 

[Qemu-devel] [RFC PATCH 2/5] migration: moving migration start code to a separated routine

2012-06-04 Thread Yonit Halperin
Preparation for asynchronous migration state change notifiers.
In a following patch the migrate_start routine will be used as
the completion callback of the migration start notifiers list.

Signed-off-by: Yonit Halperin yhalp...@redhat.com
---
 migration.c |   73 +-
 migration.h |2 +
 2 files changed, 58 insertions(+), 17 deletions(-)

diff --git a/migration.c b/migration.c
index acaf293..91c807d 100644
--- a/migration.c
+++ b/migration.c
@@ -41,6 +41,14 @@ enum {
 MIG_STATE_COMPLETED,
 };
 
+enum {
+   MIGRATION_PROTOCOL_ERROR,
+   MIGRATION_PROTOCOL_TCP,
+   MIGRATION_PROTOCOL_EXEC,
+   MIGRATION_PROTOCOL_UNIX,
+   MIGRATION_PROTOCOL_FD,
+};
+
 #define MAX_THROTTLE  (32  20)  /* Migration speed throttling */
 
 static NotifierList migration_state_notifiers =
@@ -361,13 +369,16 @@ void migrate_fd_connect(MigrationState *s)
 migrate_fd_put_ready(s);
 }
 
-static MigrationState *migrate_init(int blk, int inc)
+static MigrationState *migrate_init(int protocol, const char *protocol_param,
+int blk, int inc)
 {
 MigrationState *s = migrate_get_current();
 int64_t bandwidth_limit = s-bandwidth_limit;
 
 memset(s, 0, sizeof(*s));
 s-bandwidth_limit = bandwidth_limit;
+s-protocol = protocol;
+s-protocol_param = g_strdup(protocol_param);
 s-blk = blk;
 s-shared = inc;
 
@@ -389,13 +400,50 @@ void migrate_del_blocker(Error *reason)
 migration_blockers = g_slist_remove(migration_blockers, reason);
 }
 
+static void migrate_start(MigrationState *s, Error **errp)
+{
+int ret;
+
+switch (s-protocol) {
+case MIGRATION_PROTOCOL_TCP:
+ret = tcp_start_outgoing_migration(s, s-protocol_param, errp);
+break;
+#if !defined(WIN32)
+case MIGRATION_PROTOCOL_EXEC:
+ret = exec_start_outgoing_migration(s, s-protocol_param);
+break;
+case MIGRATION_PROTOCOL_UNIX:
+ret = unix_start_outgoing_migration(s, s-protocol_param);
+break;
+case MIGRATION_PROTOCOL_FD:
+ret = fd_start_outgoing_migration(s, s-protocol_param);
+break;
+#endif
+default:
+ret = -EPROTONOSUPPORT;
+}
+
+g_free(s-protocol_param);
+s-protocol_param = NULL;
+
+if (ret  0) {
+if (!error_is_set(errp)) {
+DPRINTF(migration failed: %s\n, strerror(-ret));
+/* FIXME: we should return meaningful errors */
+error_set(errp, QERR_UNDEFINED_ERROR);
+}
+return;
+}
+notifier_list_notify(migration_state_notifiers, s);
+}
+
 void qmp_migrate(const char *uri, bool has_blk, bool blk,
  bool has_inc, bool inc, bool has_detach, bool detach,
  Error **errp)
 {
 MigrationState *s = migrate_get_current();
 const char *p;
-int ret;
+int migrate_protocol;
 
 if (s-state == MIG_STATE_ACTIVE) {
 error_set(errp, QERR_MIGRATION_ACTIVE);
@@ -411,33 +459,24 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 return;
 }
 
-s = migrate_init(blk, inc);
-
 if (strstart(uri, tcp:, p)) {
-ret = tcp_start_outgoing_migration(s, p, errp);
+migrate_protocol = MIGRATION_PROTOCOL_TCP;
 #if !defined(WIN32)
 } else if (strstart(uri, exec:, p)) {
-ret = exec_start_outgoing_migration(s, p);
+migrate_protocol = MIGRATION_PROTOCOL_EXEC;
 } else if (strstart(uri, unix:, p)) {
-ret = unix_start_outgoing_migration(s, p);
+migrate_protocol = MIGRATION_PROTOCOL_UNIX;
 } else if (strstart(uri, fd:, p)) {
-ret = fd_start_outgoing_migration(s, p);
+migrate_protocol = MIGRATION_PROTOCOL_FD;
 #endif
 } else {
 error_set(errp, QERR_INVALID_PARAMETER_VALUE, uri, a valid 
migration protocol);
 return;
 }
+s = migrate_init(migrate_protocol, p, blk, inc);
 
-if (ret  0) {
-if (!error_is_set(errp)) {
-DPRINTF(migration failed: %s\n, strerror(-ret));
-/* FIXME: we should return meaningful errors */
-error_set(errp, QERR_UNDEFINED_ERROR);
-}
-return;
-}
+migrate_start(s, errp);
 
-notifier_list_notify(migration_state_notifiers, s);
 }
 
 void qmp_migrate_cancel(Error **errp)
diff --git a/migration.h b/migration.h
index 2e9ca2e..5ad67d7 100644
--- a/migration.h
+++ b/migration.h
@@ -33,6 +33,8 @@ struct MigrationState
 void *opaque;
 int blk;
 int shared;
+int protocol;
+char *protocol_param;
 };
 
 void process_incoming_migration(QEMUFile *f);
-- 
1.7.7.6




Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012-06-04 Thread mathslinux
Charles.Tsai-蔡清海-研究發展部 charles.t...@cloudena.com writes:

 We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC 
 driver. The VirtIO net driver came from the Ubuntu's default package. The VM 
 we installed was configured as a bridge mode. When we ran the Iperf test 
 against the VM, the network interface of the VM was fairly unstable. 
 Sometimes, the network interface of the VM could not receive the packets and 
 we needed to bright the network interface down and up in order to make it 
 work. After we replaced the VirtIo Net driver with ne2k driver and it worked 
 quite stably now.

 We know that the performance of virtIO is much better than ne2k in virtual 
 environment. We would like to use virtio driver instead. If this is the 
 virtio driver issue, can you tell us where to get the latest virtIO driver 
 for Ubuntu VM? Otherwise, tell us how to make the virtio net driver work in 
 Ubuntu VM if you have ever had similar issue before.

 The version of Qemu installed in Ubuntu is 0.14.1.

The virtio driver is implemented in the guest operating system, it's a
kernel module, so what is your kernel version? Maybe you need a kernel
of higher version.
-- 
linuxer, emacser and pythoner living in beijing
blog: http://mathslinux.org
twitter: https://twitter.com/mathslinux
google+: https://plus.google.com/118129852578326338750



Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012-06-04 Thread Charles . Tsai-蔡清海-研究發展部
The kernel version is 3.0.0.12
The Qemu version is 1.0.0(we upgraded it)

What version of kernel do we need to upgrade?

-Original Message-
From: mathslinux [mailto:riegama...@gmail.com] 
Sent: Monday, June 04, 2012 2:03 PM
To: Charles.Tsai-蔡清海-研究發展部
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

Charles.Tsai-蔡清海-研究發展部 charles.t...@cloudena.com writes:

 We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC 
 driver. The VirtIO net driver came from the Ubuntu's default package. The VM 
 we installed was configured as a bridge mode. When we ran the Iperf test 
 against the VM, the network interface of the VM was fairly unstable. 
 Sometimes, the network interface of the VM could not receive the packets and 
 we needed to bright the network interface down and up in order to make it 
 work. After we replaced the VirtIo Net driver with ne2k driver and it worked 
 quite stably now.

 We know that the performance of virtIO is much better than ne2k in virtual 
 environment. We would like to use virtio driver instead. If this is the 
 virtio driver issue, can you tell us where to get the latest virtIO driver 
 for Ubuntu VM? Otherwise, tell us how to make the virtio net driver work in 
 Ubuntu VM if you have ever had similar issue before.

 The version of Qemu installed in Ubuntu is 0.14.1.

The virtio driver is implemented in the guest operating system, it's a kernel 
module, so what is your kernel version? Maybe you need a kernel of higher 
version.
--
linuxer, emacser and pythoner living in beijing
blog: http://mathslinux.org
twitter: https://twitter.com/mathslinux
google+: https://plus.google.com/118129852578326338750


[Qemu-devel] [PATCH v4 16/16] hub: add the support for hub own flow control

2012-06-04 Thread zwu . kernel
From: Zhi Yong Wu wu...@linux.vnet.ibm.com

Only when all other hub port's *peer* .can_receive() all return 1,
the source hub port .can_receive() return 1.

Reviewed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 net/hub.c |   27 ---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/net/hub.c b/net/hub.c
index 230d86a..efd90b5 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -15,6 +15,7 @@
 #include monitor.h
 #include net.h
 #include hub.h
+#include iov.h
 
 /*
  * A hub broadcasts incoming packets to all its ports except the source port.
@@ -59,16 +60,16 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort 
*source_port,
const struct iovec *iov, int iovcnt)
 {
 NetHubPort *port;
-ssize_t ret = 0;
+ssize_t len = iov_size(iov, iovcnt);
 
 QLIST_FOREACH(port, hub-ports, next) {
 if (port == source_port) {
 continue;
 }
 
-ret = qemu_sendv_packet(port-nc, iov, iovcnt);
+qemu_sendv_packet(port-nc, iov, iovcnt);
 }
-return ret;
+return len;
 }
 
 static NetHub *net_hub_new(unsigned int id)
@@ -85,6 +86,25 @@ static NetHub *net_hub_new(unsigned int id)
 return hub;
 }
 
+static int net_hub_port_can_receive(NetClientState *nc)
+{
+NetHubPort *port;
+NetHubPort *src_port = DO_UPCAST(NetHubPort, nc, nc);
+NetHub *hub = src_port-hub;
+
+QLIST_FOREACH(port, hub-ports, next) {
+if (port == src_port) {
+continue;
+}
+
+if (!qemu_can_send_packet(port-nc)) {
+return 0;
+}
+}
+
+return 1;
+}
+
 static ssize_t net_hub_port_receive(NetClientState *nc,
 const uint8_t *buf, size_t len)
 {
@@ -111,6 +131,7 @@ static void net_hub_port_cleanup(NetClientState *nc)
 static NetClientInfo net_hub_port_info = {
 .type = NET_CLIENT_TYPE_HUB,
 .size = sizeof(NetHubPort),
+.can_receive = net_hub_port_can_receive,
 .receive = net_hub_port_receive,
 .receive_iov = net_hub_port_receive_iov,
 .cleanup = net_hub_port_cleanup,
-- 
1.7.6




Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012-06-04 Thread Dunrong Huang
2012/6/4 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com:
 The kernel version is 3.0.0.12
 The Qemu version is 1.0.0(we upgraded it)

 What version of kernel do we need to upgrade?
The latest version is v3.4, so you can try and upgrade to v3.1, v3.2
or v3.3, and test
it.

 -Original Message-
 From: mathslinux [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:03 PM
 To: Charles.Tsai-蔡清海-研究�l展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com writes:

 We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC 
 driver. The VirtIO net driver came from the Ubuntu's default package. The VM 
 we installed was configured as a bridge mode. When we ran the Iperf test 
 against the VM, the network interface of the VM was fairly unstable. 
 Sometimes, the network interface of the VM could not receive the packets and 
 we needed to bright the network interface down and up in order to make it 
 work. After we replaced the VirtIo Net driver with ne2k driver and it worked 
 quite stably now.

 We know that the performance of virtIO is much better than ne2k in virtual 
 environment. We would like to use virtio driver instead. If this is the 
 virtio driver issue, can you tell us where to get the latest virtIO driver 
 for Ubuntu VM? Otherwise, tell us how to make the virtio net driver work in 
 Ubuntu VM if you have ever had similar issue before.

 The version of Qemu installed in Ubuntu is 0.14.1.

 The virtio driver is implemented in the guest operating system, it's a kernel 
 module, so what is your kernel version? Maybe you need a kernel of higher 
 version.




-- 
linuxer and emacser and pythoner living in beijing
blog: http://mathslinux.org
twitter: https://twitter.com/mathslinux
google+: https://plus.google.com/118129852578326338750



Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012-06-04 Thread Dunrong Huang
2012/6/4 Dunrong Huang riegama...@gmail.com:
 2012/6/4 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com:
 The kernel version is 3.0.0.12
 The Qemu version is 1.0.0(we upgraded it)

 What version of kernel do we need to upgrade?
 The latest version is v3.4, so you can try and upgrade to v3.1, v3.2
 or v3.3, and test
 it.
Or upgrade your ubuntu VM.

 -Original Message-
 From: mathslinux [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:03 PM
 To: Charles.Tsai-蔡清海-研究�l展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com writes:

 We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC 
 driver. The VirtIO net driver came from the Ubuntu's default package. The 
 VM we installed was configured as a bridge mode. When we ran the Iperf test 
 against the VM, the network interface of the VM was fairly unstable. 
 Sometimes, the network interface of the VM could not receive the packets 
 and we needed to bright the network interface down and up in order to make 
 it work. After we replaced the VirtIo Net driver with ne2k driver and it 
 worked quite stably now.

 We know that the performance of virtIO is much better than ne2k in virtual 
 environment. We would like to use virtio driver instead. If this is the 
 virtio driver issue, can you tell us where to get the latest virtIO driver 
 for Ubuntu VM? Otherwise, tell us how to make the virtio net driver work in 
 Ubuntu VM if you have ever had similar issue before.

 The version of Qemu installed in Ubuntu is 0.14.1.

 The virtio driver is implemented in the guest operating system, it's a 
 kernel module, so what is your kernel version? Maybe you need a kernel of 
 higher version.


-- 
linuxer, emacser and pythoner living in beijing
blog: http://mathslinux.org
twitter: https://twitter.com/mathslinux
google+: https://plus.google.com/118129852578326338750



Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012-06-04 Thread Charles . Tsai-蔡清海-研究發展部
I am just curious about this issue. Is there any document mentioning the lowest 
version of the kernel to be supported by VirtIO?


-Original Message-
From: Dunrong Huang [mailto:riegama...@gmail.com] 
Sent: Monday, June 04, 2012 2:17 PM
To: Charles.Tsai-蔡清海-研究發展部
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012/6/4 Charles.Tsai-蔡清海-研究發展部 charles.t...@cloudena.com:
 The kernel version is 3.0.0.12
 The Qemu version is 1.0.0(we upgraded it)

 What version of kernel do we need to upgrade?
The latest version is v3.4, so you can try and upgrade to v3.1, v3.2 or v3.3, 
and test it.

 -Original Message-
 From: mathslinux [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:03 PM
 To: Charles.Tsai-蔡清海-研究發展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 Charles.Tsai-蔡清海-研究發展部 charles.t...@cloudena.com writes:

 We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC 
 driver. The VirtIO net driver came from the Ubuntu's default package. The VM 
 we installed was configured as a bridge mode. When we ran the Iperf test 
 against the VM, the network interface of the VM was fairly unstable. 
 Sometimes, the network interface of the VM could not receive the packets and 
 we needed to bright the network interface down and up in order to make it 
 work. After we replaced the VirtIo Net driver with ne2k driver and it worked 
 quite stably now.

 We know that the performance of virtIO is much better than ne2k in virtual 
 environment. We would like to use virtio driver instead. If this is the 
 virtio driver issue, can you tell us where to get the latest virtIO driver 
 for Ubuntu VM? Otherwise, tell us how to make the virtio net driver work in 
 Ubuntu VM if you have ever had similar issue before.

 The version of Qemu installed in Ubuntu is 0.14.1.

 The virtio driver is implemented in the guest operating system, it's a kernel 
 module, so what is your kernel version? Maybe you need a kernel of higher 
 version.




--
linuxer and emacser and pythoner living in beijing
blog: http://mathslinux.org
twitter: https://twitter.com/mathslinux
google+: https://plus.google.com/118129852578326338750


[Qemu-devel] [PATCH v4 07/16] net: Remove vlan code from net.c

2012-06-04 Thread zwu . kernel
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

The vlan implementation in net.c has been replaced by hubs so we can
remove the code.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 hw/xen_nic.c |1 -
 net.c|  108 --
 net.h|1 -
 3 files changed, 0 insertions(+), 110 deletions(-)

diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 9a59bda..85526fe 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -328,7 +328,6 @@ static int net_init(struct XenDevice *xendev)
 return -1;
 }
 
-netdev-conf.vlan = qemu_find_vlan(netdev-xendev.dev, 1);
 netdev-conf.peer = NULL;
 
 netdev-nic = qemu_new_nic(net_xen_info, netdev-conf,
diff --git a/net.c b/net.c
index 96252f9..abf5a3d 100644
--- a/net.c
+++ b/net.c
@@ -388,50 +388,6 @@ static ssize_t qemu_deliver_packet(VLANClientState *sender,
 return ret;
 }
 
-static ssize_t qemu_vlan_deliver_packet(VLANClientState *sender,
-unsigned flags,
-const uint8_t *buf,
-size_t size,
-void *opaque)
-{
-VLANState *vlan = opaque;
-VLANClientState *vc;
-ssize_t ret = -1;
-
-QTAILQ_FOREACH(vc, vlan-clients, next) {
-ssize_t len;
-
-if (vc == sender) {
-continue;
-}
-
-if (vc-link_down) {
-ret = size;
-continue;
-}
-
-if (vc-receive_disabled) {
-ret = 0;
-continue;
-}
-
-if (flags  QEMU_NET_PACKET_FLAG_RAW  vc-info-receive_raw) {
-len = vc-info-receive_raw(vc, buf, size);
-} else {
-len = vc-info-receive(vc, buf, size);
-}
-
-if (len == 0) {
-vc-receive_disabled = 1;
-}
-
-ret = (ret = 0) ? ret : len;
-
-}
-
-return ret;
-}
-
 void qemu_purge_queued_packets(VLANClientState *vc)
 {
 NetQueue *queue;
@@ -538,42 +494,6 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState 
*sender,
 }
 }
 
-static ssize_t qemu_vlan_deliver_packet_iov(VLANClientState *sender,
-unsigned flags,
-const struct iovec *iov,
-int iovcnt,
-void *opaque)
-{
-VLANState *vlan = opaque;
-VLANClientState *vc;
-ssize_t ret = -1;
-
-QTAILQ_FOREACH(vc, vlan-clients, next) {
-ssize_t len;
-
-if (vc == sender) {
-continue;
-}
-
-if (vc-link_down) {
-ret = iov_size(iov, iovcnt);
-continue;
-}
-
-assert(!(flags  QEMU_NET_PACKET_FLAG_RAW));
-
-if (vc-info-receive_iov) {
-len = vc-info-receive_iov(vc, iov, iovcnt);
-} else {
-len = vc_sendv_compat(vc, iov, iovcnt);
-}
-
-ret = (ret = 0) ? ret : len;
-}
-
-return ret;
-}
-
 ssize_t qemu_sendv_packet_async(VLANClientState *sender,
 const struct iovec *iov, int iovcnt,
 NetPacketSent *sent_cb)
@@ -601,34 +521,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec 
*iov, int iovcnt)
 return qemu_sendv_packet_async(vc, iov, iovcnt, NULL);
 }
 
-/* find or alloc a new VLAN */
-VLANState *qemu_find_vlan(int id, int allocate)
-{
-VLANState *vlan;
-
-QTAILQ_FOREACH(vlan, vlans, next) {
-if (vlan-id == id) {
-return vlan;
-}
-}
-
-if (!allocate) {
-return NULL;
-}
-
-vlan = g_malloc0(sizeof(VLANState));
-vlan-id = id;
-QTAILQ_INIT(vlan-clients);
-
-vlan-send_queue = qemu_new_net_queue(qemu_vlan_deliver_packet,
-  qemu_vlan_deliver_packet_iov,
-  vlan);
-
-QTAILQ_INSERT_TAIL(vlans, vlan, next);
-
-return vlan;
-}
-
 VLANClientState *qemu_find_netdev(const char *id)
 {
 VLANClientState *vc;
diff --git a/net.h b/net.h
index 7d18b10..a4ac48d 100644
--- a/net.h
+++ b/net.h
@@ -87,7 +87,6 @@ struct VLANState {
 NetQueue *send_queue;
 };
 
-VLANState *qemu_find_vlan(int id, int allocate);
 VLANClientState *qemu_find_netdev(const char *id);
 VLANClientState *qemu_new_net_client(NetClientInfo *info,
  VLANClientState *peer,
-- 
1.7.6




[Qemu-devel] [PATCH v4 06/16] net: Remove vlan qdev property

2012-06-04 Thread zwu . kernel
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

The vlan feature is implemented using hubs and no longer uses
special-purpose VLANState structs that are accessible as qdev
properties.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 hw/qdev-properties.c |   72 --
 hw/qdev.c|2 -
 hw/qdev.h|4 ---
 net.h|3 --
 4 files changed, 0 insertions(+), 81 deletions(-)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index b7b5597..d2e2afb 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -623,71 +623,6 @@ PropertyInfo qdev_prop_netdev = {
 .set   = set_netdev,
 };
 
-/* --- vlan --- */
-
-static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
-{
-VLANState **ptr = qdev_get_prop_ptr(dev, prop);
-
-if (*ptr) {
-return snprintf(dest, len, %d, (*ptr)-id);
-} else {
-return snprintf(dest, len, null);
-}
-}
-
-static void get_vlan(Object *obj, Visitor *v, void *opaque,
- const char *name, Error **errp)
-{
-DeviceState *dev = DEVICE(obj);
-Property *prop = opaque;
-VLANState **ptr = qdev_get_prop_ptr(dev, prop);
-int64_t id;
-
-id = *ptr ? (*ptr)-id : -1;
-visit_type_int(v, id, name, errp);
-}
-
-static void set_vlan(Object *obj, Visitor *v, void *opaque,
- const char *name, Error **errp)
-{
-DeviceState *dev = DEVICE(obj);
-Property *prop = opaque;
-VLANState **ptr = qdev_get_prop_ptr(dev, prop);
-Error *local_err = NULL;
-int64_t id;
-VLANState *vlan;
-
-if (dev-state != DEV_STATE_CREATED) {
-error_set(errp, QERR_PERMISSION_DENIED);
-return;
-}
-
-visit_type_int(v, id, name, local_err);
-if (local_err) {
-error_propagate(errp, local_err);
-return;
-}
-if (id == -1) {
-*ptr = NULL;
-return;
-}
-vlan = qemu_find_vlan(id, 1);
-if (!vlan) {
-error_set(errp, QERR_INVALID_PARAMETER_VALUE,
-  name, prop-info-name);
-return;
-}
-*ptr = vlan;
-}
-
-PropertyInfo qdev_prop_vlan = {
-.name  = vlan,
-.print = print_vlan,
-.get   = get_vlan,
-.set   = set_vlan,
-};
-
 /* --- pointer --- */
 
 /* Not a proper property, just for dirty hacks.  TODO Remove it!  */
@@ -1094,13 +1029,6 @@ void qdev_prop_set_netdev(DeviceState *dev, const char 
*name, VLANClientState *v
 assert_no_error(errp);
 }
 
-void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
-{
-Error *errp = NULL;
-object_property_set_int(OBJECT(dev), value ? value-id : -1, name, errp);
-assert_no_error(errp);
-}
-
 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
 {
 Error *errp = NULL;
diff --git a/hw/qdev.c b/hw/qdev.c
index 6a8f6bd..49dd303 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -316,8 +316,6 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, 
qemu_irq pin)
 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
 {
 qdev_prop_set_macaddr(dev, mac, nd-macaddr.a);
-if (nd-vlan)
-qdev_prop_set_vlan(dev, vlan, nd-vlan);
 if (nd-netdev)
 qdev_prop_set_netdev(dev, netdev, nd-netdev);
 if (nd-nvectors != DEV_NVECTORS_UNSPECIFIED 
diff --git a/hw/qdev.h b/hw/qdev.h
index 4e90119..0a50a40 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -222,7 +222,6 @@ extern PropertyInfo qdev_prop_macaddr;
 extern PropertyInfo qdev_prop_losttickpolicy;
 extern PropertyInfo qdev_prop_drive;
 extern PropertyInfo qdev_prop_netdev;
-extern PropertyInfo qdev_prop_vlan;
 extern PropertyInfo qdev_prop_pci_devfn;
 extern PropertyInfo qdev_prop_blocksize;
 
@@ -277,8 +276,6 @@ extern PropertyInfo qdev_prop_blocksize;
 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
-#define DEFINE_PROP_VLAN(_n, _s, _f) \
-DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
@@ -305,7 +302,6 @@ void qdev_prop_set_uint64(DeviceState *dev, const char 
*name, uint64_t value);
 void qdev_prop_set_string(DeviceState *dev, const char *name, char *value);
 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState 
*value);
 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState 
*value);
-void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState 
*value) QEMU_WARN_UNUSED_RESULT;
 void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, 
BlockDriverState *value);
 void qdev_prop_set_macaddr(DeviceState *dev, 

Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012-06-04 Thread Dunrong Huang
2012/6/4 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com:
 I am just curious about this issue. Is there any document mentioning the 
 lowest version of the kernel to be supported by VirtIO?

See http://www.linux-kvm.org/page/Virtio

 -Original Message-
 From: Dunrong Huang [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:17 PM
 To: Charles.Tsai-蔡清海-研究�l展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 2012/6/4 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com:
 The kernel version is 3.0.0.12
 The Qemu version is 1.0.0(we upgraded it)

 What version of kernel do we need to upgrade?
 The latest version is v3.4, so you can try and upgrade to v3.1, v3.2 or v3.3, 
 and test it.

 -Original Message-
 From: mathslinux [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:03 PM
 To: Charles.Tsai-蔡清海-研究�l展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com writes:

 We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC 
 driver. The VirtIO net driver came from the Ubuntu's default package. The 
 VM we installed was configured as a bridge mode. When we ran the Iperf test 
 against the VM, the network interface of the VM was fairly unstable. 
 Sometimes, the network interface of the VM could not receive the packets 
 and we needed to bright the network interface down and up in order to make 
 it work. After we replaced the VirtIo Net driver with ne2k driver and it 
 worked quite stably now.

 We know that the performance of virtIO is much better than ne2k in virtual 
 environment. We would like to use virtio driver instead. If this is the 
 virtio driver issue, can you tell us where to get the latest virtIO driver 
 for Ubuntu VM? Otherwise, tell us how to make the virtio net driver work in 
 Ubuntu VM if you have ever had similar issue before.

 The version of Qemu installed in Ubuntu is 0.14.1.

 The virtio driver is implemented in the guest operating system, it's a 
 kernel module, so what is your kernel version? Maybe you need a kernel of 
 higher version.



-- 
linuxer and emacser and pythoner living in beijing
blog: http://mathslinux.org
twitter: https://twitter.com/mathslinux
google+: https://plus.google.com/118129852578326338750



Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012-06-04 Thread Charles . Tsai-蔡清海-研究發展部
Yes, I saw that page too. But our current kernel version meets the kernel 
requirement.
Why do we need to upgrade it?

-Original Message-
From: Dunrong Huang [mailto:riegama...@gmail.com] 
Sent: Monday, June 04, 2012 2:26 PM
To: Charles.Tsai-蔡清海-研究發展部
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012/6/4 Charles.Tsai-蔡清海-研究發展部 charles.t...@cloudena.com:
 I am just curious about this issue. Is there any document mentioning the 
 lowest version of the kernel to be supported by VirtIO?

See http://www.linux-kvm.org/page/Virtio

 -Original Message-
 From: Dunrong Huang [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:17 PM
 To: Charles.Tsai-蔡清海-研究發展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 2012/6/4 Charles.Tsai-蔡清海-研究發展部 charles.t...@cloudena.com:
 The kernel version is 3.0.0.12
 The Qemu version is 1.0.0(we upgraded it)

 What version of kernel do we need to upgrade?
 The latest version is v3.4, so you can try and upgrade to v3.1, v3.2 or v3.3, 
 and test it.

 -Original Message-
 From: mathslinux [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:03 PM
 To: Charles.Tsai-蔡清海-研究發展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 Charles.Tsai-蔡清海-研究發展部 charles.t...@cloudena.com writes:

 We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC 
 driver. The VirtIO net driver came from the Ubuntu's default package. The 
 VM we installed was configured as a bridge mode. When we ran the Iperf test 
 against the VM, the network interface of the VM was fairly unstable. 
 Sometimes, the network interface of the VM could not receive the packets 
 and we needed to bright the network interface down and up in order to make 
 it work. After we replaced the VirtIo Net driver with ne2k driver and it 
 worked quite stably now.

 We know that the performance of virtIO is much better than ne2k in virtual 
 environment. We would like to use virtio driver instead. If this is the 
 virtio driver issue, can you tell us where to get the latest virtIO driver 
 for Ubuntu VM? Otherwise, tell us how to make the virtio net driver work in 
 Ubuntu VM if you have ever had similar issue before.

 The version of Qemu installed in Ubuntu is 0.14.1.

 The virtio driver is implemented in the guest operating system, it's a 
 kernel module, so what is your kernel version? Maybe you need a kernel of 
 higher version.



-- 
linuxer and emacser and pythoner living in beijing
blog: http://mathslinux.org
twitter: https://twitter.com/mathslinux
google+: https://plus.google.com/118129852578326338750


[Qemu-devel] [PATCH v4 09/16] net: Rename non_vlan_clients to net_clients

2012-06-04 Thread zwu . kernel
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

There is no longer a distinction between vlan clients and non-vlan
clients in the net core.  The net core only knows about point-to-point
clients which are connected to a peer.  It's time to rename the global
list of net clients since it no longer refers to vlans at all.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 net.c |   20 ++--
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/net.c b/net.c
index eb2ad06..2ca4285 100644
--- a/net.c
+++ b/net.c
@@ -44,7 +44,7 @@
 # define CONFIG_NET_BRIDGE
 #endif
 
-static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
+static QTAILQ_HEAD(, VLANClientState) net_clients;
 
 int default_net = 1;
 
@@ -165,7 +165,7 @@ static char *assign_name(VLANClientState *vc1, const char 
*model)
 char buf[256];
 int id = 0;
 
-QTAILQ_FOREACH(vc, non_vlan_clients, next) {
+QTAILQ_FOREACH(vc, net_clients, next) {
 if (vc == vc1) {
 continue;
 }
@@ -216,7 +216,7 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,
 vc-peer = peer;
 peer-peer = vc;
 }
-QTAILQ_INSERT_TAIL(non_vlan_clients, vc, next);
+QTAILQ_INSERT_TAIL(net_clients, vc, next);
 
 vc-send_queue = qemu_new_net_queue(qemu_deliver_packet,
 qemu_deliver_packet_iov,
@@ -248,7 +248,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
 
 static void qemu_cleanup_vlan_client(VLANClientState *vc)
 {
-QTAILQ_REMOVE(non_vlan_clients, vc, next);
+QTAILQ_REMOVE(net_clients, vc, next);
 
 if (vc-info-cleanup) {
 vc-info-cleanup(vc);
@@ -302,7 +302,7 @@ void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
 {
 VLANClientState *nc;
 
-QTAILQ_FOREACH(nc, non_vlan_clients, next) {
+QTAILQ_FOREACH(nc, net_clients, next) {
 if (nc-info-type == NET_CLIENT_TYPE_NIC) {
 func(DO_UPCAST(NICState, nc, nc), opaque);
 }
@@ -467,7 +467,7 @@ VLANClientState *qemu_find_netdev(const char *id)
 {
 VLANClientState *vc;
 
-QTAILQ_FOREACH(vc, non_vlan_clients, next) {
+QTAILQ_FOREACH(vc, net_clients, next) {
 if (vc-info-type == NET_CLIENT_TYPE_NIC)
 continue;
 if (!strcmp(vc-name, id)) {
@@ -1080,7 +1080,7 @@ void do_info_network(Monitor *mon)
 net_client_type type;
 
 monitor_printf(mon, Devices not on any VLAN:\n);
-QTAILQ_FOREACH(vc, non_vlan_clients, next) {
+QTAILQ_FOREACH(vc, net_clients, next) {
 peer = vc-peer;
 type = vc-info-type;
 if (!peer || type == NET_CLIENT_TYPE_NIC) {
@@ -1133,7 +1133,7 @@ void net_cleanup(void)
 {
 VLANClientState *vc, *next_vc;
 
-QTAILQ_FOREACH_SAFE(vc, non_vlan_clients, next, next_vc) {
+QTAILQ_FOREACH_SAFE(vc, net_clients, next, next_vc) {
 qemu_del_vlan_client(vc);
 }
 }
@@ -1157,7 +1157,7 @@ void net_check_clients(void)
 
 net_hub_check_clients();
 
-QTAILQ_FOREACH(vc, non_vlan_clients, next) {
+QTAILQ_FOREACH(vc, net_clients, next) {
 if (!vc-peer) {
 fprintf(stderr, Warning: %s %s has no peer\n,
 vc-info-type == NET_CLIENT_TYPE_NIC ? nic : netdev,
@@ -1204,7 +1204,7 @@ int net_init_clients(void)
 #endif
 }
 
-QTAILQ_INIT(non_vlan_clients);
+QTAILQ_INIT(net_clients);
 
 if (qemu_opts_foreach(qemu_find_opts(netdev), net_init_netdev, NULL, 1) 
== -1)
 return -1;
-- 
1.7.6




Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

2012-06-04 Thread Dunrong Huang
2012/6/4 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com:
 Yes, I saw that page too. But our current kernel version meets the kernel 
 requirement.
 Why do we need to upgrade it?
I mean maybe the virtio drivers you installed in your VM is unstable.
Virtio is implemented
as a kernel module,  so if you upgrade your kernel, maybe this problem
can be fixed.

It's just a suggestion.

 -Original Message-
 From: Dunrong Huang [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:26 PM
 To: Charles.Tsai-蔡清海-研究�l展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 2012/6/4 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com:
 I am just curious about this issue. Is there any document mentioning the 
 lowest version of the kernel to be supported by VirtIO?

 See http://www.linux-kvm.org/page/Virtio

 -Original Message-
 From: Dunrong Huang [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:17 PM
 To: Charles.Tsai-蔡清海-研究�l展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 2012/6/4 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com:
 The kernel version is 3.0.0.12
 The Qemu version is 1.0.0(we upgraded it)

 What version of kernel do we need to upgrade?
 The latest version is v3.4, so you can try and upgrade to v3.1, v3.2 or 
 v3.3, and test it.

 -Original Message-
 From: mathslinux [mailto:riegama...@gmail.com]
 Sent: Monday, June 04, 2012 2:03 PM
 To: Charles.Tsai-蔡清海-研究�l展部
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] VirtIO Net driver for Ubuntu 11.10

 Charles.Tsai-蔡清海-研究�l展部 charles.t...@cloudena.com writes:

 We recently ran an Ubuntu 11.10 VM which was installed with VirtIO NIC 
 driver. The VirtIO net driver came from the Ubuntu's default package. The 
 VM we installed was configured as a bridge mode. When we ran the Iperf 
 test against the VM, the network interface of the VM was fairly unstable. 
 Sometimes, the network interface of the VM could not receive the packets 
 and we needed to bright the network interface down and up in order to make 
 it work. After we replaced the VirtIo Net driver with ne2k driver and it 
 worked quite stably now.

 We know that the performance of virtIO is much better than ne2k in virtual 
 environment. We would like to use virtio driver instead. If this is the 
 virtio driver issue, can you tell us where to get the latest virtIO driver 
 for Ubuntu VM? Otherwise, tell us how to make the virtio net driver work 
 in Ubuntu VM if you have ever had similar issue before.

 The version of Qemu installed in Ubuntu is 0.14.1.

 The virtio driver is implemented in the guest operating system, it's a 
 kernel module, so what is your kernel version? Maybe you need a kernel of 
 higher version.



-- 
linuxer and emacser and pythoner living in beijing
blog: http://mathslinux.org
twitter: https://twitter.com/mathslinux
google+: https://plus.google.com/118129852578326338750



[Qemu-devel] [PATCH v4 11/16] net: Rename vc local variables to nc

2012-06-04 Thread zwu . kernel
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Now that VLANClientState has been renamed to NetClientState all 'vc'
local variables should be 'nc'.  Much of the code already used 'nc' but
there are places where 'vc' needs to be renamed.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 hw/ne2000.h |4 +-
 hw/vhost_net.c  |   18 +++---
 net.c   |  214 +++---
 net.h   |   20 +++---
 net/tap-win32.c |8 +-
 net/tap.h   |   16 ++--
 6 files changed, 140 insertions(+), 140 deletions(-)

diff --git a/hw/ne2000.h b/hw/ne2000.h
index 6c196a2..1e7ab07 100644
--- a/hw/ne2000.h
+++ b/hw/ne2000.h
@@ -31,5 +31,5 @@ typedef struct NE2000State {
 void ne2000_setup_io(NE2000State *s, unsigned size);
 extern const VMStateDescription vmstate_ne2000;
 void ne2000_reset(NE2000State *s);
-int ne2000_can_receive(NetClientState *vc);
-ssize_t ne2000_receive(NetClientState *vc, const uint8_t *buf, size_t size_);
+int ne2000_can_receive(NetClientState *nc);
+ssize_t ne2000_receive(NetClientState *nc, const uint8_t *buf, size_t size_);
diff --git a/hw/vhost_net.c b/hw/vhost_net.c
index c3e6546..c2d90df 100644
--- a/hw/vhost_net.c
+++ b/hw/vhost_net.c
@@ -42,7 +42,7 @@ struct vhost_net {
 struct vhost_dev dev;
 struct vhost_virtqueue vqs[2];
 int backend;
-NetClientState *vc;
+NetClientState *nc;
 };
 
 unsigned vhost_net_get_features(struct vhost_net *net, unsigned features)
@@ -104,7 +104,7 @@ struct vhost_net *vhost_net_init(NetClientState *backend, 
int devfd,
 if (r  0) {
 goto fail;
 }
-net-vc = backend;
+net-nc = backend;
 net-dev.backend_features = tap_has_vnet_hdr(backend) ? 0 :
 (1  VHOST_NET_F_VIRTIO_NET_HDR);
 net-backend = r;
@@ -151,7 +151,7 @@ int vhost_net_start(struct vhost_net *net,
 goto fail_notifiers;
 }
 if (net-dev.acked_features  (1  VIRTIO_NET_F_MRG_RXBUF)) {
-tap_set_vnet_hdr_len(net-vc,
+tap_set_vnet_hdr_len(net-nc,
  sizeof(struct virtio_net_hdr_mrg_rxbuf));
 }
 
@@ -160,7 +160,7 @@ int vhost_net_start(struct vhost_net *net,
 goto fail_start;
 }
 
-net-vc-info-poll(net-vc, false);
+net-nc-info-poll(net-nc, false);
 qemu_set_fd_handler(net-backend, NULL, NULL, NULL);
 file.fd = net-backend;
 for (file.index = 0; file.index  net-dev.nvqs; ++file.index) {
@@ -177,10 +177,10 @@ fail:
 int r = ioctl(net-dev.control, VHOST_NET_SET_BACKEND, file);
 assert(r = 0);
 }
-net-vc-info-poll(net-vc, true);
+net-nc-info-poll(net-nc, true);
 vhost_dev_stop(net-dev, dev);
 if (net-dev.acked_features  (1  VIRTIO_NET_F_MRG_RXBUF)) {
-tap_set_vnet_hdr_len(net-vc, sizeof(struct virtio_net_hdr));
+tap_set_vnet_hdr_len(net-nc, sizeof(struct virtio_net_hdr));
 }
 fail_start:
 vhost_dev_disable_notifiers(net-dev, dev);
@@ -197,10 +197,10 @@ void vhost_net_stop(struct vhost_net *net,
 int r = ioctl(net-dev.control, VHOST_NET_SET_BACKEND, file);
 assert(r = 0);
 }
-net-vc-info-poll(net-vc, true);
+net-nc-info-poll(net-nc, true);
 vhost_dev_stop(net-dev, dev);
 if (net-dev.acked_features  (1  VIRTIO_NET_F_MRG_RXBUF)) {
-tap_set_vnet_hdr_len(net-vc, sizeof(struct virtio_net_hdr));
+tap_set_vnet_hdr_len(net-nc, sizeof(struct virtio_net_hdr));
 }
 vhost_dev_disable_notifiers(net-dev, dev);
 }
@@ -209,7 +209,7 @@ void vhost_net_cleanup(struct vhost_net *net)
 {
 vhost_dev_cleanup(net-dev);
 if (net-dev.acked_features  (1  VIRTIO_NET_F_MRG_RXBUF)) {
-tap_set_vnet_hdr_len(net-vc, sizeof(struct virtio_net_hdr));
+tap_set_vnet_hdr_len(net-nc, sizeof(struct virtio_net_hdr));
 }
 g_free(net);
 }
diff --git a/net.c b/net.c
index de18c76..10fb601 100644
--- a/net.c
+++ b/net.c
@@ -129,11 +129,11 @@ int parse_host_port(struct sockaddr_in *saddr, const char 
*str)
 return 0;
 }
 
-void qemu_format_nic_info_str(NetClientState *vc, uint8_t macaddr[6])
+void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6])
 {
-snprintf(vc-info_str, sizeof(vc-info_str),
+snprintf(nc-info_str, sizeof(nc-info_str),
  model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x,
- vc-model,
+ nc-model,
  macaddr[0], macaddr[1], macaddr[2],
  macaddr[3], macaddr[4], macaddr[5]);
 }
@@ -159,19 +159,19 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)
  * Only net clients created with the legacy -net option need this.  Naming is
  * mandatory for net clients created with -netdev.
  */
-static char *assign_name(NetClientState *vc1, const char *model)
+static char *assign_name(NetClientState *nc1, const char *model)
 {
-NetClientState *vc;
+NetClientState *nc;
 char buf[256];
 int id = 0;
 
-QTAILQ_FOREACH(vc, net_clients, next) 

Re: [Qemu-devel] [PATCH 00/24] per-directory Makefile snippets, limit vpath abuse

2012-06-04 Thread Paolo Bonzini
Il 04/06/2012 00:57, Anthony Liguori ha scritto:

 As before, I dislike the use of the filename Makefile for files that
 are not self-contained. If make is called from that deep directory, it
 leads to undefined results. Either we must make sure through some clever
 ifeq'ery and a local all target that such an attempt fails, or better
 use a filename that is recognized by editors as Makefile syntax but not
 used by make without explicit -f, e.g., foo.mak.
 
 Linux does this.  I think it's expected behavior at this point.  In the
 long term, we should either move to kconfig or autoconf so trying to act
 like one of the two seems like a good idea to me.

This is not really necessary; we won't really move to kbuild anytime.  I
don't really like the magic Makefiles and did it only because Linux does
this.

Naming files Makefile.objs would make just as much sense.

Paolo



[Qemu-devel] [PATCH v4 08/16] net: Remove VLANState

2012-06-04 Thread zwu . kernel
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

VLANState is no longer used and can be removed.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 net.c |  127 ++---
 net.h |8 
 net/socket.c  |6 +-
 net/tap.c |6 +-
 net/tap.h |2 +-
 qemu-common.h |1 -
 6 files changed, 29 insertions(+), 121 deletions(-)

diff --git a/net.c b/net.c
index abf5a3d..eb2ad06 100644
--- a/net.c
+++ b/net.c
@@ -44,7 +44,6 @@
 # define CONFIG_NET_BRIDGE
 #endif
 
-static QTAILQ_HEAD(, VLANState) vlans;
 static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
 
 int default_net = 1;
@@ -249,11 +248,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
 
 static void qemu_cleanup_vlan_client(VLANClientState *vc)
 {
-if (vc-vlan) {
-QTAILQ_REMOVE(vc-vlan-clients, vc, next);
-} else {
-QTAILQ_REMOVE(non_vlan_clients, vc, next);
-}
+QTAILQ_REMOVE(non_vlan_clients, vc, next);
 
 if (vc-info-cleanup) {
 vc-info-cleanup(vc);
@@ -262,13 +257,11 @@ static void qemu_cleanup_vlan_client(VLANClientState *vc)
 
 static void qemu_free_vlan_client(VLANClientState *vc)
 {
-if (!vc-vlan) {
-if (vc-send_queue) {
-qemu_del_net_queue(vc-send_queue);
-}
-if (vc-peer) {
-vc-peer-peer = NULL;
-}
+if (vc-send_queue) {
+qemu_del_net_queue(vc-send_queue);
+}
+if (vc-peer) {
+vc-peer-peer = NULL;
 }
 g_free(vc-name);
 g_free(vc-model);
@@ -278,7 +271,7 @@ static void qemu_free_vlan_client(VLANClientState *vc)
 void qemu_del_vlan_client(VLANClientState *vc)
 {
 /* If there is a peer NIC, delete and cleanup client, but do not free. */
-if (!vc-vlan  vc-peer  vc-peer-info-type == NET_CLIENT_TYPE_NIC) {
+if (vc-peer  vc-peer-info-type == NET_CLIENT_TYPE_NIC) {
 NICState *nic = DO_UPCAST(NICState, nc, vc-peer);
 if (nic-peer_deleted) {
 return;
@@ -294,7 +287,7 @@ void qemu_del_vlan_client(VLANClientState *vc)
 }
 
 /* If this is a peer NIC and peer has already been deleted, free it now. */
-if (!vc-vlan  vc-peer  vc-info-type == NET_CLIENT_TYPE_NIC) {
+if (vc-peer  vc-info-type == NET_CLIENT_TYPE_NIC) {
 NICState *nic = DO_UPCAST(NICState, nc, vc);
 if (nic-peer_deleted) {
 qemu_free_vlan_client(vc-peer);
@@ -308,52 +301,25 @@ void qemu_del_vlan_client(VLANClientState *vc)
 void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
 {
 VLANClientState *nc;
-VLANState *vlan;
 
 QTAILQ_FOREACH(nc, non_vlan_clients, next) {
 if (nc-info-type == NET_CLIENT_TYPE_NIC) {
 func(DO_UPCAST(NICState, nc, nc), opaque);
 }
 }
-
-QTAILQ_FOREACH(vlan, vlans, next) {
-QTAILQ_FOREACH(nc, vlan-clients, next) {
-if (nc-info-type == NET_CLIENT_TYPE_NIC) {
-func(DO_UPCAST(NICState, nc, nc), opaque);
-}
-}
-}
 }
 
 int qemu_can_send_packet(VLANClientState *sender)
 {
-VLANState *vlan = sender-vlan;
-VLANClientState *vc;
-
-if (sender-peer) {
-if (sender-peer-receive_disabled) {
-return 0;
-} else if (sender-peer-info-can_receive 
-   !sender-peer-info-can_receive(sender-peer)) {
-return 0;
-} else {
-return 1;
-}
-}
-
-if (!sender-vlan) {
+if (!sender-peer) {
 return 1;
 }
 
-QTAILQ_FOREACH(vc, vlan-clients, next) {
-if (vc == sender) {
-continue;
-}
-
-/* no can_receive() handler, they can always receive */
-if (vc-info-can_receive  !vc-info-can_receive(vc)) {
-return 0;
-}
+if (sender-peer-receive_disabled) {
+return 0;
+} else if (sender-peer-info-can_receive 
+   !sender-peer-info-can_receive(sender-peer)) {
+return 0;
 }
 return 1;
 }
@@ -390,34 +356,18 @@ static ssize_t qemu_deliver_packet(VLANClientState 
*sender,
 
 void qemu_purge_queued_packets(VLANClientState *vc)
 {
-NetQueue *queue;
-
-if (!vc-peer  !vc-vlan) {
+if (!vc-peer) {
 return;
 }
 
-if (vc-peer) {
-queue = vc-peer-send_queue;
-} else {
-queue = vc-vlan-send_queue;
-}
-
-qemu_net_queue_purge(queue, vc);
+qemu_net_queue_purge(vc-peer-send_queue, vc);
 }
 
 void qemu_flush_queued_packets(VLANClientState *vc)
 {
-NetQueue *queue;
-
 vc-receive_disabled = 0;
 
-if (vc-vlan) {
-queue = vc-vlan-send_queue;
-} else {
-queue = vc-send_queue;
-}
-
-qemu_net_queue_flush(queue);
+qemu_net_queue_flush(vc-send_queue);
 }
 
 static ssize_t qemu_send_packet_async_with_flags(VLANClientState *sender,
@@ -432,15 +382,11 @@ static ssize_t 
qemu_send_packet_async_with_flags(VLANClientState *sender,
 

[Qemu-devel] [PATCH v4 12/16] net: Rename qemu_del_vlan_client() to qemu_del_net_client()

2012-06-04 Thread zwu . kernel
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Another step in moving the vlan feature out of net core.  Users only
deal with NetClientState and therefore qemu_del_vlan_client() should be
named qemu_del_net_client().

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 hw/e1000.c   |2 +-
 hw/eepro100.c|2 +-
 hw/ne2000.c  |2 +-
 hw/pcnet-pci.c   |2 +-
 hw/rtl8139.c |2 +-
 hw/usb/dev-network.c |2 +-
 hw/virtio-net.c  |2 +-
 hw/xen_nic.c |2 +-
 net.c|   20 ++--
 net.h|2 +-
 net/slirp.c  |2 +-
 11 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 8c7fd3b..cf1e124 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1201,7 +1201,7 @@ pci_e1000_uninit(PCIDevice *dev)
 qemu_free_timer(d-autoneg_timer);
 memory_region_destroy(d-mmio);
 memory_region_destroy(d-io);
-qemu_del_vlan_client(d-nic-nc);
+qemu_del_net_client(d-nic-nc);
 return 0;
 }
 
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 5725ccf..0217795 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1840,7 +1840,7 @@ static int pci_nic_uninit(PCIDevice *pci_dev)
 memory_region_destroy(s-flash_bar);
 vmstate_unregister(pci_dev-qdev, s-vmstate, s);
 eeprom93xx_free(pci_dev-qdev, s-eeprom);
-qemu_del_vlan_client(s-nic-nc);
+qemu_del_net_client(s-nic-nc);
 return 0;
 }
 
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 2339725..e8b1d68 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -750,7 +750,7 @@ static int pci_ne2000_exit(PCIDevice *pci_dev)
 NE2000State *s = d-ne2000;
 
 memory_region_destroy(s-io);
-qemu_del_vlan_client(s-nic-nc);
+qemu_del_net_client(s-nic-nc);
 return 0;
 }
 
diff --git a/hw/pcnet-pci.c b/hw/pcnet-pci.c
index 8c82667..8bbad47 100644
--- a/hw/pcnet-pci.c
+++ b/hw/pcnet-pci.c
@@ -279,7 +279,7 @@ static int pci_pcnet_uninit(PCIDevice *dev)
 memory_region_destroy(d-io_bar);
 qemu_del_timer(d-state.poll_timer);
 qemu_free_timer(d-state.poll_timer);
-qemu_del_vlan_client(d-state.nic-nc);
+qemu_del_net_client(d-state.nic-nc);
 return 0;
 }
 
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 1e4f4eb..3642fcb 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3448,7 +3448,7 @@ static int pci_rtl8139_uninit(PCIDevice *dev)
 }
 qemu_del_timer(s-timer);
 qemu_free_timer(s-timer);
-qemu_del_vlan_client(s-nic-nc);
+qemu_del_net_client(s-nic-nc);
 return 0;
 }
 
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
index 21e0069..4bd4243 100644
--- a/hw/usb/dev-network.c
+++ b/hw/usb/dev-network.c
@@ -1309,7 +1309,7 @@ static void usb_net_handle_destroy(USBDevice *dev)
 
 /* TODO: remove the nd_table[] entry */
 rndis_clear_responsequeue(s);
-qemu_del_vlan_client(s-nic-nc);
+qemu_del_net_client(s-nic-nc);
 }
 
 static NetClientInfo net_usbnet_info = {
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index a73c523..d5527d4 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -1077,6 +1077,6 @@ void virtio_net_exit(VirtIODevice *vdev)
 qemu_bh_delete(n-tx_bh);
 }
 
-qemu_del_vlan_client(n-nic-nc);
+qemu_del_net_client(n-nic-nc);
 virtio_cleanup(n-vdev);
 }
diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 6391a04..ba4a45c 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -409,7 +409,7 @@ static void net_disconnect(struct XenDevice *xendev)
 netdev-rxs = NULL;
 }
 if (netdev-nic) {
-qemu_del_vlan_client(netdev-nic-nc);
+qemu_del_net_client(netdev-nic-nc);
 netdev-nic = NULL;
 }
 }
diff --git a/net.c b/net.c
index 10fb601..61dc28d 100644
--- a/net.c
+++ b/net.c
@@ -246,7 +246,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
 return nic;
 }
 
-static void qemu_cleanup_vlan_client(NetClientState *nc)
+static void qemu_cleanup_net_client(NetClientState *nc)
 {
 QTAILQ_REMOVE(net_clients, nc, next);
 
@@ -255,7 +255,7 @@ static void qemu_cleanup_vlan_client(NetClientState *nc)
 }
 }
 
-static void qemu_free_vlan_client(NetClientState *nc)
+static void qemu_free_net_client(NetClientState *nc)
 {
 if (nc-send_queue) {
 qemu_del_net_queue(nc-send_queue);
@@ -268,7 +268,7 @@ static void qemu_free_vlan_client(NetClientState *nc)
 g_free(nc);
 }
 
-void qemu_del_vlan_client(NetClientState *nc)
+void qemu_del_net_client(NetClientState *nc)
 {
 /* If there is a peer NIC, delete and cleanup client, but do not free. */
 if (nc-peer  nc-peer-info-type == NET_CLIENT_TYPE_NIC) {
@@ -282,7 +282,7 @@ void qemu_del_vlan_client(NetClientState *nc)
 if (nc-peer-info-link_status_changed) {
 nc-peer-info-link_status_changed(nc-peer);
 }
-qemu_cleanup_vlan_client(nc);
+qemu_cleanup_net_client(nc);
 return;
 }
 
@@ -290,12 +290,12 @@ void 

[Qemu-devel] [PATCH v4 13/16] net: Make info network output more readable info

2012-06-04 Thread zwu . kernel
From: Zhi Yong Wu wu...@linux.vnet.ibm.com

Reviewed-by:   Jan Kiszka  jan.kis...@siemens.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 net.c |   14 +-
 net.h |1 +
 net/hub.c |   23 +--
 net/hub.h |1 +
 4 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/net.c b/net.c
index 61dc28d..6cedc7a 100644
--- a/net.c
+++ b/net.c
@@ -1068,7 +1068,7 @@ int do_netdev_del(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 return 0;
 }
 
-static void print_net_client(Monitor *mon, NetClientState *vc)
+void print_net_client(Monitor *mon, NetClientState *vc)
 {
 monitor_printf(mon, %s: type=%s,%s\n, vc-name,
net_client_types[vc-info-type].type, vc-info_str);
@@ -1079,20 +1079,24 @@ void do_info_network(Monitor *mon)
 NetClientState *nc, *peer;
 net_client_type type;
 
-monitor_printf(mon, Devices not on any VLAN:\n);
+net_hub_info(mon);
+
 QTAILQ_FOREACH(nc, net_clients, next) {
 peer = nc-peer;
 type = nc-info-type;
+
+if (net_hub_port_peer_nc(nc)) {
+continue;
+}
+
 if (!peer || type == NET_CLIENT_TYPE_NIC) {
-monitor_printf(mon,   );
 print_net_client(mon, nc);
 } /* else it's a netdev connected to a NIC, printed with the NIC */
 if (peer  type == NET_CLIENT_TYPE_NIC) {
-monitor_printf(mon,\\ );
+monitor_printf(mon,  \\ );
 print_net_client(mon, peer);
 }
 }
-net_hub_info(mon);
 }
 
 void qmp_set_link(const char *name, bool up, Error **errp)
diff --git a/net.h b/net.h
index 250669a..0692283 100644
--- a/net.h
+++ b/net.h
@@ -112,6 +112,7 @@ void qemu_check_nic_model(NICInfo *nd, const char *model);
 int qemu_find_nic_model(NICInfo *nd, const char * const *models,
 const char *default_model);
 
+void print_net_client(Monitor *mon, NetClientState *vc);
 void do_info_network(Monitor *mon);
 
 /* NIC info */
diff --git a/net/hub.c b/net/hub.c
index 122de69..230d86a 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -184,6 +184,25 @@ NetClientState *net_hub_find_client_by_name(unsigned int 
hub_id,
 }
 
 /**
+ * Determine if one nc peers with one hub port
+ */
+bool net_hub_port_peer_nc(NetClientState *nc)
+{
+NetHub *hub;
+NetHubPort *port;
+
+QLIST_FOREACH(hub, hubs, next) {
+QLIST_FOREACH(port, hub-ports, next) {
+if (nc == port-nc.peer) {
+return true;
+}
+}
+}
+
+return false;
+}
+
+/**
  * Print hub configuration
  */
 void net_hub_info(Monitor *mon)
@@ -194,8 +213,8 @@ void net_hub_info(Monitor *mon)
 QLIST_FOREACH(hub, hubs, next) {
 monitor_printf(mon, hub %u\n, hub-id);
 QLIST_FOREACH(port, hub-ports, next) {
-monitor_printf(mon, port %u peer %s\n, port-id,
-   port-nc.peer ? port-nc.peer-name : none);
+monitor_printf(mon,  \\ );
+print_net_client(mon, port-nc.peer);
 }
 }
 }
diff --git a/net/hub.h b/net/hub.h
index ff5024a..550189b 100644
--- a/net/hub.h
+++ b/net/hub.h
@@ -23,5 +23,6 @@ NetClientState *net_hub_find_client_by_name(unsigned int 
hub_id,
 void net_hub_info(Monitor *mon);
 int net_hub_id_for_client(NetClientState *nc, unsigned int *id);
 void net_hub_check_clients(void);
+bool net_hub_port_peer_nc(NetClientState *nc);
 
 #endif /* NET_HUB_H */
-- 
1.7.6




Re: [Qemu-devel] [PATCH v3 00/16] net: hub-based networking

2012-06-04 Thread Markus Armbruster
Anthony Liguori anth...@codemonkey.ws writes:

 On 05/29/2012 04:14 PM, Markus Armbruster wrote:
 Luiz Capitulinolcapitul...@redhat.com  writes:

 On Mon, 28 May 2012 12:17:04 +0100
 Stefan Hajnoczistefa...@linux.vnet.ibm.com  wrote:

 What we need to decide is whether it's okay to drop QEMU VLANs
 completely and change dump command-line syntax?

 I'd vote for dropping it.

 I think vlan-hub doesn't hurt anyone because the code has been isolated
 and we keep backwards compatibility.  So I'd personally still go the
 vlan-hub route for QEMU 1.x.

 Just to make it clear: I'm not against this series. I'm against having
 the functionality in qemu. If we want to keep the functionality, then I
 completely agree that this series is the way to go.

 I agree with Luiz: if we want to reimplement that much of networking
 within QEMU, this series does it in a much better way than VLANs, but
 I'd rather not do it at all.

 Just advice, not a strong objection.

 Doesn't the same logic apply to reimplementing file systems?
 Shouldn't we drop qcow3 in favor of using btrfs?

btrfs isn't ready for production, so this is a hypothetical question.

 It's easy to make the NIH argument when it's a feature you don't care about.

 A lot of people use vlans.  It's the only way -net socket is useful
 too.  Just because most KVM/libvirt users don't doesn't mean they
 aren't an important feature to preserve.

I specifically asked for evidence on actual use of VLANs, and which uses
of VLANs can't be readily upgraded to better-performing external
solutions.  You asserting it is used a lot isn't a full answer, but
it's (slightly) better than nothing.

 I would strongly nack any attempt to remove vlans w/o providing some
 mechanism for backwards compatibility which is exactly what this patch
 series does.

Roma locuta, causa finita.



[Qemu-devel] [PATCH v3] net: add the support for -netdev socket, listen

2012-06-04 Thread zwu . kernel
From: Zhi Yong Wu wu...@linux.vnet.ibm.com

The -net socket,listen option does not work with the newer -netdev
syntax:
 http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html

This patch makes it work now.

For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.

Supported syntax:
 1.) -net socket,listen=127.0.0.1:1234,vlan=0
 2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net 
socket,listen=127.0.0.1:1235,vlan=0
 3.) -netdev socket,listen=127.0.0.1:1234,id=socket0

Suggested-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 net.c|   24 
 net.h|3 ++
 net/socket.c |  115 +++---
 3 files changed, 113 insertions(+), 29 deletions(-)

diff --git a/net.c b/net.c
index 1922d8a..0114537 100644
--- a/net.c
+++ b/net.c
@@ -190,6 +190,30 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState 
*sender,
int iovcnt,
void *opaque);
 
+VLANClientState *qemu_lookup_net_client(VLANState *vlan,
+const char *name)
+{
+VLANClientState *vc = NULL;
+
+if (vlan) {
+QTAILQ_FOREACH(vc, vlan-clients, next) {
+if ((vc-info-type == NET_CLIENT_TYPE_SOCKET)
+ (!vc-consumed)) {
+return vc;
+}
+}
+} else {
+QTAILQ_FOREACH(vc, non_vlan_clients, next) {
+if (!strcmp(vc-name, name)
+ (!vc-consumed)) {
+return vc;
+}
+}
+}
+
+return NULL;
+}
+
 VLANClientState *qemu_new_net_client(NetClientInfo *info,
  VLANState *vlan,
  VLANClientState *peer,
diff --git a/net.h b/net.h
index 64993b4..6033f43 100644
--- a/net.h
+++ b/net.h
@@ -72,6 +72,7 @@ struct VLANClientState {
 char *name;
 char info_str[256];
 unsigned receive_disabled : 1;
+bool consumed;
 };
 
 typedef struct NICState {
@@ -90,6 +91,8 @@ struct VLANState {
 
 VLANState *qemu_find_vlan(int id, int allocate);
 VLANClientState *qemu_find_netdev(const char *id);
+VLANClientState *qemu_lookup_net_client(VLANState *vlan,
+const char *name);
 VLANClientState *qemu_new_net_client(NetClientInfo *info,
  VLANState *vlan,
  VLANClientState *peer,
diff --git a/net/socket.c b/net/socket.c
index 0bcf229..459b6a8 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -32,6 +32,10 @@
 #include qemu-option.h
 #include qemu_socket.h
 
+#define NET_SOCKET_CONNECT0x0001
+#define NET_SOCKET_LISTEN 0x0002
+#define NET_SOCKET_CREATE 0x0004
+
 typedef struct NetSocketState {
 VLANClientState nc;
 int fd;
@@ -47,6 +51,7 @@ typedef struct NetSocketListenState {
 char *model;
 char *name;
 int fd;
+bool consumed;
 } NetSocketListenState;
 
 /* XXX: we consider we can send the whole packet without blocking */
@@ -247,7 +252,7 @@ static NetClientInfo net_dgram_socket_info = {
 static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
 const char *model,
 const char *name,
-int fd, int is_connected)
+int fd, int flag)
 {
 struct sockaddr_in saddr;
 int newfd;
@@ -260,7 +265,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState 
*vlan,
  * by ONLY ONE process: we must clone this dgram socket --jjo
  */
 
-if (is_connected) {
+if (flag  NET_SOCKET_CONNECT) {
 if (getsockname(fd, (struct sockaddr *) saddr, saddr_len) == 0) {
 /* must be bound */
 if (saddr.sin_addr.s_addr == 0) {
@@ -286,21 +291,36 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState 
*vlan,
 }
 }
 
-nc = qemu_new_net_client(net_dgram_socket_info, vlan, NULL, model, name);
+
+if (flag  NET_SOCKET_CREATE) {
+nc = qemu_new_net_client(net_dgram_socket_info,
+ vlan, NULL, model, name);
+} else {
+nc = qemu_lookup_net_client(vlan, name);
+if (!nc) {
+goto err;
+}
+}
+
+s = DO_UPCAST(NetSocketState, nc, nc);
+
+if (flag  NET_SOCKET_LISTEN) {
+return s;
+}
 
 snprintf(nc-info_str, sizeof(nc-info_str),
 socket: fd=%d (%s mcast=%s:%d),
-fd, is_connected ? cloned : ,
+fd, flag  NET_SOCKET_CONNECT ? cloned : ,
 inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
 
-s = DO_UPCAST(NetSocketState, nc, nc);
-
 s-fd = fd;
 
 qemu_set_fd_handler(s-fd, net_socket_send_dgram, NULL, s);
 
 /* mcast: save 

Re: [Qemu-devel] [PATCH v2 00/25] x86 AREG0 conversion

2012-06-04 Thread Markus Armbruster
Anthony Liguori anth...@codemonkey.ws writes:

 On 06/03/2012 10:29 PM, Blue Swirl wrote:
 v1: I only sent the tree URL.

 v2: Rebased. Updated 07/25: removed confused comment and split
 sse_op_table3 so that void pointers are avoided there too, adjusted
 08/25 accordingly.

 The patch series most probably need to rebased after QOM patches.

 Please thread patches when sending large patch series.  git-send-email
 will do it automagically for you.

Actually, please thread patches when you send series, period.
Maintainers should lead by setting good examples.

You may have to configure git for your SMTP server.  Here's advice from
someone who did, with gmail:

http://morefedora.blogspot.de/2009/02/configuring-git-send-email-to-use-gmail.html



Re: [Qemu-devel] [PATCH qom-next] qom: make object cast assert if NULL object is passed as argument

2012-06-04 Thread Markus Armbruster
Andreas Färber afaer...@suse.de writes:

 Am 01.06.2012 13:18, schrieb Markus Armbruster:
 Andreas Färber afaer...@suse.de writes:
 
 Am 31.05.2012 13:17, schrieb Igor Mammedov:
 On 05/31/2012 12:16 PM, Paolo Bonzini wrote:
 Il 31/05/2012 10:30, Markus Armbruster ha scritto:
 Makes much sense, but maybe it should be done in OBJECT() cast? Assert
 when we do OBJECT(NULL).
 In my opinion, OBJECT(p) where p is a null pointer is perfectly valid
 and should yield a null pointer.

 Perhaps object_dynamic_cast and object_dynamic_cast_assert should do the
 same?


 or better object_dynamic_cast should return NULL if obj is NULL,
 after all it's expected that it may return NULL

 That's what I was suggesting: I think that we should define NULL is not
 of type TYPE_FOO and thus have the ..._is_... functions return false,
 and have the ..._cast_assert assert.
 
 Is it?

 See http://www.mail-archive.com/qemu-devel@nongnu.org/msg113922.html

 Igor: object_dynamic_cast should return NULL if obj is NULL,
 
 You: have the ..._cast_assert assert [on null argument, I presume]
 
 Doesn't sound like the same suggestion to me :)

 I'll let you to your opinion. :) However, my opinion is that

My question isn't about a difference of opinions between us two.  It's
about Igor writing X should do Y, and you replying Yes, that's what I
was suggesting, X should do !Y.  There's a misunderstanding there, and
it could well be mine.  So I ask.

[...]



[Qemu-devel] [PATCH V4 0/5] Ehnahced SSI bus support + M25P80 SPI flash + Xilinx SPI controller

2012-06-04 Thread Peter A. G. Crosthwaite
Patch 1 Enhances SSI bus support to properly support multiple attached devices. 
An api is provided for SSI/SPI masters to select a particular device attached 
to the bus.

Patch 2 is a device model for the m25p80 style SPI flash chip.

Patch 3 is  the Xilinx XPS SPI contoller. Its a sysbus device that instantiates 
a ssi bus, and interfaces the two (as per the controllers functionality)

Patch 4 instantiates the XPS SPI controller in the petalogix ML605 reference 
platform and connects two m25p80s to it.

Patch 5 updates the stellaris machine model to use the multi slave SSI support

CHANGELOG:
changed from v3:
addressed reviewer comments from P Maydell and S Hajnoczi
added patch 5 (re Paul Brooks request)
changed from v2:
folded former SPI bus functionality into existing SSI infrastructure (suggested 
- Paul Brook) (all patches)
made m25p80 use async io (suggested - Stefan Hajnoczi) (2/4)
instantiated two spi flashes instead of one in ml605 ref design (4/4)
changed from v1:
minor sylistic changes (1/4)
converted spi api to modified txrx style (1-3/4)
heavily refactored m25p80 model (2/4)

Peter A. G. Crosthwaite (5):
  SSI: Built in multiple device support
  m25p80: initial verion
  xilinx_spi: initial version
  petalogix-ml605: added spi controller with m25p80
  stellaris: Updated spi bus implementation

 Makefile.target  |2 +
 default-configs/microblaze-softmmu.mak   |1 +
 default-configs/microblazeel-softmmu.mak |1 +
 hw/m25p80.c  |  557 ++
 hw/petalogix_ml605_mmu.c |   23 ++
 hw/spitz.c   |8 +-
 hw/ssi.c |  107 +-
 hw/ssi.h |   28 ++-
 hw/stellaris.c   |   21 +-
 hw/tosa.c|2 +-
 hw/xilinx_spi.c  |  481 ++
 hw/z2.c  |2 +-
 12 files changed, 1196 insertions(+), 37 deletions(-)
 create mode 100644 hw/m25p80.c
 create mode 100644 hw/xilinx_spi.c

-- 
1.7.3.2




[Qemu-devel] [PATCH V4 1/5] SSI: Built in multiple device support

2012-06-04 Thread Peter A. G. Crosthwaite
Added support for multiple devices attached to a single SSI bus (Previously
SSI masters with multiple slaves were emulated as multiple point to point SSI
busses)

Signed-off-by: Peter A. G. Crosthwaite peter.crosthwa...@petalogix.com
---
changed from v3:
added ssi_create_slave_noinit
changed from v2:
This patch is new (totally rewitten replacement of (1/4) from v2)
 hw/spitz.c |8 ++--
 hw/ssi.c   |  107 
 hw/ssi.h   |   28 --
 hw/stellaris.c |6 ++--
 hw/tosa.c  |2 +-
 hw/z2.c|2 +-
 6 files changed, 125 insertions(+), 28 deletions(-)

diff --git a/hw/spitz.c b/hw/spitz.c
index 1d6d2b0..f63a9bf 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -669,18 +669,18 @@ static void spitz_ssp_attach(PXA2xxState *cpu)
 DeviceState *dev;
 void *bus;
 
-mux = ssi_create_slave(cpu-ssp[CORGI_SSP_PORT - 1], corgi-ssp);
+mux = ssi_create_slave(cpu-ssp[CORGI_SSP_PORT - 1], corgi-ssp, 0);
 
 bus = qdev_get_child_bus(mux, ssi0);
-ssi_create_slave(bus, spitz-lcdtg);
+ssi_create_slave(bus, spitz-lcdtg, 0);
 
 bus = qdev_get_child_bus(mux, ssi1);
-dev = ssi_create_slave(bus, ads7846);
+dev = ssi_create_slave(bus, ads7846, 0);
 qdev_connect_gpio_out(dev, 0,
   qdev_get_gpio_in(cpu-gpio, SPITZ_GPIO_TP_INT));
 
 bus = qdev_get_child_bus(mux, ssi2);
-max = ssi_create_slave(bus, max);
+max = ssi_create_slave(bus, max, 0);
 max111x_set_input(max, MAX_BATT_VOLT, SPITZ_BATTERY_VOLT);
 max111x_set_input(max, MAX_BATT_TEMP, 0);
 max111x_set_input(max, MAX_ACIN_VOLT, SPITZ_CHARGEON_ACIN);
diff --git a/hw/ssi.c b/hw/ssi.c
index 8f2d9bc..af7e887 100644
--- a/hw/ssi.c
+++ b/hw/ssi.c
@@ -2,6 +2,8 @@
  * QEMU Synchronous Serial Interface support
  *
  * Copyright (c) 2009 CodeSourcery.
+ * Copyright (c) 2012 Peter A.G. Crosthwaite (peter.crosthwa...@petalogix.com)
+ * Copyright (c) 2012 PetaLogix Pty Ltd.
  * Written by Paul Brook
  *
  * This code is licensed under the GNU GPL v2.
@@ -14,24 +16,33 @@
 
 struct SSIBus {
 BusState qbus;
+int32_t selected_slave;
 };
 
 static struct BusInfo ssi_bus_info = {
 .name = SSI,
 .size = sizeof(SSIBus),
+.props = (Property[]) {
+DEFINE_PROP_INT32(slave_select, struct SSISlave, slave_select, 0),
+DEFINE_PROP_END_OF_LIST(),
+}
+};
+
+static const VMStateDescription vmstate_ssi_bus = {
+.name = ssi_bus,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField[]) {
+VMSTATE_INT32(selected_slave, SSIBus),
+VMSTATE_END_OF_LIST()
+}
 };
 
 static int ssi_slave_init(DeviceState *dev)
 {
 SSISlave *s = SSI_SLAVE(dev);
 SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
-SSIBus *bus;
-
-bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
-if (QTAILQ_FIRST(bus-qbus.children) != dev
-|| QTAILQ_NEXT(dev, sibling) != NULL) {
-hw_error(Too many devices on SSI bus);
-}
 
 return ssc-init(s);
 }
@@ -46,40 +57,106 @@ static void ssi_slave_class_init(ObjectClass *klass, void 
*data)
 static TypeInfo ssi_slave_info = {
 .name = TYPE_SSI_SLAVE,
 .parent = TYPE_DEVICE,
+.instance_size = sizeof(struct SSISlave),
 .class_init = ssi_slave_class_init,
 .class_size = sizeof(SSISlaveClass),
 .abstract = true,
 };
 
-DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name,
+int32_t slave_select)
 {
 DeviceState *dev;
 dev = qdev_create(bus-qbus, name);
+qdev_prop_set_int32(dev, slave_select, slave_select);
+return dev;
+}
+
+DeviceState *ssi_create_slave(SSIBus *bus, const char *name,
+int32_t slave_select)
+{
+DeviceState *dev;
+dev = ssi_create_slave_no_init(bus, name, slave_select);
 qdev_init_nofail(dev);
 return dev;
+
 }
 
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
 {
-BusState *bus;
-bus = qbus_create(ssi_bus_info, parent, name);
-return FROM_QBUS(SSIBus, bus);
+SSIBus *bus;
+
+bus = FROM_QBUS(SSIBus, qbus_create(ssi_bus_info, parent, name));
+vmstate_register(NULL, -1, vmstate_ssi_bus, bus);
+return bus;
+}
+
+static SSISlave *get_current_slave(SSIBus *bus)
+{
+DeviceState *qdev;
+
+QTAILQ_FOREACH(qdev, bus-qbus.children, sibling) {
+SSISlave *candidate = SSI_SLAVE_FROM_QDEV(qdev);
+if (candidate-slave_select == bus-selected_slave) {
+return candidate;
+}
+}
+
+return NULL;
+}
+
+void ssi_select_slave(SSIBus *bus, int32_t selected_slave)
+{
+SSISlave *slave;
+SSISlaveClass *ssc;
+
+if (bus-selected_slave == selected_slave) {
+return;
+}
+
+slave = get_current_slave(bus);
+if 

[Qemu-devel] [PATCH V4 2/5] m25p80: initial verion

2012-06-04 Thread Peter A. G. Crosthwaite
Added device model for m25p80 SPI flash

Signed-off-by: Peter A. G. Crosthwaite peter.crosthwa...@petalogix.com
---
changed from v3:
changed licence to v2 or later (PMM review)
generalised device model - rather than being fixed to the fl064k, it can handle 
a wide range of m25p80 devices
refactored erase commands (previously they were fl064k specific and used 
spansions broken terminology)
typdef'd strcuts and enums
fixed some camel casing
added comment to explain why bdrv_sync_complete is a nop (PMM review)
removed hardcoded 512 for BDRV_SECTOR_SIZE
flash_sync_area: use bdrv_aio_writev instead of bdrv_write 
flash_chip_erase/flash_block_erase32k/flash_sector_erase: consolidated to one 
function
decode_new_cmd: fixed multi-statement lines (PMM review)
CHIP_ERASE-BULK_ERASE
init: drive_get - drive_get_next (PMM review)
changed from v2:
updated for SSI slave interface
used async io (suggested - Stefan Hajnoczi)
changed from v1:
converted spi api to modified txrx style
factored out lots of common code and inlined overly short single call functions.
undated for txrx style spi interface
 Makefile.target |1 +
 hw/m25p80.c |  557 +++
 2 files changed, 558 insertions(+), 0 deletions(-)
 create mode 100644 hw/m25p80.c

diff --git a/Makefile.target b/Makefile.target
index 1582904..77feb83 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -292,6 +292,7 @@ obj-mips-$(CONFIG_FULONG) += bonito.o vt82c686.o 
mips_fulong2e.o
 obj-microblaze-y = petalogix_s3adsp1800_mmu.o
 obj-microblaze-y += petalogix_ml605_mmu.o
 obj-microblaze-y += microblaze_boot.o
+obj-microblaze-y += m25p80.o
 
 obj-microblaze-y += microblaze_pic_cpu.o
 obj-microblaze-y += xilinx_intc.o
diff --git a/hw/m25p80.c b/hw/m25p80.c
new file mode 100644
index 000..0edb67f
--- /dev/null
+++ b/hw/m25p80.c
@@ -0,0 +1,557 @@
+/*
+ * ST M25P80 emulator. Emulate all SPI flash devices based on the m25p80 
command
+ * set. Known devices table current as of Jun/2012 and taked from linux.
+ * See drivers/mtd/devices/m25p80.c.
+ *
+ * Copyright (C) 2011 Edgar E. Iglesias edgar.igles...@gmail.com
+ * Copyright (C) 2012 Peter A. G. Crosthwaite peter.crosthwa...@petalogix.com
+ * Copyright (C) 2012 PetaLogix
+ *
+ * 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 or
+ * (at your option) a later version of the License.
+ *
+ * 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/.
+ */
+
+#include hw.h
+#include blockdev.h
+#include ssi.h
+#include devices.h
+
+#ifdef M25P80_ERR_DEBUG
+#define DB_PRINT(...) do { \
+fprintf(stderr,  : %s: , __func__); \
+fprintf(stderr, ## __VA_ARGS__); \
+} while (0);
+#else
+#define DB_PRINT(...)
+#endif
+
+typedef struct FlashPartInfo {
+const char *part_name;
+/* jedec code. (jedec  16)  0xff is the 1st byte,  8 the 2nd etc */
+uint32_t jedec;
+/* extended jedec code */
+uint16_t ext_jedec;
+/* there is confusion between manufacturers as to what a sector is. In this
+ * device model, a sector is the size that is erased by the ERASE_SECTOR
+ * command (opcode 0xd8).
+ */
+uint32_t sector_size;
+uint32_t n_sectors;
+uint32_t page_size;
+uint8_t flags;
+#define ER_4K 1
+#define ER_32K 2
+} FlashPartInfo;
+
+/* adapted from linux */
+
+#define INFO(_part_name, _jedec, _ext_jedec, _sector_size, _n_sectors, _flags)\
+.part_name = (_part_name),\
+.jedec = (_jedec),\
+.ext_jedec = (_ext_jedec),\
+.sector_size = (_sector_size),\
+.n_sectors = (_n_sectors),\
+.page_size = 256,\
+.flags = (_flags),\
+
+static const FlashPartInfo known_devices[] = {
+/* Atmel -- some are (confusingly) marketed as DataFlash */
+{ INFO(at25fs010,   0x1f6601,  0,  32  10,   4, ER_4K) },
+{ INFO(at25fs040,   0x1f6604,  0,  64  10,   8, ER_4K) },
+
+{ INFO(at25df041a,  0x1f4401,  0,  64  10,   8, ER_4K) },
+{ INFO(at25df321a,  0x1f4701,  0,  64  10,  64, ER_4K) },
+{ INFO(at25df641,   0x1f4800,  0,  64  10, 128, ER_4K) },
+
+{ INFO(at26f004,0x1f0400,  0,  64  10,   8, ER_4K) },
+{ INFO(at26df081a,  0x1f4501,  0,  64  10,  16, ER_4K) },
+{ INFO(at26df161a,  0x1f4601,  0,  64  10,  32, ER_4K) },
+{ INFO(at26df321,   0x1f4700,  0,  64  10,  64, ER_4K) },
+
+/* EON -- en25xxx */
+{ INFO(en25f32, 0x1c3116,  0,  64  10,  64, ER_4K) },
+{ INFO(en25p32, 0x1c2016,  0,  64  10,  64, 0) },
+{ INFO(en25q32b,0x1c3016,  0,  64  10,  

[Qemu-devel] [PATCH V4 3/5] xilinx_spi: initial version

2012-06-04 Thread Peter A. G. Crosthwaite
device model for xilinx XPS SPI controller (v2.0)

Signed-off-by: Peter A. G. Crosthwaite peter.crosthwa...@petalogix.com
---
changed from v3:
typedef'd struct XilinxSPI
changed unsigned int - uin32_t
removed unused vars (c_fifo_exist and cmd_ongoing)
txfifo_reset removed duplicate s-regs[R_SPISR] = ~SR_TX_FULL (PMM review)
reset: changed to Device Class style reset
reset: stope the ptimer (pmm review)
xlx_spi_update_irq: dont - don't (PMM review)
init: set irq_line to 1 (force refresh on vmsd load)
init: dropped call to reset
implemetned vmsd
changed from v2:
converted spi api to ssi api
changed from v1:
converted spi api to modified txrx style
 Makefile.target |1 +
 hw/xilinx_spi.c |  481 +++
 2 files changed, 482 insertions(+), 0 deletions(-)
 create mode 100644 hw/xilinx_spi.c

diff --git a/Makefile.target b/Makefile.target
index 77feb83..4471317 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -293,6 +293,7 @@ obj-microblaze-y = petalogix_s3adsp1800_mmu.o
 obj-microblaze-y += petalogix_ml605_mmu.o
 obj-microblaze-y += microblaze_boot.o
 obj-microblaze-y += m25p80.o
+obj-microblaze-y += xilinx_spi.o
 
 obj-microblaze-y += microblaze_pic_cpu.o
 obj-microblaze-y += xilinx_intc.o
diff --git a/hw/xilinx_spi.c b/hw/xilinx_spi.c
new file mode 100644
index 000..cae88ad
--- /dev/null
+++ b/hw/xilinx_spi.c
@@ -0,0 +1,481 @@
+/*
+ * QEMU model of the Xilinx SPI Controller
+ *
+ * Copyright (C) 2010 Edgar E. Iglesias.
+ * Copyright (C) 2012 Peter A. G. Crosthwaite peter.crosthwa...@petalogix.com
+ * Copyright (C) 2012 PetaLogix
+ *
+ * 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 sysbus.h
+#include sysemu.h
+#include ptimer.h
+#include qemu-log.h
+
+#include ssi.h
+
+#ifdef XILINX_SPI_ERR_DEBUG
+#define DB_PRINT(...) do { \
+fprintf(stderr,  : %s: , __func__); \
+fprintf(stderr, ## __VA_ARGS__); \
+} while (0);
+#else
+#define DB_PRINT(...)
+#endif
+
+#define R_DGIER (0x1c / 4)
+#define R_DGIER_IE  (1  31)
+
+#define R_IPISR (0x20 / 4)
+#define IRQ_DRR_NOT_EMPTY(1  (31 - 23))
+#define IRQ_DRR_OVERRUN  (1  (31 - 26))
+#define IRQ_DRR_FULL (1  (31 - 27))
+#define IRQ_TX_FF_HALF_EMPTY (1  6)
+#define IRQ_DTR_UNDERRUN (1  3)
+#define IRQ_DTR_EMPTY(1  (31 - 29))
+
+#define R_IPIER (0x28 / 4)
+#define R_SRR   (0x40 / 4)
+#define R_SPICR (0x60 / 4)
+#define R_SPICR_TXFF_RST (1  5)
+#define R_SPICR_RXFF_RST (1  6)
+#define R_SPICR_MTI  (1  8)
+
+#define R_SPISR (0x64 / 4)
+#define SR_TX_FULL(1  3)
+#define SR_TX_EMPTY   (1  2)
+#define SR_RX_FULL(1  1)
+#define SR_RX_EMPTY   (1  0)
+
+
+#define R_SPIDTR(0x68 / 4)
+#define R_SPIDRR(0x6C / 4)
+#define R_SPISSR(0x70 / 4)
+#define R_TX_FF_OCY (0x74 / 4)
+#define R_RX_FF_OCY (0x78 / 4)
+#define R_MAX   (0x7C / 4)
+
+typedef struct XilinxSPI {
+SysBusDevice busdev;
+MemoryRegion mmio;
+qemu_irq irq;
+int irqline;
+
+QEMUBH *bh;
+ptimer_state *ptimer;
+
+SSIBus *spi;
+
+uint8_t rx_fifo[256];
+uint32_t rx_fifo_pos;
+uint32_t rx_fifo_len;
+
+uint8_t tx_fifo[256];
+uint32_t tx_fifo_pos;
+uint32_t tx_fifo_len;
+
+/* Slave select.  */
+uint8_t num_cs;
+
+uint32_t regs[R_MAX];
+} XilinxSPI;
+
+static void txfifo_reset(XilinxSPI *s)
+{
+s-tx_fifo_pos = 0;
+s-tx_fifo_len = 0;
+
+s-regs[R_SPISR] = ~SR_TX_FULL;
+s-regs[R_SPISR] |= SR_TX_EMPTY;
+s-regs[R_IPISR] |= IRQ_DTR_EMPTY;
+}
+
+static void rxfifo_reset(XilinxSPI *s)
+{
+s-rx_fifo_pos = 0;
+s-rx_fifo_len = 0;
+
+s-regs[R_SPISR] |= SR_RX_EMPTY;
+s-regs[R_SPISR] = ~SR_RX_FULL;
+s-regs[R_IPISR] = ~IRQ_DRR_NOT_EMPTY;
+s-regs[R_IPISR] = ~IRQ_DRR_OVERRUN;
+}
+
+static void xlx_spi_do_reset(XilinxSPI *s)
+{
+memset(s-regs, 0, sizeof s-regs);
+
+rxfifo_reset(s);
+txfifo_reset(s);
+
+s-regs[R_SPISSR] = 1;
+

[Qemu-devel] [PATCH V4 5/5] stellaris: Updated spi bus implementation

2012-06-04 Thread Peter A. G. Crosthwaite
Setup the stellaris_ssi_bus device to use a single multi-slave ssi bus instead
of two busses.

Signed-off-by: Peter A. G. Crosthwaite peter.crosthwa...@petalogix.com
---
changed from v3:
This patch is new

 hw/stellaris.c |   17 +++--
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/hw/stellaris.c b/hw/stellaris.c
index e0600a1..07a4187 100644
--- a/hw/stellaris.c
+++ b/hw/stellaris.c
@@ -1164,22 +1164,21 @@ static int stellaris_adc_init(SysBusDevice *dev)
 typedef struct {
 SSISlave ssidev;
 qemu_irq irq;
-int current_dev;
-SSIBus *bus[2];
+SSIBus *bus;
 } stellaris_ssi_bus_state;
 
 static void stellaris_ssi_bus_select(void *opaque, int irq, int level)
 {
 stellaris_ssi_bus_state *s = (stellaris_ssi_bus_state *)opaque;
 
-s-current_dev = level;
+ssi_select_slave(s-bus, (uint32_t)level);
 }
 
 static uint32_t stellaris_ssi_bus_transfer(SSISlave *dev, uint32_t val)
 {
 stellaris_ssi_bus_state *s = FROM_SSI_SLAVE(stellaris_ssi_bus_state, dev);
 
-return ssi_transfer(s-bus[s-current_dev], val);
+return ssi_transfer(s-bus, val);
 }
 
 static const VMStateDescription vmstate_stellaris_ssi_bus = {
@@ -1188,7 +1187,6 @@ static const VMStateDescription vmstate_stellaris_ssi_bus 
= {
 .minimum_version_id = 1,
 .minimum_version_id_old = 1,
 .fields  = (VMStateField[]) {
-VMSTATE_INT32(current_dev, stellaris_ssi_bus_state),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -1197,8 +1195,7 @@ static int stellaris_ssi_bus_init(SSISlave *dev)
 {
 stellaris_ssi_bus_state *s = FROM_SSI_SLAVE(stellaris_ssi_bus_state, dev);
 
-s-bus[0] = ssi_create_bus(dev-qdev, ssi0);
-s-bus[1] = ssi_create_bus(dev-qdev, ssi1);
+s-bus = ssi_create_bus(dev-qdev, ssi);
 qdev_init_gpio_in(dev-qdev, stellaris_ssi_bus_select, 1);
 
 vmstate_register(dev-qdev, -1, vmstate_stellaris_ssi_bus, s);
@@ -1312,11 +1309,11 @@ static void stellaris_init(const char *kernel_filename, 
const char *cpu_model,
 mux = ssi_create_slave(bus, evb6965-ssi, 0);
 gpio_out[GPIO_D][0] = qdev_get_gpio_in(mux, 0);
 
-bus = qdev_get_child_bus(mux, ssi0);
+bus = qdev_get_child_bus(mux, ssi);
+
 ssi_create_slave(bus, ssi-sd, 0);
 
-bus = qdev_get_child_bus(mux, ssi1);
-dev = ssi_create_slave(bus, ssd0323, 0);
+dev = ssi_create_slave(bus, ssd0323, 1);
 gpio_out[GPIO_C][7] = qdev_get_gpio_in(dev, 0);
 
 /* Make sure the select pin is high.  */
-- 
1.7.3.2




Re: [Qemu-devel] [PATCH V4 5/5] stellaris: Updated spi bus implementation

2012-06-04 Thread Peter Crosthwaite
Regression tested using Paul Brooks test vector:

peterc@PetaLogix-ws2:~/Petalogix/Internal/plgx_install/qemu-upstream-regression/third-party/stellaris-test$
qemu-system-arm -M lm3s6965evb -serial stdio -kernel sd_card.bin -sd
sdcard.img
VNC server running on `127.0.0.1:5900'


SD Card Example Program
Type 'help' for help.

/ ls
Open
SD: Unknown CMD8
listing

A 2012/04/25 17:4412  README.TXT

   1 File(s),12 bytes total
   0 Dir(s),  61182K bytes free

/ cat README.TXT
Hello World

Gui based test works as well.

On Mon, Jun 4, 2012 at 6:08 PM, Peter A. G. Crosthwaite
peter.crosthwa...@petalogix.com wrote:
 Setup the stellaris_ssi_bus device to use a single multi-slave ssi bus instead
 of two busses.

 Signed-off-by: Peter A. G. Crosthwaite peter.crosthwa...@petalogix.com
 ---
 changed from v3:
 This patch is new

  hw/stellaris.c |   17 +++--
  1 files changed, 7 insertions(+), 10 deletions(-)

 diff --git a/hw/stellaris.c b/hw/stellaris.c
 index e0600a1..07a4187 100644
 --- a/hw/stellaris.c
 +++ b/hw/stellaris.c
 @@ -1164,22 +1164,21 @@ static int stellaris_adc_init(SysBusDevice *dev)
  typedef struct {
     SSISlave ssidev;
     qemu_irq irq;

Just curiously, AFAICT, this irq is completely dead. Paul can it be
removed in a trivial patch or is there some GPIO related black magic
occurring here?

 -    int current_dev;
 -    SSIBus *bus[2];
 +    SSIBus *bus;
  } stellaris_ssi_bus_state;

  static void stellaris_ssi_bus_select(void *opaque, int irq, int level)
  {
     stellaris_ssi_bus_state *s = (stellaris_ssi_bus_state *)opaque;

 -    s-current_dev = level;
 +    ssi_select_slave(s-bus, (uint32_t)level);
  }

  static uint32_t stellaris_ssi_bus_transfer(SSISlave *dev, uint32_t val)
  {
     stellaris_ssi_bus_state *s = FROM_SSI_SLAVE(stellaris_ssi_bus_state, dev);

 -    return ssi_transfer(s-bus[s-current_dev], val);
 +    return ssi_transfer(s-bus, val);
  }

  static const VMStateDescription vmstate_stellaris_ssi_bus = {
 @@ -1188,7 +1187,6 @@ static const VMStateDescription 
 vmstate_stellaris_ssi_bus = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
 -        VMSTATE_INT32(current_dev, stellaris_ssi_bus_state),
         VMSTATE_END_OF_LIST()
     }
  };
 @@ -1197,8 +1195,7 @@ static int stellaris_ssi_bus_init(SSISlave *dev)
  {
     stellaris_ssi_bus_state *s = FROM_SSI_SLAVE(stellaris_ssi_bus_state, dev);

 -    s-bus[0] = ssi_create_bus(dev-qdev, ssi0);
 -    s-bus[1] = ssi_create_bus(dev-qdev, ssi1);
 +    s-bus = ssi_create_bus(dev-qdev, ssi);
     qdev_init_gpio_in(dev-qdev, stellaris_ssi_bus_select, 1);

     vmstate_register(dev-qdev, -1, vmstate_stellaris_ssi_bus, s);
 @@ -1312,11 +1309,11 @@ static void stellaris_init(const char 
 *kernel_filename, const char *cpu_model,
             mux = ssi_create_slave(bus, evb6965-ssi, 0);
             gpio_out[GPIO_D][0] = qdev_get_gpio_in(mux, 0);

 -            bus = qdev_get_child_bus(mux, ssi0);
 +            bus = qdev_get_child_bus(mux, ssi);
 +
             ssi_create_slave(bus, ssi-sd, 0);

 -            bus = qdev_get_child_bus(mux, ssi1);
 -            dev = ssi_create_slave(bus, ssd0323, 0);
 +            dev = ssi_create_slave(bus, ssd0323, 1);
             gpio_out[GPIO_C][7] = qdev_get_gpio_in(dev, 0);

             /* Make sure the select pin is high.  */
 --
 1.7.3.2




Re: [Qemu-devel] [PATCH 1/3 v9] add-cow file format

2012-06-04 Thread Dong Xu Wang
Okay, thanks all of your comments, if no other comments, I will write
next version.


On Wed, May 30, 2012 at 4:20 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 On Wed, May 30, 2012 at 2:50 AM, Dong Xu Wang
 wdon...@linux.vnet.ibm.com wrote:
 On Tue, May 29, 2012 at 11:50 PM, Stefan Hajnoczi stefa...@gmail.com wrote:

 I thought a bit more about locking.  Because the metadata is simple
 not much locking is necessary except when fetching new bitmap clusters
 from the image file into the cache and when populating untouched
 sectors during data cluster allocation.  Those are the two cases where
 parallel requests could put the block driver or image file into a bad
 state if allowed to run without any locking.

 Another way of describing the consequences of parallelism:
 1. Coroutines must not duplicate the same add-cow bitmap cluster into
 the cache if they run at the same time.
 2. Coroutines must not hold bitmap tables across blocking operations
 since the cache entry has no reference count and might be evicted from
 the cache.
 3. Coroutines must not allocate the same data cluster simultaneously
 because untouched head/tail sectors must never race with guest writes.

 +static int bdrv_add_cow_truncate(BlockDriverState *bs, int64_t size)
 +{
 +    BDRVAddCowState *s = bs-opaque;
 +    int sector_per_byte = SECTORS_PER_CLUSTER * 8;
 +    int ret;
 +    int64_t old_image_sector = s-image_hd-total_sectors;
 +    int64_t bitmap_size =
 +        (size / BDRV_SECTOR_SIZE + sector_per_byte - 1) / sector_per_byte;
 +
 +    ret = bdrv_truncate(bs-file,
 +        sizeof(AddCowHeader) + bitmap_size);
 +    if (ret  0) {
 +        bdrv_truncate(s-image_hd, old_image_sector * BDRV_SECTOR_SIZE);

 Why truncate image_hd on failure?  We never touch the image_hd size on
 success either.  I think we can just leave it alone.

 That means whether we truncate add-cow fails or not ,we should not never 
 touch
 image_hd size?

 I thought about this more and I think we should truncate image_hd in
 the success case only.  In order to resize the image we need to resize
 the cow bitmap and then resize image_hd.  If resizing the add-cow file
 failed, then we haven't changed the cow bitmap and we don't need to
 truncate image_hd.  Do you agree with this or have I missed something?

 @@ -828,6 +832,41 @@ static int img_convert(int argc, char **argv)
     }

     /* Create the new image */
 +
 +    if (0 == strcmp(out_fmt, add-cow)) {
 +        image_drv = bdrv_find_format(raw);
 +        if (!drv) {
 +            ret = -1;
 +            goto out;
 +        }
 +        snprintf(image_filename, sizeof(image_filename),
 +            %s.ct.raw, out_filename);
 +        ret = bdrv_create(image_drv, image_filename, image_param);
 +        if (ret  0) {
 +            error_report(%s: error while creating image_file: %s,
 +                     image_filename, strerror(-ret));
 +            goto out;
 +        }
 +        set_option_parameter(param, BLOCK_OPT_IMAGE_FILE, image_filename);
 +
 +        if (!out_baseimg) {
 +            backing_drv = bdrv_find_format(qcow2);
 +            if (!drv) {
 +                ret = -1;
 +                goto out;
 +            }
 +            snprintf(backing_filename, sizeof(backing_filename),
 +                %s.ct.qcow2, out_filename);
 +            ret = bdrv_create(backing_drv, backing_filename, image_param);
 +            if (ret  0) {
 +                error_report(%s: error while creating backing_file: %s,
 +                         backing_filename, strerror(-ret));
 +                goto out;
 +            }
 +            set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
 +                backing_filename);
 +        }
 +    }

 If this diff hunk is dropped then the user needs to manually create
 the raw file before running qemu-img convert?

 qemu-img convert -O add-cow seems like a very rare case.  I'm not sure
 we should add special user-friend hacks for this.

 I'm not sure I understand why you create a qcow2 file either.

 Yes, if we use qemu-img convert -O add-cow, we should create 2 other files,
 raw file and qcow2(I just picked  up qcow2, other formats is also okay) file,
 as image_file and backing_file, without the two files, .add-cow file can not
 work properly.

 Although it will occour in very rare cases, I wish to pass all qemu-iotests
 cases, so I added these code.

 Do you think these are not necessary? And some qemu-iotests cases are
 using convert operation, If I do not write previous code, these cases will
 fail. Can I let these cases do not support add-cow?

 If a test uses qemu-img convert then it's probably not that
 interesting for add-cow.  Converting is not a useful operation because
 add-cow is an add-on block driver that adds a feature on top of raw,
 rather than a format like vmdk or qcow2 which is used to share disk
 images.  I see why you did this to make qemu-iotests work, but
 personally I would drop this special case code and skip those tests.

 Stefan




[Qemu-devel] [PATCH V4 4/5] petalogix-ml605: added spi controller with m25p80

2012-06-04 Thread Peter A. G. Crosthwaite
Added spi controller to the reference design, with a single cs line and a
m25p80 style spi-flash connected

Signed-off-by: Peter A. G. Crosthwaite peter.crosthwa...@petalogix.com
---
changed from v3:
set spi flashes as being fl06k
changed from v2:
changed spi - ssi
added two spi flashes to machine model instead of one

 default-configs/microblaze-softmmu.mak   |1 +
 default-configs/microblazeel-softmmu.mak |1 +
 hw/petalogix_ml605_mmu.c |   23 +++
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/default-configs/microblaze-softmmu.mak 
b/default-configs/microblaze-softmmu.mak
index 613edab..e9f2a29 100644
--- a/default-configs/microblaze-softmmu.mak
+++ b/default-configs/microblaze-softmmu.mak
@@ -3,3 +3,4 @@
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
+CONFIG_SSI=y
diff --git a/default-configs/microblazeel-softmmu.mak 
b/default-configs/microblazeel-softmmu.mak
index 4b40fb2..00c1a87 100644
--- a/default-configs/microblazeel-softmmu.mak
+++ b/default-configs/microblazeel-softmmu.mak
@@ -3,3 +3,4 @@
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
+CONFIG_SSI=y
diff --git a/hw/petalogix_ml605_mmu.c b/hw/petalogix_ml605_mmu.c
index 31a4348..01af0da 100644
--- a/hw/petalogix_ml605_mmu.c
+++ b/hw/petalogix_ml605_mmu.c
@@ -36,6 +36,7 @@
 #include blockdev.h
 #include pc.h
 #include exec-memory.h
+#include ssi.h
 
 #include microblaze_boot.h
 #include microblaze_pic_cpu.h
@@ -54,6 +55,8 @@
 #define AXIENET_BASEADDR 0x8278
 #define AXIDMA_BASEADDR 0x8460
 
+#define NUM_SPI_FLASHES 2
+
 static void machine_cpu_reset(CPUMBState *env)
 {
 env-pvr.regs[10] = 0x0e00; /* virtex 6 */
@@ -75,6 +78,7 @@ petalogix_ml605_init(ram_addr_t ram_size,
 {
 MemoryRegion *address_space_mem = get_system_memory();
 DeviceState *dev;
+SysBusDevice *busdev;
 CPUMBState *env;
 DriveInfo *dinfo;
 int i;
@@ -131,6 +135,25 @@ petalogix_ml605_init(ram_addr_t ram_size,
  irq[1], irq[0], 100 * 100);
 }
 
+{
+void *spi;
+
+dev = qdev_create(NULL, xilinx,spi);
+qdev_prop_set_uint8(dev, num-cs, NUM_SPI_FLASHES);
+qdev_init_nofail(dev);
+busdev = sysbus_from_qdev(dev);
+sysbus_mmio_map(busdev, 0, 0x40a0);
+sysbus_connect_irq(busdev, 0, irq[4]);
+
+spi = qdev_get_child_bus(dev, spi);
+
+for (i = 0; i  NUM_SPI_FLASHES; i++) {
+dev = ssi_create_slave_no_init(spi, m25p80, i);
+qdev_prop_set_string(dev, partname, (char *)s25fl064k);
+qdev_init_nofail(dev);
+}
+}
+
 microblaze_load_kernel(env, ddr_base, ram_size, BINARY_DEVICE_TREE_FILE,
 machine_cpu_reset);
 
-- 
1.7.3.2




Re: [Qemu-devel] [PULL 1.2 00/16] hub-based networking patches

2012-06-04 Thread Stefan Hajnoczi
On Mon, Jun 04, 2012 at 01:23:10PM +0800, Zhi Yong Wu wrote:
 On Mon, Jun 4, 2012 at 12:51 PM, Anthony Liguori aligu...@us.ibm.com wrote:
  On 06/04/2012 10:46 AM, zwu.ker...@gmail.com wrote:
 
  From: Zhi Yong Wuwu...@linux.vnet.ibm.com
 
  All comments from other guys were addressed.
 
 
  v3 had review comments from Paolo that you acknowledged.  I don't see a v4
  on the list.  You cannot do a pull request of unposted patches.
 I only post v4 for some of them, not all. OK. let me send all.
 
 
  Stefan, can I assume you Reviewed-by this whole series?  I don't see any
 Stefan is on his UK holiday. But i guess that he should review them.

I need to review the entire series one more time and would appreciate it
if someone else in the community (Paolo, Markus, Jan, or Luiz?) has
time to do that too.

Stefan




Re: [Qemu-devel] [PATCH v4] target-microblaze: lwx/swx: first implementation

2012-06-04 Thread Edgar E. Iglesias
Applied this one, thanks Peter




[Qemu-devel] [Bug 1008136] Re: Cannot compile 1.1.0

2012-06-04 Thread Jorge Bastos
Debian SID on x86.

Configure output:

Install prefix/usr/local
BIOS directory/usr/local/share/qemu
binary directory  /usr/local/bin
library directory /usr/local/lib
include directory /usr/local/include
config directory  /usr/local/etc
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path   /usr/local/src/qemu/qemu-1.1.0
C compilergcc
Host C compiler   gcc
CFLAGS-O2 -g
QEMU_CFLAGS   -Werror -fPIE -DPIE -m32 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes 
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes 
-fno-strict-aliasing  -fstack-protector-all -Wendif-labels 
-Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security 
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration 
-Wold-style-definition -Wtype-limits -I/usr/include/libpng12
LDFLAGS   -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m32 -g
make  make
install   install
pythonpython
smbd  /usr/sbin/smbd
host CPU  i386
host big endian   no
target list   i386-softmmu x86_64-softmmu alpha-softmmu arm-softmmu 
cris-softmmu lm32-softmmu m68k-softmmu microblaze-softmmu microblazeel-softmmu 
mips-softmmu mipsel-softmmu mips64-softmmu mips64el-softmmu ppc-softmmu 
ppcemb-softmmu ppc64-softmmu sh4-softmmu sh4eb-softmmu sparc-softmmu 
sparc64-softmmu s390x-softmmu xtensa-softmmu xtensaeb-softmmu i386-linux-user 
x86_64-linux-user alpha-linux-user arm-linux-user armeb-linux-user 
cris-linux-user m68k-linux-user microblaze-linux-user microblazeel-linux-user 
mips-linux-user mipsel-linux-user ppc-linux-user ppc64-linux-user 
ppc64abi32-linux-user sh4-linux-user sh4eb-linux-user sparc-linux-user 
sparc64-linux-user sparc32plus-linux-user unicore32-linux-user s390x-linux-user
tcg debug enabled no
Mon debug enabled no
gprof enabled no
sparse enabledno
strip binariesyes
profiler  no
static build  no
-Werror enabled   yes
SDL support   no
curses supportyes
curl support  no
mingw32 support   no
Audio drivers oss
Extra audio cards ac97 es1370 sb16 hda
Block whitelist
Mixer emulation   no
VirtFS supportyes
VNC support   yes
VNC TLS support   no
VNC SASL support  no
VNC JPEG support  yes
VNC PNG support   yes
VNC threadno
xen support   no
brlapi supportno
bluez  supportno
Documentation yes
NPTL support  yes
GUEST_BASEyes
PIE   yes
vde support   no
Linux AIO support no
ATTR/XATTR support yes
Install blobs yes
KVM support   yes
TCG interpreter   no
fdt support   no
preadv supportyes
fdatasync yes
madvise   yes
posix_madvise yes
uuid support  yes
libcap-ng support no
vhost-net support yes
Trace backend nop
Trace output file trace-pid
spice support no
rbd support   no
xfsctl supportno
nss used  no
usb net redir no
OpenGL supportno
libiscsi support  no
build guest agent yes
coroutine backend ucontext
flecha:/usr/local/src/qemu/qemu-1.1.0#

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

Title:
  Cannot compile 1.1.0

Status in QEMU:
  New

Bug description:
  Howdy,

  Testing QEMU 1.1.0 but doesn't compile:

  
CCfsdev/virtfs-proxy-helper.o
  In file included from /usr/include/i386-linux-gnu/bits/sigcontext.h:28:0,
   from /usr/include/signal.h:339,
   from ./qemu-common.h:38,
   from fsdev/virtfs-proxy-helper.c:23:
  /usr/include/i386-linux-gnu/asm/sigcontext.h:28:2: error: unknown type name 
'__u64'
  /usr/include/i386-linux-gnu/asm/sigcontext.h:191:2: error: unknown type name 
'__u64'
  /usr/include/i386-linux-gnu/asm/sigcontext.h:192:2: error: unknown type name 
'__u64'
  /usr/include/i386-linux-gnu/asm/sigcontext.h:193:2: error: unknown type name 
'__u64'
  make: *** [fsdev/virtfs-proxy-helper.o] Error 1

  
  Ideas?
  GCC 4.7, kernel 3.2x

  Thanks in advanced,
  Jorge,

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1008136/+subscriptions



[Qemu-devel] [PATCH 02/13] pci: Fold pci_bus_new_inplace into pci_bus_new

2012-06-04 Thread Jan Kiszka
There are no external users for this function.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci.c |   29 +++--
 hw/pci.h |5 -
 2 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 893f89c..33452ab 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -259,36 +259,29 @@ int pci_find_domain(const PCIBus *bus)
 return -1;
 }
 
-void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
- const char *name,
- MemoryRegion *address_space_mem,
- MemoryRegion *address_space_io,
- uint8_t devfn_min)
+PCIBus *pci_bus_new(DeviceState *parent, const char *name,
+MemoryRegion *address_space_mem,
+MemoryRegion *address_space_io,
+uint8_t devfn_min)
 {
-qbus_create_inplace(bus-qbus, pci_bus_info, parent, name);
+PCIBus *bus;
+
+bus = g_malloc0(sizeof(*bus));
+bus-qbus.qdev_allocated = 1;
+
 assert(PCI_FUNC(devfn_min) == 0);
 bus-devfn_min = devfn_min;
 bus-address_space_mem = address_space_mem;
 bus-address_space_io = address_space_io;
 
+qbus_create_inplace(bus-qbus, pci_bus_info, parent, name);
+
 /* host bridge */
 QLIST_INIT(bus-child);
 pci_host_bus_register(0, bus); /* for now only pci domain 0 is supported */
 
 vmstate_register(NULL, -1, vmstate_pcibus, bus);
-}
-
-PCIBus *pci_bus_new(DeviceState *parent, const char *name,
-MemoryRegion *address_space_mem,
-MemoryRegion *address_space_io,
-uint8_t devfn_min)
-{
-PCIBus *bus;
 
-bus = g_malloc0(sizeof(*bus));
-bus-qbus.qdev_allocated = 1;
-pci_bus_new_inplace(bus, parent, name, address_space_mem,
-address_space_io, devfn_min);
 return bus;
 }
 
diff --git a/hw/pci.h b/hw/pci.h
index c3cacce..7eaf90b 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -285,11 +285,6 @@ typedef enum {
 
 typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev,
   PCIHotplugState state);
-void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
- const char *name,
- MemoryRegion *address_space_mem,
- MemoryRegion *address_space_io,
- uint8_t devfn_min);
 PCIBus *pci_bus_new(DeviceState *parent, const char *name,
 MemoryRegion *address_space_mem,
 MemoryRegion *address_space_io,
-- 
1.7.3.4




[Qemu-devel] [PATCH 03/13] pci: Introduce cached device INTx routing

2012-06-04 Thread Jan Kiszka
Based on the original version by Michael Tsirkin: Instead of traversing
the PCI bus hierarchy from a device to the host bridge, cache this path
in PCIDevice and use it directly on interrupt delivery. This will
specifically pay off with more complex topologies than the current
single host bus.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci.c |   53 -
 hw/pci.h |4 
 2 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 33452ab..771fb39 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -68,6 +68,8 @@ static void pci_update_mappings(PCIDevice *d);
 static void pci_set_irq(void *opaque, int irq_num, int level);
 static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom);
 static void pci_del_option_rom(PCIDevice *pdev);
+static void pci_for_each_device_under_bus(PCIBus *bus,
+  void (*fn)(PCIBus *b, PCIDevice *d));
 
 static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
 static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU;
@@ -112,18 +114,49 @@ static inline void pci_set_irq_state(PCIDevice *d, int 
irq_num, int level)
d-irq_state |= level  irq_num;
 }
 
-static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
+static void pci_set_device_intx_routing(PCIBus *bus, PCIDevice *dev)
 {
-PCIBus *bus;
+int pin, output_pin;
+PCIDevice *pci_dev;
+
+/* We might be too early, i.e. before pci_bus_irqs was called.
+ * We will be called again when this happened. */
+if (!bus-map_irq) {
+return;
+}
+
+for (pin = 0; pin  PCI_NUM_PINS; pin++) {
+pci_dev = dev;
+output_pin = pin;
+do {
+bus = pci_dev-bus;
+output_pin = bus-map_irq(pci_dev, output_pin);
+pci_dev = bus-parent_dev;
+} while (pci_dev);
+
+dev-host_intx_pin[pin] = output_pin;
+dev-host_bus = bus;
+}
+}
+
+static void pci_set_bus_intx_routing(PCIBus *bus)
+{
+PCIBus *sec;
+
+pci_for_each_device_under_bus(bus, pci_set_device_intx_routing);
 
-do {
-bus = pci_dev-bus;
-irq_num = bus-map_irq(pci_dev, irq_num);
-pci_dev = bus-parent_dev;
-} while (pci_dev);
+QLIST_FOREACH(sec, bus-child, sibling) {
+pci_set_bus_intx_routing(sec);
+}
+}
+
+static void pci_change_irq_level(PCIDevice *dev, int pin, int change)
+{
+PCIBus *bus = dev-host_bus;
+int output_pin = dev-host_intx_pin[pin];
 
-bus-irq_count[irq_num] += change;
-bus-set_irq(bus-irq_opaque, irq_num, bus-irq_count[irq_num] != 0);
+bus-irq_count[output_pin] += change;
+bus-set_irq(bus-irq_opaque, output_pin, bus-irq_count[output_pin] != 0);
 }
 
 int pci_bus_get_irq_level(PCIBus *bus, int irq_num)
@@ -293,6 +326,7 @@ void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, 
pci_map_irq_fn map_irq,
 bus-irq_opaque = irq_opaque;
 bus-nirq = nirq;
 bus-irq_count = g_malloc0(nirq * sizeof(bus-irq_count[0]));
+pci_set_bus_intx_routing(bus);
 }
 
 void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, DeviceState *qdev)
@@ -798,6 +832,7 @@ static PCIDevice *do_pci_register_device(PCIDevice 
*pci_dev, PCIBus *bus,
 bus-devices[devfn] = pci_dev;
 pci_dev-irq = qemu_allocate_irqs(pci_set_irq, pci_dev, PCI_NUM_PINS);
 pci_dev-version_id = 2; /* Current pci device vmstate version */
+pci_set_device_intx_routing(bus, pci_dev);
 return pci_dev;
 }
 
diff --git a/hw/pci.h b/hw/pci.h
index 7eaf90b..c4fd863 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -211,6 +211,10 @@ struct PCIDevice {
 /* Current IRQ levels.  Used internally by the generic PCI code.  */
 uint8_t irq_state;
 
+/* Used internally by PCI code to cache the interrupt routing */
+PCIBus *host_bus;
+int host_intx_pin[PCI_NUM_PINS];
+
 /* Capability bits */
 uint32_t cap_present;
 
-- 
1.7.3.4




[Qemu-devel] [PATCH 10/13] pci: Fix coding style of pci_parse_devaddr

2012-06-04 Thread Jan Kiszka
So that we can move it unmodified without raising alarms. No functional
changes.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci.c |   52 
 1 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 4d700a9..62ad61c 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -524,43 +524,47 @@ int pci_parse_devaddr(const char *addrstr, 
PCIDeviceAddress *addr,
 
 p = addrstr;
 val = strtoul(p, e, 16);
-if (e == p)
-   return -1;
+if (e == p) {
+return -1;
+}
 if (*e == ':') {
-   bus = val;
-   p = e + 1;
-   val = strtoul(p, e, 16);
-   if (e == p)
-   return -1;
-   if (*e == ':') {
-   dom = bus;
-   bus = val;
-   p = e + 1;
-   val = strtoul(p, e, 16);
-   if (e == p)
-   return -1;
-   }
+bus = val;
+p = e + 1;
+val = strtoul(p, e, 16);
+if (e == p) {
+return -1;
+}
+if (*e == ':') {
+dom = bus;
+bus = val;
+p = e + 1;
+val = strtoul(p, e, 16);
+if (e == p) {
+return -1;
+}
+}
 }
 
 slot = val;
 
 if (flags  PCI_DEVADDR_WITH_FUNC) {
-if (*e != '.')
+if (*e != '.') {
 return -1;
-
+}
 p = e + 1;
 val = strtoul(p, e, 16);
-if (e == p)
+if (e == p) {
 return -1;
-
+}
 func = val;
 }
 
-if (dom  0x || bus  0xff || slot  0x1f || func  7)
-   return -1;
-
-if (*e)
-   return -1;
+if (dom  0x || bus  0xff || slot  0x1f || func  7) {
+return -1;
+}
+if (*e) {
+return -1;
+}
 
 addr-domain = dom;
 addr-bus = bus;
-- 
1.7.3.4




Re: [Qemu-devel] tcg_qemu_tb_exec...

2012-06-04 Thread Wei-Ren Chen
On Sun, Jun 03, 2012 at 10:44:32PM +0200, Davide Ferraretto wrote:
 I'm in qemu-arm.
 tcg_qemu_tb_exec function is a macro:
 #define tcg_qemu_tb_exec(env, tb_ptr)\
 ((long REGPARM (*)(void *, void *))code_gen_prologue)(env, tb_ptr)
 #endif

  QEMU treats execution in code cache as a function call. As you might know,
function has its prologue/epilogue, the code_gen_prologue stores the
prologue/epilogue code. After executing prologue, it'll jump to the code cache
(tb_ptr), then back to epilogue, finally return to QEMU.

Regards,
chenwj

[1] http://en.wikipedia.org/wiki/Function_prologue

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj



[Qemu-devel] [Bug 1008136] Re: Cannot compile 1.1.0

2012-06-04 Thread Jorge Bastos
Extra info, the header exists, QEMU doesn't seems to find it, it's on
this place:

http://packages.debian.org/search?searchon=contentskeywords=int-
ll64.hmode=exactfilenamesuite=stablearch=any

and provided by linux-libc-dev debian package.

How can I force configure to include this dir?

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

Title:
  Cannot compile 1.1.0

Status in QEMU:
  New

Bug description:
  Howdy,

  Testing QEMU 1.1.0 but doesn't compile:

  
CCfsdev/virtfs-proxy-helper.o
  In file included from /usr/include/i386-linux-gnu/bits/sigcontext.h:28:0,
   from /usr/include/signal.h:339,
   from ./qemu-common.h:38,
   from fsdev/virtfs-proxy-helper.c:23:
  /usr/include/i386-linux-gnu/asm/sigcontext.h:28:2: error: unknown type name 
'__u64'
  /usr/include/i386-linux-gnu/asm/sigcontext.h:191:2: error: unknown type name 
'__u64'
  /usr/include/i386-linux-gnu/asm/sigcontext.h:192:2: error: unknown type name 
'__u64'
  /usr/include/i386-linux-gnu/asm/sigcontext.h:193:2: error: unknown type name 
'__u64'
  make: *** [fsdev/virtfs-proxy-helper.o] Error 1

  
  Ideas?
  GCC 4.7, kernel 3.2x

  Thanks in advanced,
  Jorge,

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1008136/+subscriptions



Re: [Qemu-devel] [PATCH 1.1] intel-hda: Fix reset of MSI function

2012-06-04 Thread Gerd Hoffmann
On 05/30/12 10:41, Jan Kiszka wrote:
 Call msi_reset on device reset as still required by the core.

Acked-by: Gerd Hoffmann kra...@redhat.com

cheers,
  Gerd



[Qemu-devel] [PATCH 00/13] pci: Cleanups preparations for KVM device assignment

2012-06-04 Thread Jan Kiszka
Besides some smaller cleanups, this series has two main topics:

The first is the already posted PCI IRQ routing lookup and notifier. The
lookup has been based on the cached routing Michael suggested also for
emulated devices. However, this still introduces a new callback and
keeps the bus irq_count untouched due to the vmstate complications when
changing it.

The second half refactors PCI device address parsing, introducing an
universal parsing function. It is then used to provide a new qdev
property that accepts fully qualified PCI addresses (domain:bus:device.
function).

These two major changes will help refactoring PCI device assignment in
qemu-kvm in order to upstream it soon. But also the upcoming VFIO-based
assignment should be able to benefit.

Jan Kiszka (13):
  pci: Refactor pci_change_irq_level
  pci: Fold pci_bus_new_inplace into pci_bus_new
  pci: Introduce cached device INTx routing
  pci: Rename map_irq to route_pin
  pci: Add pci_device_route_intx_to_irq
  pci: Add INTx routing notifier
  pci: Make domain and bus unsigned in pci_read_devaddr
  pci: Export pci_parse_devaddr instead of pci_read_devaddr
  pci: Introduce and apply PCIDeviceAddress
  pci: Fix coding style of pci_parse_devaddr
  Move pci_parse_devaddr to qdev-properties
  qdev-properties: Use qemu_parse_pci_devaddr for pci-devfn property
  qdev-properties: Add pci-devaddr property

 hw/alpha_sys.h  |2 +-
 hw/alpha_typhoon.c  |4 +-
 hw/apb_pci.c|6 +-
 hw/bonito.c |2 +-
 hw/dec_pci.c|2 +-
 hw/grackle_pci.c|1 +
 hw/gt64xxx.c|1 +
 hw/ioh3420.c|5 +-
 hw/ioh3420.h|3 +-
 hw/pci-hotplug.c|   33 +--
 hw/pci.c|  212 ++-
 hw/pci.h|   40 +++---
 hw/pci_bridge.c |   18 +++-
 hw/pci_bridge.h |4 +-
 hw/pci_bridge_dev.c |7 +-
 hw/pci_internals.h  |5 +-
 hw/piix_pci.c   |   25 +-
 hw/ppc4xx_pci.c |2 +-
 hw/ppce500_pci.c|2 +-
 hw/prep_pci.c   |2 +-
 hw/qdev-properties.c|  142 
 hw/qdev.h   |   10 ++
 hw/sh_pci.c |2 +-
 hw/spapr_pci.c  |2 +-
 hw/unin_pci.c   |4 +-
 hw/versatile_pci.c  |2 +-
 hw/xio3130_downstream.c |5 +-
 hw/xio3130_downstream.h |3 +-
 hw/xio3130_upstream.c   |5 +-
 hw/xio3130_upstream.h   |3 +-
 qemu-common.h   |7 ++
 31 files changed, 371 insertions(+), 190 deletions(-)

-- 
1.7.3.4




Re: [Qemu-devel] ARM: Virtual / Physical address translation

2012-06-04 Thread Laurent Desnogues
On Thu, May 31, 2012 at 9:07 PM, Ira Ray Jenkins
irarayjenk...@gmail.com wrote:
 On Wed, May 30, 2012 at 10:30 AM, Laurent Desnogues
 laurent.desnog...@gmail.com wrote:
 On Wed, May 30, 2012 at 3:20 AM, Peter Maydell peter.mayd...@linaro.org 
 wrote:
 On 30 May 2012 02:00, Ira Ray Jenkins irarayjenk...@gmail.com wrote:
 What I would like is to be able to get the physical addresses of both
 data and instructions. Can anyone help me work through how to get the
 properly translated physical addresses given the virtual address?

 See the function get_phys_addr() in target-arm/helper.c ... That is
 a private function but if you're doing a local hack you can wire
 it up to what you need it for.

 Using that function directly is not that great an idea as it has
 side effects on the environment.  IMHO the best is to duplicate
 it and remove the side effects (which is what I did for my
 cache simulator).

 BTW Edgar Iglesias has implemented a cache simulator in
 QEMU.  I just can't remember where the repository is...


 Laurent

 Would I also need to duplicate get_phys_addr_mpu/v5/v6 ?

Depending on the target CPU, you'd have to duplicate one of them.

 The side effects you mentioned, are these in the above functions?

I was wrong in my previous mail:  the changes to env are done
in cpu_arm_handle_mmu_fault which is the entry point to handle
VA/PA translation from generated code.

 Since I'm really only interested in the physical address - phys_ptr -
 , can I ignore protection  page size? What about access type and
 user?

You don't need to return these values.  But be careful about
translations that fault:  if you insert your helper call before the
code for the emulated ld/st, you can get faults and in this
case you probably don't want to log that memory access.

 Edgar's work was for the cris target, so I'm unsure if it is different
 for arm.

The way it's done should be similar.

 Basically, since I am just doing a memory trace dump for arm
 target, I just want a simple translation from virtual address to
 physical, unobtrusively - without modify the state/env. I'm not sure
 how to modify get_phys_addr*() to do this. Any help would be great.

I hope you have enough information now.


Laurent



Re: [Qemu-devel] [PATCH 5/6] fdc: use LOG_UNIMP logging

2012-06-04 Thread Kevin Wolf
Am 03.06.2012 19:38, schrieb Blue Swirl:
 Convert uses of FLOPPY_ERROR to either FLOPPY_DPRINTF
 (for implemented cases) or to use LOG_UNIMP (unimplemented).
 
 Signed-off-by: Blue Swirl blauwir...@gmail.com

I would suggest that you check the messages of those cases that became
FLOPPY_DPRINTF(). Originally the macro printed FLOPPY ERROR:  and now
it's not even mentioned any more that it is an error message, making
messages like writing sector %d totally misleading.

If you fix that up:

Acked-by: Kevin Wolf kw...@redhat.com



[Qemu-devel] [PATCH 12/13] qdev-properties: Use qemu_parse_pci_devaddr for pci-devfn property

2012-06-04 Thread Jan Kiszka
Generalize qemu_parse_pci_devaddr by two flags so that it can be used
for parsing pci-devfn properties as well.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci-hotplug.c |2 +-
 hw/pci.c |3 ++-
 hw/qdev-properties.c |   49 -
 hw/qdev.h|2 ++
 4 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index 60c8989..3156e99 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -41,7 +41,7 @@ static int read_pci_devaddr(Monitor *mon, const char *addrstr,
 if (!strncmp(addrstr, pci_addr=, 9)) {
 addrstr += 9;
 }
-if (qemu_parse_pci_devaddr(addrstr, addr, 0)) {
+if (qemu_parse_pci_devaddr(addrstr, addr, PCI_DEVADDR_WITH_DOM_BUS_OPT)) {
 monitor_printf(mon, Invalid pci address\n);
 return -1;
 }
diff --git a/hw/pci.c b/hw/pci.c
index 5056fc4..ccbc6aa 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -517,7 +517,8 @@ PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 return pci_find_bus_nr(pci_find_root_bus(0), 0);
 }
 
-if (qemu_parse_pci_devaddr(devaddr, addr, 0)  0) {
+if (qemu_parse_pci_devaddr(devaddr, addr,
+   PCI_DEVADDR_WITH_DOM_BUS_OPT)  0) {
 return NULL;
 }
 
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 14ea394..32e41f1 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -817,8 +817,11 @@ PropertyInfo qdev_prop_losttickpolicy = {
 /* --- pci address --- */
 
 /*
- * Parse [[domain:]bus:]slot, return -1 on error if 
!PCI_DEVADDR_WITH_FUNC
- *   [[domain:]bus:]slot.func, return -1 on error
+ * Parse
+ *  [[domain:]bus:]slot...   if PCI_DEVADDR_WITH_DOM_BUS_OPT
+ *  ...slot.func   if PCI_DEVADDR_WITH_FUNC
+ *  ...slot[.func] if PCI_DEVADDR_WITH_FUNC_OPT
+ * return -1 on error
  */
 int qemu_parse_pci_devaddr(const char *addrstr, PCIDeviceAddress *addr,
unsigned int flags)
@@ -836,6 +839,9 @@ int qemu_parse_pci_devaddr(const char *addrstr, 
PCIDeviceAddress *addr,
 return -1;
 }
 if (*e == ':') {
+if (!(flags  PCI_DEVADDR_WITH_DOM_BUS_OPT)) {
+return -1;
+}
 bus = val;
 p = e + 1;
 val = strtoul(p, e, 16);
@@ -855,16 +861,19 @@ int qemu_parse_pci_devaddr(const char *addrstr, 
PCIDeviceAddress *addr,
 
 slot = val;
 
-if (flags  PCI_DEVADDR_WITH_FUNC) {
+if (flags  (PCI_DEVADDR_WITH_FUNC | PCI_DEVADDR_WITH_FUNC_OPT)) {
 if (*e != '.') {
-return -1;
-}
-p = e + 1;
-val = strtoul(p, e, 16);
-if (e == p) {
-return -1;
+if (flags  PCI_DEVADDR_WITH_FUNC) {
+return -1;
+}
+} else {
+p = e + 1;
+val = strtoul(p, e, 16);
+if (e == p) {
+return -1;
+}
+func = val;
 }
-func = val;
 }
 
 if (dom  0x || bus  0xff || slot  0x1f || func  7) {
@@ -890,7 +899,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void 
*opaque,
 DeviceState *dev = DEVICE(obj);
 Property *prop = opaque;
 uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
-unsigned int slot, fn, n;
+PCIDeviceAddress addr;
 Error *local_err = NULL;
 char *str;
 
@@ -905,21 +914,11 @@ static void set_pci_devfn(Object *obj, Visitor *v, void 
*opaque,
 return set_int32(obj, v, opaque, name, errp);
 }
 
-if (sscanf(str, %x.%x%n, slot, fn, n) != 2) {
-fn = 0;
-if (sscanf(str, %x%n, slot, n) != 1) {
-goto invalid;
-}
-}
-if (str[n] != '\0' || fn  7 || slot  31) {
-goto invalid;
+if (qemu_parse_pci_devaddr(str, addr, PCI_DEVADDR_WITH_FUNC_OPT)  0) {
+error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+} else {
+*ptr = addr.slot  3 | addr.function;
 }
-*ptr = slot  3 | fn;
-g_free(str);
-return;
-
-invalid:
-error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
 g_free(str);
 }
 
diff --git a/hw/qdev.h b/hw/qdev.h
index 102550b..15acfca 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -360,7 +360,9 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
 
 extern int qdev_hotplug;
 
+#define PCI_DEVADDR_WITH_DOM_BUS_OPT1
 #define PCI_DEVADDR_WITH_FUNC   2
+#define PCI_DEVADDR_WITH_FUNC_OPT   4
 
 int qemu_parse_pci_devaddr(const char *addrstr, PCIDeviceAddress *addr,
unsigned int flags);
-- 
1.7.3.4




[Qemu-devel] [PATCH 04/13] pci: Rename map_irq to route_pin

2012-06-04 Thread Jan Kiszka
To avoid confusion with the board-level IRQ the host bridge triggers on
output, rename the per-bridge routing function for the INTx pins to
pci_route_pin_fn. Also adjust variable names of that type. And
rename pci_bridge_map_irq to pci_bridge_prepare, which better reflects
the job of that function.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/alpha_sys.h  |2 +-
 hw/alpha_typhoon.c  |2 +-
 hw/apb_pci.c|4 ++--
 hw/dec_pci.c|2 +-
 hw/ioh3420.c|5 +++--
 hw/ioh3420.h|3 ++-
 hw/pci.c|   14 --
 hw/pci.h|8 +---
 hw/pci_bridge.c |   10 +-
 hw/pci_bridge.h |4 ++--
 hw/pci_bridge_dev.c |7 ---
 hw/pci_internals.h  |4 ++--
 hw/xio3130_downstream.c |5 +++--
 hw/xio3130_downstream.h |3 ++-
 hw/xio3130_upstream.c   |5 +++--
 hw/xio3130_upstream.h   |3 ++-
 16 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/hw/alpha_sys.h b/hw/alpha_sys.h
index de40f8b..ddeb360 100644
--- a/hw/alpha_sys.h
+++ b/hw/alpha_sys.h
@@ -12,7 +12,7 @@
 
 
 PCIBus *typhoon_init(ram_addr_t, ISABus **, qemu_irq *, CPUAlphaState *[4],
- pci_map_irq_fn);
+ pci_route_pin_fn);
 
 /* alpha_pci.c.  */
 extern const MemoryRegionOps alpha_pci_bw_io_ops;
diff --git a/hw/alpha_typhoon.c b/hw/alpha_typhoon.c
index 872e112..d5193bb 100644
--- a/hw/alpha_typhoon.c
+++ b/hw/alpha_typhoon.c
@@ -693,7 +693,7 @@ static void typhoon_alarm_timer(void *opaque)
 
 PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
  qemu_irq *p_rtc_irq,
- CPUAlphaState *cpus[4], pci_map_irq_fn sys_map_irq)
+ CPUAlphaState *cpus[4], pci_route_pin_fn sys_map_irq)
 {
 const uint64_t MB = 1024 * 1024;
 const uint64_t GB = 1024 * MB;
diff --git a/hw/apb_pci.c b/hw/apb_pci.c
index c28411a..57ead09 100644
--- a/hw/apb_pci.c
+++ b/hw/apb_pci.c
@@ -392,7 +392,7 @@ PCIBus *pci_apb_init(target_phys_addr_t special_base,
 pci_dev = pci_create_multifunction(d-bus, PCI_DEVFN(1, 0), true,
pbm-bridge);
 br = DO_UPCAST(PCIBridge, dev, pci_dev);
-pci_bridge_map_irq(br, Advanced PCI Bus secondary bridge 1,
+pci_bridge_prepare(br, Advanced PCI Bus secondary bridge 1,
pci_apb_map_irq);
 qdev_init_nofail(pci_dev-qdev);
 *bus2 = pci_bridge_get_sec_bus(br);
@@ -400,7 +400,7 @@ PCIBus *pci_apb_init(target_phys_addr_t special_base,
 pci_dev = pci_create_multifunction(d-bus, PCI_DEVFN(1, 1), true,
pbm-bridge);
 br = DO_UPCAST(PCIBridge, dev, pci_dev);
-pci_bridge_map_irq(br, Advanced PCI Bus secondary bridge 2,
+pci_bridge_prepare(br, Advanced PCI Bus secondary bridge 2,
pci_apb_map_irq);
 qdev_init_nofail(pci_dev-qdev);
 *bus3 = pci_bridge_get_sec_bus(br);
diff --git a/hw/dec_pci.c b/hw/dec_pci.c
index 37337bf..be63ac7 100644
--- a/hw/dec_pci.c
+++ b/hw/dec_pci.c
@@ -81,7 +81,7 @@ PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
 dev = pci_create_multifunction(parent_bus, devfn, false,
dec-21154-p2p-bridge);
 br = DO_UPCAST(PCIBridge, dev, dev);
-pci_bridge_map_irq(br, DEC 21154 PCI-PCI bridge, dec_map_irq);
+pci_bridge_prepare(br, DEC 21154 PCI-PCI bridge, dec_map_irq);
 qdev_init_nofail(dev-qdev);
 return pci_bridge_get_sec_bus(br);
 }
diff --git a/hw/ioh3420.c b/hw/ioh3420.c
index 1632d31..21bc1fb 100644
--- a/hw/ioh3420.c
+++ b/hw/ioh3420.c
@@ -164,7 +164,8 @@ static int ioh3420_exitfn(PCIDevice *d)
 }
 
 PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction,
- const char *bus_name, pci_map_irq_fn map_irq,
+ const char *bus_name,
+ pci_route_pin_fn route_intx_pin,
  uint8_t port, uint8_t chassis, uint16_t slot)
 {
 PCIDevice *d;
@@ -178,7 +179,7 @@ PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool 
multifunction,
 br = DO_UPCAST(PCIBridge, dev, d);
 
 qdev = br-dev.qdev;
-pci_bridge_map_irq(br, bus_name, map_irq);
+pci_bridge_prepare(br, bus_name, route_intx_pin);
 qdev_prop_set_uint8(qdev, port, port);
 qdev_prop_set_uint8(qdev, chassis, chassis);
 qdev_prop_set_uint16(qdev, slot, slot);
diff --git a/hw/ioh3420.h b/hw/ioh3420.h
index 68c523a..091bef4 100644
--- a/hw/ioh3420.h
+++ b/hw/ioh3420.h
@@ -4,7 +4,8 @@
 #include pcie_port.h
 
 PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction,
-   const char *bus_name, pci_map_irq_fn map_irq,
+   const char *bus_name,
+   pci_route_pin_fn route_intx_pin,
uint8_t port, uint8_t chassis, uint16_t slot);
 
 #endif /* QEMU_IOH3420_H */
diff --git a/hw/pci.c 

[Qemu-devel] [PATCH 07/13] pci: Make domain and bus unsigned in pci_read_devaddr

2012-06-04 Thread Jan Kiszka
It's the more appropriate type as there are no negative domain or bus
values.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci-hotplug.c |4 ++--
 hw/pci.c |   11 ++-
 hw/pci.h |4 ++--
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index c55d8b9..e0ea8bb 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -108,7 +108,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
 int pci_drive_hot_add(Monitor *mon, const QDict *qdict,
   DriveInfo *dinfo, int type)
 {
-int dom, pci_bus;
+unsigned int dom, pci_bus;
 unsigned slot;
 PCIDevice *dev;
 const char *pci_addr = qdict_get_str(qdict, pci_addr);
@@ -257,7 +257,7 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
 static int pci_device_hot_remove(Monitor *mon, const char *pci_addr)
 {
 PCIDevice *d;
-int dom, bus;
+unsigned int dom, bus;
 unsigned slot;
 Error *local_err = NULL;
 
diff --git a/hw/pci.c b/hw/pci.c
index 5b99f4b..d4c8b71 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -512,8 +512,9 @@ static void pci_set_default_subsystem_id(PCIDevice *pci_dev)
  * Parse [[domain:]bus:]slot, return -1 on error if funcp == NULL
  *   [[domain:]bus:]slot.func, return -1 on error
  */
-static int pci_parse_devaddr(const char *addr, int *domp, int *busp,
-  unsigned int *slotp, unsigned int *funcp)
+static int pci_parse_devaddr(const char *addr, unsigned int *domp,
+ unsigned int *busp, unsigned int *slotp,
+ unsigned int *funcp)
 {
 const char *p;
 char *e;
@@ -571,8 +572,8 @@ static int pci_parse_devaddr(const char *addr, int *domp, 
int *busp,
 return 0;
 }
 
-int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
- unsigned *slotp)
+int pci_read_devaddr(Monitor *mon, const char *addr, unsigned int *domp,
+ unsigned int *busp, unsigned *slotp)
 {
 /* strip legacy tag */
 if (!strncmp(addr, pci_addr=, 9)) {
@@ -587,7 +588,7 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int 
*domp, int *busp,
 
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 {
-int dom, bus;
+unsigned int dom, bus;
 unsigned slot;
 
 if (!devaddr) {
diff --git a/hw/pci.h b/hw/pci.h
index e7237cf..0c38c36 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -340,8 +340,8 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, 
uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
 
-int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
- unsigned *slotp);
+int pci_read_devaddr(Monitor *mon, const char *addr, unsigned int *domp,
+ unsigned int *busp, unsigned *slotp);
 
 void pci_device_deassert_intx(PCIDevice *dev);
 
-- 
1.7.3.4




[Qemu-devel] [PATCH 06/13] pci: Add INTx routing notifier

2012-06-04 Thread Jan Kiszka
This per-device notifier shall be triggered by any interrupt router
along the path of a device's legacy interrupt signal on routing changes.
For simplicity reasons and as this is a slow path anyway, no further
details on the routing changes are provided. Instead, the callback is
expected to use pci_device_get_host_irq to check the effect of the
change.

Will be used by KVM PCI device assignment and VFIO.

Acked-by: Alex Williamson alex.william...@redhat.com
Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci.c|   19 +++
 hw/pci.h|7 +++
 hw/pci_bridge.c |8 
 hw/piix_pci.c   |2 ++
 4 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 8878a11..5b99f4b 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1101,6 +1101,25 @@ PCIINTxRoute pci_device_route_intx_to_irq(PCIDevice 
*dev, int pin)
 return bus-route_intx_to_irq(bus-irq_opaque, dev-host_intx_pin[pin]);
 }
 
+void pci_bus_fire_intx_routing_notifier(PCIBus *bus)
+{
+PCIDevice *dev;
+int i;
+
+for (i = 0; i  ARRAY_SIZE(bus-devices); ++i) {
+dev = bus-devices[i];
+if (dev  dev-intx_routing_notifier) {
+dev-intx_routing_notifier(dev);
+}
+}
+}
+
+void pci_device_set_intx_routing_notifier(PCIDevice *dev,
+  INTxRoutingNotifier notifier)
+{
+dev-intx_routing_notifier = notifier;
+}
+
 /***/
 /* monitor info on PCI */
 
diff --git a/hw/pci.h b/hw/pci.h
index bbba01e..e7237cf 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -182,6 +182,7 @@ typedef struct PCIDeviceClass {
 const char *romfile;
 } PCIDeviceClass;
 
+typedef void (*INTxRoutingNotifier)(PCIDevice *dev);
 typedef int (*MSIVectorUseNotifier)(PCIDevice *dev, unsigned int vector,
   MSIMessage msg);
 typedef void (*MSIVectorReleaseNotifier)(PCIDevice *dev, unsigned int vector);
@@ -261,6 +262,9 @@ struct PCIDevice {
 MemoryRegion rom;
 uint32_t rom_bar;
 
+/* INTx routing notifier */
+INTxRoutingNotifier intx_routing_notifier;
+
 /* MSI-X notifiers */
 MSIVectorUseNotifier msix_vector_use_notifier;
 MSIVectorReleaseNotifier msix_vector_release_notifier;
@@ -318,6 +322,9 @@ PCIBus *pci_register_bus(DeviceState *parent, const char 
*name,
  MemoryRegion *address_space_io,
  uint8_t devfn_min, int nirq);
 PCIINTxRoute pci_device_route_intx_to_irq(PCIDevice *dev, int pin);
+void pci_bus_fire_intx_routing_notifier(PCIBus *bus);
+void pci_device_set_intx_routing_notifier(PCIDevice *dev,
+  INTxRoutingNotifier notifier);
 void pci_device_reset(PCIDevice *dev);
 void pci_bus_reset(PCIBus *bus);
 
diff --git a/hw/pci_bridge.c b/hw/pci_bridge.c
index 7d13a85..9ace0b7 100644
--- a/hw/pci_bridge.c
+++ b/hw/pci_bridge.c
@@ -298,6 +298,13 @@ void pci_bridge_reset(DeviceState *qdev)
 pci_bridge_reset_reg(dev);
 }
 
+static void pci_bridge_intx_routing_update(PCIDevice *dev)
+{
+PCIBridge *br = DO_UPCAST(PCIBridge, dev, dev);
+
+pci_bus_fire_intx_routing_notifier(br-sec_bus);
+}
+
 /* default qdev initialization function for PCI-to-PCI bridge */
 int pci_bridge_initfn(PCIDevice *dev)
 {
@@ -333,6 +340,7 @@ int pci_bridge_initfn(PCIDevice *dev)
 sec_bus-address_space_io = br-address_space_io;
 memory_region_init(br-address_space_io, pci_bridge_io, 65536);
 pci_bridge_region_init(br);
+pci_device_set_intx_routing_notifier(dev, pci_bridge_intx_routing_update);
 QLIST_INIT(sec_bus-child);
 QLIST_INSERT_HEAD(parent-child, sec_bus, sibling);
 return 0;
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index 347177f..8fd21f3 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -422,6 +422,8 @@ static void piix3_write_config(PCIDevice *dev,
 if (ranges_overlap(address, len, PIIX_PIRQC, 4)) {
 PIIX3State *piix3 = DO_UPCAST(PIIX3State, dev, dev);
 int pic_irq;
+
+pci_bus_fire_intx_routing_notifier(piix3-dev.bus);
 piix3_update_irq_levels(piix3);
 for (pic_irq = 0; pic_irq  PIIX_NUM_PIC_IRQS; pic_irq++) {
 piix3_set_irq_pic(piix3, pic_irq);
-- 
1.7.3.4




[Qemu-devel] [PATCH 05/13] pci: Add pci_device_route_intx_to_irq

2012-06-04 Thread Jan Kiszka
Add a PCI IRQ path discovery function that walks from a given device to
the host bridge, returning the mode (enabled/inverted/disabled) and the
IRQ number that is reported to the attached interrupt controller. For
this purpose, another host bridge callback function is introduced:
route_intx_to_irq. It is so far only implemented by the PIIX3, other
host bridges can be added later on as required.

Will be used for KVM PCI device assignment and VFIO.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/alpha_typhoon.c |2 +-
 hw/apb_pci.c   |2 +-
 hw/bonito.c|2 +-
 hw/grackle_pci.c   |1 +
 hw/gt64xxx.c   |1 +
 hw/pci.c   |   14 +-
 hw/pci.h   |   13 +
 hw/pci_internals.h |1 +
 hw/piix_pci.c  |   23 ---
 hw/ppc4xx_pci.c|2 +-
 hw/ppce500_pci.c   |2 +-
 hw/prep_pci.c  |2 +-
 hw/sh_pci.c|2 +-
 hw/spapr_pci.c |2 +-
 hw/unin_pci.c  |4 ++--
 hw/versatile_pci.c |2 +-
 16 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/hw/alpha_typhoon.c b/hw/alpha_typhoon.c
index d5193bb..1056b50 100644
--- a/hw/alpha_typhoon.c
+++ b/hw/alpha_typhoon.c
@@ -764,7 +764,7 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
 s-pchip.reg_io);
 
 b = pci_register_bus(s-host.busdev.qdev, pci,
- typhoon_set_irq, sys_map_irq, s,
+ typhoon_set_irq, sys_map_irq, NULL, s,
  s-pchip.reg_mem, addr_space_io, 0, 64);
 s-host.bus = b;
 
diff --git a/hw/apb_pci.c b/hw/apb_pci.c
index 57ead09..270a785 100644
--- a/hw/apb_pci.c
+++ b/hw/apb_pci.c
@@ -378,7 +378,7 @@ PCIBus *pci_apb_init(target_phys_addr_t special_base,
 memory_region_add_subregion(get_system_memory(), mem_base, d-pci_mmio);
 
 d-bus = pci_register_bus(d-busdev.qdev, pci,
-  pci_apb_set_irq, pci_pbm_map_irq, d,
+  pci_apb_set_irq, pci_pbm_map_irq, NULL, d,
   d-pci_mmio,
   get_system_io(),
   0, 32);
diff --git a/hw/bonito.c b/hw/bonito.c
index 77786f8..7ce5993 100644
--- a/hw/bonito.c
+++ b/hw/bonito.c
@@ -750,7 +750,7 @@ PCIBus *bonito_init(qemu_irq *pic)
 dev = qdev_create(NULL, Bonito-pcihost);
 pcihost = FROM_SYSBUS(BonitoState, sysbus_from_qdev(dev));
 b = pci_register_bus(pcihost-busdev.qdev, pci, pci_bonito_set_irq,
- pci_bonito_map_irq, pic, get_system_memory(),
+ pci_bonito_map_irq, NULL, pic, get_system_memory(),
  get_system_io(),
  0x28, 32);
 pcihost-bus = b;
diff --git a/hw/grackle_pci.c b/hw/grackle_pci.c
index 81ff3a3..f47d9fe 100644
--- a/hw/grackle_pci.c
+++ b/hw/grackle_pci.c
@@ -85,6 +85,7 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic,
 d-host_state.bus = pci_register_bus(d-busdev.qdev, pci,
  pci_grackle_set_irq,
  pci_grackle_map_irq,
+ NULL,
  pic,
  d-pci_mmio,
  address_space_io,
diff --git a/hw/gt64xxx.c b/hw/gt64xxx.c
index a2d0e5a..2418238 100644
--- a/hw/gt64xxx.c
+++ b/hw/gt64xxx.c
@@ -1093,6 +1093,7 @@ PCIBus *gt64120_register(qemu_irq *pic)
 d = FROM_SYSBUS(GT64120State, s);
 d-pci.bus = pci_register_bus(d-busdev.qdev, pci,
   gt64120_pci_set_irq, gt64120_pci_map_irq,
+  NULL,
   pic,
   get_system_memory(),
   get_system_io(),
diff --git a/hw/pci.c b/hw/pci.c
index 9a2b4a3..8878a11 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -320,10 +320,12 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name,
 
 void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq,
   pci_route_pin_fn route_intx_pin,
+  pci_route_irq_fn route_intx_to_irq,
   void *irq_opaque, int nirq)
 {
 bus-set_irq = set_irq;
 bus-route_intx_pin = route_intx_pin;
+bus-route_intx_to_irq = route_intx_to_irq;
 bus-irq_opaque = irq_opaque;
 bus-nirq = nirq;
 bus-irq_count = g_malloc0(nirq * sizeof(bus-irq_count[0]));
@@ -340,6 +342,7 @@ void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, 
DeviceState *qdev)
 PCIBus *pci_register_bus(DeviceState *parent, const char *name,
  pci_set_irq_fn set_irq,
  pci_route_pin_fn route_intx_pin,
+ pci_route_irq_fn route_intx_to_irq,
  void *irq_opaque,
  MemoryRegion *address_space_mem,

[Qemu-devel] [PATCH 09/13] pci: Introduce and apply PCIDeviceAddress

2012-06-04 Thread Jan Kiszka
This type encapsulates everything from domain to function. Use it first
to simplify the pci_parse_devaddr interface.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci-hotplug.c |   29 ++---
 hw/pci.c |   31 ++-
 hw/pci.h |6 --
 qemu-common.h|7 +++
 4 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index e1654dc..aff4d85 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -34,14 +34,14 @@
 #include blockdev.h
 #include error.h
 
-static int read_pci_devaddr(Monitor *mon, const char *addr, unsigned int *domp,
-unsigned int *busp, unsigned *slotp)
+static int read_pci_devaddr(Monitor *mon, const char *addrstr,
+PCIDeviceAddress *addr)
 {
 /* strip legacy tag */
-if (!strncmp(addr, pci_addr=, 9)) {
-addr += 9;
+if (!strncmp(addrstr, pci_addr=, 9)) {
+addrstr += 9;
 }
-if (pci_parse_devaddr(addr, domp, busp, slotp, NULL)) {
+if (pci_parse_devaddr(addrstr, addr, 0)) {
 monitor_printf(mon, Invalid pci address\n);
 return -1;
 }
@@ -122,18 +122,17 @@ static int scsi_hot_add(Monitor *mon, DeviceState 
*adapter,
 int pci_drive_hot_add(Monitor *mon, const QDict *qdict,
   DriveInfo *dinfo, int type)
 {
-unsigned int dom, pci_bus;
-unsigned slot;
+PCIDeviceAddress addr;
 PCIDevice *dev;
 const char *pci_addr = qdict_get_str(qdict, pci_addr);
 
 switch (type) {
 case IF_SCSI:
-if (read_pci_devaddr(mon, pci_addr, dom, pci_bus, slot)) {
+if (read_pci_devaddr(mon, pci_addr, addr)) {
 goto err;
 }
-dev = pci_find_device(pci_find_root_bus(dom), pci_bus,
-  PCI_DEVFN(slot, 0));
+dev = pci_find_device(pci_find_root_bus(addr.domain), addr.bus,
+  PCI_DEVFN(addr.slot, 0));
 if (!dev) {
 monitor_printf(mon, no pci device with address %s\n, pci_addr);
 goto err;
@@ -270,18 +269,18 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
 
 static int pci_device_hot_remove(Monitor *mon, const char *pci_addr)
 {
+PCIDeviceAddress addr;
 PCIDevice *d;
-unsigned int dom, bus;
-unsigned slot;
 Error *local_err = NULL;
 
-if (read_pci_devaddr(mon, pci_addr, dom, bus, slot)) {
+if (read_pci_devaddr(mon, pci_addr, addr)) {
 return -1;
 }
 
-d = pci_find_device(pci_find_root_bus(dom), bus, PCI_DEVFN(slot, 0));
+d = pci_find_device(pci_find_root_bus(addr.domain), addr.bus,
+PCI_DEVFN(addr.slot, 0));
 if (!d) {
-monitor_printf(mon, slot %d empty\n, slot);
+monitor_printf(mon, slot %d empty\n, addr.slot);
 return -1;
 }
 
diff --git a/hw/pci.c b/hw/pci.c
index 6471a68..4d700a9 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -509,20 +509,20 @@ static void pci_set_default_subsystem_id(PCIDevice 
*pci_dev)
 }
 
 /*
- * Parse [[domain:]bus:]slot, return -1 on error if funcp == NULL
+ * Parse [[domain:]bus:]slot, return -1 on error if 
!PCI_DEVADDR_WITH_FUNC
  *   [[domain:]bus:]slot.func, return -1 on error
  */
-int pci_parse_devaddr(const char *addr, unsigned int *domp, unsigned int *busp,
-  unsigned int *slotp, unsigned int *funcp)
+int pci_parse_devaddr(const char *addrstr, PCIDeviceAddress *addr,
+  unsigned int flags)
 {
 const char *p;
 char *e;
 unsigned long val;
 unsigned long dom = 0, bus = 0;
-unsigned int slot = 0;
+unsigned int slot;
 unsigned int func = 0;
 
-p = addr;
+p = addrstr;
 val = strtoul(p, e, 16);
 if (e == p)
return -1;
@@ -544,7 +544,7 @@ int pci_parse_devaddr(const char *addr, unsigned int *domp, 
unsigned int *busp,
 
 slot = val;
 
-if (funcp != NULL) {
+if (flags  PCI_DEVADDR_WITH_FUNC) {
 if (*e != '.')
 return -1;
 
@@ -556,37 +556,34 @@ int pci_parse_devaddr(const char *addr, unsigned int 
*domp, unsigned int *busp,
 func = val;
 }
 
-/* if funcp == NULL func is 0 */
 if (dom  0x || bus  0xff || slot  0x1f || func  7)
return -1;
 
 if (*e)
return -1;
 
-*domp = dom;
-*busp = bus;
-*slotp = slot;
-if (funcp != NULL)
-*funcp = func;
+addr-domain = dom;
+addr-bus = bus;
+addr-slot = slot;
+addr-function = func;
 return 0;
 }
 
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 {
-unsigned int dom, bus;
-unsigned slot;
+PCIDeviceAddress addr;
 
 if (!devaddr) {
 *devfnp = -1;
 return pci_find_bus_nr(pci_find_root_bus(0), 0);
 }
 
-if (pci_parse_devaddr(devaddr, dom, bus, slot, NULL)  0) {
+if (pci_parse_devaddr(devaddr, addr, 0)  0) {
 return NULL;
 }
 
-*devfnp = PCI_DEVFN(slot, 0);

[Qemu-devel] [PATCH v2 36/41] postcopy: implement incoming part of postcopy live migration

2012-06-04 Thread Isaku Yamahata
This patch implements postcopy live migration for incoming part

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
Changes v3 - v4:
- fork umemd early to address qemu devices touching guest ram via
  post/pre_load
- code clean up on initialization
- Makefile.target
  migration-postcopy.c is target dependent due to TARGET_PAGE_xxx
  So it can't be shared between target architecture.
- use qemu_fopen_fd
- introduce incoming_flags_use_umem_make_present flag
- use MADV_DONTNEED

Changes v2 - v3:
- make incoming socket nonblocking
- several clean ups
- Dropped QEMUFilePipe
- Moved QEMUFileNonblock to buffered_file
- Split out into umem/incoming/outgoing

Changes v1 - v2:
- make mig_read nonblocking when socket
- updates for umem device changes
---
 Makefile.target|5 +
 cpu-all.h  |7 +
 exec.c |   20 +-
 migration-exec.c   |4 +
 migration-fd.c |6 +
 .../linux/umem.h = migration-postcopy-stub.c  |   47 +-
 migration-postcopy.c   | 1267 
 migration.c|4 +
 migration.h|   13 +
 qemu-common.h  |1 +
 qemu-options.hx|5 +-
 savevm.c   |   43 +
 vl.c   |8 +-
 13 files changed, 1409 insertions(+), 21 deletions(-)
 copy linux-headers/linux/umem.h = migration-postcopy-stub.c (55%)
 create mode 100644 migration-postcopy.c

diff --git a/Makefile.target b/Makefile.target
index 1582904..618bd3e 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -4,6 +4,7 @@ GENERATED_HEADERS = config-target.h
 CONFIG_NO_PCI = $(if $(subst n,,$(CONFIG_PCI)),n,y)
 CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)
 CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
+CONFIG_NO_POSTCOPY = $(if $(subst n,,$(CONFIG_POSTCOPY)),n,y)
 
 include ../config-host.mak
 include config-devices.mak
@@ -196,6 +197,10 @@ LIBS+=-lz
 
 obj-i386-$(CONFIG_KVM) += hyperv.o
 
+obj-$(CONFIG_POSTCOPY) += migration-postcopy.o
+obj-$(CONFIG_NO_POSTCOPY) += migration-postcopy-stub.o
+common-obj-$(CONFIG_POSTCOPY) += umem.o
+
 QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
 QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
diff --git a/cpu-all.h b/cpu-all.h
index ff7f827..e0956bc 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -486,6 +486,9 @@ extern ram_addr_t ram_size;
 /* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */
 #define RAM_PREALLOC_MASK   (1  0)
 
+/* RAM is allocated via umem for postcopy incoming mode */
+#define RAM_POSTCOPY_UMEM_MASK  (1  1)
+
 typedef struct RAMBlock {
 struct MemoryRegion *mr;
 uint8_t *host;
@@ -497,6 +500,10 @@ typedef struct RAMBlock {
 #if defined(__linux__)  !defined(TARGET_S390X)
 int fd;
 #endif
+
+#ifdef CONFIG_POSTCOPY
+UMem *umem;/* for incoming postcopy mode */
+#endif
 } RAMBlock;
 
 typedef struct RAMList {
diff --git a/exec.c b/exec.c
index 785..e5ff2ed 100644
--- a/exec.c
+++ b/exec.c
@@ -36,6 +36,7 @@
 #include arch_init.h
 #include memory.h
 #include exec-memory.h
+#include migration.h
 #if defined(CONFIG_USER_ONLY)
 #include qemu.h
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
@@ -2632,6 +2633,13 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
 new_block-host = host;
 new_block-flags |= RAM_PREALLOC_MASK;
 } else {
+#ifdef CONFIG_POSTCOPY
+if (incoming_postcopy) {
+ram_addr_t page_size = getpagesize();
+size = (size + page_size - 1)  ~(page_size - 1);
+mem_path = NULL;
+}
+#endif
 if (mem_path) {
 #if defined (__linux__)  !defined(TARGET_S390X)
 new_block-host = file_ram_alloc(new_block, size, mem_path);
@@ -2709,7 +2717,13 @@ void qemu_ram_free(ram_addr_t addr)
 QLIST_REMOVE(block, next);
 if (block-flags  RAM_PREALLOC_MASK) {
 ;
-} else if (mem_path) {
+}
+#ifdef CONFIG_POSTCOPY
+else if (block-flags  RAM_POSTCOPY_UMEM_MASK) {
+postcopy_incoming_ram_free(block-umem);
+}
+#endif
+else if (mem_path) {
 #if defined (__linux__)  !defined(TARGET_S390X)
 if (block-fd) {
 munmap(block-host, block-length);
@@ -2755,6 +2769,10 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
 } else {
 flags = MAP_FIXED;
 munmap(vaddr, length);
+if (block-flags  RAM_POSTCOPY_UMEM_MASK) {
+postcopy_incoming_qemu_pages_unmapped(addr, length);
+block-flags = ~RAM_POSTCOPY_UMEM_MASK;
+}
 if 

[Qemu-devel] [PATCH 01/13] pci: Refactor pci_change_irq_level

2012-06-04 Thread Jan Kiszka
Align the bus traversal in pci_change_irq_level to other functions. They
use PCIBus:parent_dev to detect the root.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index c1ebdde..893f89c 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -115,13 +115,13 @@ static inline void pci_set_irq_state(PCIDevice *d, int 
irq_num, int level)
 static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
 {
 PCIBus *bus;
-for (;;) {
+
+do {
 bus = pci_dev-bus;
 irq_num = bus-map_irq(pci_dev, irq_num);
-if (bus-set_irq)
-break;
 pci_dev = bus-parent_dev;
-}
+} while (pci_dev);
+
 bus-irq_count[irq_num] += change;
 bus-set_irq(bus-irq_opaque, irq_num, bus-irq_count[irq_num] != 0);
 }
-- 
1.7.3.4




[Qemu-devel] [PATCH 11/13] Move pci_parse_devaddr to qdev-properties

2012-06-04 Thread Jan Kiszka
We will some use this function also for property parsing, so move it
over unmodified and rename it.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci-hotplug.c |2 +-
 hw/pci.c |   67 +-
 hw/pci.h |5 ---
 hw/qdev-properties.c |   65 
 hw/qdev.h|5 +++
 5 files changed, 72 insertions(+), 72 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index aff4d85..60c8989 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -41,7 +41,7 @@ static int read_pci_devaddr(Monitor *mon, const char *addrstr,
 if (!strncmp(addrstr, pci_addr=, 9)) {
 addrstr += 9;
 }
-if (pci_parse_devaddr(addrstr, addr, 0)) {
+if (qemu_parse_pci_devaddr(addrstr, addr, 0)) {
 monitor_printf(mon, Invalid pci address\n);
 return -1;
 }
diff --git a/hw/pci.c b/hw/pci.c
index 62ad61c..5056fc4 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -508,71 +508,6 @@ static void pci_set_default_subsystem_id(PCIDevice 
*pci_dev)
  pci_default_sub_device_id);
 }
 
-/*
- * Parse [[domain:]bus:]slot, return -1 on error if 
!PCI_DEVADDR_WITH_FUNC
- *   [[domain:]bus:]slot.func, return -1 on error
- */
-int pci_parse_devaddr(const char *addrstr, PCIDeviceAddress *addr,
-  unsigned int flags)
-{
-const char *p;
-char *e;
-unsigned long val;
-unsigned long dom = 0, bus = 0;
-unsigned int slot;
-unsigned int func = 0;
-
-p = addrstr;
-val = strtoul(p, e, 16);
-if (e == p) {
-return -1;
-}
-if (*e == ':') {
-bus = val;
-p = e + 1;
-val = strtoul(p, e, 16);
-if (e == p) {
-return -1;
-}
-if (*e == ':') {
-dom = bus;
-bus = val;
-p = e + 1;
-val = strtoul(p, e, 16);
-if (e == p) {
-return -1;
-}
-}
-}
-
-slot = val;
-
-if (flags  PCI_DEVADDR_WITH_FUNC) {
-if (*e != '.') {
-return -1;
-}
-p = e + 1;
-val = strtoul(p, e, 16);
-if (e == p) {
-return -1;
-}
-func = val;
-}
-
-if (dom  0x || bus  0xff || slot  0x1f || func  7) {
-return -1;
-}
-if (*e) {
-return -1;
-}
-
-addr-domain = dom;
-addr-bus = bus;
-addr-slot = slot;
-addr-function = func;
-return 0;
-}
-
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 {
 PCIDeviceAddress addr;
@@ -582,7 +517,7 @@ PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 return pci_find_bus_nr(pci_find_root_bus(0), 0);
 }
 
-if (pci_parse_devaddr(devaddr, addr, 0)  0) {
+if (qemu_parse_pci_devaddr(devaddr, addr, 0)  0) {
 return NULL;
 }
 
diff --git a/hw/pci.h b/hw/pci.h
index 6c48ffa..a3e5ad9 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -340,11 +340,6 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, 
uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
 
-#define PCI_DEVADDR_WITH_FUNC   2
-
-int pci_parse_devaddr(const char *addrstr, PCIDeviceAddress *addr,
-  unsigned int flags);
-
 void pci_device_deassert_intx(PCIDevice *dev);
 
 static inline void
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index b7b5597..14ea394 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -817,6 +817,71 @@ PropertyInfo qdev_prop_losttickpolicy = {
 /* --- pci address --- */
 
 /*
+ * Parse [[domain:]bus:]slot, return -1 on error if 
!PCI_DEVADDR_WITH_FUNC
+ *   [[domain:]bus:]slot.func, return -1 on error
+ */
+int qemu_parse_pci_devaddr(const char *addrstr, PCIDeviceAddress *addr,
+   unsigned int flags)
+{
+const char *p;
+char *e;
+unsigned long val;
+unsigned long dom = 0, bus = 0;
+unsigned int slot;
+unsigned int func = 0;
+
+p = addrstr;
+val = strtoul(p, e, 16);
+if (e == p) {
+return -1;
+}
+if (*e == ':') {
+bus = val;
+p = e + 1;
+val = strtoul(p, e, 16);
+if (e == p) {
+return -1;
+}
+if (*e == ':') {
+dom = bus;
+bus = val;
+p = e + 1;
+val = strtoul(p, e, 16);
+if (e == p) {
+return -1;
+}
+}
+}
+
+slot = val;
+
+if (flags  PCI_DEVADDR_WITH_FUNC) {
+if (*e != '.') {
+return -1;
+}
+p = e + 1;
+val = strtoul(p, e, 16);
+if (e == p) {
+return -1;
+}
+func = val;
+}
+
+if (dom  0x || bus  0xff || slot  0x1f || func  7) {
+return -1;
+}
+if (*e) {
+return -1;
+}
+
+addr-domain = dom;
+  

[Qemu-devel] [PATCH v2 10/41] arch_init: simplify a bit by ram_find_block()

2012-06-04 Thread Isaku Yamahata
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 arch_init.c |   21 -
 exec.c  |   12 ++--
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 9981abe..73bf250 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -432,11 +432,10 @@ void *ram_load_host_from_stream_offset(QEMUFile *f,
 qemu_get_buffer(f, (uint8_t *)id, len);
 id[len] = 0;
 
-QLIST_FOREACH(block, ram_list.blocks, next) {
-if (!strncmp(id, block-idstr, sizeof(id))) {
-*last_blockp = block;
-return memory_region_get_ram_ptr(block-mr) + offset;
-}
+block = ram_find_block(id, len);
+if (block) {
+*last_blockp = block;
+return memory_region_get_ram_ptr(block-mr) + offset;
 }
 
 fprintf(stderr, Can't find block %s!\n, id);
@@ -466,19 +465,15 @@ int ram_load_mem_size(QEMUFile *f, ram_addr_t 
total_ram_bytes)
 id[len] = 0;
 length = qemu_get_be64(f);
 
-QLIST_FOREACH(block, ram_list.blocks, next) {
-if (!strncmp(id, block-idstr, sizeof(id))) {
-if (block-length != length)
-return -EINVAL;
-break;
-}
-}
-
+block = ram_find_block(id, len);
 if (!block) {
 fprintf(stderr, Unknown ramblock \%s\, cannot 
 accept migration\n, id);
 return -EINVAL;
 }
+if (block-length != length) {
+return -EINVAL;
+}
 
 total_ram_bytes -= length;
 }
diff --git a/exec.c b/exec.c
index a0494c7..078a408 100644
--- a/exec.c
+++ b/exec.c
@@ -33,6 +33,7 @@
 #include kvm.h
 #include hw/xen.h
 #include qemu-timer.h
+#include arch_init.h
 #include memory.h
 #include exec-memory.h
 #if defined(CONFIG_USER_ONLY)
@@ -2609,12 +2610,11 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char 
*name, DeviceState *dev)
 }
 pstrcat(new_block-idstr, sizeof(new_block-idstr), name);
 
-QLIST_FOREACH(block, ram_list.blocks, next) {
-if (block != new_block  !strcmp(block-idstr, new_block-idstr)) {
-fprintf(stderr, RAMBlock \%s\ already registered, abort!\n,
-new_block-idstr);
-abort();
-}
+block = ram_find_block(new_block-idstr, strlen(new_block-idstr));
+if (block != new_block) {
+fprintf(stderr, RAMBlock \%s\ already registered, abort!\n,
+new_block-idstr);
+abort();
 }
 }
 
-- 
1.7.1.1




[Qemu-devel] [PATCHv3] Get system state configuration from QEMU and patch DSDT with it.

2012-06-04 Thread Gleb Natapov
QEMU may want to disable guest's S3/S4 support and it wants to distinguish
between regular powerdown and S4 powerdown. To support that new fw_cfg
option was added that passes supported system states and what value should
guest use to enter each state. States are passed in 6 byte array. Each
byte represents one system state. If byte at offset X has its MSB set
it means that system state X is supported and to enter it guest should
use the value from lowest 7 bits. Patch also detects old QEMU and uses
values that work in backwards compatible way there.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 src/acpi-dsdt.dsl  |   32 -
 src/acpi-dsdt.hex  |   42 +---
 src/acpi.c |   15 
 src/ssdt-pcihp.dsl |   36 ++
 src/ssdt-pcihp.hex |  185 +---
 5 files changed, 172 insertions(+), 138 deletions(-)

diff --git a/src/acpi-dsdt.dsl b/src/acpi-dsdt.dsl
index 4bdc268..37899fc 100644
--- a/src/acpi-dsdt.dsl
+++ b/src/acpi-dsdt.dsl
@@ -604,38 +604,6 @@ DefinitionBlock (
 }
 }
 
-
-/
- * Suspend
- /
-
-/*
- * S3 (suspend-to-ram), S4 (suspend-to-disk) and S5 (power-off) type codes:
- * must match piix4 emulation.
- */
-Name (\_S3, Package (0x04)
-{
-0x01,  /* PM1a_CNT.SLP_TYP */
-0x01,  /* PM1b_CNT.SLP_TYP */
-Zero,  /* reserved */
-Zero   /* reserved */
-})
-Name (\_S4, Package (0x04)
-{
-Zero,  /* PM1a_CNT.SLP_TYP */
-Zero,  /* PM1b_CNT.SLP_TYP */
-Zero,  /* reserved */
-Zero   /* reserved */
-})
-Name (\_S5, Package (0x04)
-{
-Zero,  /* PM1a_CNT.SLP_TYP */
-Zero,  /* PM1b_CNT.SLP_TYP */
-Zero,  /* reserved */
-Zero   /* reserved */
-})
-
-
 /
  * CPU hotplug
  /
diff --git a/src/acpi-dsdt.hex b/src/acpi-dsdt.hex
index a4af597..8678fbf 100644
--- a/src/acpi-dsdt.hex
+++ b/src/acpi-dsdt.hex
@@ -3,12 +3,12 @@ static unsigned char AmlCode[] = {
 0x53,
 0x44,
 0x54,
-0x21,
-0x11,
+0xfd,
+0x10,
 0x0,
 0x0,
 0x1,
-0xe8,
+0x4a,
 0x42,
 0x58,
 0x50,
@@ -3925,42 +3925,6 @@ static unsigned char AmlCode[] = {
 0x52,
 0x51,
 0x30,
-0x8,
-0x5f,
-0x53,
-0x33,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x1,
-0x1,
-0x0,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x34,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x35,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x0,
-0x0,
-0x0,
-0x0,
 0x10,
 0x49,
 0xe,
diff --git a/src/acpi.c b/src/acpi.c
index 30888b9..06ffe0a 100644
--- a/src/acpi.c
+++ b/src/acpi.c
@@ -492,6 +492,8 @@ extern void link_time_assertion(void);
 
 static void* build_pcihp(void)
 {
+char *sys_states;
+int sys_state_size;
 u32 rmvc_pcrm;
 int i;
 
@@ -523,6 +525,19 @@ static void* build_pcihp(void)
 }
 }
 
+sys_states = romfile_loadfile(etc/system-states, sys_state_size);
+if (!sys_states || sys_state_size != 6)
+sys_states = (char[]){128, 0, 0, 129, 128, 128};
+
+if (!(sys_states[3]  128))
+ssdt[acpi_s3_name[0]] = 'X';
+if (!(sys_states[4]  128))
+ssdt[acpi_s4_name[0]] = 'X';
+else
+ssdt[acpi_s4_pkg[0] + 1] = ssdt[acpi_s4_pkg[0] + 3] = sys_states[4]  
127;
+((struct acpi_table_header*)ssdt)-checksum = 0;
+((struct acpi_table_header*)ssdt)-checksum -= checksum(ssdt, 
sizeof(ssdp_pcihp_aml));
+
 return ssdt;
 }
 
diff --git a/src/ssdt-pcihp.dsl b/src/ssdt-pcihp.dsl
index 4b435b8..12555e2 100644
--- a/src/ssdt-pcihp.dsl
+++ b/src/ssdt-pcihp.dsl
@@ -95,4 +95,40 @@ DefinitionBlock (ssdt-pcihp.aml, SSDT, 0x01, BXPC, 
BXSSDTPCIHP, 0x1)
 gen_pci_hotplug(1f)
 }
 }
+
+Scope(\) {
+/
+ * Suspend
+ /
+
+/*
+ * S3 (suspend-to-ram), S4 (suspend-to-disk) and S5 (power-off) type codes:
+ * must match piix4 emulation.
+ */
+
+ACPI_EXTRACT_NAME_STRING acpi_s3_name
+Name (_S3, Package (0x04)
+{
+One,  /* PM1a_CNT.SLP_TYP */
+One,  /* PM1b_CNT.SLP_TYP */
+Zero,  /* reserved */
+Zero   /* reserved */
+})
+ACPI_EXTRACT_NAME_STRING acpi_s4_name
+ACPI_EXTRACT_PKG_START acpi_s4_pkg
+Name (_S4, Package (0x04)
+{
+0x2,  /* PM1a_CNT.SLP_TYP */
+0x2,  /* PM1b_CNT.SLP_TYP */
+Zero,  /* reserved */
+Zero   /* reserved */
+})
+Name (_S5, Package (0x04)
+{
+Zero,  /* PM1a_CNT.SLP_TYP */
+Zero,  /* PM1b_CNT.SLP_TYP */
+Zero,  /* reserved */
+Zero   /* reserved */
+})
+}
 }
diff --git 

Re: [Qemu-devel] [PATCH 1.2 0/7] Manual writethrough cache and cache mode toggle

2012-06-04 Thread Kevin Wolf
Am 22.05.2012 18:17, schrieb Paolo Bonzini:
 This is an alternative implementation of writethrough caching.  By always
 opening protocols in writethrough mode and doing flushes manually after
 every write, it achieves two results: 1) it makes flipping the cache mode
 extremely easy; 2) it lets formats control flushes during metadata updates
 even in writethrough mode, which makes the updates more efficient; 3)
 it makes cache=writethrough automatically flush metadata without needing
 extra work in the formats.
 
 In practice, the performance result is a wash.  I measured make -j3
 vmlinux on a 2-core guest/4-core host, with 2GB memory in the guest
 and 8GB in the host.
 
 Performance was measured starting qemu-kvm with an empty qcow2 image,
 a virtio disk and cache=writethrough (F16 installation + exploded kernel
 tarball in the backing file), and the results are as follows:
 
 without patch:
 real9m22.416s user12m8.955s sys 3m46.331s
 real9m21.602s user12m20.124s sys 3m51.126s
 real9m22.258s user12m14.900s sys 3m48.595s
 
 with patch:
 real9m17.617s user12m16.837s sys 3m48.637s
 real9m18.926s user12m20.083s sys 3m50.458s
 real9m15.751s user12m41.944s sys 3m56.447s
 
 Unlike the RFC, this is tested exactly with these seven patches.  The RFC
 was tested with follow-up cleanups that hid the problem in patch 3.
 
 v1-v2: only patch 3 changed, was completely backwards in v1

Are you going to send a v3 for patches 3 and possibly 5/6?

Kevin



[Qemu-devel] [PATCH v2 18/41] QEMUFile: add qemu_file_fd() for later use

2012-06-04 Thread Isaku Yamahata
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 qemu-file.h |1 +
 savevm.c|   12 
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/qemu-file.h b/qemu-file.h
index 331ac8b..98a8023 100644
--- a/qemu-file.h
+++ b/qemu-file.h
@@ -71,6 +71,7 @@ QEMUFile *qemu_fopen_socket(int fd);
 QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
 int qemu_stdio_fd(QEMUFile *f);
+int qemu_file_fd(QEMUFile *f);
 void qemu_fflush(QEMUFile *f);
 void qemu_buffered_file_drain(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
diff --git a/savevm.c b/savevm.c
index fb47529..cba1a69 100644
--- a/savevm.c
+++ b/savevm.c
@@ -178,6 +178,7 @@ struct QEMUFile {
 uint8_t buf[IO_BUF_SIZE];
 
 int last_error;
+int fd; /* -1 means fd isn't associated */
 };
 
 typedef struct QEMUFileStdio
@@ -276,6 +277,7 @@ QEMUFile *qemu_popen(FILE *stdio_file, const char *mode)
 s-file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_pclose, 
 NULL, NULL, NULL);
 }
+s-file-fd = fileno(stdio_file);
 return s-file;
 }
 
@@ -291,6 +293,7 @@ QEMUFile *qemu_popen_cmd(const char *command, const char 
*mode)
 return qemu_popen(popen_file, mode);
 }
 
+/* TODO: replace this with qemu_file_fd() */
 int qemu_stdio_fd(QEMUFile *f)
 {
 QEMUFileStdio *p;
@@ -325,6 +328,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
 s-file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_fclose, 
 NULL, NULL, NULL);
 }
+s-file-fd = fd;
 return s-file;
 
 fail:
@@ -339,6 +343,7 @@ QEMUFile *qemu_fopen_socket(int fd)
 s-fd = fd;
 s-file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, 
 NULL, NULL, NULL);
+s-file-fd = fd;
 return s-file;
 }
 
@@ -381,6 +386,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
 s-file = qemu_fopen_ops(s, NULL, file_get_buffer, stdio_fclose, 
   NULL, NULL, NULL);
 }
+s-file-fd = fileno(s-stdio_file);
 return s-file;
 fail:
 g_free(s);
@@ -431,10 +437,16 @@ QEMUFile *qemu_fopen_ops(void *opaque, 
QEMUFilePutBufferFunc *put_buffer,
 f-set_rate_limit = set_rate_limit;
 f-get_rate_limit = get_rate_limit;
 f-is_write = 0;
+f-fd = -1;
 
 return f;
 }
 
+int qemu_file_fd(QEMUFile *f)
+{
+return f-fd;
+}
+
 int qemu_file_get_error(QEMUFile *f)
 {
 return f-last_error;
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 30/41] update-linux-headers.sh: teach umem.h to update-linux-headers.sh

2012-06-04 Thread Isaku Yamahata
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 scripts/update-linux-headers.sh |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 9d2a4bc..2afdd54 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -43,7 +43,7 @@ done
 
 rm -rf $output/linux-headers/linux
 mkdir -p $output/linux-headers/linux
-for header in kvm.h kvm_para.h vhost.h virtio_config.h virtio_ring.h; do
+for header in kvm.h kvm_para.h vhost.h virtio_config.h virtio_ring.h umem.h; do
 cp $tmpdir/include/linux/$header $output/linux-headers/linux
 done
 if [ -L $linux/source ]; then
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 26/41] buffered_file: factor out buffer management logic

2012-06-04 Thread Isaku Yamahata
This patch factors out buffer management logic.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 buffered_file.c |  141 +-
 buffered_file.h |8 +++
 2 files changed, 94 insertions(+), 55 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index a38caec..22dd4c9 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -20,24 +20,6 @@
 #include buffered_file.h
 
 //#define DEBUG_BUFFERED_FILE
-
-typedef struct QEMUFileBuffered
-{
-BufferedPutFunc *put_buffer;
-BufferedPutReadyFunc *put_ready;
-BufferedWaitForUnfreezeFunc *wait_for_unfreeze;
-BufferedCloseFunc *close;
-void *opaque;
-QEMUFile *file;
-int freeze_output;
-size_t bytes_xfer;
-size_t xfer_limit;
-uint8_t *buffer;
-size_t buffer_size;
-size_t buffer_capacity;
-QEMUTimer *timer;
-} QEMUFileBuffered;
-
 #ifdef DEBUG_BUFFERED_FILE
 #define DPRINTF(fmt, ...) \
 do { printf(buffered-file:  fmt, ## __VA_ARGS__); } while (0)
@@ -46,57 +28,71 @@ typedef struct QEMUFileBuffered
 do { } while (0)
 #endif
 
-static void buffered_append(QEMUFileBuffered *s,
-const uint8_t *buf, size_t size)
-{
-if (size  (s-buffer_capacity - s-buffer_size)) {
-void *tmp;
-
-DPRINTF(increasing buffer capacity from %zu by %zu\n,
-s-buffer_capacity, size + 1024);
 
-s-buffer_capacity += size + 1024;
+/***
+ * buffer management
+ */
 
-tmp = g_realloc(s-buffer, s-buffer_capacity);
-if (tmp == NULL) {
-fprintf(stderr, qemu file buffer expansion failed\n);
-exit(1);
-}
+static void buffer_destroy(QEMUBuffer *s)
+{
+g_free(s-buffer);
+}
 
-s-buffer = tmp;
+static void buffer_consume(QEMUBuffer *s, size_t offset)
+{
+if (offset  0) {
+assert(s-buffer_size = offset);
+memmove(s-buffer, s-buffer + offset, s-buffer_size - offset);
+s-buffer_size -= offset;
 }
+}
 
+static void buffer_append(QEMUBuffer *s, const uint8_t *buf, size_t size)
+{
+#define BUF_SIZE_INC(32 * 1024) /* = IO_BUF_SIZE */
+int inc = size - (s-buffer_capacity - s-buffer_size);
+if (inc  0) {
+s-buffer_capacity += DIV_ROUND_UP(inc, BUF_SIZE_INC) * BUF_SIZE_INC;
+s-buffer = g_realloc(s-buffer, s-buffer_capacity);
+}
 memcpy(s-buffer + s-buffer_size, buf, size);
 s-buffer_size += size;
 }
 
-static void buffered_flush(QEMUFileBuffered *s)
+typedef ssize_t (BufferPutBuf)(void *opaque, const void *data, size_t size);
+
+static void buffer_flush(QEMUBuffer *buf, QEMUFile *file,
+ void *opaque, BufferPutBuf *put_buf)
 {
 size_t offset = 0;
 int error;
 
-error = qemu_file_get_error(s-file);
+error = qemu_file_get_error(file);
 if (error != 0) {
 DPRINTF(flush when error, bailing: %s\n, strerror(-error));
 return;
 }
 
-DPRINTF(flushing %zu byte(s) of data\n, s-buffer_size);
+DPRINTF(flushing %zu byte(s) of data\n, buf-buffer_size);
 
-while (offset  s-buffer_size) {
+while (offset  buf-buffer_size) {
 ssize_t ret;
 
-ret = s-put_buffer(s-opaque, s-buffer + offset,
-s-buffer_size - offset);
-if (ret == -EAGAIN) {
+ret = put_buf(opaque, buf-buffer + offset, buf-buffer_size - offset);
+if (ret == -EINTR) {
+continue;
+} else if (ret == -EAGAIN) {
 DPRINTF(backend not ready, freezing\n);
-s-freeze_output = 1;
+buf-freeze_output = true;
 break;
 }
 
-if (ret = 0) {
+if (ret  0) {
 DPRINTF(error flushing data, %zd\n, ret);
-qemu_file_set_error(s-file, ret);
+qemu_file_set_error(file, ret);
+break;
+} else if (ret == 0) {
+DPRINTF(ret == 0\n);
 break;
 } else {
 DPRINTF(flushed %zd byte(s)\n, ret);
@@ -104,9 +100,44 @@ static void buffered_flush(QEMUFileBuffered *s)
 }
 }
 
-DPRINTF(flushed %zu of %zu byte(s)\n, offset, s-buffer_size);
-memmove(s-buffer, s-buffer + offset, s-buffer_size - offset);
-s-buffer_size -= offset;
+DPRINTF(flushed %zu of %zu byte(s)\n, offset, buf-buffer_size);
+buffer_consume(buf, offset);
+}
+
+
+/***
+ * Buffered File
+ */
+
+typedef struct QEMUFileBuffered
+{
+BufferedPutFunc *put_buffer;
+BufferedPutReadyFunc *put_ready;
+BufferedWaitForUnfreezeFunc *wait_for_unfreeze;
+BufferedCloseFunc *close;
+void *opaque;
+QEMUFile *file;
+size_t bytes_xfer;
+size_t xfer_limit;
+QEMUTimer *timer;
+QEMUBuffer buf;
+} QEMUFileBuffered;
+
+static ssize_t buffered_flush_putbuf(void *opaque,
+ const 

[Qemu-devel] [PATCH v2 13/41] exec.c: factor out qemu_get_ram_ptr()

2012-06-04 Thread Isaku Yamahata
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 cpu-all.h |2 ++
 exec.c|   51 +--
 2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index 028528f..ff7f827 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -508,6 +508,8 @@ extern RAMList ram_list;
 extern const char *mem_path;
 extern int mem_prealloc;
 
+RAMBlock *qemu_get_ram_block(ram_addr_t adar);
+
 /* Flags stored in the low bits of the TLB virtual address.  These are
defined so that fast path ram access is all zeros.  */
 /* Zero if TLB entry is valid.  */
diff --git a/exec.c b/exec.c
index 078a408..7f44893 100644
--- a/exec.c
+++ b/exec.c
@@ -2799,15 +2799,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
 }
 #endif /* !_WIN32 */
 
-/* Return a host pointer to ram allocated with qemu_ram_alloc.
-   With the exception of the softmmu code in this file, this should
-   only be used for local memory (e.g. video ram) that the device owns,
-   and knows it isn't going to access beyond the end of the block.
-
-   It should not be used for general purpose DMA.
-   Use cpu_physical_memory_map/cpu_physical_memory_rw instead.
- */
-void *qemu_get_ram_ptr(ram_addr_t addr)
+RAMBlock *qemu_get_ram_block(ram_addr_t addr)
 {
 RAMBlock *block;
 
@@ -2818,19 +2810,7 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
 QLIST_REMOVE(block, next);
 QLIST_INSERT_HEAD(ram_list.blocks, block, next);
 }
-if (xen_enabled()) {
-/* We need to check if the requested address is in the RAM
- * because we don't want to map the entire memory in QEMU.
- * In that case just map until the end of the page.
- */
-if (block-offset == 0) {
-return xen_map_cache(addr, 0, 0);
-} else if (block-host == NULL) {
-block-host =
-xen_map_cache(block-offset, block-length, 1);
-}
-}
-return block-host + (addr - block-offset);
+return block;
 }
 }
 
@@ -2841,6 +2821,33 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
 }
 
 /* Return a host pointer to ram allocated with qemu_ram_alloc.
+   With the exception of the softmmu code in this file, this should
+   only be used for local memory (e.g. video ram) that the device owns,
+   and knows it isn't going to access beyond the end of the block.
+
+   It should not be used for general purpose DMA.
+   Use cpu_physical_memory_map/cpu_physical_memory_rw instead.
+ */
+void *qemu_get_ram_ptr(ram_addr_t addr)
+{
+RAMBlock *block = qemu_get_ram_block(addr);
+
+if (xen_enabled()) {
+/* We need to check if the requested address is in the RAM
+ * because we don't want to map the entire memory in QEMU.
+ * In that case just map until the end of the page.
+ */
+if (block-offset == 0) {
+return xen_map_cache(addr, 0, 0);
+} else if (block-host == NULL) {
+block-host =
+xen_map_cache(block-offset, block-length, 1);
+}
+}
+return block-host + (addr - block-offset);
+}
+
+/* Return a host pointer to ram allocated with qemu_ram_alloc.
  * Same as qemu_get_ram_ptr but avoid reordering ramblocks.
  */
 void *qemu_safe_ram_ptr(ram_addr_t addr)
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 38/41] postcopy/outgoing: add forward, backward option to specify the size of prefault

2012-06-04 Thread Isaku Yamahata
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 hmp-commands.hx  |   15 ++-
 hmp.c|3 +++
 migration.c  |   20 
 migration.h  |2 ++
 qapi-schema.json |3 ++-
 5 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 3c647f7..38e5c95 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -798,26 +798,31 @@ ETEXI
 
 {
 .name   = migrate,
-.args_type  = detach:-d,blk:-b,inc:-i,postcopy:-p,nobg:-n,uri:s,
-.params = [-d] [-b] [-i] [-p [-n]] uri,
+.args_type  = detach:-d,blk:-b,inc:-i,postcopy:-p,nobg:-n,uri:s,
+ forward:i?,backward:i?,
+.params = [-d] [-b] [-i] [-p [-n] uri [forward] [backword],
 .help   = migrate to URI (using -d to not wait for completion)
  \n\t\t\t -b for migration without shared storage with
   full copy of disk\n\t\t\t -i for migration without 
  shared storage with incremental copy of disk 
  (base image shared between src and destination)
  \n\t\t\t-p for migration with postcopy mode enabled
- \n\t\t\t-n for no background transfer of postcopy mode,
+ \n\t\t\t-n for no background transfer of postcopy mode
+ \n\t\t\tforward: the number of pages to 
+ forward-prefault when postcopy (default 0)
+ \n\t\t\tbackward: the number of pages to 
+ backward-prefault when postcopy (default 0),
 .mhandler.cmd = hmp_migrate,
 },
 
 
 STEXI
-@item migrate [-d] [-b] [-i] [-p [-n]] @var{uri}
+@item migrate [-d] [-b] [-i] [-p [-n]] @var{uri} @var{forward} @var{backward}
 @findex migrate
 Migrate to @var{uri} (using -d to not wait for completion).
-b for migration with full copy of disk
-i for migration with incremental copy of disk (base image is shared)
-   -p for migration with postcopy mode enabled
+   -p for migration with postcopy mode enabled (forward/backward is 
prefault size when postcopy)
-n for migration with postcopy mode enabled without background transfer
 ETEXI
 
diff --git a/hmp.c b/hmp.c
index d546a52..79a9c86 100644
--- a/hmp.c
+++ b/hmp.c
@@ -913,11 +913,14 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
 int inc = qdict_get_try_bool(qdict, inc, 0);
 int postcopy = qdict_get_try_bool(qdict, postcopy, 0);
 int nobg = qdict_get_try_bool(qdict, nobg, 0);
+int forward = qdict_get_try_int(qdict, forward, 0);
+int backward = qdict_get_try_int(qdict, backward, 0);
 const char *uri = qdict_get_str(qdict, uri);
 Error *err = NULL;
 
 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false,
 !!postcopy, postcopy, !!nobg, nobg,
+!!forward, forward, !!backward, backward,
 err);
 if (err) {
 monitor_printf(mon, migrate: %s\n, error_get_pretty(err));
diff --git a/migration.c b/migration.c
index e8be0d1..e026085 100644
--- a/migration.c
+++ b/migration.c
@@ -423,6 +423,8 @@ void migrate_del_blocker(Error *reason)
 void qmp_migrate(const char *uri, bool has_blk, bool blk,
  bool has_inc, bool inc, bool has_detach, bool detach,
  bool has_postcopy, bool postcopy, bool has_nobg, bool nobg,
+ bool has_forward, int64_t forward,
+ bool has_backward, int64_t backward,
  Error **errp)
 {
 MigrationState *s = migrate_get_current();
@@ -431,6 +433,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 .shared = false,
 .postcopy = false,
 .nobg = false,
+.prefault_forward = 0,
+.prefault_backward = 0,
 };
 const char *p;
 int ret;
@@ -447,6 +451,22 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 if (has_nobg) {
 params.nobg = nobg;
 }
+if (has_forward) {
+if (forward  0) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+  forward, forward = 0);
+return;
+}
+params.prefault_forward = forward;
+}
+if (has_backward) {
+if (backward  0) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+  backward, backward = 0);
+return;
+}
+params.prefault_backward = backward;
+}
 
 if (s-state == MIG_STATE_ACTIVE) {
 error_set(errp, QERR_MIGRATION_ACTIVE);
diff --git a/migration.h b/migration.h
index 90f3bdf..9a9b9c6 100644
--- a/migration.h
+++ b/migration.h
@@ -24,6 +24,8 @@ struct MigrationParams {
 int shared;
 int postcopy;
 int nobg;
+int64_t prefault_forward;
+int64_t prefault_backward;
 };
 
 typedef struct MigrationState MigrationState;
diff --git a/qapi-schema.json b/qapi-schema.json
index 5861fb9..83c2170 100644

[Qemu-devel] [PATCH v2 00/41] postcopy live migration

2012-06-04 Thread Isaku Yamahata
After the long time, we have v2. This is qemu part.
The linux kernel part is sent separatedly.

Changes v1 - v2:
- split up patches for review
- buffered file refactored
- many bug fixes
  Espcially PV drivers can work with postcopy
- optimization/heuristic

Patches
1 - 30: refactoring exsiting code and preparation
31 - 37: implement postcopy itself (essential part)
38 - 41: some optimization/heuristic for postcopy

Intro
=
This patch series implements postcopy live migration.[1]
As discussed at KVM forum 2011, dedicated character device is used for
distributed shared memory between migration source and destination.
Now we can discuss/benchmark/compare with precopy. I believe there are
much rooms for improvement.

[1] http://wiki.qemu.org/Features/PostCopyLiveMigration


Usage
=
You need load umem character device on the host before starting migration.
Postcopy can be used for tcg and kvm accelarator. The implementation depend
on only linux umem character device. But the driver dependent code is split
into a file.
I tested only host page size == guest page size case, but the implementation
allows host page size != guest page size case.

The following options are added with this patch series.
- incoming part
  command line options
  -postcopy [-postcopy-flags flags]
  where flags is for changing behavior for benchmark/debugging
  Currently the following flags are available
  0: default
  1: enable touching page request

  example:
  qemu -postcopy -incoming tcp:0: -monitor stdio -machine accel=kvm

- outging part
  options for migrate command 
  migrate [-p [-n] [-m]] URI [prefault forward [prefault backword]]
  -p: indicate postcopy migration
  -n: disable background transferring pages: This is for benchmark/debugging
  -m: move background transfer of postcopy mode
  prefault forward: The number of forward pages which is sent with on-demand
  prefault backward: The number of backward pages which is sent with
   on-demand

  example:
  migrate -p -n tcp:dest ip address: 
  migrate -p -n -m tcp:dest ip address: 32 0


TODO

- benchmark/evaluation. Especially how async page fault affects the result.
- improve/optimization
  At the moment at least what I'm aware of is
  - making incoming socket non-blocking with thread
As page compression is comming, it is impractical to non-blocking read
and check if the necessary data is read.
  - touching pages in incoming qemu process by fd handler seems suboptimal.
creating dedicated thread?
  - outgoing handler seems suboptimal causing latency.
- consider on FUSE/CUSE possibility
- don't fork umemd, but create thread?

basic postcopy work flow

qemu on the destination
  |
  V
open(/dev/umem)
  |
  V
UMEM_INIT
  |
  V
Here we have two file descriptors to
umem device and shmem file
  |
  |  umemd
  |  daemon on the destination
  |
  Vcreate pipe to communicate
fork()---,
  |  |
  V  |
close(socket)V
close(shmem)  mmap(shmem file)
  |  |
  V  V
mmap(umem device) for guest RAM   close(shmem file)
  |  |
close(umem device)   |
  |  |
  V  |
wait for ready from daemon pipe-send ready message
  |  |
  | Here the daemon takes over 
send okpipe--- the owner of the socket
  | to the source  
  V  |
entering post copy stage |
start guest execution|
  |  |
  V  V
access guest RAM  read() to get faulted pages
  |  |
  V  V
page fault --page offset is returned
block|
 V
  pull page from the source
  write the page contents

[Qemu-devel] [PATCH v2 24/41] migration: export migrate_fd_completed() and migrate_fd_cleanup()

2012-06-04 Thread Isaku Yamahata
This will be used by postcopy migration.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 migration.c |4 ++--
 migration.h |2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/migration.c b/migration.c
index 753addb..48a8f68 100644
--- a/migration.c
+++ b/migration.c
@@ -159,7 +159,7 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 
 /* shared migration helpers */
 
-static int migrate_fd_cleanup(MigrationState *s)
+int migrate_fd_cleanup(MigrationState *s)
 {
 int ret = 0;
 
@@ -187,7 +187,7 @@ void migrate_fd_error(MigrationState *s)
 migrate_fd_cleanup(s);
 }
 
-static void migrate_fd_completed(MigrationState *s)
+void migrate_fd_completed(MigrationState *s)
 {
 DPRINTF(setting completed state\n);
 if (migrate_fd_cleanup(s)  0) {
diff --git a/migration.h b/migration.h
index 6cf4512..d0dd536 100644
--- a/migration.h
+++ b/migration.h
@@ -62,7 +62,9 @@ int fd_start_incoming_migration(const char *path);
 
 int fd_start_outgoing_migration(MigrationState *s, const char *fdname);
 
+int migrate_fd_cleanup(MigrationState *s);
 void migrate_fd_error(MigrationState *s);
+void migrate_fd_completed(MigrationState *s);
 
 void migrate_fd_connect(MigrationState *s);
 
-- 
1.7.1.1




[Qemu-devel] [PATCH v3 1/2] export necessary symbols

2012-06-04 Thread Isaku Yamahata
Cc: Andrea Arcangeli aarca...@redhat.com
Cc: Avi Kivity a...@redhat.com
Cc: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 mm/memcontrol.c |1 +
 mm/mempolicy.c  |1 +
 mm/shmem.c  |1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ac35bcc..265ba2f 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2761,6 +2761,7 @@ int mem_cgroup_cache_charge(struct page *page, struct 
mm_struct *mm,
}
return ret;
 }
+EXPORT_SYMBOL_GPL(mem_cgroup_cache_charge);
 
 /*
  * While swap-in, try_charge - commit or cancel, the page is locked.
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index f15c1b2..ede02e2 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1907,6 +1907,7 @@ retry_cpuset:
goto retry_cpuset;
return page;
 }
+EXPORT_SYMBOL_GPL(alloc_pages_vma);
 
 /**
  * alloc_pages_current - Allocate pages.
diff --git a/mm/shmem.c b/mm/shmem.c
index 585bd22..f2b8aa7 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3041,6 +3041,7 @@ int shmem_zero_setup(struct vm_area_struct *vma)
vma-vm_flags |= VM_CAN_NONLINEAR;
return 0;
 }
+EXPORT_SYMBOL_GPL(shmem_zero_setup);
 
 /**
  * shmem_read_mapping_page_gfp - read into page cache, using specified page 
allocation flags.
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 08/41] arch_init/ram_load: refactor ram_load

2012-06-04 Thread Isaku Yamahata
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 arch_init.c |   67 +-
 arch_init.h |1 +
 2 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index c861e30..bb0cd52 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -438,6 +438,41 @@ static inline void *host_from_stream_offset(QEMUFile *f,
 return ram_load_host_from_stream_offset(f, offset, flags, block);
 }
 
+int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes)
+{
+/* Synchronize RAM block list */
+char id[256];
+ram_addr_t length;
+
+while (total_ram_bytes) {
+RAMBlock *block;
+uint8_t len;
+
+len = qemu_get_byte(f);
+qemu_get_buffer(f, (uint8_t *)id, len);
+id[len] = 0;
+length = qemu_get_be64(f);
+
+QLIST_FOREACH(block, ram_list.blocks, next) {
+if (!strncmp(id, block-idstr, sizeof(id))) {
+if (block-length != length)
+return -EINVAL;
+break;
+}
+}
+
+if (!block) {
+fprintf(stderr, Unknown ramblock \%s\, cannot 
+accept migration\n, id);
+return -EINVAL;
+}
+
+total_ram_bytes -= length;
+}
+
+return 0;
+}
+
 int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
 ram_addr_t addr;
@@ -456,35 +491,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)
 
 if (flags  RAM_SAVE_FLAG_MEM_SIZE) {
 if (version_id == 4) {
-/* Synchronize RAM block list */
-char id[256];
-ram_addr_t length;
-ram_addr_t total_ram_bytes = addr;
-
-while (total_ram_bytes) {
-RAMBlock *block;
-uint8_t len;
-
-len = qemu_get_byte(f);
-qemu_get_buffer(f, (uint8_t *)id, len);
-id[len] = 0;
-length = qemu_get_be64(f);
-
-QLIST_FOREACH(block, ram_list.blocks, next) {
-if (!strncmp(id, block-idstr, sizeof(id))) {
-if (block-length != length)
-return -EINVAL;
-break;
-}
-}
-
-if (!block) {
-fprintf(stderr, Unknown ramblock \%s\, cannot 
-accept migration\n, id);
-return -EINVAL;
-}
-
-total_ram_bytes -= length;
+error = ram_load_mem_size(f, addr);
+if (error) {
+return error;
 }
 }
 }
diff --git a/arch_init.h b/arch_init.h
index 0a39082..507f110 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -45,6 +45,7 @@ void *ram_load_host_from_stream_offset(QEMUFile *f,
ram_addr_t offset,
int flags,
RAMBlock **last_blockp);
+int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes);
 #endif
 
 #endif
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 17/41] savevm, buffered_file: introduce method to drain buffer of buffered file

2012-06-04 Thread Isaku Yamahata
Introduce a new method to drain the buffer of QEMUBufferedFile.
When postcopy migration, buffer size can increase unboundedly.
To keep the buffer size reasonably small, introduce the method to
wait for buffer to drain.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 buffered_file.c |   20 +++-
 buffered_file.h |1 +
 qemu-file.h |1 +
 savevm.c|7 +++
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index f170aa0..a38caec 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -170,6 +170,15 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in
 return offset;
 }
 
+static void buffered_drain(QEMUFileBuffered *s)
+{
+while (!qemu_file_get_error(s-file)  s-buffer_size) {
+buffered_flush(s);
+if (s-freeze_output)
+s-wait_for_unfreeze(s-opaque);
+}
+}
+
 static int buffered_close(void *opaque)
 {
 QEMUFileBuffered *s = opaque;
@@ -177,11 +186,7 @@ static int buffered_close(void *opaque)
 
 DPRINTF(closing\n);
 
-while (!qemu_file_get_error(s-file)  s-buffer_size) {
-buffered_flush(s);
-if (s-freeze_output)
-s-wait_for_unfreeze(s-opaque);
-}
+buffered_drain(s);
 
 ret = s-close(s-opaque);
 
@@ -291,3 +296,8 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
 
 return s-file;
 }
+
+void qemu_buffered_file_drain_buffer(void *buffered_file)
+{
+buffered_drain(buffered_file);
+}
diff --git a/buffered_file.h b/buffered_file.h
index 98d358b..cd8e1e8 100644
--- a/buffered_file.h
+++ b/buffered_file.h
@@ -26,5 +26,6 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque, size_t 
xfer_limit,
   BufferedPutReadyFunc *put_ready,
   BufferedWaitForUnfreezeFunc 
*wait_for_unfreeze,
   BufferedCloseFunc *close);
+void qemu_buffered_file_drain_buffer(void *buffered_file);
 
 #endif
diff --git a/qemu-file.h b/qemu-file.h
index 880ef4b..331ac8b 100644
--- a/qemu-file.h
+++ b/qemu-file.h
@@ -72,6 +72,7 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
 int qemu_stdio_fd(QEMUFile *f);
 void qemu_fflush(QEMUFile *f);
+void qemu_buffered_file_drain(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
 void qemu_put_byte(QEMUFile *f, int v);
diff --git a/savevm.c b/savevm.c
index 2992f97..fb47529 100644
--- a/savevm.c
+++ b/savevm.c
@@ -85,6 +85,7 @@
 #include cpus.h
 #include memory.h
 #include qmp-commands.h
+#include buffered_file.h
 
 #define SELF_ANNOUNCE_ROUNDS 5
 
@@ -477,6 +478,12 @@ void qemu_fflush(QEMUFile *f)
 }
 }
 
+void qemu_buffered_file_drain(QEMUFile *f)
+{
+qemu_fflush(f);
+qemu_buffered_file_drain_buffer(f-opaque);
+}
+
 static void qemu_fill_buffer(QEMUFile *f)
 {
 int len;
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 14/41] exec.c: export last_ram_offset()

2012-06-04 Thread Isaku Yamahata
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 exec-obsolete.h |1 +
 exec.c  |4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/exec-obsolete.h b/exec-obsolete.h
index 792c831..fb21dd7 100644
--- a/exec-obsolete.h
+++ b/exec-obsolete.h
@@ -25,6 +25,7 @@
 
 #ifndef CONFIG_USER_ONLY
 
+ram_addr_t qemu_last_ram_offset(void);
 ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
MemoryRegion *mr);
 ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);
diff --git a/exec.c b/exec.c
index 7f44893..785 100644
--- a/exec.c
+++ b/exec.c
@@ -2576,7 +2576,7 @@ static ram_addr_t find_ram_offset(ram_addr_t size)
 return offset;
 }
 
-static ram_addr_t last_ram_offset(void)
+ram_addr_t qemu_last_ram_offset(void)
 {
 RAMBlock *block;
 ram_addr_t last = 0;
@@ -2672,7 +2672,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
 QLIST_INSERT_HEAD(ram_list.blocks, new_block, next);
 
 ram_list.phys_dirty = g_realloc(ram_list.phys_dirty,
-   last_ram_offset()  TARGET_PAGE_BITS);
+qemu_last_ram_offset()  
TARGET_PAGE_BITS);
 memset(ram_list.phys_dirty + (new_block-offset  TARGET_PAGE_BITS),
0xff, size  TARGET_PAGE_BITS);
 
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 28/41] buffered_file: add qemu_file to read/write to buffer in memory

2012-06-04 Thread Isaku Yamahata
This is used by postcopy live migration.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 buffered_file.c |   50 ++
 buffered_file.h |   10 ++
 2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 5198923..4f0c98e 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -106,6 +106,56 @@ static void buffer_flush(QEMUBuffer *buf, QEMUFile *file,
 
 
 /***
+ * read/write to buffer on memory
+ */
+
+static int buf_close(void *opaque)
+{
+QEMUFileBuf *s = opaque;
+buffer_destroy(s-buf);
+g_free(s);
+return 0;
+}
+
+static int buf_put_buffer(void *opaque,
+  const uint8_t *buf, int64_t pos, int size)
+{
+QEMUFileBuf *s = opaque;
+buffer_append(s-buf, buf, size);
+return size;
+}
+
+QEMUFileBuf *qemu_fopen_buf_write(void)
+{
+QEMUFileBuf *s = g_malloc0(sizeof(*s));
+
+s-file = qemu_fopen_ops(s,  buf_put_buffer, NULL, buf_close,
+ NULL, NULL, NULL);
+return s;
+}
+
+static int buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
+{
+QEMUFileBuf *s = opaque;
+ssize_t len = MIN(size, s-buf.buffer_capacity - s-buf.buffer_size);
+memcpy(buf, s-buf.buffer + s-buf.buffer_size, len);
+s-buf.buffer_size += len;
+return len;
+}
+
+/* This get the ownership of buf. */
+QEMUFile *qemu_fopen_buf_read(uint8_t *buf, size_t size)
+{
+QEMUFileBuf *s = g_malloc0(sizeof(*s));
+s-buf.buffer = buf;
+s-buf.buffer_size = 0; /* this is used as index to read */
+s-buf.buffer_capacity = size;
+s-file = qemu_fopen_ops(s, NULL, buf_get_buffer, buf_close,
+ NULL, NULL, NULL);
+return s-file;
+}
+
+/***
  * Nonblocking write only file
  */
 static ssize_t nonblock_flush_buffer_putbuf(void *opaque,
diff --git a/buffered_file.h b/buffered_file.h
index 2712e01..9e28bef 100644
--- a/buffered_file.h
+++ b/buffered_file.h
@@ -24,6 +24,16 @@ struct QEMUBuffer {
 };
 typedef struct QEMUBuffer QEMUBuffer;
 
+struct QEMUFileBuf {
+QEMUFile *file;
+QEMUBuffer buf;
+};
+typedef struct QEMUFileBuf QEMUFileBuf;
+
+QEMUFileBuf *qemu_fopen_buf_write(void);
+/* This get the ownership of buf. */
+QEMUFile *qemu_fopen_buf_read(uint8_t *buf, size_t size);
+
 struct QEMUFileNonblock {
 int fd;
 QEMUFile *file;
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 39/41] postcopy/outgoing: implement prefault

2012-06-04 Thread Isaku Yamahata
When page is requested, send surrounding pages are also sent.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 migration-postcopy.c |   56 +
 1 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/migration-postcopy.c b/migration-postcopy.c
index eb37094..6165657 100644
--- a/migration-postcopy.c
+++ b/migration-postcopy.c
@@ -353,6 +353,36 @@ int postcopy_outgoing_ram_save_live(QEMUFile *f, int 
stage, void *opaque)
 return ret;
 }
 
+static void postcopy_outgoing_ram_save_page(PostcopyOutgoingState *s,
+uint64_t pgoffset, bool *written,
+bool forward,
+int prefault_pgoffset)
+{
+ram_addr_t offset;
+int ret;
+
+if (forward) {
+pgoffset += prefault_pgoffset;
+} else {
+if (pgoffset  prefault_pgoffset) {
+return;
+}
+pgoffset -= prefault_pgoffset;
+}
+
+offset = pgoffset  TARGET_PAGE_BITS;
+if (offset = s-last_block_read-length) {
+assert(forward);
+assert(prefault_pgoffset  0);
+return;
+}
+
+ret = ram_save_page(s-mig_buffered_write, s-last_block_read, offset);
+if (ret  0) {
+*written = true;
+}
+}
+
 /*
  * return value
  *   0: continue postcopy mode
@@ -364,6 +394,7 @@ static int 
postcopy_outgoing_handle_req(PostcopyOutgoingState *s,
 bool *written)
 {
 int i;
+uint64_t j;
 RAMBlock *block;
 
 DPRINTF(cmd %d state %d\n, req-cmd, s-state);
@@ -398,11 +429,26 @@ static int 
postcopy_outgoing_handle_req(PostcopyOutgoingState *s,
 break;
 }
 for (i = 0; i  req-nr; i++) {
-DPRINTF(offs[%d] 0x%PRIx64\n, i, req-pgoffs[i]);
-int ret = ram_save_page(s-mig_buffered_write, s-last_block_read,
-req-pgoffs[i]  TARGET_PAGE_BITS);
-if (ret  0) {
-*written = true;
+DPRINTF(pgoffs[%d] 0x%PRIx64\n, i, req-pgoffs[i]);
+postcopy_outgoing_ram_save_page(s, req-pgoffs[i], written,
+true, 0);
+}
+/* forward prefault */
+for (j = 1; j = s-ms-params.prefault_forward; j++) {
+for (i = 0; i  req-nr; i++) {
+DPRINTF(pgoffs[%d] + 0x%PRIx64 0x%PRIx64\n,
+i, j, req-pgoffs[i] + j);
+postcopy_outgoing_ram_save_page(s, req-pgoffs[i], written,
+true, j);
+}
+}
+/* backward prefault */
+for (j = 1; j = s-ms-params.prefault_backward; j++) {
+for (i = 0; i  req-nr; i++) {
+DPRINTF(pgoffs[%d] - 0x%PRIx64 0x%PRIx64\n,
+i, j, req-pgoffs[i] - j);
+postcopy_outgoing_ram_save_page(s, req-pgoffs[i], written,
+false, j);
 }
 }
 break;
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 31/41] configure: add CONFIG_POSTCOPY option

2012-06-04 Thread Isaku Yamahata
Add enable/disable postcopy mode. No dynamic test yet.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 configure |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 1f338f8..21de4cb 100755
--- a/configure
+++ b/configure
@@ -194,6 +194,7 @@ zlib=yes
 guest_agent=yes
 libiscsi=
 coroutine=
+postcopy=yes
 
 # parse CC options first
 for opt do
@@ -824,6 +825,10 @@ for opt do
   ;;
   --disable-guest-agent) guest_agent=no
   ;;
+  --enable-postcopy) postcopy=yes
+  ;;
+  --disable-postcopy) postcopy=no
+  ;;
   *) echo ERROR: unknown option $opt; show_help=yes
   ;;
   esac
@@ -1110,6 +1115,8 @@ echo   --disable-guest-agentdisable building of the 
QEMU Guest Agent
 echo   --enable-guest-agent enable building of the QEMU Guest Agent
 echo   --with-coroutine=BACKEND coroutine backend. Supported options:
 echogthread, ucontext, sigaltstack, windows
+echo   --disable-postcopy   disable postcopy mode for live migration
+echo   --enable-postcopyenable postcopy mode for live migration
 echo 
 echo NOTE: The object files are built at the place where configure is 
launched
 exit 1
@@ -3029,6 +3036,7 @@ echo OpenGL support$opengl
 echo libiscsi support  $libiscsi
 echo build guest agent $guest_agent
 echo coroutine backend $coroutine_backend
+echo postcopy support  $postcopy
 
 if test $sdl_too_old = yes; then
 echo - Your SDL version is too old - please upgrade to have SDL support
@@ -3329,6 +3337,10 @@ if test $libiscsi = yes ; then
   echo CONFIG_LIBISCSI=y  $config_host_mak
 fi
 
+if test $postcopy = yes ; then
+  echo CONFIG_POSTCOPY=y  $config_host_mak
+fi
+
 # XXX: suppress that
 if [ $bsd = yes ] ; then
   echo CONFIG_BSD=y  $config_host_mak
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 02/41] arch_init: export RAM_SAVE_xxx flags for postcopy

2012-06-04 Thread Isaku Yamahata
Those constants will be also used by postcopy.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 arch_init.c |7 ---
 arch_init.h |7 +++
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 38e0173..bd4e61e 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -88,13 +88,6 @@ const uint32_t arch_type = QEMU_ARCH;
 /***/
 /* ram save/restore */
 
-#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
-#define RAM_SAVE_FLAG_COMPRESS 0x02
-#define RAM_SAVE_FLAG_MEM_SIZE 0x04
-#define RAM_SAVE_FLAG_PAGE 0x08
-#define RAM_SAVE_FLAG_EOS  0x10
-#define RAM_SAVE_FLAG_CONTINUE 0x20
-
 #ifdef __ALTIVEC__
 #include altivec.h
 #define VECTYPEvector unsigned char
diff --git a/arch_init.h b/arch_init.h
index c7cb94a..7cc3fa7 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -30,4 +30,11 @@ int tcg_available(void);
 int kvm_available(void);
 int xen_available(void);
 
+#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
+#define RAM_SAVE_FLAG_COMPRESS 0x02
+#define RAM_SAVE_FLAG_MEM_SIZE 0x04
+#define RAM_SAVE_FLAG_PAGE 0x08
+#define RAM_SAVE_FLAG_EOS  0x10
+#define RAM_SAVE_FLAG_CONTINUE 0x20
+
 #endif
-- 
1.7.1.1




Re: [Qemu-devel] [PATCH v2 1/1] virtio-rng: hardware random number generator device

2012-06-04 Thread Anthony Liguori

On 05/26/2012 04:20 AM, Amit Shah wrote:

On (Fri) 25 May 2012 [15:00:53], Anthony Liguori wrote:

On 05/25/2012 02:32 PM, Amit Shah wrote:

The Linux kernel already has a virtio-rng driver, this is the device
implementation.

When the guest asks for entropy from the virtio hwrng, it puts a buffer
in the vq.  We then put entropy into that buffer, and push it back to
the guest.

The chardev connected to this device is fed the data to be sent to the
guest.

Invocation is simple:

   $ qemu ... -device virtio-rng-pci,chardev=foo

In the guest, we see

   $ cat /sys/devices/virtual/misc/hw_random/rng_available
   virtio

   $ cat /sys/devices/virtual/misc/hw_random/rng_current
   virtio

   # cat /dev/hwrng

Simply feeding /dev/urandom from the host to the chardev is sufficient:

   $ qemu ... -chardev socket,path=/tmp/foo,server,nowait,id=foo \
  -device virtio-rng,chardev=foo

   $ nc -U /tmp/foo   /dev/urandom

A QMP event is sent for interested apps to monitor activity and send the
appropriate number of bytes that get asked by the guest:

   {timestamp: {seconds: 1337966878, microseconds: 517009}, \
event: ENTROPY_NEEDED, data: {bytes: 64}}


I don't understand the point of this event.  Can't a management app
just create a socket and then it can see all the requests the guest
makes?


How?  With the chardev, it can only keep feeding data, and that data
will be consumed when chr_can_read() returns  0.  And even then the
mgmt app has no idea how much data was asked for, and how much was
consumed.


Okay, then the right approach is to use a message protocol where QEMU asks for a 
certain amount of data and then the daemon sends it back.


I think this is pretty much why the egd protocol exists, no?  Why not just 
implement egd protocol support?


Once we introduce a protocol of any form (even raw), we have to support it 
forever so let's not do it carelessly.


Regards,

Anthony Liguori



Amit







[Qemu-devel] [PATCH v3 0/2] postcopy migration: umem: Linux char device for postcopy

2012-06-04 Thread Isaku Yamahata
This is Linux kernel driver for qemu/kvm postcopy live migration.
This is used by qemu/kvm postcopy live migration patch.

TODO:
- Consider FUSE/CUSE option
  So far several mmap patches for FUSE/CUSE are floating around. (their
  purpose isn't different from our purpose, though). They haven't merged
  into the upstream yet.
  The driver specific part in qemu patches is modularized. So I expect it
  wouldn't be difficult to switch kernel driver to CUSE based driver.

ioctl commands:
UMEM_INIT: initialize umem device for qemu
UMEM_MAKE_VMA_ANONYMOUS: make the specified vma in the qemu process
 This is _NOT_ implemented yet.
 anonymous I'm not sure whether this can be implemented
 or not.
---
Changes v2 - v3:
- make fault handler killable
- make use of read()/write()
- documentation

Changes version 1 - 2:
- make ioctl structures padded to align
- un-KVM
  KVM_VMEM - UMEM
- dropped some ioctl commands as Avi requested

Isaku Yamahata (2):
  export necessary symbols
  umem: chardevice for kvm postcopy

 Documentation/misc-devices/umem.txt |  303 
 drivers/char/Kconfig|   10 +
 drivers/char/Makefile   |1 +
 drivers/char/umem.c |  900 +++
 include/linux/umem.h|   42 ++
 mm/memcontrol.c |1 +
 mm/mempolicy.c  |1 +
 mm/shmem.c  |1 +
 8 files changed, 1259 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/misc-devices/umem.txt
 create mode 100644 drivers/char/umem.c
 create mode 100644 include/linux/umem.h




[Qemu-devel] [PATCH v2 20/41] savevm/QEMUFileSocket: drop duplicated member fd

2012-06-04 Thread Isaku Yamahata
fd is already stored in QEMUFile so drop duplicated member
QEMUFileSocket::fd.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 savevm.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/savevm.c b/savevm.c
index ec9f5d0..4b560b3 100644
--- a/savevm.c
+++ b/savevm.c
@@ -189,7 +189,6 @@ typedef struct QEMUFileStdio
 
 typedef struct QEMUFileSocket
 {
-int fd;
 QEMUFile *file;
 } QEMUFileSocket;
 
@@ -199,7 +198,7 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, 
int64_t pos, int size)
 ssize_t len;
 
 do {
-len = qemu_recv(s-fd, buf, size, 0);
+len = qemu_recv(s-file-fd, buf, size, 0);
 } while (len == -1  socket_error() == EINTR);
 
 if (len == -1)
@@ -328,7 +327,6 @@ QEMUFile *qemu_fopen_socket(int fd)
 {
 QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
 
-s-fd = fd;
 s-file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, 
 NULL, NULL, NULL);
 s-file-fd = fd;
-- 
1.7.1.1




[Qemu-devel] [PATCH v2 25/41] migration: factor out parameters into MigrationParams

2012-06-04 Thread Isaku Yamahata
Introduce MigrationParams for parameters of migration.

Cc: Orit Wasserman owass...@redhat.com
Cc: Juan Quintela quint...@redhat.com
Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
Changes v1 - v2:
- catch up qapi change
---
 block-migration.c |8 
 migration.c   |   21 +++--
 migration.h   |8 ++--
 qemu-common.h |1 +
 savevm.c  |   10 +++---
 sysemu.h  |2 +-
 vmstate.h |2 +-
 7 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/block-migration.c b/block-migration.c
index fd2..b95b4e1 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -700,13 +700,13 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 return 0;
 }
 
-static void block_set_params(int blk_enable, int shared_base, void *opaque)
+static void block_set_params(const MigrationParams *params, void *opaque)
 {
-block_mig_state.blk_enable = blk_enable;
-block_mig_state.shared_base = shared_base;
+block_mig_state.blk_enable = params-blk;
+block_mig_state.shared_base = params-shared;
 
 /* shared base means that blk_enable = 1 */
-block_mig_state.blk_enable |= shared_base;
+block_mig_state.blk_enable |= params-shared;
 }
 
 void blk_mig_init(void)
diff --git a/migration.c b/migration.c
index 48a8f68..3b97aec 100644
--- a/migration.c
+++ b/migration.c
@@ -352,7 +352,7 @@ void migrate_fd_connect(MigrationState *s)
   migrate_fd_close);
 
 DPRINTF(beginning savevm\n);
-ret = qemu_savevm_state_begin(s-file, s-blk, s-shared);
+ret = qemu_savevm_state_begin(s-file, s-params);
 if (ret  0) {
 DPRINTF(failed, %d\n, ret);
 migrate_fd_error(s);
@@ -361,15 +361,13 @@ void migrate_fd_connect(MigrationState *s)
 migrate_fd_put_ready(s);
 }
 
-static MigrationState *migrate_init(int blk, int inc)
+static MigrationState *migrate_init(const MigrationParams *params)
 {
 MigrationState *s = migrate_get_current();
 int64_t bandwidth_limit = s-bandwidth_limit;
 
 memset(s, 0, sizeof(*s));
-s-blk = blk;
-s-shared = inc;
-
+s-params = *params;
 s-bandwidth_limit = bandwidth_limit;
 s-state = MIG_STATE_SETUP;
 
@@ -393,9 +391,20 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
  Error **errp)
 {
 MigrationState *s = migrate_get_current();
+MigrationParams params = {
+.blk = false,
+.shared = false,
+};
 const char *p;
 int ret;
 
+if (has_blk) {
+params.blk = blk;
+}
+if (has_inc) {
+params.shared = inc;
+}
+
 if (s-state == MIG_STATE_ACTIVE) {
 error_set(errp, QERR_MIGRATION_ACTIVE);
 return;
@@ -410,7 +419,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 return;
 }
 
-s = migrate_init(blk, inc);
+s = migrate_init(params);
 
 if (strstart(uri, tcp:, p)) {
 ret = tcp_start_outgoing_migration(s, p, errp);
diff --git a/migration.h b/migration.h
index d0dd536..59e6e68 100644
--- a/migration.h
+++ b/migration.h
@@ -19,6 +19,11 @@
 #include notify.h
 #include error.h
 
+struct MigrationParams {
+int blk;
+int shared;
+};
+
 typedef struct MigrationState MigrationState;
 
 struct MigrationState
@@ -31,8 +36,7 @@ struct MigrationState
 int (*close)(MigrationState *s);
 int (*write)(MigrationState *s, const void *buff, size_t size);
 void *opaque;
-int blk;
-int shared;
+MigrationParams params;
 };
 
 void process_incoming_migration(QEMUFile *f);
diff --git a/qemu-common.h b/qemu-common.h
index 91e0562..057c810 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -263,6 +263,7 @@ typedef struct EventNotifier EventNotifier;
 typedef struct VirtIODevice VirtIODevice;
 typedef struct QEMUSGList QEMUSGList;
 typedef struct SHPCDevice SHPCDevice;
+typedef struct MigrationParams MigrationParams;
 
 typedef uint64_t pcibus_t;
 
diff --git a/savevm.c b/savevm.c
index 5640614..318ec61 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1611,7 +1611,7 @@ bool qemu_savevm_state_blocked(Error **errp)
 return false;
 }
 
-int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared)
+int qemu_savevm_state_begin(QEMUFile *f, const MigrationParams *params)
 {
 SaveStateEntry *se;
 int ret;
@@ -1620,7 +1620,7 @@ int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, 
int shared)
 if(se-set_params == NULL) {
 continue;
}
-   se-set_params(blk_enable, shared, se-opaque);
+   se-set_params(params, se-opaque);
 }
 
 qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
@@ -1758,13 +1758,17 @@ void qemu_savevm_state_cancel(QEMUFile *f)
 static int qemu_savevm_state(QEMUFile *f)
 {
 int ret;
+MigrationParams params = {
+.blk = 0,
+.shared = 0,
+};
 
 if (qemu_savevm_state_blocked(NULL)) {
 ret = -EINVAL;
 goto out;
 }
 
-ret = 

[Qemu-devel] [PATCH 08/13] pci: Export pci_parse_devaddr instead of pci_read_devaddr

2012-06-04 Thread Jan Kiszka
The latter is an internal helper for PCI hotplug. So move it where it
belongs - before someone misuses it - and export the more versatile
pci_parse_devaddr instead.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/pci-hotplug.c |   18 --
 hw/pci.c |   19 ++-
 hw/pci.h |4 ++--
 3 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index e0ea8bb..e1654dc 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -34,6 +34,20 @@
 #include blockdev.h
 #include error.h
 
+static int read_pci_devaddr(Monitor *mon, const char *addr, unsigned int *domp,
+unsigned int *busp, unsigned *slotp)
+{
+/* strip legacy tag */
+if (!strncmp(addr, pci_addr=, 9)) {
+addr += 9;
+}
+if (pci_parse_devaddr(addr, domp, busp, slotp, NULL)) {
+monitor_printf(mon, Invalid pci address\n);
+return -1;
+}
+return 0;
+}
+
 #if defined(TARGET_I386)
 static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
const char *devaddr,
@@ -115,7 +129,7 @@ int pci_drive_hot_add(Monitor *mon, const QDict *qdict,
 
 switch (type) {
 case IF_SCSI:
-if (pci_read_devaddr(mon, pci_addr, dom, pci_bus, slot)) {
+if (read_pci_devaddr(mon, pci_addr, dom, pci_bus, slot)) {
 goto err;
 }
 dev = pci_find_device(pci_find_root_bus(dom), pci_bus,
@@ -261,7 +275,7 @@ static int pci_device_hot_remove(Monitor *mon, const char 
*pci_addr)
 unsigned slot;
 Error *local_err = NULL;
 
-if (pci_read_devaddr(mon, pci_addr, dom, bus, slot)) {
+if (read_pci_devaddr(mon, pci_addr, dom, bus, slot)) {
 return -1;
 }
 
diff --git a/hw/pci.c b/hw/pci.c
index d4c8b71..6471a68 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -512,9 +512,8 @@ static void pci_set_default_subsystem_id(PCIDevice *pci_dev)
  * Parse [[domain:]bus:]slot, return -1 on error if funcp == NULL
  *   [[domain:]bus:]slot.func, return -1 on error
  */
-static int pci_parse_devaddr(const char *addr, unsigned int *domp,
- unsigned int *busp, unsigned int *slotp,
- unsigned int *funcp)
+int pci_parse_devaddr(const char *addr, unsigned int *domp, unsigned int *busp,
+  unsigned int *slotp, unsigned int *funcp)
 {
 const char *p;
 char *e;
@@ -572,20 +571,6 @@ static int pci_parse_devaddr(const char *addr, unsigned 
int *domp,
 return 0;
 }
 
-int pci_read_devaddr(Monitor *mon, const char *addr, unsigned int *domp,
- unsigned int *busp, unsigned *slotp)
-{
-/* strip legacy tag */
-if (!strncmp(addr, pci_addr=, 9)) {
-addr += 9;
-}
-if (pci_parse_devaddr(addr, domp, busp, slotp, NULL)) {
-monitor_printf(mon, Invalid pci address\n);
-return -1;
-}
-return 0;
-}
-
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 {
 unsigned int dom, bus;
diff --git a/hw/pci.h b/hw/pci.h
index 0c38c36..552a586 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -340,8 +340,8 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, 
uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
 
-int pci_read_devaddr(Monitor *mon, const char *addr, unsigned int *domp,
- unsigned int *busp, unsigned *slotp);
+int pci_parse_devaddr(const char *addr, unsigned int *domp, unsigned int *busp,
+  unsigned int *slotp, unsigned int *funcp);
 
 void pci_device_deassert_intx(PCIDevice *dev);
 
-- 
1.7.3.4




[Qemu-devel] [PATCH v2 21/41] savevm: rename QEMUFileSocket to QEMUFileFD, socket_close to fd_close

2012-06-04 Thread Isaku Yamahata
Later the structure will be shared.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 savevm.c |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/savevm.c b/savevm.c
index 4b560b3..2fb0c3e 100644
--- a/savevm.c
+++ b/savevm.c
@@ -187,14 +187,14 @@ typedef struct QEMUFileStdio
 QEMUFile *file;
 } QEMUFileStdio;
 
-typedef struct QEMUFileSocket
+typedef struct QEMUFileFD
 {
 QEMUFile *file;
-} QEMUFileSocket;
+} QEMUFileFD;
 
 static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
 {
-QEMUFileSocket *s = opaque;
+QEMUFileFD *s = opaque;
 ssize_t len;
 
 do {
@@ -207,9 +207,9 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, 
int64_t pos, int size)
 return len;
 }
 
-static int socket_close(void *opaque)
+static int fd_close(void *opaque)
 {
-QEMUFileSocket *s = opaque;
+QEMUFileFD *s = opaque;
 g_free(s);
 return 0;
 }
@@ -325,9 +325,9 @@ fail:
 
 QEMUFile *qemu_fopen_socket(int fd)
 {
-QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
+QEMUFileFD *s = g_malloc0(sizeof(QEMUFileFD));
 
-s-file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, 
+s-file = qemu_fopen_ops(s, NULL, socket_get_buffer, fd_close,
 NULL, NULL, NULL);
 s-file-fd = fd;
 return s-file;
-- 
1.7.1.1




[Qemu-devel] [PULL 00/12] Block patches

2012-06-04 Thread Kevin Wolf
The following changes since commit 8cc9b43f7c5f826b39af4b012ad89bb55faac29c:

  target-microblaze: lwx/swx: first implementation (2012-06-04 10:19:46 +0200)

are available in the git repository at:
  git://repo.or.cz/qemu/kevin.git for-anthony

Josh Durgin (1):
  rbd: hook up cache options

Kevin Wolf (3):
  qemu-img check -r for repairing images
  qemu-img check: Print fixed clusters and recheck
  qcow2: Support for fixing refcount inconsistencies

MORITA Kazutaka (1):
  sheepdog: add coroutine_fn markers to coroutine functions

Markus Armbruster (1):
  Un-inline fdctrl_init_isa()

Paolo Bonzini (4):
  block: implement is_allocated for raw
  stream: tweak usage of bdrv_co_is_allocated
  stream: move is_allocated_above to block.c
  stream: move rate limiting to a separate header file

Zhi Yong Wu (2):
  qcow2: remove a line of unnecessary code
  qcow2: fix the byte endian convertion

 block.c  |   53 +-
 block.h  |   13 +-
 block/qcow2-cluster.c|1 -
 block/qcow2-refcount.c   |   33 --
 block/qcow2.c|5 +-
 block/qcow2.h|3 +-
 block/qed-check.c|2 +
 block/qed.c  |5 +-
 block/raw-posix.c|   98 +
 block/raw.c  |8 +++
 block/rbd.c  |   19 
 block/sheepdog.c |9 ++--
 block/stream.c   |  109 +++---
 block/vdi.c  |7 +++-
 block_int.h  |3 +-
 hw/fdc.c |   20 
 hw/fdc.h |   24 +-
 hw/ide/piix.c|3 +-
 hw/isa.h |2 -
 hw/pc_sysfw.c|1 +
 include/qemu/ratelimit.h |   48 
 qemu-common.h|1 +
 qemu-img-cmds.hx |4 +-
 qemu-img.c   |   35 +-
 qemu-img.texi|7 +++-
 25 files changed, 369 insertions(+), 144 deletions(-)
 create mode 100644 include/qemu/ratelimit.h



  1   2   3   4   >