Re: [Qemu-devel] q35 chipset support

2012-06-15 Thread Markus Armbruster
Anthony Liguori  writes:

> On 06/14/2012 02:54 PM, Jason Baron wrote:
>> Hi,
>>
>> I recently updated Isaku Yamahata's q35 patches to work on the latest qemu 
>> and
>> seabios trees. On the qemu side, most of the changes revolved around updating
>> to use QOM and updates to the memory API. I was also able to drop quite a few
>> patches that had already been resolved by the current qemu tree.
>>
>> The trees seem pretty stable and can be found here:
>>
>> git://github.com/jibaron/q35-qemu.git
>> git://github.com/jibaron/q35-seabios.git
>
> I'm got the beginnings of a feature page started:
>
> http://wiki.qemu.org/Features/Q35
>
> The approach above will not work in a QOM world unfortunately.  We
> need to do quite a bit of ground work before adding another chipset.
> The biggest task is converting devices to not require an ISA bus since
> ICH9 simply doesn't have an ISA bus.

Could you explain briefly why use of a software ISA bus construct
matters for device models and/or guests?

[...]



Re: [Qemu-devel] [PATCH v3 0/2] Balloon event change notifications

2012-06-15 Thread Amit Shah
On (Thu) 14 Jun 2012 [18:12:55], Daniel P. Berrange wrote:
> This is a followup to:
> 
>   https://lists.gnu.org/archive/html/qemu-devel/2012-05/msg02833.html
> 
> 
> Changes since v2:
> 
>   - Drop 'query-events' patch which is already merged
>   - Rename balloon_change() function to balloon_changed per
> Amit's request
>   - Misc typos fixed
>   - Remove monitor_global_init(), folding code into the
> one-time initialization block in monitor_init()
> 
> This series is being tested with a corresponding patch to libvirt
> for handling balloon events
> 
> https://www.redhat.com/archives/libvir-list/2012-May/msg00868.html

Acked-by: Amit Shah 

Amit



Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

2012-06-15 Thread Amos Kong

On 14/06/12 18:20, Amos Kong wrote:

On 12/06/12 01:25, Luiz Capitulino wrote:




Hi Luiz, Anthony


BTW, why is there a 16 keycode limit?


'Sendkey' command was added by this commit
a3a91a355bc6107b7d06d722fb97d2b80065ee0b
Limitation of keycodes number (16) was also introduced here,
and I didn't find the root reason.




That's a good point. This comes form the array used by the original
implementation to store the keycodes.

Amos, is it still needed now that we're using qapi lists?



I try to drop this limitation from monitor.c [1], then execute

(qemu) sendkey 1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0

kbd_put_keycode() are called for all (20) keycodes,
but only '123456789012345' can be sent to guest.


It seems we need to notice user when inputted keys are more than 16.



Hi Gerd,

When I use 'sendkey' command to send key-series to guest, some keyboard
events will be send. There is a limitation (16) that was introduced by this
old commit c8256f9d (without description). Do you know the reason?


I found in bonzini's commit 13f8b97a :
+#define QUEUE_LENGTH16 /* should be enough for a triple-click */
bonzini told me that the reason to do it for the keyboard, was
to do ctrl-alt-delete, nothing more

I drop this limitation (16) in monitor.c for sendkey command,
when I execute (qemu) sendkey 1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0 ,
hw/ps2.c:ps2_put_keycode() is called for all keys,
but only '123456789012345' is inputted to guest.

There is a 'PS2_QUEUE_SIZE' (256) in hw/ps2.c, this event queue is
shared by mouse and keyboard, but I only inputted 20 keys.

I didn't find where the other keys are ignored, and there is
no warning in stderr.

Hi Anthony, Luiz,

However, the limitation (16) for sendkey is necessary, 16 is enough for 
all combination keys




[1]
https://github.com/kongove/QEMU/commit/a198cdcce3ce4c1632221ac7f1e7c4e8efcd9c82


--
Amos.



Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

2012-06-15 Thread Gerd Hoffmann
  Hi,

>> It seems we need to notice user when inputted keys are more than 16.
> 
> Hi Gerd,
> 
> When I use 'sendkey' command to send key-series to guest, some keyboard
> events will be send. There is a limitation (16) that was introduced by this
> old commit c8256f9d (without description). Do you know the reason?

Probably hardware limitation, ps/2 keyboards can buffer up to 16 keys IIRC.

Likewise the usb hid devices can buffer up to 16 events.  In that case
it is just a qemu implementation detail and not a property of the
hardware we are emulating, so it can be changed.  Not trivially though
as the buffer is part of the migration data, so it is more work that
just changing a #define.

HTH,
  Gerd




Re: [Qemu-devel] qemu-system-ppc64 hanging occasionally in disk writes

2012-06-15 Thread Paolo Bonzini
Il 15/06/2012 00:01, Richard W.M. Jones ha scritto:
>>> > > /home/rjones/d/qemu/ppc64-softmmu/qemu-system-ppc64 \
>>> > >-global virtio-blk-pci.scsi=off \
>>> > >-nodefconfig \
>>> > >-nodefaults \
>>> > >-nographic \
>>> > >-device virtio-scsi-pci,id=scsi \
>>> > >-drive file=test1.img,cache=off,format=raw,id=hd0,if=none \
>>> > >-device scsi-hd,drive=hd0 \
>> > 
>> > Don't you have to specify bus= too?

No, it will just look for a scsi bus.  With -nodefaults there should be
no default vscsi controller, so it should work.

Try info qdev to get a definitive answer though.

Paolo




Re: [Qemu-devel] How to measure guest memory access (qemu_ld/qemu_st) time?

2012-06-15 Thread Laurent Desnogues
On Fri, Jun 15, 2012 at 12:30 AM, Lluís Vilanova  wrote:
[...]
> Now that I think of it, you will have problems generating code to surround 
> each
> qemu_ld/st with a lightweight mechanism to get the time. In x86 it would be
> rdtsc, but you want to generate a host rdtsc instruction inside the code
> generated by QEMU's TCG, so you should also have to hack TCG (or the code
> generation pointers) to issue an rdtsc instruction.

Even rdtsc would introduce enough noise that it wouldn't be reliable
for such a micro measurement:  as far as I understand it, this instruction
can be reordered, so you need to flush the pipeline before issuing it.

Intel has a document about that:
download.intel.com/embedded/software/IA/324264.pdf
The overhead of their proposed method is so high that it's likely it
would take longer than the execution of the fast path itself.

IMHO a mix of YeongKyoon Lee way to count ld/st and comparison
between user mode and softmmu still seems to be the best approach
(well unless you have access to a cycle accurate simulator :-).


Laurent



Re: [Qemu-devel] [PATCH] trace: added ability to comment out events in the list

2012-06-15 Thread Stefan Hajnoczi
On Fri, Jun 15, 2012 at 5:36 AM, Alexey Kardashevskiy  wrote:
> On 14/06/12 23:18, Stefan Hajnoczi wrote:
>> On Thu, Jun 14, 2012 at 02:41:40PM +1000, Alexey Kardashevskiy wrote:
>>> It is convenient for debug to be able to switch on/off some events easily.
>>> The only possibility now is to remove event name from the file completely
>>> and type it again when we want it back.
>>>
>>> The patch adds '#' symbol handling as a comment specifier.
>>>
>>> Signed-off-by: Alexey Kardashevskiy 
>>> ---
>>>  trace/control.c |    3 +++
>>>  1 files changed, 3 insertions(+), 0 deletions(-)
>>
>> Thanks, applied to the tracing patches tree:
>> https://github.com/stefanha/qemu/commits/tracing
>
> Cannot find it there though :)

I just pushed the 'tracing' branch, sorry for the delay!

Stefan



[Qemu-devel] question about irq update

2012-06-15 Thread Zhi Hui Li



In the code of libqtest.c have a function :



bool qtest_get_irq(QTestState *s, int num)
{
/* dummy operation in order to make sure irq is up to date */
qtest_inb(s, 0);

return s->irq_level[num];
}

but I don't know how it can make the irq up to date
and why we will read from the address of 0 ?


can anybody explain for me?
Thank you very much!




Re: [Qemu-devel] question about irq update

2012-06-15 Thread Paolo Bonzini
Il 15/06/2012 10:42, Zhi Hui Li ha scritto:
> 
> bool qtest_get_irq(QTestState *s, int num)
> {
> /* dummy operation in order to make sure irq is up to date */
> qtest_inb(s, 0);
> 
> return s->irq_level[num];
> }
> 
> but I don't know how it can make the irq up to date
> and why we will read from the address of 0 ?

It just forces libqtest to read any pending events.

Paolo



Re: [Qemu-devel] question about irq update

2012-06-15 Thread Zhi Hui Li

On 2012年06月15日 17:04, Paolo Bonzini wrote:

It just forces libqtest to read any pending events.


Ok, Thank you very much!  :)




Re: [Qemu-devel] [PATCH 0/2] introduce bdrv_swap, implement bdrv_append on top

2012-06-15 Thread Kevin Wolf
Am 14.06.2012 16:55, schrieb Paolo Bonzini:
> Yet another tiny bit extracted from block mirroring, looks like it
> should be useful for block commit too.
> 
> Paolo Bonzini (2):
>   block: copy over job and dirty bitmap fields in bdrv_append
>   block: introduce bdrv_swap, implement bdrv_append on top of it
> 
>  block.c |  175 
> +--
>  block.h |1 +
>  2 files changed, 103 insertions(+), 73 deletions(-)
> 

I was really hoping we could get rid of bdrv_append() rather than extend
it and spread its use...

What exactly do we need this for? I'm sure you have good reasons, but
with such hackish approaches the justification should be explicit.

Kevin



Re: [Qemu-devel] [PATCH 0/2] introduce bdrv_swap, implement bdrv_append on top

2012-06-15 Thread Paolo Bonzini
Il 15/06/2012 11:38, Kevin Wolf ha scritto:
>> > Yet another tiny bit extracted from block mirroring, looks like it
>> > should be useful for block commit too.
>> > 
>> > Paolo Bonzini (2):
>> >   block: copy over job and dirty bitmap fields in bdrv_append
>> >   block: introduce bdrv_swap, implement bdrv_append on top of it
>> > 
>> >  block.c |  175 
>> > +--
>> >  block.h |1 +
>> >  2 files changed, 103 insertions(+), 73 deletions(-)
>> > 
> I was really hoping we could get rid of bdrv_append() rather than extend
> it and spread its use...
> 
> What exactly do we need this for? I'm sure you have good reasons, but
> with such hackish approaches the justification should be explicit.

It's part of the replacement for drive_reopen.  It is used by a new
command called block-job-complete when switching the device from the
mirroring source to the target.  Unlike drive_reopen, it is safe (it
just reuses the target BDS without closing it) and asynchronous, so
overall an improvement.

Paolo



[Qemu-devel] [PATCHv2 03/13] unicore32-softmmu: Make UniCore32 cpuid & exceptions correct and runable

2012-06-15 Thread Guan Xuetao
This patch initializes the cpuid to exactly correct value because
linux kernel will check it. Also UC32_CPUID_* are removed.
In addition, the exception types are specified in proper situations.
Then it could make exceptions generated correctly and timely.

Signed-off-by: Guan Xuetao 
---
 cpu-exec.c |1 +
 linux-user/main.c  |3 ++-
 target-unicore32/cpu.c |   25 -
 target-unicore32/cpu.h |   12 +---
 4 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 0344cd5..929b535 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -416,6 +416,7 @@ int cpu_exec(CPUArchState *env)
 #elif defined(TARGET_UNICORE32)
 if (interrupt_request & CPU_INTERRUPT_HARD
 && !(env->uncached_asr & ASR_I)) {
+env->exception_index = UC32_EXCP_INTR;
 do_interrupt(env);
 next_tb = 0;
 }
diff --git a/linux-user/main.c b/linux-user/main.c
index 191b750..a394409 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -958,7 +958,8 @@ void cpu_loop(CPUUniCore32State *env)
 }
 }
 break;
-case UC32_EXCP_TRAP:
+case UC32_EXCP_DTRAP:
+case UC32_EXCP_ITRAP:
 info.si_signo = SIGSEGV;
 info.si_errno = 0;
 /* XXX: check env->error_code */
diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c
index de63f58..f296420 100644
--- a/target-unicore32/cpu.c
+++ b/target-unicore32/cpu.c
@@ -1,15 +1,13 @@
 /*
  * QEMU UniCore32 CPU
  *
- * Copyright (c) 2010-2011 GUAN Xue-tao
+ * Copyright (c) 2010-2012 Guan Xuetao
  * Copyright (c) 2012 SUSE LINUX Products GmbH
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Contributions from 2012-04-01 on are considered under GPL version 2,
- * or (at your option) any later version.
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
  */
 
 #include "cpu-qom.h"
@@ -32,13 +30,16 @@ static void unicore_ii_cpu_initfn(Object *obj)
 UniCore32CPU *cpu = UNICORE32_CPU(obj);
 CPUUniCore32State *env = &cpu->env;
 
-env->cp0.c0_cpuid = 0x40010863;
+env->cp0.c0_cpuid = 0x4d000863;
+env->cp0.c0_cachetype = 0x0d152152;
+env->cp0.c1_sys = 0x2000;
+env->cp0.c2_base = 0x0;
+env->cp0.c3_faultstatus = 0x0;
+env->cp0.c4_faultaddr = 0x0;
+env->ucf64.xregs[UC32_UCF64_FPSCR] = 0;
 
 set_feature(env, UC32_HWCAP_CMOV);
 set_feature(env, UC32_HWCAP_UCF64);
-env->ucf64.xregs[UC32_UCF64_FPSCR] = 0;
-env->cp0.c0_cachetype = 0x1dd20d2;
-env->cp0.c1_sys = 0x00090078;
 }
 
 static void uc32_any_cpu_initfn(Object *obj)
@@ -47,6 +48,7 @@ static void uc32_any_cpu_initfn(Object *obj)
 CPUUniCore32State *env = &cpu->env;
 
 env->cp0.c0_cpuid = 0x;
+env->ucf64.xregs[UC32_UCF64_FPSCR] = 0;
 
 set_feature(env, UC32_HWCAP_CMOV);
 set_feature(env, UC32_HWCAP_UCF64);
@@ -65,8 +67,13 @@ static void uc32_cpu_initfn(Object *obj)
 cpu_exec_init(env);
 env->cpu_model_str = object_get_typename(obj);
 
+#ifdef CONFIG_USER_ONLY
 env->uncached_asr = ASR_MODE_USER;
 env->regs[31] = 0;
+#else
+env->uncached_asr = ASR_MODE_PRIV;
+env->regs[31] = 0x0300;
+#endif
 
 tlb_flush(env, 1);
 }
diff --git a/target-unicore32/cpu.h b/target-unicore32/cpu.h
index 81c14ff..ff99bda 100644
--- a/target-unicore32/cpu.h
+++ b/target-unicore32/cpu.h
@@ -1,7 +1,7 @@
 /*
  * UniCore32 virtual CPU header
  *
- * Copyright (C) 2010-2011 GUAN Xue-tao
+ * Copyright (C) 2010-2012 Guan Xuetao
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -89,8 +89,10 @@ typedef struct CPUUniCore32State {
 #define ASR_NZCV(ASR_N | ASR_Z | ASR_C | ASR_V)
 #define ASR_RESERVED(~(ASR_M | ASR_I | ASR_NZCV))
 
-#define UC32_EXCP_PRIV  (ASR_MODE_PRIV)
-#define UC32_EXCP_TRAP  (ASR_MODE_TRAP)
+#define UC32_EXCP_PRIV  (1)
+#define UC32_EXCP_ITRAP (2)
+#define UC32_EXCP_DTRAP (3)
+#define UC32_EXCP_INTR  (4)
 
 /* Return the current ASR value.  */
 target_ulong cpu_asr_read(CPUUniCore32State *env1);
@@ -120,10 +122,6 @@ void cpu_asr_write(CPUUniCore32State *env1, target_ulong 
val, target_ulong mask)
 #define UC32_HWCAP_CMOV 4 /* 1 << 2 */
 #define UC32_HWCAP_UCF648 /* 1 << 3 */
 
-#define UC32_CPUID(env) (env->cp0.c0_cpuid)
-#define UC32_CPUID_UCV2 0x40010863
-#define UC32_CPUID_ANY  0x
-
 #define cpu_inituc32_cpu_init
 #define cpu_execuc32_cpu_exec
 #

[Qemu-devel] [PATCHv2 04/13] unicore32-softmmu: Implement softmmu specific functions

2012-06-15 Thread Guan Xuetao
This patch implements softmmu specific functions, include tlb_fill,
switch_mode, do_interrupt and uc32_cpu_handle_mmu_fault.
So the full exception handlers and page table walking could work now.

Signed-off-by: Guan Xuetao 
---
 target-unicore32/op_helper.c |   22 -
 target-unicore32/softmmu.c   |  236 +-
 2 files changed, 253 insertions(+), 5 deletions(-)

diff --git a/target-unicore32/op_helper.c b/target-unicore32/op_helper.c
index d96d2c8..8ecab86 100644
--- a/target-unicore32/op_helper.c
+++ b/target-unicore32/op_helper.c
@@ -267,6 +267,26 @@ uint32_t HELPER(ror_cc)(uint32_t x, uint32_t i)
 void tlb_fill(CPUUniCore32State *env1, target_ulong addr, int is_write, int 
mmu_idx,
 uintptr_t retaddr)
 {
-cpu_abort(env, "%s not supported yet\n", __func__);
+TranslationBlock *tb;
+CPUUniCore32State *saved_env;
+unsigned long pc;
+int ret;
+
+saved_env = env;
+env = env1;
+ret = uc32_cpu_handle_mmu_fault(env, addr, is_write, mmu_idx);
+if (unlikely(ret)) {
+if (retaddr) {
+/* now we have a real cpu fault */
+pc = (unsigned long)retaddr;
+tb = tb_find_pc(pc);
+if (tb) {/* the PC is inside the translated code.
+It means that we have a virtual CPU fault */
+cpu_restore_state(tb, env, pc);
+}
+}
+cpu_loop_exit(env);
+}
+env = saved_env;
 }
 #endif
diff --git a/target-unicore32/softmmu.c b/target-unicore32/softmmu.c
index 6fec77e..373f94b 100644
--- a/target-unicore32/softmmu.c
+++ b/target-unicore32/softmmu.c
@@ -14,21 +14,249 @@
 
 #include 
 
+#undef DEBUG_UC32
+
+#ifdef DEBUG_UC32
+#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
+#else
+#define DPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#define SUPERPAGE_SIZE (1 << 22)
+#define UC32_PAGETABLE_READ(1 << 8)
+#define UC32_PAGETABLE_WRITE   (1 << 7)
+#define UC32_PAGETABLE_EXEC(1 << 6)
+#define UC32_PAGETABLE_EXIST   (1 << 2)
+#define PAGETABLE_TYPE(x)  ((x) & 3)
+
+
+/* Map CPU modes onto saved register banks.  */
+static inline int bank_number(int mode)
+{
+switch (mode) {
+case ASR_MODE_USER:
+case ASR_MODE_SUSR:
+return 0;
+case ASR_MODE_PRIV:
+return 1;
+case ASR_MODE_TRAP:
+return 2;
+case ASR_MODE_EXTN:
+return 3;
+case ASR_MODE_INTR:
+return 4;
+}
+cpu_abort(cpu_single_env, "Bad mode %x\n", mode);
+return -1;
+}
+
 void switch_mode(CPUUniCore32State *env, int mode)
 {
-cpu_abort(env, "%s not supported yet\n", __func__);
+int old_mode;
+int i;
+
+old_mode = env->uncached_asr & ASR_M;
+if (mode == old_mode) {
+return;
+}
+
+i = bank_number(old_mode);
+env->banked_r29[i] = env->regs[29];
+env->banked_r30[i] = env->regs[30];
+env->banked_bsr[i] = env->bsr;
+
+i = bank_number(mode);
+env->regs[29] = env->banked_r29[i];
+env->regs[30] = env->banked_r30[i];
+env->bsr = env->banked_bsr[i];
 }
 
+/* Handle a CPU exception.  */
 void do_interrupt(CPUUniCore32State *env)
 {
-cpu_abort(env, "%s not supported yet\n", __func__);
+uint32_t addr;
+int new_mode;
+
+switch (env->exception_index) {
+case UC32_EXCP_PRIV:
+new_mode = ASR_MODE_PRIV;
+addr = 0x08;
+break;
+case UC32_EXCP_ITRAP:
+DPRINTF("itrap happened at %x\n", env->regs[31]);
+new_mode = ASR_MODE_TRAP;
+addr = 0x0c;
+break;
+case UC32_EXCP_DTRAP:
+DPRINTF("dtrap happened at %x\n", env->regs[31]);
+new_mode = ASR_MODE_TRAP;
+addr = 0x10;
+break;
+case UC32_EXCP_INTR:
+new_mode = ASR_MODE_INTR;
+addr = 0x18;
+break;
+default:
+cpu_abort(env, "Unhandled exception 0x%x\n", env->exception_index);
+return;
+}
+/* High vectors.  */
+if (env->cp0.c1_sys & (1 << 13)) {
+addr += 0x;
+}
+
+switch_mode(env, new_mode);
+env->bsr = cpu_asr_read(env);
+env->uncached_asr = (env->uncached_asr & ~ASR_M) | new_mode;
+env->uncached_asr |= ASR_I;
+/* The PC already points to the proper instruction.  */
+env->regs[30] = env->regs[31];
+env->regs[31] = addr;
+env->interrupt_request |= CPU_INTERRUPT_EXITTB;
+}
+
+static int get_phys_addr_ucv2(CPUUniCore32State *env, uint32_t address,
+int access_type, int is_user, uint32_t *phys_ptr, int *prot,
+target_ulong *page_size)
+{
+int code;
+uint32_t table;
+uint32_t desc;
+uint32_t phys_addr;
+
+/* Pagetable walk.  */
+/* Lookup l1 descriptor.  */
+table = env->cp0.c2_base & 0xf000;
+table |= (address >> 20) & 0xffc;
+desc = ldl_phys(table);
+code = 0;
+switch (PAGETABLE_TYPE(desc)) {
+case 3:
+/* Superpage  */
+if (!(desc & UC32_PAGETABLE_EXIST)) {
+

Re: [Qemu-devel] [PATCHv2 05/13] unicore32-softmmu: Make sure that kernel can access user space

2012-06-15 Thread Wei-Ren Chen
Hi Guan,

>  /* These instructions trap after executing, so defer them until after the
> conditional executions state has been updated.  */
> @@ -1551,12 +1558,12 @@ static void do_misc(CPUUniCore32State *env, 
> DisasContext *s, uint32_t insn)
>  /* load/store I_offset and R_offset */
>  static void do_ldst_ir(CPUUniCore32State *env, DisasContext *s, uint32_t 
> insn)
>  {
> -unsigned int i;
> +unsigned int mmuindex;

   I would suggest you to rename it to mmu_idx or something like that. :)

Regards,
chenwj

-- 
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] [PATCHv2 1/1] Add usb option in machine options to enable/disable usb

2012-06-15 Thread Li Zhang
For pseries machine, it needs to enable usb to add
keyboard or usb mouse. -usb option won't be used in
the future, and machine options is a better way to
enable usb.

So this patch is to add usb option to machine options
(-machine type=psereis,usb=on/off)to enable/disable
usb controller.

In this patch, usb_on is an global option which can
be checked by machines.
For example, on pseries, it will check if usb_on is 1,
if it is 1, it will create one usb ohci controller.
As the following:
if (usb_on == 1) {
 pci_create_simple(bus, -1, "pci-ohci");
}

In this patch, usb is on by default. So, for -nodefault,
usb should be set off in the command line as the following:
 -machine type=pseries,usb=off.

Signed-off-by: Li Zhang 
---
 hw/spapr.c |5 +
 sysemu.h   |1 +
 vl.c   |   17 +
 3 files changed, 23 insertions(+)

diff --git a/hw/spapr.c b/hw/spapr.c
index d0bddbc..1feb739 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -661,6 +661,11 @@ static void ppc_spapr_init(ram_addr_t ram_size,
 spapr_vscsi_create(spapr->vio_bus);
 }
 
+if (usb_on == 1) {
+pci_create_simple(QLIST_FIRST(&spapr->phbs)->host_state.bus,
+  -1, "pci-ohci");
+}
+
 if (rma_size < (MIN_RMA_SLOF << 20)) {
 fprintf(stderr, "qemu: pSeries SLOF firmware requires >= "
 "%ldM guest RMA (Real Mode Area memory)\n", MIN_RMA_SLOF);
diff --git a/sysemu.h b/sysemu.h
index bc2c788..08134ae 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -109,6 +109,7 @@ extern int vga_interface_type;
 #define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
 #define qxl_enabled (vga_interface_type == VGA_QXL)
 
+extern int usb_on;
 extern int graphic_width;
 extern int graphic_height;
 extern int graphic_depth;
diff --git a/vl.c b/vl.c
index 204d85b..b200203 100644
--- a/vl.c
+++ b/vl.c
@@ -202,6 +202,7 @@ int smp_cpus = 1;
 int max_cpus = 0;
 int smp_cores = 1;
 int smp_threads = 1;
+int usb_on = 0;
 #ifdef CONFIG_VNC
 const char *vnc_display;
 #endif
@@ -758,6 +759,21 @@ static int bt_parse(const char *opt)
 return 1;
 }
 
+static int get_usb_opt(QemuOpts *opts)
+{
+const char *usb_opt = NULL;
+int usb_on = 0;
+
+if (NULL == qemu_opt_get(opts, "usb"))
+qemu_opt_set(opts, "usb", "on");
+
+usb_opt = qemu_opt_get(opts, "usb");
+if (usb_opt && strcmp(usb_opt, "on") == 0)
+usb_on = 1;
+
+return usb_on;
+}
+
 /***/
 /* QEMU Block devices */
 
@@ -3356,6 +3372,7 @@ int main(int argc, char **argv, char **envp)
 kernel_filename = qemu_opt_get(machine_opts, "kernel");
 initrd_filename = qemu_opt_get(machine_opts, "initrd");
 kernel_cmdline = qemu_opt_get(machine_opts, "append");
+usb_on = get_usb_opt(machine_opts);
 } else {
 kernel_filename = initrd_filename = kernel_cmdline = NULL;
 }
-- 
1.7.9.5




[Qemu-devel] [PATCHv2 09/13] unicore32-softmmu: Add puv3 gpio support

2012-06-15 Thread Guan Xuetao
This patch adds puv3 gpio (General Purpose Input/Output) support,
include gpio device simulation and its interrupt support.

Signed-off-by: Guan Xuetao 
---
 Makefile.objs  |1 +
 hw/puv3.c  |6 ++
 hw/puv3_gpio.c |  141 
 3 files changed, 148 insertions(+), 0 deletions(-)
 create mode 100644 hw/puv3_gpio.c

diff --git a/Makefile.objs b/Makefile.objs
index 65a2bf5..d7c63c4 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -277,6 +277,7 @@ hw-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
 # PKUnity SoC devices
 hw-obj-$(CONFIG_PUV3) += puv3_intc.o
 hw-obj-$(CONFIG_PUV3) += puv3_ost.o
+hw-obj-$(CONFIG_PUV3) += puv3_gpio.o
 
 # PCI watchdog devices
 hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
diff --git a/hw/puv3.c b/hw/puv3.c
index cc824e0..453b404 100644
--- a/hw/puv3.c
+++ b/hw/puv3.c
@@ -49,6 +49,12 @@ static void puv3_soc_init(CPUUniCore32State *env)
 
 /* Initialize minimal necessary devices for kernel booting */
 sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]);
+sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE,
+irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],
+irqs[PUV3_IRQS_GPIOLOW2], irqs[PUV3_IRQS_GPIOLOW3],
+irqs[PUV3_IRQS_GPIOLOW4], irqs[PUV3_IRQS_GPIOLOW5],
+irqs[PUV3_IRQS_GPIOLOW6], irqs[PUV3_IRQS_GPIOLOW7],
+irqs[PUV3_IRQS_GPIOHIGH], NULL);
 }
 
 static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size)
diff --git a/hw/puv3_gpio.c b/hw/puv3_gpio.c
new file mode 100644
index 000..c97dbb8
--- /dev/null
+++ b/hw/puv3_gpio.c
@@ -0,0 +1,141 @@
+/*
+ * GPIO device simulation in PKUnity SoC
+ *
+ * Copyright (C) 2010-2012 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
+ */
+#include "hw.h"
+#include "sysbus.h"
+
+#undef DEBUG_PUV3
+#include "puv3.h"
+
+typedef struct {
+SysBusDevice busdev;
+MemoryRegion iomem;
+qemu_irq irq[9];
+
+uint32_t reg_GPLR;
+uint32_t reg_GPDR;
+uint32_t reg_GPIR;
+} puv3_gpio_t;
+
+static uint64_t puv3_gpio_read(void *opaque, target_phys_addr_t offset,
+unsigned size)
+{
+puv3_gpio_t *s = (puv3_gpio_t *) opaque;
+uint32_t ret;
+
+switch (offset) {
+case 0x00:
+ret = s->reg_GPLR;
+break;
+case 0x04:
+ret = s->reg_GPDR;
+break;
+case 0x20:
+ret = s->reg_GPIR;
+break;
+default:
+hw_error("%s: Bad offset 0x%x\n", __func__, offset);
+}
+DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
+
+return ret;
+}
+
+static void puv3_gpio_write(void *opaque, target_phys_addr_t offset,
+uint64_t value, unsigned size)
+{
+puv3_gpio_t *s = (puv3_gpio_t *) opaque;
+
+DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
+switch (offset) {
+case 0x04:
+s->reg_GPDR = value;
+break;
+case 0x08:
+if (s->reg_GPDR & value) {
+s->reg_GPLR |= value;
+} else {
+hw_error("write gpio input port error!");
+}
+break;
+case 0x0c:
+if (s->reg_GPDR & value) {
+s->reg_GPLR &= ~value;
+} else {
+hw_error("write gpio input port error!");
+}
+break;
+case 0x10: /* GRER */
+case 0x14: /* GFER */
+case 0x18: /* GEDR */
+break;
+case 0x20: /* GPIR */
+s->reg_GPIR = value;
+break;
+default:
+hw_error("%s: Bad offset 0x%x\n", __func__, offset);
+}
+}
+
+static const MemoryRegionOps puv3_gpio_ops = {
+.read = puv3_gpio_read,
+.write = puv3_gpio_write,
+.impl = {
+.min_access_size = 4,
+.max_access_size = 4,
+},
+.endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static int puv3_gpio_init(SysBusDevice *dev)
+{
+puv3_gpio_t *s = FROM_SYSBUS(puv3_gpio_t, dev);
+
+s->reg_GPLR = 0;
+s->reg_GPDR = 0;
+
+/* FIXME: these irqs not handled yet */
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOLOW0]);
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOLOW1]);
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOLOW2]);
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOLOW3]);
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOLOW4]);
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOLOW5]);
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOLOW6]);
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOLOW7]);
+sysbus_init_irq(dev, &s->irq[PUV3_IRQS_GPIOHIGH]);
+
+memory_region_init_io(&s->iomem, &puv3_gpio_ops, s, "puv3_gpio",
+PUV3_REGS_OFFSET);
+sysbus_init_mmio(dev, &s->iomem);
+
+return 0;
+}
+
+static void puv3_gpio_class_init(ObjectClass *klass, void *data)
+{
+SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+sdc->init = puv3_g

Re: [Qemu-devel] [PATCHv2 00/13] unicore32: add softmmu support and puv3 machine

2012-06-15 Thread Wei-Ren Chen
On Fri, Jun 15, 2012 at 05:47:33PM +0800, Guan Xuetao wrote:
> These patches implement softmmu support on unicore32 architecture.
> 
> UniCore32 CPU is embedded in PKUnity-3 SoC, so we add necessary puv3
> devices simulation codes together.
> Only minimal system control modules are simulated, to make linux kernel
> boot and busybox run in initramfs.

  Do you plan put disk image on http://wiki.qemu.org/Testing ?

Regards,
chenwj

-- 
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] [PATCHv2 06/13] unicore32-softmmu: Add puv3 soc/board support

