[Qemu-devel] [PATCH] net: Fix a potential segfault

2018-06-10 Thread Lin Ma
Signed-off-by: Lin Ma 
---
 net/net.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/net.c b/net/net.c
index efb9eaf779..f89790be4a 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1093,9 +1093,12 @@ static int net_client_init(QemuOpts *opts, bool 
is_netdev, Error **errp)
 int ret = -1;
 Visitor *v = opts_visitor_new(opts);
 
-if (is_netdev && is_help_option(qemu_opt_get(opts, "type"))) {
-show_netdevs();
-exit(0);
+if (is_netdev) {
+const char *type = qemu_opt_get(opts, "type");
+if (type && is_help_option(type)) {
+show_netdevs();
+exit(0);
+}
 } else {
 /* Parse convenience option format ip6-net=fec0::0[/64] */
 const char *ip6_net = qemu_opt_get(opts, "ipv6-net");
-- 
2.16.2




[Qemu-devel] [PATCH] hw/i386: Deprecate the machine types pc-0.10 and pc-0.11

2018-06-10 Thread Thomas Huth
The oldest machine type which is still used in a maintained distribution
is a pc-0.12 based machine type in RHEL6, so everything that is older
than pc-0.12 should not be used anymore. Thus let's deprecate pc-0.10
and pc-0.11 so that we can finally remove them in a future release.

Signed-off-by: Thomas Huth 
---
 This is based on a patch that I already sent in 2017. But back then, we
 were still in progress of discussing our deprecation policies (e.g. auto-
 matic deprecation for old machine types), and there was no clear consensus
 whether we should deprecate 0.10 - 0.11, all 0.x or even up to version 1.2.
 After some iterations and too much discussion, I've forgotten about this
 patch. Anyway, I think we agreed that at least 0.10 and 0.11 can certainly
 be removed nowadays, so let's finally get at least those two machine types
 marked as deprecated! If that works fine and we will finally have removed
 these two types in v3.2, we can resume the discussion about newer machine
 types afterwards.
 
 hw/i386/pc_piix.c   | 2 ++
 include/hw/boards.h | 1 +
 qemu-doc.texi   | 5 +
 vl.c| 9 +++--
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 3d81136..fa61dc3 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -955,6 +955,8 @@ static void pc_i440fx_0_11_machine_options(MachineClass *m)
 {
 pc_i440fx_0_12_machine_options(m);
 m->hw_version = "0.11";
+m->deprecation_msg = "Old and unsupported machine version, "
+ "use a newer machine type instead.";
 SET_MACHINE_COMPAT(m, PC_COMPAT_0_11);
 }
 
diff --git a/include/hw/boards.h b/include/hw/boards.h
index ef7457f..e1bd25f 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -166,6 +166,7 @@ struct MachineClass {
 char *name;
 const char *alias;
 const char *desc;
+const char *deprecation_msg;
 
 void (*init)(MachineState *state);
 void (*reset)(void);
diff --git a/qemu-doc.texi b/qemu-doc.texi
index 2effe66..2a597d6 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -2965,6 +2965,11 @@ support page sizes < 4096 any longer.
 
 @section System emulator machines
 
+@subsection pc-0.10 and pc-0.11 (since 3.0)
+
+These machine types are very old and likely can not be used for life-migration
+from old QEMU versions anymore. A newer machine type should be used instead.
+
 @section Block device options
 
 @subsection "backing": "" (since 2.12.0)
diff --git a/vl.c b/vl.c
index 0603171..096814c 100644
--- a/vl.c
+++ b/vl.c
@@ -2560,8 +2560,9 @@ static gint machine_class_cmp(gconstpointer a, 
gconstpointer b)
 if (mc->alias) {
 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, 
mc->name);
 }
-printf("%-20s %s%s\n", mc->name, mc->desc,
-   mc->is_default ? " (default)" : "");
+printf("%-20s %s%s%s\n", mc->name, mc->desc,
+   mc->is_default ? " (default)" : "",
+   mc->deprecation_msg ? " (deprecated)" : "");
 }
 }
 
@@ -3952,6 +3953,10 @@ int main(int argc, char **argv, char **envp)
 }
 
 machine_class = select_machine();
+if (machine_class->deprecation_msg) {
+error_report("Machine type '%s' is deprecated: %s",
+ machine_class->name, machine_class->deprecation_msg);
+}
 
 set_memory_options(_slots, _size, machine_class);
 
-- 
1.8.3.1




Re: [Qemu-devel] question: a dead loop in qemu when do blockJobAbort and vm suspend coinstantaneously

2018-06-10 Thread l00284672

I tried your patch with my modification below can slove this problem.

void blk_set_aio_context(BlockBackend *blk, AioContext *new_context)
{
    BlockDriverState *bs = blk_bs(blk);
    ThrottleGroupMember *tgm = >public.throttle_group_member;

    if (bs) {
    if (tgm->throttle_state) {
    bdrv_drained_begin(bs);
    throttle_group_detach_aio_context(tgm);
    throttle_group_attach_aio_context(tgm, new_context);
    bdrv_drained_end(bs);
    }
     bdrv_ref(bs);
   bdrv_set_aio_context(bs, new_context);
       bdrv_unref(bs);
    }
}

I add bdrv_ref before bdrv_set_aio_context to avoid bs freed in 
mirror_exit.  Do you agree with

my modification ?

On 2018/6/11 11:01, l00284672 wrote:


Thanks for your reply.

I tried your patch but it didn't work for qemu crashed.  The qemu 
crash bt is below:


(gdb) bt
#0  bdrv_detach_aio_context (bs=bs@entry=0x55a96b79ca30)
#1  0x55a9688249ae in bdrv_set_aio_context 
(bs=bs@entry=0x55a96b79ca30,

    new_context=new_context@entry=0x55a96b766920)
#2  0x55a96885f721 in blk_set_aio_context (blk=0x55a96b792820, 
new_context=0x55a96b766920)
#3  0x55a9685ab797 in virtio_blk_data_plane_stop (vdev=out>)

#4  0x55a9687bf705 in virtio_bus_stop_ioeventfd (bus=0x55a96cc42220)
#5  0x55a9685d9d94 in virtio_vmstate_change 
(opaque=0x55a96cc42290, running=,

    state=)
#6  0x55a96866e1a2 in vm_state_notify (running=running@entry=0, 
state=state@entry=RUN_STATE_PAUSED)

#7  0x55a96857b4c5 in do_vm_stop (state=RUN_STATE_PAUSED)
#8  vm_stop (state=state@entry=RUN_STATE_PAUSED)
#9  0x55a96867d52b in qmp_stop (errp=errp@entry=0x7fff4e54a0d8)
#10 0x55a96867b6ab in qmp_marshal_stop (args=, 
ret=, errp=0x7fff4e54a
#11 0x55a9688c2267 in do_qmp_dispatch (errp=0x7fff4e54a118, 
request=0x55a96b7b4740)

#12 qmp_dispatch (request=request@entry=0x55a96b7ae490)
#13 0x55a96857dd42 in handle_qmp_command (parser=, 
tokens=)
#14 0x55a9688c7534 in json_message_process_token 
(lexer=0x55a96b776a68, input=0x55a96b70cae0, type=

    x=36, y=91)
#15 0x55a9688e960b in json_lexer_feed_char 
(lexer=lexer@entry=0x55a96b776a68, ch=125 '}',

    flush=flush@entry=false)
#16 0x55a9688e96ce in json_lexer_feed (lexer=0x55a96b776a68, 
buffer=, size=#17 0x55a9688c75f9 in json_message_parser_feed (parser=out>, buffer=,
#18 0x55a96857c5fb in monitor_qmp_read (opaque=, 
buf=,  size=)
#19 0x55a968667596 in tcp_chr_read (chan=, 
cond=, opaque=0x55a96b7748
#20 0x7f8a9447899a in g_main_context_dispatch () from 
/lib64/libglib-2.0.so.0

#21 0x55a968828c3c in glib_pollfds_poll ()
#22 os_host_main_loop_wait (timeout=)
#23 main_loop_wait (nonblocking=)
#24 0x55a96854351f in main_loop () at vl.c:2095
#25 main (argc=, argv=, envp=out>)


(gdb) p *bs
$1 = {total_sectors = 94186141054112, open_flags = 1811887680, 
read_only = 169, encrypted = 85, valid_k
  sg = false, probed = false, copy_on_read = 0, flush_queue = {entries 
= {sqh_first = 0x0,
  sqh_last = 0x55a96b79ca48}}, active_flush_req = false, 
flushed_gen = 68727, drv = 0x0, opaque = 0
  aio_context = 0x55a96b778cd0, aio_notifiers = {lh_first = 0x0}, 
walking_aio_notifiers = false,

  filename = "/mnt/sdb/lzg/disk_10G.son", '\000' ,
  backing_file = "\000mnt/sdb/lzg/disk_10G.raw", '\000' times>,
  backing_format = "\000aw", '\000' , 
full_open_options = 0x0,
  exact_filename = "/mnt/sdb/lzg/disk_10G.son", '\000' times>, backing = 0x0, file = 0x0,
  before_write_notifiers = {notifiers = {lh_first = 0x0}}, in_flight = 
0, serialising_in_flight = 0,
  wakeup = false, wr_highest_offset = 35188224, bl = 
{request_alignment = 0, max_pdiscard = 0,
    pdiscard_alignment = 0, max_pwrite_zeroes = 0, 
pwrite_zeroes_alignment = 0, opt_transfer = 0, max_t
    min_mem_alignment = 0, opt_mem_alignment = 0, max_iov = 0}, 
supported_write_flags = 0,
  supported_zero_flags = 4, node_name = "#block349", '\000' 22 times>, node_list = {
    tqe_next = 0x55a96b7b14f0, tqe_prev = 0x0}, bs_list = {tqe_next = 
0x55a96b7ab240, tqe_prev = 0x0},
  monitor_list = {tqe_next = 0x0, tqe_prev = 0x0}, dirty_bitmaps = 
{lh_first = 0x0}, refcnt = 0,
  tracked_requests = {lh_first = 0x0}, op_blockers = {{lh_first = 0x0} 
}, job = 0x0,
  inherits_from = 0x0, children = {lh_first = 0x0}, parents = 
{lh_first = 0x0}, options = 0x0,
  explicit_options = 0x0, detect_zeroes = 
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, backing_blocker = 0x0,
  write_threshold_offset = 0, write_threshold_notifier = {notify = 
0x0, node = {le_next = 0x0, le_prev

  io_plugged = 0, quiesce_counter = 0, write_gen = 68727}
(gdb) p *bs->drv
Cannot access memory at address 0x0

From the bt we can see,  qemu met a Null pointer reference in 
bdrv_detach_aio_context. The code is below:


void bdrv_detach_aio_context(BlockDriverState *bs)
{
    .

QLIST_FOREACH_SAFE(baf, >aio_notifiers, list, baf_tmp) {
    if (baf->deleted) {
    bdrv_do_remove_aio_context_notifier(baf);
    } else {
    

Re: [Qemu-devel] question: a dead loop in qemu when do blockJobAbort and vm suspend coinstantaneously

2018-06-10 Thread l00284672

Thanks for your reply.

I tried your patch but it didn't work for qemu crashed.  The qemu crash 
bt is below:


(gdb) bt
#0  bdrv_detach_aio_context (bs=bs@entry=0x55a96b79ca30)
#1  0x55a9688249ae in bdrv_set_aio_context (bs=bs@entry=0x55a96b79ca30,
    new_context=new_context@entry=0x55a96b766920)
#2  0x55a96885f721 in blk_set_aio_context (blk=0x55a96b792820, 
new_context=0x55a96b766920)

#3  0x55a9685ab797 in virtio_blk_data_plane_stop (vdev=)
#4  0x55a9687bf705 in virtio_bus_stop_ioeventfd (bus=0x55a96cc42220)
#5  0x55a9685d9d94 in virtio_vmstate_change (opaque=0x55a96cc42290, 
running=,

    state=)
#6  0x55a96866e1a2 in vm_state_notify (running=running@entry=0, 
state=state@entry=RUN_STATE_PAUSED)

#7  0x55a96857b4c5 in do_vm_stop (state=RUN_STATE_PAUSED)
#8  vm_stop (state=state@entry=RUN_STATE_PAUSED)
#9  0x55a96867d52b in qmp_stop (errp=errp@entry=0x7fff4e54a0d8)
#10 0x55a96867b6ab in qmp_marshal_stop (args=, 
ret=, errp=0x7fff4e54a
#11 0x55a9688c2267 in do_qmp_dispatch (errp=0x7fff4e54a118, 
request=0x55a96b7b4740)

#12 qmp_dispatch (request=request@entry=0x55a96b7ae490)
#13 0x55a96857dd42 in handle_qmp_command (parser=, 
tokens=)
#14 0x55a9688c7534 in json_message_process_token 
(lexer=0x55a96b776a68, input=0x55a96b70cae0, type=

    x=36, y=91)
#15 0x55a9688e960b in json_lexer_feed_char 
(lexer=lexer@entry=0x55a96b776a68, ch=125 '}',

    flush=flush@entry=false)
#16 0x55a9688e96ce in json_lexer_feed (lexer=0x55a96b776a68, 
buffer=, size=#17 0x55a9688c75f9 in json_message_parser_feed (parser=out>, buffer=,
#18 0x55a96857c5fb in monitor_qmp_read (opaque=, 
buf=,  size=)
#19 0x55a968667596 in tcp_chr_read (chan=, 
cond=, opaque=0x55a96b7748
#20 0x7f8a9447899a in g_main_context_dispatch () from 
/lib64/libglib-2.0.so.0

#21 0x55a968828c3c in glib_pollfds_poll ()
#22 os_host_main_loop_wait (timeout=)
#23 main_loop_wait (nonblocking=)
#24 0x55a96854351f in main_loop () at vl.c:2095
#25 main (argc=, argv=, envp=)