2012-06-15 Thread Guan Xuetao
This patch only add puv3 soc/board support, which introduces puv3
machine description, and specifies console type.

Signed-off-by: Guan Xuetao 
---
 Makefile.target   |1 +
 default-configs/unicore32-softmmu.mak |1 +
 hw/puv3.c |   93 +
 hw/puv3.h |   49 +
 4 files changed, 144 insertions(+), 0 deletions(-)
 create mode 100644 hw/puv3.c
 create mode 100644 hw/puv3.h

diff --git a/Makefile.target b/Makefile.target
index 7d3b1fd..e552450 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -388,6 +388,7 @@ obj-xtensa-y += core-dc233c.o
 obj-xtensa-y += core-fsf.o
 
 obj-unicore32-y += softmmu.o
+obj-unicore32-$(CONFIG_PUV3) += puv3.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
diff --git a/default-configs/unicore32-softmmu.mak 
b/default-configs/unicore32-softmmu.mak
index 5f04fe3..726a338 100644
--- a/default-configs/unicore32-softmmu.mak
+++ b/default-configs/unicore32-softmmu.mak
@@ -1 +1,2 @@
 # Default configuration for unicore32-softmmu
+CONFIG_PUV3=y
diff --git a/hw/puv3.c b/hw/puv3.c
new file mode 100644
index 000..90231d4
--- /dev/null
+++ b/hw/puv3.c
@@ -0,0 +1,93 @@
+/*
+ * Generic PKUnity SoC machine and board descriptor
+ *
+ * Copyright (C) 2010-2012 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
+ */
+#include "console.h"
+#include "elf.h"
+#include "exec-memory.h"
+#include "sysbus.h"
+#include "boards.h"
+#include "loader.h"
+#include "pc.h"
+
+#undef DEBUG_PUV3
+#include "puv3.h"
+
+#define KERNEL_LOAD_ADDR0x0300
+#define KERNEL_MAX_SIZE 0x0080 /* Just a guess */
+
+static void puv3_soc_init(CPUUniCore32State *env)
+{
+/* TODO */
+}
+
+static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size)
+{
+MemoryRegion *ram_memory = g_new(MemoryRegion, 1);
+
+/* SDRAM at address zero.  */
+memory_region_init_ram(ram_memory, "puv3.ram", ram_size);
+vmstate_register_ram_global(ram_memory);
+memory_region_add_subregion(get_system_memory(), 0, ram_memory);
+}
+
+static void puv3_load_kernel(const char *kernel_filename)
+{
+int size;
+
+assert(kernel_filename != NULL);
+
+/* only zImage format supported */
+size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
+KERNEL_MAX_SIZE);
+if (size < 0) {
+hw_error("Load kernel error: '%s'\n", kernel_filename);
+}
+
+/* cheat curses that we have a graphic console, only under ocd console */
+graphic_console_init(NULL, NULL, NULL, NULL, NULL);
+}
+
+static void puv3_init(ram_addr_t ram_size, const char *boot_device,
+ const char *kernel_filename, const char *kernel_cmdline,
+ const char *initrd_filename, const char *cpu_model)
+{
+CPUUniCore32State *env;
+
+if (initrd_filename) {
+hw_error("Please use kernel built-in initramdisk.\n");
+}
+
+if (!cpu_model) {
+cpu_model = "UniCore-II";
+}
+
+env = cpu_init(cpu_model);
+if (!env) {
+hw_error("Unable to find CPU definition\n");
+}
+
+puv3_soc_init(env);
+puv3_board_init(env, ram_size);
+puv3_load_kernel(kernel_filename);
+}
+
+static QEMUMachine puv3_machine = {
+.name = "puv3",
+.desc = "PKUnity Version-3 based on UniCore32",
+.init = puv3_init,
+.use_scsi = 0,
+};
+
+static void puv3_machine_init(void)
+{
+qemu_register_machine(&puv3_machine);
+}
+
+machine_init(puv3_machine_init);
diff --git a/hw/puv3.h b/hw/puv3.h
new file mode 100644
index 000..bcfc978
--- /dev/null
+++ b/hw/puv3.h
@@ -0,0 +1,49 @@
+/*
+ * Misc PKUnity SoC declarations
+ *
+ * Copyright (C) 2010-2012 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef __PUV3_H__
+#define __PUV3_H__
+
+#define PUV3_REGS_OFFSET(0x1000) /* 4K is reasonable */
+
+/* PKUnity System bus (AHB): 0xc000 - 0xedff (640MB) */
+#define PUV3_DMA_BASE   (0xc020) /* AHB-4 */
+
+/* PKUnity Peripheral bus (APB): 0xee00 - 0xefff (128MB) */
+#define PUV3_GPIO_BASE  (0xee50) /* APB-5 */
+#define PUV3_INTC_BASE  (0xee60) /* APB-6 */
+#define PUV3_OST_BASE   (0xee80) /* APB-8 */
+#define PUV3_PM_BASE(0xeea0) /* APB-10 */
+#define PUV3_PS2_BASE   (0xeeb0) /* APB-11 */
+
+/* Hardware interrupts */
+#define PUV3_IRQS_NR(32)
+
+#define PUV3_IRQS_GPIOLOW0  (0)
+#define PUV3_IRQS_GPIOLOW1  (1)
+#define PUV3_IRQS_GPIOLOW2  

[Qemu-devel] [PATCH] cris: Fix NMI-flag handling on crisv10.

2012-06-15 Thread Lars Persson
- The M-flag is encoded in different bits on cris v10 and cris v32.

Signed-off-by: Lars Persson 
---
 cpu-exec.c  |   17 -
 target-cris/cpu.h   |3 ++-
 target-cris/helper.c|4 ++--
 target-cris/op_helper.c |4 ++--
 4 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 83cac93..ce4718f 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -467,11 +467,18 @@ int cpu_exec(CPUArchState *env)
 do_interrupt(env);
 next_tb = 0;
 }
-if (interrupt_request & CPU_INTERRUPT_NMI
-&& (env->pregs[PR_CCS] & M_FLAG)) {
-env->exception_index = EXCP_NMI;
-do_interrupt(env);
-next_tb = 0;
+if (interrupt_request & CPU_INTERRUPT_NMI) {
+unsigned int m_flag_archval;
+if (env->pregs[PR_VR] < 32) {
+m_flag_archval = M_FLAG_V10;
+} else {
+m_flag_archval = M_FLAG_V32;
+}
+if ((env->pregs[PR_CCS] & m_flag_archval)) {
+env->exception_index = EXCP_NMI;
+do_interrupt(env);
+next_tb = 0;
+   }
 }
 #elif defined(TARGET_M68K)
 if (interrupt_request & CPU_INTERRUPT_HARD
diff --git a/target-cris/cpu.h b/target-cris/cpu.h
index 73004af..4f4df6d 100644
--- a/target-cris/cpu.h
+++ b/target-cris/cpu.h
@@ -69,13 +69,14 @@
 
 /* CPU flags.  */
 #define Q_FLAG 0x8000
-#define M_FLAG 0x4000
+#define M_FLAG_V32 0x4000
 #define PFIX_FLAG 0x800  /* CRISv10 Only.  */
 #define F_FLAG_V10 0x400
 #define P_FLAG_V10 0x200
 #define S_FLAG 0x200
 #define R_FLAG 0x100
 #define P_FLAG 0x80
+#define M_FLAG_V10 0x80
 #define U_FLAG 0x40
 #define I_FLAG 0x20
 #define X_FLAG 0x10
diff --git a/target-cris/helper.c b/target-cris/helper.c
index dcc19ef..bfbc29e 100644
--- a/target-cris/helper.c
+++ b/target-cris/helper.c
@@ -127,7 +127,7 @@ static void do_interruptv10(CPUCRISState *env)
case EXCP_NMI:
/* NMI is hardwired to vector zero.  */
ex_vec = 0;
-   env->pregs[PR_CCS] &= ~M_FLAG;
+   env->pregs[PR_CCS] &= ~M_FLAG_V10;
env->pregs[PRV10_BRP] = env->pc;
break;
 
@@ -185,7 +185,7 @@ void do_interrupt(CPUCRISState *env)
case EXCP_NMI:
/* NMI is hardwired to vector zero.  */
ex_vec = 0;
-   env->pregs[PR_CCS] &= ~M_FLAG;
+   env->pregs[PR_CCS] &= ~M_FLAG_V32;
env->pregs[PR_NRP] = env->pc;
break;
 
diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c
index b92c106..ac7c98c 100644
--- a/target-cris/op_helper.c
+++ b/target-cris/op_helper.c
@@ -247,8 +247,8 @@ void helper_rfn(void)
if (!rflag)
env->pregs[PR_CCS] |= P_FLAG;
 
-/* Always set the M flag.  */
-env->pregs[PR_CCS] |= M_FLAG;
+   /* Always set the M flag.  */
+   env->pregs[PR_CCS] |= M_FLAG_V32;
 }
 
 uint32_t helper_lz(uint32_t t0)
-- 
1.7.2.5




Re: [Qemu-devel] [PATCHv2 01/13] unicore32-softmmu: Add unicore32-softmmu build support

2012-06-15 Thread Paolo Bonzini
Il 15/06/2012 11:47, Guan Xuetao ha scritto:
> This patch adds unicore32-softmmu build support, include configure,
> makefile, arch_init, and all missing functions needed by softmmu.
> Although all missing functions are empty, unicore32-softmmu could
> be build successfully.
> 
> Signed-off-by: Guan Xuetao 
> ---
>  Makefile.target   |2 +
>  arch_init.c   |2 +
>  arch_init.h   |1 +
>  configure |1 +
>  default-configs/unicore32-softmmu.mak |1 +
>  target-unicore32/helper.c |   25 +++--
>  target-unicore32/machine.c|   23 +++
>  target-unicore32/op_helper.c  |   24 +++-
>  target-unicore32/softmmu.c|   39 
> +
>  9 files changed, 105 insertions(+), 13 deletions(-)
>  create mode 100644 default-configs/unicore32-softmmu.mak
>  create mode 100644 target-unicore32/machine.c
>  create mode 100644 target-unicore32/softmmu.c
> 
> diff --git a/Makefile.target b/Makefile.target
> index 1582904..7d3b1fd 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -387,6 +387,8 @@ obj-xtensa-y += core-dc232b.o
>  obj-xtensa-y += core-dc233c.o
>  obj-xtensa-y += core-fsf.o
>  
> +obj-unicore32-y += softmmu.o
> +

You need to rebase this and put this line (actually
obj-$(CONFIG_SOFTMMU) += softmmu.o) in target-unicore32/Makefile.objs.

Paolo




[Qemu-devel] [PATCHv2 01/13] unicore32-softmmu: Add unicore32-softmmu build support

2012-06-15 Thread Guan Xuetao
This patch adds unicore32-softmmu build support, include configure,
makefile, arch_init, and all missing functions needed by softmmu.
Although all missing functions are empty, unicore32-softmmu could
be build successfully.

Signed-off-by: Guan Xuetao 
---
 Makefile.target   |2 +
 arch_init.c   |2 +
 arch_init.h   |1 +
 configure |1 +
 default-configs/unicore32-softmmu.mak |1 +
 target-unicore32/helper.c |   25 +++--
 target-unicore32/machine.c|   23 +++
 target-unicore32/op_helper.c  |   24 +++-
 target-unicore32/softmmu.c|   39 +
 9 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 default-configs/unicore32-softmmu.mak
 create mode 100644 target-unicore32/machine.c
 create mode 100644 target-unicore32/softmmu.c

diff --git a/Makefile.target b/Makefile.target
index 1582904..7d3b1fd 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -387,6 +387,8 @@ obj-xtensa-y += core-dc232b.o
 obj-xtensa-y += core-dc233c.o
 obj-xtensa-y += core-fsf.o
 
+obj-unicore32-y += softmmu.o
+
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 monitor.o: hmp-commands.h qmp-commands-old.h
diff --git a/arch_init.c b/arch_init.c
index 988adca..9314025 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -81,6 +81,8 @@ int graphic_depth = 15;
 #define QEMU_ARCH QEMU_ARCH_SPARC
 #elif defined(TARGET_XTENSA)
 #define QEMU_ARCH QEMU_ARCH_XTENSA
+#elif defined(TARGET_UNICORE32)
+#define QEMU_ARCH QEMU_ARCH_UNICORE32
 #endif
 
 const uint32_t arch_type = QEMU_ARCH;
diff --git a/arch_init.h b/arch_init.h
index c7cb94a..5298139 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -16,6 +16,7 @@ enum {
 QEMU_ARCH_SH4 = 1024,
 QEMU_ARCH_SPARC = 2048,
 QEMU_ARCH_XTENSA = 4096,
+QEMU_ARCH_UNICORE32 = 8192,
 };
 
 extern const uint32_t arch_type;
diff --git a/configure b/configure
index b55a792..795b7d9 100755
--- a/configure
+++ b/configure
@@ -934,6 +934,7 @@ sparc64-softmmu \
 s390x-softmmu \
 xtensa-softmmu \
 xtensaeb-softmmu \
+unicore32-softmmu \
 "
 fi
 # the following are Linux specific
diff --git a/default-configs/unicore32-softmmu.mak 
b/default-configs/unicore32-softmmu.mak
new file mode 100644
index 000..5f04fe3
--- /dev/null
+++ b/default-configs/unicore32-softmmu.mak
@@ -0,0 +1 @@
+# Default configuration for unicore32-softmmu
diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index 9fe4a37..17d9b41 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -45,18 +45,26 @@ uint32_t HELPER(clz)(uint32_t x)
 return clz32(x);
 }
 
+#ifdef CONFIG_USER_ONLY
+void switch_mode(CPUUniCore32State *env, int mode)
+{
+if (mode != ASR_MODE_USER) {
+cpu_abort(env, "Tried to switch out of user mode\n");
+}
+}
+
 void do_interrupt(CPUUniCore32State *env)
 {
-env->exception_index = -1;
+cpu_abort(env, "NO interrupt in user mode\n");
 }
 
-int uc32_cpu_handle_mmu_fault(CPUUniCore32State *env, target_ulong address, 
int rw,
-  int mmu_idx)
+int uc32_cpu_handle_mmu_fault(CPUUniCore32State *env, target_ulong address,
+  int access_type, int mmu_idx)
 {
-env->exception_index = UC32_EXCP_TRAP;
-env->cp0.c4_faultaddr = address;
+cpu_abort(env, "NO mmu fault in user mode\n");
 return 1;
 }
+#endif
 
 /* These should probably raise undefined insn exceptions.  */
 void HELPER(set_cp)(CPUUniCore32State *env, uint32_t insn, uint32_t val)
@@ -84,13 +92,6 @@ uint32_t HELPER(get_cp0)(CPUUniCore32State *env, uint32_t 
insn)
 return 0;
 }
 
-void switch_mode(CPUUniCore32State *env, int mode)
-{
-if (mode != ASR_MODE_USER) {
-cpu_abort(env, "Tried to switch out of user mode\n");
-}
-}
-
 void HELPER(set_r29_banked)(CPUUniCore32State *env, uint32_t mode, uint32_t 
val)
 {
 cpu_abort(env, "banked r29 write\n");
diff --git a/target-unicore32/machine.c b/target-unicore32/machine.c
new file mode 100644
index 000..60b2ec1
--- /dev/null
+++ b/target-unicore32/machine.c
@@ -0,0 +1,23 @@
+/*
+ * Generic machine functions for UniCore32 ISA
+ *
+ * Copyright (C) 2010-2012 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
+ */
+#include "hw/hw.h"
+
+void cpu_save(QEMUFile *f, void *opaque)
+{
+hw_error("%s not supported yet.\n", __func__);
+}
+
+int cpu_load(QEMUFile *f, void *opaque, int version_id)
+{
+hw_error("%s not supported yet.\n", __func__);
+
+return 0;
+}
diff --git a/target-unicore32/op_helper.c b/target-unicore32/op_helper.c
index b954c30..d96d2c8 100644
--- a/target-unicore32/op_helper.c
+++ b/target-unicore32/op_

Re: [Qemu-devel] IO performance test on the tcm-vhost scsi

2012-06-15 Thread Stefan Hajnoczi
On Thu, Jun 14, 2012 at 9:41 PM, Nicholas A. Bellinger
 wrote:
> Btw, I'll likely end up doing this conversion to realize the performance
> benefits when testing with raw flash backends, but I'm more than happy
> to take a patch ahead of that if you have the extra cycles to spare.

This was mentioned on target-devel a little while ago.  Unfortunately
I'm busy, the chance of a patch appearing from me is low, sorry.  If I
do get some cycles to tackle it I'll let you know first so we don't
duplicate work.

Stefan



[Qemu-devel] [PATCHv2 12/13] unicore32-softmmu: Add ps2 support

2012-06-15 Thread Guan Xuetao
This patch adds ps2/keyboard support, and enables CONFIG_PCKBD.

Signed-off-by: Guan Xuetao 
---
 default-configs/unicore32-softmmu.mak |1 +
 hw/puv3.c |5 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/default-configs/unicore32-softmmu.mak 
b/default-configs/unicore32-softmmu.mak
index 4d4fbfc..de38577 100644
--- a/default-configs/unicore32-softmmu.mak
+++ b/default-configs/unicore32-softmmu.mak
@@ -1,3 +1,4 @@
 # Default configuration for unicore32-softmmu
 CONFIG_PUV3=y
 CONFIG_PTIMER=y
+CONFIG_PCKBD=y
diff --git a/hw/puv3.c b/hw/puv3.c
index 226a34f..0eabefd 100644
--- a/hw/puv3.c
+++ b/hw/puv3.c
@@ -38,6 +38,7 @@ static void puv3_soc_init(CPUUniCore32State *env)
 {
 qemu_irq *cpu_intc, irqs[PUV3_IRQS_NR];
 DeviceState *dev;
+MemoryRegion *i8042 = g_new(MemoryRegion, 1);
 int i;
 
 /* Initialize interrupt controller */
@@ -57,6 +58,10 @@ static void puv3_soc_init(CPUUniCore32State *env)
 irqs[PUV3_IRQS_GPIOLOW4], irqs[PUV3_IRQS_GPIOLOW5],
 irqs[PUV3_IRQS_GPIOLOW6], irqs[PUV3_IRQS_GPIOLOW7],
 irqs[PUV3_IRQS_GPIOHIGH], NULL);
+
+/* Keyboard (i8042), mouse disabled for nographic */
+i8042_mm_init(irqs[PUV3_IRQS_PS2_KBD], NULL, i8042, PUV3_REGS_OFFSET, 4);
+memory_region_add_subregion(get_system_memory(), PUV3_PS2_BASE, i8042);
 }
 
 static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size)
-- 
1.7.0.4




[Qemu-devel] [PATCHv2 02/13] unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction support

2012-06-15 Thread Guan Xuetao
Coprocessor 0 is system control coprocessor, and we need get/set its contents.
Also, all cache/tlb ops shoule be implemented here, but just ignored with no 
harm.

Coprocessor 1 is OCD (on-chip-debugger), which is used for faked console,
so we could output chars to this console without graphic card.

Signed-off-by: Guan Xuetao 
---
 target-unicore32/helper.c|  185 --
 target-unicore32/helper.h|   15 ++--
 target-unicore32/translate.c |   75 +-
 3 files changed, 223 insertions(+), 52 deletions(-)

diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index 17d9b41..f58a5af 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -1,12 +1,10 @@
 /*
- * Copyright (C) 2010-2011 GUAN Xue-tao
+ * Copyright (C) 2010-2012 Guan Xuetao
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Contributions from 2012-04-01 on are considered under GPL version 2,
- * or (at your option) any later version.
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
  */
 
 #include "cpu.h"
@@ -14,6 +12,14 @@
 #include "helper.h"
 #include "host-utils.h"
 
+#undef DEBUG_UC32
+
+#ifdef DEBUG_UC32
+#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
+#else
+#define DPRINTF(fmt, ...) do {} while (0)
+#endif
+
 CPUUniCore32State *uc32_cpu_init(const char *cpu_model)
 {
 UniCore32CPU *cpu;
@@ -45,6 +51,138 @@ uint32_t HELPER(clz)(uint32_t x)
 return clz32(x);
 }
 
+#ifndef CONFIG_USER_ONLY
+void helper_cp0_set(CPUUniCore32State *env, uint32_t val, uint32_t creg,
+uint32_t cop)
+{
+/*
+ * movc pp.nn, rn, #imm9
+ *  rn: UCOP_REG_D
+ *  nn: UCOP_REG_N
+ *  1: sys control reg.
+ *  2: page table base reg.
+ *  3: data fault status reg.
+ *  4: insn fault status reg.
+ *  5: cache op. reg.
+ *  6: tlb op. reg.
+ *  imm9: split UCOP_IMM10 with bit5 is 0
+ */
+switch (creg) {
+case 1:
+if (cop != 0) goto unrecognized;
+env->cp0.c1_sys = val;
+break;
+case 2:
+if (cop != 0) goto unrecognized;
+env->cp0.c2_base = val;
+break;
+case 3:
+if (cop != 0) goto unrecognized;
+env->cp0.c3_faultstatus = val;
+break;
+case 4:
+if (cop != 0) goto unrecognized;
+env->cp0.c4_faultaddr = val;
+break;
+case 5:
+switch(cop) {
+case 28:
+DPRINTF("Invalidate Entire I&D cache\n");
+return;
+case 20:
+DPRINTF("Invalidate Entire Icache\n");
+return;
+case 12:
+DPRINTF("Invalidate Entire Dcache\n");
+return;
+case 10:
+DPRINTF("Clean Entire Dcache\n");
+return;
+case 14:
+DPRINTF("Flush Entire Dcache\n");
+return;
+case 13:
+DPRINTF("Invalidate Dcache line\n");
+return;
+case 11:
+DPRINTF("Clean Dcache line\n");
+return;
+case 15:
+DPRINTF("Flush Dcache line\n");
+return;
+}
+break;
+case 6:
+if ((cop <= 6) && (cop >=2)) {
+/* invalid all tlb */
+tlb_flush(env, 1);
+return;
+}
+break;
+default:
+goto unrecognized;
+}
+return;
+unrecognized:
+cpu_abort(env, "Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
+creg, cop);
+}
+
+uint32_t helper_cp0_get(CPUUniCore32State *env, uint32_t creg, uint32_t cop)
+{
+/*
+ * movc rd, pp.nn, #imm9
+ *  rd: UCOP_REG_D
+ *  nn: UCOP_REG_N
+ *  0: cpuid and cachetype
+ *  1: sys control reg.
+ *  2: page table base reg.
+ *  3: data fault status reg.
+ *  4: insn fault status reg.
+ *  imm9: split UCOP_IMM10 with bit5 is 0
+ */
+switch (creg) {
+case 0:
+switch (cop) {
+case 0:
+return env->cp0.c0_cpuid;
+case 1:
+return env->cp0.c0_cachetype;
+}
+break;
+case 1:
+if (cop == 0) {
+return env->cp0.c1_sys;
+}
+break;
+case 2:
+if (cop == 0) {
+return env->cp0.c2_base;
+}
+break;
+case 3:
+if (cop == 0) {
+return env->cp0.c3_faultstatus;
+}
+break;
+case 4:
+if (cop == 0) {
+return env->cp0.c4_faultaddr;
+}
+break;
+}
+cpu_abort(env, "Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
+creg, cop);
+}
+
+void helper_cp1_putc(target_ulong x)
+

[Qemu-devel] [PATCHv2 00/13] unicore32: add softmmu support and puv3 machine

2012-06-15 Thread Guan Xuetao
These patches implement softmmu support on unicore32 architecture.

UniCore32 CPU is embedded in PKUnity-3 SoC, so we add necessary puv3
devices simulation codes together.
Only minimal system control modules are simulated, to make linux kernel
boot and busybox run in initramfs.

Any advice is greatly appreciated.

Thanks,

Guan Xuetao

---

Guan Xuetao (13):
  unicore32-softmmu: Add unicore32-softmmu build support
  unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction
support
  unicore32-softmmu: Make UniCore32 cpuid & exceptions correct and
runable
  unicore32-softmmu: Implement softmmu specific functions
  unicore32-softmmu: Make sure that kernel can access user space
  unicore32-softmmu: Add puv3 soc/board support
  unicore32-softmmu: Add puv3 interrupt support
  unicore32-softmmu: Add puv3 ostimer support
  unicore32-softmmu: Add puv3 gpio support
  unicore32-softmmu: Add puv3 pm support
  unicore32-softmmu: Add puv3 dma support
  unicore32-softmmu: Add ps2 support
  unicore32-softmmu: Add maintainer information for UniCore32 machine

 MAINTAINERS   |7 +
 Makefile.objs |7 +
 Makefile.target   |3 +
 arch_init.c   |2 +
 arch_init.h   |1 +
 configure |1 +
 cpu-exec.c|1 +
 default-configs/unicore32-softmmu.mak |4 +
 hw/puv3.c |  130 
 hw/puv3.h |   49 ++
 hw/puv3_dma.c |  109 +
 hw/puv3_gpio.c|  141 +
 hw/puv3_intc.c|  135 +
 hw/puv3_ost.c |  151 +++
 hw/puv3_pm.c  |  148 ++
 linux-user/main.c |3 +-
 target-unicore32/cpu.c|   25 ++-
 target-unicore32/cpu.h|   12 +-
 target-unicore32/helper.c |  180 +-
 target-unicore32/helper.h |   15 +-
 target-unicore32/machine.c|   23 +++
 target-unicore32/op_helper.c  |   44 ++-
 target-unicore32/softmmu.c|  267 +
 target-unicore32/translate.c  |  111 --
 24 files changed, 1492 insertions(+), 77 deletions(-)
 create mode 100644 default-configs/unicore32-softmmu.mak
 create mode 100644 hw/puv3.c
 create mode 100644 hw/puv3.h
 create mode 100644 hw/puv3_dma.c
 create mode 100644 hw/puv3_gpio.c
 create mode 100644 hw/puv3_intc.c
 create mode 100644 hw/puv3_ost.c
 create mode 100644 hw/puv3_pm.c
 create mode 100644 target-unicore32/machine.c
 create mode 100644 target-unicore32/softmmu.c




Re: [Qemu-devel] libguestfs now uses virtio-scsi, supports large numbers of disks

2012-06-15 Thread Stefan Hajnoczi
On Thu, Jun 14, 2012 at 2:49 PM, Richard W.M. Jones  wrote:
> I switched libguestfs over to using virtio-scsi.  One immediate
> benefit is support for large numbers of disks: up to 255 because we're
> using 1 target / disk and we reserve one disk for the appliance, in
> theory more could be supported if we used LUNs.

Cool, thanks for sharing!  Does libguestfs hotplug LUNS/targets?

Cong and Wan Seng are implementing guest driver and QEMU-side changes
so the guest receives notifications of hotplugged LUNs.  It's nicer
than manually rescanning the bus from inside the guest.

Stefan



[Qemu-devel] [PATCHv2 13/13] unicore32-softmmu: Add maintainer information for UniCore32 machine

2012-06-15 Thread Guan Xuetao
Signed-off-by: Guan Xuetao 
---
 MAINTAINERS |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index b45f075..eb5d93a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -394,6 +394,13 @@ M: Alexander Graf 
 S: Maintained
 F: hw/s390-*.c
 
+UniCore32 Machines
+-
+PKUnity-3 SoC initramfs-with-busybox
+M: Guan Xuetao 
+S: Maintained
+F: hw/puv3*
+
 X86 Machines
 
 PC
-- 
1.7.0.4




[Qemu-devel] [PATCHv2 08/13] unicore32-softmmu: Add puv3 ostimer support

2012-06-15 Thread Guan Xuetao
This patch adds puv3 ostimer support, include os timer
device simulation and ptimer support in puv3 machine.

Signed-off-by: Guan Xuetao 
---
 Makefile.objs |1 +
 default-configs/unicore32-softmmu.mak |1 +
 hw/puv3.c |3 +
 hw/puv3_ost.c |  151 +
 4 files changed, 156 insertions(+), 0 deletions(-)
 create mode 100644 hw/puv3_ost.c

diff --git a/Makefile.objs b/Makefile.objs
index 37bd3d4..65a2bf5 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -276,6 +276,7 @@ hw-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
 
 # PKUnity SoC devices
 hw-obj-$(CONFIG_PUV3) += puv3_intc.o
+hw-obj-$(CONFIG_PUV3) += puv3_ost.o
 
 # PCI watchdog devices
 hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
diff --git a/default-configs/unicore32-softmmu.mak 
b/default-configs/unicore32-softmmu.mak
index 726a338..4d4fbfc 100644
--- a/default-configs/unicore32-softmmu.mak
+++ b/default-configs/unicore32-softmmu.mak
@@ -1,2 +1,3 @@
 # Default configuration for unicore32-softmmu
 CONFIG_PUV3=y
+CONFIG_PTIMER=y
diff --git a/hw/puv3.c b/hw/puv3.c
index 7b0cfde..cc824e0 100644
--- a/hw/puv3.c
+++ b/hw/puv3.c
@@ -46,6 +46,9 @@ static void puv3_soc_init(CPUUniCore32State *env)
 for (i = 0; i < PUV3_IRQS_NR; i++) {
 irqs[i] = qdev_get_gpio_in(dev, i);
 }
+
+/* Initialize minimal necessary devices for kernel booting */
+sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]);
 }
 
 static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size)
diff --git a/hw/puv3_ost.c b/hw/puv3_ost.c
new file mode 100644
index 000..8b74eb4
--- /dev/null
+++ b/hw/puv3_ost.c
@@ -0,0 +1,151 @@
+/*
+ * OSTimer device simulation in PKUnity SoC
+ *
+ * Copyright (C) 2010-2012 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
+ */
+#include "sysbus.h"
+#include "ptimer.h"
+
+#undef DEBUG_PUV3
+#include "puv3.h"
+
+/* puv3 ostimer implementation. */
+typedef struct {
+SysBusDevice busdev;
+MemoryRegion iomem;
+QEMUBH *bh;
+qemu_irq irq;
+ptimer_state *ptimer;
+
+uint32_t reg_OSMR0;
+uint32_t reg_OSCR;
+uint32_t reg_OSSR;
+uint32_t reg_OIER;
+} puv3_ost_t;
+
+static uint64_t puv3_ost_read(void *opaque, target_phys_addr_t offset,
+unsigned size)
+{
+puv3_ost_t *s = (puv3_ost_t *)opaque;
+uint32_t ret = 0;
+
+switch (offset) {
+case 0x10: /* Counter Register */
+ret = s->reg_OSMR0 - (uint32_t)ptimer_get_count(s->ptimer);
+break;
+case 0x14: /* Status Register */
+ret = s->reg_OSSR;
+break;
+case 0x1c: /* Interrupt Enable Register */
+ret = s->reg_OIER;
+break;
+default:
+hw_error("puv3_ost_read: Bad offset %x\n", (int)offset);
+}
+DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
+return ret;
+}
+
+static void puv3_ost_write(void *opaque, target_phys_addr_t offset,
+uint64_t value, unsigned size)
+{
+puv3_ost_t *s = (puv3_ost_t *)opaque;
+
+DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
+switch (offset) {
+case 0x00: /* Match Register 0 */
+s->reg_OSMR0 = value;
+if (s->reg_OSMR0 > s->reg_OSCR) {
+ptimer_set_count(s->ptimer, s->reg_OSMR0 - s->reg_OSCR);
+} else {
+ptimer_set_count(s->ptimer, s->reg_OSMR0 +
+(0x - s->reg_OSCR));
+}
+ptimer_run(s->ptimer, 2);
+break;
+case 0x14: /* Status Register */
+assert(value == 0);
+if (s->reg_OSSR) {
+s->reg_OSSR = value;
+qemu_irq_lower(s->irq);
+}
+break;
+case 0x1c: /* Interrupt Enable Register */
+s->reg_OIER = value;
+break;
+default:
+hw_error("puv3_ost_write: Bad offset %x\n", (int)offset);
+}
+}
+
+static const MemoryRegionOps puv3_ost_ops = {
+.read = puv3_ost_read,
+.write = puv3_ost_write,
+.impl = {
+.min_access_size = 4,
+.max_access_size = 4,
+},
+.endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static void puv3_ost_tick(void *opaque)
+{
+puv3_ost_t *s = (puv3_ost_t *)opaque;
+
+DPRINTF("ost hit when ptimer counter from 0x%x to 0x%x!\n",
+s->reg_OSCR, s->reg_OSMR0);
+
+s->reg_OSCR = s->reg_OSMR0;
+if (s->reg_OIER) {
+s->reg_OSSR = 1;
+qemu_irq_raise(s->irq);
+}
+}
+
+static int puv3_ost_init(SysBusDevice *dev)
+{
+puv3_ost_t *s = FROM_SYSBUS(puv3_ost_t, dev);
+
+s->reg_OIER = 0;
+s->reg_OSSR = 0;
+s->reg_OSMR0 = 0;
+s->reg_OSCR = 0;
+
+sysbus_init_irq(dev, &s->irq);
+
+s->bh = qemu_bh_new(puv3_ost_tick, s);
+s->ptimer = ptimer_init(s->bh);
+ptimer_set_freq(s->ptimer, 

[Qemu-devel] [PATCHv2 11/13] unicore32-softmmu: Add puv3 dma support

2012-06-15 Thread Guan Xuetao
This patch adds puv3 dma (Direct Memory Access) support,
include dma device simulation for kernel booting.

Signed-off-by: Guan Xuetao 
---
 Makefile.objs |1 +
 hw/puv3.c |1 +
 hw/puv3_dma.c |  109 +
 3 files changed, 111 insertions(+), 0 deletions(-)
 create mode 100644 hw/puv3_dma.c

diff --git a/Makefile.objs b/Makefile.objs
index d14a08e..cdf7ef7 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -279,6 +279,7 @@ hw-obj-$(CONFIG_PUV3) += puv3_intc.o
 hw-obj-$(CONFIG_PUV3) += puv3_ost.o
 hw-obj-$(CONFIG_PUV3) += puv3_gpio.o
 hw-obj-$(CONFIG_PUV3) += puv3_pm.o
+hw-obj-$(CONFIG_PUV3) += puv3_dma.o
 
 # PCI watchdog devices
 hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
diff --git a/hw/puv3.c b/hw/puv3.c
index 595aa9e..226a34f 100644
--- a/hw/puv3.c
+++ b/hw/puv3.c
@@ -49,6 +49,7 @@ static void puv3_soc_init(CPUUniCore32State *env)
 
 /* Initialize minimal necessary devices for kernel booting */
 sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL);
+sysbus_create_simple("puv3_dma", PUV3_DMA_BASE, NULL);
 sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]);
 sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE,
 irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],
diff --git a/hw/puv3_dma.c b/hw/puv3_dma.c
new file mode 100644
index 000..c9ec5f5
--- /dev/null
+++ b/hw/puv3_dma.c
@@ -0,0 +1,109 @@
+/*
+ * DMA device simulation in PKUnity SoC
+ *
+ * Copyright (C) 2010-2012 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
+ */
+#include "hw.h"
+#include "sysbus.h"
+
+#undef DEBUG_PUV3
+#include "puv3.h"
+
+#define PUV3_DMA_CH_NR  (6)
+#define PUV3_DMA_CH_MASK(0xff)
+#define PUV3_DMA_CH(offset) ((offset) >> 8)
+
+typedef struct {
+SysBusDevice busdev;
+MemoryRegion iomem;
+uint32_t reg_CFG[PUV3_DMA_CH_NR];
+} puv3_dma_t;
+
+static uint64_t puv3_dma_read(void *opaque, target_phys_addr_t offset,
+unsigned size)
+{
+puv3_dma_t *s = (puv3_dma_t *) opaque;
+uint32_t ret;
+
+assert(PUV3_DMA_CH(offset) < PUV3_DMA_CH_NR);
+
+switch (offset & PUV3_DMA_CH_MASK) {
+case 0x10:
+ret = s->reg_CFG[PUV3_DMA_CH(offset)];
+break;
+default:
+hw_error("%s: Bad offset 0x%x\n", __func__, offset);
+}
+DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
+
+return ret;
+}
+
+static void puv3_dma_write(void *opaque, target_phys_addr_t offset,
+uint64_t value, unsigned size)
+{
+puv3_dma_t *s = (puv3_dma_t *) opaque;
+
+assert(PUV3_DMA_CH(offset) < PUV3_DMA_CH_NR);
+
+switch (offset & PUV3_DMA_CH_MASK) {
+case 0x10:
+s->reg_CFG[PUV3_DMA_CH(offset)] = value;
+break;
+default:
+hw_error("%s: Bad offset 0x%x\n", __func__, offset);
+}
+DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
+}
+
+static const MemoryRegionOps puv3_dma_ops = {
+.read = puv3_dma_read,
+.write = puv3_dma_write,
+.impl = {
+.min_access_size = 4,
+.max_access_size = 4,
+},
+.endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static int puv3_dma_init(SysBusDevice *dev)
+{
+puv3_dma_t *s = FROM_SYSBUS(puv3_dma_t, dev);
+int i;
+
+for (i = 0; i < PUV3_DMA_CH_NR; i++) {
+s->reg_CFG[i] = 0x0;
+}
+
+memory_region_init_io(&s->iomem, &puv3_dma_ops, s, "puv3_dma",
+PUV3_REGS_OFFSET);
+sysbus_init_mmio(dev, &s->iomem);
+
+return 0;
+}
+
+static void puv3_dma_class_init(ObjectClass *klass, void *data)
+{
+SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+sdc->init = puv3_dma_init;
+}
+
+static TypeInfo puv3_dma_info = {
+.name = "puv3_dma",
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(puv3_dma_t),
+.class_init = puv3_dma_class_init,
+};
+
+static void puv3_dma_register_type(void)
+{
+type_register_static(&puv3_dma_info);
+}
+
+type_init(puv3_dma_register_type)
-- 
1.7.0.4




[Qemu-devel] [PATCHv2 10/13] unicore32-softmmu: Add puv3 pm support

2012-06-15 Thread Guan Xuetao
This patch adds puv3 pm (power management) support,
include pm device simulation for kernel booting.

Signed-off-by: Guan Xuetao 
---
 Makefile.objs |1 +
 hw/puv3.c |1 +
 hw/puv3_pm.c  |  148 +
 3 files changed, 150 insertions(+), 0 deletions(-)
 create mode 100644 hw/puv3_pm.c

diff --git a/Makefile.objs b/Makefile.objs
index d7c63c4..d14a08e 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -278,6 +278,7 @@ hw-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
 hw-obj-$(CONFIG_PUV3) += puv3_intc.o
 hw-obj-$(CONFIG_PUV3) += puv3_ost.o
 hw-obj-$(CONFIG_PUV3) += puv3_gpio.o
+hw-obj-$(CONFIG_PUV3) += puv3_pm.o
 
 # PCI watchdog devices
 hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
diff --git a/hw/puv3.c b/hw/puv3.c
index 453b404..595aa9e 100644
--- a/hw/puv3.c
+++ b/hw/puv3.c
@@ -48,6 +48,7 @@ static void puv3_soc_init(CPUUniCore32State *env)
 }
 
 /* Initialize minimal necessary devices for kernel booting */
+sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL);
 sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]);
 sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE,
 irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],