(gdb) p *bs
$1 = {total_sectors = 94186141054112, open_flags = 1811887680, read_only 
= 169, encrypted = 85, valid_k
  sg = false, probed = false, copy_on_read = 0, flush_queue = {entries 
= {sqh_first = 0x0,
  sqh_last = 0x55a96b79ca48}}, active_flush_req = false, 
flushed_gen = 68727, drv = 0x0, opaque = 0
  aio_context = 0x55a96b778cd0, aio_notifiers = {lh_first = 0x0}, 
walking_aio_notifiers = false,

  filename = "/mnt/sdb/lzg/disk_10G.son", '\000' ,
  backing_file = "\000mnt/sdb/lzg/disk_10G.raw", '\000' times>,
  backing_format = "\000aw", '\000' , 
full_open_options = 0x0,
  exact_filename = "/mnt/sdb/lzg/disk_10G.son", '\000' times>, backing = 0x0, file = 0x0,
  before_write_notifiers = {notifiers = {lh_first = 0x0}}, in_flight = 
0, serialising_in_flight = 0,
  wakeup = false, wr_highest_offset = 35188224, bl = {request_alignment 
= 0, max_pdiscard = 0,
    pdiscard_alignment = 0, max_pwrite_zeroes = 0, 
pwrite_zeroes_alignment = 0, opt_transfer = 0, max_t
    min_mem_alignment = 0, opt_mem_alignment = 0, max_iov = 0}, 
supported_write_flags = 0,
  supported_zero_flags = 4, node_name = "#block349", '\000' times>, node_list = {
    tqe_next = 0x55a96b7b14f0, tqe_prev = 0x0}, bs_list = {tqe_next = 
0x55a96b7ab240, tqe_prev = 0x0},
  monitor_list = {tqe_next = 0x0, tqe_prev = 0x0}, dirty_bitmaps = 
{lh_first = 0x0}, refcnt = 0,
  tracked_requests = {lh_first = 0x0}, op_blockers = {{lh_first = 0x0} 
}, job = 0x0,
  inherits_from = 0x0, children = {lh_first = 0x0}, parents = {lh_first 
= 0x0}, options = 0x0,
  explicit_options = 0x0, detect_zeroes = 
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, backing_blocker = 0x0,
  write_threshold_offset = 0, write_threshold_notifier = {notify = 0x0, 
node = {le_next = 0x0, le_prev

  io_plugged = 0, quiesce_counter = 0, write_gen = 68727}
(gdb) p *bs->drv
Cannot access memory at address 0x0

From the bt we can see,  qemu met a Null pointer reference in 
bdrv_detach_aio_context. The code is below:


void bdrv_detach_aio_context(BlockDriverState *bs)
{
    .

QLIST_FOREACH_SAFE(baf, >aio_notifiers, list, baf_tmp) {
    if (baf->deleted) {
    bdrv_do_remove_aio_context_notifier(baf);
    } else {
    baf->detach_aio_context(baf->opaque);
    }
    }
    /* Never mind iterating again to check for ->deleted. bdrv_close() will
 * remove remaining aio notifiers if we aren't called again.
 */
    bs->walking_aio_notifiers = false;

if (bs->drv->bdrv_detach_aio_context) {
    bs->drv->bdrv_detach_aio_context(bs);
    }

..
}

In your patch, the mirror_exit is done in 
aio_poll(qemu_get_aio_context(), true).  In

mirror_exit, the top bs willl be free by bdrv_unref.  So it will make a
Null pointer access in the follow-up procedure.




On 2018/6/10 15:43, Fam Zheng wrote:

On Sat, 06/09 17:10, l00284672 wrote:

Hi, I found a dead loop in qemu when do blockJobAbort and vm suspend
coinstantaneously.

The qemu bt is below:

Re: [Qemu-devel] [PATCH] pc: Remove PC_COMPAT_2_12 from 3.0 machine-types

2018-06-10 Thread Xiao Guangrong




On 06/09/2018 03:29 AM, Eduardo Habkost wrote:

commit f548222c added PC_COMPAT_2_12 to the 3.0 PC machine-types.
I believe this happened during manual conflict resolution when
applying the patch.



Indeed!

Reviewed-by: Xiao Guangrong 



Re: [Qemu-devel] [PATCH v3 1/3] util: remove redundant include of glib.h and add osdep.h

2018-06-10 Thread Peter Xu
On Fri, Jun 08, 2018 at 02:16:02PM +0100, Daniel P. Berrangé wrote:
> Code must only ever include glib.h indirectly via the glib-compat.h
> header file, because we will need some macros set before glib.h is
> pulled in. Adding extra includes of glib.h will (soon) cause compile
> failures such as:
> 
> In file included from /home/berrange/src/virt/qemu/include/qemu/osdep.h:107,
>  from 
> /home/berrange/src/virt/qemu/include/qemu/iova-tree.h:26,
>  from util/iova-tree.c:13:
> /home/berrange/src/virt/qemu/include/glib-compat.h:22: error: 
> "GLIB_VERSION_MIN_REQUIRED" redefined [-Werror]
>  #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40
> 
> In file included from /usr/include/glib-2.0/glib/gtypes.h:34,
>  from /usr/include/glib-2.0/glib/galloca.h:32,
>  from /usr/include/glib-2.0/glib.h:30,
>  from util/iova-tree.c:12:
> /usr/include/glib-2.0/glib/gversionmacros.h:237: note: this is the location 
> of the previous definition
>  # define GLIB_VERSION_MIN_REQUIRED  (GLIB_VERSION_CUR_STABLE)
> 
> Furthermore, the osdep.h include should always be done directly from the
> .c file rather than indirectly via any .h file.
> 
> Reviewed-by: Philippe Mathieu-Daudé 
> Signed-off-by: Daniel P. Berrangé 

Reviewed-by: Peter Xu 

-- 
Peter Xu



Re: [Qemu-devel] [PATCH v10 5/7] monitor: remove event_clock_type

2018-06-10 Thread Peter Xu
On Fri, Jun 08, 2018 at 09:09:57AM +0200, Markus Armbruster wrote:
> Peter Xu  writes:
> 
> > On Fri, Jun 08, 2018 at 07:38:11AM +0200, Markus Armbruster wrote:
> >
> > [...]
> >
> >> > +/*
> >> > + * This should never be called before configure_accelerator() since
> >> > + * only until then could we know whether qtest was enabled or not.
> >> 
> >> Uh, we know it after then, not until then.  What about
> >> 
> >>/*
> >> * Return the clock to use for recording an event's time.
> >> * Beware: result is invalid before configure_accelerator().
> >
> > Oh, another Chinglish from me. :(
> 
> Useful code, occasional Chinglish, the humility to go with it, and a
> sense of humor --- you're doing fine.

Very high evaluation. Thank you. :)

-- 
Peter Xu



Re: [Qemu-devel] [Qemu-arm] [PATCH v4 00/40] Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/10/2018 11:22 PM, Michael S. Tsirkin wrote:
> On Sun, Jun 10, 2018 at 10:14:21PM -0300, Philippe Mathieu-Daudé wrote:
>> Hi,
>>
>> This series:
>>
>> - split the byte-based definitions from "qemu/cutils.h" to "qemu/units.h"
>>   (this now triggers WARNING: 1 added file, does MAINTAINERS need updating?)
>> - clean hw/ includes;
>> - replace different constants used for byte size with their corresponding
>>   IEC binary prefix definitions.
>>
>> Since v3:
>> - use IEC binary prefix definitions (Stefan Weil)
>> - rebased
>> - added R-b tags
> 
> It violates our coding style which requires KIB for macros.
> But strangely, I like how this looks anyway.

Each use this saves 3 char of the 80 columns limit!

> 
> So series
> 
> Reviewed-by: Michael S. Tsirkin 

Thanks!

> 
> 
> but I think you need to update the coding style explaining
> that there's an exception.

OK, if there is no NACK/negative comment I'll simply add a patch
Based-on this series.

> 
>> Since v2:
>> - use "qemu/units.h" instead of "qemu/cunits.h" (Daniel P. Berrangé)
>> - avoid rebuilding the world including "qemu/units.h" in "hw/hw.h" (Thomas 
>> Huth)
>> - more constant replaced
>>
>> Since v1:
>> - corrected Xen mult -> div (Alan Robinson)
>> - tagged 'include "qemu/cunits.h" in "hw/hw.h" as RFC
>> - fixed mips_r4k 'params_size' (Thomas Huth)
>> - added command used to generate patch in each commit (Alistair Francis)
>> - use G_BYTE for the raspi3 machine
>> - added Reviewed-by tags
>>
>> Regards,
>>
>> Phil.
>>
>> Philippe Mathieu-Daudé (40):
>>   include: Add IEC binary prefixes in "qemu/units.h"
>>   vdi: Use definitions from "qemu/units.h"
>>   x86/cpu: Use definitions from "qemu/units.h"
>>   checkpatch: Recognize IEC binary prefix definitions
>>   hw: Use IEC binary prefix definitions from "qemu/units.h"
>>   hw: Directly use "qemu/units.h" instead of "qemu/cutils.h"
>>   hw/ivshmem: Use the IEC binary prefix definitions
>>   hw/ipack: Use the IEC binary prefix definitions
>>   hw/scsi: Use the IEC binary prefix definitions
>>   hw/smbios: Use the IEC binary prefix definitions
>>   hw/xen: Use the IEC binary prefix definitions
>>   hw/tpm: Use the IEC binary prefix definitions
>>   hw/block: Use the IEC binary prefix definitions
>>   hw/display: Use the IEC binary prefix definitions
>>   hw/misc: Use the IEC binary prefix definitions
>>   hw/riscv: Use the IEC binary prefix definitions
>>   hw/m68k: Use the IEC binary prefix definitions
>>   hw/sparc: Use the IEC binary prefix definitions
>>   hw/s390x: Use the IEC binary prefix definitions
>>   hw/hppa: Use the IEC binary prefix definitions
>>   hw/xtensa: Use the IEC binary prefix definitions
>>   hw/alpha: Use the IEC binary prefix definitions
>>   hw/tricore: Use the IEC binary prefix definitions
>>   hw/microblaze: Use the IEC binary prefix definitions
>>   hw/nios2: Use the IEC binary prefix definitions
>>   hw/cris: Use the IEC binary prefix definitions
>>   hw/lm32: Use the IEC binary prefix definitions
>>   hw/sh4: Use the IEC binary prefix definitions
>>   hw/mips/r4k: Constify params_size
>>   hw/mips: Use the IEC binary prefix definitions
>>   hw/arm: Use the IEC binary prefix definitions
>>   hw/ppc: Use the IEC binary prefix definitions
>>   hw/i386: Use the IEC binary prefix definitions
>>   hw/net: Use the IEC binary prefix definitions
>>   hw/usb: Use the IEC binary prefix definitions
>>   hw/sd: Use the IEC binary prefix definitions
>>   hw/vfio: Use the IEC binary prefix definitions
>>   hw/virtio: Use the IEC binary prefix definitions
>>   hw/rdma: Use the IEC binary prefix definitions
>>   cutils: Do not include "qemu/units.h" directly
>>
>>  hw/net/ne2000.h  |  5 ++--
>>  hw/ppc/mac.h |  3 ++-
>>  hw/rdma/vmw/pvrdma.h |  3 ++-
>>  include/hw/acpi/tpm.h|  3 ++-
>>  include/hw/arm/fsl-imx7.h|  5 ++--
>>  include/hw/arm/stm32f205_soc.h   |  5 ++--
>>  include/hw/display/xlnx_dp.h |  5 ++--
>>  include/hw/i386/ich9.h   |  3 ++-
>>  include/hw/intc/mips_gic.h   |  3 ++-
>>  include/hw/mips/bios.h   |  3 ++-
>>  include/hw/net/allwinner_emac.h  |  5 ++--
>>  include/hw/ppc/spapr.h   |  5 ++--
>>  include/hw/virtio/virtio-net.h   |  3 ++-
>>  include/qemu/cutils.h|  7 --
>>  include/qemu/units.h | 20 
>>  block/vdi.c  |  8 +++
>>  hw/alpha/typhoon.c   | 17 +++---
>>  hw/arm/bcm2835_peripherals.c |  3 ++-
>>  hw/arm/boot.c|  7 +++---
>>  hw/arm/collie.c  |  5 ++--
>>  hw/arm/digic_boards.c|  7 +++---
>>  hw/arm/exynos4_boards.c  |  3 ++-
>>  hw/arm/gumstix.c |  3 ++-
>>  hw/arm/integratorcp.c|  3 ++-
>>  

Re: [Qemu-devel] [PATCH v4 33/40] hw/i386: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/10/2018 11:18 PM, Michael S. Tsirkin wrote:
> On Sun, Jun 10, 2018 at 10:14:54PM -0300, Philippe Mathieu-Daudé wrote:
>> @@ -1392,11 +1393,11 @@ void pc_memory_init(PCMachineState *pcms,
>>  }
>>  
>>  machine->device_memory->base =
>> -ROUND_UP(0x1ULL + pcms->above_4g_mem_size, 1ULL << 30);
>> +ROUND_UP(0x1ULL + pcms->above_4g_mem_size, GiB);
>>  
> 
> 
> For some reason, GiB got special treatment. Why not 1* GiB?

Oops I didn't notice, I really prefer "1 * GiB" too.



Re: [Qemu-devel] [PATCH v6 00/49] fix building of tests/tcg

2018-06-10 Thread Philippe Mathieu-Daudé
Hi Alex,

On 06/08/2018 09:32 AM, Alex Bennée wrote:
> Hi,
> 
> Not a super amount has changed since the last version but review
> comments and review tags have been added. The new patches at the end
> enable a .travis.yml run and try and make the image building part of
> check-tcg -j safe. Essentially the problem is trying to avoid
> re-building the images multiple times. The additional issue is wanting
> an upto date Debian SID image whenever we actually build an image but
> not forcing a rebuild every time.
> 
> Essentially I'd like to encode a conditional dependency when:
>   - the target image doesn't exist
>   - or the target image is out of date w.r.t. the dockerfike
> 
> I'm thinking this is going to involve some sort of extension to the
> docker.py script to feed the Makefile.
> 
> A number of the prerequisite patches have already been pulled in the
> docker fixes series however I think this series is ready to go in now.
> Unless there are any objections I'll send a pull on Monday.
> 
> Current unreviewed patches:
> 
>   patch 0017/tests tcg i386 add runner for test i386 fprem.patch needs review
>   patch 0039/docker move debian powerpc cross to sid based bui.patch needs 
> review
>   patch 0040/tests tcg enable building for PowerPC.patch needs review
>   patch 0042/Makefile.target add clean build guest tests targe.patch needs 
> review
>   patch 0044/tests tcg add run diff and skip helper macros.patch needs review
>   patch 0045/tests tcg override runners for broken tests.patch needs review

No problem until here.

>   patch 0046/target sh4 Fix translator.c assertion failure for.patch needs 
> review

Probably unrelated.

>   patch 0047/tests add top level make dependency for docker bu.patch needs 
> review

I think you could add patch #47 (which is the last piece required to
test your work) removing the 'build-docker-prereqs' rule, and fix it
during the week.

>   patch 0048/tests docker prevent sub makes re building debian.patch needs 
> review

I wouldn't include this one (yet).

>   patch 0049/.travis.yml add check tcg test.patch needs review

You can include this one fixed using "-j1".

Good work! :)

Regards,

Phil.

> 
> 
> Alex Bennée (46):
>   configure: add support for --cross-cc-FOO
>   configure: move i386_cc to cross_cc_i386
>   configure: allow user to specify --cross-cc-cflags-foo=
>   configure: set cross_cc_FOO for host compiler
>   docker: Add "cc" subcommand
>   docker: extend "cc" command to accept compiler
>   docker: allow "cc" command to run in user context
>   docker: Makefile.include introduce DOCKER_SCRIPT
>   tests/tcg: move architecture independent tests into subdir
>   tests/tcg/multiarch: enable additional linux-test tests
>   tests/tcg/multiarch: move most output to stdout
>   tests/tcg: move i386 specific tests into subdir
>   tests/tcg: enable building for i386
>   tests/tcg/i386: fix test-i386
>   tests/tcg/i386: add runner for test-i386-fprem
>   tests/tcg/x86_64: add Makefile.target
>   tests/tcg/i386/test-i386: use modern vector_size attributes
>   tests/tcg/i386/test-i386: fix printf format
>   tests/tcg: move ARM specific tests into subdir
>   tests/tcg: enable building for ARM
>   tests/tcg/arm: fix up test-arm-iwmmxt test
>   tests/tcg: enable building for AArch64
>   tests/tcg/arm: add fcvt test cases for AArch32/64
>   tests/tcg: move MIPS specific tests into subdir
>   tests/tcg: enable building for MIPS
>   tests/tcg/mips: include common mips hello-mips
>   tests/tcg: enable building for s390x
>   tests/tcg: enable building for ppc64
>   tests/tcg: enable building for Alpha
>   tests/tcg/alpha: add Alpha specific tests
>   tests/tcg: enable building for HPPA
>   tests/tcg: enable building for m68k
>   tests/tcg: enable building for sh4
>   tests/tcg: enable building for sparc64
>   tests/tcg: enable building for mips64
>   tests/tcg: enable building for RISCV64
>   docker: move debian-powerpc-cross to sid based build
>   tests/tcg: enable building for PowerPC
>   tests/tcg/Makefile: update to be called from Makefile.target
>   Makefile.target: add (clean-/build-)guest-tests targets
>   tests/Makefile.include: add [build|clean|check]-tcg targets
>   tests/tcg: add run, diff, and skip helper macros
>   tests/tcg: override runners for broken tests
>   tests: add top-level make dependency for docker builds
>   tests/docker: prevent sub-makes re-building debian-sid
>   .travis.yml: add check-tcg test
> 
> Fam Zheng (2):
>   tests/tcg/multiarch: Build fix for linux-test
>   tests/tcg/i386: Build fix for hello-i386
> 
> Richard Henderson (1):
>   target/sh4: Fix translator.c assertion failure for gUSA
> 
>  .travis.yml   |6 +
>  MAINTAINERS   |   14 +
>  Makefile.target   |5 +
>  configure |  134 +-
>  target/sh4/translate.c|   81 +-
>  tests/Makefile.include|   38 +-
>  

Re: [Qemu-devel] [PATCH v4 05/40] hw: Use IEC binary prefix definitions from "qemu/units.h"

2018-06-10 Thread David Gibson
On Sun, Jun 10, 2018 at 10:14:26PM -0300, Philippe Mathieu-Daudé wrote:
> Code change produced with:
> 
>   $ git ls-files | egrep '\.[ch]$' | \
> xargs sed -i -e 's/\(\W[KMGTPE]\)_BYTE/\1iB/g'
> 
> Suggested-by: Stefan Weil 
> Signed-off-by: Philippe Mathieu-Daudé 

ppc parts
Acked-by: David Gibson 

> ---
>  include/qemu/cutils.h  |  8 +---
>  hw/arm/msf2-soc.c  |  4 ++--
>  hw/arm/msf2-som.c  |  6 +++---
>  hw/core/loader-fit.c   |  3 ++-
>  hw/core/machine.c  |  2 +-
>  hw/display/sm501.c | 14 +++---
>  hw/hppa/machine.c  |  2 +-
>  hw/mips/boston.c   | 28 ++--
>  hw/ppc/pnv.c   |  4 ++--
>  hw/ppc/ppc440_uc.c | 26 +-
>  hw/ppc/prep.c  |  2 +-
>  hw/ppc/sam460ex.c  |  2 +-
>  hw/ppc/spapr.c | 10 +-
>  hw/ppc/spapr_rtas.c|  2 +-
>  hw/sd/sd.c |  4 ++--
>  hw/sd/sdhci.c  |  2 +-
>  tests/test-cutils.c| 18 +-
>  tests/test-keyval.c|  6 +++---
>  tests/test-qemu-opts.c |  7 +++
>  19 files changed, 72 insertions(+), 78 deletions(-)
> 
> diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
> index a663340b23..056e6629bb 100644
> --- a/include/qemu/cutils.h
> +++ b/include/qemu/cutils.h
> @@ -2,6 +2,7 @@
>  #define QEMU_CUTILS_H
>  
>  #include "qemu/fprintf-fn.h"
> +#include "qemu/units.h"
>  
>  /**
>   * pstrcpy:
> @@ -147,13 +148,6 @@ int qemu_strtosz(const char *nptr, char **end, uint64_t 
> *result);
>  int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result);
>  int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result);
>  
> -#define K_BYTE (1ULL << 10)
> -#define M_BYTE (1ULL << 20)
> -#define G_BYTE (1ULL << 30)
> -#define T_BYTE (1ULL << 40)
> -#define P_BYTE (1ULL << 50)
> -#define E_BYTE (1ULL << 60)
> -
>  /* used to print char* safely */
>  #define STR_OR_NULL(str) ((str) ? (str) : "null")
>  
> diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c
> index 75c44adf7d..530e461c42 100644
> --- a/hw/arm/msf2-soc.c
> +++ b/hw/arm/msf2-soc.c
> @@ -40,14 +40,14 @@
>  
>  #define SRAM_BASE_ADDRESS 0x2000
>  
> -#define MSF2_ENVM_MAX_SIZE(512 * K_BYTE)
> +#define MSF2_ENVM_MAX_SIZE(512 * KiB)
>  
>  /*
>   * eSRAM max size is 80k without SECDED(Single error correction and
>   * dual error detection) feature and 64k with SECDED.
>   * We do not support SECDED now.
>   */
> -#define MSF2_ESRAM_MAX_SIZE   (80 * K_BYTE)
> +#define MSF2_ESRAM_MAX_SIZE   (80 * KiB)
>  
>  static const uint32_t spi_addr[MSF2_NUM_SPIS] = { 0x40001000 , 0x40011000 };
>  static const uint32_t uart_addr[MSF2_NUM_UARTS] = { 0x4000 , 0x4001 
> };
> diff --git a/hw/arm/msf2-som.c b/hw/arm/msf2-som.c
> index 0795a3a3a1..ed533bbde1 100644
> --- a/hw/arm/msf2-som.c
> +++ b/hw/arm/msf2-som.c
> @@ -33,10 +33,10 @@
>  #include "cpu.h"
>  
>  #define DDR_BASE_ADDRESS  0xA000
> -#define DDR_SIZE  (64 * M_BYTE)
> +#define DDR_SIZE  (64 * MiB)
>  
> -#define M2S010_ENVM_SIZE  (256 * K_BYTE)
> -#define M2S010_ESRAM_SIZE (64 * K_BYTE)
> +#define M2S010_ENVM_SIZE  (256 * KiB)
> +#define M2S010_ESRAM_SIZE (64 * KiB)
>  
>  static void emcraft_sf2_s2s010_init(MachineState *machine)
>  {
> diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c
> index 6387854b54..447f60857d 100644
> --- a/hw/core/loader-fit.c
> +++ b/hw/core/loader-fit.c
> @@ -18,6 +18,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "exec/memory.h"
>  #include "hw/loader.h"
>  #include "hw/loader-fit.h"
> @@ -194,7 +195,7 @@ static int fit_load_fdt(const struct fit_loader *ldr, 
> const void *itb,
>  
>  err = fit_image_addr(itb, img_off, "load", _addr);
>  if (err == -ENOENT) {
> -load_addr = ROUND_UP(kernel_end, 64 * K_BYTE) + (10 * M_BYTE);
> +load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB);
>  } else if (err) {
>  ret = err;
>  goto out;
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 617e5f8d75..ccf3a4b9c7 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -522,7 +522,7 @@ static void machine_class_init(ObjectClass *oc, void 
> *data)
>  MachineClass *mc = MACHINE_CLASS(oc);
>  
>  /* Default 128 MB as guest ram size */
> -mc->default_ram_size = 128 * M_BYTE;
> +mc->default_ram_size = 128 * MiB;
>  mc->rom_file_has_mr = true;
>  
>  /* numa node memory size aligned on 8MB by default.
> diff --git a/hw/display/sm501.c b/hw/display/sm501.c
> index e47be99451..1c6c9445c5 100644
> --- a/hw/display/sm501.c
> +++ b/hw/display/sm501.c
> @@ -452,12 +452,12 @@
>  
>  /* SM501 local memory size taken from "linux/drivers/mfd/sm501.c" */
>  static const uint32_t sm501_mem_local_size[] = {
> -[0] = 4 * M_BYTE,
> -[1] = 8 * M_BYTE,
> -[2] = 16 * M_BYTE,
> -[3] = 32 * M_BYTE,
> -[4] = 64 * M_BYTE,
> -[5] = 2 * M_BYTE,
> +   

Re: [Qemu-devel] [PATCH v4 06/40] hw: Directly use "qemu/units.h" instead of "qemu/cutils.h"

2018-06-10 Thread David Gibson
On Sun, Jun 10, 2018 at 10:14:27PM -0300, Philippe Mathieu-Daudé wrote:
> These files don't use anything exposed by "qemu/cutils.h",
> simplify preprocessing including directly "qemu/units.h".
> 
> Signed-off-by: Philippe Mathieu-Daudé 

ppc parts
Acked-by: David Gibson 

> ---
>  hw/arm/msf2-soc.c  | 2 +-
>  hw/arm/msf2-som.c  | 2 +-
>  hw/core/machine.c  | 2 +-
>  hw/display/sm501.c | 2 +-
>  hw/mips/boston.c   | 2 +-
>  hw/ppc/pnv.c   | 2 +-
>  hw/ppc/ppc440_uc.c | 2 +-
>  7 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c
> index 530e461c42..edb3ba824f 100644
> --- a/hw/arm/msf2-soc.c
> +++ b/hw/arm/msf2-soc.c
> @@ -23,13 +23,13 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "qapi/error.h"
>  #include "qemu-common.h"
>  #include "hw/arm/arm.h"
>  #include "exec/address-spaces.h"
>  #include "hw/char/serial.h"
>  #include "hw/boards.h"
> -#include "qemu/cutils.h"
>  #include "hw/arm/msf2-soc.h"
>  #include "hw/misc/unimp.h"
>  
> diff --git a/hw/arm/msf2-som.c b/hw/arm/msf2-som.c
> index ed533bbde1..2432b5e935 100644
> --- a/hw/arm/msf2-som.c
> +++ b/hw/arm/msf2-som.c
> @@ -23,12 +23,12 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
>  #include "hw/boards.h"
>  #include "hw/arm/arm.h"
>  #include "exec/address-spaces.h"
> -#include "qemu/cutils.h"
>  #include "hw/arm/msf2-soc.h"
>  #include "cpu.h"
>  
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index ccf3a4b9c7..2077328bcc 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -11,6 +11,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "hw/boards.h"
>  #include "qapi/error.h"
>  #include "qapi/qapi-visit-common.h"
> @@ -19,7 +20,6 @@
>  #include "sysemu/sysemu.h"
>  #include "sysemu/numa.h"
>  #include "qemu/error-report.h"
> -#include "qemu/cutils.h"
>  #include "sysemu/qtest.h"
>  
>  static char *machine_get_accel(Object *obj, Error **errp)
> diff --git a/hw/display/sm501.c b/hw/display/sm501.c
> index 1c6c9445c5..bbb9274886 100644
> --- a/hw/display/sm501.c
> +++ b/hw/display/sm501.c
> @@ -24,7 +24,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> -#include "qemu/cutils.h"
> +#include "qemu/units.h"
>  #include "qapi/error.h"
>  #include "qemu-common.h"
>  #include "cpu.h"
> diff --git a/hw/mips/boston.c b/hw/mips/boston.c
> index 512c60c03e..b7bfeccf4c 100644
> --- a/hw/mips/boston.c
> +++ b/hw/mips/boston.c
> @@ -18,6 +18,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "qemu-common.h"
>  
>  #include "exec/address-spaces.h"
> @@ -32,7 +33,6 @@
>  #include "hw/mips/cpudevs.h"
>  #include "hw/pci-host/xilinx-pcie.h"
>  #include "qapi/error.h"
> -#include "qemu/cutils.h"
>  #include "qemu/error-report.h"
>  #include "qemu/log.h"
>  #include "chardev/char.h"
> diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> index bdb6f63d2c..0df4a4fd74 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -18,6 +18,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "qapi/error.h"
>  #include "sysemu/sysemu.h"
>  #include "sysemu/numa.h"
> @@ -31,7 +32,6 @@
>  #include "hw/ppc/pnv_core.h"
>  #include "hw/loader.h"
>  #include "exec/address-spaces.h"
> -#include "qemu/cutils.h"
>  #include "qapi/visitor.h"
>  #include "monitor/monitor.h"
>  #include "hw/intc/intc.h"
> diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
> index b5b31b4b9b..1ab2235f20 100644
> --- a/hw/ppc/ppc440_uc.c
> +++ b/hw/ppc/ppc440_uc.c
> @@ -9,8 +9,8 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "qemu-common.h"
> -#include "qemu/cutils.h"
>  #include "qemu/error-report.h"
>  #include "qapi/error.h"
>  #include "cpu.h"

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v4 00/40] Use the IEC binary prefix definitions

2018-06-10 Thread Michael S. Tsirkin
On Sun, Jun 10, 2018 at 10:14:21PM -0300, Philippe Mathieu-Daudé wrote:
> Hi,
> 
> This series:
> 
> - split the byte-based definitions from "qemu/cutils.h" to "qemu/units.h"
>   (this now triggers WARNING: 1 added file, does MAINTAINERS need updating?)
> - clean hw/ includes;
> - replace different constants used for byte size with their corresponding
>   IEC binary prefix definitions.
> 
> Since v3:
> - use IEC binary prefix definitions (Stefan Weil)
> - rebased
> - added R-b tags

It violates our coding style which requires KIB for macros.
But strangely, I like how this looks anyway.

So series

Reviewed-by: Michael S. Tsirkin 


but I think you need to update the coding style explaining
that there's an exception.

> Since v2:
> - use "qemu/units.h" instead of "qemu/cunits.h" (Daniel P. Berrangé)
> - avoid rebuilding the world including "qemu/units.h" in "hw/hw.h" (Thomas 
> Huth)
> - more constant replaced
> 
> Since v1:
> - corrected Xen mult -> div (Alan Robinson)
> - tagged 'include "qemu/cunits.h" in "hw/hw.h" as RFC
> - fixed mips_r4k 'params_size' (Thomas Huth)
> - added command used to generate patch in each commit (Alistair Francis)
> - use G_BYTE for the raspi3 machine
> - added Reviewed-by tags
> 
> Regards,
> 
> Phil.
> 
> Philippe Mathieu-Daudé (40):
>   include: Add IEC binary prefixes in "qemu/units.h"
>   vdi: Use definitions from "qemu/units.h"
>   x86/cpu: Use definitions from "qemu/units.h"
>   checkpatch: Recognize IEC binary prefix definitions
>   hw: Use IEC binary prefix definitions from "qemu/units.h"
>   hw: Directly use "qemu/units.h" instead of "qemu/cutils.h"
>   hw/ivshmem: Use the IEC binary prefix definitions
>   hw/ipack: Use the IEC binary prefix definitions
>   hw/scsi: Use the IEC binary prefix definitions
>   hw/smbios: Use the IEC binary prefix definitions
>   hw/xen: Use the IEC binary prefix definitions
>   hw/tpm: Use the IEC binary prefix definitions
>   hw/block: Use the IEC binary prefix definitions
>   hw/display: Use the IEC binary prefix definitions
>   hw/misc: Use the IEC binary prefix definitions
>   hw/riscv: Use the IEC binary prefix definitions
>   hw/m68k: Use the IEC binary prefix definitions
>   hw/sparc: Use the IEC binary prefix definitions
>   hw/s390x: Use the IEC binary prefix definitions
>   hw/hppa: Use the IEC binary prefix definitions
>   hw/xtensa: Use the IEC binary prefix definitions
>   hw/alpha: Use the IEC binary prefix definitions
>   hw/tricore: Use the IEC binary prefix definitions
>   hw/microblaze: Use the IEC binary prefix definitions
>   hw/nios2: Use the IEC binary prefix definitions
>   hw/cris: Use the IEC binary prefix definitions
>   hw/lm32: Use the IEC binary prefix definitions
>   hw/sh4: Use the IEC binary prefix definitions
>   hw/mips/r4k: Constify params_size
>   hw/mips: Use the IEC binary prefix definitions
>   hw/arm: Use the IEC binary prefix definitions
>   hw/ppc: Use the IEC binary prefix definitions
>   hw/i386: Use the IEC binary prefix definitions
>   hw/net: Use the IEC binary prefix definitions
>   hw/usb: Use the IEC binary prefix definitions
>   hw/sd: Use the IEC binary prefix definitions
>   hw/vfio: Use the IEC binary prefix definitions
>   hw/virtio: Use the IEC binary prefix definitions
>   hw/rdma: Use the IEC binary prefix definitions
>   cutils: Do not include "qemu/units.h" directly
> 
>  hw/net/ne2000.h  |  5 ++--
>  hw/ppc/mac.h |  3 ++-
>  hw/rdma/vmw/pvrdma.h |  3 ++-
>  include/hw/acpi/tpm.h|  3 ++-
>  include/hw/arm/fsl-imx7.h|  5 ++--
>  include/hw/arm/stm32f205_soc.h   |  5 ++--
>  include/hw/display/xlnx_dp.h |  5 ++--
>  include/hw/i386/ich9.h   |  3 ++-
>  include/hw/intc/mips_gic.h   |  3 ++-
>  include/hw/mips/bios.h   |  3 ++-
>  include/hw/net/allwinner_emac.h  |  5 ++--
>  include/hw/ppc/spapr.h   |  5 ++--
>  include/hw/virtio/virtio-net.h   |  3 ++-
>  include/qemu/cutils.h|  7 --
>  include/qemu/units.h | 20 
>  block/vdi.c  |  8 +++
>  hw/alpha/typhoon.c   | 17 +++---
>  hw/arm/bcm2835_peripherals.c |  3 ++-
>  hw/arm/boot.c|  7 +++---
>  hw/arm/collie.c  |  5 ++--
>  hw/arm/digic_boards.c|  7 +++---
>  hw/arm/exynos4_boards.c  |  3 ++-
>  hw/arm/gumstix.c |  3 ++-
>  hw/arm/integratorcp.c|  3 ++-
>  hw/arm/mainstone.c   |  3 ++-
>  hw/arm/msf2-soc.c|  6 ++---
>  hw/arm/msf2-som.c|  8 +++
>  hw/arm/musicpal.c|  9 +++
>  hw/arm/omap_sx1.c| 11 +
>  hw/arm/raspi.c  

Re: [Qemu-devel] [PATCH v6 17/49] tests/tcg/i386: add runner for test-i386-fprem

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:32 AM, Alex Bennée wrote:
> The runner needs to compare against a reference run. We also only run
> this test when SPEED=slow as it takes a while.
> 
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> 
> ---
> v5
>   - include test-i386-fprem.ref
> v5.1
>   - remove the 69Mb test-i386-fprem.ref
>   - generate test-i386-fprem.ref on developers machine
>   - add TIMEOUT=60
> ---
>  tests/tcg/i386/Makefile.target   | 16 
>  tests/tcg/i386/test-i386-fprem.c | 12 +---
>  2 files changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target
> index 8b46cc021e..64d241cfdf 100644
> --- a/tests/tcg/i386/Makefile.target
> +++ b/tests/tcg/i386/Makefile.target
> @@ -33,5 +33,21 @@ test-i386: test-i386.c test-i386-code16.S test-i386-vm86.S 
> test-i386.h test-i386
>  run-runcom: runcom pi_10.com
>   $(call quiet-command, $(QEMU) ./runcom $(I386_SRC)/pi_10.com > 
> runcom.out, "TEST", "$< on $(TARGET_NAME)")
>  
> +ifeq ($(SPEED), slow)
> +
> +test-i386-fprem.ref: test-i386-fprem
> + $(call quiet-command, ./$< > $@,"GENREF","generating $@")
> +
> +run-test-i386-fprem: TIMEOUT=60
> +run-test-i386-fprem: test-i386-fprem
> + $(call quiet-command, \
> + $(QEMU) $< > $<.out && \
> + diff -u $(I386_SRC)/$<.ref $<.out, \
> + "TEST", "$< (default) on $(TARGET_NAME)")
> +else
> +run-test-i386-fprem: test-i386-fprem
> + $(call quiet-command, /bin/true, "SLOW TEST", "$< SKIPPED on 
> $(TARGET_NAME)")
> +endif
> +
>  # On i386 and x86_64 Linux only supports 4k pages (large pages are a 
> different hack)
>  EXTRA_RUNS+=run-test-mmap-4096
> diff --git a/tests/tcg/i386/test-i386-fprem.c 
> b/tests/tcg/i386/test-i386-fprem.c
> index 1a71623204..66f5a9657d 100644
> --- a/tests/tcg/i386/test-i386-fprem.c
> +++ b/tests/tcg/i386/test-i386-fprem.c
> @@ -23,7 +23,10 @@
>   *  along with this program; if not, see .
>   */
>  
> -#include "qemu/osdep.h"
> +#include 
> +#include 
> +
> +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
>  
>  /*
>   * Inspired by 's union ieee854_long_double, but with single
> @@ -39,7 +42,7 @@ union float80u {
>  unsigned int exponent:15;
>  unsigned int negative:1;
>  unsigned int empty:16;
> -} QEMU_PACKED ieee;
> +} __attribute__((packed)) ieee;
>  
>  /* This is for NaNs in the IEEE 854 double-extended-precision format.  */
>  struct {
> @@ -49,7 +52,7 @@ union float80u {
>  unsigned int exponent:15;
>  unsigned int negative:1;
>  unsigned int empty:16;
> -} QEMU_PACKED ieee_nan;
> +} __attribute__((packed)) ieee_nan;
>  };
>  
>  #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
> @@ -229,6 +232,7 @@ static void test_fprem_cases(void)
>  do_fprem_stack_underflow();
>  
>  printf("= invalid operation =\n");
> +do_fprem(q_nan.d, 1.0);
>  do_fprem(s_nan.d, 1.0);
>  do_fprem(1.0, 0.0);
>  do_fprem(pos_inf.d, 1.0);
> @@ -238,6 +242,8 @@ static void test_fprem_cases(void)
>  do_fprem(pos_denorm.d, 1.0);
>  do_fprem(1.0, pos_denorm.d);
>  
> +do_fprem(smallest_positive_norm.d, smallest_positive_norm.d);
> +
>  /* printf("= underflow =\n"); */
>  /* TODO: Is there a case where FPREM raises underflow? */
>  }
> 



Re: [Qemu-devel] [PATCH v4 33/40] hw/i386: Use the IEC binary prefix definitions

2018-06-10 Thread Michael S. Tsirkin
On Sun, Jun 10, 2018 at 10:14:54PM -0300, Philippe Mathieu-Daudé wrote:
> @@ -1392,11 +1393,11 @@ void pc_memory_init(PCMachineState *pcms,
>  }
>  
>  machine->device_memory->base =
> -ROUND_UP(0x1ULL + pcms->above_4g_mem_size, 1ULL << 30);
> +ROUND_UP(0x1ULL + pcms->above_4g_mem_size, GiB);
>  


For some reason, GiB got special treatment. Why not 1* GiB?



Re: [Qemu-devel] [PATCH v6 44/49] tests/tcg: add run, diff, and skip helper macros

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:33 AM, Alex Bennée wrote:
> As we aren't using the default runners for all the test cases it is
> easy to miss out things like timeouts. To help with this we add some
> helpers and use them so we only need to make core changes in one
> place.

Thanks, much nicer now :)

> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> 
> ---
> v5
>   - new for v5
> v5.1
>   - diff-test->diff-out
> ---
>  tests/tcg/Makefile  | 13 ++---
>  tests/tcg/aarch64/Makefile.target   |  6 ++
>  tests/tcg/arm/Makefile.target   |  6 ++
>  tests/tcg/i386/Makefile.target  | 10 --
>  tests/tcg/multiarch/Makefile.target |  4 ++--
>  5 files changed, 20 insertions(+), 19 deletions(-)
> 
> diff --git a/tests/tcg/Makefile b/tests/tcg/Makefile
> index e7dbcdb5bf..d4c5140210 100644
> --- a/tests/tcg/Makefile
> +++ b/tests/tcg/Makefile
> @@ -34,6 +34,15 @@
>  
>  quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, 
> @$1))
>  
> +# $1 = test name, $2 = cmd, $3 = desc
> +run-test = $(call quiet-command, timeout $(TIMEOUT) $2 > $1.out,"TEST",$3)
> +
> +# $1 = test name, $2 = reference
> +diff-out = $(call quiet-command, diff -u $1.out $2 | head -n 
> 10,"DIFF","$1.out with $2")
> +
> +# $1 = test name, $2 = reason
> +skip-test = @printf "  SKIPPED %s because %s\n" $1 $2
> +
>  # Tests we are building
>  TESTS=
>  
> @@ -84,9 +93,7 @@ RUN_TESTS=$(patsubst %,run-%, $(TESTS))
>  RUN_TESTS+=$(EXTRA_RUNS)
>  
>  run-%: %
> - $(call quiet-command, \
> - timeout $(TIMEOUT) $(QEMU) $< > $<.out, \
> - "TEST", "$< on $(TARGET_NAME)")
> + $(call run-test, $<, $(QEMU) $<, "$< on $(TARGET_NAME)")
>  
>  .PHONY: run
>  run: $(RUN_TESTS)
> diff --git a/tests/tcg/aarch64/Makefile.target 
> b/tests/tcg/aarch64/Makefile.target
> index 7dba32138d..08c45b8470 100644
> --- a/tests/tcg/aarch64/Makefile.target
> +++ b/tests/tcg/aarch64/Makefile.target
> @@ -13,7 +13,5 @@ TESTS:=$(AARCH64_TESTS)
>  fcvt: LDFLAGS+=-lm
>  
>  run-fcvt: fcvt
> - $(call quiet-command, \
> - $(QEMU) $< > fcvt.out && \
> - diff -u $(AARCH64_SRC)/fcvt.ref fcvt.out, \
> - "TEST", "$< (default) on $(TARGET_NAME)")
> + $(call run-test,$<,$(QEMU) $<, "$< on $(TARGET_NAME)")
> + $(call diff-out,$<,$(AARCH64_SRC)/fcvt.ref)
> diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target
> index 14b5435fc6..aa4e4e3782 100644
> --- a/tests/tcg/arm/Makefile.target
> +++ b/tests/tcg/arm/Makefile.target
> @@ -24,10 +24,8 @@ fcvt: LDFLAGS+=-lm
>  # fcvt: CFLAGS+=-march=armv8.2-a+fp16 -mfpu=neon-fp-armv8
>  
>  run-fcvt: fcvt
> - $(call quiet-command, \
> - $(QEMU) $< > fcvt.out && \
> - diff -u $(ARM_SRC)/fcvt.ref fcvt.out, \
> - "TEST", "$< (default) on $(TARGET_NAME)")
> + $(call run-test,fcvt,$(QEMU) $<,"$< on $(TARGET_NAME)")
> + $(call diff-out,fcvt,$(ARM_SRC)/fcvt.ref)
>  endif
>  
>  # On ARM Linux only supports 4k pages
> diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target
> index cd173363ee..97b7c23cf1 100644
> --- a/tests/tcg/i386/Makefile.target
> +++ b/tests/tcg/i386/Makefile.target
> @@ -31,7 +31,7 @@ test-i386: test-i386.c test-i386-code16.S test-i386-vm86.S 
> test-i386.h test-i386
>  
>  # Specialist test runners
>  run-runcom: runcom pi_10.com
> - $(call quiet-command, $(QEMU) ./runcom $(I386_SRC)/pi_10.com > 
> runcom.out, "TEST", "$< on $(TARGET_NAME)")
> + $(call run-test,$<,$(QEMU) ./runcom $(I386_SRC)/pi_10.com,"$< on 
> $(TARGET_NAME)")
>  
>  ifeq ($(SPEED), slow)
>  
> @@ -40,13 +40,11 @@ test-i386-fprem.ref: test-i386-fprem
>  
>  run-test-i386-fprem: TIMEOUT=60
>  run-test-i386-fprem: test-i386-fprem
> - $(call quiet-command, \
> - $(QEMU) $< > $<.out && \
> - diff -u $(I386_SRC)/$<.ref $<.out, \
> - "TEST", "$< (default) on $(TARGET_NAME)")
> + $(call run-test,test-i386-fprem, $(QEMU) $<,"$< on $(TARGET_NAME)")
> + $(call diff-out,test-i386-fprem, $(I386_SRC)/$<.ref)
>  else
>  run-test-i386-fprem: test-i386-fprem
> - $(call quiet-command, /bin/true, "SLOW TEST", "$< SKIPPED on 
> $(TARGET_NAME)")
> + $(call skip-test, $<, "SLOW")
>  endif
>  
>  # On i386 and x86_64 Linux only supports 4k pages (large pages are a 
> different hack)
> diff --git a/tests/tcg/multiarch/Makefile.target 
> b/tests/tcg/multiarch/Makefile.target
> index 90e45a881e..b77084c146 100644
> --- a/tests/tcg/multiarch/Makefile.target
> +++ b/tests/tcg/multiarch/Makefile.target
> @@ -27,10 +27,10 @@ testthread: LDFLAGS+=-lpthread
>  
>  # default case (host page size)
>  run-test-mmap: test-mmap
> - $(call quiet-command, $(QEMU) $< > test-mmap.out, "TEST", \
> + $(call run-test, test-mmap, $(QEMU) $<, \
>   "$< (default) on $(TARGET_NAME)")
>  
>  # additional page sizes (defined by each architecture adding to EXTRA_RUNS)
> 

[Qemu-devel] [RFC PATCH 1/1] nvdimm: let qemu requiring section alignment of pmem resource.

2018-06-10 Thread Zhang Yi
Nvdimm driver use Memory hot-plug APIs to map it's pmem resource,
which at a section granularity.

When QEMU emulated the vNVDIMM device, decrease the label-storage,
QEMU will put the vNVDIMMs directly next to one another in physical
address space, which means that the boundary between them won't
align to the 128 MB memory section size.

Signed-off-by: Zhang Yi 
---
 hw/mem/nvdimm.c | 2 +-
 include/hw/mem/nvdimm.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index 4087aca..ff6e171 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -109,7 +109,7 @@ static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp)
 NVDIMMDevice *nvdimm = NVDIMM(dimm);
 uint64_t align, pmem_size, size = memory_region_size(mr);
 
-align = memory_region_get_alignment(mr);
+align = MAX(memory_region_get_alignment(mr), NVDIMM_ALIGN_SIZE);
 
 pmem_size = size - nvdimm->label_size;
 nvdimm->label_data = memory_region_get_ram_ptr(mr) + pmem_size;
diff --git a/include/hw/mem/nvdimm.h b/include/hw/mem/nvdimm.h
index 3c82751..1d384e4 100644
--- a/include/hw/mem/nvdimm.h
+++ b/include/hw/mem/nvdimm.h
@@ -41,6 +41,7 @@
  *at least 128KB in size, which holds around 1000 labels."
  */
 #define MIN_NAMESPACE_LABEL_SIZE  (128UL << 10)
+#define NVDIMM_ALIGN_SIZE  (128UL << 20)
 
 #define TYPE_NVDIMM  "nvdimm"
 #define NVDIMM(obj)  OBJECT_CHECK(NVDIMMDevice, (obj), TYPE_NVDIMM)
-- 
2.7.4




Re: [Qemu-devel] [PATCH v6 42/49] Makefile.target: add (clean-/build-)guest-tests targets

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:33 AM, Alex Bennée wrote:
> Now all the build infrastructure is in place we can build tests for
> each guest that we support. That support mainly depends on having
> cross compilers installed or docker setup. To keep all the logic for
> that together we put the rules in tests/tcg/Makefile.include and
> include it from the main Makefile.target.
> 
> Signed-off-by: Alex Bennée 
> 
> ---
> v4
>   - pulled Makefile.include bits from next patch
>   - added qemu-$(TARGET_NAME) dependency for running tests
>   - accept SPEED parameter to run slow tests
>   - pass BUILD_STATIC
>   - update MAINTAINERS
> v6
>   - bare make -> $(MAKE) for sub-makes
> ---
>  MAINTAINERS|  1 +
>  Makefile.target|  5 +++
>  tests/tcg/Makefile.include | 88 ++
>  3 files changed, 94 insertions(+)
>  create mode 100644 tests/tcg/Makefile.include
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 4761f8cab4..6c1eca3a1c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2147,6 +2147,7 @@ W: http://patchew.org/QEMU/
>  Guest Test Compilation Support
>  M: Alex Bennée 
>  F: tests/tcg/Makefile
> +F: tests/tcg/Makefile.include
>  L: qemu-devel@nongnu.org
>  
>  Documentation
> diff --git a/Makefile.target b/Makefile.target
> index dad2cf8778..a9d8928f96 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -36,6 +36,11 @@ endif
>  PROGS=$(QEMU_PROG) $(QEMU_PROGW)
>  STPFILES=
>  
> +# Makefile Tests
> +ifdef CONFIG_USER_ONLY
> +include $(SRC_PATH)/tests/tcg/Makefile.include
> +endif
> +
>  config-target.h: config-target.h-timestamp
>  config-target.h-timestamp: config-target.mak
>  
> diff --git a/tests/tcg/Makefile.include b/tests/tcg/Makefile.include
> new file mode 100644
> index 00..4851df0951
> --- /dev/null
> +++ b/tests/tcg/Makefile.include
> @@ -0,0 +1,88 @@
> +# -*- Mode: makefile -*-
> +#
> +# TCG tests (per-target rules)
> +#
> +# This Makefile fragement is included from the per-target
> +# Makefile.target so will be invoked for each linux-user program we
> +# build. We have two options for compiling, either using a configured
> +# guest compiler or calling one of our docker images to do it for us.
> +#
> +
> +# The per ARCH makefile, if it exists, holds extra information about
> +# useful docker images or alternative compiler flags.
> +
> +-include $(SRC_PATH)/tests/tcg/$(TARGET_BASE_ARCH)/Makefile.include
> +-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.include
> +
> +GUEST_BUILD=
> +TCG_MAKE=$(SRC_PATH)/tests/tcg/Makefile
> +# Support installed Cross Compilers
> +
> +ifdef CROSS_CC_GUEST
> +
> +.PHONY: cross-build-guest-tests
> +cross-build-guest-tests:
> + $(call quiet-command, \
> +(mkdir -p tests && cd tests && \
> + $(MAKE) -f $(TCG_MAKE) CC=$(CROSS_CC_GUEST) \
> + BUILD_STATIC=$(CROSS_CC_GUEST_STATIC) \
> + EXTRA_CFLAGS=$(CROSS_CC_GUEST_CFLAGS)), \
> + "CROSS-BUILD","$(TARGET_NAME) guest-tests with $(CROSS_CC_GUEST)")
> +
> +GUEST_BUILD=cross-build-guest-tests
> +
> +endif
> +
> +# Support building with Docker
> +
> +ifeq ($(HAVE_USER_DOCKER)$(GUEST_BUILD),y)
> +ifneq ($(DOCKER_IMAGE),)
> +
> +# We also need the Docker make rules to depend on
> +include $(SRC_PATH)/tests/docker/Makefile.include
> +
> +DOCKER_COMPILE_CMD="$(DOCKER_SCRIPT) cc --user $(shell id -u) \
> + --cc $(DOCKER_CROSS_COMPILER) \
> + -i qemu:$(DOCKER_IMAGE) \
> + -s $(SRC_PATH) -- "
> +DOCKER_PREREQ=docker-image-$(DOCKER_IMAGE)
> +
> +.PHONY: docker-build-guest-tests
> +docker-build-guest-tests: $(DOCKER_PREREQ)
> + $(call quiet-command, \
> +   (mkdir -p tests && cd tests && \
> +$(MAKE) -f $(TCG_MAKE) CC=$(DOCKER_COMPILE_CMD) \
> + BUILD_STATIC=y \
> + EXTRA_CFLAGS=$(DOCKER_CROSS_COMPILER_CFLAGS)), \
> + "CROSS-BUILD","$(TARGET_NAME) guest-tests with docker 
> qemu:$(DOCKER_IMAGE)")
> +
> +GUEST_BUILD=docker-build-guest-tests
> +
> +endif
> +endif
> +
> +# Final targets
> +.PHONY: guest-tests
> +
> +ifneq ($(GUEST_BUILD),)
> +guest-tests: $(GUEST_BUILD)
> +
> +run-guest-tests: guest-tests qemu-$(TARGET_NAME)
> + $(call quiet-command, \
> + (cd tests && $(MAKE) -f $(TCG_MAKE) SPEED=$(SPEED) run), \
> + "RUN-TESTS", "for $(TARGET_NAME)")
> +
> +else
> +guest-tests:
> + $(call quiet-command, /bin/true, "CROSS-BUILD", \
> + "$(TARGET_NAME) guest-tests SKIPPED")
> +
> +run-guest-tests:
> + $(call quiet-command, /bin/true, "RUN-TESTS", \
> + "for $(TARGET_NAME) SKIPPED")
> +endif
> +
> +# It doesn't mater if these don't exits

"matter"?

> +.PHONY: clean-guest-tests
> +clean-guest-tests:
> + rm -rf tests || echo "no $(TARGET_NAME) tests to remove"
> 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 



Re: [Qemu-devel] [PATCH v6 49/49] .travis.yml: add check-tcg test

2018-06-10 Thread Philippe Mathieu-Daudé
Hi Alex,

On 06/08/2018 09:33 AM, Alex Bennée wrote:
> Signed-off-by: Alex Bennée 
> ---
>  .travis.yml | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/.travis.yml b/.travis.yml
> index 814be151f4..f1d2d9edec 100644
> --- a/.travis.yml
> +++ b/.travis.yml
> @@ -152,3 +152,9 @@ matrix:
>  - TEST_CMD=""
>before_script:
>  - ./configure ${CONFIG} --extra-cflags="-g3 -O0 -fsanitize=thread 
> -fuse-ld=gold" || cat config.log
> +- env:
> +- CONFIG="--disable-system --disable-docs"
> +- TEST_CMD="make check-tcg"

Since we have default MAKEFLAGS="-j3"

I'm getting many failures:

  CROSS-BUILD ppc64le guest-tests with docker qemu:debian-ppc64el-cross
  BUILD   debian-riscv64-cross
  BUILD   debian-s390x-cross
  CROSS-BUILD riscv64 guest-tests with docker qemu:debian-riscv64-cross
  CROSS-BUILD s390x guest-tests with docker qemu:debian-s390x-cross
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
  File "/home/travis/qemu/tests/docker/docker.py", line 174, in
_kill_instances
return self._do_kill_instances(True)
  File "/home/travis/qemu/tests/docker/docker.py", line 154, in
_do_kill_instances
resp = self._output(["inspect", i])
  File "/home/travis/qemu/tests/docker/docker.py", line 179, in _output
**kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 223, in check_output
raise CalledProcessError(retcode, cmd, output=output)
CalledProcessError: Command '['docker', 'inspect', 'c71dbe973c55']'
returned non-zero exit status 1
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
  File "/home/travis/qemu/tests/docker/docker.py", line 174, in
_kill_instances
return self._do_kill_instances(True)
  File "/home/travis/qemu/tests/docker/docker.py", line 154, in
_do_kill_instances
resp = self._output(["inspect", i])
  File "/home/travis/qemu/tests/docker/docker.py", line 179, in _output
**kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 223, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['docker', 'inspect',
'c71dbe973c55']' returned non-zero exit status 1
  BUILD   debian-sid
  GEN sh4eb-linux-user/config-target.h
  CROSS-BUILD sh4eb guest-tests SKIPPED
  CROSS-BUILD sparc guest-tests SKIPPED
  GEN sparc32plus-linux-user/config-target.h
  CROSS-BUILD sparc32plus guest-tests SKIPPED
  BUILD   debian-sid

This works fine adding:

 - MAKEFLAGS="-j1"

Adding MAKEFLAGS="-j1":
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> +  sudo: required
> +  dist: trusty
> +  compiler: gcc
> 



Re: [Qemu-devel] storing machine data in qcow images?

2018-06-10 Thread Michael S. Tsirkin
On Sat, Jun 09, 2018 at 11:34:03PM +0200, Max Reitz wrote:
> qemu would be very easy to use if it didn't offer any configuration
> options.  The problem is that is offers a huge load of configuration
> options and it is not reasonable to expect every user to know all of them.

Right but once one user id find a way to make a specific guest work in a
specific VM, it should not be as hard as it is to replicate the success.

...

> > This just means we should make it flexible enough to possibly
> > support more uses. It does not mean we need to make it
> > read mail on day 1.
> 
> So you are saying that we may end up with multiple parties storing
> (meta-)data independently in the qcow2 file?

Absolutely.

> before there are concrete design documents, and on why it doesn't matter
> that you focus on qemu whereas others focus on the management layer.

Right. That's what I'm saying.

> Though it would mean opaque storage, as I've said, and that storing data
> in the qcow2 file still probably does not make sense for some of the
> possible use cases.  For instance, you propose storing data for qemu
> proper without any management layer, but this poses the question again
> of who should interpret that data.  (A management layer may just query
> the image before launching qemu and then set the appropriate options,
> but it gets difficult for the block layer to open the qcow2 image and
> change the machine type when qemu is already running.  Though maybe you
> could at least error out when incompatible options have been used to
> launch qemu.  Hm.  Another question was who'd be supposed to store the
> data.)
> 
> [...]
> 
> >> And if you make the format decidedly qcow2-independent, the whole
> >> "putting it into qcow2 is the simplest implementation" argument becomes
> >> rather weak.
> > 
> > I don't see why. Yes I think it's a separate format that we should just
> > allow storing in qcow2 for usability.
> 
> It becomes weak because storing it in qcow2 would no longer be the
> simplest implementation if you'd need to be able to read it from a file
> outside of a qcow2 image anyway.
> 
> It still may be the easiest use case for users.
> 
> [...]
> 
> >> But all of that writing once again comes down to this: You are talking
> >> about qemu.  Dave is talking about something higher in the management
> >> layer.  Those are different things, and as I said, we first need to find
> >> common ground there.
> > 
> > The common ground is that both me and Dave find it useful to store meta-data
> > in the disk image.
> 
> Though it seems to me that you have very different ideas on how to store
> it.  As far as I have understood, Dave just wants to store a bit of data
> that might even go into the image header, whereas you'd prefer a
> full-blown infrastructure for binary storage and large objects, because
> someone might want that at some point.
> 
> That isn't to say I personally prefer either, it just means that those
> are different and deciding on one naturally changes what to do.
> 
> There may be even other approaches, I don't know.

I thought I heard Dave utter "key-value store" at some point,
which likely precludes "go directly into the header".


> And my idea was that we should evaluate the different use cases for
> storing arbitrary metadata in a qcow2 file, and then we'd see whether it
> does or doesn't make sense to do so, for each case.

As block guys maybe you could ask more specific questions then.
E.g. "would 1/2K of data be sufficient for these purposes"?
That's a more valid point than a generic "tells us what it's
for" question.

> I think making qemu store something in the qcow2 file doesn't bring too
> much because first, qemu couldn't really interpret that information by
> itself (it could at best detect conflicting configuration, though in my
> head checking qemu configuration in the qcow2 driver screams complexity;
> and storing that information automatically would be problematic); and
> secondly, I don't think that we can solve the complexity that is modern
> qemu configuration by just putting it into a qcow2 file.  That will only
> work as long as the user doesn't want to change anything.  There is
> probably much more to say, but all of that would deserve its own thread.

But I do think we can solve only doing it once and not per user
of an image.

> Regarding designing an appliance format, there has already been some
> discussion, so I won't say anything about that now, except that it too
> should go into its own thread so that people are aware and don't think
> it's just a qcow2 issue.
> 
> >> This is exactly why I said "where to store it heavily depends on what we
> >> want to store and how we want to use it."  As long as we don't know
> >> that, all of us are using strawman arguments where some other party
> >> suddenly chimes in and says "no, no, no, this is not what I'm talking
> >> about".  Yes, maybe you aren't, but someone else is.
> >>
> >> [...]
> > 
> > Looks like discussion has run its 

Re: [Qemu-devel] [PATCH v6 00/49] fix building of tests/tcg

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:32 AM, Alex Bennée wrote:
> Hi,
> 
> Not a super amount has changed since the last version but review
> comments and review tags have been added. The new patches at the end
> enable a .travis.yml run and try and make the image building part of
> check-tcg -j safe. Essentially the problem is trying to avoid
> re-building the images multiple times. The additional issue is wanting
> an upto date Debian SID image whenever we actually build an image but
> not forcing a rebuild every time.
> 
> Essentially I'd like to encode a conditional dependency when:
>   - the target image doesn't exist
>   - or the target image is out of date w.r.t. the dockerfike
> 
> I'm thinking this is going to involve some sort of extension to the
> docker.py script to feed the Makefile.
> 
> A number of the prerequisite patches have already been pulled in the
> docker fixes series however I think this series is ready to go in now.
> Unless there are any objections I'll send a pull on Monday.
> 
> Current unreviewed patches:
> 
>   patch 0017/tests tcg i386 add runner for test i386 fprem.patch needs review
>   patch 0039/docker move debian powerpc cross to sid based bui.patch needs 
> review
>   patch 0040/tests tcg enable building for PowerPC.patch needs review
>   patch 0042/Makefile.target add clean build guest tests targe.patch needs 
> review
>   patch 0044/tests tcg add run diff and skip helper macros.patch needs review
>   patch 0045/tests tcg override runners for broken tests.patch needs review
>   patch 0046/target sh4 Fix translator.c assertion failure for.patch needs 
> review

Is this patch related/required to this series?
It looks it should enter via another tree.

The SH4 tests pass without it:

$ make run-tcg-tests-sh4-linux-user -j1
  ...
  RUN-TESTS for sh4
  TESTtest-mmap (default) on sh4
  TESTsha1 on sh4
  TESTlinux-test on sh4
  TESTtestthread on sh4
  TESTtest-mmap (4096 byte pages) on sh4

>   patch 0047/tests add top level make dependency for docker bu.patch needs 
> review
>   patch 0048/tests docker prevent sub makes re building debian.patch needs 
> review
>   patch 0049/.travis.yml add check tcg test.patch needs review
> 
> 
> Alex Bennée (46):
>   configure: add support for --cross-cc-FOO
>   configure: move i386_cc to cross_cc_i386
>   configure: allow user to specify --cross-cc-cflags-foo=
>   configure: set cross_cc_FOO for host compiler
>   docker: Add "cc" subcommand
>   docker: extend "cc" command to accept compiler
>   docker: allow "cc" command to run in user context
>   docker: Makefile.include introduce DOCKER_SCRIPT
>   tests/tcg: move architecture independent tests into subdir
>   tests/tcg/multiarch: enable additional linux-test tests
>   tests/tcg/multiarch: move most output to stdout
>   tests/tcg: move i386 specific tests into subdir
>   tests/tcg: enable building for i386
>   tests/tcg/i386: fix test-i386
>   tests/tcg/i386: add runner for test-i386-fprem
>   tests/tcg/x86_64: add Makefile.target
>   tests/tcg/i386/test-i386: use modern vector_size attributes
>   tests/tcg/i386/test-i386: fix printf format
>   tests/tcg: move ARM specific tests into subdir
>   tests/tcg: enable building for ARM
>   tests/tcg/arm: fix up test-arm-iwmmxt test
>   tests/tcg: enable building for AArch64
>   tests/tcg/arm: add fcvt test cases for AArch32/64
>   tests/tcg: move MIPS specific tests into subdir
>   tests/tcg: enable building for MIPS
>   tests/tcg/mips: include common mips hello-mips
>   tests/tcg: enable building for s390x
>   tests/tcg: enable building for ppc64
>   tests/tcg: enable building for Alpha
>   tests/tcg/alpha: add Alpha specific tests
>   tests/tcg: enable building for HPPA
>   tests/tcg: enable building for m68k
>   tests/tcg: enable building for sh4
>   tests/tcg: enable building for sparc64
>   tests/tcg: enable building for mips64
>   tests/tcg: enable building for RISCV64
>   docker: move debian-powerpc-cross to sid based build
>   tests/tcg: enable building for PowerPC
>   tests/tcg/Makefile: update to be called from Makefile.target
>   Makefile.target: add (clean-/build-)guest-tests targets
>   tests/Makefile.include: add [build|clean|check]-tcg targets
>   tests/tcg: add run, diff, and skip helper macros
>   tests/tcg: override runners for broken tests
>   tests: add top-level make dependency for docker builds
>   tests/docker: prevent sub-makes re-building debian-sid
>   .travis.yml: add check-tcg test
> 
> Fam Zheng (2):
>   tests/tcg/multiarch: Build fix for linux-test
>   tests/tcg/i386: Build fix for hello-i386
> 
> Richard Henderson (1):
>   target/sh4: Fix translator.c assertion failure for gUSA
> 
>  .travis.yml   |6 +
>  MAINTAINERS   |   14 +
>  Makefile.target   |5 +
>  configure |  134 +-
>  target/sh4/translate.c|   81 +-
>  tests/Makefile.include  

Re: [Qemu-devel] [PATCH v6 45/49] tests/tcg: override runners for broken tests

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:33 AM, Alex Bennée wrote:
> To get a clean run of check-tcg these tests are currently skipped:
> 
>   - hello-mips for mips
>   - linux-test for sparc
> 
> Signed-off-by: Alex Bennée 
> 
> ---
> v4
>   - document broken tests in commit
>   - temporarily demote fcvt while fixes percolate upstream
> v5
>   - reinstate fcvt
>   - remove test-mmap overrides (done with EXTRA_RUNS now)
> v6
>   - move to after the skip-test helper
> ---
>  tests/tcg/mips/Makefile.target| 3 +++
>  tests/tcg/sparc64/Makefile.target | 7 ++-
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/tcg/mips/Makefile.target b/tests/tcg/mips/Makefile.target
> index 71f0c2dd53..086625f533 100644
> --- a/tests/tcg/mips/Makefile.target
> +++ b/tests/tcg/mips/Makefile.target
> @@ -17,3 +17,6 @@ hello-mips: LDFLAGS+=-nostdlib
>  
>  # For MIPS32 and 64 we have a bunch of extra tests in sub-directories
>  # however they are intended for system tests.
> +
> +run-hello-mips: hello-mips
> + $(call skip-test, $<, "BROKEN")
> diff --git a/tests/tcg/sparc64/Makefile.target 
> b/tests/tcg/sparc64/Makefile.target
> index 408dace783..064c7a598b 100644
> --- a/tests/tcg/sparc64/Makefile.target
> +++ b/tests/tcg/sparc64/Makefile.target
> @@ -1,6 +1,11 @@
>  # -*- Mode: makefile -*-
>  #
> -# sparc specific tweaks
> +# sparc specific tweaks and masking out broken tests
> +
> +# different from the other hangs
> +# /home/alex/lsrc/qemu/qemu.git/tests/tcg/multiarch/linux-test.c:264: Value 
> too large for defined data type (ret=-1, errno=92/Value too large for defined 
> data type)

Tested-by: Philippe Mathieu-Daudé 

Dropping "/home/alex/lsrc/qemu/qemu.git/":
Reviewed-by: Philippe Mathieu-Daudé 

> +run-linux-test: linux-test
> + $(call skip-test, $<, "BROKEN")
>  
>  # On Sparc64 Linux support 8k pages
>  EXTRA_RUNS+=run-test-mmap-8192
> 



Re: [Qemu-devel] [PATCH v6 47/49] tests: add top-level make dependency for docker builds

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:33 AM, Alex Bennée wrote:
> One problem with satisfying your docker dependencies in a sub-make it
> you might end up trying to satisfy the dependency multiple times. This
> is especially a problem with debian-sid based cross compilers and CI
> setups. We solve this by doing a docker build pass at the top level
> before any sub-makes are called.
> 
> We still need to satisfy dependencies in the Makefile.target call so
> people can run tests from individual target directories. We introduce
> a new Makefile.probe which gets called for each PROBE_TARGET and
> allows us to build up the list. It does require multiply including
> config-target.mak which shouldn't cause any issues as it shouldn't
> define anything that clashes with config-host.mak. However we undefine
> a few key variables each time around.
> 
> Signed-off-by: Alex Bennée 
> ---
>  tests/Makefile.include   | 14 +-
>  tests/tcg/Makefile.probe | 31 +++
>  2 files changed, 44 insertions(+), 1 deletion(-)
>  create mode 100644 tests/tcg/Makefile.probe
> 
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index ca00247e36..049a387436 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -931,7 +931,19 @@ BUILD_TCG_TARGET_RULES=$(patsubst %,build-tcg-tests-%, 
> $(LINUX_USER_TARGETS))
>  CLEAN_TCG_TARGET_RULES=$(patsubst %,clean-tcg-tests-%, $(LINUX_USER_TARGETS))
>  RUN_TCG_TARGET_RULES=$(patsubst %,run-tcg-tests-%, $(LINUX_USER_TARGETS))
>  
> -build-tcg-tests-%:
> +# Probe for the Docker Builds we need for later
> +DOCKER_BUILD_TARGETS:=
> +$(foreach PROBE_TARGET,$(TARGET_LIST),   \
> + $(eval -include $(SRC_PATH)/tests/tcg/Makefile.probe)   \
> + $(if $(DOCKER_PREREQ),  \
> + $(eval DOCKER_BUILD_TARGETS+=$(DOCKER_PREREQ
> +
> +$(info DOCKER_BUILD_TARGETS=$(sort $(DOCKER_BUILD_TARGETS)))
> +
> +.PHONY: build-docker-prereqs
> +build-docker-prereqs: $(sort $(DOCKER_BUILD_TARGETS))

It seems now all docker images are built, even if you want to test a
single arch... Using ~7GB of storage at once.

> +
> +build-tcg-tests-%: build-docker-prereqs
>   $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" 
> TARGET_DIR="$*/" guest-tests,)
>  
>  run-tcg-tests-%: build-tcg-tests-%
> diff --git a/tests/tcg/Makefile.probe b/tests/tcg/Makefile.probe
> new file mode 100644
> index 00..7529e203ad
> --- /dev/null
> +++ b/tests/tcg/Makefile.probe
> @@ -0,0 +1,31 @@
> +# -*- Mode: makefile -*-
> +#
> +# TCG Compiler Probe
> +#
> +# This Makefile fragement is included multiple times in the main make
> +# script to probe for available compilers. This is used to build up a
> +# selection of required docker targets before we invoke a sub-make for
> +# each target.
> +
> +# First we need the target makefile which tells us the target architecture
> +-include $(BUILD_DIR)/$(PROBE_TARGET)/config-target.mak
> +
> +# Then we load up the target architecture makefiles which tell us
> +# about the compilers
> +undefine CROSS_CC_GUEST
> +undefine DOCKER_IMAGE
> +DOCKER_PREREQ:=
> +
> +-include $(SRC_PATH)/tests/tcg/$(TARGET_BASE_ARCH)/Makefile.include
> +-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.include
> +
> +ifndef CROSS_CC_GUEST
> +ifneq ($(DOCKER_IMAGE),)
> +DOCKER_PREREQ:=docker-image-$(DOCKER_IMAGE)
> +endif
> +endif
> +
> +# Clean-up
> +undefine TARGET_NAME
> +undefine TARGET_BASE_ARCH
> +undefine TARGET_ABI_DIR
> 



Re: [Qemu-devel] [PATCH V8 14/17] filter: Add handle_event method for NetFilterClass

2018-06-10 Thread Jason Wang




On 2018年06月10日 22:09, Zhang Chen wrote:

I think when COLO is enabled, qemu should reject all other types of
backends.

Yes, you are right.
May be we should add a assert here? Because we can not get backend info when
colo-compare start up.
Have any idea?




Is there a global variable or function to detect the COLO existence? If 
yes, maybe we could use that.


Thanks




Re: [Qemu-devel] [PATCH v4 16/40] hw/riscv: Use the IEC binary prefix definitions

2018-06-10 Thread Michael Clark
On Mon, Jun 11, 2018 at 1:14 PM, Philippe Mathieu-Daudé 
wrote:

> It eases code review, unit is explicit.
>
> Patch generated using:
>
>   $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/
> include/hw/
>
> and modified manually.
>
> Signed-off-by: Philippe Mathieu-Daudé 
>

Reviewed-by: Michael Clark 


> ---
>  hw/riscv/virt.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index ad03113e0f..34d48993a2 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -19,6 +19,7 @@
>   */
>
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "qemu/log.h"
>  #include "qemu/error-report.h"
>  #include "qapi/error.h"
> @@ -84,7 +85,7 @@ static hwaddr load_initrd(const char *filename, uint64_t
> mem_size,
>   * halfway into RAM, and for boards with 256MB of RAM or more we put
>   * the initrd at 128MB.
>   */
> -*start = kernel_entry + MIN(mem_size / 2, 128 * 1024 * 1024);
> +*start = kernel_entry + MIN(mem_size / 2, 128 * MiB);
>
>  size = load_ramdisk(filename, *start, mem_size - *start);
>  if (size == -1) {
> --
> 2.17.1
>
>


Re: [Qemu-devel] [PATCH v6 40/49] tests/tcg: enable building for PowerPC

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:32 AM, Alex Bennée wrote:
> Now we have restored debian-image-powerpc-cross using Debian SID
> compilers we can build for 32 bit powerpc. Although PPC32 supports a
> range of pages sizes currently only 4k works so the others are
> commented out for now.
> 
> We can also merge the ppc64 support under the base architecture
> directory to avoid too much proliferation of directories.

ppc64el doesn't seem to work:

$ make subdir-ppc64le-linux-user build-tcg-tests-ppc64el-linux-user -j1
make[1]: *** ppc64el-linux-user: No such file or directory.  Stop.
make: *** [tests/Makefile.include:947:
build-tcg-tests-ppc64el-linux-user] Error 2

> Signed-off-by: Alex Bennée 

ppc32:

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> 
> ---
> v5
>   - new for v5
> ---
>  tests/tcg/ppc/Makefile.include |  7 +++
>  tests/tcg/ppc/Makefile.target  | 12 
>  tests/tcg/ppc64le/Makefile.include |  2 --
>  3 files changed, 19 insertions(+), 2 deletions(-)
>  create mode 100644 tests/tcg/ppc/Makefile.include
>  create mode 100644 tests/tcg/ppc/Makefile.target
>  delete mode 100644 tests/tcg/ppc64le/Makefile.include
> 
> diff --git a/tests/tcg/ppc/Makefile.include b/tests/tcg/ppc/Makefile.include
> new file mode 100644
> index 00..b062c30dd3
> --- /dev/null
> +++ b/tests/tcg/ppc/Makefile.include
> @@ -0,0 +1,7 @@
> +ifeq ($(TARGET_NAME),ppc)
> +DOCKER_IMAGE=debian-powerpc-cross
> +DOCKER_CROSS_COMPILER=powerpc-linux-gnu-gcc
> +else ifeq ($(TARGET_NAME),ppc64le)
> +DOCKER_IMAGE=debian-ppc64el-cross
> +DOCKER_CROSS_COMPILER=powerpc64le-linux-gnu-gcc
> +endif
> diff --git a/tests/tcg/ppc/Makefile.target b/tests/tcg/ppc/Makefile.target
> new file mode 100644
> index 00..f5e08c7376
> --- /dev/null
> +++ b/tests/tcg/ppc/Makefile.target
> @@ -0,0 +1,12 @@
> +# -*- Mode: makefile -*-
> +#
> +# PPC - included from tests/tcg/Makefile
> +#
> +
> +ifneq (,$(findstring 64,$(TARGET_NAME)))
> +# On PPC64 Linux can be configured with 4k (default) or 64k pages (currently 
> broken)
> +EXTRA_RUNS+=run-test-mmap-4096 #run-test-mmap-65536
> +else
> +# On PPC32 Linux supports 4K/16K/64K/256K (but currently only 4k works)
> +EXTRA_RUNS+=run-test-mmap-4096 #run-test-mmap-16384 run-test-mmap-65536 
> run-test-mmap-262144
> +endif
> diff --git a/tests/tcg/ppc64le/Makefile.include 
> b/tests/tcg/ppc64le/Makefile.include
> deleted file mode 100644
> index d71cfc9aa7..00
> --- a/tests/tcg/ppc64le/Makefile.include
> +++ /dev/null
> @@ -1,2 +0,0 @@
> -DOCKER_IMAGE=debian-ppc64el-cross
> -DOCKER_CROSS_COMPILER=powerpc64le-linux-gnu-gcc
> 



[Qemu-devel] [PATCH v4 40/40] cutils: Do not include "qemu/units.h" directly

2018-06-10 Thread Philippe Mathieu-Daudé
All files using "qemu/units.h" definitions already include it directly,
we can now remove it from "qemu/cutils.h".

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Marcel Apfelbaum 
---
 include/qemu/cutils.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 056e6629bb..cdb0f0db75 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -2,7 +2,6 @@
 #define QEMU_CUTILS_H
 
 #include "qemu/fprintf-fn.h"
-#include "qemu/units.h"
 
 /**
  * pstrcpy:
-- 
2.17.1




[Qemu-devel] [PATCH v4 32/40] hw/ppc: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Acked-by: David Gibson 
---
 hw/ppc/mac.h   |  3 ++-
 include/hw/ppc/spapr.h |  5 +++--
 hw/nvram/spapr_nvram.c | 10 ++
 hw/pci-host/prep.c |  3 ++-
 hw/ppc/e500.c  | 13 +++--
 hw/ppc/e500plat.c  |  3 ++-
 hw/ppc/mac_newworld.c  |  1 -
 hw/ppc/mac_oldworld.c  |  9 -
 hw/ppc/ppc405_boards.c |  9 +
 hw/ppc/ppc405_uc.c |  7 ---
 hw/ppc/ppc440_bamboo.c |  6 --
 hw/ppc/ppc4xx_devs.c   | 22 --
 hw/ppc/ppce500_spin.c  |  3 ++-
 hw/ppc/prep.c  |  4 ++--
 hw/ppc/rs6000_mc.c | 13 +++--
 hw/ppc/sam460ex.c  | 18 ++
 hw/ppc/spapr.c |  2 +-
 hw/ppc/virtex_ml507.c  |  7 ---
 18 files changed, 77 insertions(+), 61 deletions(-)

diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h
index 22a7efbed6..c0af576f8c 100644
--- a/hw/ppc/mac.h
+++ b/hw/ppc/mac.h
@@ -26,6 +26,7 @@
 #ifndef PPC_MAC_H
 #define PPC_MAC_H
 
+#include "qemu/units.h"
 #include "exec/memory.h"
 #include "hw/sysbus.h"
 #include "hw/ide/internal.h"
@@ -37,7 +38,7 @@
 /* SMP is not enabled, for now */
 #define MAX_CPUS 1
 
-#define BIOS_SIZE (1024 * 1024)
+#define BIOS_SIZE(1 * MiB)
 #define NVRAM_SIZE0x2000
 #define PROM_FILENAME"openbios-ppc"
 #define PROM_ADDR 0xfff0
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 3388750fc7..210cbdd2ca 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -1,6 +1,7 @@
 #ifndef HW_SPAPR_H
 #define HW_SPAPR_H
 
+#include "qemu/units.h"
 #include "sysemu/dma.h"
 #include "hw/boards.h"
 #include "hw/ppc/xics.h"
@@ -747,8 +748,8 @@ int spapr_rng_populate_dt(void *fdt);
  */
 #define SPAPR_MAX_RAM_SLOTS 32
 
-/* 1GB alignment for device memory region */
-#define SPAPR_DEVICE_MEM_ALIGN (1ULL << 30)
+/* 1GB alignment for hotplug memory region */
+#define SPAPR_DEVICE_MEM_ALIGN (1 * GiB)
 
 /*
  * Number of 32 bit words in each LMB list entry in ibm,dynamic-memory
diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index 4a0aec8e1d..3c88f42acf 100644
--- a/hw/nvram/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -47,9 +48,9 @@ typedef struct sPAPRNVRAM {
 #define VIO_SPAPR_NVRAM(obj) \
  OBJECT_CHECK(sPAPRNVRAM, (obj), TYPE_VIO_SPAPR_NVRAM)
 
-#define MIN_NVRAM_SIZE 8192
-#define DEFAULT_NVRAM_SIZE 65536
-#define MAX_NVRAM_SIZE 1048576
+#define MIN_NVRAM_SIZE  (8 * KiB)
+#define DEFAULT_NVRAM_SIZE  (64 * KiB)
+#define MAX_NVRAM_SIZE  (1 * MiB)
 
 static void rtas_nvram_fetch(PowerPCCPU *cpu, sPAPRMachineState *spapr,
  uint32_t token, uint32_t nargs,
@@ -167,7 +168,8 @@ static void spapr_nvram_realize(VIOsPAPRDevice *dev, Error 
**errp)
 nvram->buf = g_malloc0(nvram->size);
 
 if ((nvram->size < MIN_NVRAM_SIZE) || (nvram->size > MAX_NVRAM_SIZE)) {
-error_setg(errp, "spapr-nvram must be between %d and %d bytes in size",
+error_setg(errp,
+   "spapr-nvram must be between %llu and %llu bytes in size",
MIN_NVRAM_SIZE, MAX_NVRAM_SIZE);
 return;
 }
diff --git a/hw/pci-host/prep.c b/hw/pci-host/prep.c
index 01f67f9db1..88f035c20b 100644
--- a/hw/pci-host/prep.c
+++ b/hw/pci-host/prep.c
@@ -24,6 +24,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
@@ -70,7 +71,7 @@ typedef struct PRePPCIState {
 int contiguous_map;
 } PREPPCIState;
 
-#define BIOS_SIZE (1024 * 1024)
+#define BIOS_SIZE (1 * MiB)
 
 static inline uint32_t raven_pci_io_config(hwaddr addr)
 {
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 826053edc8..7d19b1498c 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -15,6 +15,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "e500.h"
 #include "e500-ccsr.h"
@@ -46,11 +47,11 @@
 #define BINARY_DEVICE_TREE_FILE"mpc8544ds.dtb"
 #define DTC_LOAD_PAD   0x180
 #define DTC_PAD_MASK   0xF
-#define DTB_MAX_SIZE   (8 * 1024 * 1024)
+#define DTB_MAX_SIZE   (8 * MiB)
 #define INITRD_LOAD_PAD0x200
 #define INITRD_PAD_MASK0xFF
 
-#define RAM_SIZES_ALIGN(64UL << 20)
+#define RAM_SIZES_ALIGN(64 * MiB)
 
 /* TODO: parameterize */
 #define MPC8544_CCSRBAR_SIZE   0x0010ULL
@@ -603,7 +604,7 @@ static int ppce500_prep_device_tree(PPCE500MachineState 
*machine,
 /* Create -kernel TLB entries for BookE.  */
 hwaddr booke206_page_size_to_tlb(uint64_t size)
 {
-return 63 - clz64(size >> 10);
+return 63 - clz64(size / KiB);
 }
 
 static 

Re: [Qemu-devel] [PATCH v6 41/49] tests/tcg/Makefile: update to be called from Makefile.target

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:32 AM, Alex Bennée wrote:
> This make is now invoked from each individual target make with the
> appropriate CC and EXTRA_CFLAGS set for each guest. It then includes
> additional Makefile.targets from:
> 
>   - tests/tcg/multiarch (always)
>   - tests/tcg/$(TARGET_BASE_ARCH) (if available)
>   - tests/tcg/$(TARGET_NAME)
> 
> The order is important as the later Makefile's may want to suppress
> TESTS from its base arch profile. Each included Makefile.target is
> responsible for adding TESTS as well as defining any special build
> instructions for individual tests.
> 
> Signed-off-by: Alex Bennée 
> Reviewed-by: Richard Henderson 
> Reviewed-by: Philippe Mathieu-Daudé 
> Tested-by: Philippe Mathieu-Daudé 
> ---
> v2
>   - cleaner approach to include sub makefiles
>   - move TESTS/VPATH manipulation into sub-makefile
>   - avoid double inclusion when TARGET_BASE_ARCH==TARGET_NAME
> v4
>   - add timeout to default runner
>   - clean-up comments about build flags
>   - update to handle BUILD_STATIC
>   - add MAINTAINERS entry
> v5
>   - support EXTRA_RUNS for run variants
> v6
>   - extend timeout for DEBUG_TCG
> ---
>  MAINTAINERS|   5 ++
>  tests/tcg/Makefile | 183 +++--
>  2 files changed, 81 insertions(+), 107 deletions(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index b8fbef495b..4761f8cab4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2144,6 +2144,11 @@ W: https://travis-ci.org/qemu/qemu
>  W: https://app.shippable.com/github/qemu/qemu
>  W: http://patchew.org/QEMU/
>  
> +Guest Test Compilation Support
> +M: Alex Bennée 

Since I'm interested in cross-builds and planning further testing, can
you also add a R-tag for me please?

R: Philippe Mathieu-Daudé 

> +F: tests/tcg/Makefile
> +L: qemu-devel@nongnu.org
> +
>  Documentation
>  -
>  Build system architecture
> diff --git a/tests/tcg/Makefile b/tests/tcg/Makefile
> index e12395117a..e7dbcdb5bf 100644
> --- a/tests/tcg/Makefile
> +++ b/tests/tcg/Makefile
> @@ -1,125 +1,94 @@
> +# -*- Mode: makefile -*-
> +#
> +# TCG tests
> +#
> +# These are complicated by the fact we want to build them for guest
> +# systems. This requires knowing what guests we are building and which
> +# ones we have cross-compilers for or docker images with
> +# cross-compilers.
> +#
> +# The tests themselves should be as minimal as possible as
> +# cross-compilers don't always have a large amount of libraries
> +# available.
> +#
> +# We only include the host build system for SRC_PATH and we don't
> +# bother with the common rules.mk. We expect the following:
> +#
> +#   CC - the C compiler command
> +#   EXTRA_CFLAGS - any extra CFLAGS
> +#   BUILD_STATIC - are we building static binaries
> +#
> +# By default all tests are statically compiled but some host systems
> +# may not package static libraries by default. If an external
> +# cross-compiler can only build dynamic libraries the user might need
> +# to make extra efforts to ensure ld.so can link at runtime when the
> +# tests are run.
> +#
> +# We also accept SPEED=slow to enable slower running tests
> +#
> +# We also expect to be in the tests build dir for the FOO-linux-user.
> +#
> +
>  -include ../../config-host.mak
> --include $(SRC_PATH)/rules.mak
> +-include ../config-target.mak
>  
> -$(call set-vpath, $(SRC_PATH)/tests/tcg)
> +quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, 
> @$1))
>  
> -QEMU=../../i386-linux-user/qemu-i386
> -QEMU_X86_64=../../x86_64-linux-user/qemu-x86_64
> -CC_X86_64=$(CC_I386) -m64
> +# Tests we are building
> +TESTS=
>  
> -QEMU_INCLUDES += -I../..
> -CFLAGS=-Wall -O2 -g -fno-strict-aliasing
> -#CFLAGS+=-msse2
> +# Start with a blank slate, the build targets get to add stuff first
> +CFLAGS=
> +QEMU_CFLAGS=
>  LDFLAGS=
>  
> -# TODO: automatically detect ARM and MIPS compilers, and run those too
> -
> -# runcom maps page 0, so it requires root privileges
> -# also, pi_10.com runs indefinitely
> -
> -I386_TESTS=hello-i386 \
> -sha1-i386 \
> -test-i386 \
> -test-i386-fprem \
> -# runcom
> +# The QEMU for this TARGET
> +QEMU=../qemu-$(TARGET_NAME)
>  
> -# native i386 compilers sometimes are not biarch.  assume cross-compilers are
> -ifneq ($(ARCH),i386)
> -I386_TESTS+=run-test-x86_64
> +# If TCG debugging is enabled things are a lot slower
> +ifeq ($(CONFIG_DEBUG_TCG),y)
> +TIMEOUT=45
> +else
> +TIMEOUT=15
>  endif
>  
> -TESTS = test_path
> -ifneq ($(call find-in-path, $(CC_I386)),)
> -TESTS += $(I386_TESTS)
> +# The order we include is important. We include multiarch, base arch
> +# and finally arch if it's not the same as base arch.
> +-include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target
> +-include $(SRC_PATH)/tests/tcg/$(TARGET_BASE_ARCH)/Makefile.target
> +ifneq ($(TARGET_BASE_ARCH),$(TARGET_NAME))
> +-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target
>  endif
>  
> -all: $(patsubst %,run-%,$(TESTS))
> -test: all
> -
> -# rules to 

[Qemu-devel] [PATCH v4 27/40] hw/lm32: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Acked-by: Michael Walle 
---
 hw/lm32/lm32_boards.c | 13 +++--
 hw/lm32/milkymist.c   | 10 +-
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
index 167058348e..fd8eccca14 100644
--- a/hw/lm32/lm32_boards.c
+++ b/hw/lm32/lm32_boards.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -87,10 +88,10 @@ static void lm32_evr_init(MachineState *machine)
 
 /* memory map */
 hwaddr flash_base  = 0x0400;
-size_t flash_sector_size   = 256 * 1024;
-size_t flash_size  = 32 * 1024 * 1024;
+size_t flash_sector_size   = 256 * KiB;
+size_t flash_size  = 32 * MiB;
 hwaddr ram_base= 0x0800;
-size_t ram_size= 64 * 1024 * 1024;
+size_t ram_size= 64 * MiB;
 hwaddr timer0_base = 0x80002000;
 hwaddr uart0_base  = 0x80006000;
 hwaddr timer1_base = 0x8000a000;
@@ -173,10 +174,10 @@ static void lm32_uclinux_init(MachineState *machine)
 
 /* memory map */
 hwaddr flash_base   = 0x0400;
-size_t flash_sector_size= 256 * 1024;
-size_t flash_size   = 32 * 1024 * 1024;
+size_t flash_sector_size= 256 * KiB;
+size_t flash_size   = 32 * MiB;
 hwaddr ram_base = 0x0800;
-size_t ram_size = 64 * 1024 * 1024;
+size_t ram_size = 64 * MiB;
 hwaddr uart0_base   = 0x8000;
 hwaddr timer0_base  = 0x80002000;
 hwaddr timer1_base  = 0x8001;
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index c36bbc4ae2..321f184595 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -33,11 +34,10 @@
 #include "milkymist-hw.h"
 #include "lm32.h"
 #include "exec/address-spaces.h"
-#include "qemu/cutils.h"
 
 #define BIOS_FILENAME"mmone-bios.bin"
 #define BIOS_OFFSET  0x0086
-#define BIOS_SIZE(512*1024)
+#define BIOS_SIZE(512 * KiB)
 #define KERNEL_LOAD_ADDR 0x4000
 
 typedef struct {
@@ -96,10 +96,10 @@ milkymist_init(MachineState *machine)
 
 /* memory map */
 hwaddr flash_base   = 0x;
-size_t flash_sector_size= 128 * 1024;
-size_t flash_size   = 32 * 1024 * 1024;
+size_t flash_sector_size= 128 * KiB;
+size_t flash_size   = 32 * MiB;
 hwaddr sdram_base   = 0x4000;
-size_t sdram_size   = 128 * 1024 * 1024;
+size_t sdram_size   = 128 * MiB;
 
 hwaddr initrd_base  = sdram_base + 0x1002000;
 hwaddr cmdline_base = sdram_base + 0x100;
-- 
2.17.1




[Qemu-devel] [PATCH v4 38/40] hw/virtio: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/virtio/virtio-net.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 02484dc94c..4d7f3c82ca 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -14,6 +14,7 @@
 #ifndef QEMU_VIRTIO_NET_H
 #define QEMU_VIRTIO_NET_H
 
+#include "qemu/units.h"
 #include "standard-headers/linux/virtio_net.h"
 #include "hw/virtio/virtio.h"
 
@@ -44,7 +45,7 @@ typedef struct virtio_net_conf
 } virtio_net_conf;
 
 /* Maximum packet size we can receive from tap device: header + 64k */
-#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
+#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 * KiB))
 
 typedef struct VirtIONetQueue {
 VirtQueue *rx_vq;
-- 
2.17.1




[Qemu-devel] [PATCH v4 25/40] hw/nios2: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/nios2/boot.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c
index 94f436e7fb..4bb5b601d3 100644
--- a/hw/nios2/boot.c
+++ b/hw/nios2/boot.c
@@ -29,6 +29,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 #include "cpu.h"
 #include "qemu/option.h"
@@ -38,7 +39,6 @@
 #include "sysemu/sysemu.h"
 #include "hw/loader.h"
 #include "elf.h"
-#include "qemu/cutils.h"
 
 #include "boot.h"
 
@@ -177,7 +177,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
 high = ddr_base + kernel_size;
 }
 
-high = ROUND_UP(high, 1024 * 1024);
+high = ROUND_UP(high, 1 * MiB);
 
 /* If initrd is available, it goes after the kernel, aligned to 1M. */
 if (initrd_filename) {
@@ -213,7 +213,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
 high += fdt_size;
 
 /* Kernel command is at the end, 4k aligned. */
-boot_info.cmdline = ROUND_UP(high, 4096);
+boot_info.cmdline = ROUND_UP(high, 4 * KiB);
 if (kernel_cmdline && strlen(kernel_cmdline)) {
 pstrcpy_targphys("cmdline", boot_info.cmdline, 256, 
kernel_cmdline);
 }
-- 
2.17.1




[Qemu-devel] [PATCH v4 36/40] hw/sd: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/sd/sd.c| 4 ++--
 hw/sd/sdhci.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 9a16b768ed..d4356e9b73 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -31,6 +31,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/qdev.h"
 #include "hw/hw.h"
 #include "hw/registerfields.h"
@@ -38,7 +39,6 @@
 #include "hw/sd/sd.h"
 #include "qapi/error.h"
 #include "qemu/bitmap.h"
-#include "qemu/cutils.h"
 #include "hw/qdev-properties.h"
 #include "qemu/error-report.h"
 #include "qemu/timer.h"
@@ -403,7 +403,7 @@ static void sd_set_csd(SDState *sd, uint64_t size)
 ((HWBLOCK_SHIFT << 6) & 0xc0);
 sd->csd[14] = 0x00;/* File format group */
 } else {   /* SDHC */
-size /= 512 * 1024;
+size /= 512 * KiB;
 size -= 1;
 sd->csd[0] = 0x40;
 sd->csd[1] = 0x0e;
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index a11e802485..39c2b3a6e8 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "hw/hw.h"
@@ -32,7 +33,6 @@
 #include "hw/sd/sdhci.h"
 #include "sdhci-internal.h"
 #include "qemu/log.h"
-#include "qemu/cutils.h"
 #include "trace.h"
 
 #define TYPE_SDHCI_BUS "sdhci-bus"
@@ -790,7 +790,7 @@ static void sdhci_do_adma(SDHCIState *s)
 return;
 }
 
-length = dscr.length ? dscr.length : 65536;
+length = dscr.length ? dscr.length : 64 * KiB;
 
 switch (dscr.attr & SDHC_ADMA_ATTR_ACT_MASK) {
 case SDHC_ADMA_ATTR_ACT_TRAN:  /* data transfer */
-- 
2.17.1




[Qemu-devel] [PATCH v4 22/40] hw/alpha: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/alpha/typhoon.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 6a40869488..f42b706a08 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -7,6 +7,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "hw/hw.h"
@@ -812,8 +813,6 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
  qemu_irq *p_rtc_irq,
  AlphaCPU *cpus[4], pci_map_irq_fn sys_map_irq)
 {
-const uint64_t MB = 1024 * 1024;
-const uint64_t GB = 1024 * MB;
 MemoryRegion *addr_space = get_system_memory();
 DeviceState *dev;
 TyphoonState *s;
@@ -854,30 +853,30 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus 
**isa_bus,
 
 /* Pchip0 CSRs, 0x801.8000., 256MB.  */
 memory_region_init_io(>pchip.region, OBJECT(s), _ops, s, "pchip0",
-  256*MB);
+  256 * MiB);
 memory_region_add_subregion(addr_space, 0x8018000ULL,
 >pchip.region);
 
 /* Cchip CSRs, 0x801.A000., 256MB.  */
 memory_region_init_io(>cchip.region, OBJECT(s), _ops, s, "cchip0",
-  256*MB);
+  256 * MiB);
 memory_region_add_subregion(addr_space, 0x801a000ULL,
 >cchip.region);
 
 /* Dchip CSRs, 0x801.B000., 256MB.  */
 memory_region_init_io(>dchip_region, OBJECT(s), _ops, s, "dchip0",
-  256*MB);
+  256 * MiB);
 memory_region_add_subregion(addr_space, 0x801b000ULL,
 >dchip_region);
 
 /* Pchip0 PCI memory, 0x800.., 4GB.  */
-memory_region_init(>pchip.reg_mem, OBJECT(s), "pci0-mem", 4*GB);
+memory_region_init(>pchip.reg_mem, OBJECT(s), "pci0-mem", 4 * GiB);
 memory_region_add_subregion(addr_space, 0x800ULL,
 >pchip.reg_mem);
 
 /* Pchip0 PCI I/O, 0x801.FC00., 32MB.  */
 memory_region_init_io(>pchip.reg_io, OBJECT(s), _pci_ignore_ops,
-  NULL, "pci0-io", 32*MB);
+  NULL, "pci0-io", 32 * MiB);
 memory_region_add_subregion(addr_space, 0x801fc00ULL,
 >pchip.reg_io);
 
@@ -898,13 +897,13 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus 
**isa_bus,
 
 /* Pchip0 PCI special/interrupt acknowledge, 0x801.F800., 64MB.  */
 memory_region_init_io(>pchip.reg_iack, OBJECT(s), _pci_iack_ops,
-  b, "pci0-iack", 64*MB);
+  b, "pci0-iack", 64 * MiB);
 memory_region_add_subregion(addr_space, 0x801f800ULL,
 >pchip.reg_iack);
 
 /* Pchip0 PCI configuration, 0x801.FE00., 16MB.  */
 memory_region_init_io(>pchip.reg_conf, OBJECT(s), _pci_conf1_ops,
-  b, "pci0-conf", 16*MB);
+  b, "pci0-conf", 16 * MiB);
 memory_region_add_subregion(addr_space, 0x801fe00ULL,
 >pchip.reg_conf);
 
-- 
2.17.1




[Qemu-devel] [PATCH v4 30/40] hw/mips: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Alistair Francis 
---
 include/hw/intc/mips_gic.h |  3 ++-
 include/hw/mips/bios.h |  3 ++-
 hw/mips/mips_fulong2e.c|  7 ---
 hw/mips/mips_malta.c   | 23 +--
 hw/mips/mips_r4k.c | 11 ++-
 hw/misc/mips_itu.c |  3 ++-
 hw/pci-host/xilinx-pcie.c  |  5 +++--
 7 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/include/hw/intc/mips_gic.h b/include/hw/intc/mips_gic.h
index b98d50094a..902a12b178 100644
--- a/include/hw/intc/mips_gic.h
+++ b/include/hw/intc/mips_gic.h
@@ -11,6 +11,7 @@
 #ifndef MIPS_GIC_H
 #define MIPS_GIC_H
 
+#include "qemu/units.h"
 #include "hw/timer/mips_gictimer.h"
 #include "cpu.h"
 /*
@@ -19,7 +20,7 @@
 
 /* The MIPS default location */
 #define GIC_BASE_ADDR   0x1bdcULL
-#define GIC_ADDRSPACE_SZ(128 * 1024)
+#define GIC_ADDRSPACE_SZ(128 * KiB)
 
 /* Constants */
 #define GIC_POL_POS 1
diff --git a/include/hw/mips/bios.h b/include/hw/mips/bios.h
index b4b88ac43d..d67ef33e83 100644
--- a/include/hw/mips/bios.h
+++ b/include/hw/mips/bios.h
@@ -1,6 +1,7 @@
+#include "qemu/units.h"
 #include "cpu.h"
 
-#define BIOS_SIZE (4 * 1024 * 1024)
+#define BIOS_SIZE (4 * MiB)
 #ifdef TARGET_WORDS_BIGENDIAN
 #define BIOS_FILENAME "mips_bios.bin"
 #else
diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c
index 02fb2fdcc4..d22f50e97b 100644
--- a/hw/mips/mips_fulong2e.c
+++ b/hw/mips/mips_fulong2e.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
@@ -159,7 +160,7 @@ static int64_t load_kernel (CPUMIPSState *env)
 /* Setup minimum environment variables */
 prom_set(prom_buf, index++, "busclock=3300");
 prom_set(prom_buf, index++, "cpuclock=1");
-prom_set(prom_buf, index++, "memsize=%i", loaderparams.ram_size/1024/1024);
+prom_set(prom_buf, index++, "memsize=%llu", loaderparams.ram_size / MiB);
 prom_set(prom_buf, index++, "modetty0=38400n8r");
 prom_set(prom_buf, index++, NULL);
 
@@ -303,10 +304,10 @@ static void mips_fulong2e_init(MachineState *machine)
 qemu_register_reset(main_cpu_reset, cpu);
 
 /* fulong 2e has 256M ram. */
-ram_size = 256 * 1024 * 1024;
+ram_size = 256 * MiB;
 
 /* fulong 2e has a 1M flash.Winbond W39L040AP70Z */
-bios_size = 1024 * 1024;
+bios_size = 1 * MiB;
 
 /* allocate RAM */
 memory_region_allocate_system_memory(ram, NULL, "fulong2e.ram", ram_size);
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 494f84e290..c8ae477d75 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 #include "cpu.h"
 #include "hw/hw.h"
@@ -843,7 +844,8 @@ static int64_t load_kernel (void)
 /* The kernel allocates the bootmap memory in the low memory after
the initrd.  It takes at most 128kiB for 2GB RAM and 4kiB
pages.  */
-initrd_offset = (loaderparams.ram_low_size - initrd_size - 131072
+initrd_offset = (loaderparams.ram_low_size - initrd_size
+ - (128 * KiB)
  - ~INITRD_PAGE_MASK) & INITRD_PAGE_MASK;
 if (kernel_high >= initrd_offset) {
 error_report("memory too small for initial ram disk '%s'",
@@ -1021,9 +1023,9 @@ void mips_malta_init(MachineState *machine)
 mips_create_cpu(s, machine->cpu_type, _irq, _irq);
 
 /* allocate RAM */
-if (ram_size > (2048u << 20)) {
-error_report("Too much memory for this machine: %dMB, maximum 2048MB",
- ((unsigned int)ram_size / (1 << 20)));
+if (ram_size > 2 * GiB) {
+error_report("Too much memory for this machine: %lluMB, maximum 
2048MB",
+ ram_size / MiB);
 exit(1);
 }
 
@@ -1034,17 +1036,18 @@ void mips_malta_init(MachineState *machine)
 
 /* alias for pre IO hole access */
 memory_region_init_alias(ram_low_preio, NULL, "mips_malta_low_preio.ram",
- ram_high, 0, MIN(ram_size, (256 << 20)));
+ ram_high, 0, MIN(ram_size, 256 * MiB));
 memory_region_add_subregion(system_memory, 0, ram_low_preio);
 
 /* alias for post IO hole access, if there is enough RAM */
-if (ram_size > (512 << 20)) {
+if (ram_size > 512 * MiB) {
 ram_low_postio = g_new(MemoryRegion, 1);
 memory_region_init_alias(ram_low_postio, NULL,
  "mips_malta_low_postio.ram",
- ram_high, 512 << 20,
- ram_size - (512 << 20));
-

[Qemu-devel] [PATCH v4 21/40] hw/xtensa: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Acked-by: Max Filippov 
---
 hw/xtensa/xtfpga.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index 5dc13034f9..918cdadbb4 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -26,6 +26,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "sysemu/sysemu.h"
@@ -152,7 +153,7 @@ static void xtfpga_net_init(MemoryRegion *address_space,
 sysbus_mmio_get_region(s, 1));
 
 ram = g_malloc(sizeof(*ram));
-memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16384,
+memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16 * KiB,
_fatal);
 vmstate_register_ram_global(ram);
 memory_region_add_subregion(address_space, buffers, ram);
@@ -229,7 +230,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, 
MachineState *machine)
 const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
 const char *dtb_filename = qemu_opt_get(machine_opts, "dtb");
 const char *initrd_filename = qemu_opt_get(machine_opts, "initrd");
-const unsigned system_io_size = 224 * 1024 * 1024;
+const unsigned system_io_size = 224 * MiB;
 int n;
 
 for (n = 0; n < smp_cpus; n++) {
-- 
2.17.1




[Qemu-devel] [PATCH v4 28/40] hw/sh4: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/sh4/r2d.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index 8fe8766eb9..6a5fc46a47 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -24,6 +24,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -291,7 +292,7 @@ static void r2d_init(MachineState *machine)
 dinfo = drive_get(IF_PFLASH, 0, 0);
 pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-  (16 * 1024), FLASH_SIZE >> 16,
+  16 * KiB, FLASH_SIZE >> 16,
   1, 4, 0x, 0x, 0x, 0x,
   0x555, 0x2aa, 0);
 
-- 
2.17.1




Re: [Qemu-devel] [PATCH v6 39/49] docker: move debian-powerpc-cross to sid based build

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/08/2018 09:32 AM, Alex Bennée wrote:
> The original Jessie based cross builder hasn't worked for a while. The
> state of the libraries is still perilous for cross-building QEMU but
> we can use it for building TCG tests.
> 
> The debian-apt-fake.sh script can also be dropped as it is no longer
> used.
> 
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/docker/Makefile.include |  4 +-
>  tests/docker/dockerfiles/debian-apt-fake.sh   | 46 ---
>  .../dockerfiles/debian-powerpc-cross.docker   | 39 +++-
>  tests/docker/dockerfiles/debian8.docker   |  3 --
>  4 files changed, 7 insertions(+), 85 deletions(-)
>  delete mode 100755 tests/docker/dockerfiles/debian-apt-fake.sh
> 
> diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
> index 10f98916f9..78568d7c61 100644
> --- a/tests/docker/Makefile.include
> +++ b/tests/docker/Makefile.include
> @@ -47,8 +47,6 @@ docker-image-%: $(DOCKER_FILES_DIR)/%.docker
>   $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
>   "BUILD","$*")
>  
> -docker-image-debian-powerpc-cross: 
> EXTRA_FILES:=$(SRC_PATH)/tests/docker/dockerfiles/debian-apt-fake.sh
> -
>  # Enforce dependencies for composite images
>  docker-image-debian: docker-image-debian9
>  docker-image-debian8-mxe: docker-image-debian8
> @@ -58,7 +56,6 @@ docker-image-debian-armhf-cross: docker-image-debian9
>  docker-image-debian-arm64-cross: docker-image-debian9
>  docker-image-debian-mips-cross: docker-image-debian9
>  docker-image-debian-mips64el-cross: docker-image-debian9
> -docker-image-debian-powerpc-cross: docker-image-debian8
>  docker-image-debian-ppc64el-cross: docker-image-debian9
>  docker-image-debian-s390x-cross: docker-image-debian9
>  docker-image-debian-win32-cross: docker-image-debian8-mxe
> @@ -76,6 +73,7 @@ docker-image-debian-sh4-cross: docker-image-debian-sid
>  docker-image-debian-sparc64-cross: docker-image-debian-sid
>  docker-image-debian-mips64-cross: docker-image-debian-sid
>  docker-image-debian-riscv64-cross: docker-image-debian-sid
> +docker-image-debian-powerpc-cross: docker-image-debian-sid
>  docker-image-travis: NOUSER=1
>  
>  # Specialist build images, sometimes very limited tools
> diff --git a/tests/docker/dockerfiles/debian-apt-fake.sh 
> b/tests/docker/dockerfiles/debian-apt-fake.sh
> deleted file mode 100755
> index 2ec0fdf47a..00
> --- a/tests/docker/dockerfiles/debian-apt-fake.sh
> +++ /dev/null
> @@ -1,46 +0,0 @@
> -#! /bin/sh
> -#
> -# Generate fake debian package to resolve unimportant unmet dependencies held
> -# by upstream multiarch broken packages.
> -#
> -# Copyright (c) 2017 Philippe Mathieu-Daudé 
> -#
> -# This work is licensed under the terms of the GNU GPL, version 2
> -# or (at your option) any later version. See the COPYING file in
> -# the top-level directory.
> -
> -test $1 = "install" && shift 1
> -
> -fake_install()
> -{
> -echo "Generating fake $2 $1 $3 ..."
> -(cd /var/cache/apt/archives
> -(cat << 'EOF'
> -Section: misc
> -Priority: optional
> -Standards-Version: 3.9.2
> -
> -Package: NAME
> -Version: VERSION
> -Maintainer: qemu-devel@nongnu.org
> -Architecture: any
> -Multi-Arch: same
> -Description: fake NAME
> -EOF
> -) | sed s/NAME/$2/g | sed s/VERSION/$3/g > $2.control
> -equivs-build -a $1 $2.control 1>/dev/null 2>/dev/null
> -dpkg -i --force-overwrite $2_$3_$1.deb
> -)
> -}
> -
> -try_install()
> -{
> -name=$(echo $1|sed "s/\(.*\):\(.*\)=\(.*\)/\1/")
> -arch=$(echo $1|sed "s/\(.*\):\(.*\)=\(.*\)/\2/")
> -vers=$(echo $1|sed "s/\(.*\):\(.*\)=\(.*\)/\3/")
> -apt-get install -q -yy $1 || fake_install $arch $name $vers
> -}
> -
> -for package in $*; do
> -try_install $package
> -done
> diff --git a/tests/docker/dockerfiles/debian-powerpc-cross.docker 
> b/tests/docker/dockerfiles/debian-powerpc-cross.docker
> index a5dd46b4ac..5e62ca0df1 100644
> --- a/tests/docker/dockerfiles/debian-powerpc-cross.docker
> +++ b/tests/docker/dockerfiles/debian-powerpc-cross.docker
> @@ -1,40 +1,13 @@
>  #
>  # Docker powerpc cross-compiler target
>  #
> -# This docker target builds on the debian Jessie base image.
> +# This docker target builds on the debian sid base image which
> +# contains cross compilers for Debian "ports" targets. The original
> +# Jessie based no longer builds.
>  #
> -FROM qemu:debian8
> -MAINTAINER Philippe Mathieu-Daudé 
> +FROM qemu:debian-sid
>  
> -# Add the foreign architecture we want and install dependencies
> -RUN dpkg --add-architecture powerpc
> -RUN apt-get update
>  RUN DEBIAN_FRONTEND=noninteractive eatmydata \
>  apt-get install -y --no-install-recommends \
> -crossbuild-essential-powerpc
> -
> -#  to fix "following packages have unmet dependencies" ...
> -ADD debian-apt-fake.sh /usr/local/bin/apt-fake
> -RUN apt-get install -y --no-install-recommends \
> -

[Qemu-devel] [PATCH v4 39/40] hw/rdma: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Marcel Apfelbaum 
Reviewed-by: Yuval Shaia 
---
 hw/rdma/vmw/pvrdma.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/rdma/vmw/pvrdma.h b/hw/rdma/vmw/pvrdma.h
index 0b46dc5a9b..81e0e0e99c 100644
--- a/hw/rdma/vmw/pvrdma.h
+++ b/hw/rdma/vmw/pvrdma.h
@@ -16,6 +16,7 @@
 #ifndef PVRDMA_PVRDMA_H
 #define PVRDMA_PVRDMA_H
 
+#include "qemu/units.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/msix.h"
 
@@ -30,7 +31,7 @@
 #define RDMA_MSIX_BAR_IDX0
 #define RDMA_REG_BAR_IDX 1
 #define RDMA_UAR_BAR_IDX 2
-#define RDMA_BAR0_MSIX_SIZE  (16 * 1024)
+#define RDMA_BAR0_MSIX_SIZE  (16 * KiB)
 #define RDMA_BAR1_REGS_SIZE  64
 #define RDMA_BAR2_UAR_SIZE   (0x1000 * MAX_UCS) /* each uc gets page */
 
-- 
2.17.1




[Qemu-devel] [PATCH v4 19/40] hw/s390x: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Acked-by: Cornelia Huck 
---
 hw/s390x/s390-skeys.c| 3 ++-
 hw/s390x/s390-stattrib.c | 3 ++-
 hw/s390x/sclp.c  | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
index 76241c240e..15f7ab0e53 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -10,6 +10,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/boards.h"
 #include "hw/s390x/storage-keys.h"
 #include "qapi/error.h"
@@ -19,7 +20,7 @@
 #include "sysemu/kvm.h"
 #include "migration/register.h"
 
-#define S390_SKEYS_BUFFER_SIZE 131072  /* Room for 128k storage keys */
+#define S390_SKEYS_BUFFER_SIZE (128 * KiB)  /* Room for 128k storage keys */
 #define S390_SKEYS_SAVE_FLAG_EOS 0x01
 #define S390_SKEYS_SAVE_FLAG_SKEYS 0x02
 #define S390_SKEYS_SAVE_FLAG_ERROR 0x04
diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index 70b95550a8..5161a1659b 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -10,6 +10,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/boards.h"
 #include "cpu.h"
 #include "migration/qemu-file.h"
@@ -20,7 +21,7 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 
-#define CMMA_BLOCK_SIZE  (1 << 10)
+#define CMMA_BLOCK_SIZE  (1 * KiB)
 
 #define STATTR_FLAG_EOS 0x01ULL
 #define STATTR_FLAG_MORE0x02ULL
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 047d577313..04b51fbd15 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -13,6 +13,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "sysemu/sysemu.h"
@@ -288,8 +289,7 @@ static void sclp_realize(DeviceState *dev, Error **errp)
 
 ret = s390_set_memory_limit(machine->maxram_size, _limit);
 if (ret == -E2BIG) {
-error_setg(, "host supports a maximum of %" PRIu64 " GB",
-   hw_limit >> 30);
+error_setg(, "host supports a maximum of %llu GB", hw_limit / GiB);
 } else if (ret) {
 error_setg(, "setting the guest size failed");
 }
-- 
2.17.1




[Qemu-devel] [PATCH v4 26/40] hw/cris: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/cris/axis_dev88.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c
index 56ee398ee5..191292eebf 100644
--- a/hw/cris/axis_dev88.c
+++ b/hw/cris/axis_dev88.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -242,7 +243,7 @@ static const MemoryRegionOps gpio_ops = {
 },
 };
 
-#define INTMEM_SIZE (128 * 1024)
+#define INTMEM_SIZE (128 * KiB)
 
 static struct cris_load_info li;
 
-- 
2.17.1




[Qemu-devel] [PATCH v4 37/40] hw/vfio: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/vfio/pci-quirks.c | 9 +
 hw/vfio/pci.c| 3 ++-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index 061259b86b..481fd08df7 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "qemu/range.h"
@@ -1448,9 +1449,9 @@ static int vfio_igd_gtt_max(VFIOPCIDevice *vdev)
 ggms = 1 << ggms;
 }
 
-ggms *= 1024 * 1024;
+ggms *= MiB;
 
-return (ggms / (4 * 1024)) * (gen < 8 ? 4 : 8);
+return (ggms / (4 * KiB)) * (gen < 8 ? 4 : 8);
 }
 
 /*
@@ -1705,7 +1706,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
 igd->vdev = vdev;
 igd->index = ~0;
 igd->bdsm = vfio_pci_read_config(>pdev, IGD_BDSM, 4);
-igd->bdsm &= ~((1 << 20) - 1); /* 1MB aligned */
+igd->bdsm &= ~((1 * MiB) - 1); /* 1MB aligned */
 
 memory_region_init_io(>mem[0], OBJECT(vdev), _igd_index_quirk,
   igd, "vfio-igd-index-quirk", 4);