diff --git a/hw/puv3_pm.c b/hw/puv3_pm.c
new file mode 100644
index 000..d3b646c
--- /dev/null
+++ b/hw/puv3_pm.c
@@ -0,0 +1,148 @@
+/*
+ * Power Management device simulation in PKUnity SoC
+ *
+ * Copyright (C) 2010-2012 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
+ */
+#include "hw.h"
+#include "sysbus.h"
+
+#undef DEBUG_PUV3
+#include "puv3.h"
+
+typedef struct {
+SysBusDevice busdev;
+MemoryRegion iomem;
+
+uint32_t reg_PMCR;
+uint32_t reg_PCGR;
+uint32_t reg_PLL_SYS_CFG;
+uint32_t reg_PLL_DDR_CFG;
+uint32_t reg_PLL_VGA_CFG;
+uint32_t reg_DIVCFG;
+} puv3_pm_t;
+
+static uint64_t puv3_pm_read(void *opaque, target_phys_addr_t offset,
+unsigned size)
+{
+puv3_pm_t *s = (puv3_pm_t *) opaque;
+uint32_t ret;
+
+switch (offset) {
+case 0x14:
+ret = s->reg_PCGR;
+break;
+case 0x18:
+ret = s->reg_PLL_SYS_CFG;
+break;
+case 0x1c:
+ret = s->reg_PLL_DDR_CFG;
+break;
+case 0x20:
+ret = s->reg_PLL_VGA_CFG;
+break;
+case 0x24:
+ret = s->reg_DIVCFG;
+break;
+case 0x28: /* PLL SYS STATUS */
+ret = 0x2401;
+break;
+case 0x2c: /* PLL DDR STATUS */
+ret = 0x00100c00;
+break;
+case 0x30: /* PLL VGA STATUS */
+ret = 0x3801;
+break;
+case 0x34: /* DIV STATUS */
+ret = 0x22f52015;
+break;
+case 0x38: /* SW RESET */
+ret = 0x0;
+break;
+case 0x44: /* PLL DFC DONE */
+ret = 0x7;
+break;
+default:
+hw_error("%s: Bad offset 0x%x\n", __func__, offset);
+}
+DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
+
+return ret;
+}
+
+static void puv3_pm_write(void *opaque, target_phys_addr_t offset,
+uint64_t value, unsigned size)
+{
+puv3_pm_t *s = (puv3_pm_t *) opaque;
+
+switch (offset) {
+case 0x0:
+s->reg_PMCR = value;
+case 0x14:
+s->reg_PCGR = value;
+break;
+case 0x18:
+s->reg_PLL_SYS_CFG = value;
+break;
+case 0x1c:
+s->reg_PLL_DDR_CFG = value;
+break;
+case 0x20:
+s->reg_PLL_VGA_CFG = value;
+break;
+case 0x24:
+case 0x38:
+break;
+default:
+hw_error("%s: Bad offset 0x%x\n", __func__, offset);
+}
+DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
+}
+
+static const MemoryRegionOps puv3_pm_ops = {
+.read = puv3_pm_read,
+.write = puv3_pm_write,
+.impl = {
+.min_access_size = 4,
+.max_access_size = 4,
+},
+.endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static int puv3_pm_init(SysBusDevice *dev)
+{
+puv3_pm_t *s = FROM_SYSBUS(puv3_pm_t, dev);
+
+s->reg_PCGR = 0x0;
+
+memory_region_init_io(&s->iomem, &puv3_pm_ops, s, "puv3_pm",
+PUV3_REGS_OFFSET);
+sysbus_init_mmio(dev, &s->iomem);
+
+return 0;
+}
+
+static void puv3_pm_class_init(ObjectClass *klass, void *data)
+{
+SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+sdc->init = puv3_pm_init;
+}
+
+static TypeInfo puv3_pm_info = {
+.name = "puv3_pm",
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(puv3_pm_t),
+.class_init = puv3_pm_class_init,
+};
+
+static void puv3_pm_register_type(void)
+{
+type_register_static(&puv3_pm_info);
+}
+
+type_init(puv3_pm_register_type)
-- 
1.7.0.4




[Qemu-devel] [PATCHv2 05/13] unicore32-softmmu: Make sure that kernel can access user space

2012-06-15 Thread Guan Xuetao
As a matter of course, we need to access user space in kernel code,
so we need to correct load/store decoders to indicate correct memory
region.

Signed-off-by: Guan Xuetao 
---
 target-unicore32/translate.c |   36 ++--
 1 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/target-unicore32/translate.c b/target-unicore32/translate.c
index fd51a61..43317a6 100644
--- a/target-unicore32/translate.c
+++ b/target-unicore32/translate.c
@@ -33,9 +33,16 @@ typedef struct DisasContext {
 int condlabel;
 struct TranslationBlock *tb;
 int singlestep_enabled;
+#ifndef CONFIG_USER_ONLY
+int user;
+#endif
 } DisasContext;
 
-#define IS_USER(s) 1
+#ifndef CONFIG_USER_ONLY
+#define IS_USER(s)  (s->user)
+#else
+#define IS_USER(s)  1
+#endif
 
 /* These instructions trap after executing, so defer them until after the
conditional executions state has been updated.  */
@@ -1551,12 +1558,12 @@ static void do_misc(CPUUniCore32State *env, 
DisasContext *s, uint32_t insn)
 /* load/store I_offset and R_offset */
 static void do_ldst_ir(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
 {
-unsigned int i;
+unsigned int mmuindex;
 TCGv tmp;
 TCGv tmp2;
 
 tmp2 = load_reg(s, UCOP_REG_N);
-i = (IS_USER(s) || (!UCOP_SET_P && UCOP_SET_W));
+mmuindex = (IS_USER(s) || (!UCOP_SET_P && UCOP_SET_W));
 
 /* immediate */
 if (UCOP_SET_P) {
@@ -1566,17 +1573,17 @@ static void do_ldst_ir(CPUUniCore32State *env, 
DisasContext *s, uint32_t insn)
 if (UCOP_SET_L) {
 /* load */
 if (UCOP_SET_B) {
-tmp = gen_ld8u(tmp2, i);
+tmp = gen_ld8u(tmp2, mmuindex);
 } else {
-tmp = gen_ld32(tmp2, i);
+tmp = gen_ld32(tmp2, mmuindex);
 }
 } else {
 /* store */
 tmp = load_reg(s, UCOP_REG_D);
 if (UCOP_SET_B) {
-gen_st8(tmp, tmp2, i);
+gen_st8(tmp, tmp2, mmuindex);
 } else {
-gen_st32(tmp, tmp2, i);
+gen_st32(tmp, tmp2, mmuindex);
 }
 }
 if (!UCOP_SET_P) {
@@ -1679,7 +1686,7 @@ static void do_ldst_hwsb(CPUUniCore32State *env, 
DisasContext *s, uint32_t insn)
 /* load/store multiple words */
 static void do_ldst_m(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
 {
-unsigned int val, i;
+unsigned int val, i, mmuindex;
 int j, n, reg, user, loaded_base;
 TCGv tmp;
 TCGv tmp2;
@@ -1700,6 +1707,7 @@ static void do_ldst_m(CPUUniCore32State *env, 
DisasContext *s, uint32_t insn)
 }
 }
 
+mmuindex = (IS_USER(s) || (!UCOP_SET_P && UCOP_SET_W));
 addr = load_reg(s, UCOP_REG_N);
 
 /* compute total size */
@@ -1744,7 +1752,7 @@ static void do_ldst_m(CPUUniCore32State *env, 
DisasContext *s, uint32_t insn)
 }
 if (UCOP_SET(i)) {
 if (UCOP_SET_L) { /* load */
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = gen_ld32(addr, mmuindex);
 if (reg == 31) {
 gen_bx(s, tmp);
 } else if (user) {
@@ -1772,7 +1780,7 @@ static void do_ldst_m(CPUUniCore32State *env, 
DisasContext *s, uint32_t insn)
 } else {
 tmp = load_reg(s, reg);
 }
-gen_st32(tmp, addr, IS_USER(s));
+gen_st32(tmp, addr, mmuindex);
 }
 j++;
 /* no need to add after the last transfer */
@@ -1961,6 +1969,14 @@ static inline void 
gen_intermediate_code_internal(CPUUniCore32State *env,
 max_insns = CF_COUNT_MASK;
 }
 
+#ifndef CONFIG_USER_ONLY
+if ((env->uncached_asr & ASR_M) == ASR_MODE_USER) {
+dc->user = 1;
+} else {
+dc->user = 0;
+}
+#endif
+
 gen_icount_start();
 do {
 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
-- 
1.7.0.4




[Qemu-devel] [PATCHv2 07/13] unicore32-softmmu: Add puv3 interrupt support

2012-06-15 Thread Guan Xuetao
This patch adds puv3 interrupt support, include interrupt controler
device simulation and interrupt handler in puv3 machine.

Signed-off-by: Guan Xuetao 
---
 Makefile.objs  |3 +
 hw/puv3.c  |   23 +-
 hw/puv3_intc.c |  135 
 3 files changed, 160 insertions(+), 1 deletions(-)
 create mode 100644 hw/puv3_intc.c

diff --git a/Makefile.objs b/Makefile.objs
index 70c5c79..37bd3d4 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -274,6 +274,9 @@ hw-obj-$(CONFIG_PIIX4) += piix4.o
 hw-obj-$(CONFIG_G364FB) += g364fb.o
 hw-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
 
+# PKUnity SoC devices
+hw-obj-$(CONFIG_PUV3) += puv3_intc.o
+
 # PCI watchdog devices
 hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
 
diff --git a/hw/puv3.c b/hw/puv3.c
index 90231d4..7b0cfde 100644
--- a/hw/puv3.c
+++ b/hw/puv3.c
@@ -22,9 +22,30 @@
 #define KERNEL_LOAD_ADDR0x0300
 #define KERNEL_MAX_SIZE 0x0080 /* Just a guess */
 
+static void puv3_intc_cpu_handler(void *opaque, int irq, int level)
+{
+CPUUniCore32State *env = (CPUUniCore32State *)opaque;
+
+assert(irq == 0);
+if (level) {
+cpu_interrupt(env, CPU_INTERRUPT_HARD);
+} else {
+cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
+}
+}
+
 static void puv3_soc_init(CPUUniCore32State *env)
 {
-/* TODO */
+qemu_irq *cpu_intc, irqs[PUV3_IRQS_NR];
+DeviceState *dev;
+int i;
+
+/* Initialize interrupt controller */
+cpu_intc = qemu_allocate_irqs(puv3_intc_cpu_handler, env, 1);
+dev = sysbus_create_simple("puv3_intc", PUV3_INTC_BASE, *cpu_intc);
+for (i = 0; i < PUV3_IRQS_NR; i++) {
+irqs[i] = qdev_get_gpio_in(dev, i);
+}
 }
 
 static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size)
diff --git a/hw/puv3_intc.c b/hw/puv3_intc.c
new file mode 100644
index 000..15de9d0
--- /dev/null
+++ b/hw/puv3_intc.c
@@ -0,0 +1,135 @@
+/*
+ * INTC device simulation in PKUnity SoC
+ *
+ * Copyright (C) 2010-2012 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation, or any later version.
+ * See the COPYING file in the top-level directory.
+ */
+#include "sysbus.h"
+
+#undef DEBUG_PUV3
+#include "puv3.h"
+
+typedef struct puv3_intc_t {
+SysBusDevice busdev;
+MemoryRegion iomem;
+qemu_irq parent_irq;
+
+uint32_t reg_ICMR;
+uint32_t reg_ICPR;
+} puv3_intc_t;
+
+/* Update interrupt status after enabled or pending bits have been changed.  */
+static void puv3_intc_update(puv3_intc_t *s)
+{
+if (s->reg_ICMR & s->reg_ICPR) {
+qemu_irq_raise(s->parent_irq);
+} else {
+qemu_irq_lower(s->parent_irq);
+}
+}
+
+/* Process a change in an external INTC input. */
+static void puv3_intc_handler(void *opaque, int irq, int level)
+{
+puv3_intc_t *s = (puv3_intc_t *)opaque;
+
+DPRINTF("irq 0x%x, level 0x%x\n", irq, level);
+if (level) {
+s->reg_ICPR |= (1 << irq);
+} else {
+s->reg_ICPR &= ~(1 << irq);
+}
+puv3_intc_update(s);
+}
+
+static uint64_t puv3_intc_read(void *opaque, target_phys_addr_t offset,
+unsigned size)
+{
+puv3_intc_t *s = (puv3_intc_t *)opaque;
+uint32_t ret = 0;
+
+switch (offset) {
+case 0x04: /* INTC_ICMR */
+ret = s->reg_ICMR;
+break;
+case 0x0c: /* INTC_ICIP */
+ret = s->reg_ICPR; /* the same value with ICPR */
+break;
+default:
+hw_error("puv3_intc_read: Bad offset %x\n", (int)offset);
+}
+DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
+return ret;
+}
+
+static void puv3_intc_write(void *opaque, target_phys_addr_t offset,
+uint64_t value, unsigned size)
+{
+puv3_intc_t *s = (puv3_intc_t *)opaque;
+
+DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
+switch (offset) {
+case 0x00: /* INTC_ICLR */
+case 0x14: /* INTC_ICCR */
+break;
+case 0x04: /* INTC_ICMR */
+s->reg_ICMR = value;
+break;
+default:
+hw_error("puv3_intc_write: Bad offset 0x%x\n", (int)offset);
+return;
+}
+puv3_intc_update(s);
+}
+
+static const MemoryRegionOps puv3_intc_ops = {
+.read = puv3_intc_read,
+.write = puv3_intc_write,
+.impl = {
+.min_access_size = 4,
+.max_access_size = 4,
+},
+.endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static int puv3_intc_init(SysBusDevice *dev)
+{
+puv3_intc_t *s = FROM_SYSBUS(puv3_intc_t, dev);
+
+qdev_init_gpio_in(&s->busdev.qdev, puv3_intc_handler, PUV3_IRQS_NR);
+sysbus_init_irq(&s->busdev, &s->parent_irq);
+
+s->reg_ICMR = 0;
+s->reg_ICPR = 0;
+
+memory_region_init_io(&s->iomem, &puv3_intc_ops, s, "puv3_intc",
+PUV3_REGS_OFFSET);
+sysbus_init_mmio(dev, &s->iomem);
+
+return 0;
+}
+
+static void puv3_intc_class_init(ObjectClass *klass, void *dat

Re: [Qemu-devel] [PATCH V13 0/9] Xen PCI Passthrough

2012-06-15 Thread Stefano Stabellini
On Thu, 14 Jun 2012, Michael S. Tsirkin wrote:
> On Thu, Jun 14, 2012 at 06:01:40PM +0100, Anthony PERARD wrote:
> > Hi all,
> > 
> > This patch series introduces the PCI passthrough for Xen.
> > 
> > Changes since the last version:
> >   - New patch that introduce a new qdev-property pci-host-devaddr.
> >   => the "export pci_parse_devaddr" patch is not anymore usefull.
> > 
> > Thanks,
> 
> I reviewed some patches and Acked. Won't have the time to
> review the rest of the series short term.
> If you need me to merge some of these patches myself
> pls let me know.

Considering that you Acked all the non-Xen patches (apart from the
configure patch), I think I'll just go ahead and submit a pull request
to Anthony myself, if you are OK with it.



Re: [Qemu-devel] [PATCH 1/1] Add usb option in machine options.

2012-06-15 Thread Andreas Färber
Am 15.06.2012 05:06, schrieb Li Zhang:
> 
> 
> On Thu, Jun 14, 2012 at 10:27 PM, Andreas Färber  > wrote:
> 
> Am 14.06.2012 07:17, schrieb zhlci...@gmail.com
> :
> > From: Li Zhang  >
> >
> > For pseries machine, it needs to enable usb
> > to add kbd or usb mouse. -usb option won't
> > be used in the future, and machine options
> > is a better way to enable usb.
> >
> > So this patch is to add usb option to machine
> > options (-machine type=psereis,usb=on/off)
> > to enable/disable usb controller.
> >
> > In this patch, usb_opt is an global option
> > which can be checked by machines. For example,
> > on pseries, it will check if usb_opt is on, if
> > it is on, it will create one usb ohci controller.
> > As the following:
> > if (usb_opts && strcmp(usb_opts, "on") == 0)
> >  pci_create_simple(bus, -1, "pci-ohci");
> >
> > In this patch, usb is on by default.
> > So, for -nodefault, usb should be set off in the
> > command line as the following:
> >  -machine type=pseries,usb=off.
> >
> > Signed-off-by: Li Zhang  >
> > reviewed-by:   Anthony Liguori  >
> > reviewed-by:   Benjamin Herrenschmidt  >
> > ---
> >  qemu-config.c |4 
> >  sysemu.h  |1 +
> >  vl.c  |   12 
> >  3 files changed, 17 insertions(+)
> >
> > diff --git a/qemu-config.c b/qemu-config.c
> > index bb3bff4..258712a 100644
> > --- a/qemu-config.c
> > +++ b/qemu-config.c
> > @@ -583,6 +583,10 @@ static QemuOptsList qemu_machine_opts = {
> >  .name = "dtb",
> >  .type = QEMU_OPT_STRING,
> >  .help = "Linux kernel device tree file",
> > +}, {
> > +.name = "usb",
> > +.type = QEMU_OPT_BOOL,
> > +.help = "Set on/off to enable/disable usb",
> >  },
> >  { /* End of list */ }
> >  },
> > diff --git a/sysemu.h b/sysemu.h
> > index bc2c788..c5ea10d 100644
> > --- a/sysemu.h
> > +++ b/sysemu.h
> > @@ -13,6 +13,7 @@
> >  /* vl.c */
> >
> >  extern const char *bios_name;
> > +extern const char *usb_opt;
> >
> >  extern const char *qemu_name;
> >  extern uint8_t qemu_uuid[];
> > diff --git a/vl.c b/vl.c
> > index 204d85b..10f8e4c 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -171,6 +171,7 @@ int main(int argc, char **argv)
> >
> >  static const char *data_dir;
> >  const char *bios_name = NULL;
> > +const char *usb_opt = NULL;
> >  enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
> >  DisplayType display_type = DT_DEFAULT;
> >  int display_remote = 0;

[...]

> The point of using machine options is so that you can use the QemuOpts
> infrastructure to inquire this value, not to save more global state.
> 
> OK, I think it still needs one global value because other machines need
> to check whether usb is enabled.
>  
> 
> Especially not a string when all you want is a boolean value.
> 
> From the qemu, QEMU_OPT_BOOL type  still use a string
> "on/off" to enable/disable usb.
> Maybe it's better to convert it to boolean value. 
> 
> Further, in this patch it's only being assigned, not used anywhere.
> 
> In vl.c, it seems that it is not used.  
> I have been thinking to use it in spapr.c. 
> 
> if (usb_opts && strcmp(usb_opts, "on") == 0)
> pci_create_simple(bus, -1, "pci-ohci");
> 
> But I want to see whether this way is accepted. 
> If it is ok, I will add this option to spapr.c.  

First, please don't reply with HTML mails, it breaks the quoting as you
can see.

You don't seem to be getting what I'm saying: As discussed in great
lengths for how to access a passed-in device tree for ARM, the code
checking this option (i.e., in spapr.c) is expected to call
qemu_opt_get() itself, instead of saving its value globally in vl.c. For
example:

machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
usb_opt = qemu_opt_get(machine_opts, "usb");
if (strcmp(usb_opt, "off") != 0) {
// set up OHCI
}

with appropriate NULL checks left as exercise for the reader.

So you should combine the definition of the option in qemu-config.c
(which looks okay) with its actual use in hw/spapr.c in one patch.

Once introduced, hw/ppc_newworld.c should be updated to check the new
option as well, but that can be a follow-up patch.

Regards,
Andreas

> > @@ -758,6 +759,15 @@ static int bt_parse(const char *opt)
> >  return 1;
> >  }
> >
> > +static int default_enable_usb(QemuOpts *opts)
> > +{
> > +if (NULL == qemu_opt_get(opts, "usb")) {
> > +qemu_opt_set(opts, "usb", "on");

Re: [Qemu-devel] [PATCH 0/3] xilinx: Speed up the build

2012-06-15 Thread Edgar E. Iglesias
On Sat, Jun 09, 2012 at 03:54:28AM +0200, Andreas Färber wrote:
> Hello Edgar and Peter,
> 
> With the Makefile refactoring applied now, here's the Makefile improvements
> for MicroBlaze I mentioned.
> 
> All Xilinx devices that are used for more than one softmmu are compiled once
> in libhw32. Actually some also in libhw64 due to ppc440 being compiled into
> ppc64, but we can fix that in a second step via Alex' ppc-next, we're already
> down from thrice to twice.
> 
> The middle patch is extracted from Blue's logging refactoring.
> 
> Please test and apply. Your s3adp1800 and virtel_ml507 test images complain
> both with and without patches about not finding "eth0". Selftest completes ok
> except for not finding /usr/bin/sha1test on ppc440.
> 
> xilinx_ethlite.c uses tswap32(). Have you ever tested this device to work on
> microblazeel? I wonder if we could change the device from DEVICE_NATIVE_ENDIAN
> to DEVICE_BIG_ENDIAN and in place of tswap32() use a bswap32() conditional on
> HOST_WORDS_BIGENDIAN so that it becomes independent of the target, too?
> 
> Instead of adding random devices to hw/microblaze/Makefile.objs in new series,
> they should be added to hw/Makefile.objs with appropriate CONFIG_* options set
> in default-configs/microblaze[el]-softmmu.mak as demonstrated here, easy to do
> and also ensures that the appropriate poisoning is applied.

Applied the series, thanks Andreas.


> 
> Regards,
> Andreas
> 
> Cc: Edgar E. Iglesias 
> Cc: Peter A. G. Crosthwaite 
> Cc: Alexander Graf 
> Cc: Blue Swirl 
> 
> Andreas Färber (3):
>   hw/xilinx_*: Share Xilinx devices between ppc and microblaze
>   qemu-log: Allow usage in libhw
>   xilinx_axi*: Share devices between microblaze and microblazeel
> 
>  default-configs/microblaze-softmmu.mak   |2 ++
>  default-configs/microblazeel-softmmu.mak |2 ++
>  default-configs/ppc-softmmu.mak  |1 +
>  default-configs/ppc64-softmmu.mak|1 +
>  default-configs/ppcemb-softmmu.mak   |1 +
>  hw/Makefile.objs |7 +++
>  hw/microblaze/Makefile.objs  |5 -
>  hw/ppc/Makefile.objs |3 ---
>  qemu-log.h   |2 ++
>  9 files changed, 16 insertions(+), 8 deletions(-)
> 
> -- 
> 1.7.7
> 



Re: [Qemu-devel] [PATCHv2 02/13] unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction support

2012-06-15 Thread Andreas Färber
Am 15.06.2012 11:47, schrieb Guan Xuetao:
> Coprocessor 0 is system control coprocessor, and we need get/set its contents.
> Also, all cache/tlb ops shoule be implemented here, but just ignored with no 
> harm.
> 
> Coprocessor 1 is OCD (on-chip-debugger), which is used for faked console,
> so we could output chars to this console without graphic card.
> 
> Signed-off-by: Guan Xuetao 
> ---
>  target-unicore32/helper.c|  185 
> --
>  target-unicore32/helper.h|   15 ++--
>  target-unicore32/translate.c |   75 +-
>  3 files changed, 223 insertions(+), 52 deletions(-)
> 
> diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
> index 17d9b41..f58a5af 100644
> --- a/target-unicore32/helper.c
> +++ b/target-unicore32/helper.c
> @@ -1,12 +1,10 @@
>  /*
> - * Copyright (C) 2010-2011 GUAN Xue-tao
> + * Copyright (C) 2010-2012 Guan Xuetao
>   *
>   * This program is free software; you can redistribute it and/or modify
>   * it under the terms of the GNU General Public License version 2 as
> - * published by the Free Software Foundation.
> - *
> - * Contributions from 2012-04-01 on are considered under GPL version 2,
> - * or (at your option) any later version.
> + * published by the Free Software Foundation, or any later version.
> + * See the COPYING file in the top-level directory.
>   */

NACK. You can't just change the license here since IBM haven't agreed to
relicense their contribution yet. Thought we explained that already?

Anthony, any news on that matter?

Andreas

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



Re: [Qemu-devel] [PATCH v2 00/11] Xilinx Devs: refactored device and property names

2012-06-15 Thread Edgar E. Iglesias
On Wed, Jun 13, 2012 at 02:46:40PM +1000, Peter A. G. Crosthwaite wrote:
> Refactored the device and property names of the Xilinx IP models to match 
> those used by Xilinx in their tools.
> 
> This lays the groundwork for creating Xilinx IP machines from Xilinx 
> generated sources (using -readconfig or -device arguments or dtb driven 
> machine creation) without having to provide a translation layer to change 
> from Xilinx names to QEMU names.
> 

Applied all, thanks Peter.


> Peter A. G. Crosthwaite (11):
>   xilinx_uartlite: changed device name
>   xilinx_timer: added default frequency
>   xilinx_timer: changed nr_timers to one_timer_only
>   xilinx_timer: changed device name
>   xilinx_intc: changed device name
>   xilinx_ethlite: tweaked naming of ping-pong props
>   xilinx_ethlite: changed device name
>   xilinx_axienet: droped the c_ on parameters
>   xilinx_axienet: changed device name
>   xilinx_axidma: (un)reversed irq initialisation
>   xilinx_axidma: changed device name
> 
>  hw/petalogix_ml605_mmu.c  |2 +-
>  hw/petalogix_s3adsp1800_mmu.c |4 ++--
>  hw/virtex_ml507.c |2 +-
>  hw/xilinx.h   |   30 +++---
>  hw/xilinx_axidma.c|6 +++---
>  hw/xilinx_axienet.c   |6 +++---
>  hw/xilinx_ethlite.c   |9 +
>  hw/xilinx_intc.c  |4 ++--
>  hw/xilinx_timer.c |   23 ++-
>  hw/xilinx_uartlite.c  |5 +++--
>  10 files changed, 49 insertions(+), 42 deletions(-)
> 
> -- 
> 1.7.3.2
> 



[Qemu-devel] [PATCH 2/2] xenstore: Use

2012-06-15 Thread Anthony PERARD
In the next release of Xen (4.2), xs.h became deprecated.

Signed-off-by: Anthony PERARD 
---
 configure   |2 +-
 hw/xen_common.h |6 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index c2366ee..e7f66c9 100755
--- a/configure
+++ b/configure
@@ -1382,7 +1382,7 @@ EOF
   elif (
   cat > $TMPC <
-#include 
+#include 
 #include 
 #include 
 #if !defined(HVM_MAX_VCPUS)
diff --git a/hw/xen_common.h b/hw/xen_common.h
index fe7f227..cc99204 100644
--- a/hw/xen_common.h
+++ b/hw/xen_common.h
@@ -7,7 +7,11 @@
 #include 
 
 #include 
-#include 
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
+#  include 
+#else
+#  include 
+#endif
 #include 
 
 #include "hw.h"
-- 
Anthony PERARD




[Qemu-devel] [PATCH 1/2] xen: Reorganize includes of Xen headers.

2012-06-15 Thread Anthony PERARD
Because xs.h will be remove in future release of Xen, this patch removes the
extra includes of this headers.

Also, it removes the extra includes of xenctrl.h and xen/io/xenbus.h as there
already are in xen_common.h.

Signed-off-by: Anthony PERARD 
---
 hw/xen_backend.c |6 ++
 hw/xen_console.c |5 ++---
 hw/xen_disk.c|6 +-
 hw/xen_nic.c |7 ++-
 hw/xenfb.c   |   13 +
 5 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/hw/xen_backend.c b/hw/xen_backend.c
index 66cb144..f83a1e1 100644
--- a/hw/xen_backend.c
+++ b/hw/xen_backend.c
@@ -34,15 +34,13 @@
 #include 
 #include 
 
-#include 
-#include 
-#include 
-
 #include "hw.h"
 #include "qemu-char.h"
 #include "qemu-log.h"
 #include "xen_backend.h"
 
+#include 
+
 /* - */
 
 /* public */
diff --git a/hw/xen_console.c b/hw/xen_console.c
index 3794b19..9426d73 100644
--- a/hw/xen_console.c
+++ b/hw/xen_console.c
@@ -28,14 +28,13 @@
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
 
 #include "hw.h"
 #include "qemu-char.h"
 #include "xen_backend.h"
 
+#include 
+
 struct buffer {
 uint8_t *data;
 size_t consumed;
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index de7e8a4..48f99c6 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -35,15 +35,11 @@
 #include 
 #include 
 
-#include 
-#include 
-#include 
-
 #include "hw.h"
 #include "block_int.h"
 #include "qemu-char.h"
-#include "xen_blkif.h"
 #include "xen_backend.h"
+#include "xen_blkif.h"
 #include "blockdev.h"
 
 /* - */
diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 9a59bda..98db9bb 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -35,11 +35,6 @@
 #include 
 #include 
 
-#include 
-#include 
-#include 
-#include 
-
 #include "hw.h"
 #include "net.h"
 #include "net/checksum.h"
@@ -47,6 +42,8 @@
 #include "qemu-char.h"
 #include "xen_backend.h"
 
+#include 
+
 /* - */
 
 struct XenNetDev {
diff --git a/hw/xenfb.c b/hw/xenfb.c
index 1bcf171..338800a 100644
--- a/hw/xenfb.c
+++ b/hw/xenfb.c
@@ -35,19 +35,16 @@
 #include 
 #include 
 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include "hw.h"
 #include "console.h"
 #include "qemu-char.h"
 #include "xen_backend.h"
 
+#include 
+#include 
+#include 
+#include 
+
 #ifndef BTN_LEFT
 #define BTN_LEFT 0x110 /* from  */
 #endif
-- 
Anthony PERARD




[Qemu-devel] [PATCH 0/2] xen: Deprecation of .

2012-06-15 Thread Anthony PERARD
Considering that  will be deprecated in the next release of Xen, this two
patches clean a bit the inclusion of xs.h and changes it in a single place.

Anthony PERARD (2):
  xen: Reorganize includes of Xen headers.
  xenstore: Use 

 configure|2 +-
 hw/xen_backend.c |6 ++
 hw/xen_common.h  |6 +-
 hw/xen_console.c |5 ++---
 hw/xen_disk.c|6 +-
 hw/xen_nic.c |7 ++-
 hw/xenfb.c   |   13 +
 7 files changed, 18 insertions(+), 27 deletions(-)

-- 
Anthony PERARD




Re: [Qemu-devel] libguestfs now uses virtio-scsi, supports large numbers of disks

2012-06-15 Thread Richard W.M. Jones
On Fri, Jun 15, 2012 at 11:44:42AM +0100, Stefan Hajnoczi wrote:
> On Thu, Jun 14, 2012 at 2:49 PM, Richard W.M. Jones  wrote:
> > I switched libguestfs over to using virtio-scsi.  One immediate
> > benefit is support for large numbers of disks: up to 255 because we're
> > using 1 target / disk and we reserve one disk for the appliance, in
> > theory more could be supported if we used LUNs.
> 
> Cool, thanks for sharing!  Does libguestfs hotplug LUNS/targets?

Not quite, but in the near future it will.  It's something I'm aiming
to have working for RHEL 7.

> Cong and Wan Seng are implementing guest driver and QEMU-side changes
> so the guest receives notifications of hotplugged LUNs.  It's nicer
> than manually rescanning the bus from inside the guest.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora



Re: [Qemu-devel] [PATCH] cris: Fix NMI-flag handling on crisv10.

2012-06-15 Thread Edgar E. Iglesias
On Thu, Jun 14, 2012 at 04:23:55PM +0200, Lars Persson wrote:
> - The M-flag is encoded in different bits on cris v10 and cris v32.

I applied this with a small change to remove an accidental tab from
cpu-exec.c

Thanks Lars.



> 
> Signed-off-by: Lars Persson 
> ---
>  cpu-exec.c  |   17 -
>  target-cris/cpu.h   |3 ++-
>  target-cris/helper.c|4 ++--
>  target-cris/op_helper.c |4 ++--
>  4 files changed, 18 insertions(+), 10 deletions(-)
> 
> diff --git a/cpu-exec.c b/cpu-exec.c
> index 83cac93..ce4718f 100644
> --- a/cpu-exec.c
> +++ b/cpu-exec.c
> @@ -467,11 +467,18 @@ int cpu_exec(CPUArchState *env)
>  do_interrupt(env);
>  next_tb = 0;
>  }
> -if (interrupt_request & CPU_INTERRUPT_NMI
> -&& (env->pregs[PR_CCS] & M_FLAG)) {
> -env->exception_index = EXCP_NMI;
> -do_interrupt(env);
> -next_tb = 0;
> +if (interrupt_request & CPU_INTERRUPT_NMI) {
> +unsigned int m_flag_archval;
> +if (env->pregs[PR_VR] < 32) {
> +m_flag_archval = M_FLAG_V10;
> +} else {
> +m_flag_archval = M_FLAG_V32;
> +}
> +if ((env->pregs[PR_CCS] & m_flag_archval)) {
> +env->exception_index = EXCP_NMI;
> +do_interrupt(env);
> +next_tb = 0;
> + }
>  }
>  #elif defined(TARGET_M68K)
>  if (interrupt_request & CPU_INTERRUPT_HARD
> diff --git a/target-cris/cpu.h b/target-cris/cpu.h
> index 73004af..4f4df6d 100644
> --- a/target-cris/cpu.h
> +++ b/target-cris/cpu.h
> @@ -69,13 +69,14 @@
>  
>  /* CPU flags.  */
>  #define Q_FLAG 0x8000
> -#define M_FLAG 0x4000
> +#define M_FLAG_V32 0x4000
>  #define PFIX_FLAG 0x800  /* CRISv10 Only.  */
>  #define F_FLAG_V10 0x400
>  #define P_FLAG_V10 0x200
>  #define S_FLAG 0x200
>  #define R_FLAG 0x100
>  #define P_FLAG 0x80
> +#define M_FLAG_V10 0x80
>  #define U_FLAG 0x40
>  #define I_FLAG 0x20
>  #define X_FLAG 0x10
> diff --git a/target-cris/helper.c b/target-cris/helper.c
> index dcc19ef..bfbc29e 100644
> --- a/target-cris/helper.c
> +++ b/target-cris/helper.c
> @@ -127,7 +127,7 @@ static void do_interruptv10(CPUCRISState *env)
>   case EXCP_NMI:
>   /* NMI is hardwired to vector zero.  */
>   ex_vec = 0;
> - env->pregs[PR_CCS] &= ~M_FLAG;
> + env->pregs[PR_CCS] &= ~M_FLAG_V10;
>   env->pregs[PRV10_BRP] = env->pc;
>   break;
>  
> @@ -185,7 +185,7 @@ void do_interrupt(CPUCRISState *env)
>   case EXCP_NMI:
>   /* NMI is hardwired to vector zero.  */
>   ex_vec = 0;
> - env->pregs[PR_CCS] &= ~M_FLAG;
> + env->pregs[PR_CCS] &= ~M_FLAG_V32;
>   env->pregs[PR_NRP] = env->pc;
>   break;
>  
> diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c
> index b92c106..ac7c98c 100644
> --- a/target-cris/op_helper.c
> +++ b/target-cris/op_helper.c
> @@ -247,8 +247,8 @@ void helper_rfn(void)
>   if (!rflag)
>   env->pregs[PR_CCS] |= P_FLAG;
>  
> -/* Always set the M flag.  */
> -env->pregs[PR_CCS] |= M_FLAG;
> + /* Always set the M flag.  */
> + env->pregs[PR_CCS] |= M_FLAG_V32;
>  }
>  
>  uint32_t helper_lz(uint32_t t0)
> -- 
> 1.7.2.5
> 



Re: [Qemu-devel] [PATCH v2 09/11] xilinx_axienet: changed device name

2012-06-15 Thread Andreas Färber
Am 13.06.2012 06:46, schrieb Peter A. G. Crosthwaite:
> Changed device name to xlnx,axi-ethernet. This is the exact name of the
> device in the xilinx EDK development tools.
> 
> Signed-off-by: Peter A. G. Crosthwaite 

Commit message doesn't match the change. Which one is right?

/-F

> ---
>  hw/xilinx.h |4 ++--
>  hw/xilinx_axienet.c |2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/xilinx.h b/hw/xilinx.h
> index 5108cf5..52fce01 100644
> --- a/hw/xilinx.h
> +++ b/hw/xilinx.h
> @@ -54,9 +54,9 @@ xilinx_axiethernet_create(void *dmach,
>int txmem, int rxmem)
>  {
>  DeviceState *dev;
> -qemu_check_nic_model(nd, "xilinx-axienet");
> +qemu_check_nic_model(nd, "xlnx.axi-ethernet");
>  
> -dev = qdev_create(NULL, "xilinx,axienet");
> +dev = qdev_create(NULL, "xlnx.axi-ethernet");
>  qdev_set_nic_properties(dev, nd);
>  qdev_prop_set_uint32(dev, "rxmem", rxmem);
>  qdev_prop_set_uint32(dev, "txmem", txmem);
> diff --git a/hw/xilinx_axienet.c b/hw/xilinx_axienet.c
> index d383aee..2e8d8a5 100644
> --- a/hw/xilinx_axienet.c
> +++ b/hw/xilinx_axienet.c
> @@ -889,7 +889,7 @@ static void xilinx_enet_class_init(ObjectClass *klass, 
> void *data)
>  }
>  
>  static TypeInfo xilinx_enet_info = {
> -.name  = "xilinx,axienet",
> +.name  = "xlnx.axi-ethernet",
>  .parent= TYPE_SYS_BUS_DEVICE,
>  .instance_size = sizeof(struct XilinxAXIEnet),
>  .class_init= xilinx_enet_class_init,

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



Re: [Qemu-devel] [PATCH v2 11/11] xilinx_axidma: changed device name

2012-06-15 Thread Andreas Färber
Am 13.06.2012 06:46, schrieb Peter A. G. Crosthwaite:
> Changed device name to xlnx,axi-dma. This is the exact name of the device in 
> the
> Xilinx EDK development tools.
> 
> Signed-off-by: Peter A. G. Crosthwaite 

Same here. Please review more carefully.

/-F

> ---
>  hw/xilinx.h|2 +-
>  hw/xilinx_axidma.c |4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/xilinx.h b/hw/xilinx.h
> index 8f915b4..7df21eb 100644
> --- a/hw/xilinx.h
> +++ b/hw/xilinx.h
> @@ -75,7 +75,7 @@ xilinx_axiethernetdma_create(void *dmach,
>  {
>  DeviceState *dev = NULL;
>  
> -dev = qdev_create(NULL, "xilinx,axidma");
> +dev = qdev_create(NULL, "xlnx.axi-dma");
>  qdev_prop_set_uint32(dev, "freqhz", freqhz);
>  qdev_prop_set_ptr(dev, "dmach", dmach);
>  qdev_init_nofail(dev);
> diff --git a/hw/xilinx_axidma.c b/hw/xilinx_axidma.c
> index 59373b5..f4bec37 100644
> --- a/hw/xilinx_axidma.c
> +++ b/hw/xilinx_axidma.c
> @@ -473,7 +473,7 @@ static int xilinx_axidma_init(SysBusDevice *dev)
>  xlx_dma_connect_dma(s->dmach, s, axidma_push);
>  
>  memory_region_init_io(&s->iomem, &axidma_ops, s,
> -  "axidma", R_MAX * 4 * 2);
> +  "xlnx.axi-dma", R_MAX * 4 * 2);
>  sysbus_init_mmio(dev, &s->iomem);
>  
>  for (i = 0; i < 2; i++) {
> @@ -502,7 +502,7 @@ static void axidma_class_init(ObjectClass *klass, void 
> *data)
>  }
>  
>  static TypeInfo axidma_info = {
> -.name  = "xilinx,axidma",
> +.name  = "xlnx.axi-dma",
>  .parent= TYPE_SYS_BUS_DEVICE,
>  .instance_size = sizeof(struct XilinxAXIDMA),
>  .class_init= axidma_class_init,


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



Re: [Qemu-devel] [PATCH v2 07/11] xilinx_ethlite: changed device name

2012-06-15 Thread Andreas Färber
Am 13.06.2012 06:46, schrieb Peter A. G. Crosthwaite:
> Changed device name to xlnx,xps-ethernetlite. This is the exact name of the
> device in the xilinx EDK development tools.
> 
> Signed-off-by: Peter A. G. Crosthwaite 

Dito.

/-F

> ---
>  hw/xilinx.h |4 ++--
>  hw/xilinx_ethlite.c |5 +++--
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/xilinx.h b/hw/xilinx.h
> index 7776e1b..5f7c5e9 100644
> --- a/hw/xilinx.h
> +++ b/hw/xilinx.h
> @@ -36,9 +36,9 @@ xilinx_ethlite_create(NICInfo *nd, target_phys_addr_t base, 
> qemu_irq irq,
>  {
>  DeviceState *dev;
>  
> -qemu_check_nic_model(nd, "xilinx-ethlite");
> +qemu_check_nic_model(nd, "xlnx.xps-ethernetlite");
>  
> -dev = qdev_create(NULL, "xilinx,ethlite");
> +dev = qdev_create(NULL, "xlnx.xps-ethernetlite");
>  qdev_set_nic_properties(dev, nd);
>  qdev_prop_set_uint32(dev, "tx-ping-pong", txpingpong);
>  qdev_prop_set_uint32(dev, "rx-ping-pong", rxpingpong);
> diff --git a/hw/xilinx_ethlite.c b/hw/xilinx_ethlite.c
> index aa02715..affbb8b 100644
> --- a/hw/xilinx_ethlite.c
> +++ b/hw/xilinx_ethlite.c
> @@ -216,7 +216,8 @@ static int xilinx_ethlite_init(SysBusDevice *dev)
>  sysbus_init_irq(dev, &s->irq);
>  s->rxbuf = 0;
>  
> -memory_region_init_io(&s->mmio, ð_ops, s, "xilinx-ethlite", R_MAX * 
> 4);
> +memory_region_init_io(&s->mmio, ð_ops, s, "xlnx.xps-ethernetlite",
> +R_MAX * 
> 4);
>  sysbus_init_mmio(dev, &s->mmio);
>  
>  qemu_macaddr_default_if_unset(&s->conf.macaddr);
> @@ -243,7 +244,7 @@ static void xilinx_ethlite_class_init(ObjectClass *klass, 
> void *data)
>  }
>  
>  static TypeInfo xilinx_ethlite_info = {
> -.name  = "xilinx,ethlite",
> +.name  = "xlnx.xps-ethernetlite",
>  .parent= TYPE_SYS_BUS_DEVICE,
>  .instance_size = sizeof(struct xlx_ethlite),
>  .class_init= xilinx_ethlite_class_init,


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



Re: [Qemu-devel] [PATCH v2 05/11] xilinx_intc: changed device name

2012-06-15 Thread Andreas Färber
Am 13.06.2012 06:46, schrieb Peter A. G. Crosthwaite:
> Changed device name to xlnx,xps-intc. This is the exact name of the device
> in the xilinx EDK development tools.
> 
> Signed-off-by: Peter A. G. Crosthwaite 

Dito.

/-F

> ---
>  hw/xilinx.h  |2 +-
>  hw/xilinx_intc.c |4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/xilinx.h b/hw/xilinx.h
> index 9ff4c2b..c183e2f 100644
> --- a/hw/xilinx.h
> +++ b/hw/xilinx.h
> @@ -6,7 +6,7 @@ xilinx_intc_create(target_phys_addr_t base, qemu_irq irq, int 
> kind_of_intr)
>  {
>  DeviceState *dev;
>  
> -dev = qdev_create(NULL, "xilinx,intc");
> +dev = qdev_create(NULL, "xlnx.xps-intc");
>  qdev_prop_set_uint32(dev, "kind-of-intr", kind_of_intr);
>  qdev_init_nofail(dev);
>  sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
> diff --git a/hw/xilinx_intc.c b/hw/xilinx_intc.c
> index 553f848..386fd30 100644
> --- a/hw/xilinx_intc.c
> +++ b/hw/xilinx_intc.c
> @@ -156,7 +156,7 @@ static int xilinx_intc_init(SysBusDevice *dev)
>  qdev_init_gpio_in(&dev->qdev, irq_handler, 32);
>  sysbus_init_irq(dev, &p->parent_irq);
>  
> -memory_region_init_io(&p->mmio, &pic_ops, p, "xilinx-pic", R_MAX * 4);
> +memory_region_init_io(&p->mmio, &pic_ops, p, "xlnx.xps-intc", R_MAX * 4);
>  sysbus_init_mmio(dev, &p->mmio);
>  return 0;
>  }
> @@ -176,7 +176,7 @@ static void xilinx_intc_class_init(ObjectClass *klass, 
> void *data)
>  }
>  
>  static TypeInfo xilinx_intc_info = {
> -.name  = "xilinx,intc",
> +.name  = "xlnx.xps-intc",
>  .parent= TYPE_SYS_BUS_DEVICE,
>  .instance_size = sizeof(struct xlx_pic),
>  .class_init= xilinx_intc_class_init,


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



Re: [Qemu-devel] [PATCH v2 01/11] xilinx_uartlite: changed device name

2012-06-15 Thread Andreas Färber
Am 13.06.2012 06:46, schrieb Peter A. G. Crosthwaite:
> Changed device name to xlnx,xps-uartlite. This is the exact name of the device
> in the xilinx EDK development tools.
> 
> Signed-off-by: Peter A. G. Crosthwaite 

Dito.

/-F

> ---
>  hw/petalogix_s3adsp1800_mmu.c |2 +-
>  hw/xilinx_uartlite.c  |5 +++--
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/petalogix_s3adsp1800_mmu.c b/hw/petalogix_s3adsp1800_mmu.c
> index f41c559..7d83c21 100644
> --- a/hw/petalogix_s3adsp1800_mmu.c
> +++ b/hw/petalogix_s3adsp1800_mmu.c
> @@ -104,7 +104,7 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size,
>  irq[i] = qdev_get_gpio_in(dev, i);
>  }
>  
> -sysbus_create_simple("xilinx,uartlite", UARTLITE_BASEADDR, irq[3]);
> +sysbus_create_simple("xlnx.xps-uartlite", UARTLITE_BASEADDR, irq[3]);
>  /* 2 timers at irq 2 @ 62 Mhz.  */
>  xilinx_timer_create(TIMER_BASEADDR, irq[0], 2, 62 * 100);
>  xilinx_ethlite_create(&nd_table[0], ETHLITE_BASEADDR, irq[1], 0, 0);
> diff --git a/hw/xilinx_uartlite.c b/hw/xilinx_uartlite.c
> index aa0170d..d0f32db 100644
> --- a/hw/xilinx_uartlite.c
> +++ b/hw/xilinx_uartlite.c
> @@ -202,7 +202,8 @@ static int xilinx_uartlite_init(SysBusDevice *dev)
>  sysbus_init_irq(dev, &s->irq);
>  
>  uart_update_status(s);
> -memory_region_init_io(&s->mmio, &uart_ops, s, "xilinx-uartlite", R_MAX * 
> 4);
> +memory_region_init_io(&s->mmio, &uart_ops, s, "xlnx.xps-uartlite",
> +R_MAX * 4);
>  sysbus_init_mmio(dev, &s->mmio);
>  
>  s->chr = qemu_char_get_next_serial();
> @@ -219,7 +220,7 @@ static void xilinx_uartlite_class_init(ObjectClass 
> *klass, void *data)
>  }
>  
>  static TypeInfo xilinx_uartlite_info = {
> -.name  = "xilinx,uartlite",
> +.name  = "xlnx.xps-uartlite",
>  .parent= TYPE_SYS_BUS_DEVICE,
>  .instance_size = sizeof (struct xlx_uartlite),
>  .class_init= xilinx_uartlite_class_init,


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



[Qemu-devel] [PATCH] qcow2: Silence false warning

2012-06-15 Thread Kevin Wolf
Some gcc versions seem not to be able to figure out that the switch
statement covers all possible values and that c is therefore always
initialised. Add a default branch for them.

Reported-by: malc 
Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index b663b9f..d7e0e19 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -471,6 +471,8 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t 
offset,
 QCOW_OFLAG_COMPRESSED | QCOW_OFLAG_ZERO);
 *cluster_offset &= L2E_OFFSET_MASK;
 break;
+default:
+abort();
 }
 
 qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
-- 
1.7.6.5




Re: [Qemu-devel] [PATCH 2/2] xenstore: Use

2012-06-15 Thread Juan Quintela
Anthony PERARD  wrote:
> In the next release of Xen (4.2), xs.h became deprecated.
>
> Signed-off-by: Anthony PERARD 
> ---
>  configure   |2 +-
>  hw/xen_common.h |6 +-
>  2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index c2366ee..e7f66c9 100755
> --- a/configure
> +++ b/configure
> @@ -1382,7 +1382,7 @@ EOF
>elif (
>cat > $TMPC <  #include 
> -#include 
> +#include 
>  #include 
>  #include 
>  #if !defined(HVM_MAX_VCPUS)
> diff --git a/hw/xen_common.h b/hw/xen_common.h
> index fe7f227..cc99204 100644
> --- a/hw/xen_common.h
> +++ b/hw/xen_common.h
> @@ -7,7 +7,11 @@
>  #include 
>  
>  #include 
> -#include 
> +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
> +#  include 
> +#else
> +#  include 
> +#endif
>  #include 
>  
>  #include "hw.h"

Shouldn't we need the ifdef also in configure?  On my system xenstore.h
still don't exist.

(master *)$ rpm -qa xen-devel
xen-devel-4.1.2-17.fc17.x86_64
(master *)$ ls /usr/include/xs.h 
/usr/include/xs.h
(master *)$ ls /usr/include/xenstore.h
ls: cannot access /usr/include/xenstore.h: No such file or directory
(master *)$ 


Later, Juan.



Re: [Qemu-devel] [PATCH] qcow2: Silence false warning

2012-06-15 Thread malc
On Fri, 15 Jun 2012, Kevin Wolf wrote:

> Some gcc versions seem not to be able to figure out that the switch
> statement covers all possible values and that c is therefore always
> initialised. Add a default branch for them.
> 

Applied, thanks.

-- 
mailto:av1...@comtv.ru



Re: [Qemu-devel] [PATCHv2 1/1] Add usb option in machine options to enable/disable usb

2012-06-15 Thread Markus Armbruster
Li Zhang  writes:

> For pseries machine, it needs to enable usb to add
> keyboard or usb mouse. -usb option won't be used in
> the future, and machine options is a better way to
> enable usb.
>
> So this patch is to add usb option to machine options
> (-machine type=psereis,usb=on/off)to enable/disable
> usb controller.
>
> In this patch, usb_on is an global option which can
> be checked by machines.
> For example, on pseries, it will check if usb_on is 1,
> if it is 1, it will create one usb ohci controller.
> As the following:
> if (usb_on == 1) {
>  pci_create_simple(bus, -1, "pci-ohci");
> }
>
> In this patch, usb is on by default. So, for -nodefault,
> usb should be set off in the command line as the following:
>  -machine type=pseries,usb=off.
>
> Signed-off-by: Li Zhang 
>
> ---
>  hw/spapr.c |5 +
>  sysemu.h   |1 +
>  vl.c   |   17 +
>  3 files changed, 23 insertions(+)
>
> diff --git a/hw/spapr.c b/hw/spapr.c
> index d0bddbc..1feb739 100644
> --- a/hw/spapr.c
> +++ b/hw/spapr.c
> @@ -661,6 +661,11 @@ static void ppc_spapr_init(ram_addr_t ram_size,
>  spapr_vscsi_create(spapr->vio_bus);
>  }
>  
> +if (usb_on == 1) {
> +pci_create_simple(QLIST_FIRST(&spapr->phbs)->host_state.bus,
> +  -1, "pci-ohci");
> +}
> +
>  if (rma_size < (MIN_RMA_SLOF << 20)) {
>  fprintf(stderr, "qemu: pSeries SLOF firmware requires >= "
>  "%ldM guest RMA (Real Mode Area memory)\n", MIN_RMA_SLOF);
> diff --git a/sysemu.h b/sysemu.h
> index bc2c788..08134ae 100644
> --- a/sysemu.h
> +++ b/sysemu.h
> @@ -109,6 +109,7 @@ extern int vga_interface_type;
>  #define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
>  #define qxl_enabled (vga_interface_type == VGA_QXL)
>  
> +extern int usb_on;
>  extern int graphic_width;
>  extern int graphic_height;
>  extern int graphic_depth;
> diff --git a/vl.c b/vl.c
> index 204d85b..b200203 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -202,6 +202,7 @@ int smp_cpus = 1;
>  int max_cpus = 0;
>  int smp_cores = 1;
>  int smp_threads = 1;
> +int usb_on = 0;
>  #ifdef CONFIG_VNC
>  const char *vnc_display;
>  #endif
> @@ -758,6 +759,21 @@ static int bt_parse(const char *opt)
>  return 1;
>  }
>  
> +static int get_usb_opt(QemuOpts *opts)
> +{
> +const char *usb_opt = NULL;

Useless initializer.

> +int usb_on = 0;
> +
> +if (NULL == qemu_opt_get(opts, "usb"))
> +qemu_opt_set(opts, "usb", "on");

Why are you changing opts?

> +
> +usb_opt = qemu_opt_get(opts, "usb");
> +if (usb_opt && strcmp(usb_opt, "on") == 0)

Please don't duplicate parsing of bools; use qemu_opt_get_bool().

> +usb_on = 1;
> +
> +return usb_on;
> +}
> +
>  /***/
>  /* QEMU Block devices */
>  
> @@ -3356,6 +3372,7 @@ int main(int argc, char **argv, char **envp)
>  kernel_filename = qemu_opt_get(machine_opts, "kernel");
>  initrd_filename = qemu_opt_get(machine_opts, "initrd");
>  kernel_cmdline = qemu_opt_get(machine_opts, "append");
> +usb_on = get_usb_opt(machine_opts);

Anything wrong with

 usb_on = qemu_opt_get_bool(machine_opts, "usb", 0);

?

>  } else {
>  kernel_filename = initrd_filename = kernel_cmdline = NULL;
>  }

Your new global usb_on is still unused, and it's not integrated with
-usb.  I doubt it can be merged that way.



Re: [Qemu-devel] [PATCH 2/2] xenstore: Use

2012-06-15 Thread Anthony PERARD

On 15/06/12 12:53, Juan Quintela wrote:

Anthony PERARD  wrote:

In the next release of Xen (4.2), xs.h became deprecated.

Signed-off-by: Anthony PERARD
---
  configure   |2 +-
  hw/xen_common.h |6 +-
  2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index c2366ee..e7f66c9 100755
--- a/configure
+++ b/configure
@@ -1382,7 +1382,7 @@ EOF
elif (
cat>  $TMPC<
-#include
+#include
  #include
  #include
  #if !defined(HVM_MAX_VCPUS)
diff --git a/hw/xen_common.h b/hw/xen_common.h
index fe7f227..cc99204 100644
--- a/hw/xen_common.h
+++ b/hw/xen_common.h
@@ -7,7 +7,11 @@
  #include

  #include
-#include
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION<  420
+#  include
+#else
+#  include
+#endif
  #include

  #include "hw.h"


Shouldn't we need the ifdef also in configure?  On my system xenstore.h
still don't exist.


No, configure does not need it. In the configure, I just change the 
header in the test for the next version of Xen. Also the define is 
defined by configure.


Regards,

--
Anthony PERARD



Re: [Qemu-devel] [PATCH 2/2] xenstore: Use

2012-06-15 Thread Stefano Stabellini
On Fri, 15 Jun 2012, Juan Quintela wrote:
> Anthony PERARD  wrote:
> > In the next release of Xen (4.2), xs.h became deprecated.
> >
> > Signed-off-by: Anthony PERARD 
> > ---
> >  configure   |2 +-
> >  hw/xen_common.h |6 +-
> >  2 files changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/configure b/configure
> > index c2366ee..e7f66c9 100755
> > --- a/configure
> > +++ b/configure
> > @@ -1382,7 +1382,7 @@ EOF
> >elif (
> >cat > $TMPC < >  #include 
> > -#include 
> > +#include 
> >  #include 
> >  #include 
> >  #if !defined(HVM_MAX_VCPUS)
> > diff --git a/hw/xen_common.h b/hw/xen_common.h
> > index fe7f227..cc99204 100644
> > --- a/hw/xen_common.h
> > +++ b/hw/xen_common.h
> > @@ -7,7 +7,11 @@
> >  #include 
> >  
> >  #include 
> > -#include 
> > +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
> > +#  include 
> > +#else
> > +#  include 
> > +#endif
> >  #include 
> >  
> >  #include "hw.h"
> 
> Shouldn't we need the ifdef also in configure?  On my system xenstore.h
> still don't exist.
> 
> (master *)$ rpm -qa xen-devel
> xen-devel-4.1.2-17.fc17.x86_64
> (master *)$ ls /usr/include/xs.h 
> /usr/include/xs.h
> (master *)$ ls /usr/include/xenstore.h
> ls: cannot access /usr/include/xenstore.h: No such file or directory
> (master *)$ 

configure is already testing for a number of specific xen versions,
this patch is only changing the xen-unstable test, but all the other
tests for older xen versions still use xs.h.



Re: [Qemu-devel] [PATCH 0/2] xen: Deprecation of .

2012-06-15 Thread Stefano Stabellini
On Fri, 15 Jun 2012, Anthony PERARD wrote:
> Considering that  will be deprecated in the next release of Xen, this 
> two
> patches clean a bit the inclusion of xs.h and changes it in a single place.
> 
> Anthony PERARD (2):
>   xen: Reorganize includes of Xen headers.
>   xenstore: Use 
> 
>  configure|2 +-
>  hw/xen_backend.c |6 ++
>  hw/xen_common.h  |6 +-
>  hw/xen_console.c |5 ++---
>  hw/xen_disk.c|6 +-
>  hw/xen_nic.c |7 ++-
>  hw/xenfb.c   |   13 +
>  7 files changed, 18 insertions(+), 27 deletions(-)

both patches are fine.



Re: [Qemu-devel] [PATCHv2 1/1] Add usb option in machine options to enable/disable usb

2012-06-15 Thread Andreas Färber
Am 15.06.2012 12:06, schrieb Li Zhang:
> For pseries machine, it needs to enable usb to add
> keyboard or usb mouse. -usb option won't be used in
> the future, and machine options is a better way to
> enable usb.
> 
> So this patch is to add usb option to machine options
> (-machine type=psereis,usb=on/off)to enable/disable
> usb controller.
> 
> In this patch, usb_on is an global option which can
> be checked by machines.
[snip]

...which is exactly what you've been asked to change in v1. Please do.

Also please stick to QEMU Coding Style, which requires braces for if.
Use of the bool type is preferred of int for two-state logic.

Regards,
Andreas

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



Re: [Qemu-devel] [PATCHv2 01/13] unicore32-softmmu: Add unicore32-softmmu build support

2012-06-15 Thread Andreas Färber
Am 15.06.2012 12:28, schrieb Paolo Bonzini:
> Il 15/06/2012 11:47, Guan Xuetao ha scritto:
>> This patch adds unicore32-softmmu build support, include configure,
>> makefile, arch_init, and all missing functions needed by softmmu.
>> Although all missing functions are empty, unicore32-softmmu could
>> be build successfully.
>>
>> Signed-off-by: Guan Xuetao 
>> ---
>>  Makefile.target   |2 +
>>  arch_init.c   |2 +
>>  arch_init.h   |1 +
>>  configure |1 +
>>  default-configs/unicore32-softmmu.mak |1 +
>>  target-unicore32/helper.c |   25 +++--
>>  target-unicore32/machine.c|   23 +++
>>  target-unicore32/op_helper.c  |   24 +++-
>>  target-unicore32/softmmu.c|   39 
>> +
>>  9 files changed, 105 insertions(+), 13 deletions(-)
>>  create mode 100644 default-configs/unicore32-softmmu.mak
>>  create mode 100644 target-unicore32/machine.c
>>  create mode 100644 target-unicore32/softmmu.c
>>
>> diff --git a/Makefile.target b/Makefile.target
>> index 1582904..7d3b1fd 100644
>> --- a/Makefile.target
>> +++ b/Makefile.target
>> @@ -387,6 +387,8 @@ obj-xtensa-y += core-dc232b.o
>>  obj-xtensa-y += core-dc233c.o
>>  obj-xtensa-y += core-fsf.o
>>  
>> +obj-unicore32-y += softmmu.o
>> +
> 
> You need to rebase this and put this line (actually
> obj-$(CONFIG_SOFTMMU) += softmmu.o) in target-unicore32/Makefile.objs.

Noticed this, too. I wonder if Xuetao could place the new puv3.c machine
file into hw/unicore32/ now, if he wanted?
The devices now compiled through hw/Makefile.objs should probably remain
in hw/? Or is it acceptable to have "unicore32/puv3.o" in
hw/Makefile.objs with the new build system?

General design question. :)

Andreas

P.S. Please avoid dropping the CCs, the author doesn't seem to be
following qemu-devel too closely and it helps avoid double replies.

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



Re: [Qemu-devel] [PATCH 1/1] Add usb option in machine options.

2012-06-15 Thread Li Zhang
On Fri, Jun 15, 2012 at 7:09 PM, Andreas Färber  wrote:
>
> Am 15.06.2012 05:06, schrieb Li Zhang:
> >
> >
> > On Thu, Jun 14, 2012 at 10:27 PM, Andreas Färber  > > wrote:
> >
> >     Am 14.06.2012 07:17, schrieb zhlci...@gmail.com
> >     :
> >     > From: Li Zhang  >     >
> >     >
> >     > For pseries machine, it needs to enable usb
> >     > to add kbd or usb mouse. -usb option won't
> >     > be used in the future, and machine options
> >     > is a better way to enable usb.
> >     >
> >     > So this patch is to add usb option to machine
> >     > options (-machine type=psereis,usb=on/off)
> >     > to enable/disable usb controller.
> >     >
> >     > In this patch, usb_opt is an global option
> >     > which can be checked by machines. For example,
> >     > on pseries, it will check if usb_opt is on, if
> >     > it is on, it will create one usb ohci controller.
> >     > As the following:
> >     > if (usb_opts && strcmp(usb_opts, "on") == 0)
> >     >      pci_create_simple(bus, -1, "pci-ohci");
> >     >
> >     > In this patch, usb is on by default.
> >     > So, for -nodefault, usb should be set off in the
> >     > command line as the following:
> >     >  -machine type=pseries,usb=off.
> >     >
> >     > Signed-off-by: Li Zhang  >     >
> >     > reviewed-by:   Anthony Liguori  >     >
> >     > reviewed-by:   Benjamin Herrenschmidt  >     >
> >     > ---
> >     >  qemu-config.c |    4 
> >     >  sysemu.h      |    1 +
> >     >  vl.c          |   12 
> >     >  3 files changed, 17 insertions(+)
> >     >
> >     > diff --git a/qemu-config.c b/qemu-config.c
> >     > index bb3bff4..258712a 100644
> >     > --- a/qemu-config.c
> >     > +++ b/qemu-config.c
> >     > @@ -583,6 +583,10 @@ static QemuOptsList qemu_machine_opts = {
> >     >              .name = "dtb",
> >     >              .type = QEMU_OPT_STRING,
> >     >              .help = "Linux kernel device tree file",
> >     > +        }, {
> >     > +            .name = "usb",
> >     > +            .type = QEMU_OPT_BOOL,
> >     > +            .help = "Set on/off to enable/disable usb",
> >     >          },
> >     >          { /* End of list */ }
> >     >      },
> >     > diff --git a/sysemu.h b/sysemu.h
> >     > index bc2c788..c5ea10d 100644
> >     > --- a/sysemu.h
> >     > +++ b/sysemu.h
> >     > @@ -13,6 +13,7 @@
> >     >  /* vl.c */
> >     >
> >     >  extern const char *bios_name;
> >     > +extern const char *usb_opt;
> >     >
> >     >  extern const char *qemu_name;
> >     >  extern uint8_t qemu_uuid[];
> >     > diff --git a/vl.c b/vl.c
> >     > index 204d85b..10f8e4c 100644
> >     > --- a/vl.c
> >     > +++ b/vl.c
> >     > @@ -171,6 +171,7 @@ int main(int argc, char **argv)
> >     >
> >     >  static const char *data_dir;
> >     >  const char *bios_name = NULL;
> >     > +const char *usb_opt = NULL;
> >     >  enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
> >     >  DisplayType display_type = DT_DEFAULT;
> >     >  int display_remote = 0;
>
> [...]
>
> >     The point of using machine options is so that you can use the
> > QemuOpts
> >     infrastructure to inquire this value, not to save more global state.
> >
> > OK, I think it still needs one global value because other machines need
> > to check whether usb is enabled.
> >
> >
> >     Especially not a string when all you want is a boolean value.
> >
> > From the qemu, QEMU_OPT_BOOL type  still use a string
> > "on/off" to enable/disable usb.
> > Maybe it's better to convert it to boolean value.
> >
> >     Further, in this patch it's only being assigned, not used anywhere.
> >
> > In vl.c, it seems that it is not used.
> > I have been thinking to use it in spapr.c.
> >
> > if (usb_opts && strcmp(usb_opts, "on") == 0)
> >             pci_create_simple(bus, -1, "pci-ohci");
> >
> > But I want to see whether this way is accepted.
> > If it is ok, I will add this option to spapr.c.
>
> First, please don't reply with HTML mails, it breaks the quoting as you
> can see.

Thanks for your reminding. :)

> You don't seem to be getting what I'm saying: As discussed in great
> lengths for how to access a passed-in device tree for ARM, the code
> checking this option (i.e., in spapr.c) is expected to call
> qemu_opt_get() itself, instead of saving its value globally in vl.c. For
> example:
>
> machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
> usb_opt = qemu_opt_get(machine_opts, "usb");
> if (strcmp(usb_opt, "off") != 0) {
>    // set up OHCI
> }
>
I see.
I  just thought if every machine has the same code, it can be done in vl.c.
Isn't  the global variable good ?

> with appropriate NULL checks left as exercise for the reader.
>
> So you should combine the definition of the option in qemu-config.c
> (which looks okay) with its actual use in 

Re: [Qemu-devel] [PATCHv2 1/1] Add usb option in machine options to enable/disable usb

2012-06-15 Thread Li Zhang
On Fri, Jun 15, 2012 at 8:04 PM, Markus Armbruster  wrote:
> Li Zhang  writes:
>
>> For pseries machine, it needs to enable usb to add
>> keyboard or usb mouse. -usb option won't be used in
>> the future, and machine options is a better way to
>> enable usb.
>>
>> So this patch is to add usb option to machine options
>> (-machine type=psereis,usb=on/off)to enable/disable
>> usb controller.
>>
>> In this patch, usb_on is an global option which can
>> be checked by machines.
>> For example, on pseries, it will check if usb_on is 1,
>> if it is 1, it will create one usb ohci controller.
>> As the following:
>> if (usb_on == 1) {
>>      pci_create_simple(bus, -1, "pci-ohci");
>> }
>>
>> In this patch, usb is on by default. So, for -nodefault,
>> usb should be set off in the command line as the following:
>>  -machine type=pseries,usb=off.
>>
>> Signed-off-by: Li Zhang 
>>
>> ---
>>  hw/spapr.c |    5 +
>>  sysemu.h   |    1 +
>>  vl.c       |   17 +
>>  3 files changed, 23 insertions(+)
>>
>> diff --git a/hw/spapr.c b/hw/spapr.c
>> index d0bddbc..1feb739 100644
>> --- a/hw/spapr.c
>> +++ b/hw/spapr.c
>> @@ -661,6 +661,11 @@ static void ppc_spapr_init(ram_addr_t ram_size,
>>          spapr_vscsi_create(spapr->vio_bus);
>>      }
>>
>> +    if (usb_on == 1) {
>> +        pci_create_simple(QLIST_FIRST(&spapr->phbs)->host_state.bus,
>> +                          -1, "pci-ohci");
>> +    }
>> +
>>      if (rma_size < (MIN_RMA_SLOF << 20)) {
>>          fprintf(stderr, "qemu: pSeries SLOF firmware requires >= "
>>                  "%ldM guest RMA (Real Mode Area memory)\n", MIN_RMA_SLOF);
>> diff --git a/sysemu.h b/sysemu.h
>> index bc2c788..08134ae 100644
>> --- a/sysemu.h
>> +++ b/sysemu.h
>> @@ -109,6 +109,7 @@ extern int vga_interface_type;
>>  #define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
>>  #define qxl_enabled (vga_interface_type == VGA_QXL)
>>
>> +extern int usb_on;
>>  extern int graphic_width;
>>  extern int graphic_height;
>>  extern int graphic_depth;
>> diff --git a/vl.c b/vl.c
>> index 204d85b..b200203 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -202,6 +202,7 @@ int smp_cpus = 1;
>>  int max_cpus = 0;
>>  int smp_cores = 1;
>>  int smp_threads = 1;
>> +int usb_on = 0;
>>  #ifdef CONFIG_VNC
>>  const char *vnc_display;
>>  #endif
>> @@ -758,6 +759,21 @@ static int bt_parse(const char *opt)
>>      return 1;
>>  }
>>
>> +static int get_usb_opt(QemuOpts *opts)
>> +{
>> +    const char *usb_opt = NULL;
>
> Useless initializer.
Thanks. I will remove it.
>
>> +    int usb_on = 0;
>> +
>> +    if (NULL == qemu_opt_get(opts, "usb"))
>> +        qemu_opt_set(opts, "usb", "on");
>
> Why are you changing opts?
USB is enabled by default when there is no usb option setting.
For example,
using  # qemu-system-ppc64 -machine type=pseries
There is no usb option, but usb is set on.
>
>> +
>> +    usb_opt = qemu_opt_get(opts, "usb");
>> +    if (usb_opt && strcmp(usb_opt, "on") == 0)
>
> Please don't duplicate parsing of bools; use qemu_opt_get_bool().
OK.
>
>> +        usb_on = 1;
>> +
>> +    return usb_on;
>> +}
>> +
>>  /***/
>>  /* QEMU Block devices */
>>
>> @@ -3356,6 +3372,7 @@ int main(int argc, char **argv, char **envp)
>>          kernel_filename = qemu_opt_get(machine_opts, "kernel");
>>          initrd_filename = qemu_opt_get(machine_opts, "initrd");
>>          kernel_cmdline = qemu_opt_get(machine_opts, "append");
>> +        usb_on = get_usb_opt(machine_opts);
>
> Anything wrong with
>
>         usb_on = qemu_opt_get_bool(machine_opts, "usb", 0);
>
> ?
>
>>      } else {
>>          kernel_filename = initrd_filename = kernel_cmdline = NULL;
>>      }
>
> Your new global usb_on is still unused, and it's not integrated with
> -usb.  I doubt it can be merged that way.
>
It is used in spapr.c. In the front of this patch, it is used.
It seems that this is not good.
Maybe it is better to move the options setting  to spapr.c.



-- 

Best Regards
-Li



Re: [Qemu-devel] [PATCHv2 1/1] Add usb option in machine options to enable/disable usb

2012-06-15 Thread Li Zhang
On Fri, Jun 15, 2012 at 8:30 PM, Andreas Färber  wrote:
> Am 15.06.2012 12:06, schrieb Li Zhang:
>> For pseries machine, it needs to enable usb to add
>> keyboard or usb mouse. -usb option won't be used in
>> the future, and machine options is a better way to
>> enable usb.
>>
>> So this patch is to add usb option to machine options
>> (-machine type=psereis,usb=on/off)to enable/disable
>> usb controller.
>>
>> In this patch, usb_on is an global option which can
>> be checked by machines.
> [snip]
>
> ...which is exactly what you've been asked to change in v1. Please do.
>
OK. I will do it. :)

> Also please stick to QEMU Coding Style, which requires braces for if.
> Use of the bool type is preferred of int for two-state logic.
>
Got it. I will do it carefully in the future.
> Regards,
> Andreas
>
> --
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
>



-- 

Best Regards
-Li



Re: [Qemu-devel] [PATCHv2 01/13] unicore32-softmmu: Add unicore32-softmmu build support

2012-06-15 Thread Paolo Bonzini
> >> +obj-unicore32-y += softmmu.o
> >> +
> > 
> > You need to rebase this and put this line (actually
> > obj-$(CONFIG_SOFTMMU) += softmmu.o) in
> > target-unicore32/Makefile.objs.
> 
> Noticed this, too. I wonder if Xuetao could place the new puv3.c
> machine file into hw/unicore32/ now, if he wanted?
> The devices now compiled through hw/Makefile.objs should probably
> remain in hw/? Or is it acceptable to have "unicore32/puv3.o" in
> hw/Makefile.objs with the new build system?
> 
> General design question. :)

In my intention, having device model sources in hw/TARGET would be
mostly limited to boards and other special cases like interrupt
controllers.

All other devices should gain a CONFIG_* symbol and be moved to
hw/Makefile.objs, like you did with the Xilinx stuff recently.

Having common-obj-y or hw-obj-y definitions in Makefiles named
according to the target still could make sense for boards/PICs if
you are building your target multiple times (e.g. with different
endianness).

Paolo



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

2012-06-15 Thread Kevin Wolf
The following changes since commit 63bb682a18acc5d2f3219ea96c4d81c1a3b50748:

  Merge branch 'master' of git://git.qemu.org/qemu (2012-06-15 15:53:34 +0400)

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 (7):
  qemu-img check -r for repairing images
  qemu-img check: Print fixed clusters and recheck
  qcow2: Support for fixing refcount inconsistencies
  qcow2: Simplify calculation for COW area at the end
  qcow2: Fix avail_sectors in cluster allocation code
  qemu-iotests: Some backing file COW tests
  qemu-iotests: COW with many AIO requests on the same cluster

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

Markus Armbruster (7):
  Un-inline fdctrl_init_isa()
  block: Simplify how drive_init() computes default ID
  block: New bdrv_get_flags()
  scsi-disk: Don't peek behind the BlockDriverState abstraction
  block: Replace bdrv_get_format() by bdrv_get_format_name()
  xen: Don't change -drive if=xen device name during machine init
  xen: Don't peek behind the BlockDriverState abstraction

Max Filippov (1):
  xtensa_lx60: add missing #include "blockdev.h"

Paolo Bonzini (13):
  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
  qemu-iotests: fill streaming test image with data
  qemu-iotests: start vms in qtest mode
  block: flush in writethrough mode after writes
  savevm: flush after saving vm state
  block: copy enable_write_cache in bdrv_append
  block: add bdrv_set_enable_write_cache
  block: always open drivers in writeback mode
  ide: support enable/disable write cache
  qcow2: always operate caches in writeback mode

Pavel Dovgaluk (1):
  Prevent disk data loss when closing qemu

Pavel Hrdina (2):
  fdc: fix implied seek while there is no media in drive
  fdc-test: introduced qtest read_without_media

Stefan Hajnoczi (4):
  qemu-img: document qed format on qemu-img man page
  qcow2: fix autoclear image header update
  qemu-iotests: add qcow2.py set-feature-bit command
  qemu-iotests: add 036 autoclear feature bit test

Zhi Yong Wu (2):
  qcow2: remove a line of unnecessary code
  qcow2: fix endianness conversion

 block.c   |   90 -
 block.h   |   17 +-
 block/qcow2-cache.c   |   25 +-
 block/qcow2-cluster.c |   16 +-
 block/qcow2-refcount.c|   57 ++-
 block/qcow2.c |   29 +-
 block/qcow2.h |8 +-
 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 +-
 blockdev.c|7 +-
 hw/fdc.c  |   24 ++
 hw/fdc.h  |   24 +-
 hw/ide/core.c |   21 +-
 hw/ide/piix.c |3 +-
 hw/isa.h  |2 -
 hw/pc_sysfw.c |1 +
 hw/scsi-disk.c|3 +-
 hw/xen_devconfig.c|   13 +-
 hw/xen_disk.c |3 +-
 hw/xtensa_lx60.c  |1 +
 include/qemu/ratelimit.h  |   48 +++
 os-win32.c|8 +-
 qemu-common.h |1 +
 qemu-img-cmds.hx  |4 +-
 qemu-img.c|   40 ++-
 qemu-img.texi |   30 ++-
 savevm.c  |2 +-
 tests/fdc-test.c  |   66 +++
 tests/qemu-iotests/030|   15 +-
 tests/qemu-iotests/036|   68 +++
 tests/qemu-iotests/036.out|   52 +++
 tests/qemu-iotests/037|  119 ++
 tests/qemu-iotests/037.out|  645 +
 tests/qemu-iotests/038|  133 ++
 tests/qemu-iotests/038.out|  909 +
 tests/qemu-iotests/group  |3 +
 tests/qemu-iotests/iotests.py |4 +-
 tests/qemu-iotests/qcow2.py   |   23 +
 45 files changed, 2531 insertions(+), 243 deletions(-)
 create mode 100644 include/qemu/ratelimit.h
 create mode 100755 tests/qemu-iotests/036
 create mode 100644 tests/qemu-iotests/036.out
 create mode 100755 tests/qemu-iotests/037
 create mode 100644 tests/qemu-iotests/037.out
 create mode 100755 tests/qemu-iotests/038
 create mode 100644 tests/qemu-iotests/038.out



[Qemu-devel] [PATCH 20/39] block: flush in writethrough mode after writes

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

We want to make the formats handle their own flushes
autonomously, while keeping for guests the ability to use a writethrough
cache.  Since formats will write metadata via bs->file, bdrv_co_do_writev
is the only place where we need to add a flush.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 block.c |   11 +--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 85ef6af..7538112 100644
--- a/block.c
+++ b/block.c
@@ -1758,8 +1758,8 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
 return ret;
 }
 
-/* No flush needed for cache modes that use O_DSYNC */
-if ((bs->open_flags & BDRV_O_CACHE_WB) != 0) {
+/* No flush needed for cache modes that already do it */
+if (bs->enable_write_cache) {
 bdrv_flush(bs);
 }
 
@@ -1808,6 +1808,9 @@ static int coroutine_fn 
bdrv_co_do_copy_on_readv(BlockDriverState *bs,
 ret = bdrv_co_do_write_zeroes(bs, cluster_sector_num,
   cluster_nb_sectors);
 } else {
+/* This does not change the data on the disk, it is not necessary
+ * to flush even in cache=writethrough mode.
+ */
 ret = drv->bdrv_co_writev(bs, cluster_sector_num, cluster_nb_sectors,
   &bounce_qiov);
 }
@@ -1977,6 +1980,10 @@ static int coroutine_fn 
bdrv_co_do_writev(BlockDriverState *bs,
 ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
 }
 
+if (ret == 0 && !bs->enable_write_cache) {
+ret = bdrv_co_flush(bs);
+}
+
 if (bs->dirty_bitmap) {
 set_dirty_bitmap(bs, sector_num, nb_sectors, 1);
 }
-- 
1.7.6.5




[Qemu-devel] [PATCH 19/39] qemu-iotests: start vms in qtest mode

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

This way, they will not execute any VM code at all.  However, right now
the cancellation test is "relying" on being slowed down by TCG executing
BIOS code.  So, change the timeouts.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 tests/qemu-iotests/030|2 +-
 tests/qemu-iotests/iotests.py |4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
index 4ab7d62..cc671dd 100755
--- a/tests/qemu-iotests/030
+++ b/tests/qemu-iotests/030
@@ -147,7 +147,7 @@ class TestStreamStop(ImageStreamingTestCase):
 result = self.vm.qmp('block-stream', device='drive0')
 self.assert_qmp(result, 'return', {})
 
-time.sleep(1)
+time.sleep(0.1)
 events = self.vm.get_qmp_events(wait=False)
 self.assertEqual(events, [], 'unexpected QMP event: %s' % events)
 
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index e27b40e..e05b1d6 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -54,7 +54,9 @@ class VM(object):
 self._qemu_log_path = os.path.join(test_dir, 'qemu-log.%d' % 
os.getpid())
 self._args = qemu_args + ['-chardev',
  'socket,id=mon,path=' + self._monitor_path,
- '-mon', 'chardev=mon,mode=control', '-nographic']
+ '-mon', 'chardev=mon,mode=control',
+ '-qtest', 'stdio', '-machine', 'accel=qtest',
+ '-display', 'none', '-vga', 'none']
 self._num_drives = 0
 
 def add_drive(self, path, opts=''):
-- 
1.7.6.5




[Qemu-devel] [PATCH 36/39] fdc: fix implied seek while there is no media in drive

2012-06-15 Thread Kevin Wolf
From: Pavel Hrdina 

The Windows uses 'READ' command at the start of an instalation
without checking the 'dir' register. We have to abort the transfer
with an abnormal termination if there is no media in the drive.

Signed-off-by: Pavel Hrdina 
Signed-off-by: Kevin Wolf 
---
 hw/fdc.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index bfa4e68..78b4e33 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -159,6 +159,10 @@ static int fd_seek(FDrive *drv, uint8_t head, uint8_t 
track, uint8_t sect,
 drv->sect = sect;
 }
 
+if (drv->bs == NULL || !bdrv_is_inserted(drv->bs)) {
+ret = 2;
+}
+
 return ret;
 }
 
-- 
1.7.6.5




Re: [Qemu-devel] [libseccomp-discuss] [RFC] [PATCHv2 0/2] Sandboxing Qemu guests with Libseccomp

2012-06-15 Thread Paul Moore
On Thursday, June 14, 2012 02:59:06 PM Kees Cook wrote:
> On Wed, Jun 13, 2012 at 1:31 PM, Paul Moore  wrote:
> > On Wednesday, June 13, 2012 04:20:20 PM Eduardo Otubo wrote:
> >> Hello all,
> >> 
> >> This is the second effort to sandbox Qemu guests using Libseccomp[0].
> > 
> > ...
> > 
> >> [0] - http://sourceforge.net/projects/libseccomp/ [1] -
> >> http://git.kernel.org/?p=linux/kernel/git/next/linux-next.git;a=commit;h=
> >> e2c fabdfd075648216f99c2c03821cf3f47c1727
> > 
> > It is worth pointing out that you no longer need to fetch libseccomp from
> > the git repository, we did our first release (v 0.1.0) last Friday, June
> > 8th:
> > 
> >  * https://sourceforge.net/projects/libseccomp/files
> > 
> > Packages are available for Debian/Ubuntu and Fedora packaging is currently
> > in progress.
> 
> Gentoo has en ebuild as well. If you hit any snags with the packaging
> there or in Debian and Ubuntu, let me know. :)

Excellent, thanks for contributing the Gentoo ebuild.

-- 
paul moore
security and virtualization @ redhat




[Qemu-devel] [PATCH 25/39] ide: support enable/disable write cache

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

Enabling or disabling the write cache is done with the SET FEATURES
command.  The command can be issued with sg_sat_set_features from
sg3-utils.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 hw/ide/core.c |   21 ++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 9785d5f..f28229a 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1047,6 +1047,7 @@ static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
 
 void ide_exec_cmd(IDEBus *bus, uint32_t val)
 {
+uint16_t *identify_data;
 IDEState *s;
 int n;
 int lba48 = 0;
@@ -1231,10 +1232,21 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 goto abort_cmd;
 /* XXX: valid for CDROM ? */
 switch(s->feature) {
-case 0xcc: /* reverting to power-on defaults enable */
-case 0x66: /* reverting to power-on defaults disable */
 case 0x02: /* write cache enable */
+bdrv_set_enable_write_cache(s->bs, true);
+identify_data = (uint16_t *)s->identify_data;
+put_le16(identify_data + 85, (1 << 14) | (1 << 5) | 1);
+s->status = READY_STAT | SEEK_STAT;
+ide_set_irq(s->bus);
+break;
 case 0x82: /* write cache disable */
+bdrv_set_enable_write_cache(s->bs, false);
+identify_data = (uint16_t *)s->identify_data;
+put_le16(identify_data + 85, (1 << 14) | 1);
+ide_flush_cache(s);
+break;
+case 0xcc: /* reverting to power-on defaults enable */
+case 0x66: /* reverting to power-on defaults disable */
 case 0xaa: /* read look-ahead enable */
 case 0x55: /* read look-ahead disable */
 case 0x05: /* set advanced power management mode */
@@ -1250,7 +1262,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 break;
 case 0x03: { /* set transfer mode */
uint8_t val = s->nsector & 0x07;
-uint16_t *identify_data = (uint16_t *)s->identify_data;
+   identify_data = (uint16_t *)s->identify_data;
 
switch (s->nsector >> 3) {
case 0x00: /* pio default */
@@ -2146,6 +2158,9 @@ static int ide_drive_post_load(void *opaque, int 
version_id)
 s->cdrom_changed = 1;
 }
 }
+if (s->identify_set) {
+bdrv_set_enable_write_cache(s->bs, !!(s->identify_data[85] & (1 << 
5)));
+}
 return 0;
 }
 
-- 
1.7.6.5




Re: [Qemu-devel] [PATCH v2] qapi: converted commit

2012-06-15 Thread Luiz Capitulino
On Thu, 14 Jun 2012 09:35:21 +0200
Pavel Hrdina  wrote:

> 
> Signed-off-by: Pavel Hrdina 
> ---
> Please ignore previous patch, I forget to change 'Since' version.
> 
>  blockdev.c   |9 -
>  blockdev.h   |1 -
>  hmp-commands.hx  |2 +-
>  hmp.c|9 +
>  hmp.h|1 +
>  qapi-schema.json |   15 +++
>  qmp-commands.hx  |   24 
>  7 files changed, 54 insertions(+), 7 deletions(-)
> 
> diff --git a/blockdev.c b/blockdev.c
> index 622ecba..d78af31 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -631,27 +631,26 @@ err:
>  return NULL;
>  }
>  
> -void do_commit(Monitor *mon, const QDict *qdict)
> +void qmp_commit(const char *device, Error **errp)
>  {
> -const char *device = qdict_get_str(qdict, "device");
>  BlockDriverState *bs;
>  int ret;
>  
>  if (!strcmp(device, "all")) {

This 'all' functionality should be moved to hmp_commit(). You can call
qmp_query_block() and loop through the list of devices calling qmp_commit()
on them.

Note that we should do this even if we go for Jeff's block-commit.

>  ret = bdrv_commit_all();
>  if (ret == -EBUSY) {
> -qerror_report(QERR_DEVICE_IN_USE, device);
> +error_set(errp, QERR_DEVICE_IN_USE, device);
>  return;
>  }
>  } else {
>  bs = bdrv_find(device);
>  if (!bs) {
> -qerror_report(QERR_DEVICE_NOT_FOUND, device);
> +error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>  return;
>  }
>  ret = bdrv_commit(bs);
>  if (ret == -EBUSY) {
> -qerror_report(QERR_DEVICE_IN_USE, device);
> +error_set(errp, QERR_DEVICE_IN_USE, device);
>  return;
>  }

bdrv_commit() can return more errors, but this will ignore them and
report success instead. We want to return qerrors for all possible
bdrv_commit() errors. But it's a good idea to wait to see if we'll use
Jeff's block-commit before making changed to this patch.

>  }
> diff --git a/blockdev.h b/blockdev.h
> index 260e16b..c2e52bb 100644
> --- a/blockdev.h
> +++ b/blockdev.h
> @@ -60,6 +60,5 @@ DriveInfo *add_init_drive(const char *opts);
>  
>  void qmp_change_blockdev(const char *device, const char *filename,
>   bool has_format, const char *format, Error **errp);
> -void do_commit(Monitor *mon, const QDict *qdict);
>  int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
>  #endif
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index f5d9d91..53d2c34 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -28,7 +28,7 @@ ETEXI
>  .args_type  = "device:B",
>  .params = "device|all",
>  .help   = "commit changes to the disk images (if -snapshot is 
> used) or backing files",
> -.mhandler.cmd = do_commit,
> +.mhandler.cmd = hmp_commit,
>  },
>  
>  STEXI
> diff --git a/hmp.c b/hmp.c
> index 2ce8cb9..176defa 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -999,3 +999,12 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
>  qmp_netdev_del(id, &err);
>  hmp_handle_error(mon, &err);
>  }
> +
> +void hmp_commit(Monitor *mon, const QDict *qdict)
> +{
> +const char *device = qdict_get_str(qdict, "device");
> +Error *err = NULL;
> +
> +qmp_commit(device, &err);
> +hmp_handle_error(mon, &err);
> +}
> diff --git a/hmp.h b/hmp.h
> index 79d138d..99d57c0 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -64,5 +64,6 @@ void hmp_device_del(Monitor *mon, const QDict *qdict);
>  void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
>  void hmp_netdev_add(Monitor *mon, const QDict *qdict);
>  void hmp_netdev_del(Monitor *mon, const QDict *qdict);
> +void hmp_commit(Monitor *mon, const QDict *qdict);
>  
>  #endif
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 3b6e346..10cb22b 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -1169,6 +1169,21 @@
>  { 'command': 'block_resize', 'data': { 'device': 'str', 'size': 'int' }}
>  
>  ##
> +# @commit
> +#
> +# Commit changes to the disk images (if -snapshot is used) or backing files.
> +#
> +# @device: the name of the device or the "all" to commit all devices
> +#
> +# Returns: nothing on success
> +#  If @device is not a valid block device, DeviceNotFound
> +#  If a long-running operation is using the device, DeviceInUse
> +#
> +# Since: 1.2
> +##
> +{ 'command': 'commit', 'data': { 'device': 'str' }}
> +
> +##
>  # @NewImageMode
>  #
>  # An enumeration that tells QEMU how to set the backing file path in
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 2e1a38e..8b6bfbc 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -714,6 +714,30 @@ Example:
>  -> { "execute": "block_resize", "arguments": { "device": "scratch", "size": 
> 1073741824 } }
>  <- { "return": {} }
>  
> +
> +EQMP
> +
> +{
> +.name   = "commit",
> +  

[Qemu-devel] [PatchV2] s390: autodetect map private

2012-06-15 Thread Christian Borntraeger
By default qemu will use MAP_PRIVATE for guest pages. This will write
protect pages and thus break on s390 systems that dont support this feature.
Therefore qemu has a hack to always use MAP_SHARED for s390. But MAP_SHARED
has other problems (no dirty pages tracking, a lot more swap overhead etc.)
Newer systems allow the distinction via KVM_CAP_S390_COW. With this feature
qemu can use the standard qemu alloc if available, otherwise it will use
the old s390 hack.

Signed-off-by: Christian Borntraeger 
---
 exec.c |   18 +++---
 kvm-all.c  |   13 +
 kvm.h  |3 +++
 oslib-posix.c  |3 +++
 target-s390x/kvm.c |   35 +++
 5 files changed, 57 insertions(+), 15 deletions(-)

diff --git a/exec.c b/exec.c
index 5c9b762..584a484 100644
--- a/exec.c
+++ b/exec.c
@@ -2647,26 +2647,14 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, 
void *host,
 exit(1);
 #endif
 } else {
-#if defined(TARGET_S390X) && defined(CONFIG_KVM)
-/* S390 KVM requires the topmost vma of the RAM to be smaller than
-   an system defined value, which is at least 256GB. Larger systems
-   have larger values. We put the guest between the end of data
-   segment (system break) and this value. We use 32GB as a base to
-   have enough room for the system break to grow. */
-new_block->host = mmap((void*)0x8, size,
-   PROT_EXEC|PROT_READ|PROT_WRITE,
-   MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 
0);
-if (new_block->host == MAP_FAILED) {
-fprintf(stderr, "Allocating RAM failed\n");
-abort();
-}
-#else
 if (xen_enabled()) {
 xen_ram_alloc(new_block->offset, size, mr);
+} else if (kvm_enabled()) {
+/* some s390/kvm configurations have special constraints */
+new_block->host = kvm_vmalloc(size);
 } else {
 new_block->host = qemu_vmalloc(size);
 }
-#endif
 qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);
 }
 }
diff --git a/kvm-all.c b/kvm-all.c
index 4ea7d85..0372f7a 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1653,6 +1653,19 @@ int kvm_allows_irq0_override(void)
 return !kvm_irqchip_in_kernel() || kvm_has_gsi_routing();
 }
 
+void *kvm_vmalloc(ram_addr_t size)
+{
+#ifdef TARGET_S390X
+void *mem; 
+
+mem = kvm_arch_vmalloc(size);
+if (mem) {
+return mem;
+}
+#endif
+return qemu_vmalloc(size);
+}
+
 void kvm_setup_guest_memory(void *start, size_t size)
 {
 if (!kvm_has_sync_mmu()) {
diff --git a/kvm.h b/kvm.h
index 9c7b0ea..c8ebf3d 100644
--- a/kvm.h
+++ b/kvm.h
@@ -60,6 +60,7 @@ int kvm_has_xsave(void);
 int kvm_has_xcrs(void);
 int kvm_has_pit_state2(void);
 int kvm_has_many_ioeventfds(void);
+
 int kvm_has_gsi_routing(void);
 
 int kvm_allows_irq0_override(void);
@@ -70,6 +71,7 @@ int kvm_init_vcpu(CPUArchState *env);
 int kvm_cpu_exec(CPUArchState *env);
 
 #if !defined(CONFIG_USER_ONLY)
+void *kvm_vmalloc(ram_addr_t size);
 void kvm_setup_guest_memory(void *start, size_t size);
 
 int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
@@ -177,6 +179,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *env, 
uint32_t function,
 void kvm_cpu_synchronize_state(CPUArchState *env);
 void kvm_cpu_synchronize_post_reset(CPUArchState *env);
 void kvm_cpu_synchronize_post_init(CPUArchState *env);
+void *kvm_arch_vmalloc(ram_addr_t size);
 
 /* generic hooks - to be moved/refactored once there are more users */
 
diff --git a/oslib-posix.c b/oslib-posix.c
index b6a3c7f..93902ac 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -41,6 +41,9 @@ extern int daemon(int, int);
   therefore we need special code which handles running on Valgrind. */
 #  define QEMU_VMALLOC_ALIGN (512 * 4096)
 #  define CONFIG_VALGRIND
+#elif defined(__linux__) && defined(__s390x__)
+   /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */
+#  define QEMU_VMALLOC_ALIGN (256 * 4096)
 #else
 #  define QEMU_VMALLOC_ALIGN getpagesize()
 #endif
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 5800fd6..4d38820 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -135,6 +135,41 @@ int kvm_arch_get_registers(CPUS390XState *env)
 return 0;
 }
 
+/*
+ * Legacy layout for s390:
+ * Older S390 KVM requires the topmost vma of the RAM to be
+ * smaller than an system defined value, which is at least 256GB.
+ * Larger systems have larger values. We put the guest between
+ * the end of data segment (system break) and this value. We
+ * use 32GB as a base to have enough room for the system break
+ * to grow. We also have to use MAP parameters that avoid
+ * read-only mapping of guest pages.
+ */
+static void *legacy_s390_alloc(ram_addr_t size)
+{
+v

[Qemu-devel] Next version of memory allocation fixup

2012-06-15 Thread Christian Borntraeger
Jan, Alex,
what about this version? I had two options: ifdef in kvm for
s390 or provide a kvm_arch_vmalloc for every kvm arch. I did choose
the first one.




Re: [Qemu-devel] [PATCH v2] qapi: converted commit

2012-06-15 Thread Luiz Capitulino
On Thu, 14 Jun 2012 17:21:44 +0200
Pavel Hrdina  wrote:

> On 06/14/2012 05:04 PM, Eric Blake wrote:
> > On 06/14/2012 08:56 AM, Pavel Hrdina wrote:
> >> On 06/14/2012 02:18 PM, Eric Blake wrote:
> >>> On 06/14/2012 01:35 AM, Pavel Hrdina wrote:
>  Signed-off-by: Pavel Hrdina
>  ---
>  +++ b/qapi-schema.json
>  @@ -1169,6 +1169,21 @@
> { 'command': 'block_resize', 'data': { 'device': 'str', 'size':
>  'int' }}
> 
> ##
>  +# @commit
>  +#
>  +# Commit changes to the disk images (if -snapshot is used) or
>  backing files.
>  +#
>  +# @device: the name of the device or the "all" to commit all devices
>  +#
>  +# Returns: nothing on success
>  +#  If @device is not a valid block device, DeviceNotFound
>  +#  If a long-running operation is using the device, DeviceInUse
>  +#
>  +# Since: 1.2
>  +##
>  +{ 'command': 'commit', 'data': { 'device': 'str' }}
> >>> Should we use this as an opportunity to make the command more powerful?
> >>>For example, integrating this with the 'transaction' command or a block
> >>> job queried by 'query-block-jobs' to track its progress would be useful.
> >>>Also, suppose I have A<- B<- C.  Does 'commit' only do one layer (C
> >>> into B), or all layers (B and C into A)?  That argues that we need an
> >>> optional parameter that says how deep to commit (committing C into B
> >>> only to repeat and commit B into A is more time-consuming than directly
> >>> committing both B and C into A to start with).  When a commit is
> >>> complete, which file is backing the device - is it still C (which
> >>> continues to diverge, but now from the point of the commit) or does qemu
> >>> pivot things to have the device now backed by B (and C can be discarded,
> >>> particularly true if changes are now going into B which invalidate C).
> >> What i find out is that 'commit' will commit changes only from C to B
> >> and qemu continues with C from the new commit point. I couldn't find a
> >> way to commit changes and go back to backing file. This should be
> >> supported by parameter and also as you mention that commit all changes
> >> through all snapshots should be supported by another parameter.
> >> The 'transaction' feature would be nice to have too.
> > Which makes it sound like we're starting to overlap with Jeff's work on
> > 'block-commit'.
> >
> > If 'block-commit' proves to be better all around at doing what we want,
> > do we even need to keep 'commit' in QMP, or would it be okay for HMP only?
> If the 'block-commit' will be better I think that we could drop the 
> 'commit' completely. And have only 'block-commit' for both QMP and HMP.

I completely agree about the QMP part, but for HMP it's a good idea to
maintain the commit command. To achieve this, we can implement hmp_commit()
in terms of block-commit.

Jeff, can you answer us here? Does block-commit supersedes the commit command
we have today?



[Qemu-devel] [PATCH 31/39] qemu-img: document qed format on qemu-img man page

2012-06-15 Thread Kevin Wolf
From: Stefan Hajnoczi 

The qemu-img.1 man page is missing the qed format from its list of
supported formats.  Document the image creation options for qed.

Suggested-by: Michael Tokarev 
Signed-off-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qemu-img.texi |   23 +++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/qemu-img.texi b/qemu-img.texi
index 5a7b2bb..77c6d0b 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -237,6 +237,29 @@ to grow.
 
 @end table
 
+@item qed
+Image format with support for backing files and compact image files (when your
+filesystem or transport medium does not support holes).  Good performance due
+to less metadata than the more featureful qcow2 format, especially with
+cache=writethrough or cache=directsync.  Consider using qcow2 which will soon
+have a similar optimization and is most actively developed.
+
+Supported options:
+@table @code
+@item backing_file
+File name of a base image (see @option{create} subcommand).
+@item backing_fmt
+Image file format of backing file (optional).  Useful if the format cannot be
+autodetected because it has no header, like some vhd/vpc files.
+@item cluster_size
+Changes the cluster size (must be power-of-2 between 4K and 64K). Smaller
+cluster sizes can improve the image file size whereas larger cluster sizes
+generally provide better performance.
+@item table_size
+Changes the number of clusters per L1/L2 table (must be power-of-2 between 1
+and 16).  There is normally no need to change this value but this option can be
+used for performance benchmarking.
+@end table
 
 @item qcow
 Old QEMU image format. Left for compatibility.
-- 
1.7.6.5




Re: [Qemu-devel] [PATCH v2] qapi: converted commit

2012-06-15 Thread Jeff Cody
On 06/15/2012 10:02 AM, Luiz Capitulino wrote:
> On Thu, 14 Jun 2012 17:21:44 +0200
> Pavel Hrdina  wrote:
> 
>> On 06/14/2012 05:04 PM, Eric Blake wrote:
>>> On 06/14/2012 08:56 AM, Pavel Hrdina wrote:
 On 06/14/2012 02:18 PM, Eric Blake wrote:
> On 06/14/2012 01:35 AM, Pavel Hrdina wrote:
>> Signed-off-by: Pavel Hrdina
>> ---
>> +++ b/qapi-schema.json
>> @@ -1169,6 +1169,21 @@
>>{ 'command': 'block_resize', 'data': { 'device': 'str', 'size':
>> 'int' }}
>>
>>##
>> +# @commit
>> +#
>> +# Commit changes to the disk images (if -snapshot is used) or
>> backing files.
>> +#
>> +# @device: the name of the device or the "all" to commit all devices
>> +#
>> +# Returns: nothing on success
>> +#  If @device is not a valid block device, DeviceNotFound
>> +#  If a long-running operation is using the device, DeviceInUse
>> +#
>> +# Since: 1.2
>> +##
>> +{ 'command': 'commit', 'data': { 'device': 'str' }}
> Should we use this as an opportunity to make the command more powerful?
>For example, integrating this with the 'transaction' command or a block
> job queried by 'query-block-jobs' to track its progress would be useful.
>Also, suppose I have A<- B<- C.  Does 'commit' only do one layer (C
> into B), or all layers (B and C into A)?  That argues that we need an
> optional parameter that says how deep to commit (committing C into B
> only to repeat and commit B into A is more time-consuming than directly
> committing both B and C into A to start with).  When a commit is
> complete, which file is backing the device - is it still C (which
> continues to diverge, but now from the point of the commit) or does qemu
> pivot things to have the device now backed by B (and C can be discarded,
> particularly true if changes are now going into B which invalidate C).
 What i find out is that 'commit' will commit changes only from C to B
 and qemu continues with C from the new commit point. I couldn't find a
 way to commit changes and go back to backing file. This should be
 supported by parameter and also as you mention that commit all changes
 through all snapshots should be supported by another parameter.
 The 'transaction' feature would be nice to have too.
>>> Which makes it sound like we're starting to overlap with Jeff's work on
>>> 'block-commit'.
>>>
>>> If 'block-commit' proves to be better all around at doing what we want,
>>> do we even need to keep 'commit' in QMP, or would it be okay for HMP only?
>> If the 'block-commit' will be better I think that we could drop the 
>> 'commit' completely. And have only 'block-commit' for both QMP and HMP.
> 
> I completely agree about the QMP part, but for HMP it's a good idea to
> maintain the commit command. To achieve this, we can implement hmp_commit()
> in terms of block-commit.
> 
> Jeff, can you answer us here? Does block-commit supersedes the commit command
> we have today?

The block-commit will supercede in functionality the commit command in
place today, but it is a live operation - as such, it will take longer
to complete, but it won't pause the guest.

In general, I think it would be safe to say that it could supersede the
current commit command, unless others see a use case for a commit
operation that completes faster yet pauses the guest.  I think being
able to rely on qemu-img to perform an offline commit would be
sufficient.

I agree on the HMP command matching the QMP command in the method used,
so that there is no confusion.




[Qemu-devel] [PATCH 15/39] Prevent disk data loss when closing qemu

2012-06-15 Thread Kevin Wolf
From: Pavel Dovgaluk 

Prevent disk data loss when closing qemu console window
under Windows 7.

v3. Comment for Sleep() parameter was updated.

Signed-off-by: Pavel Dovgalyuk
Signed-off-by: Kevin Wolf 
---
 os-win32.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/os-win32.c b/os-win32.c
index ad76370..13892ba 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -57,7 +57,13 @@ int setenv(const char *name, const char *value, int 
overwrite)
 
 static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 {
-exit(STATUS_CONTROL_C_EXIT);
+qemu_system_shutdown_request();
+/* Windows 7 kills application when the function returns.
+   Sleep here to give QEMU a try for closing.
+   Sleep period is 1ms because Windows kills the program
+   after 10 seconds anyway. */
+Sleep(1);
+
 return TRUE;
 }
 
-- 
1.7.6.5




[Qemu-devel] [PATCH 13/39] sheepdog: add coroutine_fn markers to coroutine functions

2012-06-15 Thread Kevin Wolf
From: MORITA Kazutaka 

Signed-off-by: MORITA Kazutaka 
Reviewed-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 block/sheepdog.c |9 +
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index f46ca8f..8877f45 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -522,8 +522,8 @@ static int send_req(int sockfd, SheepdogReq *hdr, void 
*data,
 return ret;
 }
 
-static int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
-   unsigned int *wlen)
+static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
+unsigned int *wlen)
 {
 int ret;
 
@@ -540,6 +540,7 @@ static int send_co_req(int sockfd, SheepdogReq *hdr, void 
*data,
 
 return ret;
 }
+
 static int do_req(int sockfd, SheepdogReq *hdr, void *data,
   unsigned int *wlen, unsigned int *rlen)
 {
@@ -576,8 +577,8 @@ out:
 return ret;
 }
 
-static int do_co_req(int sockfd, SheepdogReq *hdr, void *data,
- unsigned int *wlen, unsigned int *rlen)
+static coroutine_fn int do_co_req(int sockfd, SheepdogReq *hdr, void *data,
+  unsigned int *wlen, unsigned int *rlen)
 {
 int ret;
 
-- 
1.7.6.5




[Qemu-devel] [PATCH 38/39] qemu-iotests: add qcow2.py set-feature-bit command

2012-06-15 Thread Kevin Wolf
From: Stefan Hajnoczi 

This new command sets feature bits in the image file header:

  qcow2.py set-feature-bit incompatible|compatible|autoclear 

The bit number must be in the range [0, 64).

Signed-off-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 tests/qemu-iotests/qcow2.py |   23 +++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py
index e27196a..97f3770 100755
--- a/tests/qemu-iotests/qcow2.py
+++ b/tests/qemu-iotests/qcow2.py
@@ -181,10 +181,33 @@ def cmd_del_header_ext(fd, magic):
 
 h.update(fd)
 
+def cmd_set_feature_bit(fd, group, bit):
+try:
+bit = int(bit, 0)
+if bit < 0 or bit >= 64:
+raise ValueError
+except:
+print "'%s' is not a valid bit number in range [0, 64)" % bit
+sys.exit(1)
+
+h = QcowHeader(fd)
+if group == 'incompatible':
+h.incompatible_features |= 1 << bit
+elif group == 'compatible':
+h.compatible_features |= 1 << bit
+elif group == 'autoclear':
+h.autoclear_features |= 1 << bit
+else:
+print "'%s' is not a valid group, try 'incompatible', 'compatible', or 
'autoclear'" % group
+sys.exit(1)
+
+h.update(fd)
+
 cmds = [
 [ 'dump-header',cmd_dump_header,0, 'Dump image header and header 
extensions' ],
 [ 'add-header-ext', cmd_add_header_ext, 2, 'Add a header extension' ],
 [ 'del-header-ext', cmd_del_header_ext, 1, 'Delete a header extension' ],
+[ 'set-feature-bit', cmd_set_feature_bit, 2, 'Set a feature bit'],
 ]
 
 def main(filename, cmd, args):
-- 
1.7.6.5




Re: [Qemu-devel] qemu-system-ppc64 hanging occasionally in disk writes

2012-06-15 Thread Richard W.M. Jones
On Thu, Jun 14, 2012 at 06:13:11PM +0100, Richard W.M. Jones wrote:
> I just tried virtio-scsi, but only the first disk shows up.  I added
> two disks.  See below for detailed logs.  This works fine on x86-64.
> Should I file a separate bug for this?

Here's that bug:

https://bugs.launchpad.net/qemu/+bug/1013691

Also happens with very latest Linus's tree in host+guest.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw



[Qemu-devel] [Bug 1013691] [NEW] ppc64 + virtio-scsi: only first scsi disk shows up in the guest

2012-06-15 Thread Richard W.M. Jones
Public bug reported:

When adding two virtio-scsi targets to a single guest, only the first
disk is seen inside the guest.  For some unknown reason the guest
doesn't enumerate the second disk.

For full qemu-system-ppc64 command line and 'dmesg' output, see:

http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg02430.html

I have also tried this with Linus's git tree (3.5.0-rc2+ at time of writing),
same thing.

In both cases I'm using qemu from git.

** Affects: qemu
 Importance: Undecided
 Status: New

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

Title:
  ppc64 + virtio-scsi: only first scsi disk shows up in the guest

Status in QEMU:
  New

Bug description:
  When adding two virtio-scsi targets to a single guest, only the first
  disk is seen inside the guest.  For some unknown reason the guest
  doesn't enumerate the second disk.

  For full qemu-system-ppc64 command line and 'dmesg' output, see:

  http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg02430.html

  I have also tried this with Linus's git tree (3.5.0-rc2+ at time of writing),
  same thing.

  In both cases I'm using qemu from git.

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



Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add pass-fd QMP command

2012-06-15 Thread Luiz Capitulino
On Thu, 14 Jun 2012 11:55:02 -0400
Corey Bryant  wrote:

> This patch adds the pass-fd QMP command using the QAPI framework.
> Like the getfd command, it is used to pass a file descriptor via
> SCM_RIGHTS.  However, the pass-fd command also returns the received
> file descriptor, which is a difference in behavior from the getfd
> command, which returns nothing.
> 
> The closefd command can be used to close a file descriptor that was
> passed with the pass-fd command.
> 
> Note that when using getfd or pass-fd, there are some commands
> (e.g. migrate with fd:name) that implicitly close the named fd.
> When this is not the case, closefd must be used to avoid fd leaks.
> 
> Signed-off-by: Corey Bryant 
> ---
> v2:
>  -Introduce new QMP command to pass/return fd (lcapitul...@redhat.com)
>  -Use passfd as command name (berra...@redhat.com)
> 
> v3:
>  -Use pass-fd as command name (lcapitul...@redhat.com)
>  -Fail pass-fd if fdname already exists (lcapitul...@redhat.com)
>  -Add notes to QMP command describing behavior in more detail
>   (lcapitul...@redhat.com, ebl...@redhat.com)
>  -Add note about fd leakage (ebl...@redhat.com)
> 
>  monitor.c|   33 +
>  qapi-schema.json |   19 +++
>  qmp-commands.hx  |   34 ++
>  3 files changed, 86 insertions(+)
> 
> diff --git a/monitor.c b/monitor.c
> index 1a7f7e7..6d99368 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2182,6 +2182,39 @@ static void do_inject_mce(Monitor *mon, const QDict 
> *qdict)
>  }
>  #endif
>  
> +int64_t qmp_pass_fd(const char *fdname, Error **errp)
> +{
> +mon_fd_t *monfd;
> +int fd;
> +
> +fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
> +if (fd == -1) {
> +error_set(errp, QERR_FD_NOT_SUPPLIED);
> +return -1;
> +}
> +
> +if (qemu_isdigit(fdname[0])) {
> +error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
> +  "a name not starting with a digit");
> +return -1;
> +}
> +
> +QLIST_FOREACH(monfd, &cur_mon->fds, next) {
> +if (strcmp(monfd->name, fdname) == 0) {
> +error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
> +  "a name that does not already exist");
> +return -1;
> +}
> +}

Returning the same error class for two different errors is not a good idea.
I think you have two options here. You could return QERR_INVALID_PARAMETER
for the "already exists" case or introduce QERR_FD_EXISTS. The later is
certainly nicer, but we were trying to avoid having too specific errors...

> +
> +monfd = g_malloc0(sizeof(mon_fd_t));
> +monfd->name = g_strdup(fdname);
> +monfd->fd = fd;

Maybe you could try to move this to a separate function to share code with
qmp_getfd()?

> +
> +QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
> +return fd;
> +}
> +
>  void qmp_getfd(const char *fdname, Error **errp)
>  {
>  mon_fd_t *monfd;
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 26a6b84..ed99f23 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -1864,6 +1864,25 @@
>  { 'command': 'netdev_del', 'data': {'id': 'str'} }
>  
>  ##
> +# @pass-fd:
> +#
> +# Pass a file descriptor via SCM rights and assign it a name
> +#
> +# @fdname: file descriptor name
> +#
> +# Returns: The QEMU file descriptor that was received
> +#  If file descriptor was not received, FdNotSupplied
> +#  If @fdname is not valid, InvalidParameterType
> +#
> +# Since: 1.2.0
> +#
> +# Notes: If @fdname already exists, the command will fail.
> +#The 'closefd' command can be used to explicitly close the
> +#file descriptor when it is no longer needed.
> +##
> +{ 'command': 'pass-fd', 'data': {'fdname': 'str'}, 'returns': 'int' }
> +
> +##
>  # @getfd:
>  #
>  # Receive a file descriptor via SCM rights and assign it a name
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index e3cf3c5..c039947 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -869,6 +869,40 @@ Example:
>  EQMP
>  
>  {
> +.name   = "pass-fd",
> +.args_type  = "fdname:s",
> +.params = "pass-fd name",
> +.help   = "pass a file descriptor via SCM rights and assign it a 
> name",
> +.mhandler.cmd_new = qmp_marshal_input_pass_fd,
> +},
> +
> +SQMP
> +pass-fd
> +---
> +
> +Pass a file descriptor via SCM rights and assign it a name.
> +
> +Arguments:
> +
> +- "fdname": file descriptor name (json-string)
> +
> +Return a json-int with the QEMU file descriptor that was received.
> +
> +Example:
> +
> +-> { "execute": "pass-fd", "arguments": { "fdname": "fd1" } }
> +<- { "return": 42 }
> +
> +Notes:
> +
> +(1) If the name specified by the "fdname" argument already exists,
> +the command will fail.
> +(2) The 'closefd' command can be used to explicitly close the file
> +descriptor when it is no longer needed.
> +
> +EQMP
> +
> +{
>  .name   = "ge

Re: [Qemu-devel] [PATCH v3 4/5] block: Convert open calls to qemu_open

2012-06-15 Thread Luiz Capitulino
On Thu, 14 Jun 2012 11:55:04 -0400
Corey Bryant  wrote:

> This patch converts all block layer open calls to qemu_open.  This
> enables all block layer open paths to dup(X) a pre-opened file
> descriptor if the filename is of the format /dev/fd/X.  This is
> useful if QEMU is restricted from opening certain files.
> 
> Note that this adds the O_CLOEXEC flag to the changed open paths
> when the O_CLOEXEC macro is defined.

Very minor comment, but I'd exchange this with the previous patch. Because
this change is not only related to the /dev/fd/X feature and also because
as soon as you introduce the /dev/fd/X it will work for all file formats.

> 
> Signed-off-by: Corey Bryant 
> ---
> v2:
>  -Convert calls to qemu_open instead of file_open (kw...@redhat.com)
>  -Mention introduction of O_CLOEXEC (kw...@redhat.com)
> 
> v3:
>  -No changes
> 
>  block/raw-posix.c |   18 +-
>  block/raw-win32.c |4 ++--
>  block/vdi.c   |5 +++--
>  block/vmdk.c  |   21 +
>  block/vpc.c   |2 +-
>  block/vvfat.c |   21 +++--
>  6 files changed, 35 insertions(+), 36 deletions(-)
> 
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index 03fcfcc..d8eff2f 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -568,8 +568,8 @@ static int raw_create(const char *filename, 
> QEMUOptionParameter *options)
>  options++;
>  }
>  
> -fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
> -  0644);
> +fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
> +   0644);
>  if (fd < 0) {
>  result = -errno;
>  } else {
> @@ -741,7 +741,7 @@ static int hdev_open(BlockDriverState *bs, const char 
> *filename, int flags)
>  if ( bsdPath[ 0 ] != '\0' ) {
>  strcat(bsdPath,"s0");
>  /* some CDs don't have a partition 0 */
> -fd = open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE);
> +fd = qemu_open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE);
>  if (fd < 0) {
>  bsdPath[strlen(bsdPath)-1] = '1';
>  } else {
> @@ -798,7 +798,7 @@ static int fd_open(BlockDriverState *bs)
>  #endif
>  return -EIO;
>  }
> -s->fd = open(bs->filename, s->open_flags & ~O_NONBLOCK);
> +s->fd = qemu_open(bs->filename, s->open_flags & ~O_NONBLOCK);
>  if (s->fd < 0) {
>  s->fd_error_time = get_clock();
>  s->fd_got_error = 1;
> @@ -872,7 +872,7 @@ static int hdev_create(const char *filename, 
> QEMUOptionParameter *options)
>  options++;
>  }
>  
> -fd = open(filename, O_WRONLY | O_BINARY);
> +fd = qemu_open(filename, O_WRONLY | O_BINARY);
>  if (fd < 0)
>  return -errno;
>  
> @@ -950,7 +950,7 @@ static int floppy_probe_device(const char *filename)
>  if (strstart(filename, "/dev/fd", NULL))
>  prio = 50;
>  
> -fd = open(filename, O_RDONLY | O_NONBLOCK);
> +fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
>  if (fd < 0) {
>  goto out;
>  }
> @@ -1003,7 +1003,7 @@ static void floppy_eject(BlockDriverState *bs, bool 
> eject_flag)
>  close(s->fd);
>  s->fd = -1;
>  }
> -fd = open(bs->filename, s->open_flags | O_NONBLOCK);
> +fd = qemu_open(bs->filename, s->open_flags | O_NONBLOCK);
>  if (fd >= 0) {
>  if (ioctl(fd, FDEJECT, 0) < 0)
>  perror("FDEJECT");
> @@ -1053,7 +1053,7 @@ static int cdrom_probe_device(const char *filename)
>  int prio = 0;
>  struct stat st;
>  
> -fd = open(filename, O_RDONLY | O_NONBLOCK);
> +fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
>  if (fd < 0) {
>  goto out;
>  }
> @@ -1177,7 +1177,7 @@ static int cdrom_reopen(BlockDriverState *bs)
>   */
>  if (s->fd >= 0)
>  close(s->fd);
> -fd = open(bs->filename, s->open_flags, 0644);
> +fd = qemu_open(bs->filename, s->open_flags, 0644);
>  if (fd < 0) {
>  s->fd = -1;
>  return -EIO;
> diff --git a/block/raw-win32.c b/block/raw-win32.c
> index e4b0b75..8d7838d 100644
> --- a/block/raw-win32.c
> +++ b/block/raw-win32.c
> @@ -255,8 +255,8 @@ static int raw_create(const char *filename, 
> QEMUOptionParameter *options)
>  options++;
>  }
>  
> -fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
> -  0644);
> +fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
> +   0644);
>  if (fd < 0)
>  return -EIO;
>  set_sparse(fd);
> diff --git a/block/vdi.c b/block/vdi.c
> index 119d3c7..6183fdf 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -648,8 +648,9 @@ static int vdi_create(const char *filename, 
> QEMUOptionParameter *options)
>  options++;
>  }
>  
> -fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | 
> O_LARGEFILE,
> -  0644);
> +fd = qemu_open(f

Re: [Qemu-devel] [PATCH v3 5/5] block: Prevent /dev/fd/X filename from being detected as floppy

2012-06-15 Thread Luiz Capitulino
On Thu, 14 Jun 2012 11:55:05 -0400
Corey Bryant  wrote:

> Reported-by: Kevin Wolf 
> Reviewed-by: Paolo Bonzini 
> Signed-off-by: Corey Bryant 

This too, would be better to move before the /dev/fd/X feature so that we
avoid having introducing a bug and fixing it in a later commit. But again,
it's not a huge issue.

> ---
> v3:
>  -This patch is new in v3.  It was previously submitted on its
>   own, and is now being included in this series.
> 
>  block/raw-posix.c |4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index d8eff2f..68886cd 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -946,9 +946,11 @@ static int floppy_probe_device(const char *filename)
>  int prio = 0;
>  struct floppy_struct fdparam;
>  struct stat st;
> +const char *p;
>  
> -if (strstart(filename, "/dev/fd", NULL))
> +if (strstart(filename, "/dev/fd", &p) && p[0] != '/') {
>  prio = 50;
> +}
>  
>  fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
>  if (fd < 0) {




[Qemu-devel] [PATCH 14/39] block: Simplify how drive_init() computes default ID

2012-06-15 Thread Kevin Wolf
From: Markus Armbruster 

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 blockdev.c |7 ++-
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 622ecba..9e0a72a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -278,7 +278,6 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 {
 const char *buf;
 const char *file = NULL;
-char devname[128];
 const char *serial;
 const char *mediastr = "";
 BlockInterfaceType type;
@@ -318,7 +317,6 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 serial = qemu_opt_get(opts, "serial");
 
 if ((buf = qemu_opt_get(opts, "if")) != NULL) {
-pstrcpy(devname, sizeof(devname), buf);
 for (type = 0; type < IF_COUNT && strcmp(buf, if_name[type]); type++)
 ;
 if (type == IF_COUNT) {
@@ -327,7 +325,6 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
}
 } else {
 type = default_to_scsi ? IF_SCSI : IF_IDE;
-pstrcpy(devname, sizeof(devname), if_name[type]);
 }
 
 max_devs = if_max_devs[type];
@@ -523,10 +520,10 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
 if (max_devs)
 snprintf(dinfo->id, 32, "%s%i%s%i",
- devname, bus_id, mediastr, unit_id);
+ if_name[type], bus_id, mediastr, unit_id);
 else
 snprintf(dinfo->id, 32, "%s%s%i",
- devname, mediastr, unit_id);
+ if_name[type], mediastr, unit_id);
 }
 dinfo->bdrv = bdrv_new(dinfo->id);
 dinfo->devaddr = devaddr;