@@ -1752,7 +1753,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
  * config offset 0x5C.
  */
 bdsm_size = g_malloc(sizeof(*bdsm_size));
-*bdsm_size = cpu_to_le64((ggms_mb + gms_mb) * 1024 * 1024);
+*bdsm_size = cpu_to_le64((ggms_mb + gms_mb) * MiB);
 fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size",
 bdsm_size, sizeof(*bdsm_size));
 
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 18c493b49e..a1577dea7f 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -28,6 +28,7 @@
 #include "qemu/error-report.h"
 #include "qemu/option.h"
 #include "qemu/range.h"
+#include "qemu/units.h"
 #include "sysemu/kvm.h"
 #include "sysemu/sysemu.h"
 #include "pci.h"
@@ -1417,7 +1418,7 @@ static void vfio_pci_relocate_msix(VFIOPCIDevice *vdev, 
Error **errp)
 }
 
 /* 2GB max size for 32-bit BARs, cannot double if already > 1G */
-if (vdev->bars[target_bar].size > (1 * 1024 * 1024 * 1024) &&
+if (vdev->bars[target_bar].size > 1 * GiB &&
 !vdev->bars[target_bar].mem64) {
 error_setg(errp, "Invalid MSI-X relocation BAR %d, "
"no space to extend 32-bit BAR", target_bar);
-- 
2.17.1




[Qemu-devel] [PATCH v4 17/40] hw/m68k: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
---
 hw/m68k/mcf5208.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
index ae3dcc98c3..0f2245dd81 100644
--- a/hw/m68k/mcf5208.c
+++ b/hw/m68k/mcf5208.c
@@ -6,6 +6,7 @@
  * This code is licensed under the GPL
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
@@ -241,7 +242,7 @@ static void mcf5208evb_init(MachineState *machine)
 memory_region_add_subregion(address_space_mem, 0x4000, ram);
 
 /* Internal SRAM.  */
-memory_region_init_ram(sram, NULL, "mcf5208.sram", 16384, _fatal);
+memory_region_init_ram(sram, NULL, "mcf5208.sram", 16 * KiB, _fatal);
 memory_region_add_subregion(address_space_mem, 0x8000, sram);
 
 /* Internal peripherals.  */
-- 
2.17.1




[Qemu-devel] [PATCH v4 34/40] hw/net: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Stefan Weil 
---
 hw/net/ne2000.h | 5 +++--
 include/hw/net/allwinner_emac.h | 5 +++--
 hw/net/e1000e.c | 7 ---
 hw/net/e1000x_common.c  | 3 ++-
 hw/net/eepro100.c   | 3 +--
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/hw/net/ne2000.h b/hw/net/ne2000.h
index adb8021bd1..2cd193e4c6 100644
--- a/hw/net/ne2000.h
+++ b/hw/net/ne2000.h
@@ -1,11 +1,12 @@
 #ifndef HW_NE2000_H
 #define HW_NE2000_H
 
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "net/net.h"
 
-#define NE2000_PMEM_SIZE(32*1024)
-#define NE2000_PMEM_START   (16*1024)
+#define NE2000_PMEM_SIZE(32 * KiB)
+#define NE2000_PMEM_START   (16 * KiB)
 #define NE2000_PMEM_END (NE2000_PMEM_SIZE+NE2000_PMEM_START)
 #define NE2000_MEM_SIZE NE2000_PMEM_END
 
diff --git a/include/hw/net/allwinner_emac.h b/include/hw/net/allwinner_emac.h
index 4cc8aab7ec..905a43deb4 100644
--- a/include/hw/net/allwinner_emac.h
+++ b/include/hw/net/allwinner_emac.h
@@ -23,6 +23,7 @@
 #ifndef ALLWINNER_EMAC_H
 #define ALLWINNER_EMAC_H
 
+#include "qemu/units.h"
 #include "net/net.h"
 #include "qemu/fifo8.h"
 #include "hw/net/mii.h"
@@ -125,8 +126,8 @@
 #define EMAC_INT_RX (1 << 8)
 
 /* Due to lack of specifications, size of fifos is chosen arbitrarily */
-#define TX_FIFO_SIZE(4 * 1024)
-#define RX_FIFO_SIZE(32 * 1024)
+#define TX_FIFO_SIZE(4 * KiB)
+#define RX_FIFO_SIZE(32 * KiB)
 
 #define NUM_TX_FIFOS2
 #define RX_HDR_SIZE 8
diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c
index cda8d48333..510ddb3897 100644
--- a/hw/net/e1000e.c
+++ b/hw/net/e1000e.c
@@ -34,6 +34,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "net/net.h"
 #include "net/tap.h"
 #include "qemu/range.h"
@@ -81,10 +82,10 @@ typedef struct E1000EState {
 #define E1000E_IO_IDX   2
 #define E1000E_MSIX_IDX 3
 
-#define E1000E_MMIO_SIZE(128 * 1024)
-#define E1000E_FLASH_SIZE   (128 * 1024)
+#define E1000E_MMIO_SIZE(128 * KiB)
+#define E1000E_FLASH_SIZE   (128 * KiB)
 #define E1000E_IO_SIZE  (32)
-#define E1000E_MSIX_SIZE(16 * 1024)
+#define E1000E_MSIX_SIZE(16 * KiB)
 
 #define E1000E_MSIX_TABLE   (0x)
 #define E1000E_MSIX_PBA (0x2000)
diff --git a/hw/net/e1000x_common.c b/hw/net/e1000x_common.c
index eb0e097137..09047806f2 100644
--- a/hw/net/e1000x_common.c
+++ b/hw/net/e1000x_common.c
@@ -23,6 +23,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
@@ -111,7 +112,7 @@ bool e1000x_is_oversized(uint32_t *mac, size_t size)
 static const int maximum_ethernet_vlan_size = 1522;
 /* this is the size past which hardware will
drop packets when setting LPE=1 */
-static const int maximum_ethernet_lpe_size = 16384;
+static const int maximum_ethernet_lpe_size = 16 * KiB;
 
 if ((size > maximum_ethernet_lpe_size ||
 (size > maximum_ethernet_vlan_size
diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index a07a63247e..e761daf551 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -41,6 +41,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
@@ -60,8 +61,6 @@
  * changed to pad short packets itself. */
 #define CONFIG_PAD_RECEIVED_FRAMES
 
-#define KiB 1024
-
 /* Debug EEPRO100 card. */
 #if 0
 # define DEBUG_EEPRO100
-- 
2.17.1




[Qemu-devel] [PATCH v4 23/40] hw/tricore: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Acked-by: Bastian Koppelmann 
---
 hw/tricore/tricore_testboard.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c
index 8e61dfc3e6..a58096f05e 100644
--- a/hw/tricore/tricore_testboard.c
+++ b/hw/tricore/tricore_testboard.c
@@ -19,6 +19,7 @@
 
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -72,17 +73,17 @@ static void tricore_testboard_init(MachineState *machine, 
int board_id)
 cpu = TRICORE_CPU(cpu_create(machine->cpu_type));
 env = >env;
 memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram",
-   2 * 1024 * 1024, _fatal);
+   2 * MiB, _fatal);
 memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram",
-   4 * 1024 * 1024, _fatal);
-memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48 * 1024,
+   4 * MiB, _fatal);
+memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48 * KiB,
_fatal);
-memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48 * 1024,
+memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48 * KiB,
_fatal);
 memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram",