-- 
1.7.6.5




[Qemu-devel] [PATCH 35/39] qcow2: fix autoclear image header update

2012-06-15 Thread Kevin Wolf
From: Stefan Hajnoczi 

The autoclear feature bits can be used for qcow2 file format features
that are safe to "drop" by old programs that do not understand the
feature.  Upon opening the image file unknown autoclear feature bits are
cleared and the image file header is rewritten, but this was happening
too early in the code when critical header fields were not yet loaded.

Process autoclear feature bits after all necessary header information
has been loaded.

Signed-off-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 block/qcow2.c |   17 +
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 57fd43d..2c1cd0a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -297,14 +297,6 @@ static int qcow2_open(BlockDriverState *bs, int flags)
 goto fail;
 }
 
-if (!bs->read_only && s->autoclear_features != 0) {
-s->autoclear_features = 0;
-ret = qcow2_update_header(bs);
-if (ret < 0) {
-goto fail;
-}
-}
-
 /* Check support for various header values */
 if (header.refcount_order != 4) {
 report_unsupported(bs, "%d bit reference counts",
@@ -408,6 +400,15 @@ static int qcow2_open(BlockDriverState *bs, int flags)
 goto fail;
 }
 
+/* Clear unknown autoclear feature bits */
+if (!bs->read_only && s->autoclear_features != 0) {
+s->autoclear_features = 0;
+ret = qcow2_update_header(bs);
+if (ret < 0) {
+goto fail;
+}
+}
+
 /* Initialise locks */
 qemu_co_mutex_init(&s->lock);
 
-- 
1.7.6.5




Re: [Qemu-devel] [PATCH v2] qapi: converted commit

2012-06-15 Thread Luiz Capitulino
On Fri, 15 Jun 2012 10:11:46 -0400
Jeff Cody  wrote:

> On 06/15/2012 10:02 AM, Luiz Capitulino wrote:
> > On Thu, 14 Jun 2012 17:21:44 +0200
> > Pavel Hrdina  wrote:
> > 
> >> On 06/14/2012 05:04 PM, Eric Blake wrote:
> >>> On 06/14/2012 08:56 AM, Pavel Hrdina wrote:
>  On 06/14/2012 02:18 PM, Eric Blake wrote:
> > On 06/14/2012 01:35 AM, Pavel Hrdina wrote:
> >> Signed-off-by: Pavel Hrdina
> >> ---
> >> +++ b/qapi-schema.json
> >> @@ -1169,6 +1169,21 @@
> >>{ 'command': 'block_resize', 'data': { 'device': 'str', 'size':
> >> 'int' }}
> >>
> >>##
> >> +# @commit
> >> +#
> >> +# Commit changes to the disk images (if -snapshot is used) or
> >> backing files.
> >> +#
> >> +# @device: the name of the device or the "all" to commit all devices
> >> +#
> >> +# Returns: nothing on success
> >> +#  If @device is not a valid block device, DeviceNotFound
> >> +#  If a long-running operation is using the device, 
> >> DeviceInUse
> >> +#
> >> +# Since: 1.2
> >> +##
> >> +{ 'command': 'commit', 'data': { 'device': 'str' }}
> > Should we use this as an opportunity to make the command more powerful?
> >For example, integrating this with the 'transaction' command or a 
> > block
> > job queried by 'query-block-jobs' to track its progress would be useful.
> >Also, suppose I have A<- B<- C.  Does 'commit' only do one layer (C
> > into B), or all layers (B and C into A)?  That argues that we need an
> > optional parameter that says how deep to commit (committing C into B
> > only to repeat and commit B into A is more time-consuming than directly
> > committing both B and C into A to start with).  When a commit is
> > complete, which file is backing the device - is it still C (which
> > continues to diverge, but now from the point of the commit) or does qemu
> > pivot things to have the device now backed by B (and C can be discarded,
> > particularly true if changes are now going into B which invalidate C).
>  What i find out is that 'commit' will commit changes only from C to B
>  and qemu continues with C from the new commit point. I couldn't find a
>  way to commit changes and go back to backing file. This should be
>  supported by parameter and also as you mention that commit all changes
>  through all snapshots should be supported by another parameter.
>  The 'transaction' feature would be nice to have too.
> >>> Which makes it sound like we're starting to overlap with Jeff's work on
> >>> 'block-commit'.
> >>>
> >>> If 'block-commit' proves to be better all around at doing what we want,
> >>> do we even need to keep 'commit' in QMP, or would it be okay for HMP only?
> >> If the 'block-commit' will be better I think that we could drop the 
> >> 'commit' completely. And have only 'block-commit' for both QMP and HMP.
> > 
> > I completely agree about the QMP part, but for HMP it's a good idea to
> > maintain the commit command. To achieve this, we can implement hmp_commit()
> > in terms of block-commit.
> > 
> > Jeff, can you answer us here? Does block-commit supersedes the commit 
> > command
> > we have today?
> 
> The block-commit will supercede in functionality the commit command in
> place today, but it is a live operation - as such, it will take longer
> to complete, but it won't pause the guest.

This is very nice, is this being targeted for 1.2?



[Qemu-devel] [PATCH 10/39] qemu-img check: Print fixed clusters and recheck

2012-06-15 Thread Kevin Wolf
When any inconsistencies have been fixed, print the statistics and run
another check to make sure everything is correct now.

Signed-off-by: Kevin Wolf 
---
 block.h   |2 ++
 block/qed-check.c |2 ++
 qemu-img.c|   10 ++
 3 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/block.h b/block.h
index 61b7e8e..f8200eb 100644
--- a/block.h
+++ b/block.h
@@ -187,6 +187,8 @@ typedef struct BdrvCheckResult {
 int corruptions;
 int leaks;
 int check_errors;
+int corruptions_fixed;
+int leaks_fixed;
 BlockFragInfo bfi;
 } BdrvCheckResult;
 
diff --git a/block/qed-check.c b/block/qed-check.c
index 94327ff..5edf607 100644
--- a/block/qed-check.c
+++ b/block/qed-check.c
@@ -87,6 +87,7 @@ static unsigned int qed_check_l2_table(QEDCheck *check, 
QEDTable *table)
 if (!qed_check_cluster_offset(s, offset)) {
 if (check->fix) {
 table->offsets[i] = 0;
+check->result->corruptions_fixed++;
 } else {
 check->result->corruptions++;
 }
@@ -127,6 +128,7 @@ static int qed_check_l1_table(QEDCheck *check, QEDTable 
*table)
 /* Clear invalid offset */
 if (check->fix) {
 table->offsets[i] = 0;
+check->result->corruptions_fixed++;
 } else {
 check->result->corruptions++;
 }
diff --git a/qemu-img.c b/qemu-img.c
index c45ff62..9336c86 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -425,6 +425,16 @@ static int img_check(int argc, char **argv)
 return 1;
 }
 
+if (result.corruptions_fixed || result.leaks_fixed) {
+printf("The following inconsistencies were found and repaired:\n\n"
+   "%d leaked clusters\n"
+   "%d corruptions\n\n"
+   "Double checking the fixed image now...\n",
+   result.leaks_fixed,
+   result.corruptions_fixed);
+ret = bdrv_check(bs, &result, 0);
+}
+
 if (!(result.corruptions || result.leaks || result.check_errors)) {
 printf("No errors were found on the image.\n");
 } else {
-- 
1.7.6.5




Re: [Qemu-devel] Adding errno to QMP errors

2012-06-15 Thread Luiz Capitulino
On Wed, 13 Jun 2012 14:49:10 -0300
Luiz Capitulino  wrote:

> On Thu, 31 May 2012 16:54:47 +0200
> Paolo Bonzini  wrote:
> 
> > Wait, I think you're conflating two things.
> > 
> > One is "do not shoehorn errors into errno values".  So for QOM invalid 
> > values we
> > have PropertyValueBad, not a generic InvalidArgument value.  We convert 
> > everything
> > to Error rather than returning negative errno values and then returning 
> > generic
> > error codes, because those would be ugly and non-descriptive.  I agree with 
> > that.
> > 
> > The other is "when errors come straight from the OS, _do_ use errno values".
> > This is for OpenFileFailed, for the new socket errors and so on.  This is 
> > what
> > I am proposing.
> 
> [...]
> 
> > $ echo | sed p > /dev/full
> > sed: couldn't flush stdout: No space left on device
> >  ^^ error type
> > ^^  ^^^ arguments
> > 
> > That would become, in JSON:
> > 
> > { 'error': 'FlushFailed',
> >   'file': 'stdout',
> >   'os_error': 'enospc' }
> 
> This is not a new discussion and what we're doing today is to return errno
> as a QError class name. So, for the example above we'd return something like:
> 
>  { 'error': 'NoSpace' }
> 
> It's possible to add new optional values if you need more information, but
> I know that that's not what you're asking.
> 
> I mostly agree that your version would be better, the only problem I see
> is that this is probably going to mess a bit more our API as we have been
> doing like my example above for some time.
> 
> Anthony, the current design was mostly influenced by you and you had
> objections on doing what Paolo and Kevin are suggesting. What do you think?

Ping?

We have to reach a consensus of this because this is holding qapi conversions.



[Qemu-devel] [PATCH 05/39] stream: move is_allocated_above to block.c

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 block.c|   49 +
 block.h|4 
 block/stream.c |   53 ++---
 3 files changed, 55 insertions(+), 51 deletions(-)

diff --git a/block.c b/block.c
index 7547051..c07ff39 100644
--- a/block.c
+++ b/block.c
@@ -2569,6 +2569,55 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t 
sector_num, int nb_sectors,
 return data.ret;
 }
 
+/*
+ * Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP]
+ *
+ * Return true if the given sector is allocated in any image between
+ * BASE and TOP (inclusive).  BASE can be NULL to check if the given
+ * sector is allocated in any image of the chain.  Return false otherwise.
+ *
+ * 'pnum' is set to the number of sectors (including and immediately following
+ *  the specified sector) that are known to be in the same
+ *  allocated/unallocated state.
+ *
+ */
+int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top,
+BlockDriverState *base,
+int64_t sector_num,
+int nb_sectors, int *pnum)
+{
+BlockDriverState *intermediate;
+int ret, n = nb_sectors;
+
+intermediate = top;
+while (intermediate && intermediate != base) {
+int pnum_inter;
+ret = bdrv_co_is_allocated(intermediate, sector_num, nb_sectors,
+   &pnum_inter);
+if (ret < 0) {
+return ret;
+} else if (ret) {
+*pnum = pnum_inter;
+return 1;
+}
+
+/*
+ * [sector_num, nb_sectors] is unallocated on top but intermediate
+ * might have
+ *
+ * [sector_num+x, nr_sectors] allocated.
+ */
+if (n > pnum_inter) {
+n = pnum_inter;
+}
+
+intermediate = intermediate->backing_hd;
+}
+
+*pnum = n;
+return 0;
+}
+
 BlockInfoList *qmp_query_block(Error **errp)
 {
 BlockInfoList *head = NULL, *cur_item = NULL;
diff --git a/block.h b/block.h
index 7408acc..799cf48 100644
--- a/block.h
+++ b/block.h
@@ -165,6 +165,10 @@ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState 
*bs, int64_t sector_num,
 int nb_sectors);
 int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num,
 int nb_sectors, int *pnum);
+int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top,
+BlockDriverState *base,
+int64_t sector_num,
+int nb_sectors, int *pnum);
 BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
 const char *backing_file);
 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
diff --git a/block/stream.c b/block/stream.c
index 4490a25..811388a 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -98,55 +98,6 @@ static void close_unused_images(BlockDriverState *top, 
BlockDriverState *base,
 top->backing_hd = base;
 }
 
-/*
- * Given an image chain: [BASE] -> [INTER1] -> [INTER2] -> [TOP]
- *
- * Return true if the given sector is allocated in any image between
- * BASE and TOP (inclusive).  BASE can be NULL to check if the given
- * sector is allocated in any image of the chain.  Return false otherwise.
- *
- * 'pnum' is set to the number of sectors (including and immediately following
- *  the specified sector) that are known to be in the same
- *  allocated/unallocated state.
- *
- */
-static int coroutine_fn is_allocated_above(BlockDriverState *top,
-   BlockDriverState *base,
-   int64_t sector_num,
-   int nb_sectors, int *pnum)
-{
-BlockDriverState *intermediate;
-int ret, n = nb_sectors;
-
-intermediate = top;
-while (intermediate != base) {
-int pnum_inter;
-ret = bdrv_co_is_allocated(intermediate, sector_num, nb_sectors,
-   &pnum_inter);
-if (ret < 0) {
-return ret;
-} else if (ret) {
-*pnum = pnum_inter;
-return 1;
-}
-
-/*
- * [sector_num, nb_sectors] is unallocated on top but intermediate
- * might have
- *
- * [sector_num+x, nr_sectors] allocated.
- */
-if (n > pnum_inter) {
-n = pnum_inter;
-}
-
-intermediate = intermediate->backing_hd;
-}
-
-*pnum = n;
-return 0;
-}
-
 static void coroutine_fn stream_run(void *opaque)
 {
 StreamBlockJob *s = opaque;
@@ -196,10 +147,10 @@ wait:
 } else {
 /* Copy if allocated in the intermediate images.  Limit to the
  * known-unallocated area [sector_num, sector_num+n).

[Qemu-devel] [PATCH 02/39] qcow2: fix endianness conversion

2012-06-15 Thread Kevin Wolf
From: Zhi Yong Wu 

Signed-off-by: Zhi Yong Wu 
Reviewed-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 block/qcow2-refcount.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 812c93c..443c021 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -367,7 +367,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
 }
 
 for(i = 0; i < table_size; i++) {
-cpu_to_be64s(&new_table[i]);
+be64_to_cpus(&new_table[i]);
 }
 
 /* Hook up the new refcount table in the qcow2 header */
-- 
1.7.6.5




Re: [Qemu-devel] [PATCH 0/3] xilinx: Speed up the build

2012-06-15 Thread Andreas Färber
Am 15.06.2012 13:13, schrieb Edgar E. Iglesias:
> On Sat, Jun 09, 2012 at 03:54:28AM +0200, Andreas Färber wrote:
>> Hello Edgar and Peter,
>>
>> With the Makefile refactoring applied now, here's the Makefile improvements
>> for MicroBlaze I mentioned.
>>
>> All Xilinx devices that are used for more than one softmmu are compiled once
>> in libhw32. Actually some also in libhw64 due to ppc440 being compiled into
>> ppc64, but we can fix that in a second step via Alex' ppc-next, we're already
>> down from thrice to twice.
>>
>> The middle patch is extracted from Blue's logging refactoring.
>>
>> Please test and apply. Your s3adp1800 and virtel_ml507 test images complain
>> both with and without patches about not finding "eth0". Selftest completes ok
>> except for not finding /usr/bin/sha1test on ppc440.
>>
>> xilinx_ethlite.c uses tswap32(). Have you ever tested this device to work on
>> microblazeel? I wonder if we could change the device from 
>> DEVICE_NATIVE_ENDIAN
>> to DEVICE_BIG_ENDIAN and in place of tswap32() use a bswap32() conditional on
>> HOST_WORDS_BIGENDIAN so that it becomes independent of the target, too?
>>
>> Instead of adding random devices to hw/microblaze/Makefile.objs in new 
>> series,
>> they should be added to hw/Makefile.objs with appropriate CONFIG_* options 
>> set
>> in default-configs/microblaze[el]-softmmu.mak as demonstrated here, easy to 
>> do
>> and also ensures that the appropriate poisoning is applied.
> 
> Applied the series, thanks Andreas.

Thanks, but didn't you want CONFIG_XILINX renamed? :)

Andreas

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



[Qemu-devel] [PATCH 37/39] fdc-test: introduced qtest read_without_media

2012-06-15 Thread Kevin Wolf
From: Pavel Hrdina 

If you try to read from a floppy drive without a media, you should get
an abnormal termination error.

Signed-off-by: Pavel Hrdina 
Signed-off-by: Kevin Wolf 
---
 tests/fdc-test.c |   66 ++
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/tests/fdc-test.c b/tests/fdc-test.c
index 22d24ac..e730398 100644
--- a/tests/fdc-test.c
+++ b/tests/fdc-test.c
@@ -49,6 +49,7 @@ enum {
 enum {
 CMD_SENSE_INT   = 0x08,
 CMD_SEEK= 0x0f,
+CMD_READ= 0xe6,
 };
 
 enum {
@@ -99,6 +100,62 @@ static void ack_irq(void)
 g_assert(!get_irq(FLOPPY_IRQ));
 }
 
+static uint8_t send_read_command(void)
+{
+uint8_t drive = 0;
+uint8_t head = 0;
+uint8_t cyl = 0;
+uint8_t sect_addr = 1;
+uint8_t sect_size = 2;
+uint8_t eot = 1;
+uint8_t gap = 0x1b;
+uint8_t gpl = 0xff;
+
+uint8_t msr = 0;
+uint8_t st0;
+
+uint8_t ret = 0;
+
+floppy_send(CMD_READ);
+floppy_send(head << 2 | drive);
+g_assert(!get_irq(FLOPPY_IRQ));
+floppy_send(cyl);
+floppy_send(head);
+floppy_send(sect_addr);
+floppy_send(sect_size);
+floppy_send(eot);
+floppy_send(gap);
+floppy_send(gpl);
+
+uint8_t i = 0;
+uint8_t n = 2;
+for (; i < n; i++) {
+msr = inb(FLOPPY_BASE + reg_msr);
+if (msr == 0xd0) {
+break;
+}
+sleep(1);
+}
+
+if (i >= n) {
+return 1;
+}
+
+st0 = floppy_recv();
+if (st0 != 0x40) {
+ret = 1;
+}
+
+floppy_recv();
+floppy_recv();
+floppy_recv();
+floppy_recv();
+floppy_recv();
+floppy_recv();
+
+return ret;
+}
+
 static void send_step_pulse(void)
 {
 int drive = 0;
@@ -146,6 +203,14 @@ static void test_no_media_on_start(void)
 assert_bit_set(dir, DSKCHG);
 }
 
+static void test_read_without_media(void)
+{
+uint8_t ret;
+
+ret = send_read_command();
+g_assert(ret == 0);
+}
+
 static void test_media_change(void)
 {
 uint8_t dir;
@@ -214,6 +279,7 @@ int main(int argc, char **argv)
 qtest_irq_intercept_in(global_qtest, "ioapic");
 qtest_add_func("/fdc/cmos", test_cmos);
 qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
+qtest_add_func("/fdc/read_without_media", test_read_without_media);
 qtest_add_func("/fdc/media_change", test_media_change);
 
 ret = g_test_run();
-- 
1.7.6.5




[Qemu-devel] [PATCH 06/39] stream: move rate limiting to a separate header file

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

Make the code reusable.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 block/stream.c   |   31 +---
 include/qemu/ratelimit.h |   48 ++
 2 files changed, 50 insertions(+), 29 deletions(-)
 create mode 100644 include/qemu/ratelimit.h

diff --git a/block/stream.c b/block/stream.c
index 811388a..37c4652 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -13,6 +13,7 @@
 
 #include "trace.h"
 #include "block_int.h"
+#include "qemu/ratelimit.h"
 
 enum {
 /*
@@ -25,34 +26,6 @@ enum {
 
 #define SLICE_TIME 1ULL /* ns */
 
-typedef struct {
-int64_t next_slice_time;
-uint64_t slice_quota;
-uint64_t dispatched;
-} RateLimit;
-
-static int64_t ratelimit_calculate_delay(RateLimit *limit, uint64_t n)
-{
-int64_t now = qemu_get_clock_ns(rt_clock);
-
-if (limit->next_slice_time < now) {
-limit->next_slice_time = now + SLICE_TIME;
-limit->dispatched = 0;
-}
-if (limit->dispatched == 0 || limit->dispatched + n <= limit->slice_quota) 
{
-limit->dispatched += n;
-return 0;
-} else {
-limit->dispatched = n;
-return limit->next_slice_time - now;
-}
-}
-
-static void ratelimit_set_speed(RateLimit *limit, uint64_t speed)
-{
-limit->slice_quota = speed / (10ULL / SLICE_TIME);
-}
-
 typedef struct StreamBlockJob {
 BlockJob common;
 RateLimit limit;
@@ -198,7 +171,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, 
Error **errp)
 error_set(errp, QERR_INVALID_PARAMETER, "speed");
 return;
 }
-ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE);
+ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
 }
 
 static BlockJobType stream_job_type = {
diff --git a/include/qemu/ratelimit.h b/include/qemu/ratelimit.h
new file mode 100644
index 000..c6ac281
--- /dev/null
+++ b/include/qemu/ratelimit.h
@@ -0,0 +1,48 @@
+/*
+ * Ratelimiting calculations
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Stefan Hajnoczi   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_RATELIMIT_H
+#define QEMU_RATELIMIT_H 1
+
+typedef struct {
+int64_t next_slice_time;
+uint64_t slice_quota;
+uint64_t slice_ns;
+uint64_t dispatched;
+} RateLimit;
+
+static inline int64_t ratelimit_calculate_delay(RateLimit *limit, uint64_t n)
+{
+int64_t now = qemu_get_clock_ns(rt_clock);
+
+if (limit->next_slice_time < now) {
+limit->next_slice_time = now + limit->slice_ns;
+limit->dispatched = 0;
+}
+if (limit->dispatched == 0 || limit->dispatched + n <= limit->slice_quota) 
{
+limit->dispatched += n;
+return 0;
+} else {
+limit->dispatched = n;
+return limit->next_slice_time - now;
+}
+}
+
+static inline void ratelimit_set_speed(RateLimit *limit, uint64_t speed,
+   uint64_t slice_ns)
+{
+limit->slice_ns = slice_ns;
+limit->slice_quota = ((double)speed * 10ULL) / slice_ns;
+}
+
+#endif
-- 
1.7.6.5




[Qemu-devel] [PATCH 04/39] stream: tweak usage of bdrv_co_is_allocated

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

is_allocated_base has complex semantics that are not really usable
outside streaming.  Split the check in two parts, where the allocated
state for the top bs is moved to the caller.  The resulting function
is more generally useful.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 block/stream.c |   51 +--
 1 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/block/stream.c b/block/stream.c
index 8e58322..4490a25 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -101,45 +101,33 @@ static void close_unused_images(BlockDriverState *top, 
BlockDriverState *base,
 /*
  * Given an image chain: [BASE] -> [INTER1] -> [INTER2] -> [TOP]
  *
- * Return true if the given sector is allocated in top.
- * Return false if the given sector is allocated in intermediate images.
- * Return true otherwise.
+ * Return true if the given sector is allocated in any image between
+ * BASE and TOP (inclusive).  BASE can be NULL to check if the given
+ * sector is allocated in any image of the chain.  Return false otherwise.
  *
  * 'pnum' is set to the number of sectors (including and immediately following
  *  the specified sector) that are known to be in the same
  *  allocated/unallocated state.
  *
  */
-static int coroutine_fn is_allocated_base(BlockDriverState *top,
-  BlockDriverState *base,
-  int64_t sector_num,
-  int nb_sectors, int *pnum)
+static int coroutine_fn is_allocated_above(BlockDriverState *top,
+   BlockDriverState *base,
+   int64_t sector_num,
+   int nb_sectors, int *pnum)
 {
 BlockDriverState *intermediate;
-int ret, n;
-
-ret = bdrv_co_is_allocated(top, sector_num, nb_sectors, &n);
-if (ret) {
-*pnum = n;
-return ret;
-}
-
-/*
- * Is the unallocated chunk [sector_num, n] also
- * unallocated between base and top?
- */
-intermediate = top->backing_hd;
+int ret, n = nb_sectors;
 
+intermediate = top;
 while (intermediate != base) {
 int pnum_inter;
-
 ret = bdrv_co_is_allocated(intermediate, sector_num, nb_sectors,
&pnum_inter);
 if (ret < 0) {
 return ret;
 } else if (ret) {
 *pnum = pnum_inter;
-return 0;
+return 1;
 }
 
 /*
@@ -156,7 +144,7 @@ static int coroutine_fn is_allocated_base(BlockDriverState 
*top,
 }
 
 *pnum = n;
-return 1;
+return 0;
 }
 
 static void coroutine_fn stream_run(void *opaque)
@@ -189,6 +177,7 @@ static void coroutine_fn stream_run(void *opaque)
 
 for (sector_num = 0; sector_num < end; sector_num += n) {
 uint64_t delay_ns = 0;
+bool copy;
 
 wait:
 /* Note that even when no rate limit is applied we need to yield
@@ -199,10 +188,20 @@ wait:
 break;
 }
 
-ret = is_allocated_base(bs, base, sector_num,
-STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
+ret = bdrv_co_is_allocated(bs, sector_num,
+   STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
+if (ret == 1) {
+/* Allocated in the top, no need to copy.  */
+copy = false;
+} else {
+/* Copy if allocated in the intermediate images.  Limit to the
+ * known-unallocated area [sector_num, sector_num+n).  */
+ret = is_allocated_above(bs->backing_hd, base, sector_num, n, &n);
+copy = (ret == 1);
+}
+
 trace_stream_one_iteration(s, sector_num, n, ret);
-if (ret == 0) {
+if (ret >= 0 && copy) {
 if (s->common.speed) {
 delay_ns = ratelimit_calculate_delay(&s->limit, n);
 if (delay_ns > 0) {
-- 
1.7.6.5




[Qemu-devel] [PATCH 28/39] qcow2: Fix avail_sectors in cluster allocation code

2012-06-15 Thread Kevin Wolf
avail_sectors should really be the number of sectors from the start of
the allocation, not from the start of the write request.

We're lucky enough that this mistake didn't cause any real bug.
avail_sectors is only used in the intialiser of QCowL2Meta:

  .nb_available   = MIN(requested_sectors, avail_sectors),

m->nb_available in turn is only used for COW at the end of the
allocation. A COW occurs only if the request wasn't cluster aligned,
which in turn would imply that requested_sectors was less than
avail_sectors (both in the original and in the fixed version). In this
case avail_sectors is ignored and therefore the mistake doesn't cause
any misbehaviour.

Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 98fba71..d7e0e19 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -947,8 +947,16 @@ again:
 
 /* save info needed for meta data update */
 if (nb_clusters > 0) {
+/*
+ * requested_sectors: Number of sectors from the start of the first
+ * newly allocated cluster to the end of the (possibly shortened
+ * before) write request.
+ *
+ * avail_sectors: Number of sectors from the start of the first
+ * newly allocated to the end of the last newly allocated cluster.
+ */
 int requested_sectors = n_end - keep_clusters * s->cluster_sectors;
-int avail_sectors = (keep_clusters + nb_clusters)
+int avail_sectors = nb_clusters
 << (s->cluster_bits - BDRV_SECTOR_BITS);
 
 *m = (QCowL2Meta) {
-- 
1.7.6.5




[Qemu-devel] [PATCH 18/39] qemu-iotests: fill streaming test image with data

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

The TestStreamStop test case is racy; if the job completes before we can
cancel it, it fails.  If we remove the sleep the job will be canceled
before it has even started, and the test succeeds but it is also not
testing anything interesting.

But if the image is left sparse, then the job has really nothing to do.
For qcow2 it will read one L2-table, for raw it will issue a bunch of
ioctls.  This also falls under "not testing anything interesting", and
this may be happening right now (depending on the filesystem) since the
file protocol got an is_allocated method.

Filling the test image with data ensures that the test covers the
intended case.  It also slows down the test, which will be particularly
important after the next patch.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 tests/qemu-iotests/030 |   13 -
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
index eb7bf99..4ab7d62 100755
--- a/tests/qemu-iotests/030
+++ b/tests/qemu-iotests/030
@@ -21,6 +21,7 @@
 import os
 import iotests
 from iotests import qemu_img, qemu_io
+import struct
 
 backing_img = os.path.join(iotests.test_dir, 'backing.img')
 mid_img = os.path.join(iotests.test_dir, 'mid.img')
@@ -48,11 +49,21 @@ class ImageStreamingTestCase(iotests.QMPTestCase):
 
 self.assert_no_active_streams()
 
+def create_image(self, name, size):
+file = open(name, 'w')
+i = 0
+while i < size:
+sector = struct.pack('>l504xl', i / 512, i / 512)
+file.write(sector)
+i = i + 512
+file.close()
+
+
 class TestSingleDrive(ImageStreamingTestCase):
 image_len = 1 * 1024 * 1024 # MB
 
 def setUp(self):
-qemu_img('create', backing_img, str(TestSingleDrive.image_len))
+self.create_image(backing_img, TestSingleDrive.image_len)
 qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
backing_img, mid_img)
 qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
mid_img, test_img)
 self.vm = iotests.VM().add_drive(test_img)
-- 
1.7.6.5




[Qemu-devel] [PATCH 24/39] block: always open drivers in writeback mode

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

Formats are entirely in charge of flushes for metadata writes.  For
guest-initiated writes, a writethrough cache is faked in the block layer.
So we can always open in writeback mode.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 block.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/block.c b/block.c
index e4396a6..48528fd 100644
--- a/block.c
+++ b/block.c
@@ -649,12 +649,13 @@ static int bdrv_open_common(BlockDriverState *bs, const 
char *filename,
 bs->opaque = g_malloc0(drv->instance_size);
 
 bs->enable_write_cache = !!(flags & BDRV_O_CACHE_WB);
+open_flags = flags | BDRV_O_CACHE_WB;
 
 /*
  * Clear flags that are internal to the block layer before opening the
  * image.
  */
-open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
+open_flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
 
 /*
  * Snapshots should be writable.
-- 
1.7.6.5




Re: [Qemu-devel] USB hardware simulation in external process

2012-06-15 Thread Daniel Mack
On 12.06.2012 09:56, Dor Laor wrote:
> On 06/11/2012 05:48 PM, Daniel Mack wrote:
>> Hey,
>>
>> I'm thinking about adding a USB hardware proxy that allows communication
>> with an external server process which in turn simulates USB devices.
>>
>> I'm new to the internals of QEMU, so what I'm sharing here might already
>> have been discussed a gazillion times. In that case, just drop me some
>> pointers.
>>
>> I want to try and outline the idea following a real-life example. As an
>> USB driver kernel developer, I often face the situation that people
>> report problems and send their lsusb dumps along with a description of
>> kernel level misbehaviour they're seeing. Sometimes things are rather
>> obvious, in other cases, it is mandatory to have hardware access to the
>> device in order to reproduce and fix the issue.
>>
>> In a recent case[1], I chose a different approach for the first time: I
>> simulated a device with a broken descriptor set by adding a dirty hack
>> to an existing virtual USB device inside QEMU. This worked surprisingly
>> well: the hosted kernel showed the reported behaviour and I could
>> finally fix it within minutes.
>>
>> So that made me thinking. Wouldn't it be possible to add a communication
>> layer to QEMU that connects to an external server which acts as emulator
>> for all sorts of USB devices? That way, I could keep the broken device
>> implementation around for later regression testing, at a place where it
>> doesn't bother anyone. Thinking further, there could be a growing number
>> of devices that either misbehave in a certain way or just simulate a
>> certain function, and along with some test code, this could be used as
>> automated function and regression test for new kernel versions. Tests
>> could also include arbitrary connection/disconnection of devices to
>> stress test the stack and provoke race conditions and all the like.
>>
>> The reason for having it hosted by an external process is to have a
>> clear separation of the emulator itself and the part that throws dirt at
>> the stack implementation. (It would also be possible to use a
>> object-oriented scripting language for easy integration of new hardware
>> models).
>>
>> I wonder whether such an approach is feasible and worth thinking about.
>> If it is, what would be a sane communication protocol? It would need to
>> be something fully bidirectional. I know there is QMP, but I'm not sure
>> whether it would be usable for this purpose.
> 
> Have you looked at spice's usb redirection [1]?
> If you're emulate the usb device on a separate process you can connect 
> it to qemu using spice.

(Cc: Hans)

Thanks a lot for the pointer! This sounds infact interesting and I've
had a similar server/client model in mind.

Unfortunately though, the protocol spoken by libusbredir is not exactly
what I'm looking for, as it is too "high level" for what I want to
achieve. Naturally, libusbredir was written for well-behaving devices
and skips most of the low-level USB protocol parsers, state machines and
the like. Which makes sense for getting the job done.

However, what I'm trying to do is simulate devices that misbehave
explicitly, to test how the descriptor parsers in Linux drivers deal
with them. Hence, all communication between the client and the server
should be broken down to control/interrupt/bulk/iso transfers, and the
server would need to implement all the low-level USB protocol functions
itself. In other words: the server would need to handle the same data
streams a typical firmware deals with.

Hans, would there be a way to implement this in libusbredir? I'm
thinking about a capability flag that states something like "this server
is only able to serve low-level requests". Not sure though how tricky it
would be to handle this in the QEMU client. Opinions?


Thanks,
Daniel




[Qemu-devel] [PATCH 33/39] xen: Don't change -drive if=xen device name during machine init

2012-06-15 Thread Kevin Wolf
From: Markus Armbruster 

A "top" BlockDriverState has a non-empty device_name.  If the user
doesn't specify one with -drive parameter id, the system supplies a
default name.

xen_config_dev_blk() changes this name, during machine initialization.
Naughty.  Don't do that.

Signed-off-by: Markus Armbruster 
Acked-by: Stefano Stabellini 
Signed-off-by: Kevin Wolf 
---
 hw/xen_devconfig.c |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/xen_devconfig.c b/hw/xen_devconfig.c
index 41accbb..7b7b0a2 100644
--- a/hw/xen_devconfig.c
+++ b/hw/xen_devconfig.c
@@ -94,16 +94,15 @@ static int xen_config_dev_all(char *fe, char *be)
 
 int xen_config_dev_blk(DriveInfo *disk)
 {
-char fe[256], be[256];
+char fe[256], be[256], device_name[32];
 int vdev = 202 * 256 + 16 * disk->unit;
 int cdrom = disk->media_cd;
 const char *devtype = cdrom ? "cdrom" : "disk";
 const char *mode= cdrom ? "r" : "w";
 
-snprintf(disk->bdrv->device_name, sizeof(disk->bdrv->device_name),
-"xvd%c", 'a' + disk->unit);
+snprintf(device_name, sizeof(device_name), "xvd%c", 'a' + disk->unit);
 xen_be_printf(NULL, 1, "config disk %d [%s]: %s\n",
-  disk->unit, disk->bdrv->device_name, disk->bdrv->filename);
+  disk->unit, device_name, disk->bdrv->filename);
 xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe));
 
 /* frontend */
@@ -111,7 +110,7 @@ int xen_config_dev_blk(DriveInfo *disk)
 xenstore_write_str(fe, "device-type", devtype);
 
 /* backend */
-xenstore_write_str(be, "dev", disk->bdrv->device_name);
+xenstore_write_str(be, "dev", device_name);
 xenstore_write_str(be, "type","file");
 xenstore_write_str(be, "params",  disk->bdrv->filename);
 xenstore_write_str(be, "mode",mode);
-- 
1.7.6.5




[Qemu-devel] [PATCH 29/39] qemu-iotests: Some backing file COW tests

2012-06-15 Thread Kevin Wolf
Looks like we're still missing these very basic tests for backing file
handling.

Signed-off-by: Kevin Wolf 
Reviewed-by: Paolo Bonzini 
---
 tests/qemu-iotests/037 |  119 
 tests/qemu-iotests/037.out |  645 
 tests/qemu-iotests/group   |1 +
 3 files changed, 765 insertions(+), 0 deletions(-)
 create mode 100755 tests/qemu-iotests/037
 create mode 100644 tests/qemu-iotests/037.out

diff --git a/tests/qemu-iotests/037 b/tests/qemu-iotests/037
new file mode 100755
index 000..c11460b
--- /dev/null
+++ b/tests/qemu-iotests/037
@@ -0,0 +1,119 @@
+#!/bin/bash
+#
+# Test COW from backing files
+#
+# Copyright (C) 2012 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+#
+
+# creator
+owner=kw...@redhat.com
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1   # failure is the default!
+
+_cleanup()
+{
+   _cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_supported_fmt qcow qcow2 vmdk qed
+_supported_proto generic
+_supported_os Linux
+
+CLUSTER_SIZE=4k
+size=128M
+
+echo
+echo "== creating backing file for COW tests =="
+
+_make_test_img $size
+
+function backing_io()
+{
+local offset=$1
+local sectors=$2
+local op=$3
+local pattern=0
+local cur_sec=0
+
+for i in $(seq 0 $((sectors - 1))); do
+cur_sec=$((offset / 512 + i))
+pattern=$(( ( (cur_sec % 256) + (cur_sec / 256)) % 256 ))
+
+echo "$op -P $pattern $((cur_sec * 512)) 512"
+done
+}
+
+backing_io 0 256 write | $QEMU_IO $TEST_IMG | _filter_qemu_io
+
+mv $TEST_IMG $TEST_IMG.base
+
+_make_test_img -b $TEST_IMG.base 6G
+
+echo
+echo "== COW in a single cluster =="
+$QEMU_IO -c "write -P 0x77 0 2k" $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "write -P 0x88 6k 2k" $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "write -P 0x99 9k 2k" $TEST_IMG | _filter_qemu_io
+
+$QEMU_IO -c "read -P 0x77 0 2k" $TEST_IMG | _filter_qemu_io
+backing_io $((2 * 1024)) 8 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "read -P 0x88 6k 2k" $TEST_IMG | _filter_qemu_io
+backing_io $((8 * 1024)) 2 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "read -P 0x99 9k 2k" $TEST_IMG | _filter_qemu_io
+backing_io $((11 * 1024)) 2 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+
+echo
+echo "== COW in two-cluster allocations =="
+$QEMU_IO -c "write -P 0x77 16k 6k" $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "write -P 0x88 26k 6k" $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "write -P 0x99 33k 5k" $TEST_IMG | _filter_qemu_io
+
+$QEMU_IO -c "read -P 0x77 16k 6k" $TEST_IMG | _filter_qemu_io
+backing_io $((22 * 1024)) 8 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "read -P 0x88 26k 6k" $TEST_IMG | _filter_qemu_io
+backing_io $((32 * 1024)) 2 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "read -P 0x99 33k 5k" $TEST_IMG | _filter_qemu_io
+backing_io $((38 * 1024)) 4 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+
+echo
+echo "== COW in multi-cluster allocations =="
+$QEMU_IO -c "write -P 0x77 48k 15k" $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "write -P 0x88 66k 14k" $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "write -P 0x99 83k 15k" $TEST_IMG | _filter_qemu_io
+
+$QEMU_IO -c "read -P 0x77 48k 15k" $TEST_IMG | _filter_qemu_io
+backing_io $((63 * 1024)) 6 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "read -P 0x88 66k 14k" $TEST_IMG | _filter_qemu_io
+backing_io $((80 * 1024)) 6 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c "read -P 0x99 83k 15k" $TEST_IMG | _filter_qemu_io
+backing_io $((98 * 1024)) 4 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
+
+_check_test_img
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/037.out b/tests/qemu-iotests/037.out
new file mode 100644
index 000..deb8a3b
--- /dev/null
+++ b/tests/qemu-iotests/037.out
@@ -0,0 +1,645 @@
+QA output created by 037
+
+== creating backing file for COW tests ==
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
+qemu-io> wrote 512/512 bytes at offset 0
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+qemu-io> wrote 512/512 bytes at offset 512
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+qemu-io> wrote 512/512 bytes at offset 1024
+512 bytes, X ops; XX:XX:XX.X 

[Qemu-devel] [PATCH 26/39] qcow2: always operate caches in writeback mode

2012-06-15 Thread Kevin Wolf
From: Paolo Bonzini 

Writethrough does not need special-casing anymore in the qcow2 caches.
The block layer adds flushes after every guest-initiated data write,
and these will also flush the qcow2 caches to the OS.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 block/qcow2-cache.c|   25 ++---
 block/qcow2-refcount.c |   12 
 block/qcow2.c  |7 ++-
 block/qcow2.h  |5 +
 4 files changed, 5 insertions(+), 44 deletions(-)

diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 710d4b1..2d4322a 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -40,11 +40,9 @@ struct Qcow2Cache {
 struct Qcow2Cache*  depends;
 int size;
 booldepends_on_flush;
-boolwritethrough;
 };
 
-Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
-bool writethrough)
+Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables)
 {
 BDRVQcowState *s = bs->opaque;
 Qcow2Cache *c;
@@ -53,7 +51,6 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int 
num_tables,
 c = g_malloc0(sizeof(*c));
 c->size = num_tables;
 c->entries = g_malloc0(sizeof(*c->entries) * num_tables);
-c->writethrough = writethrough;
 
 for (i = 0; i < c->size; i++) {
 c->entries[i].table = qemu_blockalign(bs, s->cluster_size);
@@ -307,12 +304,7 @@ found:
 *table = NULL;
 
 assert(c->entries[i].ref >= 0);
-
-if (c->writethrough) {
-return qcow2_cache_entry_flush(bs, c, i);
-} else {
-return 0;
-}
+return 0;
 }
 
 void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table)
@@ -329,16 +321,3 @@ void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void 
*table)
 found:
 c->entries[i].dirty = true;
 }
-
-bool qcow2_cache_set_writethrough(BlockDriverState *bs, Qcow2Cache *c,
-bool enable)
-{
-bool old = c->writethrough;
-
-if (!old && enable) {
-qcow2_cache_flush(bs, c);
-}
-
-c->writethrough = enable;
-return old;
-}
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 5d6ea72..66f3915 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -726,13 +726,6 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 int64_t old_offset, old_l2_offset;
 int i, j, l1_modified = 0, nb_csectors, refcount;
 int ret;
-bool old_l2_writethrough, old_refcount_writethrough;
-
-/* Switch caches to writeback mode during update */
-old_l2_writethrough =
-qcow2_cache_set_writethrough(bs, s->l2_table_cache, false);
-old_refcount_writethrough =
-qcow2_cache_set_writethrough(bs, s->refcount_block_cache, false);
 
 l2_table = NULL;
 l1_table = NULL;
@@ -856,11 +849,6 @@ fail:
 qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
 }
 
-/* Enable writethrough cache mode again */
-qcow2_cache_set_writethrough(bs, s->l2_table_cache, old_l2_writethrough);
-qcow2_cache_set_writethrough(bs, s->refcount_block_cache,
-old_refcount_writethrough);
-
 /* Update L1 only if it isn't deleted anyway (addend = -1) */
 if (addend >= 0 && l1_modified) {
 for(i = 0; i < l1_size; i++)
diff --git a/block/qcow2.c b/block/qcow2.c
index d66de58..57fd43d 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -220,7 +220,6 @@ static int qcow2_open(BlockDriverState *bs, int flags)
 int len, i, ret = 0;
 QCowHeader header;
 uint64_t ext_end;
-bool writethrough;
 
 ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
 if (ret < 0) {
@@ -367,10 +366,8 @@ static int qcow2_open(BlockDriverState *bs, int flags)
 }
 
 /* alloc L2 table/refcount block cache */
-writethrough = ((flags & BDRV_O_CACHE_WB) == 0);
-s->l2_table_cache = qcow2_cache_create(bs, L2_CACHE_SIZE, writethrough);
-s->refcount_block_cache = qcow2_cache_create(bs, REFCOUNT_CACHE_SIZE,
-writethrough);
+s->l2_table_cache = qcow2_cache_create(bs, L2_CACHE_SIZE);
+s->refcount_block_cache = qcow2_cache_create(bs, REFCOUNT_CACHE_SIZE);
 
 s->cluster_cache = g_malloc(s->cluster_size);
 /* one more sector for decompressed data alignment */
diff --git a/block/qcow2.h b/block/qcow2.h
index c6e7237..455b6d7 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -297,11 +297,8 @@ void qcow2_free_snapshots(BlockDriverState *bs);
 int qcow2_read_snapshots(BlockDriverState *bs);
 
 /* qcow2-cache.c functions */
-Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
-bool writethrough);
+Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables);
 int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c);
-bool qcow2_cache_set_writethrough(BlockDriverState *bs, Qcow2Cache *c,
-bool enable);
 
 void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
 int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
-- 
1.7.6.5




Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add pass-fd QMP command

2012-06-15 Thread Corey Bryant



On 06/15/2012 10:32 AM, Luiz Capitulino wrote:

On Thu, 14 Jun 2012 11:55:02 -0400
Corey Bryant  wrote:


This patch adds the pass-fd QMP command using the QAPI framework.
Like the getfd command, it is used to pass a file descriptor via
SCM_RIGHTS.  However, the pass-fd command also returns the received
file descriptor, which is a difference in behavior from the getfd
command, which returns nothing.

The closefd command can be used to close a file descriptor that was
passed with the pass-fd command.

Note that when using getfd or pass-fd, there are some commands
(e.g. migrate with fd:name) that implicitly close the named fd.
When this is not the case, closefd must be used to avoid fd leaks.

Signed-off-by: Corey Bryant 
---
v2:
  -Introduce new QMP command to pass/return fd (lcapitul...@redhat.com)
  -Use passfd as command name (berra...@redhat.com)

v3:
  -Use pass-fd as command name (lcapitul...@redhat.com)
  -Fail pass-fd if fdname already exists (lcapitul...@redhat.com)
  -Add notes to QMP command describing behavior in more detail
   (lcapitul...@redhat.com, ebl...@redhat.com)
  -Add note about fd leakage (ebl...@redhat.com)

  monitor.c|   33 +
  qapi-schema.json |   19 +++
  qmp-commands.hx  |   34 ++
  3 files changed, 86 insertions(+)

diff --git a/monitor.c b/monitor.c
index 1a7f7e7..6d99368 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2182,6 +2182,39 @@ static void do_inject_mce(Monitor *mon, const QDict 
*qdict)
  }
  #endif

+int64_t qmp_pass_fd(const char *fdname, Error **errp)
+{
+mon_fd_t *monfd;
+int fd;
+
+fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
+if (fd == -1) {
+error_set(errp, QERR_FD_NOT_SUPPLIED);
+return -1;
+}
+
+if (qemu_isdigit(fdname[0])) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
+  "a name not starting with a digit");
+return -1;
+}
+
+QLIST_FOREACH(monfd, &cur_mon->fds, next) {
+if (strcmp(monfd->name, fdname) == 0) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
+  "a name that does not already exist");
+return -1;
+}
+}