-   16 * 1024, _fatal);
+   16 * KiB, _fatal);
 memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram",
-   32 * 1024, _fatal);
+   32 * KiB, _fatal);
 
 memory_region_add_subregion(sysmem, 0x8000, ext_cram);
 memory_region_add_subregion(sysmem, 0xa100, ext_dram);
-- 
2.17.1




[Qemu-devel] [PATCH v4 24/40] hw/microblaze: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/microblaze/petalogix_ml605_mmu.c  | 7 ---
 hw/microblaze/petalogix_s3adsp1800_mmu.c | 7 ---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/microblaze/petalogix_ml605_mmu.c 
b/hw/microblaze/petalogix_ml605_mmu.c
index 6c4a544eac..c730878d25 100644
--- a/hw/microblaze/petalogix_ml605_mmu.c
+++ b/hw/microblaze/petalogix_ml605_mmu.c
@@ -26,6 +26,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -44,8 +45,8 @@
 
 #include "hw/stream.h"
 
-#define LMB_BRAM_SIZE  (128 * 1024)
-#define FLASH_SIZE (32 * 1024 * 1024)
+#define LMB_BRAM_SIZE  (128 * KiB)
+#define FLASH_SIZE (32 * MiB)
 
 #define BINARY_DEVICE_TREE_FILE "petalogix-ml605.dtb"
 
@@ -109,7 +110,7 @@ petalogix_ml605_init(MachineState *machine)
 pflash_cfi01_register(FLASH_BASEADDR,
   NULL, "petalogix_ml605.flash", FLASH_SIZE,
   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-  (64 * 1024), FLASH_SIZE >> 16,
+  64 * KiB, FLASH_SIZE >> 16,
   2, 0x89, 0x18, 0x, 0x0, 0);
 
 
diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c 
b/hw/microblaze/petalogix_s3adsp1800_mmu.c
index 0da3e62102..5cf7b84c79 100644
--- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
+++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
@@ -24,6 +24,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -39,8 +40,8 @@
 
 #include "boot.h"
 
-#define LMB_BRAM_SIZE  (128 * 1024)
-#define FLASH_SIZE (16 * 1024 * 1024)
+#define LMB_BRAM_SIZE  (128 * KiB)
+#define FLASH_SIZE (16 * MiB)
 
 #define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb"
 
@@ -87,7 +88,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
 pflash_cfi01_register(FLASH_BASEADDR,
   NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE,
   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-  (64 * 1024), FLASH_SIZE >> 16,
+  64 * KiB, FLASH_SIZE >> 16,
   1, 0x89, 0x18, 0x, 0x0, 1);
 
 dev = qdev_create(NULL, "xlnx.xps-intc");
-- 
2.17.1




[Qemu-devel] [PATCH v4 35/40] hw/usb: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/usb/ccid-card-passthru.c   | 5 +++--
 hw/usb/combined-packet.c  | 3 ++-
 hw/usb/dev-smartcard-reader.c | 3 ++-
 hw/usb/redirect.c | 3 ++-
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
index 25fb19b0d7..e6c73116cc 100644
--- a/hw/usb/ccid-card-passthru.c
+++ b/hw/usb/ccid-card-passthru.c
@@ -9,6 +9,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include 
 #include "chardev/char-fe.h"
 #include "qemu/error-report.h"
@@ -40,7 +41,7 @@ static const uint8_t DEFAULT_ATR[] = {
  0x13, 0x08
 };
 
-#define VSCARD_IN_SIZE 65536
+#define VSCARD_IN_SIZE  (64 * KiB)
 
 /* maximum size of ATR - from 7816-3 */
 #define MAX_ATR_SIZE40
@@ -276,7 +277,7 @@ static void ccid_card_vscard_read(void *opaque, const 
uint8_t *buf, int size)
 
 if (card->vscard_in_pos + size > VSCARD_IN_SIZE) {
 error_report(
-"no room for data: pos %d +  size %d > %d. dropping connection.",
+"no room for data: pos %d +  size %d > %llu. dropping connection.",
 card->vscard_in_pos, size, VSCARD_IN_SIZE);
 ccid_card_vscard_drop_connection(card);
 return;
diff --git a/hw/usb/combined-packet.c b/hw/usb/combined-packet.c
index 48cac87f6a..01a7ed0848 100644
--- a/hw/usb/combined-packet.c
+++ b/hw/usb/combined-packet.c
@@ -20,6 +20,7 @@
  * along with this program; if not, see .
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 #include "hw/usb.h"
 #include "qemu/iov.h"
@@ -171,7 +172,7 @@ void usb_ep_combine_input_packets(USBEndpoint *ep)
 if ((p->iov.size % ep->max_packet_size) != 0 || !p->short_not_ok ||
 next == NULL ||
 /* Work around for Linux usbfs bulk splitting + migration */
-(totalsize == 16348 && p->int_req)) {
+(totalsize == (16 * KiB - 36) && p->int_req)) {
 usb_device_handle_data(ep->dev, first);
 assert(first->status == USB_RET_ASYNC);
 if (first->combined) {
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 2131e33d27..ec862c2082 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -35,6 +35,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "qemu/error-report.h"
@@ -63,7 +64,7 @@ do { \
  * or handle the migration complexity - VMState doesn't handle this case.
  * sizes are expected never to be exceeded, unless guest misbehaves.
  */
-#define BULK_OUT_DATA_SIZE 65536
+#define BULK_OUT_DATA_SIZE  (64 * KiB)
 #define PENDING_ANSWERS_NUM 128
 
 #define BULK_IN_BUF_SIZE 384
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 65a9196c1a..8580c08dbd 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -26,6 +26,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "qemu/timer.h"
@@ -1298,7 +1299,7 @@ static int usbredir_chardev_can_read(void *opaque)
 }
 
 /* usbredir_parser_do_read will consume *all* data we give it */
-return 1024 * 1024;
+return 1 * MiB;
 }
 
 static void usbredir_chardev_read(void *opaque, const uint8_t *buf, int size)
-- 
2.17.1




[Qemu-devel] [PATCH v4 16/40] hw/riscv: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/riscv/virt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index ad03113e0f..34d48993a2 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/log.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
@@ -84,7 +85,7 @@ static hwaddr load_initrd(const char *filename, uint64_t 
mem_size,
  * halfway into RAM, and for boards with 256MB of RAM or more we put
  * the initrd at 128MB.
  */
-*start = kernel_entry + MIN(mem_size / 2, 128 * 1024 * 1024);
+*start = kernel_entry + MIN(mem_size / 2, 128 * MiB);
 
 size = load_ramdisk(filename, *start, mem_size - *start);
 if (size == -1) {
-- 
2.17.1




[Qemu-devel] [PATCH v4 20/40] hw/hppa: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/hppa/dino.c|  3 ++-
 hw/hppa/machine.c | 10 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/hw/hppa/dino.c b/hw/hppa/dino.c
index 26f2704cd5..564b938e3a 100644
--- a/hw/hppa/dino.c
+++ b/hw/hppa/dino.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "hw/hw.h"
@@ -76,7 +77,7 @@
 /* #define xxx0x200 - bit 9 not used */
 #define RS232INT  0x400
 
-#define DINO_MEM_CHUNK_SIZE (8 * 1024 * 1024) /* 8MB */
+#define DINO_MEM_CHUNK_SIZE (8 * MiB)
 
 #define DINO_PCI_HOST_BRIDGE(obj) \
 OBJECT_CHECK(DinoState, (obj), TYPE_DINO_PCI_HOST_BRIDGE)
diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
index 2ba26962f9..77513223b0 100644
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -17,7 +17,7 @@
 #include "hw/timer/i8254.h"
 #include "hw/char/serial.h"
 #include "hppa_sys.h"
-#include "qemu/cutils.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/log.h"
 
@@ -178,8 +178,8 @@ static void machine_hppa_init(MachineState *machine)
 }
 qemu_log_mask(CPU_LOG_PAGE, "Kernel loaded at 0x%08" PRIx64
   "-0x%08" PRIx64 ", entry at 0x%08" PRIx64
-  ", size %ld kB.\n",
-  kernel_low, kernel_high, kernel_entry, size / 1024);
+  ", size %llu kB\n",
+  kernel_low, kernel_high, kernel_entry, size / KiB);
 
 if (kernel_cmdline) {
 cpu[0]->env.gr[24] = 0x4000;
@@ -203,8 +203,8 @@ static void machine_hppa_init(MachineState *machine)
(1) Due to sign-extension problems and PDC,
put the initrd no higher than 1G.
(2) Reserve 64k for stack.  */
-initrd_base = MIN(ram_size, 1024 * 1024 * 1024);
-initrd_base = initrd_base - 64 * 1024;
+initrd_base = MIN(ram_size, 1 * GiB);
+initrd_base = initrd_base - 64 * KiB;
 initrd_base = (initrd_base - initrd_size) & TARGET_PAGE_MASK;
 
 if (initrd_base < kernel_high) {
-- 
2.17.1




[Qemu-devel] [PATCH v4 29/40] hw/mips/r4k: Constify params_size

2018-06-10 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/mips/mips_r4k.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index e5cf8ed1a3..fc38b4bf99 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -79,8 +79,9 @@ typedef struct ResetData {
 
 static int64_t load_kernel(void)
 {
+const size_t params_size = 264;
 int64_t entry, kernel_high;
-long kernel_size, initrd_size, params_size;
+long kernel_size, initrd_size;
 ram_addr_t initrd_offset;
 uint32_t *params_buf;
 int big_endian;
@@ -128,7 +129,6 @@ static int64_t load_kernel(void)
 }
 
 /* Store command line.  */
-params_size = 264;
 params_buf = g_malloc(params_size);
 
 params_buf[0] = tswap32(ram_size);
@@ -143,7 +143,7 @@ static int64_t load_kernel(void)
 }
 
 rom_add_blob_fixed("params", params_buf, params_size,
-   (16 << 20) - 264);
+   (16 << 20) - params_size);
 
 g_free(params_buf);
 return entry;
-- 
2.17.1




[Qemu-devel] [PATCH v4 14/40] hw/display: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Gerd Hoffmann 
Reviewed-by: Alistair Francis 
---
 include/hw/display/xlnx_dp.h |  5 +++--
 hw/display/bochs-display.c   |  9 +
 hw/display/cirrus_vga.c  | 10 +-
 hw/display/g364fb.c  |  4 ++--
 hw/display/qxl.c | 28 
 hw/display/vga-isa-mm.c  |  5 +++--
 hw/display/vga.c |  5 +++--
 hw/display/virtio-gpu.c  |  4 ++--
 hw/display/vmware_vga.c  |  3 ++-
 hw/display/xenfb.c   |  3 ++-
 10 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/include/hw/display/xlnx_dp.h b/include/hw/display/xlnx_dp.h
index ee046a5fac..26b759cd44 100644
--- a/include/hw/display/xlnx_dp.h
+++ b/include/hw/display/xlnx_dp.h
@@ -29,14 +29,15 @@
 #include "hw/display/dpcd.h"
 #include "hw/i2c/i2c-ddc.h"
 #include "qemu/fifo8.h"
+#include "qemu/units.h"
 #include "hw/dma/xlnx_dpdma.h"
 #include "audio/audio.h"
 
 #ifndef XLNX_DP_H
 #define XLNX_DP_H
 
-#define AUD_CHBUF_MAX_DEPTH 32768
-#define MAX_QEMU_BUFFER_SIZE4096
+#define AUD_CHBUF_MAX_DEPTH (32 * KiB)
+#define MAX_QEMU_BUFFER_SIZE(4 * KiB)
 
 #define DP_CORE_REG_ARRAY_SIZE  (0x3AF >> 2)
 #define DP_AVBUF_REG_ARRAY_SIZE (0x238 >> 2)
diff --git a/hw/display/bochs-display.c b/hw/display/bochs-display.c
index 1187d77576..5e0c1f1914 100644
--- a/hw/display/bochs-display.c
+++ b/hw/display/bochs-display.c
@@ -5,6 +5,7 @@
  * See the COPYING file in the top-level directory.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "hw/display/bochs-vbe.h"
@@ -70,7 +71,7 @@ static uint64_t bochs_display_vbe_read(void *ptr, hwaddr addr,
 case VBE_DISPI_INDEX_ID:
 return VBE_DISPI_ID5;
 case VBE_DISPI_INDEX_VIDEO_MEMORY_64K:
-return s->vgamem / (64 * 1024);
+return s->vgamem / (64 * KiB);
 }
 
 if (index >= ARRAY_SIZE(s->vbe_regs)) {
@@ -258,10 +259,10 @@ static void bochs_display_realize(PCIDevice *dev, Error 
**errp)
 
 s->con = graphic_console_init(DEVICE(dev), 0, _display_gfx_ops, s);
 
-if (s->vgamem < (4 * 1024 * 1024)) {
+if (s->vgamem < 4 * MiB) {
 error_setg(errp, "bochs-display: video memory too small");
 }
-if (s->vgamem > (256 * 1024 * 1024)) {
+if (s->vgamem > 256 * MiB) {
 error_setg(errp, "bochs-display: video memory too big");
 }
 s->vgamem = pow2ceil(s->vgamem);
@@ -323,7 +324,7 @@ static void bochs_display_exit(PCIDevice *dev)
 }
 
 static Property bochs_display_properties[] = {
-DEFINE_PROP_SIZE("vgamem", BochsDisplayState, vgamem, 16 * 1024 * 1024),
+DEFINE_PROP_SIZE("vgamem", BochsDisplayState, vgamem, 16 * MiB),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
index 138ae961b9..5e44f00f3f 100644
--- a/hw/display/cirrus_vga.c
+++ b/hw/display/cirrus_vga.c
@@ -27,6 +27,7 @@
  *   available at http://home.worldonline.dk/~finth/
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "trace.h"
 #include "hw/hw.h"
@@ -2218,7 +2219,7 @@ static inline void 
cirrus_cursor_compute_yrange(CirrusVGAState *s)
 uint32_t content;
 int y, y_min, y_max;
 
-src = s->vga.vram_ptr + s->real_vram_size - 16 * 1024;
+src = s->vga.vram_ptr + s->real_vram_size - 16 * KiB;
 if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) {
 src += (s->vga.sr[0x13] & 0x3c) * 256;
 y_min = 64;
@@ -2347,7 +2348,7 @@ static void cirrus_cursor_draw_line(VGACommonState *s1, 
uint8_t *d1, int scr_y)
 return;
 }
 
-src = s->vga.vram_ptr + s->real_vram_size - 16 * 1024;
+src = s->vga.vram_ptr + s->real_vram_size - 16 * KiB;
 if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) {
 src += (s->vga.sr[0x13] & 0x3c) * 256;
 src += (scr_y - s->vga.hw_cursor_y) * 16;
@@ -2995,8 +2996,7 @@ static void cirrus_init_common(CirrusVGAState *s, Object 
*owner,
 
 /* I/O handler for LFB */
 memory_region_init_io(>cirrus_linear_io, owner, _linear_io_ops, 
s,
-  "cirrus-linear-io", s->vga.vram_size_mb
-  * 1024 * 1024);
+  "cirrus-linear-io", s->vga.vram_size_mb * MiB);
 memory_region_set_flush_coalesced(>cirrus_linear_io);
 
 /* I/O handler for LFB */
@@ -3013,7 +3013,7 @@ static void cirrus_init_common(CirrusVGAState *s, Object 
*owner,
 memory_region_set_flush_coalesced(>cirrus_mmio_io);
 
 s->real_vram_size =
-(s->device_id == CIRRUS_ID_CLGD5446) ? 4096 * 1024 : 2048 * 1024;
+(s->device_id == CIRRUS_ID_CLGD5446) ? 4 * MiB : 2 * MiB;
 
 /* XXX: s->vga.vram_size must be a power of two */
 

[Qemu-devel] [PATCH v4 18/40] hw/sparc: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/sparc/leon3.c | 9 +
 hw/sparc/sun4m.c | 9 -
 hw/sparc64/niagara.c | 3 ++-
 hw/sparc64/sun4u.c   | 4 ++--
 4 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 98fa6adae0..60400923d5 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
@@ -139,9 +140,9 @@ static void leon3_generic_hw_init(MachineState *machine)
 env->qemu_irq_ack = leon3_irq_manager;
 
 /* Allocate RAM */
-if ((uint64_t)ram_size > (1UL << 30)) {
-error_report("Too much memory for this machine: %d, maximum 1G",
- (unsigned int)(ram_size / (1024 * 1024)));
+if (ram_size > 1 * GiB) {
+error_report("Too much memory for this machine: %lluMB, maximum 1G",
+ ram_size / MiB);
 exit(1);
 }
 
@@ -149,7 +150,7 @@ static void leon3_generic_hw_init(MachineState *machine)
 memory_region_add_subregion(address_space_mem, 0x4000, ram);
 
 /* Allocate BIOS */
-prom_size = 8 * 1024 * 1024; /* 8Mb */
+prom_size = 8 * MiB;
 memory_region_init_ram(prom, NULL, "Leon3.bios", prom_size, _fatal);
 memory_region_set_readonly(prom, true);
 memory_region_add_subregion(address_space_mem, 0x, prom);
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 0ee779fafe..d29411f013 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -45,7 +46,6 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "trace.h"
-#include "qemu/cutils.h"
 
 /*
  * Sun4m architecture was used in the following machines:
@@ -66,7 +66,7 @@
 #define KERNEL_LOAD_ADDR 0x4000
 #define CMDLINE_ADDR 0x007ff000
 #define INITRD_LOAD_ADDR 0x0080
-#define PROM_SIZE_MAX(1024 * 1024)
+#define PROM_SIZE_MAX(1 * MiB)
 #define PROM_VADDR   0xffd0
 #define PROM_FILENAME"openbios-sparc32"
 #define CFG_ADDR 0xd0510ULL
@@ -741,9 +741,8 @@ static void ram_init(hwaddr addr, ram_addr_t RAM_size,
 
 /* allocate RAM */
 if ((uint64_t)RAM_size > max_mem) {
-error_report("Too much memory for this machine: %d, maximum %d",
- (unsigned int)(RAM_size / (1024 * 1024)),
- (unsigned int)(max_mem / (1024 * 1024)));
+error_report("Too much memory for this machine: %llu, maximum %llu",
+ RAM_size / MiB, max_mem / MiB);
 exit(1);
 }
 dev = qdev_create(NULL, "memory");
diff --git a/hw/sparc64/niagara.c b/hw/sparc64/niagara.c
index 22c4655fde..4fa8cb2904 100644
--- a/hw/sparc64/niagara.c
+++ b/hw/sparc64/niagara.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 #include "cpu.h"
 #include "hw/hw.h"
@@ -84,7 +85,7 @@ typedef struct NiagaraBoardState {
 #define NIAGARA_PROM_BASE   0xfff000ULL
 #define NIAGARA_Q_OFFSET0x1ULL
 #define NIAGARA_OBP_OFFSET  0x8ULL
-#define PROM_SIZE_MAX   (4 * 1024 * 1024)
+#define PROM_SIZE_MAX   (4 * MiB)
 
 static void add_rom_or_fail(const char *file, const hwaddr addr)
 {
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 1bede85370..fd07b36226 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
@@ -52,11 +53,10 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "trace.h"
-#include "qemu/cutils.h"
 
 #define KERNEL_LOAD_ADDR 0x00404000
 #define CMDLINE_ADDR 0x003ff000
-#define PROM_SIZE_MAX(4 * 1024 * 1024)
+#define PROM_SIZE_MAX(4 * MiB)
 #define PROM_VADDR   0x000ffd0ULL
 #define PBM_SPECIAL_BASE 0x1feULL
 #define PBM_MEM_BASE 0x1ffULL
-- 
2.17.1




[Qemu-devel] [PATCH v4 12/40] hw/tpm: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Marc-André Lureau 
---
 include/hw/acpi/tpm.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h
index 46ac4dc581..3580ffd50c 100644
--- a/include/hw/acpi/tpm.h
+++ b/include/hw/acpi/tpm.h
@@ -16,6 +16,7 @@
 #ifndef HW_ACPI_TPM_H
 #define HW_ACPI_TPM_H
 
+#include "qemu/units.h"
 #include "hw/registerfields.h"
 
 #define TPM_TIS_ADDR_BASE   0xFED4
@@ -176,7 +177,7 @@ REG32(CRB_DATA_BUFFER, 0x80)
 #define TPM_CRB_ADDR_CTRL   (TPM_CRB_ADDR_BASE + A_CRB_CTRL_REQ)
 #define TPM_CRB_R_MAX   R_CRB_DATA_BUFFER
 
-#define TPM_LOG_AREA_MINIMUM_SIZE   (64 * 1024)
+#define TPM_LOG_AREA_MINIMUM_SIZE   (64 * KiB)
 
 #define TPM_TCPA_ACPI_CLASS_CLIENT  0
 #define TPM_TCPA_ACPI_CLASS_SERVER  1
-- 
2.17.1




[Qemu-devel] [PATCH v4 15/40] hw/misc: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/misc/auxbus.c | 3 ++-
 hw/misc/edu.c| 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/misc/auxbus.c b/hw/misc/auxbus.c
index b4cacd664b..b8a8721201 100644
--- a/hw/misc/auxbus.c
+++ b/hw/misc/auxbus.c
@@ -27,6 +27,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/log.h"
 #include "hw/misc/auxbus.h"
 #include "hw/i2c/i2c.h"
@@ -68,7 +69,7 @@ AUXBus *aux_init_bus(DeviceState *parent, const char *name)
 
 /* Memory related. */
 bus->aux_io = g_malloc(sizeof(*bus->aux_io));
-memory_region_init(bus->aux_io, OBJECT(bus), "aux-io", (1 << 20));
+memory_region_init(bus->aux_io, OBJECT(bus), "aux-io", 1 * MiB);
 address_space_init(>aux_addr_space, bus->aux_io, "aux-io");
 return bus;
 }
diff --git a/hw/misc/edu.c b/hw/misc/edu.c
index 34eb05d213..df26a4d046 100644
--- a/hw/misc/edu.c
+++ b/hw/misc/edu.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/msi.h"
 #include "qemu/timer.h"
@@ -357,7 +358,7 @@ static void pci_edu_realize(PCIDevice *pdev, Error **errp)
edu, QEMU_THREAD_JOINABLE);
 
 memory_region_init_io(>mmio, OBJECT(edu), _mmio_ops, edu,
-"edu-mmio", 1 << 20);
+"edu-mmio", 1 * MiB);
 pci_register_bar(pdev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, >mmio);
 }
 
-- 
2.17.1




[Qemu-devel] [PATCH v4 09/40] hw/scsi: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/scsi/scsi-disk.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index ded23d36ca..00c8fc571a 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -29,6 +29,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
 #endif
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/scsi/scsi.h"
@@ -44,13 +45,13 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
 #include 
 #endif
 
-#define SCSI_WRITE_SAME_MAX 524288
-#define SCSI_DMA_BUF_SIZE   131072
+#define SCSI_WRITE_SAME_MAX (512 * KiB)
+#define SCSI_DMA_BUF_SIZE   (128 * KiB)
 #define SCSI_MAX_INQUIRY_LEN256
 #define SCSI_MAX_MODE_LEN   256
 
-#define DEFAULT_DISCARD_GRANULARITY 4096
-#define DEFAULT_MAX_UNMAP_SIZE  (1 << 30)   /* 1 GB */
+#define DEFAULT_DISCARD_GRANULARITY (4 * KiB)
+#define DEFAULT_MAX_UNMAP_SIZE  (1 * GiB)
 #define DEFAULT_MAX_IO_SIZE INT_MAX /* 2 GB - 1 block */
 
 #define TYPE_SCSI_DISK_BASE "scsi-disk-base"
-- 
2.17.1




[Qemu-devel] [PATCH v4 08/40] hw/ipack: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Alberto Garcia 
---
 hw/ipack/tpci200.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/ipack/tpci200.c b/hw/ipack/tpci200.c
index da05c8589d..cd3e79139d 100644
--- a/hw/ipack/tpci200.c
+++ b/hw/ipack/tpci200.c
@@ -9,6 +9,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/ipack/ipack.h"
 #include "hw/pci/pci.h"
 #include "qemu/bitops.h"
@@ -597,9 +598,9 @@ static void tpci200_realize(PCIDevice *pci_dev, Error 
**errp)
 memory_region_init_io(>las1, OBJECT(s), _las1_ops,
   s, "tpci200_las1", 1024);
 memory_region_init_io(>las2, OBJECT(s), _las2_ops,
-  s, "tpci200_las2", 1024*1024*32);
+  s, "tpci200_las2", 32 * MiB);
 memory_region_init_io(>las3, OBJECT(s), _las3_ops,
-  s, "tpci200_las3", 1024*1024*16);
+  s, "tpci200_las3", 16 * MiB);
 pci_register_bar(>dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, >mmio);
 pci_register_bar(>dev, 1, PCI_BASE_ADDRESS_SPACE_IO, >io);
 pci_register_bar(>dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, >las0);
-- 
2.17.1




[Qemu-devel] [PATCH v4 11/40] hw/xen: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Alan Robinson 
---
 hw/block/xen_disk.c|  5 +++--
 hw/i386/xen/xen-mapcache.c |  3 ++-
 hw/xenpv/xen_domainbuild.c | 13 +++--
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 9fbc0cdb87..5e7f17ffa4 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -20,6 +20,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include 
 #include 
 
@@ -812,9 +813,9 @@ static int blk_connect(struct XenDevice *xendev)
 }
 
 xen_pv_printf(xendev, 1, "type \"%s\", fileproto \"%s\", filename \"%s\","
-  " size %" PRId64 " (%" PRId64 " MB)\n",
+  " size %" PRId64 " (%llu MB)\n",
   blkdev->type, blkdev->fileproto, blkdev->filename,
-  blkdev->file_size, blkdev->file_size >> 20);
+  blkdev->file_size, blkdev->file_size / MiB);
 
 /* Fill in number of sector size and number of sectors */
 xenstore_write_be_int(xendev, "sector-size", blkdev->file_blk);
diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c
index 628b813a11..4e4f069a24 100644
--- a/hw/i386/xen/xen-mapcache.c
+++ b/hw/i386/xen/xen-mapcache.c
@@ -9,6 +9,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 
 #include 
@@ -46,7 +47,7 @@
  * From empirical tests I observed that qemu use 75MB more than the
  * max_mcache_size.
  */
-#define NON_MCACHE_MEMORY_SIZE (80 * 1024 * 1024)
+#define NON_MCACHE_MEMORY_SIZE (80 * MiB)
 
 typedef struct MapCacheEntry {
 hwaddr paddr_index;
diff --git a/hw/xenpv/xen_domainbuild.c b/hw/xenpv/xen_domainbuild.c
index 027f76fad1..188acaca16 100644
--- a/hw/xenpv/xen_domainbuild.c
+++ b/hw/xenpv/xen_domainbuild.c
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/xen/xen_backend.h"
 #include "xen_domainbuild.h"
 #include "qemu/timer.h"
@@ -75,9 +76,9 @@ int xenstore_domain_init1(const char *kernel, const char 
*ramdisk,
 xenstore_write_str(dom, "vm", vm);
 
 /* memory */
-xenstore_write_int(dom, "memory/target", ram_size >> 10);  // kB
-xenstore_write_int(vm, "memory", ram_size >> 20);  // MB
-xenstore_write_int(vm, "maxmem", ram_size >> 20);  // MB
+xenstore_write_int(dom, "memory/target", ram_size / KiB);
+xenstore_write_int(vm, "memory", ram_size / MiB);
+xenstore_write_int(vm, "maxmem", ram_size / MiB);
 
 /* cpus */
 for (i = 0; i < smp_cpus; i++) {
@@ -113,7 +114,7 @@ int xenstore_domain_init2(int xenstore_port, int 
xenstore_mfn,
 
 /* console */
 xenstore_write_str(dom, "console/type", "ioemu");
-xenstore_write_int(dom, "console/limit",128 * 1024);
+xenstore_write_int(dom, "console/limit",128 * KiB);
 xenstore_write_int(dom, "console/ring-ref", console_mfn);
 xenstore_write_int(dom, "console/port", console_port);
 xen_config_dev_console(0);
@@ -260,7 +261,7 @@ int xen_domain_build_pv(const char *kernel, const char 
*ramdisk,
 }
 #endif
 
-rc = xc_domain_setmaxmem(xen_xc, xen_domid, ram_size >> 10);
+rc = xc_domain_setmaxmem(xen_xc, xen_domid, ram_size / KiB);
 if (rc < 0) {
 fprintf(stderr, "xen: xc_domain_setmaxmem() failed\n");
 goto err;
@@ -269,7 +270,7 @@ int xen_domain_build_pv(const char *kernel, const char 
*ramdisk,
 xenstore_port = xc_evtchn_alloc_unbound(xen_xc, xen_domid, 0);
 console_port = xc_evtchn_alloc_unbound(xen_xc, xen_domid, 0);
 
-rc = xc_linux_build(xen_xc, xen_domid, ram_size >> 20,
+rc = xc_linux_build(xen_xc, xen_domid, ram_size / MiB,
 kernel, ramdisk, cmdline,
 0, flags,
 xenstore_port, _mfn,
-- 
2.17.1




[Qemu-devel] [PATCH v4 13/40] hw/block: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/block/m25p80.c  | 5 +++--
 hw/block/nvme.c| 3 ++-
 hw/block/tc58128.c | 3 ++-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index a5ccffb4aa..38c69c81a9 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -22,6 +22,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "sysemu/block-backend.h"
 #include "hw/ssi/ssi.h"
@@ -541,12 +542,12 @@ static void flash_erase(Flash *s, int offset, FlashCMD 
cmd)
 switch (cmd) {
 case ERASE_4K:
 case ERASE4_4K:
-len = 4 << 10;
+len = 4 * KiB;
 capa_to_assert = ER_4K;
 break;
 case ERASE_32K:
 case ERASE4_32K:
-len = 32 << 10;
+len = 32 * KiB;
 capa_to_assert = ER_32K;
 break;
 case ERASE_SECTOR:
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 811084b6a7..ae2188c761 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -25,6 +25,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/block/block.h"
 #include "hw/hw.h"
 #include "hw/pci/msix.h"
@@ -648,7 +649,7 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeIdentify 
*c)
 
 static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeIdentify *c)
 {
-static const int data_len = 4096;
+static const int data_len = 4 * KiB;
 uint32_t min_nsid = le32_to_cpu(c->nsid);
 uint64_t prp1 = le64_to_cpu(c->prp1);
 uint64_t prp2 = le64_to_cpu(c->prp2);
diff --git a/hw/block/tc58128.c b/hw/block/tc58128.c
index 1d9f7ee000..808ad76ba6 100644
--- a/hw/block/tc58128.c
+++ b/hw/block/tc58128.c
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "hw/sh4/sh.h"
 #include "hw/loader.h"
@@ -26,7 +27,7 @@ typedef struct {
 
 static tc58128_dev tc58128_devs[2];
 
-#define FLASH_SIZE (16*1024*1024)
+#define FLASH_SIZE (16 * MiB)
 
 static void init_dev(tc58128_dev * dev, const char *filename)
 {
-- 
2.17.1




[Qemu-devel] [PATCH v4 07/40] hw/ivshmem: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Marc-André Lureau 
---
 hw/misc/ivshmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 16f03701b7..9a9f990867 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -17,6 +17,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
 #include "hw/hw.h"
@@ -1302,7 +1303,7 @@ static void ivshmem_realize(PCIDevice *dev, Error **errp)
 }
 
 if (s->sizearg == NULL) {
-s->legacy_size = 4 << 20; /* 4 MB default */
+s->legacy_size = 4 * MiB; /* 4 MB default */
 } else {
 int ret;
 uint64_t size;
-- 
2.17.1




[Qemu-devel] [PATCH v4 06/40] hw: Directly use "qemu/units.h" instead of "qemu/cutils.h"

2018-06-10 Thread Philippe Mathieu-Daudé
These files don't use anything exposed by "qemu/cutils.h",
simplify preprocessing including directly "qemu/units.h".

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/arm/msf2-soc.c  | 2 +-
 hw/arm/msf2-som.c  | 2 +-
 hw/core/machine.c  | 2 +-
 hw/display/sm501.c | 2 +-
 hw/mips/boston.c   | 2 +-
 hw/ppc/pnv.c   | 2 +-
 hw/ppc/ppc440_uc.c | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c
index 530e461c42..edb3ba824f 100644
--- a/hw/arm/msf2-soc.c
+++ b/hw/arm/msf2-soc.c
@@ -23,13 +23,13 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "hw/arm/arm.h"
 #include "exec/address-spaces.h"
 #include "hw/char/serial.h"
 #include "hw/boards.h"
-#include "qemu/cutils.h"
 #include "hw/arm/msf2-soc.h"
 #include "hw/misc/unimp.h"
 
diff --git a/hw/arm/msf2-som.c b/hw/arm/msf2-som.c
index ed533bbde1..2432b5e935 100644
--- a/hw/arm/msf2-som.c
+++ b/hw/arm/msf2-som.c
@@ -23,12 +23,12 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/boards.h"
 #include "hw/arm/arm.h"
 #include "exec/address-spaces.h"
-#include "qemu/cutils.h"
 #include "hw/arm/msf2-soc.h"
 #include "cpu.h"
 
diff --git a/hw/core/machine.c b/hw/core/machine.c
index ccf3a4b9c7..2077328bcc 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/boards.h"
 #include "qapi/error.h"
 #include "qapi/qapi-visit-common.h"
@@ -19,7 +20,6 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/numa.h"
 #include "qemu/error-report.h"
-#include "qemu/cutils.h"
 #include "sysemu/qtest.h"
 
 static char *machine_get_accel(Object *obj, Error **errp)
diff --git a/hw/display/sm501.c b/hw/display/sm501.c
index 1c6c9445c5..bbb9274886 100644
--- a/hw/display/sm501.c
+++ b/hw/display/sm501.c
@@ -24,7 +24,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu/cutils.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index 512c60c03e..b7bfeccf4c 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 
 #include "exec/address-spaces.h"
@@ -32,7 +33,6 @@
 #include "hw/mips/cpudevs.h"
 #include "hw/pci-host/xilinx-pcie.h"
 #include "qapi/error.h"
-#include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/log.h"
 #include "chardev/char.h"
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index bdb6f63d2c..0df4a4fd74 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/numa.h"
@@ -31,7 +32,6 @@
 #include "hw/ppc/pnv_core.h"
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
-#include "qemu/cutils.h"
 #include "qapi/visitor.h"
 #include "monitor/monitor.h"
 #include "hw/intc/intc.h"
diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
index b5b31b4b9b..1ab2235f20 100644
--- a/hw/ppc/ppc440_uc.c
+++ b/hw/ppc/ppc440_uc.c
@@ -9,8 +9,8 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
-#include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "cpu.h"
-- 
2.17.1




[Qemu-devel] [PATCH v4 10/40] hw/smbios: Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/smbios/smbios.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 27a07e96f4..a27e54b2fa 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -16,6 +16,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
@@ -625,10 +626,6 @@ static void smbios_build_type_11_table(void)
 SMBIOS_BUILD_TABLE_POST;
 }
 
-#define ONE_KB ((ram_addr_t)1 << 10)
-#define ONE_MB ((ram_addr_t)1 << 20)
-#define ONE_GB ((ram_addr_t)1 << 30)
-
 #define MAX_T16_STD_SZ 0x8000 /* 2T in Kilobytes */
 
 static void smbios_build_type_16_table(unsigned dimm_cnt)
@@ -640,7 +637,7 @@ static void smbios_build_type_16_table(unsigned dimm_cnt)
 t->location = 0x01; /* Other */
 t->use = 0x03; /* System memory */
 t->error_correction = 0x06; /* Multi-bit ECC (for Microsoft, per SeaBIOS) 
*/
-size_kb = QEMU_ALIGN_UP(ram_size, ONE_KB) / ONE_KB;
+size_kb = QEMU_ALIGN_UP(ram_size, KiB) / KiB;
 if (size_kb < MAX_T16_STD_SZ) {
 t->maximum_capacity = cpu_to_le32(size_kb);
 t->extended_maximum_capacity = cpu_to_le64(0);
@@ -668,7 +665,7 @@ static void smbios_build_type_17_table(unsigned instance, 
uint64_t size)
 t->memory_error_information_handle = cpu_to_le16(0xFFFE); /* Not provided 
*/
 t->total_width = cpu_to_le16(0x); /* Unknown */
 t->data_width = cpu_to_le16(0x); /* Unknown */
-size_mb = QEMU_ALIGN_UP(size, ONE_MB) / ONE_MB;
+size_mb = QEMU_ALIGN_UP(size, MiB) / MiB;
 if (size_mb < MAX_T17_STD_SZ) {
 t->size = cpu_to_le16(size_mb);
 t->extended_size = cpu_to_le32(0);
@@ -707,8 +704,8 @@ static void smbios_build_type_19_table(unsigned instance,
 
 end = start + size - 1;
 assert(end > start);
-start_kb = start / ONE_KB;
-end_kb = end / ONE_KB;
+start_kb = start / KiB;
+end_kb = end / KiB;
 if (start_kb < UINT32_MAX && end_kb < UINT32_MAX) {
 t->starting_address = cpu_to_le32(start_kb);
 t->ending_address = cpu_to_le32(end_kb);
@@ -869,7 +866,7 @@ void smbios_get_tables(const struct smbios_phys_mem_area 
*mem_array,
 
 smbios_build_type_11_table();
 
-#define MAX_DIMM_SZ (16ll * ONE_GB)
+#define MAX_DIMM_SZ (16 * GiB)
 #define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ \
 : ((ram_size - 1) % MAX_DIMM_SZ) + 1)
 
-- 
2.17.1




[Qemu-devel] [PATCH v4 04/40] checkpatch: Recognize IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
This fixes:

ERROR: "foo * bar" should be "foo *bar"
#310: FILE: hw/ppc/ppc440_uc.c:564:
+size = 8 * MiB * sh;
total: 1 errors, 0 warnings, 433 lines checked

Signed-off-by: Philippe Mathieu-Daudé 
---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e3d8c2cdfc..4923674c71 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -322,6 +322,7 @@ sub build_types {
(?:${all}\b)
)
(?:\s+$Modifier|\s+const)*
+   (?:[KMGTPE]iB)
  }x;
$Type   = qr{
$NonptrType
-- 
2.17.1




[Qemu-devel] [PATCH v4 00/40] Use the IEC binary prefix definitions

2018-06-10 Thread Philippe Mathieu-Daudé
Hi,

This series:

- split the byte-based definitions from "qemu/cutils.h" to "qemu/units.h"
  (this now triggers WARNING: 1 added file, does MAINTAINERS need updating?)
- clean hw/ includes;
- replace different constants used for byte size with their corresponding
  IEC binary prefix definitions.

Since v3:
- use IEC binary prefix definitions (Stefan Weil)
- rebased
- added R-b tags

Since v2:
- use "qemu/units.h" instead of "qemu/cunits.h" (Daniel P. Berrangé)
- avoid rebuilding the world including "qemu/units.h" in "hw/hw.h" (Thomas Huth)
- more constant replaced

Since v1:
- corrected Xen mult -> div (Alan Robinson)
- tagged 'include "qemu/cunits.h" in "hw/hw.h" as RFC
- fixed mips_r4k 'params_size' (Thomas Huth)
- added command used to generate patch in each commit (Alistair Francis)
- use G_BYTE for the raspi3 machine
- added Reviewed-by tags

Regards,

Phil.

Philippe Mathieu-Daudé (40):
  include: Add IEC binary prefixes in "qemu/units.h"
  vdi: Use definitions from "qemu/units.h"
  x86/cpu: Use definitions from "qemu/units.h"
  checkpatch: Recognize IEC binary prefix definitions
  hw: Use IEC binary prefix definitions from "qemu/units.h"
  hw: Directly use "qemu/units.h" instead of "qemu/cutils.h"
  hw/ivshmem: Use the IEC binary prefix definitions
  hw/ipack: Use the IEC binary prefix definitions
  hw/scsi: Use the IEC binary prefix definitions
  hw/smbios: Use the IEC binary prefix definitions
  hw/xen: Use the IEC binary prefix definitions
  hw/tpm: Use the IEC binary prefix definitions
  hw/block: Use the IEC binary prefix definitions
  hw/display: Use the IEC binary prefix definitions
  hw/misc: Use the IEC binary prefix definitions
  hw/riscv: Use the IEC binary prefix definitions
  hw/m68k: Use the IEC binary prefix definitions
  hw/sparc: Use the IEC binary prefix definitions
  hw/s390x: Use the IEC binary prefix definitions
  hw/hppa: Use the IEC binary prefix definitions
  hw/xtensa: Use the IEC binary prefix definitions
  hw/alpha: Use the IEC binary prefix definitions
  hw/tricore: Use the IEC binary prefix definitions
  hw/microblaze: Use the IEC binary prefix definitions
  hw/nios2: Use the IEC binary prefix definitions
  hw/cris: Use the IEC binary prefix definitions
  hw/lm32: Use the IEC binary prefix definitions
  hw/sh4: Use the IEC binary prefix definitions
  hw/mips/r4k: Constify params_size
  hw/mips: Use the IEC binary prefix definitions
  hw/arm: Use the IEC binary prefix definitions
  hw/ppc: Use the IEC binary prefix definitions
  hw/i386: Use the IEC binary prefix definitions
  hw/net: Use the IEC binary prefix definitions
  hw/usb: Use the IEC binary prefix definitions
  hw/sd: Use the IEC binary prefix definitions
  hw/vfio: Use the IEC binary prefix definitions
  hw/virtio: Use the IEC binary prefix definitions
  hw/rdma: Use the IEC binary prefix definitions
  cutils: Do not include "qemu/units.h" directly

 hw/net/ne2000.h  |  5 ++--
 hw/ppc/mac.h |  3 ++-
 hw/rdma/vmw/pvrdma.h |  3 ++-
 include/hw/acpi/tpm.h|  3 ++-
 include/hw/arm/fsl-imx7.h|  5 ++--
 include/hw/arm/stm32f205_soc.h   |  5 ++--
 include/hw/display/xlnx_dp.h |  5 ++--
 include/hw/i386/ich9.h   |  3 ++-
 include/hw/intc/mips_gic.h   |  3 ++-
 include/hw/mips/bios.h   |  3 ++-
 include/hw/net/allwinner_emac.h  |  5 ++--
 include/hw/ppc/spapr.h   |  5 ++--
 include/hw/virtio/virtio-net.h   |  3 ++-
 include/qemu/cutils.h|  7 --
 include/qemu/units.h | 20 
 block/vdi.c  |  8 +++
 hw/alpha/typhoon.c   | 17 +++---
 hw/arm/bcm2835_peripherals.c |  3 ++-
 hw/arm/boot.c|  7 +++---
 hw/arm/collie.c  |  5 ++--
 hw/arm/digic_boards.c|  7 +++---
 hw/arm/exynos4_boards.c  |  3 ++-
 hw/arm/gumstix.c |  3 ++-
 hw/arm/integratorcp.c|  3 ++-
 hw/arm/mainstone.c   |  3 ++-
 hw/arm/msf2-soc.c|  6 ++---
 hw/arm/msf2-som.c|  8 +++
 hw/arm/musicpal.c|  9 +++
 hw/arm/omap_sx1.c| 11 +
 hw/arm/raspi.c   |  5 ++--
 hw/arm/smmu-common.c |  3 ++-
 hw/arm/stellaris.c   |  5 ++--
 hw/arm/versatilepb.c |  5 ++--
 hw/arm/vexpress.c|  7 +++---
 hw/arm/virt.c|  5 ++--
 hw/arm/xilinx_zynq.c |  7 +++---
 hw/block/m25p80.c|  5 ++--
 hw/block/nvme.c  |  3 ++-
 hw/block/tc58128.c   |  3 ++-
 hw/block/xen_disk.c

[Qemu-devel] [PATCH v4 05/40] hw: Use IEC binary prefix definitions from "qemu/units.h"

2018-06-10 Thread Philippe Mathieu-Daudé
Code change produced with:

  $ git ls-files | egrep '\.[ch]$' | \
xargs sed -i -e 's/\(\W[KMGTPE]\)_BYTE/\1iB/g'

Suggested-by: Stefan Weil 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/qemu/cutils.h  |  8 +---
 hw/arm/msf2-soc.c  |  4 ++--
 hw/arm/msf2-som.c  |  6 +++---
 hw/core/loader-fit.c   |  3 ++-
 hw/core/machine.c  |  2 +-
 hw/display/sm501.c | 14 +++---
 hw/hppa/machine.c  |  2 +-
 hw/mips/boston.c   | 28 ++--
 hw/ppc/pnv.c   |  4 ++--
 hw/ppc/ppc440_uc.c | 26 +-
 hw/ppc/prep.c  |  2 +-
 hw/ppc/sam460ex.c  |  2 +-
 hw/ppc/spapr.c | 10 +-
 hw/ppc/spapr_rtas.c|  2 +-
 hw/sd/sd.c |  4 ++--
 hw/sd/sdhci.c  |  2 +-
 tests/test-cutils.c| 18 +-
 tests/test-keyval.c|  6 +++---
 tests/test-qemu-opts.c |  7 +++
 19 files changed, 72 insertions(+), 78 deletions(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index a663340b23..056e6629bb 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -2,6 +2,7 @@
 #define QEMU_CUTILS_H
 
 #include "qemu/fprintf-fn.h"
+#include "qemu/units.h"
 
 /**
  * pstrcpy:
@@ -147,13 +148,6 @@ int qemu_strtosz(const char *nptr, char **end, uint64_t 
*result);
 int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result);
 int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result);
 
-#define K_BYTE (1ULL << 10)
-#define M_BYTE (1ULL << 20)
-#define G_BYTE (1ULL << 30)
-#define T_BYTE (1ULL << 40)
-#define P_BYTE (1ULL << 50)
-#define E_BYTE (1ULL << 60)
-
 /* used to print char* safely */
 #define STR_OR_NULL(str) ((str) ? (str) : "null")
 
diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c
index 75c44adf7d..530e461c42 100644
--- a/hw/arm/msf2-soc.c
+++ b/hw/arm/msf2-soc.c
@@ -40,14 +40,14 @@
 
 #define SRAM_BASE_ADDRESS 0x2000
 
-#define MSF2_ENVM_MAX_SIZE(512 * K_BYTE)
+#define MSF2_ENVM_MAX_SIZE(512 * KiB)
 
 /*
  * eSRAM max size is 80k without SECDED(Single error correction and
  * dual error detection) feature and 64k with SECDED.
  * We do not support SECDED now.
  */
-#define MSF2_ESRAM_MAX_SIZE   (80 * K_BYTE)
+#define MSF2_ESRAM_MAX_SIZE   (80 * KiB)
 
 static const uint32_t spi_addr[MSF2_NUM_SPIS] = { 0x40001000 , 0x40011000 };
 static const uint32_t uart_addr[MSF2_NUM_UARTS] = { 0x4000 , 0x4001 };
diff --git a/hw/arm/msf2-som.c b/hw/arm/msf2-som.c
index 0795a3a3a1..ed533bbde1 100644
--- a/hw/arm/msf2-som.c
+++ b/hw/arm/msf2-som.c
@@ -33,10 +33,10 @@
 #include "cpu.h"
 
 #define DDR_BASE_ADDRESS  0xA000
-#define DDR_SIZE  (64 * M_BYTE)
+#define DDR_SIZE  (64 * MiB)
 
-#define M2S010_ENVM_SIZE  (256 * K_BYTE)
-#define M2S010_ESRAM_SIZE (64 * K_BYTE)
+#define M2S010_ENVM_SIZE  (256 * KiB)
+#define M2S010_ESRAM_SIZE (64 * KiB)
 
 static void emcraft_sf2_s2s010_init(MachineState *machine)
 {
diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c
index 6387854b54..447f60857d 100644
--- a/hw/core/loader-fit.c
+++ b/hw/core/loader-fit.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "exec/memory.h"
 #include "hw/loader.h"
 #include "hw/loader-fit.h"
@@ -194,7 +195,7 @@ static int fit_load_fdt(const struct fit_loader *ldr, const 
void *itb,
 
 err = fit_image_addr(itb, img_off, "load", _addr);
 if (err == -ENOENT) {
-load_addr = ROUND_UP(kernel_end, 64 * K_BYTE) + (10 * M_BYTE);
+load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB);
 } else if (err) {
 ret = err;
 goto out;
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 617e5f8d75..ccf3a4b9c7 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -522,7 +522,7 @@ static void machine_class_init(ObjectClass *oc, void *data)
 MachineClass *mc = MACHINE_CLASS(oc);
 
 /* Default 128 MB as guest ram size */
-mc->default_ram_size = 128 * M_BYTE;
+mc->default_ram_size = 128 * MiB;
 mc->rom_file_has_mr = true;
 
 /* numa node memory size aligned on 8MB by default.
diff --git a/hw/display/sm501.c b/hw/display/sm501.c
index e47be99451..1c6c9445c5 100644
--- a/hw/display/sm501.c
+++ b/hw/display/sm501.c
@@ -452,12 +452,12 @@
 
 /* SM501 local memory size taken from "linux/drivers/mfd/sm501.c" */
 static const uint32_t sm501_mem_local_size[] = {
-[0] = 4 * M_BYTE,
-[1] = 8 * M_BYTE,
-[2] = 16 * M_BYTE,
-[3] = 32 * M_BYTE,
-[4] = 64 * M_BYTE,
-[5] = 2 * M_BYTE,
+[0] = 4 * MiB,
+[1] = 8 * MiB,
+[2] = 16 * MiB,
+[3] = 32 * MiB,
+[4] = 64 * MiB,
+[5] = 2 * MiB,
 };
 #define get_local_mem_size(s) sm501_mem_local_size[(s)->local_mem_size_index]
 
@@ -1826,7 +1826,7 @@ static void sm501_realize_pci(PCIDevice *dev, Error 
**errp)
 }
 
 static Property sm501_pci_properties[] = {
-DEFINE_PROP_UINT32("vram-size", SM501PCIState, vram_size, 64 * 

[Qemu-devel] [PATCH v4 02/40] vdi: Use definitions from "qemu/units.h"

2018-06-10 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 block/vdi.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index 668af0a828..35b51dc5c5 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -50,6 +50,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qobject-input-visitor.h"
@@ -83,9 +84,6 @@
 /* Command line option for static images. */
 #define BLOCK_OPT_STATIC "static"
 
-#define KiB 1024
-#define MiB (KiB * KiB)
-
 #define SECTOR_SIZE 512
 #define DEFAULT_CLUSTER_SIZE (1 * MiB)
 
@@ -250,7 +248,7 @@ static void vdi_header_print(VdiHeader *header)
 logout("heads   0x%04x\n", header->heads);
 logout("sectors 0x%04x\n", header->sectors);
 logout("sector size 0x%04x\n", header->sector_size);
-logout("image size  0x%" PRIx64 " B (%" PRIu64 " MiB)\n",
+logout("image size  0x%" PRIx64 " B (%llu MiB)\n",
header->disk_size, header->disk_size / MiB);
 logout("block size  0x%04x\n", header->block_size);
 logout("block extra 0x%04x\n", header->block_extra);
@@ -434,7 +432,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, 
int flags,
 goto fail;
 } else if (header.block_size != DEFAULT_CLUSTER_SIZE) {
 error_setg(errp, "unsupported VDI image (block size %" PRIu32
-   " is not %u)", header.block_size, DEFAULT_CLUSTER_SIZE);
+   " is not %llu)", header.block_size, DEFAULT_CLUSTER_SIZE);
 ret = -ENOTSUP;
 goto fail;
 } else if (header.disk_size >
-- 
2.17.1




[Qemu-devel] [PATCH v4 03/40] x86/cpu: Use definitions from "qemu/units.h"

2018-06-10 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 target/i386/cpu.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 94260412e2..56c63615fe 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/cutils.h"
 
 #include "cpu.h"
@@ -64,9 +65,6 @@ struct CPUID2CacheDescriptorInfo {
 int associativity;
 };
 
-#define KiB 1024
-#define MiB (1024 * 1024)
-
 /*
  * Known CPUID 2 cache descriptors.
  * From Intel SDM Volume 2A, CPUID instruction
-- 
2.17.1




[Qemu-devel] [PATCH v4 01/40] include: Add IEC binary prefixes in "qemu/units.h"

2018-06-10 Thread Philippe Mathieu-Daudé
Loosely based on 076b35b5a56.

Suggested-by: Stefan Weil 
Signed-off-by: Philippe Mathieu-Daudé 
---
I suppose the following warning is irrelevant:

  WARNING: 1 added file, does MAINTAINERS need updating

 include/qemu/units.h | 20 
 1 file changed, 20 insertions(+)
 create mode 100644 include/qemu/units.h

diff --git a/include/qemu/units.h b/include/qemu/units.h
new file mode 100644
index 00..e3a39ed59e
--- /dev/null
+++ b/include/qemu/units.h
@@ -0,0 +1,20 @@
+/*
+ * IEC binary prefixes definitions
+ *
+ * Copyright (C) 2015 Nikunj A Dadhania, IBM Corporation
+ * Copyright (C) 2018 Philippe Mathieu-Daudé 
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_UNITS_H
+#define QEMU_UNITS_H
+
+#define KiB (1ULL << 10)
+#define MiB (1ULL << 20)
+#define GiB (1ULL << 30)
+#define TiB (1ULL << 40)
+#define PiB (1ULL << 50)
+#define EiB (1ULL << 60)
+
+#endif
-- 
2.17.1




Re: [Qemu-devel] [PATCH v6 47/49] tests: add top-level make dependency for docker builds

2018-06-10 Thread Philippe Mathieu-Daudé
Hi Alex,

On 06/08/2018 09:33 AM, Alex Bennée wrote:
> One problem with satisfying your docker dependencies in a sub-make it
> you might end up trying to satisfy the dependency multiple times. This
> is especially a problem with debian-sid based cross compilers and CI
> setups. We solve this by doing a docker build pass at the top level
> before any sub-makes are called.
> 
> We still need to satisfy dependencies in the Makefile.target call so
> people can run tests from individual target directories. We introduce
> a new Makefile.probe which gets called for each PROBE_TARGET and
> allows us to build up the list. It does require multiply including
> config-target.mak which shouldn't cause any issues as it shouldn't
> define anything that clashes with config-host.mak. However we undefine
> a few key variables each time around.
> 
> Signed-off-by: Alex Bennée 
> ---
>  tests/Makefile.include   | 14 +-
>  tests/tcg/Makefile.probe | 31 +++
>  2 files changed, 44 insertions(+), 1 deletion(-)
>  create mode 100644 tests/tcg/Makefile.probe
> 
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index ca00247e36..049a387436 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -931,7 +931,19 @@ BUILD_TCG_TARGET_RULES=$(patsubst %,build-tcg-tests-%, 
> $(LINUX_USER_TARGETS))
>  CLEAN_TCG_TARGET_RULES=$(patsubst %,clean-tcg-tests-%, $(LINUX_USER_TARGETS))
>  RUN_TCG_TARGET_RULES=$(patsubst %,run-tcg-tests-%, $(LINUX_USER_TARGETS))
>  
> -build-tcg-tests-%:
> +# Probe for the Docker Builds we need for later
> +DOCKER_BUILD_TARGETS:=
> +$(foreach PROBE_TARGET,$(TARGET_LIST),   \
> + $(eval -include $(SRC_PATH)/tests/tcg/Makefile.probe)   \
> + $(if $(DOCKER_PREREQ),  \
> + $(eval DOCKER_BUILD_TARGETS+=$(DOCKER_PREREQ
> +
> +$(info DOCKER_BUILD_TARGETS=$(sort $(DOCKER_BUILD_TARGETS)))

Is this verbose info on purpose?

Else this could be surrounded by something equiv to:

ifneq ($(V)$(DEBUG),)
...
endif

> +
> +.PHONY: build-docker-prereqs
> +build-docker-prereqs: $(sort $(DOCKER_BUILD_TARGETS))
> +
> +build-tcg-tests-%: build-docker-prereqs
>   $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" 
> TARGET_DIR="$*/" guest-tests,)
>  
>  run-tcg-tests-%: build-tcg-tests-%
> diff --git a/tests/tcg/Makefile.probe b/tests/tcg/Makefile.probe
> new file mode 100644
> index 00..7529e203ad
> --- /dev/null
> +++ b/tests/tcg/Makefile.probe
> @@ -0,0 +1,31 @@
> +# -*- Mode: makefile -*-
> +#
> +# TCG Compiler Probe
> +#
> +# This Makefile fragement is included multiple times in the main make
> +# script to probe for available compilers. This is used to build up a
> +# selection of required docker targets before we invoke a sub-make for
> +# each target.
> +
> +# First we need the target makefile which tells us the target architecture
> +-include $(BUILD_DIR)/$(PROBE_TARGET)/config-target.mak
> +
> +# Then we load up the target architecture makefiles which tell us
> +# about the compilers
> +undefine CROSS_CC_GUEST
> +undefine DOCKER_IMAGE
> +DOCKER_PREREQ:=
> +
> +-include $(SRC_PATH)/tests/tcg/$(TARGET_BASE_ARCH)/Makefile.include
> +-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.include
> +
> +ifndef CROSS_CC_GUEST
> +ifneq ($(DOCKER_IMAGE),)
> +DOCKER_PREREQ:=docker-image-$(DOCKER_IMAGE)
> +endif
> +endif
> +
> +# Clean-up
> +undefine TARGET_NAME
> +undefine TARGET_BASE_ARCH
> +undefine TARGET_ABI_DIR
> 



Re: [Qemu-devel] [PATCH] qemu-binfmt-conf.sh: ignore the OS/ABI field

2018-06-10 Thread Richard Henderson
On 06/05/2018 09:47 AM, Laurent Vivier wrote:
> Most of the binaries have a value of "UNIX - System V" for the OS/ABI.
> 
> But cc1 has a value of "UNIX - GNU", and if we don't update the binfmt
> mask to ignore the OS/ABI field, gcc fails to execute it:
> 
> gcc: error trying to exec '/usr/lib/gcc/m68k-linux-gnu/7/cc1': execv: Exec 
> format error
> 
> Signed-off-by: Laurent Vivier 
> ---
>  scripts/qemu-binfmt-conf.sh | 18 +-
>  1 file changed, 9 insertions(+), 9 deletions(-)

Reviewed-by: Richard Henderson 


r~



Re: [Qemu-devel] [PATCH v2 000/108] linux-user: Split do_syscall

2018-06-10 Thread Richard Henderson
On 06/09/2018 05:00 PM, Richard Henderson wrote:
> * Changed the table into a switch, for the reason documented.
>   Use macros to actually enter the syscall into the switch.
> * Finish the split.
> * Fix some bugs along the way.

I forgot to mention, this is based on

https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg01764.html

and nothing else.  V1 already had the is_hostfd and openat patches folded in.
I think that it will be much clearer to do those the other way around.

For the record, the whole tree is available at

https://github.com/rth7680/qemu/tree/lu-split-2


r~



Re: [Qemu-devel] [PATCH v2 009/108] linux-user: Set up infrastructure for table-izing syscalls

2018-06-10 Thread Richard Henderson
On 06/10/2018 02:39 AM, Peter Maydell wrote:
> It would be cleaner to have a single
> #if something
> static foo_impl(..) { ... }
> static syscall_impl foo = {
> .name = "foo",
> .impl = foo_impl,
> .strace_stuff = ...,
> };
> register_syscall(foo);
> #endif
> 
> Hash table?

It would be cleaner to have everything in one place, yes.  I just replied along
those lines elsewhere in the thread.

Indeed, now that I'm thinking along the lines of strace, I'm thinking that
there should be a separate argument extraction step that would be shared by
both strace and syscall implementation.

I'm not a fan of register_syscall(foo) and the startup costs that implies.

The set of syscalls that we support is fixed at compile time.  We should have a
compile-time generation step that builds everything that is required.  Whether
this is C emitting C, or python emitting C, I do not yet have an opinion.


r~



Re: [Qemu-devel] [PATCH v2 000/108] linux-user: Split do_syscall

2018-06-10 Thread Richard Henderson
On 06/10/2018 02:34 AM, Peter Maydell wrote:
> It's still a stupidly large source file -- is it worth taking
> advantage of the split into multiple implementation functions
> to break it up into multiple source files? (We could group
> related syscalls together.)

It's possible.  Any suggestions for groupings?  I can think of files,
networking, memory (mmap ), signals, session (getuid ), ipc.

I've also wondered about cutting down on ifdef boilerplate.  There's nothing
more that I can do about it within the C preprocessor.

I'd have to wire up something else via the makefiles, but haven't thought about
what form that should take.  Likely it ought to be something that can be
massaged into both syscall dispatch and strace tables.


r~



[Qemu-devel] [PATCH] i386/kvm: add support for Hyper-V TLB flush

2018-06-10 Thread Vitaly Kuznetsov
Add support for Hyper-V TLB flush which recently got added to KVM.

Just like regular Hyper-V we announce HV_EX_PROCESSOR_MASKS_RECOMMENDED
regardless of how many vCPUs we have. Windows is 'smart' and uses less
expensive non-EX Hypercall whenever possible (when it wants to flush TLB
for all vCPUs or the maximum vCPU index in the vCPU set requires flushing
is less than 64).

Signed-off-by: Vitaly Kuznetsov 
---
 linux-headers/linux/kvm.h  |  1 +
 target/i386/cpu.c  |  1 +
 target/i386/cpu.h  |  1 +
 target/i386/hyperv-proto.h |  1 +
 target/i386/kvm.c  | 15 ++-
 5 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index cdb148e959..a52a685690 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -948,6 +948,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_S390_BPB 152
 #define KVM_CAP_GET_MSR_FEATURES 153
 #define KVM_CAP_HYPERV_EVENTFD 154
+#define KVM_CAP_HYPERV_TLBFLUSH 155
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 94260412e2..756cc78808 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5151,6 +5151,7 @@ static Property x86_cpu_properties[] = {
 DEFINE_PROP_BOOL("hv-stimer", X86CPU, hyperv_stimer, false),
 DEFINE_PROP_BOOL("hv-frequencies", X86CPU, hyperv_frequencies, false),
 DEFINE_PROP_BOOL("hv-reenlightenment", X86CPU, hyperv_reenlightenment, 
false),
+DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false),
 DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true),
 DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
 DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 664504610e..738d695331 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1363,6 +1363,7 @@ struct X86CPU {
 bool hyperv_stimer;
 bool hyperv_frequencies;
 bool hyperv_reenlightenment;
+bool hyperv_tlbflush;
 bool check_cpuid;
 bool enforce_cpuid;
 bool expose_kvm;
diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h
index 93352ebd2a..d6d5a79293 100644
--- a/target/i386/hyperv-proto.h
+++ b/target/i386/hyperv-proto.h
@@ -58,6 +58,7 @@
 #define HV_APIC_ACCESS_RECOMMENDED  (1u << 3)
 #define HV_SYSTEM_RESET_RECOMMENDED (1u << 4)
 #define HV_RELAXED_TIMING_RECOMMENDED   (1u << 5)
+#define HV_EX_PROCESSOR_MASKS_RECOMMENDED   (1u << 11)
 
 /*
  * Basic virtualized MSRs
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 44f70733e7..91c8e952c8 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -585,7 +585,8 @@ static bool hyperv_enabled(X86CPU *cpu)
 cpu->hyperv_runtime ||
 cpu->hyperv_synic ||
 cpu->hyperv_stimer ||
-cpu->hyperv_reenlightenment);
+cpu->hyperv_reenlightenment ||
+cpu->hyperv_tlbflush);
 }
 
 static int kvm_arch_set_tsc_khz(CPUState *cs)
@@ -823,6 +824,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
 if (cpu->hyperv_vapic) {
 c->eax |= HV_APIC_ACCESS_RECOMMENDED;
 }
+if (cpu->hyperv_tlbflush) {
+if (kvm_check_extension(cs->kvm_state,
+KVM_CAP_HYPERV_TLBFLUSH) <= 0) {
+fprintf(stderr, "Hyper-V TLB flush support "
+"(requested by 'hv-tlbflush' cpu flag) "
+" is not supported by kernel\n");
+return -ENOSYS;
+}
+c->eax |= HV_REMOTE_TLB_FLUSH_RECOMMENDED;
+c->eax |= HV_EX_PROCESSOR_MASKS_RECOMMENDED;
+}
+
 c->ebx = cpu->hyperv_spinlock_attempts;
 
 c = _data.entries[cpuid_i++];
-- 
2.14.4




[Qemu-devel] [Bug 1776096] [NEW] qemu 2.12.0 qemu-system-ppc illegal instruction on ppc64le, crashes emulator

2018-06-10 Thread Cameron Kaiser
Public bug reported:

% uname -a
Linux tim.floodgap.com 4.16.14-300.fc28.ppc64le #1 SMP Tue Jun 5 15:59:48 UTC 
2018 ppc64le ppc64le ppc64le GNU/Linux

STR:
Start QEMU and boot Mac OS X 10.4.11.
Download the current version of TenFourFox (I used G3 so that AltiVec was not a 
confounder).
Try to start TenFourFox in safe mode (hold down Option as you double-click 
while the icon bounces in the Dock).

Expected:
TenFourFox starts.

Actual:
The entire emulator exits with an illegal instruction error.

Trace of session (including some disassembly so you can see where TCG
went wrong):

tim:/home/spectre/src/qemu-2.12.0/ppc-softmmu/% gdb --args ./qemu-
system-ppc -M mac99,accel=tcg -m 2048 -prom-env boot-args=-v -boot c
-drive file=tigerhd.img,format=raw,cache=none -netdev user,id=mynet0
-device usb-net,netdev=mynet0 -usb -device usb-tablet

GNU gdb (GDB) Fedora 8.1-15.fc28
[...]
Reading symbols from ./qemu-system-ppc...done.
(gdb) run
[...]

Thread 6 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7242ea30 (LWP 7017)]
0xfffc in ?? ()
#0  0xfffc in  ()
#1  0x7fffd4edec00 in code_gen_buffer ()
#2  0x100c9e20 in cpu_tb_exec (itb=, cpu=) at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:169
#3  0x100c9e20 in cpu_loop_exec_tb (tb_exit=, 
last_tb=, tb=, cpu=)
at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:626
#4  0x100c9e20 in cpu_exec (cpu=)
at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:734
#5  0x1007decc in tcg_cpu_exec (cpu=0x11774e10)
at /home/spectre/src/qemu-2.12.0/cpus.c:1362
(gdb) disas 0x7fffd4edebf0, 0x7fffd4edec10
Dump of assembler code from 0x7fffd4edebf0 to 0x7fffd4edec10:
   0x7fffd4edebf0 :  addir0,r4,3
   0x7fffd4edebf4 :  rlwinm  r0,r0,0,0,19
   0x7fffd4edebf8 :  cmplw   cr7,r0,r12
   0x7fffd4edebfc :  bnel
cr7,0x7fffd4ed8b64 
   0x7fffd4edec00 :  lwbrx   r14,r3,r4
   0x7fffd4edec04 :  stw r14,40(r27)
   0x7fffd4edec08 :  clrldi  r4,r14,32
   0x7fffd4edec0c :  rlwinm  r3,r4,25,19,26
End of assembler dump.
(gdb) disas 0x7fffd4ed8b60, 0x7fffd4ed8b70
Dump of assembler code from 0x7fffd4ed8b60 to 0x7fffd4ed8b70:
   0x7fffd4ed8b60 :  bctrl
   0x7fffd4ed8b64 :  mtctr   r3
   0x7fffd4ed8b68 :  mr  r31,r3
   0x7fffd4ed8b6c :  li  r3,0
End of assembler dump.
(gdb) i reg ctr
ctr0x   18446744073709551615

It appears that the branch at 0x7fffd4edebfc caused a jump back (a
return?) through CTR, but CTR has -1 in it, hence setting PC to
0xfffc. I am not sure how to debug this further.

** 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/1776096

Title:
  qemu 2.12.0 qemu-system-ppc illegal instruction on ppc64le, crashes
  emulator

Status in QEMU:
  New

Bug description:
  % uname -a
  Linux tim.floodgap.com 4.16.14-300.fc28.ppc64le #1 SMP Tue Jun 5 15:59:48 UTC 
2018 ppc64le ppc64le ppc64le GNU/Linux

  STR:
  Start QEMU and boot Mac OS X 10.4.11.
  Download the current version of TenFourFox (I used G3 so that AltiVec was not 
a confounder).
  Try to start TenFourFox in safe mode (hold down Option as you double-click 
while the icon bounces in the Dock).

  Expected:
  TenFourFox starts.

  Actual:
  The entire emulator exits with an illegal instruction error.

  Trace of session (including some disassembly so you can see where TCG
  went wrong):

  tim:/home/spectre/src/qemu-2.12.0/ppc-softmmu/% gdb --args ./qemu-
  system-ppc -M mac99,accel=tcg -m 2048 -prom-env boot-args=-v -boot c
  -drive file=tigerhd.img,format=raw,cache=none -netdev user,id=mynet0
  -device usb-net,netdev=mynet0 -usb -device usb-tablet

  GNU gdb (GDB) Fedora 8.1-15.fc28
  [...]
  Reading symbols from ./qemu-system-ppc...done.
  (gdb) run
  [...]

  Thread 6 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x7242ea30 (LWP 7017)]
  0xfffc in ?? ()
  #0  0xfffc in  ()
  #1  0x7fffd4edec00 in code_gen_buffer ()
  #2  0x100c9e20 in cpu_tb_exec (itb=, cpu=) at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:169
  #3  0x100c9e20 in cpu_loop_exec_tb (tb_exit=, 
last_tb=, tb=, cpu=)
  at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:626
  #4  0x100c9e20 in cpu_exec (cpu=)
  at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:734
  #5  0x1007decc in tcg_cpu_exec (cpu=0x11774e10)
  at /home/spectre/src/qemu-2.12.0/cpus.c:1362
  (gdb) disas 0x7fffd4edebf0, 0x7fffd4edec10
  Dump of assembler code from 0x7fffd4edebf0 to 0x7fffd4edec10:
 0x7fffd4edebf0 :addir0,r4,3
 0x7fffd4edebf4 :rlwinm  r0,r0,0,0,19
 0x7fffd4edebf8 :cmplw   

[Qemu-devel] [Bug 1776096] Re: qemu 2.12.0 qemu-system-ppc illegal instruction on ppc64le, crashes emulator

2018-06-10 Thread Cameron Kaiser
Sorry, more complete disassembly of the apparent actual fault:

   0x7fffd4ed8b64 :  mtctr   r3
   0x7fffd4ed8b68 :  mr  r31,r3
   0x7fffd4ed8b6c :  li  r3,0
   0x7fffd4ed8b70 :  bctr

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

Title:
  qemu 2.12.0 qemu-system-ppc illegal instruction on ppc64le, crashes
  emulator

Status in QEMU:
  New

Bug description:
  % uname -a
  Linux tim.floodgap.com 4.16.14-300.fc28.ppc64le #1 SMP Tue Jun 5 15:59:48 UTC 
2018 ppc64le ppc64le ppc64le GNU/Linux

  STR:
  Start QEMU and boot Mac OS X 10.4.11.
  Download the current version of TenFourFox (I used G3 so that AltiVec was not 
a confounder).
  Try to start TenFourFox in safe mode (hold down Option as you double-click 
while the icon bounces in the Dock).

  Expected:
  TenFourFox starts.

  Actual:
  The entire emulator exits with an illegal instruction error.

  Trace of session (including some disassembly so you can see where TCG
  went wrong):

  tim:/home/spectre/src/qemu-2.12.0/ppc-softmmu/% gdb --args ./qemu-
  system-ppc -M mac99,accel=tcg -m 2048 -prom-env boot-args=-v -boot c
  -drive file=tigerhd.img,format=raw,cache=none -netdev user,id=mynet0
  -device usb-net,netdev=mynet0 -usb -device usb-tablet

  GNU gdb (GDB) Fedora 8.1-15.fc28
  [...]
  Reading symbols from ./qemu-system-ppc...done.
  (gdb) run
  [...]

  Thread 6 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x7242ea30 (LWP 7017)]
  0xfffc in ?? ()
  #0  0xfffc in  ()
  #1  0x7fffd4edec00 in code_gen_buffer ()
  #2  0x100c9e20 in cpu_tb_exec (itb=, cpu=) at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:169
  #3  0x100c9e20 in cpu_loop_exec_tb (tb_exit=, 
last_tb=, tb=, cpu=)
  at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:626
  #4  0x100c9e20 in cpu_exec (cpu=)
  at /home/spectre/src/qemu-2.12.0/accel/tcg/cpu-exec.c:734
  #5  0x1007decc in tcg_cpu_exec (cpu=0x11774e10)
  at /home/spectre/src/qemu-2.12.0/cpus.c:1362
  (gdb) disas 0x7fffd4edebf0, 0x7fffd4edec10
  Dump of assembler code from 0x7fffd4edebf0 to 0x7fffd4edec10:
 0x7fffd4edebf0 :addir0,r4,3
 0x7fffd4edebf4 :rlwinm  r0,r0,0,0,19
 0x7fffd4edebf8 :cmplw   cr7,r0,r12
 0x7fffd4edebfc :bnel
cr7,0x7fffd4ed8b64 
 0x7fffd4edec00 :lwbrx   r14,r3,r4
 0x7fffd4edec04 :stw r14,40(r27)
 0x7fffd4edec08 :clrldi  r4,r14,32
 0x7fffd4edec0c :rlwinm  r3,r4,25,19,26
  End of assembler dump.
  (gdb) disas 0x7fffd4ed8b60, 0x7fffd4ed8b70
  Dump of assembler code from 0x7fffd4ed8b60 to 0x7fffd4ed8b70:
 0x7fffd4ed8b60 :bctrl
 0x7fffd4ed8b64 :mtctr   r3
 0x7fffd4ed8b68 :mr  r31,r3
 0x7fffd4ed8b6c :li  r3,0
  End of assembler dump.
  (gdb) i reg ctr
  ctr0x 18446744073709551615

  It appears that the branch at 0x7fffd4edebfc caused a jump back (a
  return?) through CTR, but CTR has -1 in it, hence setting PC to
  0xfffc. I am not sure how to debug this further.

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



[Qemu-devel] [PATCH v4] cutils: Provide strchrnul

2018-06-10 Thread Keno Fischer
strchrnul is a GNU extension and thus unavailable on a number of targets.
In the review for a commit removing strchrnul from 9p, I was asked to
create a qemu_strchrnul helper to factor out this functionality.
Do so, and use it in a number of other places in the code base that inlined
the replacement pattern in a place where strchrnul could be used.

Signed-off-by: Keno Fischer 
Acked-by: Greg Kurz 
---

Changes since v3:
 - Fix bug in configure check

 configure | 15 +++
 hmp.c |  8 
 hw/9pfs/9p-local.c|  2 +-
 include/qemu/cutils.h |  8 
 monitor.c |  8 ++--
 util/cutils.c | 15 +++
 util/qemu-option.c|  6 +-
 util/uri.c|  6 ++
 8 files changed, 48 insertions(+), 20 deletions(-)

diff --git a/configure b/configure
index 14b1113..f5ca850 100755
--- a/configure
+++ b/configure
@@ -4747,6 +4747,18 @@ if compile_prog "" "" ; then
 fi
 
 ##
+# check if we have strchrnul
+
+strchrnul=no
+cat > $TMPC << EOF
+#include 
+int main(void) { (void)strchrnul("Hello World", 'W'); return 0; }
+EOF
+if compile_prog "" "" ; then
+strchrnul=yes
+fi
+
+##
 # check if trace backend exists
 
 $python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" 
--check-backends  > /dev/null 2> /dev/null
@@ -6229,6 +6241,9 @@ fi
 if test "$sem_timedwait" = "yes" ; then
   echo "CONFIG_SEM_TIMEDWAIT=y" >> $config_host_mak
 fi
+if test "$strchrnul" = "yes" ; then
+  echo "CONFIG_STRCHRNUL=y" >> $config_host_mak
+fi
 if test "$byteswap_h" = "yes" ; then
   echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak
 fi
diff --git a/hmp.c b/hmp.c
index ef93f48..416d4c9 100644
--- a/hmp.c
+++ b/hmp.c
@@ -2123,12 +2123,12 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
 int has_hold_time = qdict_haskey(qdict, "hold-time");
 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
 Error *err = NULL;
-char *separator;
+const char *separator;
 int keyname_len;
 
 while (1) {
-separator = strchr(keys, '-');
-keyname_len = separator ? separator - keys : strlen(keys);
+separator = qemu_strchrnul(keys, '-');
+keyname_len = separator - keys;
 
 /* Be compatible with old interface, convert user inputted "<" */
 if (keys[0] == '<' && keyname_len == 1) {
@@ -2165,7 +2165,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
 keylist->value->u.qcode.data = idx;
 }
 
-if (!separator) {
+if (!*separator) {
 break;
 }
 keys = separator + 1;
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 5721eff..828e8d6 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -65,7 +65,7 @@ int local_open_nofollow(FsContext *fs_ctx, const char *path, 
int flags,
 assert(*path != '/');
 
 head = g_strdup(path);
-c = strchrnul(path, '/');
+c = qemu_strchrnul(path, '/');
 if (*c) {
 /* Intermediate path element */
 head[c - path] = 0;
diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index a663340..809090c 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -122,6 +122,14 @@ int qemu_strnlen(const char *s, int max_len);
  * Returns: the pointer originally in @input.
  */
 char *qemu_strsep(char **input, const char *delim);
+#ifdef CONFIG_STRCHRNUL
+static inline const char *qemu_strchrnul(const char *s, int c)
+{
+return strchrnul(s, c);
+}
+#else
+const char *qemu_strchrnul(const char *s, int c);
+#endif
 time_t mktimegm(struct tm *tm);
 int qemu_fdatasync(int fd);
 int fcntl_setfl(int fd, int flag);
diff --git a/monitor.c b/monitor.c
index 6d0cec5..4484d74 100644
--- a/monitor.c
+++ b/monitor.c
@@ -797,9 +797,7 @@ static int compare_cmd(const char *name, const char *list)
 p = list;
 for(;;) {
 pstart = p;
-p = strchr(p, '|');
-if (!p)
-p = pstart + strlen(pstart);
+p = qemu_strchrnul(p, '|');
 if ((p - pstart) == len && !memcmp(pstart, name, len))
 return 1;
 if (*p == '\0')
@@ -3400,9 +3398,7 @@ static void cmd_completion(Monitor *mon, const char 
*name, const char *list)
 p = list;
 for(;;) {
 pstart = p;
-p = strchr(p, '|');
-if (!p)
-p = pstart + strlen(pstart);
+p = qemu_strchrnul(p, '|');
 len = p - pstart;
 if (len > sizeof(cmd) - 2)
 len = sizeof(cmd) - 2;
diff --git a/util/cutils.c b/util/cutils.c
index 0de69e6..c365ddb 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -545,6 +545,21 @@ int qemu_strtou64(const char *nptr, const char **endptr, 
int base,
 }
 
 /**
+ * Searches for the first occurrence of 'c' in 's', and returns a pointer
+ * to the trailing null byte if none was found.
+ */
+#ifndef CONFIG_STRCHRNUL
+const char *qemu_strchrnul(const char 

Re: [Qemu-devel] [PATCH V8 11/17] qapi: Add new command to query colo status

2018-06-10 Thread Zhang Chen
On Mon, Jun 11, 2018 at 1:42 AM, Zhang Chen  wrote:

>
>
> On Tue, Jun 5, 2018 at 6:23 AM, Eric Blake  wrote:
>
>> On 06/03/2018 12:05 AM, Zhang Chen wrote:
>>
>>> Libvirt or other high level software can use this command query colo
>>> status.
>>> You can test this command like that:
>>> {'execute':'query-colo-status'}
>>>
>>> Signed-off-by: Zhang Chen 
>>> ---
>>>
>>
>> +++ b/qapi/migration.json
>>> @@ -1231,6 +1231,40 @@
>>>   ##
>>>   { 'command': 'xen-colo-do-checkpoint' }
>>>   +##
>>> +# @COLOStatus:
>>> +#
>>> +# The result format for 'query-colo-status'.
>>> +#
>>> +# @mode: COLO running mode. If COLO is running, this field will return
>>> +#'primary' or 'secodary'.
>>>
>>
>> s/secodary/secondary/
>>
>> +#
>>> +# @colo-running: true if COLO is running.
>>> +#
>>> +# @reason: describes the reason for the COLO exit.
>>> +#
>>> +# Since: 2.13
>>>
>>
>> 3.0
>>
>> +##
>>> +{ 'struct': 'COLOStatus',
>>> +  'data': { 'mode': 'COLOMode', 'colo-running': 'bool', 'reason':
>>> 'COLOExitReason' } }
>>> +
>>> +##
>>> +# @query-colo-status:
>>> +#
>>> +# Query COLO status while the vm is running.
>>> +#
>>> +# Returns: A @COLOStatus object showing the status.
>>> +#
>>> +# Example:
>>> +#
>>> +# -> { "execute": "query-colo-status" }
>>> +# <- { "return": { "mode": "primary", "colo-running": true, "reason":
>>> "request" } }
>>> +#
>>> +# Since: 2.13
>>>
>>
>> 3.0
>
>
> Oh, I can't see the new Qemu plan...
>

Typo: Sorry, I just forgot to see the new plan


>
> Thank you for the reminder.
> Zhang Chen
>
>
>
>>
>>
>> +##
>>> +{ 'command': 'query-colo-status',
>>> +  'returns': 'COLOStatus' }
>>> +
>>>   ##
>>>   # @migrate-recover:
>>>   #
>>>
>>>
>> --
>> Eric Blake, Principal Software Engineer
>> Red Hat, Inc.   +1-919-301-3266
>> Virtualization:  qemu.org | libvirt.org
>>
>
>


Re: [Qemu-devel] [PATCH V8 11/17] qapi: Add new command to query colo status

2018-06-10 Thread Zhang Chen
On Tue, Jun 5, 2018 at 6:23 AM, Eric Blake  wrote:

> On 06/03/2018 12:05 AM, Zhang Chen wrote:
>
>> Libvirt or other high level software can use this command query colo
>> status.
>> You can test this command like that:
>> {'execute':'query-colo-status'}
>>
>> Signed-off-by: Zhang Chen 
>> ---
>>
>
> +++ b/qapi/migration.json
>> @@ -1231,6 +1231,40 @@
>>   ##
>>   { 'command': 'xen-colo-do-checkpoint' }
>>   +##
>> +# @COLOStatus:
>> +#
>> +# The result format for 'query-colo-status'.
>> +#
>> +# @mode: COLO running mode. If COLO is running, this field will return
>> +#'primary' or 'secodary'.
>>
>
> s/secodary/secondary/
>
> +#
>> +# @colo-running: true if COLO is running.
>> +#
>> +# @reason: describes the reason for the COLO exit.
>> +#
>> +# Since: 2.13
>>
>
> 3.0
>
> +##
>> +{ 'struct': 'COLOStatus',
>> +  'data': { 'mode': 'COLOMode', 'colo-running': 'bool', 'reason':
>> 'COLOExitReason' } }
>> +
>> +##
>> +# @query-colo-status:
>> +#
>> +# Query COLO status while the vm is running.
>> +#
>> +# Returns: A @COLOStatus object showing the status.
>> +#
>> +# Example:
>> +#
>> +# -> { "execute": "query-colo-status" }
>> +# <- { "return": { "mode": "primary", "colo-running": true, "reason":
>> "request" } }
>> +#
>> +# Since: 2.13
>>
>
> 3.0


Oh, I can't see the new Qemu plan...

Thank you for the reminder.
Zhang Chen



>
>
> +##
>> +{ 'command': 'query-colo-status',
>> +  'returns': 'COLOStatus' }
>> +
>>   ##
>>   # @migrate-recover:
>>   #
>>
>>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org
>


Re: [Qemu-devel] [PATCH V8 11/17] qapi: Add new command to query colo status

2018-06-10 Thread Zhang Chen
On Thu, Jun 7, 2018 at 8:59 PM, Markus Armbruster  wrote:

> Zhang Chen  writes:
>
> > Libvirt or other high level software can use this command query colo
> status.
> > You can test this command like that:
> > {'execute':'query-colo-status'}
> >
> > Signed-off-by: Zhang Chen 
> > ---
> >  migration/colo.c| 39 +++
> >  qapi/migration.json | 34 ++
> >  2 files changed, 73 insertions(+)
> >
> > diff --git a/migration/colo.c b/migration/colo.c
> > index bedb677788..8c6b8e9a4e 100644
> > --- a/migration/colo.c
> > +++ b/migration/colo.c
> > @@ -29,6 +29,7 @@
> >  #include "net/colo.h"
> >  #include "block/block.h"
> >  #include "qapi/qapi-events-migration.h"
> > +#include "qapi/qmp/qerror.h"
> >
> >  static bool vmstate_loading;
> >  static Notifier packets_compare_notifier;
> > @@ -237,6 +238,44 @@ void qmp_xen_colo_do_checkpoint(Error **errp)
> >  #endif
> >  }
> >
> > +COLOStatus *qmp_query_colo_status(Error **errp)
> > +{
> > +int state;
> > +COLOStatus *s = g_new0(COLOStatus, 1);
> > +
> > +s->mode = get_colo_mode();
> > +
> > +switch (s->mode) {
> > +case COLO_MODE_UNKNOWN:
> > +error_setg(errp, "COLO is disabled");
> > +state = MIGRATION_STATUS_NONE;
> > +break;
> > +case COLO_MODE_PRIMARY:
> > +state = migrate_get_current()->state;
> > +break;
> > +case COLO_MODE_SECONDARY:
> > +state = migration_incoming_get_current()->state;
> > +break;
> > +default:
> > +abort();
> > +}
> > +
> > +s->colo_running = state == MIGRATION_STATUS_COLO;
> > +
> > +switch (failover_get_state()) {
> > +case FAILOVER_STATUS_NONE:
> > +s->reason = COLO_EXIT_REASON_NONE;
> > +break;
> > +case FAILOVER_STATUS_REQUIRE:
> > +s->reason = COLO_EXIT_REASON_REQUEST;
> > +break;
> > +default:
> > +s->reason = COLO_EXIT_REASON_ERROR;
> > +}
> > +
> > +return s;
> > +}
> > +
> >  static void colo_send_message(QEMUFile *f, COLOMessage msg,
> >Error **errp)
> >  {
> > diff --git a/qapi/migration.json b/qapi/migration.json
> > index 93136ce5a0..356a370949 100644
> > --- a/qapi/migration.json
> > +++ b/qapi/migration.json
> > @@ -1231,6 +1231,40 @@
> >  ##
> >  { 'command': 'xen-colo-do-checkpoint' }
> >
> > +##
> > +# @COLOStatus:
> > +#
> > +# The result format for 'query-colo-status'.
> > +#
> > +# @mode: COLO running mode. If COLO is running, this field will return
> > +#'primary' or 'secodary'.
> > +#
> > +# @colo-running: true if COLO is running.
> > +#
> > +# @reason: describes the reason for the COLO exit.
>
> What's the value of @reason before a "COLO exit"?
>

Before a "COLO exit", we just return 'none' in this field.

Thanks
Zhang Chen


>
> > +#
> > +# Since: 2.13
> > +##
> > +{ 'struct': 'COLOStatus',
> > +  'data': { 'mode': 'COLOMode', 'colo-running': 'bool', 'reason':
> 'COLOExitReason' } }
> > +
> > +##
> > +# @query-colo-status:
> > +#
> > +# Query COLO status while the vm is running.
> > +#
> > +# Returns: A @COLOStatus object showing the status.
> > +#
> > +# Example:
> > +#
> > +# -> { "execute": "query-colo-status" }
> > +# <- { "return": { "mode": "primary", "colo-running": true, "reason":
> "request" } }
> > +#
> > +# Since: 2.13
> > +##
> > +{ 'command': 'query-colo-status',
> > +  'returns': 'COLOStatus' }
> > +
> >  ##
> >  # @migrate-recover:
> >  #
>


Re: [Qemu-devel] [PATCH V8 10/17] qmp event: Add COLO_EXIT event to notify users while exited COLO

2018-06-10 Thread Zhang Chen
On Thu, Jun 7, 2018 at 8:54 PM, Markus Armbruster  wrote:

> Eric Blake  writes:
>
> > On 06/03/2018 12:05 AM, Zhang Chen wrote:
> >> From: zhanghailiang 
> >>
> >> If some errors happen during VM's COLO FT stage, it's important to
> >> notify the users of this event. Together with 'x-colo-lost-heartbeat',
> >> Users can intervene in COLO's failover work immediately.
> >> If users don't want to get involved in COLO's failover verdict,
> >> it is still necessary to notify users that we exited COLO mode.
> >>
> >> Signed-off-by: zhanghailiang 
> >> Signed-off-by: Li Zhijian 
> >> Signed-off-by: Zhang Chen 
> >> Reviewed-by: Eric Blake 
> >> ---
> >>   migration/colo.c| 31 +++
> >>   qapi/migration.json | 38 ++
> >>   2 files changed, 69 insertions(+)
> >>
> >> diff --git a/migration/colo.c b/migration/colo.c
> >> index c083d3696f..bedb677788 100644
> >> --- a/migration/colo.c
> >
> >>   +/*
> >> + * There are only two reasons we can go here, some error happened.
> >> + * Or the user triggered failover.
> >
> > s/go here/get here/
> > s/happened. Or/happened, or/
> >
> >> +++ b/qapi/migration.json
> >> @@ -880,6 +880,44 @@
> >>   { 'enum': 'FailoverStatus',
> >> 'data': [ 'none', 'require', 'active', 'completed', 'relaunch' ] }
> >> +##
> >> +# @COLO_EXIT:
> >> +#
> >> +# Emitted when VM finishes COLO mode due to some errors happening or
> >> +# at the request of users.
> >> +#
> >> +# @mode: report COLO mode when COLO exited.
> >> +#
> >> +# @reason: describes the reason for the COLO exit.
> >> +#
> >> +# Since: 2.13
> >
> > s/2.13/3.0/
> >
> >> +#
> >> +# Example:
> >> +#
> >> +# <- { "timestamp": {"seconds": 2032141960, "microseconds": 417172},
> >> +#  "event": "COLO_EXIT", "data": {"mode": "primary", "reason":
> "request" } }
> >> +#
> >> +##
> >> +{ 'event': 'COLO_EXIT',
> >> +  'data': {'mode': 'COLOMode', 'reason': 'COLOExitReason' } }
> >> +
> >> +##
> >> +# @COLOExitReason:
> >> +#
> >> +# The reason for a COLO exit
> >> +#
> >> +# @none: no failover has ever happened, This can't occur in the
> COLO_EXIT event,
> >
> > s/happened,/happened./
>
> While there, wrap the line around column 70, please.
>
> >> +# only in the result of query-colo-status.
> >> +#
> >> +# @request: COLO exit is due to an external request
> >> +#
> >> +# @error: COLO exit is due to an internal error
> >> +#
> >> +# Since: 2.13
> >
> > s/2.13/3.0/
> >
> >> +##
> >> +{ 'enum': 'COLOExitReason',
> >> +  'data': [ 'none', 'request', 'error' ] }
> >> +
> >>   ##
> >>   # @x-colo-lost-heartbeat:
> >>   #
> >>
>
> With these touch-ups:
> Reviewed-by: Markus Armbruster 
>


I will fixed the typo and addressed comments in next version.
Thanks Markus and Eric.

Thanks
Zhang Chen


Re: [Qemu-devel] [PATCH V8 15/17] filter-rewriter: handle checkpoint and failover event

2018-06-10 Thread Zhang Chen
On Mon, Jun 4, 2018 at 3:42 PM, Jason Wang  wrote:

>
>
> On 2018年06月03日 13:05, Zhang Chen wrote:
>
>> After one round of checkpoint, the states between PVM and SVM
>> become consistent, so it is unnecessary to adjust the sequence
>> of net packets for old connections, besides, while failover
>> happens, filter-rewriter needs to check if it still needs to
>> adjust sequence of net packets.
>>
>> Signed-off-by: zhanghailiang 
>> Signed-off-by: Zhang Chen 
>> ---
>>   migration/colo.c  | 13 +
>>   net/filter-rewriter.c | 40 
>>   2 files changed, 53 insertions(+)
>>
>> diff --git a/migration/colo.c b/migration/colo.c
>> index 442471e088..0bff21d9e5 100644
>> --- a/migration/colo.c
>> +++ b/migration/colo.c
>> @@ -31,6 +31,7 @@
>>   #include "qapi/qapi-events-migration.h"
>>   #include "qapi/qmp/qerror.h"
>>   #include "sysemu/cpus.h"
>> +#include "net/filter.h"
>> static bool vmstate_loading;
>>   static Notifier packets_compare_notifier;
>> @@ -82,6 +83,11 @@ static void secondary_vm_do_failover(void)
>>   if (local_err) {
>>   error_report_err(local_err);
>>   }
>> +/* Notify all filters of all NIC to do checkpoint */
>> +colo_notify_filters_event(COLO_EVENT_FAILOVER, _err);
>> +if (local_err) {
>> +error_report_err(local_err);
>> +}
>> if (!autostart) {
>>   error_report("\"-S\" qemu option will be ignored in secondary
>> side");
>> @@ -800,6 +806,13 @@ void *colo_process_incoming_thread(void *opaque)
>>   goto out;
>>   }
>>   +/* Notify all filters of all NIC to do checkpoint */
>> +colo_notify_filters_event(COLO_EVENT_CHECKPOINT, _err);
>> +if (local_err) {
>> +qemu_mutex_unlock_iothread();
>> +goto out;
>> +}
>> +
>>
>
> I think the above should belong to another patch.
>
>
>
Yes, I will relocate above code.



>   vmstate_loading = false;
>>   vm_start();
>>   trace_colo_vm_state_change("stop", "run");
>> diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
>> index 0909a9a8af..f3c306cc89 100644
>> --- a/net/filter-rewriter.c
>> +++ b/net/filter-rewriter.c
>> @@ -20,6 +20,8 @@
>>   #include "qemu/main-loop.h"
>>   #include "qemu/iov.h"
>>   #include "net/checksum.h"
>> +#include "net/colo.h"
>> +#include "migration/colo.h"
>> #define FILTER_COLO_REWRITER(obj) \
>>   OBJECT_CHECK(RewriterState, (obj), TYPE_FILTER_REWRITER)
>> @@ -277,6 +279,43 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState
>> *nf,
>>   return 0;
>>   }
>>   +static void reset_seq_offset(gpointer key, gpointer value, gpointer
>> user_data)
>> +{
>> +Connection *conn = (Connection *)value;
>> +
>> +conn->offset = 0;
>> +}
>> +
>> +static gboolean offset_is_nonzero(gpointer key,
>> +  gpointer value,
>> +  gpointer user_data)
>> +{
>> +Connection *conn = (Connection *)value;
>> +
>> +return conn->offset ? true : false;
>> +}
>> +
>> +static void colo_rewriter_handle_event(NetFilterState *nf, int event,
>> +   Error **errp)
>> +{
>> +RewriterState *rs = FILTER_COLO_REWRITER(nf);
>> +
>> +switch (event) {
>> +case COLO_EVENT_CHECKPOINT:
>> +g_hash_table_foreach(rs->connection_track_table,
>> +reset_seq_offset, NULL);
>> +break;
>> +case COLO_EVENT_FAILOVER:
>> +if (!g_hash_table_find(rs->connection_track_table,
>> +  offset_is_nonzero, NULL)) {
>> +object_property_set_str(OBJECT(nf), "off", "status", errp);
>> +}
>>
>
> I may miss something but I think rewriter should not be turned off even
> after failover?
>
>
Yes, after failover, rewriter should maintain the connection that created
before failover and turned off for other connections.
I will fix it in next version.
Very thanks your comments Jason~~~


Thanks
Zhang Chen




> Thanks
>
>
> +break;
>> +default:
>> +break;
>> +}
>> +}
>> +
>>   static void colo_rewriter_cleanup(NetFilterState *nf)
>>   {
>>   RewriterState *s = FILTER_COLO_REWRITER(nf);
>> @@ -332,6 +371,7 @@ static void colo_rewriter_class_init(ObjectClass
>> *oc, void *data)
>>   nfc->setup = colo_rewriter_setup;
>>   nfc->cleanup = colo_rewriter_cleanup;
>>   nfc->receive_iov = colo_rewriter_receive_iov;
>> +nfc->handle_event = colo_rewriter_handle_event;
>>   }
>> static const TypeInfo colo_rewriter_info = {
>>
>
>


Re: [Qemu-devel] [PATCH v2 001/108] linux-user: Remove DEBUG

2018-06-10 Thread Philippe Mathieu-Daudé
On 06/10/2018 12:00 AM, Richard Henderson wrote:
> This is redundant with both -strace and actual tracing.
> 
> Signed-off-by: Richard Henderson 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
>  linux-user/syscall.c | 10 --
>  1 file changed, 10 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 7b9ac3b408..c212149245 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -163,7 +163,6 @@
>   * (The one remaining unallocated bit is 0x1000 which used to be CLONE_PID.)
>   */
>  
> -//#define DEBUG
>  /* Define DEBUG_ERESTARTSYS to force every syscall to be restarted
>   * once. This exercises the codepaths for restart.
>   */
> @@ -5777,9 +5776,6 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
>  ie++;
>  }
>  arg_type = ie->arg_type;
> -#if defined(DEBUG)
> -gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name);
> -#endif
>  if (ie->do_ioctl) {
>  return ie->do_ioctl(ie, buf_temp, fd, cmd, arg);
>  } else if (!ie->host_cmd) {
> @@ -7980,9 +7976,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  }
>  #endif
>  
> -#ifdef DEBUG
> -gemu_log("syscall %d", num);
> -#endif
>  trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 
> arg7, arg8);
>  if(do_strace)
>  print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
> @@ -12772,9 +12765,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  break;
>  }
>  fail:
> -#ifdef DEBUG
> -gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
> -#endif
>  if(do_strace)
>  print_syscall_ret(num, ret);
>  trace_guest_user_syscall_ret(cpu, num, ret);
> 



[Qemu-devel] [RFC] target/arm: add ARMv6-M UNDEFINED 32-bit instruction test

2018-06-10 Thread Stefan Hajnoczi
Test that 32-bit instructions declared UNDEFINED in the ARMv6-M
Reference Manual really do raise an exception.

The Intel HEX (.hex) file is included to save people the trouble of
installing a cross-compiler toolchain.

To run the test (make sure qemu-system-arm is in your $PATH):

  $ cd tests/tcg/arm
  $ make run-test-armv6m-undef

Signed-off-by: Stefan Hajnoczi 
Based-on: http://github.com/stefanha/qemu/commits/microbit
---
Hi Julia,
Several instructions are currently not raising an exception.  I have
commented them out with "FAIL".  Maybe your 32-bit instruction work will
fix them.  Otherwise they require additional investigation.

Hi Peter and Alex,
Is this along the lines you were thinking of when we discussed this type
of test on IRC?

 tests/tcg/arm/Makefile  |  21 +
 tests/tcg/arm/test-armv6m-undef.S   | 119 
 tests/tcg/arm/test-armv6m-undef.hex |  17 
 tests/tcg/arm/test-armv6m-undef.ld  |  21 +
 4 files changed, 178 insertions(+)
 create mode 100644 tests/tcg/arm/Makefile
 create mode 100644 tests/tcg/arm/test-armv6m-undef.S
 create mode 100644 tests/tcg/arm/test-armv6m-undef.hex
 create mode 100644 tests/tcg/arm/test-armv6m-undef.ld

diff --git a/tests/tcg/arm/Makefile b/tests/tcg/arm/Makefile
new file mode 100644
index 00..c43049ca10
--- /dev/null
+++ b/tests/tcg/arm/Makefile
@@ -0,0 +1,21 @@
+CC = arm-linux-gnu-gcc
+OBJCOPY = arm-linux-gnu-objcopy
+
+SOURCES = $(wildcard *.S)
+BINARIES = $(patsubst %.S,%.hex,$(SOURCES))
+
+.PHONY: clean
+
+all: $(BINARIES)
+
+clean:
+   rm -f $(BINARIES) *.o
+
+%.o: %.S %.ld
+   $(CC) -nostdlib -Wl,--build-id=none -x assembler-with-cpp -T $(patsubst 
%.S,%.ld,$<) -x assembler-with-cpp -o $@ $<
+
+%.hex: %.o
+   $(OBJCOPY) -O ihex $< $@
+
+run-test-armv6m-undef: test-armv6m-undef.hex
+   qemu-system-arm -semihosting -M microbit -kernel $<
diff --git a/tests/tcg/arm/test-armv6m-undef.S 
b/tests/tcg/arm/test-armv6m-undef.S
new file mode 100644
index 00..d16ce0326a
--- /dev/null
+++ b/tests/tcg/arm/test-armv6m-undef.S
@@ -0,0 +1,119 @@
+/*
+ * Test ARMv6-M UNDEFINED 32-bit instructions
+ *
+ * Copyright 2018 Red Hat Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2
+ * or later. See the COPYING file in the top-level directory.
+ */
+
+/*
+ * Test that UNDEFINED 32-bit instructions fault as expected.  This is an
+ * interesting test because ARMv6-M shares code with its more fully-featured
+ * siblings and it's necessary to verify that its limited instruction set is
+ * emulated correctly.
+ *
+ * The emulator must be invoked with -semihosting so that the test case can
+ * terminate with exit code 0 on success or 1 on failure.
+ *
+ * Failures can be debugged with -d in_asm,int,exec,cpu and the
+ * gdbstub (-S -s).
+ */
+
+.syntax unified
+.cpu cortex-m0
+.thumb
+
+/*
+ * Memory map
+ */
+#define SRAM_BASE 0x2000
+#define SRAM_SIZE (16 * 1024)
+
+/*
+ * Semihosting interface on ARM T32
+ * See "Semihosting for AArch32 and AArch64 Version 2.0 Documentation" by ARM
+ */
+#define semihosting_call bkpt 0xab
+#define SYS_EXIT 0x18
+
+vector_table:
+.word SRAM_BASE + SRAM_SIZE /* 0. SP_main */
+.word exc_reset_thumb   /* 1. Reset */
+.word 0 /* 2. NMI */
+.word exc_hard_fault_thumb  /* 3. HardFault */
+.rept 7
+.word 0 /* 4-10. Reserved */
+.endr
+.word 0 /* 11. SVCall */
+.word 0 /* 12. Reserved */
+.word 0 /* 13. Reserved */
+.word 0 /* 14. PendSV */
+.word 0 /* 15. SysTick */
+.rept 32
+.word 0 /* 16-47. External Interrupts */
+.endr
+
+exc_reset:
+.equ exc_reset_thumb, exc_reset + 1
+.global exc_reset_thumb
+/* The following 32-bit UNDEFINED instructions are tested by executing
+ * them.  The HardFault exception handler should execute and return to
+ * the next test case.  If no exception is raised the test fails.
+ */
+
+/* Table A5-9 32-bit Thumb encoding */
+/* FAIL disas_thumb_insn() case 14 is missing UNDEF for BL/BLX!
+.short 0b11101000
+.short 0b
+b not_reached */
+/* FAIL.short 0b11101000
+.short 0b1000
+b not_reached */
+/* FAIL .short 0b1000
+.short 0b
+b not_reached */
+/* FAIL.short 0b1000
+.short 0b1000
+b not_reached */
+.short 0b
+.short 0b
+b not_reached
+
+/* Table A5-10 Branch and miscellaneous control instructions */
+.short 0b0111
+.short 0b1010
+b not_reached
+
+/* Success! */
+movs r0, 1
+b exit
+
+not_reached: /* Failure :( */
+movs r0, 0
+b exit
+
+/* When a HardFault occurs, return to pc+6 (test cases are 3 halfwords long) */
+exc_hard_fault:
+.equ 

Re: [Qemu-devel] [PATCH V8 14/17] filter: Add handle_event method for NetFilterClass

2018-06-10 Thread Zhang Chen
On Mon, Jun 4, 2018 at 2:57 PM, Jason Wang  wrote:

>
>
> On 2018年06月03日 13:05, Zhang Chen wrote:
>
>> Filter needs to process the event of checkpoint/failover or
>> other event passed by COLO frame.
>>
>> Signed-off-by: zhanghailiang 
>> ---
>>   include/net/filter.h |  5 +
>>   net/filter.c | 17 +
>>   net/net.c| 28 
>>   3 files changed, 50 insertions(+)
>>
>> diff --git a/include/net/filter.h b/include/net/filter.h
>> index 435acd6f82..49da666ac0 100644
>> --- a/include/net/filter.h
>> +++ b/include/net/filter.h
>> @@ -38,6 +38,8 @@ typedef ssize_t (FilterReceiveIOV)(NetFilterState *nc,
>> typedef void (FilterStatusChanged) (NetFilterState *nf, Error **errp);
>>   +typedef void (FilterHandleEvent) (NetFilterState *nf, int event, Error
>> **errp);
>> +
>>   typedef struct NetFilterClass {
>>   ObjectClass parent_class;
>>   @@ -45,6 +47,7 @@ typedef struct NetFilterClass {
>>   FilterSetup *setup;
>>   FilterCleanup *cleanup;
>>   FilterStatusChanged *status_changed;
>> +FilterHandleEvent *handle_event;
>>   /* mandatory */
>>   FilterReceiveIOV *receive_iov;
>>   } NetFilterClass;
>> @@ -77,4 +80,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState
>> *sender,
>>   int iovcnt,
>>   void *opaque);
>>   +void colo_notify_filters_event(int event, Error **errp);
>> +
>>   #endif /* QEMU_NET_FILTER_H */
>> diff --git a/net/filter.c b/net/filter.c
>> index 2fd7d7d663..0f17eba143 100644
>> --- a/net/filter.c
>> +++ b/net/filter.c
>> @@ -17,6 +17,8 @@
>>   #include "net/vhost_net.h"
>>   #include "qom/object_interfaces.h"
>>   #include "qemu/iov.h"
>> +#include "net/colo.h"
>> +#include "migration/colo.h"
>> static inline bool qemu_can_skip_netfilter(NetFilterState *nf)
>>   {
>> @@ -245,11 +247,26 @@ static void netfilter_finalize(Object *obj)
>>   g_free(nf->netdev_id);
>>   }
>>   +static void dummy_handle_event(NetFilterState *nf, int event, Error
>> **errp)
>> +{
>> +switch (event) {
>> +case COLO_EVENT_CHECKPOINT:
>> +break;
>> +case COLO_EVENT_FAILOVER:
>> +object_property_set_str(OBJECT(nf), "off", "status", errp);
>> +break;
>> +default:
>> +break;
>> +}
>> +}
>> +
>>   static void netfilter_class_init(ObjectClass *oc, void *data)
>>   {
>>   UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
>> +NetFilterClass *nfc = NETFILTER_CLASS(oc);
>> ucc->complete = netfilter_complete;
>> +nfc->handle_event = dummy_handle_event;
>>   }
>> static const TypeInfo netfilter_info = {
>> diff --git a/net/net.c b/net/net.c
>> index efb9eaf779..378cd2f9ec 100644
>> --- a/net/net.c
>> +++ b/net/net.c
>> @@ -1329,6 +1329,34 @@ void hmp_info_network(Monitor *mon, const QDict
>> *qdict)
>>   }
>>   }
>>   +void colo_notify_filters_event(int event, Error **errp)
>> +{
>> +NetClientState *nc, *peer;
>> +NetClientDriver type;
>> +NetFilterState *nf;
>> +NetFilterClass *nfc = NULL;
>> +Error *local_err = NULL;
>> +
>> +QTAILQ_FOREACH(nc, _clients, next) {
>> +peer = nc->peer;
>> +type = nc->info->type;
>> +if (!peer || type != NET_CLIENT_DRIVER_TAP) {
>> +continue;
>>
>
> I think when COLO is enabled, qemu should reject all other types of
> backends.


Yes, you are right.
May be we should add a assert here? Because we can not get backend info when
colo-compare start up.
Have any idea?


>
>
> +}
>> +QTAILQ_FOREACH(nf, >filters, next) {
>> +nfc =  NETFILTER_GET_CLASS(OBJECT(nf));
>> +if (!nfc->handle_event) {
>> +continue;
>> +}
>>
>
> Is this still necessary?
>
>
Yes, may be user will use other filter(like filter-buffer) with COLO at
same time.

Thanks
Zhang Chen



> Thanks
>
>
> +nfc->handle_event(nf, event, _err);
>> +if (local_err) {
>> +error_propagate(errp, local_err);
>> +return;
>> +}
>> +}
>> +}
>> +}
>> +
>>   void qmp_set_link(const char *name, bool up, Error **errp)
>>   {
>>   NetClientState *ncs[MAX_QUEUE_NUM];
>>
>
>


Re: [Qemu-devel] [PATCH V8 03/17] colo-compare: use notifier to notify packets comparing result

2018-06-10 Thread Zhang Chen
On Mon, Jun 4, 2018 at 2:36 PM, Jason Wang  wrote:

>
>
> On 2018年06月03日 13:05, Zhang Chen wrote:
>
>> It's a good idea to use notifier to notify COLO frame of
>> inconsistent packets comparing.
>>
>> Signed-off-by: Zhang Chen 
>> Signed-off-by: zhanghailiang 
>> ---
>>   net/colo-compare.c | 32 +---
>>   net/colo-compare.h |  2 ++
>>   2 files changed, 27 insertions(+), 7 deletions(-)
>>
>> diff --git a/net/colo-compare.c b/net/colo-compare.c
>> index 7ff3ae8904..05061cd1c4 100644
>> --- a/net/colo-compare.c
>> +++ b/net/colo-compare.c
>> @@ -29,6 +29,7 @@
>>   #include "sysemu/iothread.h"
>>   #include "net/colo-compare.h"
>>   #include "migration/colo.h"
>> +#include "migration/migration.h"
>> #define TYPE_COLO_COMPARE "colo-compare"
>>   #define COLO_COMPARE(obj) \
>> @@ -37,6 +38,9 @@
>>   static QTAILQ_HEAD(, CompareState) net_compares =
>>  QTAILQ_HEAD_INITIALIZER(net_compares);
>>   +static NotifierList colo_compare_notifiers =
>> +NOTIFIER_LIST_INITIALIZER(colo_compare_notifiers);
>> +
>>   #define COMPARE_READ_LEN_MAX NET_BUFSIZE
>>   #define MAX_QUEUE_SIZE 1024
>>   @@ -561,8 +565,24 @@ static int colo_old_packet_check_one(Packet *pkt,
>> int64_t *check_time)
>>   }
>>   }
>>   +static void colo_compare_inconsistent_notify(void)
>> +{
>>
>
> Not good at English but inconsistency sounds better here.
>
>
Sorry, I'm not good at English too...
I will change to "inconsistency" in next version.

Thanks
Zhang Chen


> Thanks
>
>
> +notifier_list_notify(_compare_notifiers,
>> +migrate_get_current());
>> +}
>> +
>> +void colo_compare_register_notifier(Notifier *notify)
>> +{
>> +notifier_list_add(_compare_notifiers, notify);
>> +}
>> +
>> +void colo_compare_unregister_notifier(Notifier *notify)
>> +{
>> +notifier_remove(notify);
>> +}
>> +
>>   static int colo_old_packet_check_one_conn(Connection *conn,
>> -  void *user_data)
>> +   void *user_data)
>>   {
>>   GList *result = NULL;
>>   int64_t check_time = REGULAR_PACKET_CHECK_MS;
>> @@ -573,10 +593,7 @@ static int colo_old_packet_check_one_conn(Connection
>> *conn,
>> if (result) {
>>   /* Do checkpoint will flush old packet */
>> -/*
>> - * TODO: Notify colo frame to do checkpoint.
>> - * colo_compare_inconsistent_notify();
>> - */
>> +colo_compare_inconsistent_notify();
>>   return 0;
>>   }
>>   @@ -620,11 +637,12 @@ static void colo_compare_packet(CompareState *s,
>> Connection *conn,
>>   /*
>>* If one packet arrive late, the secondary_list or
>>* primary_list will be empty, so we can't compare it
>> - * until next comparison.
>> + * until next comparison. If the packets in the list are
>> + * timeout, it will trigger a checkpoint request.
>>*/
>>   trace_colo_compare_main("packet different");
>>   g_queue_push_head(>primary_list, pkt);
>> -/* TODO: colo_notify_checkpoint();*/
>> +colo_compare_inconsistent_notify();
>>   break;
>>   }
>>   }
>> diff --git a/net/colo-compare.h b/net/colo-compare.h
>> index 1b1ce76aea..22ddd512e2 100644
>> --- a/net/colo-compare.h
>> +++ b/net/colo-compare.h
>> @@ -18,5 +18,7 @@
>>   #define QEMU_COLO_COMPARE_H
>> void colo_notify_compares_event(void *opaque, int event, Error
>> **errp);
>> +void colo_compare_register_notifier(Notifier *notify);
>> +void colo_compare_unregister_notifier(Notifier *notify);
>> #endif /* QEMU_COLO_COMPARE_H */
>>
>
>


Re: [Qemu-devel] [PATCH V8 02/17] colo-compare: implement the process of checkpoint

2018-06-10 Thread Zhang Chen
On Mon, Jun 4, 2018 at 2:31 PM, Jason Wang  wrote:

>
>
> On 2018年06月03日 13:05, Zhang Chen wrote:
>
>> While do checkpoint, we need to flush all the unhandled packets,
>> By using the filter notifier mechanism, we can easily to notify
>> every compare object to do this process, which runs inside
>> of compare threads as a coroutine.
>>
>> Signed-off-by: zhanghailiang 
>> Signed-off-by: Zhang Chen 
>> ---
>>   include/migration/colo.h |  6 
>>   net/colo-compare.c   | 76 
>>   net/colo-compare.h   | 22 
>>   3 files changed, 104 insertions(+)
>>   create mode 100644 net/colo-compare.h
>>
>> diff --git a/include/migration/colo.h b/include/migration/colo.h
>> index 2fe48ad353..fefb2fcf4c 100644
>> --- a/include/migration/colo.h
>> +++ b/include/migration/colo.h
>> @@ -16,6 +16,12 @@
>>   #include "qemu-common.h"
>>   #include "qapi/qapi-types-migration.h"
>>   +enum colo_event {
>> +COLO_EVENT_NONE,
>> +COLO_EVENT_CHECKPOINT,
>> +COLO_EVENT_FAILOVER,
>> +};
>> +
>>   void colo_info_init(void);
>> void migrate_start_colo_process(MigrationState *s);
>> diff --git a/net/colo-compare.c b/net/colo-compare.c
>> index 23b2d2c4cc..7ff3ae8904 100644
>> --- a/net/colo-compare.c
>> +++ b/net/colo-compare.c
>> @@ -27,11 +27,16 @@
>>   #include "qemu/sockets.h"
>>   #include "net/colo.h"
>>   #include "sysemu/iothread.h"
>> +#include "net/colo-compare.h"
>> +#include "migration/colo.h"
>> #define TYPE_COLO_COMPARE "colo-compare"
>>   #define COLO_COMPARE(obj) \
>>   OBJECT_CHECK(CompareState, (obj), TYPE_COLO_COMPARE)
>>   +static QTAILQ_HEAD(, CompareState) net_compares =
>> +   QTAILQ_HEAD_INITIALIZER(net_compares);
>> +
>>   #define COMPARE_READ_LEN_MAX NET_BUFSIZE
>>   #define MAX_QUEUE_SIZE 1024
>>   @@ -41,6 +46,10 @@
>>   /* TODO: Should be configurable */
>>   #define REGULAR_PACKET_CHECK_MS 3000
>>   +static QemuMutex event_mtx;
>> +static QemuCond event_complete_cond;
>> +static int event_unhandled_count;
>> +
>>   /*
>>*  + CompareState ++
>>*  |   |
>> @@ -87,6 +96,11 @@ typedef struct CompareState {
>>   IOThread *iothread;
>>   GMainContext *worker_context;
>>   QEMUTimer *packet_check_timer;
>> +
>> +QEMUBH *event_bh;
>> +enum colo_event event;
>> +
>> +QTAILQ_ENTRY(CompareState) next;
>>   } CompareState;
>> typedef struct CompareClass {
>> @@ -736,6 +750,25 @@ static void check_old_packet_regular(void *opaque)
>>   REGULAR_PACKET_CHECK_MS);
>>   }
>>   +/* Public API, Used for COLO frame to notify compare event */
>> +void colo_notify_compares_event(void *opaque, int event, Error **errp)
>> +{
>> +CompareState *s;
>> +
>> +qemu_mutex_lock(_mtx);
>> +QTAILQ_FOREACH(s, _compares, next) {
>> +s->event = event;
>> +qemu_bh_schedule(s->event_bh);
>> +event_unhandled_count++;
>> +}
>> +/* Wait all compare threads to finish handling this event */
>> +while (event_unhandled_count > 0) {
>> +qemu_cond_wait(_complete_cond, _mtx);
>> +}
>> +
>> +qemu_mutex_unlock(_mtx);
>> +}
>> +
>>   static void colo_compare_timer_init(CompareState *s)
>>   {
>>   AioContext *ctx = iothread_get_aio_context(s->iothread);
>> @@ -756,6 +789,28 @@ static void colo_compare_timer_del(CompareState *s)
>>   }
>>}
>>   +static void colo_flush_packets(void *opaque, void *user_data);
>> +
>> +static void colo_compare_handle_event(void *opaque)
>> +{
>> +CompareState *s = opaque;
>> +
>> +switch (s->event) {
>> +case COLO_EVENT_CHECKPOINT:
>> +g_queue_foreach(>conn_list, colo_flush_packets, s);
>> +break;
>> +case COLO_EVENT_FAILOVER:
>> +break;
>> +default:
>> +break;
>> +}
>> +qemu_mutex_lock(_mtx);
>>
>
> Isn't this a deadlock? Since colo_notify_compares_event() won't release
> event_mtx until event_unhandled_count reaches zero.
>
>
Good catch!
I will fix it in next version.


>
> +assert(event_unhandled_count > 0);
>> +event_unhandled_count--;
>> +qemu_cond_broadcast(_complete_cond);
>> +qemu_mutex_unlock(_mtx);
>> +}
>> +
>>   static void colo_compare_iothread(CompareState *s)
>>   {
>>   object_ref(OBJECT(s->iothread));
>> @@ -769,6 +824,7 @@ static void colo_compare_iothread(CompareState *s)
>>s, s->worker_context, true);
>> colo_compare_timer_init(s);
>> +s->event_bh = qemu_bh_new(colo_compare_handle_event, s);
>>   }
>> static char *compare_get_pri_indev(Object *obj, Error **errp)
>> @@ -926,8 +982,13 @@ static void colo_compare_complete(UserCreatable
>> *uc, Error **errp)
>>   net_socket_rs_init(>pri_rs, compare_pri_rs_finalize,
>> s->vnet_hdr);
>>   net_socket_rs_init(>sec_rs, compare_sec_rs_finalize,
>> s->vnet_hdr);
>>   +QTAILQ_INSERT_TAIL(_compares, s, next);
>> +
>>   g_queue_init(>conn_list);
>>   +qemu_mutex_init(_mtx);
>> +

Re: [Qemu-devel] [PATCH V8 01/17] filter-rewriter: fix memory leak for connection in connection_track_table

2018-06-10 Thread Zhang Chen
On Mon, Jun 4, 2018 at 1:51 PM, Jason Wang  wrote:

>
>
> On 2018年06月03日 13:05, Zhang Chen wrote:
>
>> After a net connection is closed, we didn't clear its releated resources
>> in connection_track_table, which will lead to memory leak.
>>
>> Let't track the state of net connection, if it is closed, its related
>> resources will be cleared up.
>>
>> Signed-off-by: zhanghailiang 
>> Signed-off-by: Zhang Chen 
>> ---
>>   net/colo.h|  4 +++
>>   net/filter-rewriter.c | 69 ++-
>>   2 files changed, 66 insertions(+), 7 deletions(-)
>>
>> diff --git a/net/colo.h b/net/colo.h
>> index da6c36dcf7..cd118510c5 100644
>> --- a/net/colo.h
>> +++ b/net/colo.h
>> @@ -18,6 +18,7 @@
>>   #include "slirp/slirp.h"
>>   #include "qemu/jhash.h"
>>   #include "qemu/timer.h"
>> +#include "slirp/tcp.h"
>> #define HASHTABLE_MAX_SIZE 16384
>>   @@ -86,6 +87,9 @@ typedef struct Connection {
>>* run once in independent tcp connection
>>*/
>>   int syn_flag;
>> +
>> +int tcp_state; /* TCP FSM state */
>> +tcp_seq fin_ack_seq; /* the seq of 'fin=1,ack=1' */
>>
>
> So the question is, the state machine is not complete. I suspect there
> will be corner cases that will be left because of lacking sufficient
> states. LAST_ACK happens only for passive close. How about active close?
>
> So I think we need either maintain a full state machine or not instead of
> a partial one. We don't want endless bugs.
>

OK, I got it.
I will add a full state machine here in next version.

Thanks
Zhang Chen


>
> Thanks
>
>
>   } Connection;
>> uint32_t connection_key_hash(const void *opaque);
>> diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
>> index 62dad2d773..0909a9a8af 100644
>> --- a/net/filter-rewriter.c
>> +++ b/net/filter-rewriter.c
>> @@ -59,9 +59,9 @@ static int is_tcp_packet(Packet *pkt)
>>   }
>> /* handle tcp packet from primary guest */
>> -static int handle_primary_tcp_pkt(NetFilterState *nf,
>> +static int handle_primary_tcp_pkt(RewriterState *rf,
>> Connection *conn,
>> -  Packet *pkt)
>> +  Packet *pkt, ConnectionKey *key)
>>   {
>>   struct tcphdr *tcp_pkt;
>>   @@ -99,15 +99,44 @@ static int handle_primary_tcp_pkt(NetFilterState
>> *nf,
>>   net_checksum_calculate((uint8_t *)pkt->data +
>> pkt->vnet_hdr_len,
>>  pkt->size - pkt->vnet_hdr_len);
>>   }
>> +/*
>> + * Case 1:
>> + * The *server* side of this connect is VM, *client* tries to
>> close
>> + * the connection.
>> + *
>> + * We got 'ack=1' packets from client side, it acks 'fin=1,
>> ack=1'
>> + * packet from server side. From this point, we can ensure that
>> there
>> + * will be no packets in the connection, except that, some errors
>> + * happen between the path of 'filter object' and vNIC, if this
>> rare
>> + * case really happen, we can still create a new connection,
>> + * So it is safe to remove the connection from
>> connection_track_table.
>> + *
>> + */
>> +if ((conn->tcp_state == TCPS_LAST_ACK) &&
>> +(ntohl(tcp_pkt->th_ack) == (conn->fin_ack_seq + 1))) {
>> +g_hash_table_remove(rf->connection_track_table, key);
>> +}
>> +}
>> +/*
>> + * Case 2:
>> + * The *server* side of this connect is VM, *server* tries to close
>> + * the connection.
>> + *
>> + * We got 'fin=1, ack=1' packet from client side, we need to
>> + * record the seq of 'fin=1, ack=1' packet.
>> + */
>> +if ((tcp_pkt->th_flags & (TH_ACK | TH_FIN)) == (TH_ACK | TH_FIN)) {
>> +conn->fin_ack_seq = htonl(tcp_pkt->th_seq);
>> +conn->tcp_state = TCPS_LAST_ACK;
>>   }
>> return 0;
>>   }
>> /* handle tcp packet from secondary guest */
>> -static int handle_secondary_tcp_pkt(NetFilterState *nf,
>> +static int handle_secondary_tcp_pkt(RewriterState *rf,
>>   Connection *conn,
>> -Packet *pkt)
>> +Packet *pkt, ConnectionKey *key)
>>   {
>>   struct tcphdr *tcp_pkt;
>>   @@ -139,8 +168,34 @@ static int handle_secondary_tcp_pkt(NetFilterState
>> *nf,
>>   net_checksum_calculate((uint8_t *)pkt->data +
>> pkt->vnet_hdr_len,
>>  pkt->size - pkt->vnet_hdr_len);
>>   }
>> +/*
>> + * Case 2:
>> + * The *server* side of this connect is VM, *server* tries to
>> close
>> + * the connection.
>> + *
>> + * We got 'ack=1' packets from server side, it acks 'fin=1,
>> ack=1'
>> + * packet from client side. Like Case 1, there should be no
>> packets
>> + * in the connection from now know, But the difference here is
>> + 

[Qemu-devel] [PATCH] hw/s390x/ipl: Fix crash that occurs when -kernel is used with small images

2018-06-10 Thread Thomas Huth
Add a sanity check to fix the following crash:

$ echo "Insane in the mainframe" > /tmp/test.txt
$ s390x-softmmu/qemu-system-s390x -nographic -kernel /tmp/test.txt
Segmentation fault (core dumped)

Signed-off-by: Thomas Huth 
---
 hw/s390x/ipl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
index 04245b5..9bb9b50 100644
--- a/hw/s390x/ipl.c
+++ b/hw/s390x/ipl.c
@@ -168,7 +168,8 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
  * we can not rely on the ELF entry point - it was 0x800 (the SALIPL
  * loader) and it won't work. For this case we force it to 0x1, 
too.
  */
-if (pentry == KERN_IMAGE_START || pentry == 0x800) {
+if ((pentry == KERN_IMAGE_START || pentry == 0x800) &&
+kernel_size > KERN_PARM_AREA + strlen(ipl->cmdline)) {
 ipl->start_addr = KERN_IMAGE_START;
 /* Overwrite parameters in the kernel image, which are "rom" */
 strcpy(rom_ptr(KERN_PARM_AREA), ipl->cmdline);
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v2 009/108] linux-user: Set up infrastructure for table-izing syscalls

2018-06-10 Thread Peter Maydell
On 10 June 2018 at 13:32, Peter Maydell  wrote:
> On 10 June 2018 at 04:00, Richard Henderson
>  wrote:
>> At the same time, split out set_robust_list and get_robust_list.
>> Put them together, along with their block comment, at the top
>> of syscall_table.
>>
>> Signed-off-by: Richard Henderson 

>> +/* For a given syscall number, return a function implementing it.
>> + * Do this via switch statement instead of table because some targets
>> + * do not begin at 0 and others have a large split in the middle of
>> + * the numbers.  The compiler should be able to produce a dense table.
>> + */

> I was expecting this to be a table lookup, something like
>return syscalls[num].impl;
>
> where the other entries in the syscalls[num] structs would be
> for instance the strace data we currently have in strace.list.

Ah, I see the comment covers this. I'd still rather we had all
the information related to a syscall in one place, though -- this
way we end up with the ifdefs and so on which determine whether
a syscall is implemented having to be duplicated:
 (a) in the implementation
 (b) in this switch code
 (c) in the handling of strace
It would be cleaner to have a single
#if something
static foo_impl(..) { ... }
static syscall_impl foo = {
.name = "foo",
.impl = foo_impl,
.strace_stuff = ...,
};
register_syscall(foo);
#endif

Hash table?

thanks
-- PMM



Re: [Qemu-devel] [PATCH v2 000/108] linux-user: Split do_syscall

2018-06-10 Thread Peter Maydell
On 10 June 2018 at 04:00, Richard Henderson
 wrote:
> * Changed the table into a switch, for the reason documented.
>   Use macros to actually enter the syscall into the switch.
> * Finish the split.
> * Fix some bugs along the way.
>
> I know it's a huge patch set, but I guess it was always going
> to be in order to finish -- it was a stupidly large function.

It's still a stupidly large source file -- is it worth taking
advantage of the split into multiple implementation functions
to break it up into multiple source files? (We could group
related syscalls together.)

thanks
-- PMM



Re: [Qemu-devel] [PATCH v2 009/108] linux-user: Set up infrastructure for table-izing syscalls

2018-06-10 Thread Peter Maydell
On 10 June 2018 at 04:00, Richard Henderson
 wrote:
> At the same time, split out set_robust_list and get_robust_list.
> Put them together, along with their block comment, at the top
> of syscall_table.
>
> Signed-off-by: Richard Henderson 
> ---
>  linux-user/syscall.c | 87 +---
>  1 file changed, 66 insertions(+), 21 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 46f123ee13..8678e749ee 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7947,6 +7947,17 @@ static int host_to_target_cpu_mask(const unsigned long 
> *host_mask,
>  return 0;
>  }
>
> +typedef abi_long impl_fn(void *cpu_env, unsigned num, abi_long arg1,
> + abi_long arg2, abi_long arg3, abi_long arg4,
> + abi_long arg5, abi_long arg6, abi_long arg7,
> + abi_long arg8);
> +
> +#define IMPL(NAME) \
> +static abi_long impl_##NAME(void *cpu_env, unsigned num, abi_long arg1,   \
> +abi_long arg2, abi_long arg3, abi_long arg4,  \
> +abi_long arg5, abi_long arg6, abi_long arg7,  \
> +abi_long arg8)
> +
>  /* This is an internal helper for do_syscall so that it is easier
>   * to have a single return point, so that actions, such as logging
>   * of syscall results, can be performed.
> @@ -11740,23 +11751,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned 
> num, abi_long arg1,
>  return get_errno(safe_tgkill((int)arg1, (int)arg2,
>   target_to_host_signal(arg3)));
>
> -#ifdef TARGET_NR_set_robust_list
> -case TARGET_NR_set_robust_list:
> -case TARGET_NR_get_robust_list:
> -/* The ABI for supporting robust futexes has userspace pass
> - * the kernel a pointer to a linked list which is updated by
> - * userspace after the syscall; the list is walked by the kernel
> - * when the thread exits. Since the linked list in QEMU guest
> - * memory isn't a valid linked list for the host and we have
> - * no way to reliably intercept the thread-death event, we can't
> - * support these. Silently return ENOSYS so that guest userspace
> - * falls back to a non-robust futex implementation (which should
> - * be OK except in the corner case of the guest crashing while
> - * holding a mutex that is shared with another process via
> - * shared memory).
> - */
> -return -TARGET_ENOSYS;
> -#endif
>
>  #if defined(TARGET_NR_utimensat)
>  case TARGET_NR_utimensat:
> @@ -12412,6 +12406,54 @@ static abi_long do_syscall1(void *cpu_env, unsigned 
> num, abi_long arg1,
>  return ret;
>  }
>
> +/* The default action for a syscall not listed in syscall_table is to
> + * log the missing syscall.  If a syscall is intentionally emulated as
> + * not present, then list it with impl_enosys as the implementation,
> + * which will avoid the logging.
> + */
> +IMPL(enosys)
> +{
> +return -TARGET_ENOSYS;
> +}
> +
> +/* For a given syscall number, return a function implementing it.
> + * Do this via switch statement instead of table because some targets
> + * do not begin at 0 and others have a large split in the middle of
> + * the numbers.  The compiler should be able to produce a dense table.
> + */
> +static impl_fn *syscall_table(unsigned num)
> +{
> +#define SYSCALL_WITH(X, Y)case TARGET_NR_##X: return impl_##Y
> +#define SYSCALL(X)SYSCALL_WITH(X, X)
> +
> +switch (num) {
> +/* The ABI for supporting robust futexes has userspace pass
> + * the kernel a pointer to a linked list which is updated by
> + * userspace after the syscall; the list is walked by the kernel
> + * when the thread exits. Since the linked list in QEMU guest
> + * memory isn't a valid linked list for the host and we have
> + * no way to reliably intercept the thread-death event, we can't
> + * support these. Silently return ENOSYS so that guest userspace
> + * falls back to a non-robust futex implementation (which should
> + * be OK except in the corner case of the guest crashing while
> + * holding a mutex that is shared with another process via
> + * shared memory).
> + */
> +SYSCALL_WITH(get_robust_list, enosys);
> +SYSCALL_WITH(set_robust_list, enosys);
> +
> +/*
> + * Other syscalls listed in collation order, with '_' ignored.
> + */
> +}

I was expecting this to be a table lookup, something like
   return syscalls[num].impl;

where the other entries in the syscalls[num] structs would be
for instance the strace data we currently have in strace.list.

thanks
-- PMM



Re: [Qemu-devel] [PATCH] pc: Remove PC_COMPAT_2_12 from 3.0 machine-types

2018-06-10 Thread Marcel Apfelbaum




On 06/08/2018 10:29 PM, Eduardo Habkost wrote:

commit f548222c added PC_COMPAT_2_12 to the 3.0 PC machine-types.
I believe this happened during manual conflict resolution when
applying the patch.

Cc: Xiao Guangrong 
Cc: Juan Quintela 
Fixes: f548222c24342ca74689de7794f9006b43f86a54
Signed-off-by: Eduardo Habkost 
---
  hw/i386/pc_piix.c | 1 -
  hw/i386/pc_q35.c  | 1 -
  2 files changed, 2 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 3d81136065..b4c5b03274 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -430,7 +430,6 @@ static void pc_i440fx_3_0_machine_options(MachineClass *m)
  pc_i440fx_machine_options(m);
  m->alias = "pc";
  m->is_default = 1;
-SET_MACHINE_COMPAT(m, PC_COMPAT_2_12);
  }
  
  DEFINE_I440FX_MACHINE(v3_0, "pc-i440fx-3.0", NULL,

diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index b60cbb9266..83d6d75efa 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -312,7 +312,6 @@ static void pc_q35_3_0_machine_options(MachineClass *m)
  {
  pc_q35_machine_options(m);
  m->alias = "q35";
-SET_MACHINE_COMPAT(m, PC_COMPAT_2_12);
  }
  
  DEFINE_Q35_MACHINE(v3_0, "pc-q35-3.0", NULL,


Reviewed-by: Marcel Apfelbaum

Thanks,
Marcel



Re: [Qemu-devel] [PATCH] hw/pvrdma: Bugfix - provide the correct attr_mask to query_qp

2018-06-10 Thread Marcel Apfelbaum




On 06/08/2018 05:37 PM, Yuval Shaia wrote:

Calling rdma_rm_query_qp with attr_mask equals to -1 leads to error
where backend query_qp fails to retrieve the needed QP attributes.
Fix it by providing the attr_mask we got from driver.

Signed-off-by: Yuval Shaia 
---
  hw/rdma/vmw/pvrdma_cmd.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/rdma/vmw/pvrdma_cmd.c b/hw/rdma/vmw/pvrdma_cmd.c
index 9d9dfc6b81..76df60a540 100644
--- a/hw/rdma/vmw/pvrdma_cmd.c
+++ b/hw/rdma/vmw/pvrdma_cmd.c
@@ -524,6 +524,7 @@ static int query_qp(PVRDMADev *dev, union pvrdma_cmd_req 
*req,
  struct ibv_qp_init_attr init_attr;
  
  pr_dbg("qp_handle=%d\n", cmd->qp_handle);

+pr_dbg("attr_mask=0x%x\n", cmd->attr_mask);
  
  memset(rsp, 0, sizeof(*rsp));

  rsp->hdr.response = cmd->hdr.response;
@@ -531,8 +532,8 @@ static int query_qp(PVRDMADev *dev, union pvrdma_cmd_req 
*req,
  
  rsp->hdr.err = rdma_rm_query_qp(>rdma_dev_res, >backend_dev,

  cmd->qp_handle,
-(struct ibv_qp_attr *)>attrs, -1,
-_attr);
+(struct ibv_qp_attr *)>attrs,
+cmd->attr_mask, _attr);
  
  pr_dbg("ret=%d\n", rsp->hdr.err);

  return rsp->hdr.err;



Reviewed-by: Marcel Apfelbaum

Thanks,
Marcel



[Qemu-devel] [Bug 1341032] Re: no-shutdown does not fire SHUTDOWN event for some guests

2018-06-10 Thread md_5
** Changed in: qemu
   Status: New => Invalid

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

Title:
  no-shutdown does not fire SHUTDOWN event for some guests

Status in QEMU:
  Invalid

Bug description:
  Currently using: qemu-x86_64 version 2.0.0
  Steps to reproduce: Create virtual machine with the arguments -no-shutdown, 
such as used by libvirt. Attach to the json event system. Load a guest such as 
Ubuntu 14.04 and run the 'halt' command. Guest ceases to execute, qemu freezes 
CPUs however no SHUTDOWN event is fired to the monitor.

  Now load a guest such as finnix or Debian 7. Run the same sequence of
  steps and note that the SHUTDOWN event is fired to the monitor.

  This seems like a qemu bug as the execution of the guest has ceased.

  Thanks
  Michael

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



Re: [Qemu-devel] [PATCH v2 001/108] linux-user: Remove DEBUG

2018-06-10 Thread Laurent Vivier
Le 10/06/2018 à 05:00, Richard Henderson a écrit :
> This is redundant with both -strace and actual tracing.
> 
> Signed-off-by: Richard Henderson 
> ---
>  linux-user/syscall.c | 10 --
>  1 file changed, 10 deletions(-)

Reviewed-by: Laurent Vivier 





Re: [Qemu-devel] [RFC 01/13] hw/m68k: add via support

2018-06-10 Thread Laurent Vivier
Le 09/06/2018 à 17:48, Mark Cave-Ayland a écrit :
> On 09/06/18 11:01, Mark Cave-Ayland wrote:
> 
>> Yeah, we can certainly remove a huge chunk of this by converting over
>> to the mos6522 device. My last set of updates to CUDA a couple of days
>> ago are probably the best reference, but I can probably find some time
>> to do the basic conversion for you at some point...
> 
> BTW is there a particular github branch I should be working from in
> order to attempt this?
> 

You can use q800-dev-part1 from git://github.com/vivier/qemu-m68k.git

Thanks,
Laurent



Re: [Qemu-devel] question: a dead loop in qemu when do blockJobAbort and vm suspend coinstantaneously

2018-06-10 Thread Fam Zheng
On Sat, 06/09 17:10, l00284672 wrote:
> Hi, I found a dead loop in qemu when do blockJobAbort and vm suspend
> coinstantaneously.
> 
> The qemu bt is below:
> 
> #0  0x7ff58b53af1f in ppoll () from /lib64/libc.so.6
> #1  0x007fdbd9 in ppoll (__ss=0x0, __timeout=0x7ffcf7055390,
> __nfds=, __fds=) at
> /usr/include/bits/poll2.h:77
> #2  qemu_poll_ns (fds=, nfds=,
> timeout=timeout@entry=0) at util/qemu-timer.c:334
> #3  0x007ff83a in aio_poll (ctx=ctx@entry=0x269d800,
> blocking=blocking@entry=false) at util/aio-posix.c:629
> #4  0x00776e91 in bdrv_drain_recurse (bs=bs@entry=0x26d9cb0) at
> block/io.c:198
> #5  0x00776ef2 in bdrv_drain_recurse (bs=bs@entry=0x3665990) at
> block/io.c:215
> #6  0x007774b8 in bdrv_do_drained_begin (bs=0x3665990,
> recursive=, parent=0x0) at block/io.c:291
> #7  0x0076a79e in blk_drain (blk=0x2780fc0) at
> block/block-backend.c:1586
> #8  0x0072d2a9 in block_job_drain (job=0x29df040) at blockjob.c:123
> #9  0x0072d228 in block_job_detach_aio_context (opaque=0x29df040) at
> blockjob.c:139
> #10 0x007298b1 in bdrv_detach_aio_context (bs=bs@entry=0x3665990) at
> block.c:4885
> #11 0x00729a46 in bdrv_set_aio_context (bs=0x3665990,
> new_context=0x268e140) at block.c:4946
> #12 0x00499743 in virtio_blk_data_plane_stop (vdev=)
> at
> /mnt/sdb/lzg/code/shequ_code/5_29/qemu/hw/block/dataplane/virtio-blk.c:285
> #13 0x006bce30 in virtio_bus_stop_ioeventfd (bus=0x3de5378) at
> hw/virtio/virtio-bus.c:246
> #14 0x004c654d in virtio_vmstate_change (opaque=0x3de53f0,
> running=, state=)
>     at /mnt/sdb/lzg/code/shequ_code/5_29/qemu/hw/virtio/virtio.c:
> #15 0x00561b52 in vm_state_notify (running=running@entry=0,
> state=state@entry=RUN_STATE_PAUSED) at vl.c:1514
> #16 0x0045d67a in do_vm_stop (state=state@entry=RUN_STATE_PAUSED,
> send_stop=send_stop@entry=true)
>     at /mnt/sdb/lzg/code/shequ_code/5_29/qemu/cpus.c:1012
> #17 0x0045dafd in vm_stop (state=state@entry=RUN_STATE_PAUSED) at
> /mnt/sdb/lzg/code/shequ_code/5_29/qemu/cpus.c:2035
> #18 0x0057301b in qmp_stop (errp=errp@entry=0x7ffcf70556f0) at
> qmp.c:106
> #19 0x0056bf7a in qmp_marshal_stop (args=,
> ret=, errp=0x7ffcf7055738) at qapi/qapi-commands-misc.c:784
> #20 0x007f2d27 in do_qmp_dispatch (errp=0x7ffcf7055730,
> request=0x3e121e0, cmds=) at qapi/qmp-dispatch.c:119
> #21 qmp_dispatch (cmds=, request=request@entry=0x26f2800) at
> qapi/qmp-dispatch.c:168
> #22 0x004655be in monitor_qmp_dispatch_one
> (req_obj=req_obj@entry=0x39abff0) at
> /mnt/sdb/lzg/code/shequ_code/5_29/qemu/monitor.c:4088
> #23 0x00465894 in monitor_qmp_bh_dispatcher (data=)
> at /mnt/sdb/lzg/code/shequ_code/5_29/qemu/monitor.c:4146
> #24 0x007fc571 in aio_bh_call (bh=0x26de7e0) at util/async.c:90
> #25 aio_bh_poll (ctx=ctx@entry=0x268dd50) at util/async.c:118
> #26 0x007ff6f0 in aio_dispatch (ctx=0x268dd50) at
> util/aio-posix.c:436
> #27 0x007fc44e in aio_ctx_dispatch (source=,
> callback=, user_data=) at util/async.c:261
> #28 0x7ff58bc7c99a in g_main_context_dispatch () from
> /lib64/libglib-2.0.so.0
> #29 0x007fea3a in glib_pollfds_poll () at util/main-loop.c:215
> #30 os_host_main_loop_wait (timeout=) at util/main-loop.c:238
> #31 main_loop_wait (nonblocking=nonblocking@entry=0) at util/main-loop.c:497
> #32 0x00561cad in main_loop () at vl.c:1848
> #33 0x0041995c in main (argc=, argv=,
> envp=) at vl.c:4605
> 
> The disk is a virtio-blk dataplane disk with a mirror job running.  The dead
> loop is here:
> 
> static void block_job_detach_aio_context(void *opaque)
> {
>     BlockJob *job = opaque;
> 
>     /* In case the job terminates during aio_poll()... */
>     job_ref(>job);
> 
>     job_pause(>job);
> 
>   while (!job->job.paused && !job_is_completed(>job)) {
>     job_drain(>job);
>     }
> 
>     job->job.aio_context = NULL;
>     job_unref(>job);
> }
> 
> The job is deferred to main loop now,  but the  job_drain only processes the
> AIO context of bs which has no more work to do,
> 
> while the main loop BH is scheduled for setting the job->completed flag is
> never processed.

In that case, main loop's AioContext should be driven like in job_finish_sync().
Could you try this patch?

diff --git a/blockjob.c b/blockjob.c
index 0306533a2e..72aa82ac2d 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -135,7 +135,15 @@ static void block_job_detach_aio_context(void *opaque)

 job_pause(>job);

-while (!job->job.paused && !job_is_completed(>job)) {
+
+while (true) {
+if (job->job.paused || job_is_completed(>job)) {
+break;
+}
+if (job->deferred_to_main_loop) {
+aio_poll(qemu_get_aio_context(), true);
+continue;
+}
 job_drain(>job);
 }



Re: [Qemu-devel] [PATCH] loader: implement START_SEG_ADDR_RECORD

2018-06-10 Thread Su Hang
Sure, Thanks for remind me of this.
One thing I must point out, in current code logic, if "START_SEG_ADDR_RECORD"
occured multiple times, only the last one works. I don't know whether GNU
binutils would emit 'The Record' many times.

Best,
SU Hang


> -Original Messages-
> From: "Stefan Hajnoczi" 
> Sent Time: 2018-06-10 00:32:52 (Sunday)
> To: qemu-devel@nongnu.org
> Cc: "Su Hang" , jus...@mail.ru, 
> j...@groklearning.com, j...@jms.id.au, qemu...@steffen-goertz.de, "Stefan 
> Hajnoczi" 
> Subject: [PATCH] loader: implement START_SEG_ADDR_RECORD
> 
> It turns out that GNU binutils emits START_SEG_ADDR_RECORD when the start
> address is within the first megabyte (< 0x10).  Therefore we must
> handle this record type.
> 
> Originally we thought this record type was x86-specific, but binutils
> also emits it on non-x86 architectures.
> 
> Based-on: <1527161340-3200-1-git-send-email-suhan...@mails.ucas.ac.cn>
> Cc: Su Hang 
> Signed-off-by: Stefan Hajnoczi 
> ---
> Su Hang: Feel free to squash this into the next revision of your hex
> loader patch.  Don't worry about the authorship information.
> 
>  hw/core/loader.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 3c0202caa8..7843b487b2 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -1423,8 +1423,14 @@ static int handle_record_type(HexParser *parser)
>  break;
>  
>  case START_SEG_ADDR_RECORD:
> -/* TODO: START_SEG_ADDR_RECORD is x86-specific */
> -return -1;
> +if (line->byte_count != 4 && line->address != 0) {
> +return -1;
> +}
> +
> +/* x86 16-bit CS:IP segmented addressing */
> +*(parser->start_addr) = (((line->data[0] << 8) | line->data[1]) << 
> 4) |
> +(line->data[2] << 8) | line->data[3];
> +break;
>  
>  case START_LINEAR_ADDR_RECORD:
>  if (line->byte_count != 4 && line->address != 0) {
> -- 
> 2.17.1