Returning the same error class for two different errors is not a good idea.
I think you have two options here. You could return QERR_INVALID_PARAMETER
for the "already exists" case or introduce QERR_FD_EXISTS. The later is
certainly nicer, but we were trying to avoid having too specific errors...



I'm not clear on what the problem is with returning the same error class 
for two different errors.  Could you explain?  I don't have a problem 
changing it if it's an issue.



+
+monfd = g_malloc0(sizeof(mon_fd_t));
+monfd->name = g_strdup(fdname);
+monfd->fd = fd;


Maybe you could try to move this to a separate function to share code with
qmp_getfd()?



Sure, no problem.  I can do that.


+
+QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
+return fd;
+}
+
  void qmp_getfd(const char *fdname, Error **errp)
  {
  mon_fd_t *monfd;
diff --git a/qapi-schema.json b/qapi-schema.json
index 26a6b84..ed99f23 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1864,6 +1864,25 @@
  { 'command': 'netdev_del', 'data': {'id': 'str'} }

  ##
+# @pass-fd:
+#
+# Pass a file descriptor via SCM rights and assign it a name
+#
+# @fdname: file descriptor name
+#
+# Returns: The QEMU file descriptor that was received
+#  If file descriptor was not received, FdNotSupplied
+#  If @fdname is not valid, InvalidParameterType
+#
+# Since: 1.2.0
+#
+# Notes: If @fdname already exists, the command will fail.
+#The 'closefd' command can be used to explicitly close the
+#file descriptor when it is no longer needed.
+##
+{ 'command': 'pass-fd', 'data': {'fdname': 'str'}, 'returns': 'int' }
+
+##
  # @getfd:
  #
  # Receive a file descriptor via SCM rights and assign it a name
diff --git a/qmp-commands.hx b/qmp-commands.hx
index e3cf3c5..c039947 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -869,6 +869,40 @@ Example:
  EQMP

  {
+.name   = "pass-fd",
+.args_type  = "fdname:s",
+.params = "pass-fd name",
+.help   = "pass a file descriptor via SCM rights and assign it a 
name",
+.mhandler.cmd_new = qmp_marshal_input_pass_fd,
+},
+
+SQMP
+pass-fd
+---
+
+Pass a file descriptor via SCM rights and assign it a name.
+
+Arguments:
+
+- "fdname": file descriptor name (json-string)
+
+Return a json-int with the QEMU file descriptor that was received.
+
+Example:
+
+-> { "execute": "pass-fd", "arguments": { "fdname": "fd1" } }
+<- { "return": 42 }
+
+Notes:
+
+(1) If the name specified by the "fdname" argument already exists,
+the command will fail.
+(2) The 'closefd' command can be used to explicitly close the file
+descriptor when it is no longer needed.
+
+EQMP
+
+{
  .name   = "getfd",
 

  1   2   3   >