Re: [Qemu-devel] [PATCH 1/2] vga: abort instead of shrinking memory

2015-02-17 Thread Gerd Hoffmann
On Mo, 2015-02-16 at 22:23 +0100, Radim Krčmář wrote:
> Automatic shrinking of vram_size leads to a segfault, because other
> variables depend on being smaller and don't get shrinked.

--verbose please.  Which other variables?

> Implications of shrinking would make the code needlessly complicated;
> assert instead.

assert isn't an option.  vram_size_mb may come from the user (via vga
device properties), so we need a friendly error message here.

Also the loop you are removing makes sure vram_size is a power of two,
removing that is not correct too.

cheers,
  Gerd





Re: [Qemu-devel] [PULL v2 00/14] target-mips queue

2015-02-17 Thread Peter Maydell
On 15 February 2015 at 02:44, Leon Alrae  wrote:
> Hi,
>
> Here is version 2 of target-mips pullreq - rebased and with signed tag.

Just fyi, this hotel's wifi and my work VPN seem to disagree with
each other, so probably no pullrequest handling til next week
some time. (Unless I manage to figure out some routing table magic
to avoid the IP address clash...)

-- PMM



Re: [Qemu-devel] [PATCH 2/2] qxl: surface0 and ram_header should fit into vram

2015-02-17 Thread Gerd Hoffmann
On Mo, 2015-02-16 at 22:23 +0100, Radim Krčmář wrote:
> The solution is not perfect, but won't let us do the same error again
> and has no overhead.

How do you get qemu into a configuration where this isn't true?

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 4/4] block: Remove unused functions

2015-02-17 Thread Thomas Huth

 Hi Max,

On Mon, 16 Feb 2015 17:26:56 -0500
Max Reitz  wrote:

> On 2015-02-16 at 16:41, Thomas Huth wrote:
> > qemu_try_blockalign0() and nbd_export_close_all() are not
> > used anymore and thus can be removed.
> >
> > Signed-off-by: Thomas Huth 
> > Cc: Kevin Wolf 
> > Cc: Stefan Hajnoczi 
> > Cc: Paolo Bonzini 
> > ---
> >   block.c   |   11 ---
> >   include/block/block.h |1 -
> >   include/block/nbd.h   |1 -
> >   nbd.c |9 -
> >   4 files changed, 0 insertions(+), 22 deletions(-)
> 
> NACK, I'm using nbd_export_close_all() in my "block: Rework 
> bdrv_close_all()" series.

Alright, if it's going to be used again, then it must not be removed,
of course.

> I'm not so sure about qemu_try_blockalign0(); it has never been used, 
> but I introduced it because we have qemu_blockalign(), 
> qemu_try_blockalign(), and qemu_blockalign0() (the latter of which I 
> introduced along with qemu_try_blockalign0(), and this function is used).
> 
> So I'd be fine with removing qemu_try_blockalign0() again, but I don't 
> really see the point in doing so. It is not a function that is per-se 
> deprecated or something, quite the opposite, actually. If people can 
> make use of that function, they should most certainly do so.

I'm not a big fan of providing unused (and likely untested) functions
just because they could be used somewhen in a distant future (unless
they are part of a proper library) ... I'd rather add such functions
again when they are really being used.

Anyway, this is just a small, trivial function, and if you prefer to
keep it, then please ignore this patch simply completely. There is
certainly no urgent need for removing unused functions, I just wanted
to make people aware that there are some.

 Thomas




Re: [Qemu-devel] [PATCH 00/13] QemuOpts: Convert various setters to Error

2015-02-17 Thread Markus Armbruster
Forgot to mention: based on my "[PATCH v2 00/10] Clean up around
error_get_pretty(), qerror_report_err()" series, because it needs its
"[PATCH v2 01/10] error: New convenience function error_report_err()".



Re: [Qemu-devel] [PATCH 04/13] qemu-img: Suppress unhelpful extra errors in convert, resize

2015-02-17 Thread Markus Armbruster
John Snow  writes:

> On 02/16/2015 09:44 AM, Markus Armbruster wrote:
>> add_old_style_options() for img_convert() and img_resize() use
>> qemu_opt_set(), which reports errors with qerror_report_err().  Its
>> error messages aren't helpful here, the caller reports one that
>> actually makes sense.  Reproducer:
>>
>>  $ qemu-img convert -B raw in.img out.img
>>  qemu-img: Invalid parameter 'backing_file'
>>  qemu-img: Backing file not supported for file format 'raw'
>>
>> Switch to qemu_opt_set_err() to get rid of the unwanted messages.
>>
>> Signed-off-by: Markus Armbruster 
>> ---
>>   qemu-img.c | 16 
>>   1 file changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/qemu-img.c b/qemu-img.c
>> index 7eea84a..7a806bc 100644
>> --- a/qemu-img.c
>> +++ b/qemu-img.c
[...]
>> @@ -2830,8 +2837,9 @@ static int img_resize(int argc, char **argv)
>>
>>   /* Parse size */
>>   param = qemu_opts_create(&resize_options, NULL, 0, &error_abort);
>> -if (qemu_opt_set(param, BLOCK_OPT_SIZE, size)) {
>> -/* Error message already printed when size parsing fails */
>> +qemu_opt_set_err(param, BLOCK_OPT_SIZE, size, &err);
>> +if (err) {
>> +error_report_err(err);
>
> Creates a new warning/failure for me, if basing off of origin/master
> or kevin/block:
>
>   CCqemu-img.o
> /home/bos/jhuston/src/qemu/qemu-img.c: In function ‘img_resize’:
> /home/bos/jhuston/src/qemu/qemu-img.c:2844:9: error: implicit
> declaration of function ‘error_report_err’
> [-Werror=implicit-function-declaration]
>  error_report_err(err);
>  ^
> /home/bos/jhuston/src/qemu/qemu-img.c:2844:9: error: nested extern
> declaration of ‘error_report_err’ [-Werror=nested-externs]
> cc1: all warnings being treated as errors
> make: *** [qemu-img.o] Error 1
> make: *** Waiting for unfinished jobs

You need my "[PATCH v2 01/10] error: New convenience function
error_report_err()", but I forgot to mention it in my cover letter.  My
apologies.

[...]



Re: [Qemu-devel] [PATCH 06/13] QemuOpts: Drop qemu_opt_set(), rename qemu_opt_set_err(), fix use

2015-02-17 Thread Markus Armbruster
Eric Blake  writes:

> On 02/16/2015 07:44 AM, Markus Armbruster wrote:
>> qemu_opt_set() is a wrapper around qemu_opt_set() that reports the
>> error with qerror_report_err().
>> 
>> Most of its users assume the function can't fail.  Make them use
>> qemu_opt_set_err() with &error_abort, so that should the assumption
>> ever break, it'll break noisily.
>> 
>> Just two users remain, in util/qemu-config.c.  Switch them to
>> qemu_opt_set_err() as well, then rename qemu_opt_set_err() to
>> qemu_opt_set().
>
> Might be better to split this into fixing the two users in one patch,
> then doing the rename in another (since the rename touches more than two
> callers).  On the other hand, it would represent more churn with
> changing existing qemu_opt_set() to qemu_opt_set_err(,&error_abort) just
> to change back to qemu_opt_set later.

Yeah, that's why I chose to do it in one go.

>> Signed-off-by: Markus Armbruster 
>> ---
>>  block.c  |  5 ++--
>>  block/qcow2.c|  3 +-
>>  block/vvfat.c|  2 +-
>>  blockdev.c   | 17 +--
>>  hw/pci/pci-hotplug-old.c |  2 +-
>>  hw/usb/dev-network.c |  4 +--
>>  hw/usb/dev-storage.c |  6 ++--
>>  hw/watchdog/watchdog.c   |  2 +-
>>  include/qemu/option.h|  5 ++--
>>  net/net.c|  2 +-
>>  qdev-monitor.c   |  6 ++--
>>  qemu-char.c  | 58 +++---
>>  qemu-img.c   |  6 ++--
>>  tests/test-qemu-opts.c   |  6 ++--
>>  util/qemu-config.c   |  9 --
>>  util/qemu-option.c   | 22 +++
>>  util/qemu-sockets.c  | 34 +++---
>>  vl.c | 73 ++--
>>  18 files changed, 131 insertions(+), 131 deletions(-)
>
> Also, the patch is fairly obvious that it is mechanical, so even if you
> don't split, I could live with:
>
> Reviewed-by: Eric Blake 
>
>> +++ b/util/qemu-config.c
>> @@ -219,6 +219,7 @@ void qemu_add_opts(QemuOptsList *list)
>>  
>>  int qemu_set_option(const char *str)
>>  {
>> +Error *local_err = NULL;
>>  char group[64], id[64], arg[64];
>>  QemuOptsList *list;
>>  QemuOpts *opts;
>> @@ -242,7 +243,9 @@ int qemu_set_option(const char *str)
>>  return -1;
>>  }
>>  
>> -if (qemu_opt_set(opts, arg, str+offset+1) == -1) {
>> +qemu_opt_set(opts, arg, str+offset+1, &local_err);
>
> Worth adding whitespace around the 2 '+' operators while touching this?

Yes, if I need to respin or send a pull request.

Thanks!



Re: [Qemu-devel] [PATCH 2/4] ui/console: Removed unused functions

2015-02-17 Thread Gerd Hoffmann
On Mo, 2015-02-16 at 22:41 +0100, Thomas Huth wrote:
> Remove dpy_gfx_update_dirty(), qemu_console_get_head(),
> qemu_console_get_ui_info(), qemu_console_get_width(),
> qemu_console_get_height(), emu_console_displaystate(),
> qemu_different_endianness_pixelformat(), void cpkey(),
> qemu_pixman_linebuf_copy(), qemu_pixman_color(),
> emu_remove_kbd_event_handler() and vnc_stop_worker_thread()
> since they are completely unused.

Vetoing this one.  Some of them belong to work-in-progress bits and
should not be removed.

Also I think this kind of cleanup should be splitted into smaller
pieces, so it is easier to get specific bits back via "git revert"
should the need arise.

> -void dpy_gfx_update_dirty(QemuConsole *con,

Keep.

> -QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con)

Keep.

> -int qemu_console_get_width(QemuConsole *con, int fallback)
> -int qemu_console_get_height(QemuConsole *con, int fallback)

Hmm, not sure.  Separate patch please.

> -DisplayState *qemu_console_displaystate(QemuConsole *console)

Ok.

> -PixelFormat qemu_different_endianness_pixelformat(int bpp)

Ok.

> -void cpkey(register unsigned long *into)

Ok.

> -void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)

Ok.

> -void qemu_input_handler_deactivate(QemuInputHandlerState *s)

Hmm, might be needed in the future.  Separate patch please.

> -/* copy linebuf to framebuffer */
> -void qemu_pixman_linebuf_copy(pixman_image_t *fb, int width, int x, int y,
> -  pixman_image_t *linebuf)
> -{
> -pixman_image_composite(PIXMAN_OP_SRC, linebuf, NULL, fb,
> -   0, 0, 0, 0, x, y, width, 1);
> -}

Keep.

> -pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t color)
> -{
> -pixman_color_t c;
> -
> -c.red   = ((color & pf->rmask) >> pf->rshift) << (16 - pf->rbits);
> -c.green = ((color & pf->gmask) >> pf->gshift) << (16 - pf->gbits);
> -c.blue  = ((color & pf->bmask) >> pf->bshift) << (16 - pf->bbits);
> -c.alpha = ((color & pf->amask) >> pf->ashift) << (16 - pf->abits);
> -return c;
> -}

Not sure.  Separate patch please.

> -void vnc_stop_worker_thread(void)

Probably ok.  Separate patch would be nice.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH v2 1/4] virtio-pci: add flags to enable/disable legacy/modern

2015-02-17 Thread Gerd Hoffmann
  Hi,

> Should we forbid setting both legacy and modern at the same time?

No, this is explicitly allowed in the spec and it is needed for the
transition from legacy to modern.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 09/13] qemu-img: Suppress unhelpful extra errors in convert, amend

2015-02-17 Thread Markus Armbruster
Eric Blake  writes:

> On 02/16/2015 07:44 AM, Markus Armbruster wrote:
>> img_convert() and img_amend() use qemu_opts_do_parse(), which reports
>> errors with qerror_report_err().  Its error messages aren't helpful
>> here, the caller reports one that actually makes sense.  Reproducer:
>> 
>> $ qemu-img convert -o backing_format=raw in.img out.img
>> qemu-img: Invalid parameter 'backing_format'
>> qemu-img: Invalid options for file format 'raw'
>> 
>> To fix, propagate errors through qemu_opts_do_parse().  This lifts the
>> error reporting into callers.  Drop it from img_convert() and
>> img_amend(), keep it in qemu_chr_parse_compat(), bdrv_img_create().
>> 
>> Since I'm touching qemu_opts_do_parse() anyway, write a function
>> comment for it.
>> 
>> Signed-off-by: Markus Armbruster 
>> ---
>>  block.c   |  5 -
>>  include/qemu/option.h |  3 ++-
>>  qemu-char.c   | 10 --
>>  qemu-img.c| 25 +
>>  util/qemu-option.c| 19 +--
>>  5 files changed, 40 insertions(+), 22 deletions(-)
>> 
>
>> -int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char 
>> *firstname)
>> +/**
>> + * Store into @opts options parsed from @params.
>
> Reads a bit awkwardly; maybe:
>
> Store options parsed from @params into @opts.

Mentioning parameters in order.  Old habits die hard...

>> + * If @firstname is non-null, the first key=value in @params may omit
>> + * key=, and is treated as if key was @firstname.
>> + * On error, store an error object through @errp if non-null.
>> + */
>> +void qemu_opts_do_parse(QemuOpts *opts, const char *params,
>> +   const char *firstname, Error **errp)
>>  {
>
> Up to you if you want to improve that; either way, it's in a comment, so
> it doesn't affect correctness, so:
>
> Reviewed-by: Eric Blake 

Thanks!



Re: [Qemu-devel] [PATCH v2 1/4] virtio-pci: add flags to enable/disable legacy/modern

2015-02-17 Thread Michael S. Tsirkin
On Tue, Feb 17, 2015 at 09:23:35AM +0100, Gerd Hoffmann wrote:
>   Hi,
> 
> > Should we forbid setting both legacy and modern at the same time?
> 
> No, this is explicitly allowed in the spec and it is needed for the
> transition from legacy to modern.
> 
> cheers,
>   Gerd

But !legacy && !modern aren't legal together, correct?




Re: [Qemu-devel] [RFC PATCH v8 08/21] cpu: replay instructions sequence

2015-02-17 Thread Pavel Dovgaluk
> From: Paolo Bonzini [mailto:paolo.bonz...@gmail.com] On Behalf Of Paolo 
> Bonzini
> On 16/02/2015 14:37, Pavel Dovgaluk wrote:
> >> From: Paolo Bonzini [mailto:paolo.bonz...@gmail.com] On Behalf Of Paolo 
> >> Bonzini
> >> On 16/02/2015 14:27, Pavel Dovgaluk wrote:
>  From: Paolo Bonzini [mailto:paolo.bonz...@gmail.com] On Behalf Of Paolo 
>  Bonzini
>  On 16/02/2015 13:26, Pavel Dovgaluk wrote:
> > I think in this case there are no events at all - just reading 
> > timers values
> > that were made while recording.
> > We have to replay these reads by waking iothread.
> >>>
> >>> I think the right place for this is in replay_read_next_clock then.
> > It doesn't fit. Log file is not read until all instructions are 
> > executed.
> > And the next read from the file should be performed by iothread which 
> > should
> > be notified and waked up.
> 
>  I still don't understand.  If you're getting EXCP_INTERRUPT it means:
> 
>  1) that cpu_signal was called
> >>>
> >>> No, it isn't. That is the branch when icount is expired.
> >>> And when it is expired in replay mode we have to wake up iothread,
> >>> because nobody will care about this.
> >>
> >> Then it's done here in qemu_tcg_cpu_thread_fn:
> >
> > Do you mean that I should put iothread notification right here?
> 
> It already notifies the iothread.
> 
> > Or that this code duplicates my patch?
> > If the second one then I guess that it doesn't help and I need to make 
> > additional checks
> about it.
> 
> Yes.  You can modify your patch to do:
> 
>  int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
>  if (deadline == 0) {
>  qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
>  }
> 
> instead of qemu_notify_event(), and remove these lines from
> qemu_tcg_cpu_thread_fn.

I tried this one. But there is one problem.
Expiring of the virtual timers is not the only reason of icount expiration in 
replay mode.
It may be caused by host timers deadline or poll timeout in record mode. In 
this case 
qemu_clock_notify(QEMU_CLOCK_VIRTUAL) will not be called in replay mode and 
we'll waste time for iothread sleeping.


Pavel Dovgalyuk




Re: [Qemu-devel] [PATCH 04/10] vnc: switch to QemuOpts, allow multiple servers

2015-02-17 Thread Gerd Hoffmann
On Fr, 2015-02-13 at 19:25 +0100, Markus Armbruster wrote:
> Gerd Hoffmann  writes:
> 
> > This patch switches vnc over to QemuOpts, and it (more or less
> > as side effect) allows multiple vnc server instances.
> >
> > Signed-off-by: Gerd Hoffmann 
> 
> I'm afraid this broke monitor command change vnc.
> 
> Reproducer
> 
> Terminal 1:
> 
> $ qemu -nodefaults -S -display vnc=:0 -monitor stdio
> QEMU 2.2.50 monitor - type 'help' for more information
> 
> Terminal 2:
> 
> $ vncviewer :0 
> 
> Terminal 1:
> 
> (qemu) change vnc :1
> 
> Terminal 3:
> 
> $ vncviewer :1
> 
> Before this patch, vncviewer works both times.  The second one kills the
> first one.
> 
> After this patch, the first one still works, but the second one fails.
> netstat shows nobody's listening on the port.

Fix for this is on the list already (Gonglei) and included in the
pending vnc pull request.

> Furthermore, the conversion to QemuOpts makes VNC visible in
> -writeconfig, but if you -readconfig it back, it doesn't quite work.
> 
> With -display vnc=:0, -writeconfig produces
> 
> [vnc]
>   vnc = ":0"
> 
> If I append that to the config file I -readconfig, I a working VNC
> display on :0 (good), but I also get an SDL display (not good).

Will send a fix to the list in a moment.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 3/4] util: Remove unused functions

2015-02-17 Thread Markus Armbruster
Thomas Huth  writes:

> Delete the unused functions qemu_opt_get_number_del(),
> qemu_signalfd_available(), qemu_send_full() and qemu_recv_full().
>
> Signed-off-by: Thomas Huth 

qemu_opt_get_number_del() was added in commit 782730b along with
qemu_opt_get_del(), qemu_opt_get_bool_del() and qemu_opt_get_size_del().
It hasn't been used so far, but removing it makes the interface
irregular.  I'd rather not.  Covering all four in tests/test-qemu-opts.c
would be nice.

qemu_send_full() and qemu_recv_full() complement qemu_write_full().  On
the other hand, there's no qemu_read_full().  I don't think keeping the
two unused ones hurts, but I don't object to dropping them, either.

For what it's worth, glibc provides a macro to solve this problem once
and for all:

/* Evaluate EXPRESSION, and repeat as long as it returns -1 with `errno'
   set to EINTR.  */

# define TEMP_FAILURE_RETRY(expression) \
  (__extension__\
({ long int __result;   \
   do __result = (long int) (expression);   \
   while (__result == -1L && errno == EINTR);   \
   __result; }))
#endif

More elegant than writing the same old boring wrapper around everything
that can fail with EINTR.

qemu_signalfd_available() is unused since commit 6d32717.  It's also the
only user of CONFIG_SIGNALFD.  If we want to drop it, I recommend
dropping CONFIG_SIGNALFD as well.



Re: [Qemu-devel] [PATCH RFC v2 8/8] migration: add migration/dirty-bitmap.c

2015-02-17 Thread Vladimir Sementsov-Ogievskiy

On 16.02.2015 21:18, John Snow wrote:



On 02/16/2015 07:06 AM, Vladimir Sementsov-Ogievskiy wrote:

On 13.02.2015 23:22, John Snow wrote:



On 02/13/2015 03:19 AM, Vladimir Sementsov-Ogievskiy wrote:

On 11.02.2015 00:33, John Snow wrote:



So in summary:
using device names is probably fine for now, as it matches the current
use case of bitmaps as well as drive migration; but using node names
may give us more power and precision later.

I talked to Max about it, and he is leaning towards using device names
for now and switching to node names if we decide we want that power.

(...I wonder if we could use a flag, for now, that says we're
including DEVICE names. Later, we could add a flag that says we're
using NODE names and add an option to toggle as the usage case sees 
fit.)



Are you confused yet? :D

O, thanks for the explanation). Are we really need this flag? As Markus
wrote, nodes and devices are sharing namespaces.. We can use
bdrv_lookup_bs(name, name, errp)..


what 'name' are you using here, though? It looked to me like in your 
backup routine we got a list of BDS entries and get the name *from* 
the BDS, so we still have to think about how we want to /get/ the name.




Also, we can, for example, send bitmaps as follows:

if node has name - send bitmap with this name
if node is root, but hasn't name - send it with blk name
otherwise - don't send the bitmap


The node a bitmap is attached to should always have a name -- it would 
not be possible via the existing interface to attach it to a node 
without a name.


I *think* the root node should always have a name, but I am actually 
less sure of that.


Hmm.. No? bitmap is attached using bdrv_lookup_bs(name, name, errp), 
which can find device with this name. qemu option -drive 
file=...,id=disk creates blk named 'disk' and attached node with no name.



--
Best regards,
Vladimir




Re: [Qemu-devel] [PATCH 04/10] vnc: switch to QemuOpts, allow multiple servers

2015-02-17 Thread Gerd Hoffmann
  Hi,

> >  static void qmp_change_vnc_listen(const char *target, Error **errp)
> >  {
> > -vnc_display_open(NULL, target, errp);
> > +QemuOptsList *olist = qemu_find_opts("vnc");
> > +QemuOpts *opts;
> > +
> > +if (strstr(target, "id=")) {
> > +error_setg(errp, "id not supported");
> > +return;
> > +}
> 
> Aside: this is unclean.  Could we somehow test qemu_opts_id() instead?

For that we would have to parse it first, which has some ugly corner
cases on id clashes ...

All I wanna do here is keep it alive for the existing use cases, without
support for multiple displays, with minimum effort.

Should we need support for vnc config change in a multiple vnc server
setup a new qmp monitor command should be designed for that.

cheers,
  Gerd





[Qemu-devel] [PATCH 0/2] vnc: -readconfig fixups

2015-02-17 Thread Gerd Hoffmann
  Hi,

Series applies on top of the pending vnc pull request.
Fix -writeconfig/-readconfig related fallout from
the QemuOpts conversion of the vnc configuration.

cheers,
  Gerd

Gerd Hoffmann (2):
  vnc: set id at parse time not init time
  vnc: -readconfig fix

 include/ui/console.h |  1 -
 qmp.c|  1 -
 ui/vnc.c | 22 --
 vl.c |  7 +--
 4 files changed, 17 insertions(+), 14 deletions(-)

-- 
1.8.3.1




[Qemu-devel] [PATCH 1/2] vnc: set id at parse time not init time

2015-02-17 Thread Gerd Hoffmann
This way the generated id will be stored in -writeconfig cfg files.
Also we can make vnc_auto_assign_id() local to vnc.c.

Signed-off-by: Gerd Hoffmann 
---
 include/ui/console.h |  1 -
 qmp.c|  1 -
 ui/vnc.c | 22 --
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 5c19c3c..8a4d671 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -335,7 +335,6 @@ void vnc_display_init(const char *id);
 void vnc_display_open(const char *id, Error **errp);
 void vnc_display_add_client(const char *id, int csock, bool skipauth);
 char *vnc_display_local_addr(const char *id);
-void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts);
 #ifdef CONFIG_VNC
 int vnc_display_password(const char *id, const char *password);
 int vnc_display_pw_expire(const char *id, time_t expires);
diff --git a/qmp.c b/qmp.c
index d701cff..c479e77 100644
--- a/qmp.c
+++ b/qmp.c
@@ -391,7 +391,6 @@ static void qmp_change_vnc_listen(const char *target, Error 
**errp)
 return;
 }
 
-vnc_auto_assign_id(olist, opts);
 vnc_display_open("default", errp);
 }
 
diff --git a/ui/vnc.c b/ui/vnc.c
index 10a2724..ff0b5bd 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3687,12 +3687,7 @@ void vnc_display_add_client(const char *id, int csock, 
bool skipauth)
 vnc_connect(vs, csock, skipauth, false);
 }
 
-QemuOpts *vnc_parse_func(const char *str)
-{
-return qemu_opts_parse(qemu_find_opts("vnc"), str, 1);
-}
-
-void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts)
+static void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts)
 {
 int i = 2;
 char *id;
@@ -3705,18 +3700,25 @@ void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts 
*opts)
 qemu_opts_set_id(opts, id);
 }
 
-int vnc_init_func(QemuOpts *opts, void *opaque)
+QemuOpts *vnc_parse_func(const char *str)
 {
-Error *local_err = NULL;
 QemuOptsList *olist = qemu_find_opts("vnc");
-char *id = (char *)qemu_opts_id(opts);
+QemuOpts *opts = qemu_opts_parse(olist, str, 1);
+const char *id = qemu_opts_id(opts);
 
 if (!id) {
 /* auto-assign id if not present */
 vnc_auto_assign_id(olist, opts);
-id = (char *)qemu_opts_id(opts);
 }
+return opts;
+}
+
+int vnc_init_func(QemuOpts *opts, void *opaque)
+{
+Error *local_err = NULL;
+char *id = (char *)qemu_opts_id(opts);
 
+assert(id);
 vnc_display_init(id);
 vnc_display_open(id, &local_err);
 if (local_err != NULL) {
-- 
1.8.3.1




[Qemu-devel] [PATCH 2/2] vnc: -readconfig fix

2015-02-17 Thread Gerd Hoffmann
Now that -vnc goes through QemuOpts we can get vnc configuration
via -readconfig too.  So setting display_remote in the command
line parsing code doesn't cut it any more, we must check QemuOpts
instead to see whenever any vnc display is configured.

Reported-by: Markus Armbruster 
Signed-off-by: Gerd Hoffmann 
---
 vl.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/vl.c b/vl.c
index 8c8f142..6677f6c 100644
--- a/vl.c
+++ b/vl.c
@@ -2000,7 +2000,6 @@ static DisplayType select_display(const char *p)
 } else if (strstart(p, "vnc", &opts)) {
 #ifdef CONFIG_VNC
 if (*opts == '=') {
-display_remote++;
 if (vnc_parse_func(opts+1) == NULL) {
 exit(1);
 }
@@ -3474,7 +3473,6 @@ int main(int argc, char **argv, char **envp)
 break;
 case QEMU_OPTION_vnc:
 #ifdef CONFIG_VNC
-display_remote++;
 if (vnc_parse_func(optarg) == NULL) {
 exit(1);
 }
@@ -3967,6 +3965,11 @@ int main(int argc, char **argv, char **envp)
 }
 }
 
+#if defined(CONFIG_VNC)
+if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) {
+display_remote++;
+}
+#endif
 if (display_type == DT_DEFAULT && !display_remote) {
 #if defined(CONFIG_GTK)
 display_type = DT_GTK;
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v2 1/4] virtio-pci: add flags to enable/disable legacy/modern

2015-02-17 Thread Gerd Hoffmann
On Di, 2015-02-17 at 09:42 +0100, Michael S. Tsirkin wrote:
> On Tue, Feb 17, 2015 at 09:23:35AM +0100, Gerd Hoffmann wrote:
> >   Hi,
> > 
> > > Should we forbid setting both legacy and modern at the same time?
> > 
> > No, this is explicitly allowed in the spec and it is needed for the
> > transition from legacy to modern.
> > 
> > cheers,
> >   Gerd
> 
> But !legacy && !modern aren't legal together, correct?

That doesn't make sense indeed.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH v3] ui/cocoa.m: Machine menu patch for Mac OS X

2015-02-17 Thread Kevin Wolf
Am 16.02.2015 um 18:00 hat Programmingkid geschrieben:
> 
> On Feb 16, 2015, at 11:22 AM, Kevin Wolf wrote:
> 
> > Am 16.02.2015 um 17:12 hat Programmingkid geschrieben:
> >> 
> >> On Feb 16, 2015, at 10:42 AM, Kevin Wolf wrote:
> >> 
> >>> Am 16.02.2015 um 16:31 hat Programmingkid geschrieben:
>  
>  On Feb 16, 2015, at 5:08 AM, Kevin Wolf wrote:
>  
> > Am 14.02.2015 um 03:28 hat Peter Maydell geschrieben:
> >> On 14 February 2015 at 01:43, Programmingkid 
> >>  wrote:
> >>> Added features:
> >>> Menu items to switch floppy and CD image files.
> >>> Menu items to eject floppy and CD image files.
> >>> Menu item to use /dev/cdrom.
> >>> Verifies with the user before quitting QEMU by displaying a dialog 
> >>> box.
> >>> 
> >>> Signed-off-by: John Arbuckle 
> >> 
> >> Stefan, Kevin -- could you review the bits of this patch
> >> which determine whether the machine has a floppy/cdrom
> >> drive and if so let the user insert/inject it, please?
> >> (that's the emulatorHasDevice and ejectFloppy/changeFloppy
> >> functions, mostly). I don't know the block layer APIs so
> >> I can't really say if this patch is doing it in the best/
> >> non-deprecated/etc way or not...
> > 
> > Well, it's trying to detect the floppy/cdrom device by comparing string
> > with default IDs that can be overridden by the user, so no, that's
> > probably far from the best way to do it. The code also doesn't consider
> > that you could have more than one floppy or cdrom drive.
> > 
> > The correct way is probably to just display any removable block device,
> > and ideally also to implement some notifiers to deal with hotplug.
>  
>  Could you provide examples?
> >>> 
> >>> You already use qmp_query_block(), so you get all existing devices.
> >>> Currently you filter for everything that has a name that starts with
> >>> either 'floppy' or 'cdrom'. You could filter for info->removable == true
> >>> instead.
> >> 
> >> 
> >>> 
> >>> Of course, you'd have to do this while building up the menu, so that the
> >>> menu will contain dynamically generated entries for every device.
> >>> 
> >>> Hotplug is a bit trickier, I guess. If you can make sure that qemu
> >>> doesn't crash if the device for a menu entry has gone away, that would
> >>> probably be acceptable for the start.
> >> 
> >> So what you want me to do is loop thru each entry in the BlockInfoList 
> >> (returned by qmp_query_block() ) and see if it is removable. Then just add 
> >> a menu item for the device name. If I did that we would have menu items 
> >> like "ide1-cd0" and "floppy0". The menu items would not have intuitive 
> >> names that the user would be able to understand easily. Sorry but your 
> >> idea is not user friendly. I did look at the type field of the 
> >> BlockInfoList structure and it is only set to "unknown". Maybe a 
> >> compromise would be the solution. We set the type field to the common name 
> >> of the device. "ide1-cd0" would have a type field set to "cdrom". Then set 
> >> the menu item to this type field's value. 
> > 
> > You could still apply some translation table to the menu entry string,
> > like:
> > 
> > floppy0 => Floppy drive A
> > floppy1 => Floppy drive B
> > ide0-cd0=> IDE CD-ROM (Primary Master)
> > ide0-cd1=> IDE CD-ROM (Primary Slave)
> > ide1-cd0=> IDE CD-ROM (Secondary Master)
> > ide1-cd1=> IDE CD-ROM (Secondary Slave)
> > 
> > And everything else just gets the block device ID in the menu name. Then
> > you get user friendly menu entry names where we have an idea what the
> > device might be, but still let the device show up with an identifiable
> > name when we don't.
> > 
> > Because having a CD-ROM drive not show up at all is definitely even less
> > user friendly than having a cryptic name for it.
> 
> This is a good start, but still needs more work. Is it safe to assume all 
> cdrom drives in QEMU will have "cd" in its name? scsi0-cd0, ide0-cd0,...

The ID is user-defined, so no, no assumption about it is safe.  If you
like, you can name your floppy drive 'ide0-cd1', your virtio harddisk
'floppy1' and your ATAPI CD-ROM drive 'virtio0'. But if you do that,
I think it's reasonable to argue that it's your own fault that you get
misleading menu entries. The default would yield the right results
anyway.

The only other option would be to start at the device tree, look for
all known block devices with removable media, and then get the
associated block backend from there. That would end up a lot more
complicated, though.

> I will still give every drive that has its removable property set to true a 
> menu item. Is it ok to translate anything that has "-cd#" in its name as 
> cdrom instead of using a translation table? A search algorithm I had in mind 
> is look for anything that has a "cd" after a hyphen. If it is found, 
> translate it to "cdrom". If there are more than one of these

Re: [Qemu-devel] [PATCH] virtio-blk: Check return value of blk_aio_ioctl

2015-02-17 Thread Kevin Wolf
Am 17.02.2015 um 04:29 hat Fam Zheng geschrieben:
> Since commit 1dc936aa84 (virtio-blk: Use blk_aio_ioctl) we silently lose
> the request if blk_aio_ioctl returns NULL (not implemented).
> 
> Fix it by directly returning VIRTIO_BLK_S_UNSUPP as we used to do.
> 
> Signed-off-by: Fam Zheng 
> ---
>  hw/block/virtio-blk.c | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index 1a8a176..c7c8f20 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -197,6 +197,7 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq *req)
>  VirtIODevice *vdev = VIRTIO_DEVICE(req->dev);
>  VirtQueueElement *elem = &req->elem;
>  VirtIOBlock *blk = req->dev;
> +BlockAIOCB *acb;
>  
>  #ifdef __linux__
>  int i;
> @@ -278,8 +279,12 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq 
> *req)
>  ioctl_req->hdr.sbp = elem->in_sg[elem->in_num - 3].iov_base;
>  ioctl_req->hdr.mx_sb_len = elem->in_sg[elem->in_num - 3].iov_len;
>  
> -blk_aio_ioctl(blk->blk, SG_IO, &ioctl_req->hdr,
> -  virtio_blk_ioctl_complete, ioctl_req);
> +acb = blk_aio_ioctl(blk->blk, SG_IO, &ioctl_req->hdr,
> +virtio_blk_ioctl_complete, ioctl_req);
> +if (!acb) {
> +status = VIRTIO_BLK_S_UNSUPP;
> +goto fail;
> +}
>  return -EINPROGRESS;
>  #else
>  abort();

This leaks ioctl_req.

Kevin



Re: [Qemu-devel] [PATCH v3] ui/cocoa.m: Machine menu patch for Mac OS X

2015-02-17 Thread Peter Maydell
On 17 February 2015 at 18:07, Kevin Wolf  wrote:
> The ID is user-defined, so no, no assumption about it is safe.  If you
> like, you can name your floppy drive 'ide0-cd1', your virtio harddisk
> 'floppy1' and your ATAPI CD-ROM drive 'virtio0'. But if you do that,
> I think it's reasonable to argue that it's your own fault that you get
> misleading menu entries. The default would yield the right results
> anyway.

Probably wise to have the menu entry include the id string as
well as any guessed friendly name (or just the id string in cases
where we can't come up with a guess).

-- PMM



[Qemu-devel] [PATCH] console/gtk: add qemu_console_get_label

2015-02-17 Thread Gerd Hoffmann
Add a new function to get a nice label for a given QemuConsole.
Drop the labeling code in gtk.c and use the new function instead.

Signed-off-by: Gerd Hoffmann 
---
 include/ui/console.h |  1 +
 ui/console.c | 15 +++
 ui/gtk.c | 12 +---
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 8a4d671..d4439a5 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -309,6 +309,7 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState 
*dev, uint32_t head);
 bool qemu_console_is_visible(QemuConsole *con);
 bool qemu_console_is_graphic(QemuConsole *con);
 bool qemu_console_is_fixedsize(QemuConsole *con);
+char *qemu_console_get_label(QemuConsole *con);
 int qemu_console_get_index(QemuConsole *con);
 uint32_t qemu_console_get_head(QemuConsole *con);
 QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con);
diff --git a/ui/console.c b/ui/console.c
index 87574a7..b64a73e 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1788,6 +1788,21 @@ bool qemu_console_is_fixedsize(QemuConsole *con)
 return con && (con->console_type != TEXT_CONSOLE);
 }
 
+char *qemu_console_get_label(QemuConsole *con)
+{
+if (con->console_type == GRAPHIC_CONSOLE) {
+if (con->device) {
+return g_strdup(object_get_typename(con->device));
+}
+return g_strdup("VGA");
+} else {
+if (con->chr && con->chr->label) {
+return g_strdup(con->chr->label);
+}
+return g_strdup_printf("vc%d", con->index);
+}
+}
+
 int qemu_console_get_index(QemuConsole *con)
 {
 if (con == NULL) {
diff --git a/ui/gtk.c b/ui/gtk.c
index b271ee4..f22d835 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1702,17 +1702,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, 
VirtualConsole *vc,
   QemuConsole *con, int idx,
   GSList *group, GtkWidget *view_menu)
 {
-Object *obj;
-
-obj = object_property_get_link(OBJECT(con), "device", NULL);
-if (obj) {
-vc->label = g_strdup_printf("%s", object_get_typename(obj));
-} else if (qemu_console_is_graphic(con)) {
-vc->label = g_strdup_printf("VGA");
-} else {
-vc->label = g_strdup_printf("vc%d", idx);
-}
-
+vc->label = qemu_console_get_label(con);
 vc->s = s;
 vc->gfx.scale_x = 1.0;
 vc->gfx.scale_y = 1.0;
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH] virtio-blk: Check return value of blk_aio_ioctl

2015-02-17 Thread Fam Zheng
On Tue, 02/17 10:34, Kevin Wolf wrote:
> Am 17.02.2015 um 04:29 hat Fam Zheng geschrieben:
> > Since commit 1dc936aa84 (virtio-blk: Use blk_aio_ioctl) we silently lose
> > the request if blk_aio_ioctl returns NULL (not implemented).
> > 
> > Fix it by directly returning VIRTIO_BLK_S_UNSUPP as we used to do.
> > 
> > Signed-off-by: Fam Zheng 
> > ---
> >  hw/block/virtio-blk.c | 9 +++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> > index 1a8a176..c7c8f20 100644
> > --- a/hw/block/virtio-blk.c
> > +++ b/hw/block/virtio-blk.c
> > @@ -197,6 +197,7 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq 
> > *req)
> >  VirtIODevice *vdev = VIRTIO_DEVICE(req->dev);
> >  VirtQueueElement *elem = &req->elem;
> >  VirtIOBlock *blk = req->dev;
> > +BlockAIOCB *acb;
> >  
> >  #ifdef __linux__
> >  int i;
> > @@ -278,8 +279,12 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq 
> > *req)
> >  ioctl_req->hdr.sbp = elem->in_sg[elem->in_num - 3].iov_base;
> >  ioctl_req->hdr.mx_sb_len = elem->in_sg[elem->in_num - 3].iov_len;
> >  
> > -blk_aio_ioctl(blk->blk, SG_IO, &ioctl_req->hdr,
> > -  virtio_blk_ioctl_complete, ioctl_req);
> > +acb = blk_aio_ioctl(blk->blk, SG_IO, &ioctl_req->hdr,
> > +virtio_blk_ioctl_complete, ioctl_req);
> > +if (!acb) {
> > +status = VIRTIO_BLK_S_UNSUPP;
> > +goto fail;
> > +}
> >  return -EINPROGRESS;
> >  #else
> >  abort();
> 
> This leaks ioctl_req.
> 

Yes, will fix in v2. Thanks,

Fam



[Qemu-devel] [PATCH v2] virtio-blk: Check return value of blk_aio_ioctl

2015-02-17 Thread Fam Zheng
Since commit 1dc936aa84 (virtio-blk: Use blk_aio_ioctl) we silently lose
the request if blk_aio_ioctl returns NULL (not implemented).

Fix it by directly returning VIRTIO_BLK_S_UNSUPP as we used to do.

Signed-off-by: Fam Zheng 

---
v2: Fix the leak of ioctl_req. (Kevin)
---
 hw/block/virtio-blk.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 1a8a176..91aceaa 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -197,6 +197,7 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq *req)
 VirtIODevice *vdev = VIRTIO_DEVICE(req->dev);
 VirtQueueElement *elem = &req->elem;
 VirtIOBlock *blk = req->dev;
+BlockAIOCB *acb;
 
 #ifdef __linux__
 int i;
@@ -278,8 +279,13 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq *req)
 ioctl_req->hdr.sbp = elem->in_sg[elem->in_num - 3].iov_base;
 ioctl_req->hdr.mx_sb_len = elem->in_sg[elem->in_num - 3].iov_len;
 
-blk_aio_ioctl(blk->blk, SG_IO, &ioctl_req->hdr,
-  virtio_blk_ioctl_complete, ioctl_req);
+acb = blk_aio_ioctl(blk->blk, SG_IO, &ioctl_req->hdr,
+virtio_blk_ioctl_complete, ioctl_req);
+if (!acb) {
+g_free(ioctl_req);
+status = VIRTIO_BLK_S_UNSUPP;
+goto fail;
+}
 return -EINPROGRESS;
 #else
 abort();
-- 
2.1.0




Re: [Qemu-devel] [PATCH v3] ui/cocoa.m: Machine menu patch for Mac OS X

2015-02-17 Thread Kevin Wolf
Am 17.02.2015 um 10:41 hat Peter Maydell geschrieben:
> On 17 February 2015 at 18:07, Kevin Wolf  wrote:
> > The ID is user-defined, so no, no assumption about it is safe.  If you
> > like, you can name your floppy drive 'ide0-cd1', your virtio harddisk
> > 'floppy1' and your ATAPI CD-ROM drive 'virtio0'. But if you do that,
> > I think it's reasonable to argue that it's your own fault that you get
> > misleading menu entries. The default would yield the right results
> > anyway.
> 
> Probably wise to have the menu entry include the id string as
> well as any guessed friendly name (or just the id string in cases
> where we can't come up with a guess).

Yes, that's a good suggestion.

Kevin



Re: [Qemu-devel] [PATCH 3/4] util: Remove unused functions

2015-02-17 Thread Thomas Huth

 Hi,

On Tue, 17 Feb 2015 09:55:33 +0100
Markus Armbruster  wrote:

> Thomas Huth  writes:
> 
> > Delete the unused functions qemu_opt_get_number_del(),
> > qemu_signalfd_available(), qemu_send_full() and qemu_recv_full().
> >
> > Signed-off-by: Thomas Huth 
> 
> qemu_opt_get_number_del() was added in commit 782730b along with
> qemu_opt_get_del(), qemu_opt_get_bool_del() and qemu_opt_get_size_del().
> It hasn't been used so far, but removing it makes the interface
> irregular.  I'd rather not.

Ok, then let's keep them.

> qemu_signalfd_available() is unused since commit 6d32717.  It's also the
> only user of CONFIG_SIGNALFD.  If we want to drop it, I recommend
> dropping CONFIG_SIGNALFD as well.

As far as I can see, CONFIG_SIGNALFD is still used in qemu_signalfd(),
so I think we've got to keep that.

 Thomas




[Qemu-devel] [PATCH 2/4] acpi-build: fix ACPI RAM management

2015-02-17 Thread Michael S. Tsirkin
This fixes multiple issues around ACPI RAM management:

RSDP and linker RAM aren't currently marked dirty
on update, so they won't be migrated correctly.

Let's handle all tables in the same way: set correct size (assert if
too big), update, mark RAM dirty.

This also drops assert checking that table size didn't change: table
size is fundamentally dynamic and depends on hw configuration,
just set the correct size and use that (memory core asserts if size is
too large).

This also means we can drop tracking table size, memory core does this
for us now.

Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c | 43 +++
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 1dfdf35..e78d6cb 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1266,13 +1266,12 @@ typedef
 struct AcpiBuildState {
 /* Copy of table in RAM (for patching). */
 ram_addr_t table_ram;
-uint32_t table_size;
 /* Is table patched? */
 uint8_t patched;
 PcGuestInfo *guest_info;
 void *rsdp;
+ram_addr_t rsdp_ram;
 ram_addr_t linker_ram;
-uint32_t linker_size;
 } AcpiBuildState;
 
 static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
@@ -1455,6 +1454,17 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables 
*tables)
 g_array_free(table_offsets, true);
 }
 
+static void acpi_ram_update(ram_addr_t ram, GArray *data)
+{
+uint32_t size = acpi_data_len(data);
+
+/* Make sure RAM size is correct - in case it got changed e.g. by 
migration */
+qemu_ram_resize(ram, size, &error_abort);
+
+memcpy(qemu_get_ram_ptr(ram), data->data, size);
+cpu_physical_memory_set_dirty_range_nocode(ram, size);
+}
+
 static void acpi_build_update(void *build_opaque, uint32_t offset)
 {
 AcpiBuildState *build_state = build_opaque;
@@ -1470,21 +1480,15 @@ static void acpi_build_update(void *build_opaque, 
uint32_t offset)
 
 acpi_build(build_state->guest_info, &tables);
 
-assert(acpi_data_len(tables.table_data) == build_state->table_size);
+acpi_ram_update(build_state->table_ram, tables.table_data);
 
-/* Make sure RAM size is correct - in case it got changed by migration */
-qemu_ram_resize(build_state->table_ram, build_state->table_size,
-&error_abort);
-
-memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
-   build_state->table_size);
-memcpy(build_state->rsdp, tables.rsdp->data, acpi_data_len(tables.rsdp));
-memcpy(qemu_get_ram_ptr(build_state->linker_ram), tables.linker->data,
-   build_state->linker_size);
-
-cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
-   build_state->table_size);
+if (build_state->rsdp) {
+memcpy(build_state->rsdp, tables.rsdp->data, 
acpi_data_len(tables.rsdp));
+} else {
+acpi_ram_update(build_state->rsdp_ram, tables.rsdp);
+}
 
+acpi_ram_update(build_state->linker_ram, tables.linker);
 acpi_build_tables_cleanup(&tables, true);
 }
 
@@ -1545,11 +1549,9 @@ void acpi_setup(PcGuestInfo *guest_info)
ACPI_BUILD_TABLE_FILE,
ACPI_BUILD_TABLE_MAX_SIZE);
 assert(build_state->table_ram != RAM_ADDR_MAX);
-build_state->table_size = acpi_data_len(tables.table_data);
 
 build_state->linker_ram =
 acpi_add_rom_blob(build_state, tables.linker, "etc/table-loader", 0);
-build_state->linker_size = acpi_data_len(tables.linker);
 
 fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
 tables.tcpalog->data, acpi_data_len(tables.tcpalog));
@@ -1564,10 +1566,11 @@ void acpi_setup(PcGuestInfo *guest_info)
  acpi_build_update, build_state,
  tables.rsdp->data, 
acpi_data_len(tables.rsdp));
 build_state->rsdp = tables.rsdp->data;
+build_state->rsdp_ram = (ram_addr_t)-1;
 } else {
-build_state->rsdp = qemu_get_ram_ptr(
-acpi_add_rom_blob(build_state, tables.rsdp, ACPI_BUILD_RSDP_FILE, 
0)
-);
+build_state->rsdp = NULL;
+build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
+  ACPI_BUILD_RSDP_FILE, 0);
 }
 
 qemu_register_reset(acpi_build_reset, build_state);
-- 
MST




[Qemu-devel] [PATCH 0/4] acpi: fix RSDP and linker memory management

2015-02-17 Thread Michael S. Tsirkin
This cleans up handling for rsdp and linker tables, which many people found
confusing, and fixes bugs around linker and rsdp migration.

Paolo, could you review/ack exec.c patch please?

Michael S. Tsirkin (4):
  exec: round up size on MR resize
  acpi-build: fix RSDP/linker RAM migration
  acpi: has_immutable_rsdp->!rsdp_in_ram
  acpi-build: simplify rsdp management for legacy

 include/hw/i386/pc.h |  2 +-
 exec.c   |  2 ++
 hw/i386/acpi-build.c | 55 
 hw/i386/pc_piix.c|  6 +++---
 hw/i386/pc_q35.c |  6 +++---
 5 files changed, 39 insertions(+), 32 deletions(-)

-- 
MST




[Qemu-devel] [PATCH 3/4] acpi: has_immutable_rsdp->!rsdp_in_ram

2015-02-17 Thread Michael S. Tsirkin
As comment in acpi-build.c notes, RSDP is not really immutable.  So it's
really a question of whether it's in RAM, name the variable accordingly.

Signed-off-by: Michael S. Tsirkin 
---
 include/hw/i386/pc.h | 2 +-
 hw/i386/acpi-build.c | 2 +-
 hw/i386/pc_piix.c| 6 +++---
 hw/i386/pc_q35.c | 6 +++---
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index b0a80cf..0c595c5 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -104,7 +104,7 @@ struct PcGuestInfo {
 int legacy_acpi_table_size;
 bool has_acpi_build;
 bool has_reserved_memory;
-bool has_immutable_rsdp;
+bool rsdp_in_ram;
 };
 
 /* parallel.c */
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index e78d6cb..ffa3f00 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1556,7 +1556,7 @@ void acpi_setup(PcGuestInfo *guest_info)
 fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
 tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
-if (guest_info->has_immutable_rsdp) {
+if (!guest_info->rsdp_in_ram) {
 /*
  * Keep for compatibility with old machine types.
  * Though RSDP is small, its contents isn't immutable, so
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index e586c7b..13ff561 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -60,7 +60,7 @@ static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
 static bool has_acpi_build = true;
-static bool has_immutable_rsdp;
+static bool rsdp_in_ram = true;
 static int legacy_acpi_table_size;
 static bool smbios_defaults = true;
 static bool smbios_legacy_mode;
@@ -169,7 +169,7 @@ static void pc_init1(MachineState *machine,
 
 guest_info->isapc_ram_fw = !pci_enabled;
 guest_info->has_reserved_memory = has_reserved_memory;
-guest_info->has_immutable_rsdp = has_immutable_rsdp;
+guest_info->rsdp_in_ram = rsdp_in_ram;
 
 if (smbios_defaults) {
 MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -312,7 +312,7 @@ static void pc_init_pci(MachineState *machine)
 
 static void pc_compat_2_2(MachineState *machine)
 {
-has_immutable_rsdp = true;
+rsdp_in_ram = false;
 x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
 x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
 x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 6151f2f..c0f21fe 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -50,7 +50,7 @@
 #define MAX_SATA_PORTS 6
 
 static bool has_acpi_build = true;
-static bool has_immutable_rsdp;
+static bool rsdp_in_ram = true;
 static bool smbios_defaults = true;
 static bool smbios_legacy_mode;
 static bool smbios_uuid_encoded = true;
@@ -155,7 +155,7 @@ static void pc_q35_init(MachineState *machine)
 guest_info->isapc_ram_fw = false;
 guest_info->has_acpi_build = has_acpi_build;
 guest_info->has_reserved_memory = has_reserved_memory;
-guest_info->has_immutable_rsdp = has_immutable_rsdp;
+guest_info->rsdp_in_ram = rsdp_in_ram;
 
 /* Migration was not supported in 2.0 for Q35, so do not bother
  * with this hack (see hw/i386/acpi-build.c).
@@ -291,7 +291,7 @@ static void pc_q35_init(MachineState *machine)
 
 static void pc_compat_2_2(MachineState *machine)
 {
-has_immutable_rsdp = true;
+rsdp_in_ram = false;
 x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
 x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
 x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);
-- 
MST




[Qemu-devel] [PATCH 1/4] exec: round up size on MR resize

2015-02-17 Thread Michael S. Tsirkin
Block size must fundamentally be a multiple of target page size.
Aligning automatically removes need to worry about the alignment
from callers.

Note: the only caller of qemu_ram_resize (acpi) already happens to have
size padded to a power of 2, but we would like to drop the padding in
ACPI core, and don't want to expose target page size knowledge to ACPI.

Signed-off-by: Michael S. Tsirkin 
---
 exec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/exec.c b/exec.c
index 6b79ad1..2433406 100644
--- a/exec.c
+++ b/exec.c
@@ -1298,6 +1298,8 @@ int qemu_ram_resize(ram_addr_t base, ram_addr_t newsize, 
Error **errp)
 
 assert(block);
 
+newsize = TARGET_PAGE_ALIGN(newsize);
+
 if (block->used_length == newsize) {
 return 0;
 }
-- 
MST




[Qemu-devel] [PATCH 4/4] acpi-build: simplify rsdp management for legacy

2015-02-17 Thread Michael S. Tsirkin
For legacy machine types, rsdp is not in RAM, so we need a copy of rsdp
for fw cfg. We previously used g_array_free with false parameter,
but this seems to confuse people.
This also wastes a bit of memory as the buffer is unused for new
machine types.

Let's just use plain g_memdup, and free original memory together with
the array.

TODO: rationalize tcpalog memory management, and get rid of the mfre
parameter.

Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index ffa3f00..f712277 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1257,7 +1257,7 @@ static inline void 
acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
 {
 void *linker_data = bios_linker_loader_cleanup(tables->linker);
 g_free(linker_data);
-g_array_free(tables->rsdp, mfre);
+g_array_free(tables->rsdp, true);
 g_array_free(tables->table_data, true);
 g_array_free(tables->tcpalog, mfre);
 }
@@ -1560,12 +1560,14 @@ void acpi_setup(PcGuestInfo *guest_info)
 /*
  * Keep for compatibility with old machine types.
  * Though RSDP is small, its contents isn't immutable, so
- * update it along with the rest of tables on guest access.
+ * we'll update it along with the rest of tables on guest access.
  */
+uint32_t rsdp_size = acpi_data_len(tables.rsdp);
+
+build_state->rsdp = g_memdup(tables.rsdp->data, rsdp_size);
 fw_cfg_add_file_callback(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
  acpi_build_update, build_state,
- tables.rsdp->data, 
acpi_data_len(tables.rsdp));
-build_state->rsdp = tables.rsdp->data;
+ build_state->rsdp, rsdp_size);
 build_state->rsdp_ram = (ram_addr_t)-1;
 } else {
 build_state->rsdp = NULL;
-- 
MST




[Qemu-devel] [RFC PATCH 2/7] hw/arm/virt-acpi-build: Add GPIO controller in ACPI DSDT table

2015-02-17 Thread Shannon Zhao
Add GPIO controller in ACPI DSDT table. It can be used
for device hotplug.

Signed-off-by: Shannon Zhao 
---
 hw/arm/virt-acpi-build.c |   21 +
 hw/arm/virt.c|2 ++
 include/hw/arm/virt-acpi-build.h |2 ++
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index bfbddbe..4f26551 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -176,6 +176,26 @@ static void acpi_dsdt_add_virtio(Aml *scope, const hwaddr 
*mmio_addrs,
 }
 }
 
+static void acpi_dsdt_add_gpio(Aml *scope, const hwaddr *gpio_addrs,
+   const int *gpio_irq)
+{
+Aml *dev, *crs;
+
+dev = aml_device("GPO0");
+aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0009")));
+aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
+aml_append(dev, aml_name_decl("_UID", aml_int(0)));
+
+crs = aml_resource_template();
+aml_append(crs,
+   aml_memory32_fixed(gpio_addrs[0], gpio_addrs[1], 0x01));
+aml_append(crs,
+   aml_interrupt(0x01, *gpio_irq + 32));
+aml_append(dev, aml_name_decl("_CRS", crs));
+
+aml_append(scope, dev);
+}
+
 /* RSDP */
 static GArray *
 build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
@@ -343,6 +363,7 @@ build_dsdt(Aml *table_data, GArray *linker, VirtGuestInfo 
*guest_info)
 acpi_dsdt_add_flash(scope, info->flash_addr);
 acpi_dsdt_add_virtio(scope, info->virtio_mmio_addr,
  info->virtio_mmio_irq, info->virtio_mmio_num);
+acpi_dsdt_add_gpio(scope, info->gpio_addr, info->gpio_irq);
 
 aml_append(dsdt, scope);
 aml_append(table_data, dsdt);
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 43c0260..f689bc3 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -159,6 +159,8 @@ static const struct acpi_dsdt_info dsdt_info = {
 .virtio_mmio_addr = &a15memmap[VIRT_MMIO].base,
 .virtio_mmio_irq = &a15irqmap[VIRT_MMIO],
 .virtio_mmio_num = NUM_VIRTIO_TRANSPORTS,
+.gpio_addr = &a15memmap[VIRT_GPIO].base,
+.gpio_irq = &a15irqmap[VIRT_GPIO],
 .rtc_addr = &a15memmap[VIRT_RTC].base,
 .rtc_irq = &a15irqmap[VIRT_RTC],
 .flash_addr = &a15memmap[VIRT_FLASH].base,
diff --git a/include/hw/arm/virt-acpi-build.h b/include/hw/arm/virt-acpi-build.h
index 451edc9..de8d4c6 100644
--- a/include/hw/arm/virt-acpi-build.h
+++ b/include/hw/arm/virt-acpi-build.h
@@ -47,6 +47,8 @@ struct acpi_dsdt_info {
 const hwaddr *virtio_mmio_addr;
 const int *virtio_mmio_irq;
 int virtio_mmio_num;
+const hwaddr *gpio_addr;
+const int *gpio_irq;
 const hwaddr *rtc_addr;
 const int *rtc_irq;
 const hwaddr *flash_addr;
-- 
1.7.1





[Qemu-devel] [RFC PATCH 3/7] hw/acpi/virt-hotplug: Add a hotplug device for machine virt

2015-02-17 Thread Shannon Zhao
Add a hotplug device for machine virt. This can be used for virt
to support device hotplug. At the moment this hotplug device just
include a mmio region which shows the present status of cpus.

Signed-off-by: Shannon Zhao 
---
 default-configs/arm-softmmu.mak |2 +
 hw/acpi/Makefile.objs   |1 +
 hw/acpi/cpu_hotplug.c   |   16 +
 hw/acpi/ich9.c  |   12 
 hw/acpi/piix4.c |   12 
 hw/acpi/virt-hotplug.c  |  130 +++
 include/hw/acpi/cpu_hotplug.h   |6 +-
 include/hw/acpi/virt-hotplug.h  |   10 +++
 8 files changed, 172 insertions(+), 17 deletions(-)
 create mode 100644 hw/acpi/virt-hotplug.c
 create mode 100644 include/hw/acpi/virt-hotplug.h

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 3c89f53..bb74707 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -89,3 +89,5 @@ CONFIG_ALLWINNER_A10_PIT=y
 CONFIG_ALLWINNER_A10_PIC=y
 CONFIG_ALLWINNER_A10=y
 CONFIG_ACPI=y
+CONFIG_VIRT_HOTPLUG=y
+CONFIG_ACPI_CPU_HOTPLUG=y
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 511771a..4bc5a4d 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -4,3 +4,4 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
 common-obj-$(CONFIG_ACPI) += acpi_interface.o
 common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
 common-obj-$(CONFIG_ACPI) += aml-build.o
+common-obj-$(CONFIG_VIRT_HOTPLUG) += virt-hotplug.o
diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index b8ebfad..dbc7e94 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,7 +36,7 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
-static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
+void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
  Error **errp)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
@@ -51,20 +51,8 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, 
CPUState *cpu,
 g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
 }
 
-void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
-  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
-{
-acpi_set_cpu_present_bit(g, CPU(dev), errp);
-if (*errp != NULL) {
-return;
-}
-
-ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
-acpi_update_sci(ar, irq);
-}
-
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
-   AcpiCpuHotplug *gpe_cpu, uint16_t base)
+   AcpiCpuHotplug *gpe_cpu, uint64_t base)
 {
 CPUState *cpu;
 
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 5352e19..6c4422a 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -383,6 +383,18 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs 
*pm, Error **errp)
 NULL, pm, NULL);
 }
 
+static void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+acpi_set_cpu_present_bit(g, CPU(dev), errp);
+if (*errp != NULL) {
+return;
+}
+
+ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)
 {
 if (pm->acpi_memory_hotplug.is_enabled &&
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index d1f1179..6faca8a 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -337,6 +337,18 @@ static void piix4_pm_powerdown_req(Notifier *n, void 
*opaque)
 acpi_pm1_evt_power_down(&s->ar);
 }
 
+static void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+acpi_set_cpu_present_bit(g, CPU(dev), errp);
+if (*errp != NULL) {
+return;
+}
+
+ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
  DeviceState *dev, Error **errp)
 {
diff --git a/hw/acpi/virt-hotplug.c b/hw/acpi/virt-hotplug.c
new file mode 100644
index 000..47da078
--- /dev/null
+++ b/hw/acpi/virt-hotplug.c
@@ -0,0 +1,130 @@
+/*
+ *
+ * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD.
+ *
+ * Author: Shannon Zhao 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see .
+ */
+
+#include "hw/hw.h"
+#include "hw/acpi/

[Qemu-devel] [RFC PATCH 1/7] hw/arm/virt: Add a GPIO controller

2015-02-17 Thread Shannon Zhao
Add a GPIO controller in machine virt, in order to support cpu hotplug.
Here we use pl061.

Signed-off-by: Shannon Zhao 
---
 hw/arm/virt.c |   28 
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 8a00574..43c0260 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -75,6 +75,7 @@ enum {
 VIRT_MMIO,
 VIRT_RTC,
 VIRT_FW_CFG,
+VIRT_GPIO,
 };
 
 typedef struct MemMapEntry {
@@ -133,6 +134,7 @@ static const MemMapEntry a15memmap[] = {
 [VIRT_UART] =   { 0x0900, 0x1000 },
 [VIRT_RTC] ={ 0x0901, 0x1000 },
 [VIRT_FW_CFG] = { 0x0902, 0x000a },
+[VIRT_GPIO] =   { 0x0950, 0x1000 },
 [VIRT_MMIO] =   { 0x0a00, 0x0200 },
 /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
 /* 0x1000 .. 0x4000 reserved for PCI */
@@ -142,6 +144,7 @@ static const MemMapEntry a15memmap[] = {
 static const int a15irqmap[] = {
 [VIRT_UART] = 1,
 [VIRT_RTC] = 2,
+[VIRT_GPIO] = 3,
 [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */
 };
 
@@ -465,6 +468,29 @@ static void create_rtc(const VirtBoardInfo *vbi, qemu_irq 
*pic)
 g_free(nodename);
 }
 
+static void create_gpio(const VirtBoardInfo *vbi, qemu_irq *pic)
+{
+char *nodename;
+hwaddr base = vbi->memmap[VIRT_GPIO].base;
+hwaddr size = vbi->memmap[VIRT_GPIO].size;
+int irq = vbi->irqmap[VIRT_GPIO];
+const char compat[] = "arm,pl061\0arm,primecell";
+
+sysbus_create_simple("pl061", base, pic[irq]);
+
+nodename = g_strdup_printf("/pl061@%" PRIx64, base);
+qemu_fdt_add_subnode(vbi->fdt, nodename);
+qemu_fdt_setprop_sized_cells(vbi->fdt, nodename, "reg",
+ 2, base, 2, size);
+qemu_fdt_setprop(vbi->fdt, nodename, "compatible", compat, sizeof(compat));
+qemu_fdt_setprop_cell(vbi->fdt, nodename, "#gpio-cells", 2);
+qemu_fdt_setprop(vbi->fdt, nodename, "gpio-controller", NULL, 0);
+qemu_fdt_setprop_cells(vbi->fdt, nodename, "interrupts",
+   GIC_FDT_IRQ_TYPE_SPI, irq,
+   GIC_FDT_IRQ_FLAGS_LEVEL_HI);
+g_free(nodename);
+}
+
 static void create_virtio_devices(const VirtBoardInfo *vbi, qemu_irq *pic)
 {
 int i;
@@ -680,6 +706,8 @@ static void machvirt_init(MachineState *machine)
 
 create_rtc(vbi, pic);
 
+create_gpio(vbi, pic);
+
 /* Create mmio transports, so the user can create virtio backends
  * (which will be automatically plugged in to the transports). If
  * no backend is created the transport will just sit harmlessly idle.
-- 
1.7.1





[Qemu-devel] [RFC PATCH 6/7] hw/arm/virt: Add cpu hotplug support

2015-02-17 Thread Shannon Zhao
Add a hotplug device in machine virt and add cpu hotplug support
using cpu-add.

Signed-off-by: Shannon Zhao 
---
 hw/arm/virt.c  |  159 +++-
 include/hw/acpi/virt-hotplug.h |1 +
 2 files changed, 159 insertions(+), 1 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index f689bc3..760afbb 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -43,6 +43,8 @@
 #include "qemu/bitops.h"
 #include "qemu/error-report.h"
 #include "hw/arm/virt-acpi-build.h"
+#include "hw/acpi/virt-hotplug.h"
+#include "hw/hotplug.h"
 
 #define NUM_VIRTIO_TRANSPORTS 32
 
@@ -76,6 +78,7 @@ enum {
 VIRT_RTC,
 VIRT_FW_CFG,
 VIRT_GPIO,
+VIRT_CPU_HOTPLUG,
 };
 
 typedef struct MemMapEntry {
@@ -102,8 +105,11 @@ typedef struct {
 typedef struct {
 MachineState parent;
 bool secure;
+HotplugHandler *acpi_dev;
 } VirtMachineState;
 
+#define VIRT_MACHINE_ACPI_DEVICE_PROP "acpi-device"
+
 #define TYPE_VIRT_MACHINE   "virt"
 #define VIRT_MACHINE(obj) \
 OBJECT_CHECK(VirtMachineState, (obj), TYPE_VIRT_MACHINE)
@@ -135,6 +141,7 @@ static const MemMapEntry a15memmap[] = {
 [VIRT_RTC] ={ 0x0901, 0x1000 },
 [VIRT_FW_CFG] = { 0x0902, 0x000a },
 [VIRT_GPIO] =   { 0x0950, 0x1000 },
+[VIRT_CPU_HOTPLUG] =   { 0x0960, 0x0020 },
 [VIRT_MMIO] =   { 0x0a00, 0x0200 },
 /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
 /* 0x1000 .. 0x4000 reserved for PCI */
@@ -381,7 +388,7 @@ static void create_gic(const VirtBoardInfo *vbi, qemu_irq 
*pic)
 
 gicdev = qdev_create(NULL, gictype);
 qdev_prop_set_uint32(gicdev, "revision", 2);
-qdev_prop_set_uint32(gicdev, "num-cpu", smp_cpus);
+qdev_prop_set_uint32(gicdev, "num-cpu", max_cpus);
 /* Note that the num-irq property counts both internal and external
  * interrupts; there are always 32 of the former (mandated by GIC spec).
  */
@@ -630,6 +637,136 @@ void virt_guest_info_machine_done(Notifier *notifier, 
void *data)
 virt_acpi_setup(&guest_info_state->info);
 }
 
+static void virt_new_cpu(const char *cpu_model, int64_t apic_id,
+  Error **errp)
+{
+ObjectClass *oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
+Object *cpuobj;
+VirtBoardInfo *vbi;
+SysBusDevice *gicbusdev;
+
+vbi = find_machine_info(cpu_model);
+
+if (!oc) {
+fprintf(stderr, "Unable to find CPU definition\n");
+exit(1);
+}
+cpuobj = object_new(object_class_get_name(oc));
+
+object_property_set_int(cpuobj, QEMU_PSCI_CONDUIT_HVC, "psci-conduit",
+NULL);
+
+/* Secondary CPUs start in PSCI powered-down state */
+object_property_set_bool(cpuobj, true, "start-powered-off", NULL);
+
+if (object_property_find(cpuobj, "reset-cbar", NULL)) {
+object_property_set_int(cpuobj, vbi->memmap[VIRT_CPUPERIPHS].base,
+"reset-cbar", &error_abort);
+}
+
+object_property_set_bool(cpuobj, true, "realized", NULL);
+
+const char *gictype = "arm_gic";
+if (kvm_irqchip_in_kernel()) {
+gictype = "kvm-arm-gic";
+}
+
+bool ambig;
+Object *o = object_resolve_path_type("", gictype, &ambig);
+DeviceState *gicdev = DEVICE(o);
+DeviceState *cpudev = DEVICE(cpuobj);
+gicbusdev = SYS_BUS_DEVICE(gicdev);
+int ppibase = NUM_IRQS + apic_id * 32;
+/* physical timer; we wire it up to the non-secure timer's ID,
+ * since a real A15 always has TrustZone but QEMU doesn't.
+ */
+qdev_connect_gpio_out(cpudev, 0,
+  qdev_get_gpio_in(gicdev, ppibase + 30));
+/* virtual timer */
+qdev_connect_gpio_out(cpudev, 1,
+  qdev_get_gpio_in(gicdev, ppibase + 27));
+
+sysbus_connect_irq(gicbusdev, apic_id,
+   qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
+}
+
+static const char *current_cpu_model;
+
+static void virt_hot_add_cpu(const int64_t id, Error **errp)
+{
+int64_t apic_id = arm_cpu_apic_id_from_index(id);
+if (id < 0) {
+error_setg(errp, "Invalid CPU id: %" PRIi64, id);
+return;
+}
+
+if (cpu_exists(apic_id)) {
+error_setg(errp, "Unable to add CPU: %" PRIi64
+   ", it already exists", id);
+return;
+}
+
+if (id >= max_cpus) {
+error_setg(errp, "Unable to add CPU: %" PRIi64
+   ", max allowed: %d", id, max_cpus - 1);
+return;
+}
+
+if (apic_id >= VIRT_ACPI_CPU_HOTPLUG_ID_LIMIT) {
+error_setg(errp, "Unable to add CPU: %" PRIi64
+   ", resulting APIC ID (%" PRIi64 ") is too large",
+   id, apic_id);
+return;
+}
+
+virt_new_cpu(current_cpu_model, apic_id, errp);
+}
+
+static void virt_cpu_plug(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+HotplugHandlerCla

[Qemu-devel] [RFC PATCH 4/7] topology: Move topology.h to an arch-independent location

2015-02-17 Thread Shannon Zhao
Move topology.h to an arch-independent location and the apicid_foo
can be reused by other architectures. And remove the x86 prefix.

Signed-off-by: Shannon Zhao 
---
 include/hw/acpi/topology.h |  134 
 target-i386/cpu.c  |4 +-
 target-i386/topology.h |  134 
 tests/test-x86-cpuid.c |   10 ++--
 4 files changed, 141 insertions(+), 141 deletions(-)
 create mode 100644 include/hw/acpi/topology.h
 delete mode 100644 target-i386/topology.h

diff --git a/include/hw/acpi/topology.h b/include/hw/acpi/topology.h
new file mode 100644
index 000..f341190
--- /dev/null
+++ b/include/hw/acpi/topology.h
@@ -0,0 +1,134 @@
+/*
+ *  CPU topology data structures and functions
+ *
+ *  Copyright (c) 2012 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef TARGET_ACPI_TOPOLOGY_H
+#define TARGET_ACPI_TOPOLOGY_H
+
+/* This file implements the APIC-ID-based CPU topology enumeration logic,
+ * documented at the following document:
+ *   Intel® 64 Architecture Processor Topology Enumeration
+ *   
http://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration/
+ *
+ * This code should be compatible with AMD's "Extended Method" described at:
+ *   AMD CPUID Specification (Publication #25481)
+ *   Section 3: Multiple Core Calcuation
+ * as long as:
+ *  nr_threads is set to 1;
+ *  OFFSET_IDX is assumed to be 0;
+ *  CPUID Fn8000_0008_ECX[ApicIdCoreIdSize[3:0]] is set to apicid_core_width().
+ */
+
+#include 
+#include 
+
+#include "qemu/bitops.h"
+
+/* APIC IDs can be 32-bit, but beware: APIC IDs > 255 require x2APIC support
+ */
+typedef uint32_t apic_id_t;
+
+/* Return the bit width needed for 'count' IDs
+ */
+static unsigned apicid_bitwidth_for_count(unsigned count)
+{
+g_assert(count >= 1);
+count -= 1;
+return count ? 32 - clz32(count) : 0;
+}
+
+/* Bit width of the SMT_ID (thread ID) field on the APIC ID
+ */
+static inline unsigned apicid_smt_width(unsigned nr_cores, unsigned nr_threads)
+{
+return apicid_bitwidth_for_count(nr_threads);
+}
+
+/* Bit width of the Core_ID field
+ */
+static inline unsigned apicid_core_width(unsigned nr_cores, unsigned 
nr_threads)
+{
+return apicid_bitwidth_for_count(nr_cores);
+}
+
+/* Bit offset of the Core_ID field
+ */
+static inline unsigned apicid_core_offset(unsigned nr_cores,
+  unsigned nr_threads)
+{
+return apicid_smt_width(nr_cores, nr_threads);
+}
+
+/* Bit offset of the Pkg_ID (socket ID) field
+ */
+static inline unsigned apicid_pkg_offset(unsigned nr_cores, unsigned 
nr_threads)
+{
+return apicid_core_offset(nr_cores, nr_threads) +
+   apicid_core_width(nr_cores, nr_threads);
+}
+
+/* Make APIC ID for the CPU based on Pkg_ID, Core_ID, SMT_ID
+ *
+ * The caller must make sure core_id < nr_cores and smt_id < nr_threads.
+ */
+static inline apic_id_t apicid_from_topo_ids(unsigned nr_cores,
+ unsigned nr_threads,
+ unsigned pkg_id,
+ unsigned core_id,
+ unsigned smt_id)
+{
+return (pkg_id  << apicid_pkg_offset(nr_cores, nr_threads)) |
+   (core_id << apicid_core_offset(nr_cores, nr_threads)) |
+   smt_id;
+}
+
+/* Calculate thread/core/package IDs for a specific topology,
+ * based on (contiguous) CPU index
+ */
+static inline void topo_ids_from_idx(unsigned nr_cores,
+ unsigned nr_threads,
+ unsigned cpu_index,
+ unsigned *pkg_id,
+ unsigned *core_id,
+ unsigned *smt_id)
+{
+unsigned core_index = cpu_index / nr_threads;
+ 

[Qemu-devel] [RFC PATCH 5/7] target-arm/cpu: Add apic_id property for ARMCPU

2015-02-17 Thread Shannon Zhao
Add apic_id property for ARMCPU. It can be used for cpu hotplug.

Signed-off-by: Shannon Zhao 
---
 target-arm/cpu-qom.h |1 +
 target-arm/cpu.c |   77 ++
 target-arm/cpu.h |2 +
 3 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/target-arm/cpu-qom.h b/target-arm/cpu-qom.h
index ed5a644..d4560e2 100644
--- a/target-arm/cpu-qom.h
+++ b/target-arm/cpu-qom.h
@@ -59,6 +59,7 @@ typedef struct ARMCPU {
 /*< public >*/
 
 CPUARMState env;
+uint32_t apic_id;
 
 /* Coprocessor information */
 GHashTable *cp_regs;
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 285947f..9202b07 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -23,12 +23,17 @@
 #include "qemu-common.h"
 #include "hw/qdev-properties.h"
 #include "qapi/qmp/qerror.h"
+#include "qapi-visit.h"
+#include "qapi/visitor.h"
+#include "hw/acpi/topology.h"
+
 #if !defined(CONFIG_USER_ONLY)
 #include "hw/loader.h"
 #endif
 #include "hw/arm/arm.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
+#include "sysemu/cpus.h"
 #include "kvm_arm.h"
 
 static void arm_cpu_set_pc(CPUState *cs, vaddr value)
@@ -332,6 +337,65 @@ static inline void unset_feature(CPUARMState *env, int 
feature)
 env->features &= ~(1ULL << feature);
 }
 
+static void arm_cpuid_get_apic_id(Object *obj, Visitor *v, void *opaque,
+  const char *name, Error **errp)
+{
+ARMCPU *cpu = ARM_CPU(obj);
+int64_t value = cpu->apic_id;
+
+visit_type_int(v, &value, name, errp);
+}
+
+static void arm_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque,
+  const char *name, Error **errp)
+{
+ARMCPU *cpu = ARM_CPU(obj);
+DeviceState *dev = DEVICE(obj);
+const int64_t min = 0;
+const int64_t max = UINT32_MAX;
+Error *error = NULL;
+int64_t value;
+
+if (dev->realized) {
+error_setg(errp, "Attempt to set property '%s' on '%s' after "
+   "it was realized", name, object_get_typename(obj));
+return;
+}
+
+visit_type_int(v, &value, name, &error);
+if (error) {
+error_propagate(errp, error);
+return;
+}
+if (value < min || value > max) {
+error_setg(errp, "Property %s.%s doesn't take value %" PRId64
+   " (minimum: %" PRId64 ", maximum: %" PRId64 ")" ,
+   object_get_typename(obj), name, value, min, max);
+return;
+}
+
+if ((value != cpu->apic_id) && cpu_exists(value)) {
+error_setg(errp, "CPU with APIC ID %" PRIi64 " exists", value);
+return;
+}
+cpu->apic_id = value;
+}
+
+/* Calculates initial APIC ID for a specific CPU index
+ *
+ * Currently we need to be able to calculate the APIC ID from the CPU index
+ * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces 
have
+ * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
+ * all CPUs up to max_cpus.
+ */
+uint32_t arm_cpu_apic_id_from_index(unsigned int cpu_index)
+{
+uint32_t correct_id;
+
+correct_id = apicid_from_cpu_idx(smp_cores, smp_threads, cpu_index);
+return correct_id;
+}
+
 static void arm_cpu_initfn(Object *obj)
 {
 CPUState *cs = CPU(obj);
@@ -343,6 +407,11 @@ static void arm_cpu_initfn(Object *obj)
 cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
  g_free, g_free);
 
+object_property_add(obj, "apic-id", "int",
+arm_cpuid_get_apic_id,
+arm_cpuid_set_apic_id, NULL, NULL, NULL);
+
+ cpu->apic_id = arm_cpu_apic_id_from_index(cs->cpu_index);
 #ifndef CONFIG_USER_ONLY
 /* Our inbound IRQ and FIQ lines */
 if (kvm_enabled()) {
@@ -379,6 +448,13 @@ static void arm_cpu_initfn(Object *obj)
 }
 }
 
+static int64_t arm_cpu_get_arch_id(CPUState *cs)
+{
+ARMCPU *cpu = ARM_CPU(cs);
+
+return cpu->apic_id;
+}
+
 static Property arm_cpu_reset_cbar_property =
 DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0);
 
@@ -1183,6 +1259,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->set_pc = arm_cpu_set_pc;
 cc->gdb_read_register = arm_cpu_gdb_read_register;
 cc->gdb_write_register = arm_cpu_gdb_write_register;
+cc->get_arch_id = arm_cpu_get_arch_id;
 #ifdef CONFIG_USER_ONLY
 cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
 #else
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index cd7a9e8..9e60972 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -1819,4 +1819,6 @@ enum {
 QEMU_PSCI_CONDUIT_HVC = 2,
 };
 
+uint32_t arm_cpu_apic_id_from_index(unsigned int cpu_index);
+
 #endif
-- 
1.7.1





[Qemu-devel] [RFC PATCH 0/7] hw/arm/virt: Add cpu-add way cpu hotplug support

2015-02-17 Thread Shannon Zhao
Add cpu-add hotplug support in machine virt. As there are some properties
which are set out of arm_cpu_initfn, so the way of device_add is not
supported now. This will add at next version. Some good suggestion?

This patchset is based on below patch:
[RFC PATCH v3 00/11] Generate ACPI v5.1 tables and  expose it to guest over 
fw_cfg on ARM
http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg03290.html

Have done compile test and start a Linux guest, execute cpu-add in monitor, use 
info cpu
to check a new cpu created. But as the guest kernel driver is not ready, so it 
can't be
used by guest now.

Any comments are welcome.
Thanks,
Shannon

Shannon Zhao (7):
  hw/arm/virt: Add a GPIO controller
  hw/arm/virt-acpi-build: Add GPIO controller in ACPI DSDT table
  hw/acpi/virt-hotplug: Add a hotplug device for machine virt
  topology: Move topology.h to an arch-independent location
  target-arm/cpu: Add apic_id property for ARMCPU
  hw/arm/virt: Add cpu hotplug support
  hw/arm/virt-acpi-build: Add cpu hotplug support in ACPI

 default-configs/arm-softmmu.mak  |2 +
 hw/acpi/Makefile.objs|1 +
 hw/acpi/aml-build.c  |  135 ++
 hw/acpi/cpu_hotplug.c|   16 +---
 hw/acpi/ich9.c   |   12 +++
 hw/acpi/piix4.c  |   12 +++
 hw/acpi/virt-hotplug.c   |  141 +++
 hw/arm/virt-acpi-build.c |  198 +-
 hw/arm/virt.c|  190 -
 include/hw/acpi/aml-build.h  |   13 +++
 include/hw/acpi/cpu_hotplug.h|6 +-
 include/hw/acpi/topology.h   |  134 +
 include/hw/acpi/virt-hotplug.h   |   11 ++
 include/hw/arm/virt-acpi-build.h |3 +
 target-arm/cpu-qom.h |1 +
 target-arm/cpu.c |   77 +++
 target-arm/cpu.h |2 +
 target-i386/cpu.c|4 +-
 target-i386/topology.h   |  134 -
 tests/test-x86-cpuid.c   |   10 +-
 20 files changed, 940 insertions(+), 162 deletions(-)
 create mode 100644 hw/acpi/virt-hotplug.c
 create mode 100644 include/hw/acpi/topology.h
 create mode 100644 include/hw/acpi/virt-hotplug.h
 delete mode 100644 target-i386/topology.h





[Qemu-devel] [RFC PATCH 7/7] hw/arm/virt-acpi-build: Add cpu hotplug support in ACPI

2015-02-17 Thread Shannon Zhao
Add cpu hotplug support in ACPI.

Signed-off-by: Shannon Zhao 
---
 hw/acpi/aml-build.c  |  135 
 hw/acpi/virt-hotplug.c   |   11 +++
 hw/arm/virt-acpi-build.c |  179 +-
 hw/arm/virt.c|1 +
 include/hw/acpi/aml-build.h  |   13 +++
 include/hw/acpi/virt-hotplug.h   |2 +-
 include/hw/arm/virt-acpi-build.h |1 +
 7 files changed, 337 insertions(+), 5 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 5e0c40b..023e055 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -468,6 +468,21 @@ Aml *aml_arg(int pos)
 return var;
 }
 
+Aml *aml_index(Aml *val, Aml *index)
+{
+Aml *var = aml_opcode(0x88 /* IndexOp */);
+aml_append(var, val);
+aml_append(var, index);
+return var;
+}
+
+Aml *aml_derefof(Aml *val)
+{
+Aml *var = aml_opcode(0x83 /* DerefofOp */);
+aml_append(var, val);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefStore */
 Aml *aml_store(Aml *val, Aml *target)
 {
@@ -496,6 +511,14 @@ Aml *aml_notify(Aml *arg1, Aml *arg2)
 return var;
 }
 
+/* helper to call method with none argument */
+Aml *aml_call0(const char *method)
+{
+Aml *var = aml_alloc();
+build_append_namestring(var->buf, "%s", method);
+return var;
+}
+
 /* helper to call method with 1 argument */
 Aml *aml_call1(const char *method, Aml *arg1)
 {
@@ -539,6 +562,48 @@ Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, 
Aml *arg3, Aml *arg4)
 }
 
 /*
+ * ACPI 5.0 19.5.53 GpioInt (GPIO Interrupt Connection Resource Descriptor 
Macro)
+ */
+Aml *aml_gpio_int(uint8_t edge, uint8_t polarity, uint8_t share, uint8_t wake,
+  int8_t pin_cfg, int32_t pin_num, const char *name)
+{
+Aml *var = aml_alloc();
+uint8_t flags = edge & (polarity >> 1) & (share >> 3) & (wake >> 4) & 0x1F;
+uint16_t length = 0x18 + sizeof(name);
+
+build_append_byte(var->buf, 0x8C); /* GpioInt Resource Descriptor */
+build_append_byte(var->buf, length & 0xff); /* Length, bits[7:0] */
+build_append_byte(var->buf, (length >> 8) & 0xff); /* Length, bits[15:8] */
+build_append_byte(var->buf, 1); /* Revision ID */
+build_append_byte(var->buf, 0); /* GPIO Connection Type 0x00 = Interrupt 
Connection */
+build_append_byte(var->buf, 0); /* General Flags, bits[7:0] */
+build_append_byte(var->buf, 0); /* General Flags, bits[15:8] */
+build_append_byte(var->buf, flags); /* Interrupt and IO Flags, bits[7:0] */
+build_append_byte(var->buf, 0); /* Interrupt and IO Flags, bits[15:8] */
+build_append_byte(var->buf, pin_cfg); /* Pin Configuration 0 = Default 1 = 
Pull-up
+   * 2 = Pull-down 3 = No Pull */
+build_append_byte(var->buf, 0); /* Output Drive Strength, bits[7:0] */
+build_append_byte(var->buf, 0); /* Output Drive Strength, bits[15:8] */
+build_append_byte(var->buf, 0); /* Debounce timeout, bits[7:0] */
+build_append_byte(var->buf, 0); /* Debounce timeout, bits[15:8] */
+
+build_append_byte(var->buf, 0x16); /* Pin Table Offset, bits[7:0] */
+build_append_byte(var->buf, 0); /* Pin Table Offset, bits[15:8] */
+build_append_byte(var->buf, 0); /* Resource Source Index */
+build_append_byte(var->buf, 0x18); /* Resource Source Name, bits[7:0] */
+build_append_byte(var->buf, 0); /* Resource Source Name, bits[15:8] */
+build_append_byte(var->buf, length & 0xff); /* Vendor Data Offset, 
bits[7:0] */
+build_append_byte(var->buf, (length >> 8) & 0xff); /* Vendor Data Offset, 
bits[15:8] */
+build_append_byte(var->buf, 0); /* Vendor Data Length, bits[7:0] */
+build_append_byte(var->buf, 0); /* Vendor Data Length, bits[15:8] */
+build_append_byte(var->buf, pin_num & 0xff); /* Pin Number, bits[7:0] */
+build_append_byte(var->buf, (pin_num >> 8) & 0xff); /* Pin Number, 
bits[15:8] */
+build_append_namestring(var->buf, "%s", name); /* Resource Source */
+
+return var;
+}
+
+/*
  * ACPI 1.0: 6.4.3.4 Memory32Fixed (Memory Resource Descriptor Macro)
  */
 Aml *aml_memory32_fixed(uint64_t addr, uint64_t size, uint8_t rw_flag)
@@ -615,6 +680,43 @@ Aml *aml_irq_no_flags(uint8_t irq)
 return var;
 }
 
+/* ACPI 1.0: 16.2.3 Operators: DefIncrement */
+Aml *aml_increment(Aml *arg)
+{
+Aml *var = aml_opcode(0x75 /* IncrementOp */);
+aml_append(var, arg);
+build_append_int(var->buf, 0x00); /* NullNameOp */
+return var;
+}
+
+/* ACPI 1.0: 16.2.3 Operators: DefShiftRight */
+Aml *aml_shiftright(Aml *arg1, Aml *arg2, Aml *arg3)
+{
+Aml *var = aml_opcode(0x7A /* ShiftRightOp */);
+aml_append(var, arg1);
+aml_append(var, arg2);
+aml_append(var, arg3);
+build_append_int(var->buf, 0x00); /* NullNameOp */
+return var;
+}
+
+/* ACPI 1.0: 16.2.3 Operators: DefSizeof */
+Aml *aml_sizeof(Aml *arg)
+{
+Aml *var = aml_opcode(0x87 /* SizeofOp */);
+aml_append(var, arg);
+ 

Re: [Qemu-devel] [PATCH v6 04/24] qcow2: Only return status from qcow2_get_refcount

2015-02-17 Thread Kevin Wolf
Am 10.02.2015 um 21:28 hat Max Reitz geschrieben:
> Refcounts can theoretically be of type uint64_t; in order to be able to
> represent the full range, qcow2_get_refcount() cannot use a single
> variable to represent both all refcount values and also keep some values
> reserved for errors.
> 
> One solution would be to add an Error pointer parameter to
> qcow2_get_refcount(); however, no caller could (currently) pass that
> error message, so it would have to be emitted immediately and be
> passed to the next caller by returning -EIO or something similar.
> Therefore, an Error parameter does not offer any advantages here.
> 
> The solution applied by this patch is simpler to use. Because no caller
> would be able to pass the error message, they would have to print it and
> free it, whereas with this patch the caller only needs to pass the
> returned integer (which is often a no-op from the code perspective,
> because that integer will be stored in a variable "ret" which will be
> returned by the fail path of many callers).
> 
> Signed-off-by: Max Reitz 

> @@ -1646,13 +1653,14 @@ static void compare_refcounts(BlockDriverState *bs, 
> BdrvCheckResult *res,
>  {
>  BDRVQcowState *s = bs->opaque;
>  int64_t i;
> -int refcount1, refcount2, ret;
> +uint16_t refcount1, refcount2;
> +int ret;
>  
>  for (i = 0, *highest_cluster = 0; i < nb_clusters; i++) {
> -refcount1 = qcow2_get_refcount(bs, i);
> -if (refcount1 < 0) {
> +ret = qcow2_get_refcount(bs, i, &refcount1);
> +if (ret < 0) {
>  fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": 
> %s\n",
> -i, strerror(-refcount1));
> +i, strerror(-ret));
>  res->check_errors++;
>  continue;
>  }
> @@ -1682,7 +1690,7 @@ static void compare_refcounts(BlockDriverState *bs, 
> BdrvCheckResult *res,
>  
>  if (num_fixed) {
>  ret = update_refcount(bs, i << s->cluster_bits, 1,
> -  refcount2 - refcount1,
> +  (int)refcount2 - (int)refcount1,
>QCOW2_DISCARD_ALWAYS);
>  if (ret >= 0) {
>  (*num_fixed)++;

Wouldn't both refcounts be promoted to int anyway, even without a cast?
But then, being explicit probably can't hurt either.

Kevin



Re: [Qemu-devel] [PATCH reformat] block: move I/O request processing to block/io.c

2015-02-17 Thread Stefan Hajnoczi
On Thu, Feb 5, 2015 at 12:22 PM, Kevin Wolf  wrote:
> Am 04.02.2015 um 18:51 hat Eric Blake geschrieben:
>> From: Stefan Hajnoczi 
>>
>> The block.c file has grown to over 6000 lines.  It is time to split this
>> file so there are fewer conflicts and the code is easier to maintain.
>>
>> Extract I/O request processing code:
>>  * Read
>>  * Write
>>  * Flush
>>  * Discard
>>  * ioctl
>>  * Tracked requests and queuing
>>  * Throttling and copy-on-read
>>
>> The patch simply moves code from block.c into block/io.c.
>>
>> No code changes are made except adding the following block_int.h
>> functions so they can be called across block.c and block/io.c:
>> bdrv_drain_one(), bdrv_set_dirty(), bdrv_reset_dirty().
>>
>> I/O request processing needs to set up BlockDriver coroutine and AIO
>> emulation function pointers, so add bdrv_setup_io_funcs(bdrv) interface
>> that block.c calls.
>>
>> Signed-off-by: Stefan Hajnoczi 
>> ---
>>
>> This patch produces identical results to Stefan's email, but is
>> MUCH more readable (hint: git config diff.algorithm patience)
>
> Any thoughts on moving (some of) the following functions in addition?
>
> * bdrv_drain_all()
> * bdrv_make_zero()
> * bdrv_flush_all()
> * bdrv_is_allocated/get_block_status family of functions
> * Anything with respect to BlockLimits
> * load/save_vmstate()
> * qemu_blockalign() and friends

I'll send a v2 with these functions added.

Stefan



Re: [Qemu-devel] [PATCH 1/2] vga: abort instead of shrinking memory

2015-02-17 Thread Radim Krčmář
2015-02-17 09:00+0100, Gerd Hoffmann:
> On Mo, 2015-02-16 at 22:23 +0100, Radim Krčmář wrote:
> > Automatic shrinking of vram_size leads to a segfault, because other
> > variables depend on being smaller and don't get shrinked.
> 
> --verbose please.  Which other variables?

I'm sorry, at least rom->surface0_area_size.
(It is sourced from qxl->vgamem_size.)

rom->surface0_area_size shouldn't be bigger than qxl->vga.vram_size,
because it accesses memory allocated by it.

> > Implications of shrinking would make the code needlessly complicated;
> > assert instead.
> 
> assert isn't an option.  vram_size_mb may come from the user (via vga
> device properties), so we need a friendly error message here.

Agreed, it would require a lot of code to do it though (in cover letter)
... what about just dropping [1/2]? :)  ([2/2] does the same job)

> Also the loop you are removing makes sure vram_size is a power of two,
> removing that is not correct too.

(True, the patch should have asserted that as well.)



Re: [Qemu-devel] [PATCH 2/2] qxl: surface0 and ram_header should fit into vram

2015-02-17 Thread Radim Krčmář
2015-02-17 09:02+0100, Gerd Hoffmann:
> On Mo, 2015-02-16 at 22:23 +0100, Radim Krčmář wrote:
> > The solution is not perfect, but won't let us do the same error again
> > and has no overhead.
> 
> How do you get qemu into a configuration where this isn't true?

Without [1/2], by setting qxl-vga.vgamem_mb > 128.
The segfault happens when qxl-vga.vgamem_mb > 256.

In both cases, qxl->vga.vram_size is rounded to 256, but in the latter
one, we allocate less memory than is later accessed.



Re: [Qemu-devel] [PATCH v10 4/5] stm32f205: Add the stm32f205 SoC

2015-02-17 Thread Alistair Francis
On Tue, Feb 10, 2015 at 4:14 PM, Peter Crosthwaite
 wrote:
> On Thu, Jan 29, 2015 at 4:31 AM, Alistair Francis  
> wrote:
>> This patch adds the stm32f205 SoC. This will be used by the
>> Netduino 2 to create a machine.
>>
>> Signed-off-by: Alistair Francis 
>> ---
>> V6:
>>  - Correct the number of USART/UART devices
>>  - Use macros to define how many devices are inited
>>  - Update the memory regions name from netduino.* to
>>STM32F205.*
>>
>>  default-configs/arm-softmmu.mak |   1 +
>>  hw/arm/Makefile.objs|   1 +
>>  hw/arm/stm32f205_soc.c  | 157 
>> 
>>  include/hw/arm/stm32f205_soc.h  |  69 ++
>>  4 files changed, 228 insertions(+)
>>  create mode 100644 hw/arm/stm32f205_soc.c
>>  create mode 100644 include/hw/arm/stm32f205_soc.h
>>
>> diff --git a/default-configs/arm-softmmu.mak 
>> b/default-configs/arm-softmmu.mak
>> index a5aab7f..9ac755e 100644
>> --- a/default-configs/arm-softmmu.mak
>> +++ b/default-configs/arm-softmmu.mak
>> @@ -81,6 +81,7 @@ CONFIG_ZYNQ=y
>>  CONFIG_STM32F2XX_TIMER=y
>>  CONFIG_STM32F2XX_USART=y
>>  CONFIG_STM32F2XX_SYSCFG=y
>> +CONFIG_STM32F205_SOC=y
>>
>>  CONFIG_VERSATILE_PCI=y
>>  CONFIG_VERSATILE_I2C=y
>> diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
>> index 6088e53..9769317 100644
>> --- a/hw/arm/Makefile.objs
>> +++ b/hw/arm/Makefile.objs
>> @@ -8,3 +8,4 @@ obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o 
>> pxa2xx_pic.o
>>  obj-$(CONFIG_DIGIC) += digic.o
>>  obj-y += omap1.o omap2.o strongarm.o
>>  obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
>> +obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
>> diff --git a/hw/arm/stm32f205_soc.c b/hw/arm/stm32f205_soc.c
>> new file mode 100644
>> index 000..186e15d
>> --- /dev/null
>> +++ b/hw/arm/stm32f205_soc.c
>> @@ -0,0 +1,157 @@
>> +/*
>> + * STM32F205 SoC
>> + *
>> + * Copyright (c) 2014 Alistair Francis 
>> + *
>> + * Permission is hereby granted, free of charge, to any person obtaining a 
>> copy
>> + * of this software and associated documentation files (the "Software"), to 
>> deal
>> + * in the Software without restriction, including without limitation the 
>> rights
>> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
>> + * copies of the Software, and to permit persons to whom the Software is
>> + * furnished to do so, subject to the following conditions:
>> + *
>> + * The above copyright notice and this permission notice shall be included 
>> in
>> + * all copies or substantial portions of the Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
>> OR
>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
>> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
>> OTHER
>> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
>> FROM,
>> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
>> + * THE SOFTWARE.
>> + */
>> +
>> +#include "hw/arm/stm32f205_soc.h"
>> +
>> +/* At the moment only Timer 2 to 5 are modelled */
>> +static const uint32_t timer_addr[STM_NUM_TIMERS] = { 0x4000, 0x4400,
>> +0x4800, 0x4C00 };
>> +static const uint32_t usart_addr[STM_NUM_USARTS] = { 0x40011000, 0x40004400,
>> +0x40004800, 0x40004C00, 0x40005000, 0x40011400 };
>> +
>> +static const int timer_irq[STM_NUM_TIMERS] = {28, 29, 30, 50};
>> +static const int usart_irq[STM_NUM_USARTS] = {37, 38, 39, 52, 53, 71};
>> +
>> +static void stm32f205_soc_initfn(Object *obj)
>> +{
>> +STM32F205State *s = STM32F205_SOC(obj);
>> +int i;
>> +
>> +object_initialize(&s->syscfg, sizeof(s->syscfg), TYPE_STM32F2XX_SYSCFG);
>> +qdev_set_parent_bus(DEVICE(&s->syscfg), sysbus_get_default());
>> +
>> +for (i = 0; i < STM_NUM_USARTS; i++) {
>> +object_initialize(&s->usart[i], sizeof(s->usart[i]),
>> +  TYPE_STM32F2XX_USART);
>> +qdev_set_parent_bus(DEVICE(&s->usart[i]), sysbus_get_default());
>> +}
>> +
>> +for (i = 0; i < STM_NUM_TIMERS; i++) {
>> +object_initialize(&s->timer[i], sizeof(s->timer[i]),
>> +  TYPE_STM32F2XX_TIMER);
>> +qdev_set_parent_bus(DEVICE(&s->timer[i]), sysbus_get_default());
>> +}
>> +}
>> +
>> +static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
>> +{
>> +STM32F205State *s = STM32F205_SOC(dev_soc);
>> +DeviceState *syscfgdev, *usartdev, *timerdev;
>> +SysBusDevice *syscfgbusdev, *usartbusdev, *timerbusdev;
>> +qemu_irq *pic;
>> +Error *err = NULL;
>> +int i;
>> +
>> +MemoryRegion *system_memory = get_system_memory();
>> +MemoryRegion *sram = g_new(MemoryRegion, 1);
>> +MemoryRegion *flash = g_new(MemoryRegion, 1);
>> +MemoryRegion *flash_alias = g_new(MemoryRegion, 1);
>> +
>> +memory_regio

Re: [Qemu-devel] [PATCH 1/2] vga: abort instead of shrinking memory

2015-02-17 Thread Gerd Hoffmann
On Di, 2015-02-17 at 11:29 +0100, Radim Krčmář wrote:
> 2015-02-17 09:00+0100, Gerd Hoffmann:
> > On Mo, 2015-02-16 at 22:23 +0100, Radim Krčmář wrote:
> > > Automatic shrinking of vram_size leads to a segfault, because other
> > > variables depend on being smaller and don't get shrinked.
> > 
> > --verbose please.  Which other variables?
> 
> I'm sorry, at least rom->surface0_area_size.
> (It is sourced from qxl->vgamem_size.)

Which command line triggers it?

In theory qxl_init_ramsize() *should* make sure this can't happen ...

I'd like to find & fix the bug instead of plugging an assert into some
random place.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 1/2] vga: abort instead of shrinking memory

2015-02-17 Thread Radim Krčmář
2015-02-17 11:37+0100, Gerd Hoffmann:
> On Di, 2015-02-17 at 11:29 +0100, Radim Krčmář wrote:
> > 2015-02-17 09:00+0100, Gerd Hoffmann:
> > > On Mo, 2015-02-16 at 22:23 +0100, Radim Krčmář wrote:
> > > > Automatic shrinking of vram_size leads to a segfault, because other
> > > > variables depend on being smaller and don't get shrinked.
> > > 
> > > --verbose please.  Which other variables?
> > 
> > I'm sorry, at least rom->surface0_area_size.
> > (It is sourced from qxl->vgamem_size.)
> 
> Which command line triggers it?

The important subset is:
  -vga qxl -global qxl-vga.vgamem_mb=512

The segfault can then be triggered by any operation that dirties the
memory (pause for example).

> In theory qxl_init_ramsize() *should* make sure this can't happen ...
> 
> I'd like to find & fix the bug instead of plugging an assert into some
> random place.

The bug happened because the init code is ovewriting variables, which
made the code unmanageable.  I added an assert, so we would fix the
callers.
Upper layers should also have no idea that our limit is 256, so we would
ideally return an error from vga_common_init() instead of silently
mangling sizes.



Re: [Qemu-devel] [PATCH 1/2] vga: abort instead of shrinking memory

2015-02-17 Thread Gerd Hoffmann
  Hi,

> > Which command line triggers it?
> 
> The important subset is:
>   -vga qxl -global qxl-vga.vgamem_mb=512

Ah, so the problem is only one place enforces a upper limit, so we can
get an invalid configuration with large values.

Can you try the attached patch?

cheers,
  Gerd

>From 7e5e3f9aa6ccd74ebbf454a0e5e4bddf87978f25 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann 
Date: Tue, 17 Feb 2015 11:50:49 +0100
Subject: [PATCH] spice: fix qxl mem size checking

Signed-off-by: Gerd Hoffmann 
---
 hw/display/qxl.c | 4 
 hw/display/vga.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 61df477..c8ca645 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1880,6 +1880,9 @@ static void qxl_init_ramsize(PCIQXLDevice *qxl)
 if (qxl->vgamem_size_mb < 8) {
 qxl->vgamem_size_mb = 8;
 }
+if (qxl->vgamem_size_mb > 512) {
+qxl->vgamem_size_mb = 512;
+}
 qxl->vgamem_size = qxl->vgamem_size_mb * 1024 * 1024;
 
 /* vga ram (bar 0, total) */
@@ -2040,6 +2043,7 @@ static int qxl_init_primary(PCIDevice *dev)
 vga->vbe_size = qxl->vgamem_size;
 vga->vram_size_mb = qxl->vga.vram_size >> 20;
 vga_common_init(vga, OBJECT(dev), true);
+assert(qxl->vgamem_size < qxl->vga.vram_size);
 vga_init(vga, OBJECT(dev),
  pci_address_space(dev), pci_address_space_io(dev), false);
 portio_list_init(&qxl->vga_port_list, OBJECT(dev), qxl_vga_portio_list,
diff --git a/hw/display/vga.c b/hw/display/vga.c
index ffcfce3..52e86ce 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -2122,10 +2122,10 @@ void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate)
 expand4to8[i] = v;
 }
 
-/* valid range: 1 MB -> 256 MB */
+/* valid range: 1 MB -> 1024 MB */
 s->vram_size = 1024 * 1024;
 while (s->vram_size < (s->vram_size_mb << 20) &&
-   s->vram_size < (256 << 20)) {
+   s->vram_size < (1024 << 20)) {
 s->vram_size <<= 1;
 }
 s->vram_size_mb = s->vram_size >> 20;
-- 
1.8.3.1



Re: [Qemu-devel] [PATCH v10 2/7] hw/vfio/platform: vfio-platform skeleton

2015-02-17 Thread Alex Bennée

Eric Auger  writes:

> Minimal VFIO platform implementation supporting register space
> user mapping but not IRQ assignment.
>
> Signed-off-by: Kim Phillips 
> Signed-off-by: Eric Auger 

See comments inline.


> +/**
> + * vfio_populate_device - initialize MMIO region and IRQ
> + * @vbasedev: the VFIO device
> + *
> + * query the VFIO device for exposed MMIO regions and IRQ and
> + * populate the associated fields in the device struct
> + */
> +static int vfio_populate_device(VFIODevice *vbasedev)
> +{
> +struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };

This could be inside the for block.

> +int i, ret = -1;
> +VFIOPlatformDevice *vdev =
> +container_of(vbasedev, VFIOPlatformDevice, vbasedev);
> +
> +if (!(vbasedev->flags & VFIO_DEVICE_FLAGS_PLATFORM)) {
> +error_report("vfio: Um, this isn't a platform device");
> +goto error;
> +}
> +
> +vdev->regions = g_malloc0(sizeof(VFIORegion *) *
> vbasedev->num_regions);

I may have considered a g_malloc0_n but I see that's not actually used
in the rest of the code (newer glib?).

> +
> +for (i = 0; i < vbasedev->num_regions; i++) {
> +vdev->regions[i] = g_malloc0(sizeof(VFIORegion));

An intermediate VFIORegion *ptr here would have saved a bunch of typing
later on ;-) 

> +reg_info.index = i;
> +ret = ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);
> +if (ret) {
> +error_report("vfio: Error getting region %d info: %m", i);
> +goto error;
> +}
> +vdev->regions[i]->flags = reg_info.flags;
> +vdev->regions[i]->size = reg_info.size;
> +vdev->regions[i]->fd_offset = reg_info.offset;
> +vdev->regions[i]->nr = i;
> +vdev->regions[i]->vbasedev = vbasedev;
> +
> +trace_vfio_platform_populate_regions(vdev->regions[i]->nr,
> +(unsigned long)vdev->regions[i]->flags,
> +(unsigned long)vdev->regions[i]->size,
> +vdev->regions[i]->vbasedev->fd,
> +(unsigned long)vdev->regions[i]->fd_offset);
> +}
> +
> +return 0;
> +error:
> +for (i = 0; i < vbasedev->num_regions; i++) {
> +g_free(vdev->regions[i]);
> +}
> +g_free(vdev->regions);
> +return ret;
> +}
> +
> +/* specialized functions ofr VFIO Platform devices */
> +static VFIODeviceOps vfio_platform_ops = {
> +.vfio_compute_needs_reset = vfio_platform_compute_needs_reset,
> +.vfio_hot_reset_multi = vfio_platform_hot_reset_multi,
> +.vfio_populate_device = vfio_populate_device,
> +};
> +
> +/**
> + * vfio_base_device_init - implements some of the VFIO mechanics
> + * @vbasedev: the VFIO device
> + *
> + * retrieves the group the device belongs to and get the device fd
> + * returns the VFIO device fd
> + * precondition: the device name must be initialized
> + */
> +static int vfio_base_device_init(VFIODevice *vbasedev)
> +{
> +VFIOGroup *group;
> +VFIODevice *vbasedev_iter;
> +char path[PATH_MAX], iommu_group_path[PATH_MAX], *group_name;
> +ssize_t len;
> +struct stat st;
> +int groupid;
> +int ret;
> +
> +/* name must be set prior to the call */
> +if (!vbasedev->name) {
> +return -EINVAL;
> +}
> +
> +/* Check that the host device exists */
> +snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
> + vbasedev->name);
> +
> +if (stat(path, &st) < 0) {
> +error_report("vfio: error: no such host device: %s", path);
> +return -errno;
> +}
> +
> +strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1);

Consider g_strlcat which has nicer max length semantics.

> +len = readlink(path, iommu_group_path, sizeof(path));
> +if (len <= 0 || len >= sizeof(path)) {

readlink should never report more than sizeof(path) although that will
indicate a ENAMETOOLONG.

> +error_report("vfio: error no iommu_group for device");
> +return len < 0 ? -errno : ENAMETOOLONG;
> +}
> +
> +iommu_group_path[len] = 0;
> +group_name = basename(iommu_group_path);
> +
> +if (sscanf(group_name, "%d", &groupid) != 1) {
> +error_report("vfio: error reading %s: %m", path);
> +return -errno;
> +}
> +
> +trace_vfio_platform_base_device_init(vbasedev->name, groupid);
> +
> +group = vfio_get_group(groupid, &address_space_memory);
> +if (!group) {
> +error_report("vfio: failed to get group %d", groupid);
> +return -ENOENT;
> +}
> +
> +snprintf(path, sizeof(path), "%s", vbasedev->name);
> +
> +QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
> +if (strcmp(vbasedev_iter->name, vbasedev->name) == 0) {
> +error_report("vfio: error: device %s is already attached", path);
> +vfio_put_group(group);
> +return -EBUSY;
> +}
> +}
> +ret = vfio_get_device(group, path, v

Re: [Qemu-devel] [RFC PATCH v8 08/21] cpu: replay instructions sequence

2015-02-17 Thread Paolo Bonzini


On 17/02/2015 09:43, Pavel Dovgaluk wrote:
>> >  int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
>> >  if (deadline == 0) {
>> >  qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
>> >  }
>> > 
>> > instead of qemu_notify_event(), and remove these lines from
>> > qemu_tcg_cpu_thread_fn.
> I tried this one. But there is one problem.
> Expiring of the virtual timers is not the only reason of icount expiration in 
> replay mode.
> It may be caused by host timers deadline or poll timeout in record mode. In 
> this case 
> qemu_clock_notify(QEMU_CLOCK_VIRTUAL) will not be called in replay mode and 
> we'll waste time for iothread sleeping.

Sure, but unconditional qemu_notify_event() is also wrong.  So, to sum up:

- it's okay to move code from qemu_tcg_cpu_thread_fn to cpu-exec.c

- it's okay to add more qemu_clock_notify calls than just
qemu_clock_notify(QEMU_CLOCK_VIRTUAL), each with its own condition

- it's better if all these, after being moved to cpu-exec.c, are also
extracted in a separate function

- it's not okay to do an unconditional qemu_notify_event() in
cpu-exec.c, even if it's under "if (replay_mode != NONE)".

Thanks for your understanding! :)

Paolo



Re: [Qemu-devel] [PATCH v6 00/24] qcow2: Support refcount orders != 4

2015-02-17 Thread Kevin Wolf
Am 10.02.2015 um 21:28 hat Max Reitz geschrieben:
> As of version 3, the qcow2 file format supports different widths for
> refcount entries, ranging from 1 to 64 bit (only powers of two).
> Currently, qemu only supports 16 bit, which is the only width supported
> by version 2 (compat=0.10) images.
> 
> This series adds support to qemu for all other valid refcount orders.
> This is mainly done by adding two function pointers into the
> BDRVQcowState structure for reading and writing refcount values
> independently of the current refcount entry width; all in-memory
> refcount arrays (mostly cached refcount blocks) now are void pointers
> and are accessed through these functions alone.
> 
> Thanks to previous work of making the qemu code agnostic of e.g. the
> number of refcount entries per refcount block, the rest is fairly
> trivial. The most complex patch in this series is patch 21 which
> implements changing the refcount order through qemu-img amend.
> 
> To test different refcount widths, simply invoke the qemu-iotests check
> program with -o refcount_bits=${your_desired_width}. The final test in
> this series adds some tests for operations which do not work with
> certain refcount orders and for refcount order amendment.
> 
> In order for iotest 015 to succeed with refcount_bits=32 and
> refcount_bits=64, this series depends on my series
> "qcow2: Respect new_block in alloc_refcount_block()".

In order to avoid re-reviewing the same patches each time you post a new
version, I applied patches 1 to 6 now. I'll continue with reviewing the
rest later today.

Kevin



Re: [Qemu-devel] [PATCH 1/2] vga: abort instead of shrinking memory

2015-02-17 Thread Radim Krčmář
2015-02-17 11:51+0100, Gerd Hoffmann:
>   Hi,
> 
> > > Which command line triggers it?
> > 
> > The important subset is:
> >   -vga qxl -global qxl-vga.vgamem_mb=512
> 
> Ah, so the problem is only one place enforces a upper limit, so we can
> get an invalid configuration with large values.

(I think that hardcoding the limit at two unrelated places is bad --
 nothing in the code has improved since the first bug.)

> Can you try the attached patch?

It doesn't crash, but spice doesn't work when setting vgamem that high,
and there is no reason to anyway, so the attached hunk would be better.

Thanks.


---
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 61df47726481..3c55aa6479d4 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1880,6 +1880,9 @@ static void qxl_init_ramsize(PCIQXLDevice *qxl)
 if (qxl->vgamem_size_mb < 8) {
 qxl->vgamem_size_mb = 8;
 }
+if (qxl->vgamem_size_mb > 128) {
+qxl->vgamem_size_mb = 128;
+}
 qxl->vgamem_size = qxl->vgamem_size_mb * 1024 * 1024;
 
 /* vga ram (bar 0, total) */



Re: [Qemu-devel] [PATCH v10 3/7] hw/vfio/platform: add irq assignment

2015-02-17 Thread Alex Bennée

Eric Auger  writes:

> This patch adds the code requested to assign interrupts to
> a guest. The interrupts are mediated through user handled
> eventfds only.
>
> The mechanics to start the IRQ handling is not yet there through.
>
> Signed-off-by: Eric Auger 

See comments inline.

>
> ---
>
> v8 -> v9:
> - free irq related resources in case of error in vfio_populate_device
> ---
>  hw/vfio/platform.c  | 319 
> 
>  include/hw/vfio/vfio-platform.h |  33 +
>  2 files changed, 352 insertions(+)
>
> diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
> index caadb92..b85ad6c 100644
> --- a/hw/vfio/platform.c
> +++ b/hw/vfio/platform.c
> @@ -22,10 +22,259 @@
>  #include "qemu/range.h"
>  #include "sysemu/sysemu.h"
>  #include "exec/memory.h"
> +#include "qemu/queue.h"
>  #include "hw/sysbus.h"
>  #include "trace.h"
>  #include "hw/platform-bus.h"
>  
> +static void vfio_intp_interrupt(VFIOINTp *intp);
> +typedef void (*eventfd_user_side_handler_t)(VFIOINTp *intp);
> +static int vfio_set_trigger_eventfd(VFIOINTp *intp,
> +eventfd_user_side_handler_t handler);
> +
> +/*
> + * Functions only used when eventfd are handled on user-side
> + * ie. without irqfd
> + */
> +
> +/**
> + * vfio_platform_eoi - IRQ completion routine
> + * @vbasedev: the VFIO device
> + *
> + * de-asserts the active virtual IRQ and unmask the physical IRQ
> + * (masked by the  VFIO driver). Handle pending IRQs if any.
> + * eoi function is called on the first access to any MMIO region
> + * after an IRQ was triggered. It is assumed this access corresponds
> + * to the IRQ status register reset. With such a mechanism, a single
> + * IRQ can be handled at a time since there is no way to know which
> + * IRQ was completed by the guest (we would need additional details
> + * about the IRQ status register mask)
> + */
> +static void vfio_platform_eoi(VFIODevice *vbasedev)
> +{
> +VFIOINTp *intp;
> +VFIOPlatformDevice *vdev =
> +container_of(vbasedev, VFIOPlatformDevice, vbasedev);
> +
> +qemu_mutex_lock(&vdev->intp_mutex);
> +QLIST_FOREACH(intp, &vdev->intp_list, next) {
> +if (intp->state == VFIO_IRQ_ACTIVE) {
> +trace_vfio_platform_eoi(intp->pin,
> +event_notifier_get_fd(&intp->interrupt));
> +intp->state = VFIO_IRQ_INACTIVE;
> +
> +/* deassert the virtual IRQ and unmask physical one */
> +qemu_set_irq(intp->qemuirq, 0);
> +vfio_unmask_single_irqindex(vbasedev, intp->pin);
> +
> +/* a single IRQ can be active at a time */
> +break;
> +}
> +}
> +/* in case there are pending IRQs, handle them one at a time */
> +if (!QSIMPLEQ_EMPTY(&vdev->pending_intp_queue)) {
> +intp = QSIMPLEQ_FIRST(&vdev->pending_intp_queue);
> +trace_vfio_platform_eoi_handle_pending(intp->pin);
> +qemu_mutex_unlock(&vdev->intp_mutex);
> +vfio_intp_interrupt(intp);
> +qemu_mutex_lock(&vdev->intp_mutex);
> +QSIMPLEQ_REMOVE_HEAD(&vdev->pending_intp_queue, pqnext);
> +qemu_mutex_unlock(&vdev->intp_mutex);

This locking is way too ugly. If the intp lock is protecting the
structures then releasing it so the child function can grab it again is
just asking for races to happen. Perhaps vfio_intp_interrupt can be
split to have a _lockheld variant that can be used here and the other
version do the locking before calling the _lockheld function.


> +} else {
> +qemu_mutex_unlock(&vdev->intp_mutex);
> +}
> +}
> +
> +/**
> + * vfio_mmap_set_enabled - enable/disable the fast path mode
> + * @vdev: the VFIO platform device
> + * @enabled: the target mmap state
> + *
> + * true ~ fast path = MMIO region is mmaped (no KVM TRAP)
> + * false ~ slow path = MMIO region is trapped and region callbacks
> + * are called slow path enables to trap the IRQ status register
> + * guest reset
> +*/
> +
> +static void vfio_mmap_set_enabled(VFIOPlatformDevice *vdev, bool enabled)
> +{
> +VFIORegion *region;

region could be defined inside the block, not that it matters too much
for a small function like this.

> +int i;
> +
> +trace_vfio_platform_mmap_set_enabled(enabled);
> +
> +for (i = 0; i < vdev->vbasedev.num_regions; i++) {
> +region = vdev->regions[i];
> +
> +/* register space is unmapped to trap EOI */
> +memory_region_set_enabled(®ion->mmap_mem, enabled);
> +}
> +}
> +
> +/**
> + * vfio_intp_mmap_enable - timer function, restores the fast path
> + * if there is no more active IRQ
> + * @opaque: actually points to the VFIO platform device
> + *
> + * Called on mmap timer timout, this function checks whether the
> + * IRQ is still active and in the negative restores the fast path.
> + * by construction a single eventfd is handled at a time.
> + * if the IRQ is still active, the timer is restarted.
> + */
> +static void vfio_intp_

Re: [Qemu-devel] [PATCH v10 5/7] hw/vfio: calxeda xgmac device

2015-02-17 Thread Alex Bennée

Eric Auger  writes:

> The platform device class has become abstract. This patch introduces
> a calxeda xgmac device that can be be instantiated on command line
> using such option.
>
> -device vfio-calxeda-xgmac,host="fff51000.ethernet"
>
> Signed-off-by: Eric Auger 
Reviewed-by: Alex Bennée 

>
> ---
> v8 -> v9:
> - renamed calxeda_xgmac.c into calxeda-xgmac.c
>
> v7 -> v8:
> - add a comment in the header about the MMIO regions and IRQ which
>   are exposed by the device
>
> v5 -> v6
> - back again following Alex Graf advises
> - fix a bug related to compat override
>
> v4 -> v5:
> removed since device tree was moved to hw/arm/dyn_sysbus_devtree.c
>
> v4: creation for device tree specialization
> ---
>  hw/arm/virt.c| 15 +++---
>  hw/vfio/Makefile.objs|  1 +
>  hw/vfio/calxeda-xgmac.c  | 54 
> 
>  include/hw/vfio/vfio-calxeda-xgmac.h | 46 ++
>  4 files changed, 112 insertions(+), 4 deletions(-)
>  create mode 100644 hw/vfio/calxeda-xgmac.c
>  create mode 100644 include/hw/vfio/vfio-calxeda-xgmac.h
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 9df9b60..c1e0a10 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -44,6 +44,7 @@
>  #include "qemu/error-report.h"
>  #include "hw/arm/sysbus-fdt.h"
>  #include "hw/platform-bus.h"
> +#include "hw/vfio/vfio-platform.h"
>  
>  #define NUM_VIRTIO_TRANSPORTS 32
>  
> @@ -342,7 +343,7 @@ static void fdt_add_gic_node(const VirtBoardInfo *vbi)
>  qemu_fdt_setprop_cell(vbi->fdt, "/intc", "phandle", gic_phandle);
>  }
>  
> -static void create_gic(const VirtBoardInfo *vbi, qemu_irq *pic)
> +static DeviceState *create_gic(const VirtBoardInfo *vbi, qemu_irq *pic)
>  {
>  /* We create a standalone GIC v2 */
>  DeviceState *gicdev;
> @@ -390,6 +391,7 @@ static void create_gic(const VirtBoardInfo *vbi, qemu_irq 
> *pic)
>  }
>  
>  fdt_add_gic_node(vbi);
> +return gicdev;
>  }
>  
>  static void create_uart(const VirtBoardInfo *vbi, qemu_irq *pic)
> @@ -594,7 +596,8 @@ static void create_fw_cfg(const VirtBoardInfo *vbi)
>  g_free(nodename);
>  }
>  
> -static void create_platform_bus(VirtBoardInfo *vbi, qemu_irq *pic)
> +static void create_platform_bus(VirtBoardInfo *vbi, qemu_irq *pic,
> +DeviceState *gic)
>  {
>  DeviceState *dev;
>  SysBusDevice *s;
> @@ -633,6 +636,9 @@ static void create_platform_bus(VirtBoardInfo *vbi, 
> qemu_irq *pic)
>  memory_region_add_subregion(sysmem,
>  platform_bus_params.platform_bus_base,
>  sysbus_mmio_get_region(s, 0));
> +
> +/* setup VFIO signaling/IRQFD for all VFIO platform sysbus devices */
> +qemu_register_reset(vfio_kick_irqs, gic);
>  }
>  
>  static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size)
> @@ -652,6 +658,7 @@ static void machvirt_init(MachineState *machine)
>  MemoryRegion *ram = g_new(MemoryRegion, 1);
>  const char *cpu_model = machine->cpu_model;
>  VirtBoardInfo *vbi;
> +DeviceState *gic;
>  
>  if (!cpu_model) {
>  cpu_model = "cortex-a15";
> @@ -713,7 +720,7 @@ static void machvirt_init(MachineState *machine)
>  
>  create_flash(vbi);
>  
> -create_gic(vbi, pic);
> +gic = create_gic(vbi, pic);
>  
>  create_uart(vbi, pic);
>  
> @@ -744,7 +751,7 @@ static void machvirt_init(MachineState *machine)
>   * another notifier is registered which adds platform bus nodes.
>   * Notifiers are executed in registration reverse order.
>   */
> -create_platform_bus(vbi, pic);
> +create_platform_bus(vbi, pic, gic);
>  }
>  
>  static bool virt_get_secure(Object *obj, Error **errp)
> diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs
> index c5c76fe..d540c9d 100644
> --- a/hw/vfio/Makefile.objs
> +++ b/hw/vfio/Makefile.objs
> @@ -2,4 +2,5 @@ ifeq ($(CONFIG_LINUX), y)
>  obj-$(CONFIG_SOFTMMU) += common.o
>  obj-$(CONFIG_PCI) += pci.o
>  obj-$(CONFIG_SOFTMMU) += platform.o
> +obj-$(CONFIG_SOFTMMU) += calxeda-xgmac.o
>  endif
> diff --git a/hw/vfio/calxeda-xgmac.c b/hw/vfio/calxeda-xgmac.c
> new file mode 100644
> index 000..199e076
> --- /dev/null
> +++ b/hw/vfio/calxeda-xgmac.c
> @@ -0,0 +1,54 @@
> +/*
> + * calxeda xgmac example VFIO device
> + *
> + * Copyright Linaro Limited, 2014
> + *
> + * Authors:
> + *  Eric Auger 
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2.  See
> + * the COPYING file in the top-level directory.
> + *
> + */
> +
> +#include "hw/vfio/vfio-calxeda-xgmac.h"
> +
> +static void calxeda_xgmac_realize(DeviceState *dev, Error **errp)
> +{
> +VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(dev);
> +VFIOCalxedaXgmacDeviceClass *k = 
> VFIO_CALXEDA_XGMAC_DEVICE_GET_CLASS(dev);
> +
> +vdev->compat = g_strdup("calxeda,hb-xgmac");
> +
> +k->parent_realize(dev, errp);
> +}
> +
> +static const VMStateDescrip

Re: [Qemu-devel] [RFC PATCH v8 08/21] cpu: replay instructions sequence

2015-02-17 Thread Pavel Dovgaluk
> From: Paolo Bonzini [mailto:pbonz...@redhat.com]
> On 17/02/2015 09:43, Pavel Dovgaluk wrote:
> >> >  int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
> >> >  if (deadline == 0) {
> >> >  qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
> >> >  }
> >> >
> >> > instead of qemu_notify_event(), and remove these lines from
> >> > qemu_tcg_cpu_thread_fn.
> > I tried this one. But there is one problem.
> > Expiring of the virtual timers is not the only reason of icount expiration 
> > in replay mode.
> > It may be caused by host timers deadline or poll timeout in record mode. In 
> > this case
> > qemu_clock_notify(QEMU_CLOCK_VIRTUAL) will not be called in replay mode and 
> > we'll waste time
> for iothread sleeping.
> 
> Sure, but unconditional qemu_notify_event() is also wrong.  So, to sum up:
> 
> - it's okay to move code from qemu_tcg_cpu_thread_fn to cpu-exec.c
> 
> - it's okay to add more qemu_clock_notify calls than just
> qemu_clock_notify(QEMU_CLOCK_VIRTUAL), each with its own condition
> 
> - it's better if all these, after being moved to cpu-exec.c, are also
> extracted in a separate function
> 
> - it's not okay to do an unconditional qemu_notify_event() in
> cpu-exec.c, even if it's under "if (replay_mode != NONE)".

How can I wake up iothread if there are no pending timers?
deadline will (almost) never become zero in my case, because there is 
another kind of event in the log (not the timer one).
Should I fetch the event and call qemu_notify_event() from replay module?

> 
> Thanks for your understanding! :)

Pavel Dovgalyuk




Re: [Qemu-devel] [PATCH v10 6/7] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation

2015-02-17 Thread Alex Bennée

Eric Auger  writes:

> vfio-calxeda-xgmac now can be instantiated using the -device option.
> The node creation function generates a very basic dt node composed
> of the compat, reg and interrupts properties
>
> Signed-off-by: Eric Auger 
>
> ---
> v8 -> v9:
> - properly free resources in case of errors in
>   add_calxeda_midway_xgmac_fdt_node
>
> v7 -> v8:
> - move the add_fdt_node_functions array declaration between the device
>   specific code and the generic code to avoid forward declarations of
>   decice specific functions
> - rename add_basic_vfio_fdt_node into
>   add_calxeda_midway_xgmac_fdt_node
>
> v6 -> v7:
> - compat string re-formatting removed since compat string is not exposed
>   anymore as a user option
> - VFIO IRQ kick-off removed from sysbus-fdt and moved to VFIO platform
>   device
> ---
>  hw/arm/sysbus-fdt.c | 83 
> +
>  1 file changed, 83 insertions(+)
>
> diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
> index 3038b94..d4f97f5 100644
> --- a/hw/arm/sysbus-fdt.c
> +++ b/hw/arm/sysbus-fdt.c
> @@ -26,6 +26,8 @@
>  #include "sysemu/device_tree.h"
>  #include "hw/platform-bus.h"
>  #include "sysemu/sysemu.h"
> +#include "hw/vfio/vfio-platform.h"
> +#include "hw/vfio/vfio-calxeda-xgmac.h"
>  
>  /*
>   * internal struct that contains the information to create dynamic
> @@ -53,11 +55,92 @@ typedef struct NodeCreationPair {
>  int (*add_fdt_node_fn)(SysBusDevice *sbdev, void *opaque);
>  } NodeCreationPair;
>  
> +/* Device Specific Code */
> +
> +/**
> + * add_calxeda_midway_xgmac_fdt_node
> + *
> + * Generates a very simple node with following properties:
> + * compatible string, regs, interrupts
> + */
> +static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void 
> *opaque)
> +{
> +PlatformBusFDTData *data = opaque;
> +PlatformBusDevice *pbus = data->pbus;
> +void *fdt = data->fdt;
> +const char *parent_node = data->pbus_node_name;
> +int compat_str_len;
> +char *nodename;
> +int i, ret = -1;
> +uint32_t *irq_attr;
> +uint64_t *reg_attr;
> +uint64_t mmio_base;
> +uint64_t irq_number;
> +VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
> +VFIODevice *vbasedev = &vdev->vbasedev;
> +Object *obj = OBJECT(sbdev);
> +
> +mmio_base = object_property_get_int(obj, "mmio[0]", NULL);
> +
> +nodename = g_strdup_printf("%s/%s@%" PRIx64, parent_node,
> +   vbasedev->name,
> +   mmio_base);
> +
> +qemu_fdt_add_subnode(fdt, nodename);
> +
> +compat_str_len = strlen(vdev->compat) + 1;
> +qemu_fdt_setprop(fdt, nodename, "compatible",
> +  vdev->compat, compat_str_len);
> +
> +reg_attr = g_new(uint64_t, vbasedev->num_regions*4);
> +
> +for (i = 0; i < vbasedev->num_regions; i++) {
> +mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, i);
> +reg_attr[4*i] = 1;
> +reg_attr[4*i+1] = mmio_base;
> +reg_attr[4*i+2] = 1;
> +reg_attr[4*i+3] = memory_region_size(&vdev->regions[i]->mem);
> +}
> +
> +ret = qemu_fdt_setprop_sized_cells_from_array(fdt, nodename, "reg",
> + vbasedev->num_regions*2, reg_attr);

Could we use qemu_fdt_setprop_sized_cells() like everyone else to hide
the uglyness of the _from_array?

> +if (ret) {
> +error_report("could not set reg property of node %s", nodename);
> +goto fail_reg;
> +}
> +
> +irq_attr = g_new(uint32_t, vbasedev->num_irqs*3);
> +
> +for (i = 0; i < vbasedev->num_irqs; i++) {
> +irq_number = platform_bus_get_irqn(pbus, sbdev , i)
> + + data->irq_start;
> +irq_attr[3*i] = cpu_to_be32(0);
> +irq_attr[3*i+1] = cpu_to_be32(irq_number);
> +irq_attr[3*i+2] = cpu_to_be32(0x4);
> +}
> +
> +   ret = qemu_fdt_setprop(fdt, nodename, "interrupts",
> + irq_attr,
> vbasedev->num_irqs*3*sizeof(uint32_t));

Ditto.

> +if (ret) {
> +error_report("could not set interrupts property of node %s",
> + nodename);
> +}
> +
> +g_free(irq_attr);
> +fail_reg:
> +g_free(reg_attr);
> +g_free(nodename);
> +return ret;
> +}
> +
>  /* list of supported dynamic sysbus devices */
>  static const NodeCreationPair add_fdt_node_functions[] = {
> +{TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node},
>  {"", NULL}, /* last element */
>  };
>  
> +/* Generic Code */
> +
>  /**
>   * add_fdt_node - add the device tree node of a dynamic sysbus device
>   *

-- 
Alex Bennée



Re: [Qemu-devel] [PATCH v10 7/7] hw/vfio/platform: add irqfd support

2015-02-17 Thread Alex Bennée

Eric Auger  writes:

> This patch aims at optimizing IRQ handling using irqfd framework.
>
> Instead of handling the eventfds on user-side they are handled on
> kernel side using
> - the KVM irqfd framework,
> - the VFIO driver virqfd framework.
>
> the virtual IRQ completion is trapped at interrupt controller
> This removes the need for fast/slow path swap.
>
> Overall this brings significant performance improvements.
>
> it depends on host kernel KVM irqfd.
>
> Signed-off-by: Alvise Rigo 
> Signed-off-by: Eric Auger 

Reviewed-by: Alex Bennée 

>
> ---
> v5 -> v6
> - rely on kvm_irqfds_enabled() and kvm_resamplefds_enabled()
> - guard KVM code with #ifdef CONFIG_KVM
>
> v3 -> v4:
> [Alvise Rigo]
> Use of VFIO Platform driver v6 unmask/virqfd feature and removal
> of resamplefd handler. Physical IRQ unmasking is now done in
> VFIO driver.
>
> v3:
> [Eric Auger]
> initial support with resamplefd handled on QEMU side since the
> unmask was not supported on VFIO platform driver v5.
>
> Conflicts:
>   hw/vfio/platform.c
> ---
>  hw/vfio/platform.c  | 104 
> +++-
>  include/hw/vfio/vfio-platform.h |   1 +
>  trace-events|   2 +
>  3 files changed, 106 insertions(+), 1 deletion(-)
>
> diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
> index 30798d8..cadc824 100644
> --- a/hw/vfio/platform.c
> +++ b/hw/vfio/platform.c
> @@ -26,6 +26,7 @@
>  #include "hw/sysbus.h"
>  #include "trace.h"
>  #include "hw/platform-bus.h"
> +#include "sysemu/kvm.h"
>  
>  static void vfio_intp_interrupt(VFIOINTp *intp);
>  typedef void (*eventfd_user_side_handler_t)(VFIOINTp *intp);
> @@ -237,6 +238,83 @@ static int vfio_start_eventfd_injection(VFIOINTp *intp)
>  }
>  
>  /*
> + * Functions used for irqfd
> + */
> +
> +#ifdef CONFIG_KVM
> +
> +/**
> + * vfio_set_resample_eventfd - sets the resamplefd for an IRQ
> + * @intp: the IRQ struct pointer
> + * programs the VFIO driver to unmask this IRQ when the
> + * intp->unmask eventfd is triggered
> + */
> +static int vfio_set_resample_eventfd(VFIOINTp *intp)
> +{
> +VFIODevice *vbasedev = &intp->vdev->vbasedev;
> +struct vfio_irq_set *irq_set;
> +int argsz, ret;
> +int32_t *pfd;
> +
> +argsz = sizeof(*irq_set) + sizeof(*pfd);
> +irq_set = g_malloc0(argsz);
> +irq_set->argsz = argsz;
> +irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_UNMASK;
> +irq_set->index = intp->pin;
> +irq_set->start = 0;
> +irq_set->count = 1;
> +pfd = (int32_t *)&irq_set->data;
> +*pfd = event_notifier_get_fd(&intp->unmask);
> +qemu_set_fd_handler(*pfd, NULL, NULL, intp);
> +ret = ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
> +g_free(irq_set);
> +if (ret < 0) {
> +error_report("vfio: Failed to set resample eventfd: %m");
> +qemu_set_fd_handler(*pfd, NULL, NULL, NULL);
> +}
> +return ret;
> +}
> +
> +/**
> + * vfio_start_irqfd_injection - starts irqfd injection for an IRQ
> + * programs VFIO driver with both the trigger and resamplefd
> + * programs KVM with the gsi, trigger & resample eventfds
> + */
> +static int vfio_start_irqfd_injection(VFIOINTp *intp)
> +{
> +struct kvm_irqfd irqfd = {
> +.fd = event_notifier_get_fd(&intp->interrupt),
> +.resamplefd = event_notifier_get_fd(&intp->unmask),
> +.gsi = intp->virtualID,
> +.flags = KVM_IRQFD_FLAG_RESAMPLE,
> +};
> +
> +if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) {
> +error_report("vfio: Error: Failed to assign the irqfd: %m");
> +goto fail_irqfd;
> +}
> +if (vfio_set_trigger_eventfd(intp, NULL) < 0) {
> +goto fail_vfio;
> +}
> +if (vfio_set_resample_eventfd(intp) < 0) {
> +goto fail_vfio;
> +}
> +
> +intp->kvm_accel = true;
> +trace_vfio_platform_start_irqfd_injection(intp->pin, intp->virtualID,
> + irqfd.fd, irqfd.resamplefd);
> +return 0;
> +
> +fail_vfio:
> +irqfd.flags = KVM_IRQFD_FLAG_DEASSIGN;
> +kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd);
> +fail_irqfd:
> +return -1;
> +}
> +
> +#endif
> +
> +/*
>   * Functions used whatever the injection method
>   */
>  
> @@ -315,6 +393,13 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, 
> unsigned int index)
>  error_report("vfio: Error: trigger event_notifier_init failed ");
>  return NULL;
>  }
> +/* Get an eventfd for resample/unmask */
> +ret = event_notifier_init(&intp->unmask, 0);
> +if (ret) {
> +g_free(intp);
> +error_report("vfio: Error: resample event_notifier_init failed eoi");
> +return NULL;
> +}
>  
>  /* store the new intp in qlist */
>  QLIST_INSERT_HEAD(&vdev->intp_list, intp, next);
> @@ -409,7 +494,6 @@ static VFIODeviceOps vfio_platform_ops = {
>  .vfio_compute_needs_reset = vfio_platform_compute_needs_reset,
>  .vfio_hot_reset_multi = vfio_platform_hot_reset_multi,
>  

Re: [Qemu-devel] KVM call for agenda for 2015-02-17

2015-02-17 Thread Juan Quintela
Juan Quintela  wrote:
> Hi
>
> Please, send any topic that you are interested in covering.

As there are no agenda, call got cancelled.

Have a good day, Juan.

>
>
>  Call details:
>
> By popular demand, a google calendar public entry with it
>
>   
> https://www.google.com/calendar/embed?src=dG9iMXRqcXAzN3Y4ZXZwNzRoMHE4a3BqcXNAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ
>
> (Let me know if you have any problems with the calendar entry.  I just
> gave up about getting right at the same time CEST, CET, EDT and DST).
>
> If you need phone number details,  contact me privately
>
> Thanks, Juan.



Re: [Qemu-devel] [PATCH 04/10] vnc: switch to QemuOpts, allow multiple servers

2015-02-17 Thread Markus Armbruster
Gerd Hoffmann  writes:

>   Hi,
>
>> >  static void qmp_change_vnc_listen(const char *target, Error **errp)
>> >  {
>> > -vnc_display_open(NULL, target, errp);
>> > +QemuOptsList *olist = qemu_find_opts("vnc");
>> > +QemuOpts *opts;
>> > +
>> > +if (strstr(target, "id=")) {
>> > +error_setg(errp, "id not supported");
>> > +return;
>> > +}
>> 
>> Aside: this is unclean.  Could we somehow test qemu_opts_id() instead?
>
> For that we would have to parse it first, which has some ugly corner
> cases on id clashes ...
>
> All I wanna do here is keep it alive for the existing use cases, without
> support for multiple displays, with minimum effort.
>
> Should we need support for vnc config change in a multiple vnc server
> setup a new qmp monitor command should be designed for that.

Fair enough.  Suggests that the QemuOpts API is lacking, though.



Re: [Qemu-devel] [PATCH v2 0/6] TriCore: Add RRR1 and RRR2 instructions

2015-02-17 Thread Bastian Koppelmann


On 02/11/2015 04:48 PM, Bastian Koppelmann wrote:

Hi,

the patchset fixes two minor bugs and takes care of all the packed/fixed point
mac instructions. So far I only implemented all the multiply-add instructions,
since the multiply-sub instructions are similar and I don't want the reviewers
to find the same mistakes twice. Once these are reviewed I will send another
patchset containing all the multiply-sub instructions.
I do plan on mirroring the multiply-add instructions, which seems okay. However
if there are ideas to make this more clean, let me know.

Cheers,
Bastian

v1 -> v2:
 * fix obvious style issues found by checkpatch

Bastian Koppelmann (6):
   target-tricore: Fix RLC_ADDI, RLC_ADDIH using wrong microcode helper
   target-tricore: fix msub32_suov return wrong results
   target-tricore: Add instructions of RRR2 opcode format
   target-tricore: Add instructions of RRR1 opcode format, which have
 0x83 as first opcode
   target-tricore: Add instructions of RRR1 opcode format, which have
 0x43 as first opcode
   target-tricore: Add instructions of RRR1 opcode format, which have
 0xc3 as first opcode

  target-tricore/helper.h  |9 +
  target-tricore/op_helper.c   |  374 +-
  target-tricore/translate.c   | 1391 --
  target-tricore/tricore-opcodes.h |   10 +-
  4 files changed, 1728 insertions(+), 56 deletions(-)

--
2.3.0



ping?

Cheers,
Bastian



Re: [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term

2015-02-17 Thread Michael S. Tsirkin
On Mon, Feb 09, 2015 at 10:53:53AM +, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov 
> ---

This causes asserts.

>  hw/acpi/aml-build.c | 11 +++
>  include/hw/acpi/aml-build.h |  1 +
>  2 files changed, 12 insertions(+)
> 
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 10995a9..cb58e19 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)
>  build_append_byte(var->buf, flags);
>  return var;
>  }
> +
> +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
> +Aml *aml_local(int num)
> +{
> +Aml *var;
> +uint8_t op = 0x60 /* Local0Op */ + num;

So op is 0x6X here.

> +
> +assert(op <= 7);

And here we assert it is <= 7?


> +var = aml_opcode(op);
> +return var;
> +}
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index 8b954d9..6e25315 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
> max_base,
>  Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
>uint32_t offset, uint32_t len);
>  Aml *aml_named_field(const char *name, unsigned length);
> +Aml *aml_local(int num);
>  
>  /* Block AML object primitives */
>  Aml *aml_def_block(const char *signature, uint8_t revision,
> -- 
> 1.8.3.1



Re: [Qemu-devel] [PATCH 0/2] vnc: -readconfig fixups

2015-02-17 Thread Markus Armbruster
Gerd Hoffmann  writes:

>   Hi,
>
> Series applies on top of the pending vnc pull request.
> Fix -writeconfig/-readconfig related fallout from
> the QemuOpts conversion of the vnc configuration.

Tested-by: Markus Armbruster 

I don't like that ID "default" is special, but as long as I can't offer
better ideas...



Re: [Qemu-devel] [RFC PATCH v8 08/21] cpu: replay instructions sequence

2015-02-17 Thread Paolo Bonzini


On 17/02/2015 12:35, Pavel Dovgaluk wrote:
> How can I wake up iothread if there are no pending timers?
> deadline will (almost) never become zero in my case, because there is 
> another kind of event in the log (not the timer one).
> Should I fetch the event and call qemu_notify_event() from replay module?

Yes, a few mails ago I suggested that (maybe I got the wrong function in
the replay module).

Paolo



Re: [Qemu-devel] [PATCH 01/25] s390x/mmu: Move mmu_translate() and friends to separate file

2015-02-17 Thread Alexander Graf

On 02/12/2015 06:09 PM, Jens Freimann wrote:

From: Thomas Huth 

helper.c is quite overcrowded already, so let's move the MMU
translation to a separate file instead (like it has been done
with the other targets already).

Signed-off-by: Thomas Huth 
Signed-off-by: Jens Freimann 


Acked-by: Alexander Graf 


Alex




[Qemu-devel] [PATCH v11 0/5] Netduino 2 Machine Model

2015-02-17 Thread Alistair Francis
This patch series adds the Netduino 2 Machine to QEMU

Information on the board is avalible at:
http://www.netduino.com/netduino2/specs.htm

The git tree can be found at:
https://github.com/alistair23/qemu/tree/netduino2.11

Some example code that runs on QEMU is avaliable at:
at: https://github.com/alistair23/CSSE3010-QEMU-Examples

There are more devices in the works, I figured I would just start
with these three

V11:
 - Include/header fixes
 - Make the CPU model a property for the SoC
V9/V10:
 - Correct timer device based on Peter C's comments
V8:
 - Update the timer device based on Peter C's comments
 - Update the USART device based on Peter C's comments
V7:
 - Rebase to QEMU 2.2
V6:
 - Rename the three devices to STM32FXX*
 - Correct the timer to use ns
 - Correct the number of devices that are inited
 - Rename memory regions


Alistair Francis (5):
  stm32f2xx_timer: Add the stm32f2xx Timer
  stm32f2xx_USART: Add the stm32f2xx USART Controller
  stm32f2xx_SYSCFG: Add the stm32f2xx SYSCFG
  stm32f205: Add the stm32f205 SoC
  netduino2: Add the Netduino 2 Machine

 default-configs/arm-softmmu.mak|   4 +
 hw/arm/Makefile.objs   |   2 +
 hw/arm/netduino2.c |  57 +++
 hw/arm/stm32f205_soc.c | 160 ++
 hw/char/Makefile.objs  |   1 +
 hw/char/stm32f2xx_usart.c  | 229 ++
 hw/misc/Makefile.objs  |   1 +
 hw/misc/stm32f2xx_syscfg.c | 160 ++
 hw/timer/Makefile.objs |   2 +
 hw/timer/stm32f2xx_timer.c | 328 +
 include/hw/arm/stm32f205_soc.h |  57 +++
 include/hw/char/stm32f2xx_usart.h  |  73 +
 include/hw/misc/stm32f2xx_syscfg.h |  61 +++
 include/hw/timer/stm32f2xx_timer.h | 101 
 14 files changed, 1236 insertions(+)
 create mode 100644 hw/arm/netduino2.c
 create mode 100644 hw/arm/stm32f205_soc.c
 create mode 100644 hw/char/stm32f2xx_usart.c
 create mode 100644 hw/misc/stm32f2xx_syscfg.c
 create mode 100644 hw/timer/stm32f2xx_timer.c
 create mode 100644 include/hw/arm/stm32f205_soc.h
 create mode 100644 include/hw/char/stm32f2xx_usart.h
 create mode 100644 include/hw/misc/stm32f2xx_syscfg.h
 create mode 100644 include/hw/timer/stm32f2xx_timer.h

-- 
2.1.0




[Qemu-devel] [PATCH v11 3/5] stm32f2xx_SYSCFG: Add the stm32f2xx SYSCFG

2015-02-17 Thread Alistair Francis
This patch adds the stm32f2xx System Configuration
Controller. This is used to configure what memory is mapped
at address 0 (although that is not supported) as well
as configure how the EXTI interrupts work (also not
supported at the moment).

This device is not required for basic examples, but more
complex systems will require it (as well as the EXTI device)

Signed-off-by: Alistair Francis 
Reviewed-by: Peter Crosthwaite 
---
V6:
 - Rename to STM32F2XX
 - Remove all casts from debug printing

 default-configs/arm-softmmu.mak|   1 +
 hw/misc/Makefile.objs  |   1 +
 hw/misc/stm32f2xx_syscfg.c | 160 +
 include/hw/misc/stm32f2xx_syscfg.h |  61 ++
 4 files changed, 223 insertions(+)
 create mode 100644 hw/misc/stm32f2xx_syscfg.c
 create mode 100644 include/hw/misc/stm32f2xx_syscfg.h

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index b28e662..dead36b 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -80,6 +80,7 @@ CONFIG_ZAURUS=y
 CONFIG_ZYNQ=y
 CONFIG_STM32F2XX_TIMER=y
 CONFIG_STM32F2XX_USART=y
+CONFIG_STM32F2XX_SYSCFG=y
 
 CONFIG_VERSATILE_PCI=y
 CONFIG_VERSATILE_I2C=y
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index 029a56f..049c1a0 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -38,6 +38,7 @@ obj-$(CONFIG_OMAP) += omap_sdrc.o
 obj-$(CONFIG_OMAP) += omap_tap.o
 obj-$(CONFIG_SLAVIO) += slavio_misc.o
 obj-$(CONFIG_ZYNQ) += zynq_slcr.o
+obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
 
 obj-$(CONFIG_PVPANIC) += pvpanic.o
 obj-$(CONFIG_EDU) += edu.o
diff --git a/hw/misc/stm32f2xx_syscfg.c b/hw/misc/stm32f2xx_syscfg.c
new file mode 100644
index 000..4ae4042
--- /dev/null
+++ b/hw/misc/stm32f2xx_syscfg.c
@@ -0,0 +1,160 @@
+/*
+ * STM32F2XX SYSCFG
+ *
+ * Copyright (c) 2014 Alistair Francis 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/misc/stm32f2xx_syscfg.h"
+
+#ifndef STM_SYSCFG_ERR_DEBUG
+#define STM_SYSCFG_ERR_DEBUG 0
+#endif
+
+#define DB_PRINT_L(lvl, fmt, args...) do { \
+if (STM_SYSCFG_ERR_DEBUG >= lvl) { \
+qemu_log("%s: " fmt, __func__, ## args); \
+} \
+} while (0);
+
+#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
+
+static void stm32f2xx_syscfg_reset(DeviceState *dev)
+{
+STM32F2XXSyscfgState *s = STM32F2XX_SYSCFG(dev);
+
+s->syscfg_memrmp = 0x;
+s->syscfg_pmc = 0x;
+s->syscfg_exticr1 = 0x;
+s->syscfg_exticr2 = 0x;
+s->syscfg_exticr3 = 0x;
+s->syscfg_exticr4 = 0x;
+s->syscfg_cmpcr = 0x;
+}
+
+static uint64_t stm32f2xx_syscfg_read(void *opaque, hwaddr addr,
+ unsigned int size)
+{
+STM32F2XXSyscfgState *s = opaque;
+
+DB_PRINT("0x%"HWADDR_PRIx"\n", addr);
+
+switch (addr) {
+case SYSCFG_MEMRMP:
+return s->syscfg_memrmp;
+case SYSCFG_PMC:
+return s->syscfg_pmc;
+case SYSCFG_EXTICR1:
+return s->syscfg_exticr1;
+case SYSCFG_EXTICR2:
+return s->syscfg_exticr2;
+case SYSCFG_EXTICR3:
+return s->syscfg_exticr3;
+case SYSCFG_EXTICR4:
+return s->syscfg_exticr4;
+case SYSCFG_CMPCR:
+return s->syscfg_cmpcr;
+default:
+qemu_log_mask(LOG_GUEST_ERROR,
+  "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr);
+return 0;
+}
+
+return 0;
+}
+
+static void stm32f2xx_syscfg_write(void *opaque, hwaddr addr,
+   uint64_t val64, unsigned int size)
+{
+STM32F2XXSyscfgState *s = opaque;
+uint32_t value = val64;
+
+DB_PRINT("0x%x, 0x%"HWADDR_PRIx"\n", value, addr);
+
+switch (addr) {
+case SYSCFG_MEMRMP:
+qemu_log_mask(LOG_UNIMP,
+  "%s: Changeing the memory mapping isn't supported " \
+  "in QEMU\n", __func__);
+

[Qemu-devel] [PATCH v11 1/5] stm32f2xx_timer: Add the stm32f2xx Timer

2015-02-17 Thread Alistair Francis
This patch adds the stm32f2xx timers: TIM2, TIM3, TIM4 and TIM5
to QEMU.

Signed-off-by: Alistair Francis 
Signed-off-by: Peter Crosthwaite 
Reviewed-by: Peter Crosthwaite 
---
V11:
 - Tidy up the register write refresh code
V10:
 - Correct the units based on a patch by Peter C
V9:
 - Convert tick_offset to now be updated on more events
- This is similar to what I did with the ARM PCCNT regiseter
V8:
 - Fix tick_offset to allow now to wrap around
 - Remove the calls to get_ticks_per_sec()
 - Pre-scale the guest visable time
V6:
 - Rename to STM32F2XX
 - Change the timer calculations to use ns
 - Update the value to timer_mod to ensure it is in ns
 - Account for reloadable/resetable timer
- Thanks to Peter C for pointing this out

 default-configs/arm-softmmu.mak|   1 +
 hw/timer/Makefile.objs |   2 +
 hw/timer/stm32f2xx_timer.c | 328 +
 include/hw/timer/stm32f2xx_timer.h | 101 
 4 files changed, 432 insertions(+)
 create mode 100644 hw/timer/stm32f2xx_timer.c
 create mode 100644 include/hw/timer/stm32f2xx_timer.h

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 7671ee2..27697c3 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -78,6 +78,7 @@ CONFIG_NSERIES=y
 CONFIG_REALVIEW=y
 CONFIG_ZAURUS=y
 CONFIG_ZYNQ=y
+CONFIG_STM32F2XX_TIMER=y
 
 CONFIG_VERSATILE_PCI=y
 CONFIG_VERSATILE_I2C=y
diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
index 2c86c3d..133bd0d 100644
--- a/hw/timer/Makefile.objs
+++ b/hw/timer/Makefile.objs
@@ -31,3 +31,5 @@ obj-$(CONFIG_DIGIC) += digic-timer.o
 obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
 
 obj-$(CONFIG_ALLWINNER_A10_PIT) += allwinner-a10-pit.o
+
+common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o
diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
new file mode 100644
index 000..ecadf9d
--- /dev/null
+++ b/hw/timer/stm32f2xx_timer.c
@@ -0,0 +1,328 @@
+/*
+ * STM32F2XX Timer
+ *
+ * Copyright (c) 2014 Alistair Francis 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/timer/stm32f2xx_timer.h"
+
+#ifndef STM_TIMER_ERR_DEBUG
+#define STM_TIMER_ERR_DEBUG 0
+#endif
+
+#define DB_PRINT_L(lvl, fmt, args...) do { \
+if (STM_TIMER_ERR_DEBUG >= lvl) { \
+qemu_log("%s: " fmt, __func__, ## args); \
+} \
+} while (0);
+
+#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
+
+static void stm32f2xx_timer_set_alarm(STM32F2XXTimerState *s, int64_t now);
+
+static void stm32f2xx_timer_interrupt(void *opaque)
+{
+STM32F2XXTimerState *s = opaque;
+
+DB_PRINT("Interrupt\n");
+
+if (s->tim_dier & TIM_DIER_UIE && s->tim_cr1 & TIM_CR1_CEN) {
+s->tim_sr |= 1;
+qemu_irq_pulse(s->irq);
+stm32f2xx_timer_set_alarm(s, s->hit_time);
+}
+}
+
+static inline int64_t stm32f2xx_ns_to_ticks(STM32F2XXTimerState *s, int64_t t)
+{
+return muldiv64(t, s->freq_hz, 10ULL) / (s->tim_psc + 1);
+}
+
+static void stm32f2xx_timer_set_alarm(STM32F2XXTimerState *s, int64_t now)
+{
+uint64_t ticks;
+int64_t now_ticks;
+
+if (s->tim_arr == 0) {
+return;
+}
+
+DB_PRINT("Alarm set at: 0x%x\n", s->tim_cr1);
+
+now_ticks = stm32f2xx_ns_to_ticks(s, now);
+ticks = s->tim_arr - (now_ticks - s->tick_offset);
+
+DB_PRINT("Alarm set in %d ticks\n", (int) ticks);
+
+s->hit_time = muldiv64((ticks + (uint64_t) now_ticks) * (s->tim_psc + 1),
+   10ULL, s->freq_hz);
+
+timer_mod(s->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->hit_time);
+DB_PRINT("Wait Time: %" PRId64 " ticks\n", s->hit_time);
+}
+
+static void stm32f2xx_timer_reset(DeviceState *dev)
+{
+STM32F2XXTimerState *s = STM32F2XXTIMER(dev);
+int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+
+s->tim_cr1 = 0;
+s->tim_cr2 = 0;
+s->tim_smcr = 0;
+s->tim_dier = 0

[Qemu-devel] [PATCH v11 4/5] stm32f205: Add the stm32f205 SoC

2015-02-17 Thread Alistair Francis
This patch adds the stm32f205 SoC. This will be used by the
Netduino 2 to create a machine.

Signed-off-by: Alistair Francis 
---
V11:
 - Update the headers to only include the required files
 - Make the CPU Model a property that can be defined
V6:
 - Correct the number of USART/UART devices
 - Use macros to define how many devices are inited
 - Update the memory regions name from netduino.* to
   STM32F205.*

 default-configs/arm-softmmu.mak |   1 +
 hw/arm/Makefile.objs|   1 +
 hw/arm/stm32f205_soc.c  | 160 
 include/hw/arm/stm32f205_soc.h  |  57 ++
 4 files changed, 219 insertions(+)
 create mode 100644 hw/arm/stm32f205_soc.c
 create mode 100644 include/hw/arm/stm32f205_soc.h

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index dead36b..c8e9ada 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -81,6 +81,7 @@ CONFIG_ZYNQ=y
 CONFIG_STM32F2XX_TIMER=y
 CONFIG_STM32F2XX_USART=y
 CONFIG_STM32F2XX_SYSCFG=y
+CONFIG_STM32F205_SOC=y
 
 CONFIG_VERSATILE_PCI=y
 CONFIG_VERSATILE_I2C=y
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 6088e53..9769317 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -8,3 +8,4 @@ obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o 
pxa2xx_pic.o
 obj-$(CONFIG_DIGIC) += digic.o
 obj-y += omap1.o omap2.o strongarm.o
 obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
+obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
diff --git a/hw/arm/stm32f205_soc.c b/hw/arm/stm32f205_soc.c
new file mode 100644
index 000..0f3bdc7
--- /dev/null
+++ b/hw/arm/stm32f205_soc.c
@@ -0,0 +1,160 @@
+/*
+ * STM32F205 SoC
+ *
+ * Copyright (c) 2014 Alistair Francis 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/arm/arm.h"
+#include "exec/address-spaces.h"
+#include "hw/arm/stm32f205_soc.h"
+
+/* At the moment only Timer 2 to 5 are modelled */
+static const uint32_t timer_addr[STM_NUM_TIMERS] = { 0x4000, 0x4400,
+0x4800, 0x4C00 };
+static const uint32_t usart_addr[STM_NUM_USARTS] = { 0x40011000, 0x40004400,
+0x40004800, 0x40004C00, 0x40005000, 0x40011400 };
+
+static const int timer_irq[STM_NUM_TIMERS] = {28, 29, 30, 50};
+static const int usart_irq[STM_NUM_USARTS] = {37, 38, 39, 52, 53, 71};
+
+static void stm32f205_soc_initfn(Object *obj)
+{
+STM32F205State *s = STM32F205_SOC(obj);
+int i;
+
+object_initialize(&s->syscfg, sizeof(s->syscfg), TYPE_STM32F2XX_SYSCFG);
+qdev_set_parent_bus(DEVICE(&s->syscfg), sysbus_get_default());
+
+for (i = 0; i < STM_NUM_USARTS; i++) {
+object_initialize(&s->usart[i], sizeof(s->usart[i]),
+  TYPE_STM32F2XX_USART);
+qdev_set_parent_bus(DEVICE(&s->usart[i]), sysbus_get_default());
+}
+
+for (i = 0; i < STM_NUM_TIMERS; i++) {
+object_initialize(&s->timer[i], sizeof(s->timer[i]),
+  TYPE_STM32F2XX_TIMER);
+qdev_set_parent_bus(DEVICE(&s->timer[i]), sysbus_get_default());
+}
+}
+
+static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
+{
+STM32F205State *s = STM32F205_SOC(dev_soc);
+DeviceState *syscfgdev, *usartdev, *timerdev;
+SysBusDevice *syscfgbusdev, *usartbusdev, *timerbusdev;
+qemu_irq *pic;
+Error *err = NULL;
+int i;
+
+MemoryRegion *system_memory = get_system_memory();
+MemoryRegion *sram = g_new(MemoryRegion, 1);
+MemoryRegion *flash = g_new(MemoryRegion, 1);
+MemoryRegion *flash_alias = g_new(MemoryRegion, 1);
+
+memory_region_init_ram(flash, NULL, "STM32F205.flash", FLASH_SIZE,
+   &error_abort);
+memory_region_init_alias(flash_alias, NULL, "STM32F205.flash.alias",
+ flash, 0, FLASH_SIZE);
+
+vmstate_register_ram_global(flash);
+
+memory_region_set_readonly(flash, true);
+memory_region_

[Qemu-devel] [PATCH v11 2/5] stm32f2xx_USART: Add the stm32f2xx USART Controller

2015-02-17 Thread Alistair Francis
This patch adds the stm32f2xx USART controller
(UART also uses the same controller).

Signed-off-by: Alistair Francis 
Reviewed-by: Peter Crosthwaite 
---
V11:
 - Update the header macros to only be included once
V8:
 - Clear IRQ on reset
 - Lower IRQ on data read/status clear
 - Set IRQ if enabled while data is avaliable
V6:
 - Rename to STM32F2XX
 - Fix up unimplemented printing
 - Add a qemu_chr_accept()

 default-configs/arm-softmmu.mak   |   1 +
 hw/char/Makefile.objs |   1 +
 hw/char/stm32f2xx_usart.c | 229 ++
 include/hw/char/stm32f2xx_usart.h |  73 
 4 files changed, 304 insertions(+)
 create mode 100644 hw/char/stm32f2xx_usart.c
 create mode 100644 include/hw/char/stm32f2xx_usart.h

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 27697c3..b28e662 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -79,6 +79,7 @@ CONFIG_REALVIEW=y
 CONFIG_ZAURUS=y
 CONFIG_ZYNQ=y
 CONFIG_STM32F2XX_TIMER=y
+CONFIG_STM32F2XX_USART=y
 
 CONFIG_VERSATILE_PCI=y
 CONFIG_VERSATILE_I2C=y
diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs
index 317385d..5931cc8 100644
--- a/hw/char/Makefile.objs
+++ b/hw/char/Makefile.objs
@@ -15,6 +15,7 @@ obj-$(CONFIG_OMAP) += omap_uart.o
 obj-$(CONFIG_SH4) += sh_serial.o
 obj-$(CONFIG_PSERIES) += spapr_vty.o
 obj-$(CONFIG_DIGIC) += digic-uart.o
+obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o
 
 common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o
 common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o
diff --git a/hw/char/stm32f2xx_usart.c b/hw/char/stm32f2xx_usart.c
new file mode 100644
index 000..260b053
--- /dev/null
+++ b/hw/char/stm32f2xx_usart.c
@@ -0,0 +1,229 @@
+/*
+ * STM32F2XX USART
+ *
+ * Copyright (c) 2014 Alistair Francis 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/char/stm32f2xx_usart.h"
+
+#ifndef STM_USART_ERR_DEBUG
+#define STM_USART_ERR_DEBUG 0
+#endif
+
+#define DB_PRINT_L(lvl, fmt, args...) do { \
+if (STM_USART_ERR_DEBUG >= lvl) { \
+qemu_log("%s: " fmt, __func__, ## args); \
+} \
+} while (0);
+
+#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
+
+static int stm32f2xx_usart_can_receive(void *opaque)
+{
+STM32F2XXUsartState *s = opaque;
+
+if (!(s->usart_sr & USART_SR_RXNE)) {
+return 1;
+}
+
+return 0;
+}
+
+static void stm32f2xx_usart_receive(void *opaque, const uint8_t *buf, int size)
+{
+STM32F2XXUsartState *s = opaque;
+
+s->usart_dr = *buf;
+
+if (!(s->usart_cr1 & USART_CR1_UE && s->usart_cr1 & USART_CR1_RE)) {
+/* USART not enabled - drop the chars */
+DB_PRINT("Dropping the chars\n");
+return;
+}
+
+s->usart_sr |= USART_SR_RXNE;
+
+if (s->usart_cr1 & USART_CR1_RXNEIE) {
+qemu_set_irq(s->irq, 1);
+}
+
+DB_PRINT("Receiving: %c\n", s->usart_dr);
+}
+
+static void stm32f2xx_usart_reset(DeviceState *dev)
+{
+STM32F2XXUsartState *s = STM32F2XX_USART(dev);
+
+s->usart_sr = USART_SR_RESET;
+s->usart_dr = 0x;
+s->usart_brr = 0x;
+s->usart_cr1 = 0x;
+s->usart_cr2 = 0x;
+s->usart_cr3 = 0x;
+s->usart_gtpr = 0x;
+
+qemu_set_irq(s->irq, 0);
+}
+
+static uint64_t stm32f2xx_usart_read(void *opaque, hwaddr addr,
+   unsigned int size)
+{
+STM32F2XXUsartState *s = opaque;
+uint64_t retvalue;
+
+DB_PRINT("Read 0x%"HWADDR_PRIx"\n", addr);
+
+switch (addr) {
+case USART_SR:
+retvalue = s->usart_sr;
+s->usart_sr &= ~USART_SR_TC;
+if (s->chr) {
+qemu_chr_accept_input(s->chr);
+}
+return retvalue;
+case USART_DR:
+DB_PRINT("Value: 0x%" PRIx32 ", %c\n", s->usart_dr, (char) 
s->usart_dr);
+s->usart_sr |= USART_SR_TXE;
+s->usart_sr &= ~USART_SR_RXNE;
+if (s->chr)

Re: [Qemu-devel] [PATCH v3] ui/cocoa.m: Machine menu patch for Mac OS X

2015-02-17 Thread Markus Armbruster
Kevin Wolf  writes:

> Am 16.02.2015 um 18:00 hat Programmingkid geschrieben:
>> 
>> On Feb 16, 2015, at 11:22 AM, Kevin Wolf wrote:
>> 
>> > Am 16.02.2015 um 17:12 hat Programmingkid geschrieben:
>> >> 
>> >> On Feb 16, 2015, at 10:42 AM, Kevin Wolf wrote:
>> >> 
>> >>> Am 16.02.2015 um 16:31 hat Programmingkid geschrieben:
>>  
>>  On Feb 16, 2015, at 5:08 AM, Kevin Wolf wrote:
>>  
>> > Am 14.02.2015 um 03:28 hat Peter Maydell geschrieben:
>> >> On 14 February 2015 at 01:43, Programmingkid
>> >>  wrote:
>> >>> Added features:
>> >>> Menu items to switch floppy and CD image files.
>> >>> Menu items to eject floppy and CD image files.
>> >>> Menu item to use /dev/cdrom.
>> >>> Verifies with the user before quitting QEMU by displaying a
>> >>> dialog box.
>> >>> 
>> >>> Signed-off-by: John Arbuckle 
>> >> 
>> >> Stefan, Kevin -- could you review the bits of this patch
>> >> which determine whether the machine has a floppy/cdrom
>> >> drive and if so let the user insert/inject it, please?
>> >> (that's the emulatorHasDevice and ejectFloppy/changeFloppy
>> >> functions, mostly). I don't know the block layer APIs so
>> >> I can't really say if this patch is doing it in the best/
>> >> non-deprecated/etc way or not...
>> > 
>> > Well, it's trying to detect the floppy/cdrom device by comparing string
>> > with default IDs that can be overridden by the user, so no, that's
>> > probably far from the best way to do it. The code also doesn't consider
>> > that you could have more than one floppy or cdrom drive.
>> > 
>> > The correct way is probably to just display any removable block device,
>> > and ideally also to implement some notifiers to deal with hotplug.
>>  
>>  Could you provide examples?
>> >>> 
>> >>> You already use qmp_query_block(), so you get all existing devices.
>> >>> Currently you filter for everything that has a name that starts with
>> >>> either 'floppy' or 'cdrom'. You could filter for info->removable == true
>> >>> instead.
>> >> 
>> >> 
>> >>> 
>> >>> Of course, you'd have to do this while building up the menu, so that the
>> >>> menu will contain dynamically generated entries for every device.
>> >>> 
>> >>> Hotplug is a bit trickier, I guess. If you can make sure that qemu
>> >>> doesn't crash if the device for a menu entry has gone away, that would
>> >>> probably be acceptable for the start.
>> >> 
>> >> So what you want me to do is loop thru each entry in the
>> >> BlockInfoList (returned by qmp_query_block() ) and see if it is
>> >> removable. Then just add a menu item for the device name. If I
>> >> did that we would have menu items like "ide1-cd0" and
>> >> "floppy0". The menu items would not have intuitive names that the
>> >> user would be able to understand easily. Sorry but your idea is
>> >> not user friendly. I did look at the type field of the
>> >> BlockInfoList structure and it is only set to "unknown". Maybe a
>> >> compromise would be the solution. We set the type field to the
>> >> common name of the device. "ide1-cd0" would have a type field set
>> >> to "cdrom". Then set the menu item to this type field's value.
>> > 
>> > You could still apply some translation table to the menu entry string,
>> > like:
>> > 
>> > floppy0 => Floppy drive A
>> > floppy1 => Floppy drive B
>> > ide0-cd0=> IDE CD-ROM (Primary Master)
>> > ide0-cd1=> IDE CD-ROM (Primary Slave)
>> > ide1-cd0=> IDE CD-ROM (Secondary Master)
>> > ide1-cd1=> IDE CD-ROM (Secondary Slave)
>> > 
>> > And everything else just gets the block device ID in the menu name. Then
>> > you get user friendly menu entry names where we have an idea what the
>> > device might be, but still let the device show up with an identifiable
>> > name when we don't.
>> > 
>> > Because having a CD-ROM drive not show up at all is definitely even less
>> > user friendly than having a cryptic name for it.
>> 
>> This is a good start, but still needs more work. Is it safe to
>> assume all cdrom drives in QEMU will have "cd" in its name?
>> scsi0-cd0, ide0-cd0,...
>
> The ID is user-defined, so no, no assumption about it is safe.  If you
> like, you can name your floppy drive 'ide0-cd1', your virtio harddisk
> 'floppy1' and your ATAPI CD-ROM drive 'virtio0'. But if you do that,
> I think it's reasonable to argue that it's your own fault that you get
> misleading menu entries. The default would yield the right results
> anyway.
>
> The only other option would be to start at the device tree, look for
> all known block devices with removable media, and then get the
> associated block backend from there. That would end up a lot more
> complicated, though.

The backend has a pointer to the frontend.  We could include the
frontend's canonical QOM path in some backend query- output.  Backends
that still haven't qdevified after all these years would make it warty,
however.

With the QOM path, you c

[Qemu-devel] [PATCH v11 5/5] netduino2: Add the Netduino 2 Machine

2015-02-17 Thread Alistair Francis
This patch adds the Netduino 2 Machine.

This is a Cortex-M3 based machine. Information can be found at:
http://www.netduino.com/netduino2/specs.htm

Signed-off-by: Alistair Francis 
Reviewed-by: Peter Crosthwaite 
---

 hw/arm/Makefile.objs |  1 +
 hw/arm/netduino2.c   | 57 
 2 files changed, 58 insertions(+)
 create mode 100644 hw/arm/netduino2.c

diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 9769317..2577f68 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -3,6 +3,7 @@ obj-$(CONFIG_DIGIC) += digic_boards.o
 obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o
 obj-y += omap_sx1.o palm.o realview.o spitz.o stellaris.o
 obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o
+obj-y += netduino2.o
 
 obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o
 obj-$(CONFIG_DIGIC) += digic.o
diff --git a/hw/arm/netduino2.c b/hw/arm/netduino2.c
new file mode 100644
index 000..8f26780
--- /dev/null
+++ b/hw/arm/netduino2.c
@@ -0,0 +1,57 @@
+/*
+ * Netduino 2 Machine Model
+ *
+ * Copyright (c) 2014 Alistair Francis 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/boards.h"
+#include "qemu/error-report.h"
+#include "hw/arm/stm32f205_soc.h"
+
+static void netduino2_init(MachineState *machine)
+{
+DeviceState *dev;
+Error *err = NULL;
+
+dev = qdev_create(NULL, TYPE_STM32F205_SOC);
+if (machine->kernel_filename) {
+qdev_prop_set_string(dev, "kernel-filename", machine->kernel_filename);
+}
+qdev_prop_set_string(dev, "cpu-model", "cortex-m3");
+object_property_set_bool(OBJECT(dev), true, "realized", &err);
+if (err != NULL) {
+error_report("%s", error_get_pretty(err));
+exit(1);
+}
+}
+
+static QEMUMachine netduino2_machine = {
+.name = "netduino2",
+.desc = "Netduino 2 Machine",
+.init = netduino2_init,
+};
+
+static void netduino2_machine_init(void)
+{
+qemu_register_machine(&netduino2_machine);
+}
+
+machine_init(netduino2_machine_init);
-- 
2.1.0




Re: [Qemu-devel] [PATCH v3 03/17] virtio: use standard virtio_ring.h

2015-02-17 Thread Thomas Huth
On Mon, 16 Feb 2015 22:35:40 +0100
"Michael S. Tsirkin"  wrote:

> Switch to virtio_ring.h from standard headers.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  include/hw/virtio/dataplane/vring.h |   2 +-
>  include/hw/virtio/virtio_ring.h | 167 
> 
>  hw/net/vhost_net.c  |   2 +-
>  3 files changed, 2 insertions(+), 169 deletions(-)
>  delete mode 100644 include/hw/virtio/virtio_ring.h
> 
> diff --git a/include/hw/virtio/dataplane/vring.h 
> b/include/hw/virtio/dataplane/vring.h
> index d3e086a..836d26a 100644
> --- a/include/hw/virtio/dataplane/vring.h
> +++ b/include/hw/virtio/dataplane/vring.h
> @@ -18,7 +18,7 @@
>  #define VRING_H
> 
>  #include "qemu-common.h"
> -#include "hw/virtio/virtio_ring.h"
> +#include "standard-headers/linux/virtio_ring.h"
>  #include "hw/virtio/virtio.h"
> 
>  typedef struct {
> diff --git a/include/hw/virtio/virtio_ring.h b/include/hw/virtio/virtio_ring.h
> deleted file mode 100644
> index 0b42e6e..000
> --- a/include/hw/virtio/virtio_ring.h
> +++ /dev/null
> @@ -1,167 +0,0 @@
> -#ifndef _LINUX_VIRTIO_RING_H
> -#define _LINUX_VIRTIO_RING_H
> -/*
> - * This file is copied from /usr/include/linux while converting __uNN types
> - * to uXX_t, __inline__ to inline, and tab to spaces.
> - * */

Hmmm, in the old header, the "__inline__" was replaced with
"inline" ... in the new header from patch 2, there's now "__inline__"
again. Was there a good reason for this replacement? If yes, your
update-linux-headers.sh patch should maybe replace the "__inline__"
into "inline", too?

Apart from that, the patch looks good to me.

 Thomas




Re: [Qemu-devel] [PATCH v3 02/17] include: import virtio headers from linux 4.0

2015-02-17 Thread Thomas Huth
On Mon, 16 Feb 2015 22:35:31 +0100
"Michael S. Tsirkin"  wrote:

> Add files imported from linux-next (what will become linux 4.0) using
> scripts/update-linux-headers.sh
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  include/standard-headers/linux/if_ether.h   |   1 +
>  include/standard-headers/linux/types.h  |   2 +
>  include/standard-headers/linux/virtio_9p.h  |  44 +
>  include/standard-headers/linux/virtio_balloon.h |  59 ++
>  include/standard-headers/linux/virtio_blk.h | 143 +++
>  include/standard-headers/linux/virtio_config.h  |  64 +++
>  include/standard-headers/linux/virtio_console.h |  78 
>  include/standard-headers/linux/virtio_ids.h |  43 +
>  include/standard-headers/linux/virtio_net.h | 233 
> 
>  include/standard-headers/linux/virtio_pci.h | 193 
>  include/standard-headers/linux/virtio_ring.h| 171 +
>  include/standard-headers/linux/virtio_rng.h |   8 +
>  include/standard-headers/linux/virtio_scsi.h| 164 +
>  include/standard-headers/linux/virtio_types.h   |  46 +
>  14 files changed, 1249 insertions(+)
>  create mode 100644 include/standard-headers/linux/if_ether.h
>  create mode 100644 include/standard-headers/linux/types.h
>  create mode 100644 include/standard-headers/linux/virtio_9p.h
>  create mode 100644 include/standard-headers/linux/virtio_balloon.h
>  create mode 100644 include/standard-headers/linux/virtio_blk.h
>  create mode 100644 include/standard-headers/linux/virtio_config.h
>  create mode 100644 include/standard-headers/linux/virtio_console.h
>  create mode 100644 include/standard-headers/linux/virtio_ids.h
>  create mode 100644 include/standard-headers/linux/virtio_net.h
>  create mode 100644 include/standard-headers/linux/virtio_pci.h
>  create mode 100644 include/standard-headers/linux/virtio_ring.h
>  create mode 100644 include/standard-headers/linux/virtio_rng.h
>  create mode 100644 include/standard-headers/linux/virtio_scsi.h
>  create mode 100644 include/standard-headers/linux/virtio_types.h
> 
> diff --git a/include/standard-headers/linux/if_ether.h 
> b/include/standard-headers/linux/if_ether.h
> new file mode 100644
> index 000..91cf735
> --- /dev/null
> +++ b/include/standard-headers/linux/if_ether.h
> @@ -0,0 +1 @@
> +#define ETH_ALEN6
> diff --git a/include/standard-headers/linux/types.h 
> b/include/standard-headers/linux/types.h
> new file mode 100644
> index 000..7d42ac6
> --- /dev/null
> +++ b/include/standard-headers/linux/types.h
> @@ -0,0 +1,2 @@
> +#include 

That should be  now, shouldn't it?

 Thomas




Re: [Qemu-devel] [PATCH v2 0/3] -incoming pause

2015-02-17 Thread Amit Shah
On (Wed) 11 Feb 2015 [16:46:21], Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> This patchset provides a way of setting options on an incoming
> migration before the fd/process/socket has been created.
> 
>start qemu with   -incoming pause
>
>migrate_incoming theuri
> 
> v2:
>   Create migrate_incoming/migrate-incoming rather than squashing the -u
>   into the existing migrate command.

So the only comment I have is with the 'pause' name.

'pause' to me means there's a time period for which a pause has to be
done; or pausing an activity which is already in progress, both of
which are not true for this case.

My suggestions are 'wait' or 'hold' -- wait signifies we wait for a
connection; the uri for which we give later; similar for hold.


Amit



Re: [Qemu-devel] [PATCH v3 04/17] virtio: use standard-headers

2015-02-17 Thread Thomas Huth
On Mon, 16 Feb 2015 22:35:46 +0100
"Michael S. Tsirkin"  wrote:

> Drop a bunch of code duplicated from virtio_config.h and virtio_ring.h.
> This makes us rename event index accessors which conflict,
> as reusing the ones from virtio_ring.h isn't trivial.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  hw/9pfs/virtio-9p.h|  1 +
>  include/hw/virtio/virtio.h | 48 
> ++
>  hw/virtio/virtio.c | 23 +-
>  3 files changed, 8 insertions(+), 64 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
> index 2c3603a..0776424 100644
> --- a/hw/9pfs/virtio-9p.h
> +++ b/hw/9pfs/virtio-9p.h
> @@ -8,6 +8,7 @@
>  #include 
>  #include 
>  #include "hw/virtio/virtio.h"
> +#include "hw/virtio/virtio-9p.h"
>  #include "fsdev/file-op-9p.h"
>  #include "fsdev/virtio-9p-marshal.h"
>  #include "qemu/thread.h"
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index f24997d..d1b416b 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -19,56 +19,12 @@
>  #include "hw/qdev.h"
>  #include "sysemu/sysemu.h"
>  #include "qemu/event_notifier.h"
> -#ifdef CONFIG_VIRTFS
> -#include "hw/virtio/virtio-9p.h"
> -#endif
> +#include "standard-headers/linux/virtio_config.h"
> +#include "standard-headers/linux/virtio_ring.h"
> 
> -/* from Linux's linux/virtio_config.h */
> -
> -/* Status byte for guest to report progress, and synchronize features. */
> -/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) 
> */
> -#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
> -/* We have found a driver for the device. */
> -#define VIRTIO_CONFIG_S_DRIVER  2
> -/* Driver has used its parts of the config, and is happy */
> -#define VIRTIO_CONFIG_S_DRIVER_OK   4
> -/* We've given up on this device. */
> -#define VIRTIO_CONFIG_S_FAILED  0x80
> -
> -/* Some virtio feature bits (currently bits 28 through 31) are reserved for 
> the
> - * transport being used (eg. virtio_ring), the rest are per-device feature 
> bits. */
> -#define VIRTIO_TRANSPORT_F_START28
> -#define VIRTIO_TRANSPORT_F_END  32
> -
> -/* We notify when the ring is completely used, even if the guest is 
> suppressing
> - * callbacks */
> -#define VIRTIO_F_NOTIFY_ON_EMPTY24
> -/* Can the device handle any descriptor layout? */
> -#define VIRTIO_F_ANY_LAYOUT 27
> -/* We support indirect buffer descriptors */
> -#define VIRTIO_RING_F_INDIRECT_DESC 28
> -/* The Guest publishes the used index for which it expects an interrupt
> - * at the end of the avail ring. Host should ignore the avail->flags field. 
> */
> -/* The Host publishes the avail index for which it expects a kick
> - * at the end of the used ring. Guest should ignore the used->flags field. */
> -#define VIRTIO_RING_F_EVENT_IDX 29
>  /* A guest should never accept this.  It implies negotiation is broken. */
>  #define VIRTIO_F_BAD_FEATURE 30
> 
> -/* from Linux's linux/virtio_ring.h */
> -
> -/* This marks a buffer as continuing via the next field. */
> -#define VRING_DESC_F_NEXT   1
> -/* This marks a buffer as write-only (otherwise read-only). */
> -#define VRING_DESC_F_WRITE  2
> -/* This means the buffer contains a list of buffer descriptors. */
> -#define VRING_DESC_F_INDIRECT  4
> -
> -/* This means don't notify other side when buffer added. */
> -#define VRING_USED_F_NO_NOTIFY  1
> -/* This means don't interrupt guest when buffer consumed. */
> -#define VRING_AVAIL_F_NO_INTERRUPT  1
> -
>  struct VirtQueue;
> 
>  static inline hwaddr vring_align(hwaddr addr,
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index d735343..f783f31 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -155,7 +155,7 @@ static inline uint16_t vring_avail_ring(VirtQueue *vq, 
> int i)
>  return virtio_lduw_phys(vq->vdev, pa);
>  }
> 
> -static inline uint16_t vring_used_event(VirtQueue *vq)
> +static inline uint16_t vring_get_used_event(VirtQueue *vq)
>  {
>  return vring_avail_ring(vq, vq->vring.num);
>  }
> @@ -204,7 +204,7 @@ static inline void vring_used_flags_unset_bit(VirtQueue 
> *vq, int mask)
>  virtio_stw_phys(vdev, pa, virtio_lduw_phys(vdev, pa) & ~mask);
>  }
> 
> -static inline void vring_avail_event(VirtQueue *vq, uint16_t val)
> +static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
>  {
>  hwaddr pa;
>  if (!vq->notification) {
> @@ -218,7 +218,7 @@ void virtio_queue_set_notification(VirtQueue *vq, int 
> enable)
>  {
>  vq->notification = enable;
>  if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
> -vring_avail_event(vq, vring_avail_idx(vq));
> +vring_set_avail_event(vq, vring_avail_idx(vq));
>  } else if (enable) {
>  vring_used_flags_unset_bit(vq, VRING_USED_F_NO_NOTIFY);
>  } else {
> @@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
> 
>  i =

Re: [Qemu-devel] [PATCH v3 05/17] virtio-balloon: use standard headers

2015-02-17 Thread Thomas Huth
On Mon, 16 Feb 2015 22:35:52 +0100
"Michael S. Tsirkin"  wrote:

> Drop code duplicated from standard headers.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  include/hw/virtio/virtio-balloon.h | 35 ++-
>  1 file changed, 2 insertions(+), 33 deletions(-)
> 
> diff --git a/include/hw/virtio/virtio-balloon.h 
> b/include/hw/virtio/virtio-balloon.h
> index f863bfe..4ab8f54 100644
> --- a/include/hw/virtio/virtio-balloon.h
> +++ b/include/hw/virtio/virtio-balloon.h
> @@ -15,6 +15,7 @@
>  #ifndef _QEMU_VIRTIO_BALLOON_H
>  #define _QEMU_VIRTIO_BALLOON_H
> 
> +#include "standard-headers/linux/virtio_balloon.h"
>  #include "hw/virtio/virtio.h"
>  #include "hw/pci/pci.h"
> 
> @@ -22,39 +23,7 @@
>  #define VIRTIO_BALLOON(obj) \
>  OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON)
> 
> -/* from Linux's linux/virtio_balloon.h */
> -
> -/* The ID for virtio_balloon */
> -#define VIRTIO_ID_BALLOON 5
> -
> -/* The feature bitmap for virtio balloon */
> -#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
> -#define VIRTIO_BALLOON_F_STATS_VQ 1   /* Memory stats virtqueue */
> -
> -/* Size of a PFN in the balloon interface. */
> -#define VIRTIO_BALLOON_PFN_SHIFT 12
> -
> -struct virtio_balloon_config
> -{
> -/* Number of pages host wants Guest to give up. */
> -uint32_t num_pages;
> -/* Number of pages we've actually got in balloon. */
> -uint32_t actual;
> -};
> -
> -/* Memory Statistics */
> -#define VIRTIO_BALLOON_S_SWAP_IN  0   /* Amount of memory swapped in */
> -#define VIRTIO_BALLOON_S_SWAP_OUT 1   /* Amount of memory swapped out */
> -#define VIRTIO_BALLOON_S_MAJFLT   2   /* Number of major faults */
> -#define VIRTIO_BALLOON_S_MINFLT   3   /* Number of minor faults */
> -#define VIRTIO_BALLOON_S_MEMFREE  4   /* Total amount of free memory */
> -#define VIRTIO_BALLOON_S_MEMTOT   5   /* Total amount of memory */
> -#define VIRTIO_BALLOON_S_NR   6
> -
> -typedef struct VirtIOBalloonStat {
> -uint16_t tag;
> -uint64_t val;
> -} QEMU_PACKED VirtIOBalloonStat;
> +typedef struct virtio_balloon_stat VirtIOBalloonStat;
> 
>  typedef struct VirtIOBalloon {
>  VirtIODevice parent_obj;

Reviewed-by: Thomas Huth 




[Qemu-devel] [PATCH 0/4] ucb: Convert remaining PCI HCDs to realize

2015-02-17 Thread Markus Armbruster
This series requires my "[PATCH 00/10] pci: Partial conversion to
realize" and my "[PATCH 0/9] Clean up around error_get_pretty(),
qerror_report_err()".

Markus Armbruster (4):
  usb: Propagate errors through usb_register_companion()
  usb: Improve companion configuration error messages
  ohci: Complete conversion to realize
  uhci: Convert to realize

 hw/usb/bus.c  | 27 ++-
 hw/usb/hcd-ehci.c | 28 +++-
 hw/usb/hcd-ohci.c | 42 +++---
 hw/usb/hcd-uhci.c | 26 ++
 include/hw/usb.h  | 12 +++-
 5 files changed, 69 insertions(+), 66 deletions(-)

-- 
1.9.3




[Qemu-devel] [PATCH 3/4] ohci: Complete conversion to realize

2015-02-17 Thread Markus Armbruster
Commit 457215ec "ohci: Use QOM realize for OHCI" converted only
"sysbus-ohci".  Finish the job: convert "pci-ohci".

Signed-off-by: Markus Armbruster 
---
 hw/usb/hcd-ohci.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 21ec65f..e180a17 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -1827,10 +1827,10 @@ static USBPortOps ohci_port_ops = {
 static USBBusOps ohci_bus_ops = {
 };
 
-static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
- int num_ports, dma_addr_t localmem_base,
- char *masterbus, uint32_t firstport,
- AddressSpace *as)
+static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
+  int num_ports, dma_addr_t localmem_base,
+  char *masterbus, uint32_t firstport,
+  AddressSpace *as, Error **errp)
 {
 Error *err = NULL;
 int i;
@@ -1863,8 +1863,8 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState 
*dev,
USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL,
&err);
 if (err) {
-error_report_err(err);
-return -1;
+error_propagate(errp, err);
+return;
 }
 } else {
 usb_bus_new(&ohci->bus, sizeof(ohci->bus), &ohci_bus_ops, dev);
@@ -1884,8 +1884,6 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState 
*dev,
 
 ohci->async_td = 0;
 qemu_register_reset(ohci_reset, ohci);
-
-return 0;
 }
 
 #define TYPE_PCI_OHCI "pci-ohci"
@@ -1918,22 +1916,24 @@ static void ohci_die(OHCIState *ohci)
  PCI_STATUS_DETECTED_PARITY);
 }
 
-static int usb_ohci_initfn_pci(PCIDevice *dev)
+static void usb_ohci_realize_pci(PCIDevice *dev, Error **errp)
 {
+Error *err = NULL;
 OHCIPCIState *ohci = PCI_OHCI(dev);
 
 dev->config[PCI_CLASS_PROG] = 0x10; /* OHCI */
 dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
 
-if (usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0,
-  ohci->masterbus, ohci->firstport,
-  pci_get_address_space(dev)) != 0) {
-return -1;
+usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0,
+  ohci->masterbus, ohci->firstport,
+  pci_get_address_space(dev), &err);
+if (err) {
+error_propagate(errp, err);
+return;
 }
+
 ohci->state.irq = pci_allocate_irq(dev);
-
 pci_register_bar(dev, 0, 0, &ohci->state.mem);
-return 0;
 }
 
 static void usb_ohci_exit(PCIDevice *dev)
@@ -1975,7 +1975,7 @@ static void ohci_realize_pxa(DeviceState *dev, Error 
**errp)
 
 /* Cannot fail as we pass NULL for masterbus */
 usb_ohci_init(&s->ohci, dev, s->num_ports, s->dma_offset, NULL, 0,
-  &address_space_memory);
+  &address_space_memory, &error_abort);
 sysbus_init_irq(sbd, &s->ohci.irq);
 sysbus_init_mmio(sbd, &s->ohci.mem);
 }
@@ -2091,7 +2091,7 @@ static void ohci_pci_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = usb_ohci_initfn_pci;
+k->realize = usb_ohci_realize_pci;
 k->exit = usb_ohci_exit;
 k->vendor_id = PCI_VENDOR_ID_APPLE;
 k->device_id = PCI_DEVICE_ID_APPLE_IPID_USB;
-- 
1.9.3




[Qemu-devel] [PATCH 4/4] uhci: Convert to realize

2015-02-17 Thread Markus Armbruster
Signed-off-by: Markus Armbruster 
---
 hw/usb/hcd-uhci.c | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index 2ca8de3..e791377 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -66,7 +66,7 @@ struct UHCIInfo {
 uint16_t   device_id;
 uint8_trevision;
 uint8_tirq_pin;
-int(*initfn)(PCIDevice *dev);
+void   (*realize)(PCIDevice *dev, Error **errp);
 bool   unplug;
 };
 
@@ -1190,7 +1190,7 @@ static USBPortOps uhci_port_ops = {
 static USBBusOps uhci_bus_ops = {
 };
 
-static int usb_uhci_common_initfn(PCIDevice *dev)
+static void usb_uhci_common_realize(PCIDevice *dev, Error **errp)
 {
 Error *err = NULL;
 PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
@@ -1215,8 +1215,8 @@ static int usb_uhci_common_initfn(PCIDevice *dev)
USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL,
&err);
 if (err) {
-error_report_err(err);
-return -1;
+error_propagate(errp, err);
+return;
 }
 } else {
 usb_bus_new(&s->bus, sizeof(s->bus), &uhci_bus_ops, DEVICE(dev));
@@ -1238,11 +1238,9 @@ static int usb_uhci_common_initfn(PCIDevice *dev)
 /* Use region 4 for consistency with real hardware.  BSD guests seem
to rely on this.  */
 pci_register_bar(&s->dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar);
-
-return 0;
 }
 
-static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
+static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
 {
 UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
 uint8_t *pci_conf = s->dev.config;
@@ -1254,7 +1252,7 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
 /* USB legacy support  */
 pci_set_long(pci_conf + 0xc0,0x2000);
 
-return usb_uhci_common_initfn(dev);
+usb_uhci_common_realize(dev, errp);
 }
 
 static void usb_uhci_exit(PCIDevice *dev)
@@ -1300,7 +1298,7 @@ static void uhci_class_init(ObjectClass *klass, void 
*data)
 UHCIPCIDeviceClass *u = container_of(k, UHCIPCIDeviceClass, parent_class);
 UHCIInfo *info = data;
 
-k->init = info->initfn ? info->initfn : usb_uhci_common_initfn;
+k->realize = info->realize ? info->realize : usb_uhci_common_realize;
 k->exit = info->unplug ? usb_uhci_exit : NULL;
 k->vendor_id = info->vendor_id;
 k->device_id = info->device_id;
@@ -1339,7 +1337,7 @@ static UHCIInfo uhci_info[] = {
 .device_id = PCI_DEVICE_ID_VIA_UHCI,
 .revision  = 0x01,
 .irq_pin   = 3,
-.initfn= usb_uhci_vt82c686b_initfn,
+.realize   = usb_uhci_vt82c686b_realize,
 .unplug= true,
 },{
 .name  = "ich9-usb-uhci1", /* 00:1d.0 */
-- 
1.9.3




[Qemu-devel] [PATCH 1/4] usb: Propagate errors through usb_register_companion()

2015-02-17 Thread Markus Armbruster
This loses the messages explaining the error printed with
error_printf_unless_qmp().  The next commit will make up for the loss.

Signed-off-by: Markus Armbruster 
---
 hw/usb/bus.c  | 17 ++---
 hw/usb/hcd-ehci.c | 23 +--
 hw/usb/hcd-ohci.c | 10 +++---
 hw/usb/hcd-uhci.c | 10 +++---
 include/hw/usb.h  | 12 +++-
 5 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 986b2d8..8be942f 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -350,9 +350,10 @@ void usb_register_port(USBBus *bus, USBPort *port, void 
*opaque, int index,
 bus->nfree++;
 }
 
-int usb_register_companion(const char *masterbus, USBPort *ports[],
-   uint32_t portcount, uint32_t firstport,
-   void *opaque, USBPortOps *ops, int speedmask)
+void usb_register_companion(const char *masterbus, USBPort *ports[],
+uint32_t portcount, uint32_t firstport,
+void *opaque, USBPortOps *ops, int speedmask,
+Error **errp)
 {
 USBBus *bus;
 int i;
@@ -364,21 +365,23 @@ int usb_register_companion(const char *masterbus, USBPort 
*ports[],
 }
 
 if (!bus || !bus->ops->register_companion) {
-qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus",
-  "an USB masterbus");
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, "masterbus",
+  "an USB masterbus");
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
 if (bus) {
 error_printf_unless_qmp(
 "USB bus '%s' does not allow companion controllers\n",
 masterbus);
 }
-return -1;
+#endif
+return;
 }
 
 for (i = 0; i < portcount; i++) {
 usb_fill_port(ports[i], opaque, i, ops, speedmask);
 }
 
-return bus->ops->register_companion(bus, ports, portcount, firstport);
+bus->ops->register_companion(bus, ports, portcount, firstport, errp);
 }
 
 void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index ccf54b6..7d16ba8 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -769,30 +769,35 @@ static void ehci_wakeup(USBPort *port)
 qemu_bh_schedule(s->async_bh);
 }
 
-static int ehci_register_companion(USBBus *bus, USBPort *ports[],
-   uint32_t portcount, uint32_t firstport)
+static void ehci_register_companion(USBBus *bus, USBPort *ports[],
+uint32_t portcount, uint32_t firstport,
+Error **errp)
 {
 EHCIState *s = container_of(bus, EHCIState, bus);
 uint32_t i;
 
 if (firstport + portcount > NB_PORTS) {
-qerror_report(QERR_INVALID_PARAMETER_VALUE, "firstport",
-  "firstport on masterbus");
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, "firstport",
+  "firstport on masterbus");
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
 error_printf_unless_qmp(
 "firstport value of %u makes companion take ports %u - %u, which "
 "is outside of the valid range of 0 - %u\n", firstport, firstport,
 firstport + portcount - 1, NB_PORTS - 1);
-return -1;
+#endif
+return;
 }
 
 for (i = 0; i < portcount; i++) {
 if (s->companion_ports[firstport + i]) {
-qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus",
-  "an USB masterbus");
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, "masterbus",
+  "an USB masterbus");
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
 error_printf_unless_qmp(
 "port %u on masterbus %s already has a companion assigned\n",
 firstport + i, bus->qbus.name);
-return -1;
+#endif
+return;
 }
 }
 
@@ -806,8 +811,6 @@ static int ehci_register_companion(USBBus *bus, USBPort 
*ports[],
 
 s->companion_count++;
 s->caps[0x05] = (s->companion_count << 4) | portcount;
-
-return 0;
 }
 
 static void ehci_wakeup_endpoint(USBBus *bus, USBEndpoint *ep,
diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index a0d478e..21ec65f 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -1832,6 +1832,7 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState 
*dev,
  char *masterbus, uint32_t firstport,
  AddressSpace *as)
 {
+Error *err = NULL;
 int i;
 
 ohci->as = as;
@@ -1857,9 +1858,12 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState 
*dev,
 for(i = 0; i < num_ports; i++) {
 ports[i] = &ohci->rhport[i].port;
 }
-if (usb_register_companion(masterbus, ports, num_ports,
-first

[Qemu-devel] [PATCH 2/4] usb: Improve companion configuration error messages

2015-02-17 Thread Markus Armbruster
The previous commit broke the additional messages explaining the error
messages.  Improve the error messages, so they don't need explaining
so much.  Helps QMP users as well, unlike additional explanations.

Signed-off-by: Markus Armbruster 
---
 hw/usb/bus.c  | 18 --
 hw/usb/hcd-ehci.c | 21 ++---
 2 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 8be942f..2219200 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -364,16 +364,14 @@ void usb_register_companion(const char *masterbus, 
USBPort *ports[],
 }
 }
 
-if (!bus || !bus->ops->register_companion) {
-error_set(errp, QERR_INVALID_PARAMETER_VALUE, "masterbus",
-  "an USB masterbus");
-#if 0 /* conversion from qerror_report() to error_set() broke this: */
-if (bus) {
-error_printf_unless_qmp(
-"USB bus '%s' does not allow companion controllers\n",
-masterbus);
-}
-#endif
+if (!bus) {
+error_setg(errp, "USB bus '%s' not found", masterbus);
+return;
+}
+if (!bus->ops->register_companion) {
+error_setg(errp, "Can't use USB bus '%s' as masterbus,"
+   " it doesn't support companion controllers",
+   masterbus);
 return;
 }
 
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 7d16ba8..5c2a452 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -777,26 +777,17 @@ static void ehci_register_companion(USBBus *bus, USBPort 
*ports[],
 uint32_t i;
 
 if (firstport + portcount > NB_PORTS) {
-error_set(errp, QERR_INVALID_PARAMETER_VALUE, "firstport",
-  "firstport on masterbus");
-#if 0 /* conversion from qerror_report() to error_set() broke this: */
-error_printf_unless_qmp(
-"firstport value of %u makes companion take ports %u - %u, which "
-"is outside of the valid range of 0 - %u\n", firstport, firstport,
-firstport + portcount - 1, NB_PORTS - 1);
-#endif
+error_setg(errp, "firstport must be between 0 and %u",
+   NB_PORTS - portcount);
 return;
 }
 
 for (i = 0; i < portcount; i++) {
 if (s->companion_ports[firstport + i]) {
-error_set(errp, QERR_INVALID_PARAMETER_VALUE, "masterbus",
-  "an USB masterbus");
-#if 0 /* conversion from qerror_report() to error_set() broke this: */
-error_printf_unless_qmp(
-"port %u on masterbus %s already has a companion assigned\n",
-firstport + i, bus->qbus.name);
-#endif
+error_setg(errp, "firstport %u asks for ports %u-%u,"
+   " but port %u has a companion assigned already",
+   firstport, firstport, firstport + portcount - 1,
+   firstport + i);
 return;
 }
 }
-- 
1.9.3




Re: [Qemu-devel] [PATCH v2 0/3] -incoming pause

2015-02-17 Thread Dr. David Alan Gilbert
* Amit Shah (amit.s...@redhat.com) wrote:
> On (Wed) 11 Feb 2015 [16:46:21], Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" 
> > 
> > This patchset provides a way of setting options on an incoming
> > migration before the fd/process/socket has been created.
> > 
> >start qemu with   -incoming pause
> >
> >migrate_incoming theuri
> > 
> > v2:
> >   Create migrate_incoming/migrate-incoming rather than squashing the -u
> >   into the existing migrate command.
> 
> So the only comment I have is with the 'pause' name.
> 
> 'pause' to me means there's a time period for which a pause has to be
> done; or pausing an activity which is already in progress, both of
> which are not true for this case.

I think that pause and wait are both pretty similar; wait generally
does mean wait for something specific though.

The 'pause' button on your video player doesn't have an expectation
of how long you will pause it.

> My suggestions are 'wait' or 'hold' -- wait signifies we wait for a
> connection; the uri for which we give later; similar for hold.

Dave
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [PATCH v6 09/24] qcow2: More helpers for refcount modification

2015-02-17 Thread Kevin Wolf
Am 10.02.2015 um 21:28 hat Max Reitz geschrieben:
> Add helper functions for getting and setting refcounts in a refcount
> array for any possible refcount order, and choose the correct one during
> refcount initialization.
> 
> Signed-off-by: Max Reitz 
> Reviewed-by: Eric Blake 
> Reviewed-by: Stefan Hajnoczi 
> ---
>  block/qcow2-refcount.c | 121 
> -
>  1 file changed, 119 insertions(+), 2 deletions(-)
> 
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index b9034ae..c9f9f4f 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
> @@ -32,10 +32,49 @@ static int QEMU_WARN_UNUSED_RESULT 
> update_refcount(BlockDriverState *bs,
>  int64_t offset, int64_t length, uint64_t addend,
>  bool decrease, enum qcow2_discard_type type);
>  
> +static uint64_t get_refcount_ro0(const void *refcount_array, uint64_t index);
> +static uint64_t get_refcount_ro1(const void *refcount_array, uint64_t index);
> +static uint64_t get_refcount_ro2(const void *refcount_array, uint64_t index);
> +static uint64_t get_refcount_ro3(const void *refcount_array, uint64_t index);
>  static uint64_t get_refcount_ro4(const void *refcount_array, uint64_t index);
> +static uint64_t get_refcount_ro5(const void *refcount_array, uint64_t index);
> +static uint64_t get_refcount_ro6(const void *refcount_array, uint64_t index);
>  
> +static void set_refcount_ro0(void *refcount_array, uint64_t index,
> + uint64_t value);
> +static void set_refcount_ro1(void *refcount_array, uint64_t index,
> + uint64_t value);
> +static void set_refcount_ro2(void *refcount_array, uint64_t index,
> + uint64_t value);
> +static void set_refcount_ro3(void *refcount_array, uint64_t index,
> + uint64_t value);
>  static void set_refcount_ro4(void *refcount_array, uint64_t index,
>   uint64_t value);
> +static void set_refcount_ro5(void *refcount_array, uint64_t index,
> + uint64_t value);
> +static void set_refcount_ro6(void *refcount_array, uint64_t index,
> + uint64_t value);

Hm, lots of forward declarations. Can't we put the implementation here?

Kevin



Re: [Qemu-devel] [PATCH 1/4] exec: round up size on MR resize

2015-02-17 Thread Igor Mammedov
On Tue, 17 Feb 2015 11:05:36 +0100
"Michael S. Tsirkin"  wrote:

> Block size must fundamentally be a multiple of target page size.
> Aligning automatically removes need to worry about the alignment
> from callers.
> 
> Note: the only caller of qemu_ram_resize (acpi) already happens to have
> size padded to a power of 2, but we would like to drop the padding in
> ACPI core, and don't want to expose target page size knowledge to ACPI.
> 
> Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 

> ---
>  exec.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/exec.c b/exec.c
> index 6b79ad1..2433406 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1298,6 +1298,8 @@ int qemu_ram_resize(ram_addr_t base, ram_addr_t 
> newsize, Error **errp)
>  
>  assert(block);
>  
> +newsize = TARGET_PAGE_ALIGN(newsize);
> +
>  if (block->used_length == newsize) {
>  return 0;
>  }




Re: [Qemu-devel] [PATCH v3 06/17] virtio-9p: use standard headers

2015-02-17 Thread Thomas Huth
On Mon, 16 Feb 2015 22:35:57 +0100
"Michael S. Tsirkin"  wrote:

> Drop code duplicated from standard headers.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  hw/9pfs/virtio-9p.h | 17 +
>  1 file changed, 1 insertion(+), 16 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
> index 0776424..58dafa9 100644
> --- a/hw/9pfs/virtio-9p.h
> +++ b/hw/9pfs/virtio-9p.h
> @@ -7,6 +7,7 @@
>  #include 
>  #include 
>  #include 
> +#include "standard-headers/linux/virtio_9p.h"
>  #include "hw/virtio/virtio.h"
>  #include "hw/virtio/virtio-9p.h"
>  #include "fsdev/file-op-9p.h"
> @@ -14,10 +15,6 @@
>  #include "qemu/thread.h"
>  #include "block/coroutine.h"
> 
> -/* The feature bitmap for virtio 9P */
> -/* The mount point is specified in a config variable */
> -#define VIRTIO_9P_MOUNT_TAG 0
> -
>  enum {
>  P9_TLERROR = 6,
>  P9_RLERROR,
> @@ -145,10 +142,6 @@ struct V9fsPDU
>   * 1) change user needs to set groups and stuff
>   */
> 
> -/* from Linux's linux/virtio_9p.h */
> -
> -/* The ID for virtio console */
> -#define VIRTIO_ID_9P9
>  #define MAX_REQ 128
>  #define MAX_TAG_LEN 32
> 
> @@ -278,14 +271,6 @@ typedef struct V9fsWriteState {
>  int cnt;
>  } V9fsWriteState;
> 
> -struct virtio_9p_config
> -{
> -/* number of characters in tag */
> -uint16_t tag_len;
> -/* Variable size tag name */
> -uint8_t tag[0];
> -} QEMU_PACKED;
> -
>  typedef struct V9fsMkState {
>  V9fsPDU *pdu;
>  size_t offset;

Reviewed-by: Thomas Huth 




[Qemu-devel] [PATCH] qcow2: Remove unused struct QCowCreateState

2015-02-17 Thread Kevin Wolf
The only user went away five years ago with commit a9420734 ('qcow2:
Simplify image creation'). It's about time to remove it.

Signed-off-by: Kevin Wolf 
---
 block/qcow2.h | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/block/qcow2.h b/block/qcow2.h
index 17c9a3f..a9108f5 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -277,17 +277,6 @@ typedef struct BDRVQcowState {
 bool cache_discards;
 } BDRVQcowState;
 
-/* XXX: use std qcow open function ? */
-typedef struct QCowCreateState {
-int cluster_size;
-int cluster_bits;
-uint16_t *refcount_block;
-uint64_t *refcount_table;
-int64_t l1_table_offset;
-int64_t refcount_table_offset;
-int64_t refcount_block_offset;
-} QCowCreateState;
-
 struct QCowAIOCB;
 
 typedef struct Qcow2COWRegion {
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH 2/4] acpi-build: fix ACPI RAM management

2015-02-17 Thread Igor Mammedov
On Tue, 17 Feb 2015 11:05:39 +0100
"Michael S. Tsirkin"  wrote:

> This fixes multiple issues around ACPI RAM management:
> 
> RSDP and linker RAM aren't currently marked dirty
> on update, so they won't be migrated correctly.
> 
> Let's handle all tables in the same way: set correct size (assert if
> too big), update, mark RAM dirty.
> 
> This also drops assert checking that table size didn't change: table
> size is fundamentally dynamic and depends on hw configuration,
> just set the correct size and use that (memory core asserts if size is
> too large).
> 
> This also means we can drop tracking table size, memory core does this
> for us now.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  hw/i386/acpi-build.c | 43 +++
>  1 file changed, 23 insertions(+), 20 deletions(-)
> 
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 1dfdf35..e78d6cb 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -1266,13 +1266,12 @@ typedef
>  struct AcpiBuildState {
>  /* Copy of table in RAM (for patching). */
>  ram_addr_t table_ram;
> -uint32_t table_size;
>  /* Is table patched? */
>  uint8_t patched;
>  PcGuestInfo *guest_info;
>  void *rsdp;
> +ram_addr_t rsdp_ram;
>  ram_addr_t linker_ram;
> -uint32_t linker_size;
>  } AcpiBuildState;
>  
>  static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
> @@ -1455,6 +1454,17 @@ void acpi_build(PcGuestInfo *guest_info, 
> AcpiBuildTables *tables)
>  g_array_free(table_offsets, true);
>  }
>  
> +static void acpi_ram_update(ram_addr_t ram, GArray *data)
> +{
> +uint32_t size = acpi_data_len(data);
> +
> +/* Make sure RAM size is correct - in case it got changed e.g. by 
> migration */
> +qemu_ram_resize(ram, size, &error_abort);
> +
> +memcpy(qemu_get_ram_ptr(ram), data->data, size);
> +cpu_physical_memory_set_dirty_range_nocode(ram, size);
> +}
> +
>  static void acpi_build_update(void *build_opaque, uint32_t offset)
>  {
>  AcpiBuildState *build_state = build_opaque;
> @@ -1470,21 +1480,15 @@ static void acpi_build_update(void *build_opaque, 
> uint32_t offset)
>  
>  acpi_build(build_state->guest_info, &tables);
>  
> -assert(acpi_data_len(tables.table_data) == build_state->table_size);
> +acpi_ram_update(build_state->table_ram, tables.table_data);
>  
> -/* Make sure RAM size is correct - in case it got changed by migration */
> -qemu_ram_resize(build_state->table_ram, build_state->table_size,
> -&error_abort);
> -
> -memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
> -   build_state->table_size);
> -memcpy(build_state->rsdp, tables.rsdp->data, acpi_data_len(tables.rsdp));
> -memcpy(qemu_get_ram_ptr(build_state->linker_ram), tables.linker->data,
> -   build_state->linker_size);
> -
> -cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
> -   build_state->table_size);
> +if (build_state->rsdp) {
> +memcpy(build_state->rsdp, tables.rsdp->data, 
> acpi_data_len(tables.rsdp));
> +} else {
> +acpi_ram_update(build_state->rsdp_ram, tables.rsdp);
> +}
>  
> +acpi_ram_update(build_state->linker_ram, tables.linker);
>  acpi_build_tables_cleanup(&tables, true);
>  }
>  
> @@ -1545,11 +1549,9 @@ void acpi_setup(PcGuestInfo *guest_info)
> ACPI_BUILD_TABLE_FILE,
> ACPI_BUILD_TABLE_MAX_SIZE);
>  assert(build_state->table_ram != RAM_ADDR_MAX);
> -build_state->table_size = acpi_data_len(tables.table_data);
>  
>  build_state->linker_ram =
>  acpi_add_rom_blob(build_state, tables.linker, "etc/table-loader", 0);
> -build_state->linker_size = acpi_data_len(tables.linker);
>  
>  fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
>  tables.tcpalog->data, acpi_data_len(tables.tcpalog));
> @@ -1564,10 +1566,11 @@ void acpi_setup(PcGuestInfo *guest_info)
>   acpi_build_update, build_state,
>   tables.rsdp->data, 
> acpi_data_len(tables.rsdp));
>  build_state->rsdp = tables.rsdp->data;
> +build_state->rsdp_ram = (ram_addr_t)-1;
I'd drop this and 

>  } else {
> -build_state->rsdp = qemu_get_ram_ptr(
> -acpi_add_rom_blob(build_state, tables.rsdp, 
> ACPI_BUILD_RSDP_FILE, 0)
> -);
> +build_state->rsdp = NULL;
this as unnecessary 

> +build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
> +  ACPI_BUILD_RSDP_FILE, 0);
>  }
>  
>  qemu_register_reset(acpi_build_reset, build_state);

Otherwise looks as a very nice improvement of current mess



Re: [Qemu-devel] [PATCH v6 09/24] qcow2: More helpers for refcount modification

2015-02-17 Thread Max Reitz

On 2015-02-17 at 08:38, Kevin Wolf wrote:

Am 10.02.2015 um 21:28 hat Max Reitz geschrieben:

Add helper functions for getting and setting refcounts in a refcount
array for any possible refcount order, and choose the correct one during
refcount initialization.

Signed-off-by: Max Reitz 
Reviewed-by: Eric Blake 
Reviewed-by: Stefan Hajnoczi 
---
  block/qcow2-refcount.c | 121 -
  1 file changed, 119 insertions(+), 2 deletions(-)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index b9034ae..c9f9f4f 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -32,10 +32,49 @@ static int QEMU_WARN_UNUSED_RESULT 
update_refcount(BlockDriverState *bs,
  int64_t offset, int64_t length, uint64_t addend,
  bool decrease, enum qcow2_discard_type type);
  
+static uint64_t get_refcount_ro0(const void *refcount_array, uint64_t index);

+static uint64_t get_refcount_ro1(const void *refcount_array, uint64_t index);
+static uint64_t get_refcount_ro2(const void *refcount_array, uint64_t index);
+static uint64_t get_refcount_ro3(const void *refcount_array, uint64_t index);
  static uint64_t get_refcount_ro4(const void *refcount_array, uint64_t index);
+static uint64_t get_refcount_ro5(const void *refcount_array, uint64_t index);
+static uint64_t get_refcount_ro6(const void *refcount_array, uint64_t index);
  
+static void set_refcount_ro0(void *refcount_array, uint64_t index,

+ uint64_t value);
+static void set_refcount_ro1(void *refcount_array, uint64_t index,
+ uint64_t value);
+static void set_refcount_ro2(void *refcount_array, uint64_t index,
+ uint64_t value);
+static void set_refcount_ro3(void *refcount_array, uint64_t index,
+ uint64_t value);
  static void set_refcount_ro4(void *refcount_array, uint64_t index,
   uint64_t value);
+static void set_refcount_ro5(void *refcount_array, uint64_t index,
+ uint64_t value);
+static void set_refcount_ro6(void *refcount_array, uint64_t index,
+ uint64_t value);

Hm, lots of forward declarations. Can't we put the implementation here?


Of course we can. I just personally found it cleaner this way 
(qcow2_refcount_init() being the first function implementation in 
qcow2-refcount.c). I'm fine either way.


Max



Re: [Qemu-devel] [PATCH v7 07/10] qmp: add rocker device support

2015-02-17 Thread Scott Feldman
On Tue, Feb 17, 2015 at 1:48 AM, Paolo Bonzini  wrote:
>
>
> On 16/02/2015 23:37, Scott Feldman wrote:
>>> > I would just merge the other nine patches for 2.3.
>> I disagree.  qmp/hmp is very important to rocker.  It would be nearly
>> impossible to debug large/complicated networking setups without having
>> a back-door view into the device.  qmp/hmp are perfect for this.
>
> I agree, but it is better than the danger of merging nothing (we're in
> soft freeze now).


Ok, let's get the other 9 of 10 in. Thank you.

-scott



Re: [Qemu-devel] [PATCH 7/7] target-mips: Add IEEE 754-2008 features support

2015-02-17 Thread Maciej W. Rozycki
On Tue, 9 Dec 2014, Maciej W. Rozycki wrote:

> Index: qemu-git-trunk/target-mips/op_helper.c
> ===
> --- qemu-git-trunk.orig/target-mips/op_helper.c   2014-12-08 
> 23:22:12.0 +
> +++ qemu-git-trunk/target-mips/op_helper.c2014-12-08 23:25:02.558929097 
> +
> @@ -2274,8 +2274,12 @@ void mips_cpu_unassigned_access(CPUState
>  
>  #define FLOAT_TWO32 make_float32(1 << 30)
>  #define FLOAT_TWO64 make_float64(1ULL << 62)
> -#define FP_TO_INT32_OVERFLOW 0x7fff
> -#define FP_TO_INT64_OVERFLOW 0x7fffULL
> +#define FLOAT_INAN32(env)   \
> +(((env)->active_fpu.fcr31 & (1 << FCR31_NAN2008))   \
> + ? 0x : 0x7fff)
> +#define FLOAT_INAN64(env)   \
> +(((env)->active_fpu.fcr31 & (1 << FCR31_NAN2008))   \
> + ? 0xULL : 0x7fffULL)
>  
>  /* convert MIPS rounding mode in FCR31 to IEEE library */
>  unsigned int ieee_rm[] = {
[...]
> @@ -2481,7 +2482,7 @@ uint64_t helper_float_cvtl_d(CPUMIPSStat
>  dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
>  if (get_float_exception_flags(&env->active_fpu.fp_status)
>  & (float_flag_invalid | float_flag_overflow)) {
> -dt2 = FP_TO_INT64_OVERFLOW;
> +dt2 = FLOAT_INAN64(env);
>  }
>  update_fcr31(env, GETPC());
>  return dt2;
> @@ -2494,7 +2495,7 @@ uint64_t helper_float_cvtl_s(CPUMIPSStat
>  dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
>  if (get_float_exception_flags(&env->active_fpu.fp_status)
>  & (float_flag_invalid | float_flag_overflow)) {
> -dt2 = FP_TO_INT64_OVERFLOW;
> +dt2 = FLOAT_INAN64(env);
>  }
>  update_fcr31(env, GETPC());
>  return dt2;
> @@ -2520,14 +2521,14 @@ uint64_t helper_float_cvtpw_ps(CPUMIPSSt
>  wt2 = float32_to_int32(fdt0 & 0X, &env->active_fpu.fp_status);
>  excp = get_float_exception_flags(&env->active_fpu.fp_status);
>  if (excp & (float_flag_overflow | float_flag_invalid)) {
> -wt2 = FP_TO_INT32_OVERFLOW;
> +wt2 = FLOAT_INAN32(env);
>  }
>  
>  set_float_exception_flags(0, &env->active_fpu.fp_status);
>  wth2 = float32_to_int32(fdt0 >> 32, &env->active_fpu.fp_status);
>  excph = get_float_exception_flags(&env->active_fpu.fp_status);
>  if (excph & (float_flag_overflow | float_flag_invalid)) {
> -wth2 = FP_TO_INT32_OVERFLOW;
> +wth2 = FLOAT_INAN32(env);
>  }
>  
>  set_float_exception_flags(excp | excph, &env->active_fpu.fp_status);
> @@ -2588,7 +2589,7 @@ uint32_t helper_float_cvtw_s(CPUMIPSStat
>  wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
>  if (get_float_exception_flags(&env->active_fpu.fp_status)
>  & (float_flag_invalid | float_flag_overflow)) {
> -wt2 = FP_TO_INT32_OVERFLOW;
> +wt2 = FLOAT_INAN32(env);
>  }
>  update_fcr31(env, GETPC());
>  return wt2;
> @@ -2601,7 +2602,7 @@ uint32_t helper_float_cvtw_d(CPUMIPSStat
>  wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
>  if (get_float_exception_flags(&env->active_fpu.fp_status)
>  & (float_flag_invalid | float_flag_overflow)) {
> -wt2 = FP_TO_INT32_OVERFLOW;
> +wt2 = FLOAT_INAN32(env);
>  }
>  update_fcr31(env, GETPC());
>  return wt2;
> @@ -2616,7 +2617,7 @@ uint64_t helper_float_roundl_d(CPUMIPSSt
>  restore_rounding_mode(env);
>  if (get_float_exception_flags(&env->active_fpu.fp_status)
>  & (float_flag_invalid | float_flag_overflow)) {
> -dt2 = FP_TO_INT64_OVERFLOW;
> +dt2 = FLOAT_INAN64(env);
>  }
>  update_fcr31(env, GETPC());
>  return dt2;
> @@ -2631,7 +2632,7 @@ uint64_t helper_float_roundl_s(CPUMIPSSt
>  restore_rounding_mode(env);
>  if (get_float_exception_flags(&env->active_fpu.fp_status)
>  & (float_flag_invalid | float_flag_overflow)) {
> -dt2 = FP_TO_INT64_OVERFLOW;
> +dt2 = FLOAT_INAN64(env);
>  }
>  update_fcr31(env, GETPC());
>  return dt2;
> @@ -2646,7 +2647,7 @@ uint32_t helper_float_roundw_d(CPUMIPSSt
>  restore_rounding_mode(env);
>  if (get_float_exception_flags(&env->active_fpu.fp_status)
>  & (float_flag_invalid | float_flag_overflow)) {
> -wt2 = FP_TO_INT32_OVERFLOW;
> +wt2 = FLOAT_INAN32(env);
>  }
>  update_fcr31(env, GETPC());
>  return wt2;
> @@ -2661,7 +2662,7 @@ uint32_t helper_float_roundw_s(CPUMIPSSt
>  restore_rounding_mode(env);
>  if (get_float_exception_flags(&env->active_fpu.fp_status)
>  & (float_flag_invalid | float_flag_overflow)) {
> -wt2 = FP_TO_INT32_OVERFLOW;
> +wt2 = FLOAT_INAN32(env);
>  }
>  update_fcr31(env, GETPC());
>  return wt2;
> @@ -2674,7 +2675,7 @@ uint64_t helper_float_truncl_d(CPUMIPSSt
>  

Re: [Qemu-devel] [PATCH 3/4] acpi: has_immutable_rsdp->!rsdp_in_ram

2015-02-17 Thread Igor Mammedov
On Tue, 17 Feb 2015 11:05:42 +0100
"Michael S. Tsirkin"  wrote:

> As comment in acpi-build.c notes, RSDP is not really immutable.  So it's
> really a question of whether it's in RAM, name the variable accordingly.
> 
> Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 

> ---
>  include/hw/i386/pc.h | 2 +-
>  hw/i386/acpi-build.c | 2 +-
>  hw/i386/pc_piix.c| 6 +++---
>  hw/i386/pc_q35.c | 6 +++---
>  4 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index b0a80cf..0c595c5 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -104,7 +104,7 @@ struct PcGuestInfo {
>  int legacy_acpi_table_size;
>  bool has_acpi_build;
>  bool has_reserved_memory;
> -bool has_immutable_rsdp;
> +bool rsdp_in_ram;
>  };
>  
>  /* parallel.c */
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index e78d6cb..ffa3f00 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -1556,7 +1556,7 @@ void acpi_setup(PcGuestInfo *guest_info)
>  fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
>  tables.tcpalog->data, acpi_data_len(tables.tcpalog));
>  
> -if (guest_info->has_immutable_rsdp) {
> +if (!guest_info->rsdp_in_ram) {
>  /*
>   * Keep for compatibility with old machine types.
>   * Though RSDP is small, its contents isn't immutable, so
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index e586c7b..13ff561 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -60,7 +60,7 @@ static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 
> };
>  static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
>  
>  static bool has_acpi_build = true;
> -static bool has_immutable_rsdp;
> +static bool rsdp_in_ram = true;
>  static int legacy_acpi_table_size;
>  static bool smbios_defaults = true;
>  static bool smbios_legacy_mode;
> @@ -169,7 +169,7 @@ static void pc_init1(MachineState *machine,
>  
>  guest_info->isapc_ram_fw = !pci_enabled;
>  guest_info->has_reserved_memory = has_reserved_memory;
> -guest_info->has_immutable_rsdp = has_immutable_rsdp;
> +guest_info->rsdp_in_ram = rsdp_in_ram;
>  
>  if (smbios_defaults) {
>  MachineClass *mc = MACHINE_GET_CLASS(machine);
> @@ -312,7 +312,7 @@ static void pc_init_pci(MachineState *machine)
>  
>  static void pc_compat_2_2(MachineState *machine)
>  {
> -has_immutable_rsdp = true;
> +rsdp_in_ram = false;
>  x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
>  x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
>  x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 6151f2f..c0f21fe 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -50,7 +50,7 @@
>  #define MAX_SATA_PORTS 6
>  
>  static bool has_acpi_build = true;
> -static bool has_immutable_rsdp;
> +static bool rsdp_in_ram = true;
>  static bool smbios_defaults = true;
>  static bool smbios_legacy_mode;
>  static bool smbios_uuid_encoded = true;
> @@ -155,7 +155,7 @@ static void pc_q35_init(MachineState *machine)
>  guest_info->isapc_ram_fw = false;
>  guest_info->has_acpi_build = has_acpi_build;
>  guest_info->has_reserved_memory = has_reserved_memory;
> -guest_info->has_immutable_rsdp = has_immutable_rsdp;
> +guest_info->rsdp_in_ram = rsdp_in_ram;
>  
>  /* Migration was not supported in 2.0 for Q35, so do not bother
>   * with this hack (see hw/i386/acpi-build.c).
> @@ -291,7 +291,7 @@ static void pc_q35_init(MachineState *machine)
>  
>  static void pc_compat_2_2(MachineState *machine)
>  {
> -has_immutable_rsdp = true;
> +rsdp_in_ram = false;
>  x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
>  x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
>  x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);




Re: [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term

2015-02-17 Thread Igor Mammedov
On Tue, 17 Feb 2015 13:18:19 +0100
"Michael S. Tsirkin"  wrote:

> On Mon, Feb 09, 2015 at 10:53:53AM +, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov 
> > ---
> 
> This causes asserts.
> 
> >  hw/acpi/aml-build.c | 11 +++
> >  include/hw/acpi/aml-build.h |  1 +
> >  2 files changed, 12 insertions(+)
> > 
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index 10995a9..cb58e19 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)
> >  build_append_byte(var->buf, flags);
> >  return var;
> >  }
> > +
> > +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
> > +Aml *aml_local(int num)
> > +{
> > +Aml *var;
> > +uint8_t op = 0x60 /* Local0Op */ + num;
> 
> So op is 0x6X here.
> 
> > +
> > +assert(op <= 7);
> 
> And here we assert it is <= 7?
yep, it should s/op/num/

I'm sorry for not running make check on the last iteration,
I'll post fixup shortly.
> 
> 
> > +var = aml_opcode(op);
> > +return var;
> > +}
> > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > index 8b954d9..6e25315 100644
> > --- a/include/hw/acpi/aml-build.h
> > +++ b/include/hw/acpi/aml-build.h
> > @@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, 
> > uint16_t max_base,
> >  Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
> >uint32_t offset, uint32_t len);
> >  Aml *aml_named_field(const char *name, unsigned length);
> > +Aml *aml_local(int num);
> >  
> >  /* Block AML object primitives */
> >  Aml *aml_def_block(const char *signature, uint8_t revision,
> > -- 
> > 1.8.3.1




Re: [Qemu-devel] [PATCH 1/4] exec: round up size on MR resize

2015-02-17 Thread Paolo Bonzini


On 17/02/2015 14:45, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 11:05:36 +0100
> "Michael S. Tsirkin"  wrote:
> 
>> Block size must fundamentally be a multiple of target page size.
>> Aligning automatically removes need to worry about the alignment
>> from callers.
>>
>> Note: the only caller of qemu_ram_resize (acpi) already happens to have
>> size padded to a power of 2, but we would like to drop the padding in
>> ACPI core, and don't want to expose target page size knowledge to ACPI.
>>
>> Signed-off-by: Michael S. Tsirkin 
> Reviewed-by: Igor Mammedov 
> 
>> ---
>>  exec.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/exec.c b/exec.c
>> index 6b79ad1..2433406 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -1298,6 +1298,8 @@ int qemu_ram_resize(ram_addr_t base, ram_addr_t 
>> newsize, Error **errp)
>>  
>>  assert(block);
>>  
>> +newsize = TARGET_PAGE_ALIGN(newsize);
>> +
>>  if (block->used_length == newsize) {
>>  return 0;
>>  }
> 

Acked-by: Paolo Bonzini 



Re: [Qemu-devel] [PATCH v3 10/17] virtio-scsi: use standard-headers

2015-02-17 Thread Paolo Bonzini


On 16/02/2015 22:36, Michael S. Tsirkin wrote:
> Drop duplicated code.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  include/hw/virtio/virtio-scsi.h | 120 
> +++-
>  hw/scsi/virtio-scsi.c   |   1 +
>  2 files changed, 10 insertions(+), 111 deletions(-)
> 
> diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
> index bf17cc9..864070d 100644
> --- a/include/hw/virtio/virtio-scsi.h
> +++ b/include/hw/virtio/virtio-scsi.h
> @@ -14,6 +14,7 @@
>  #ifndef _QEMU_VIRTIO_SCSI_H
>  #define _QEMU_VIRTIO_SCSI_H
>  
> +#include "standard-headers/linux/virtio_scsi.h"

Acked-by: Paolo Bonzini 

>  #include "hw/virtio/virtio.h"
>  #include "hw/pci/pci.h"
>  #include "hw/scsi/scsi.h"
> @@ -28,15 +29,6 @@
>  #define VIRTIO_SCSI(obj) \
>  OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
>  
> -
> -/* The ID for virtio_scsi */
> -#define VIRTIO_ID_SCSI  8
> -
> -/* Feature Bits */
> -#define VIRTIO_SCSI_F_INOUT0
> -#define VIRTIO_SCSI_F_HOTPLUG  1
> -#define VIRTIO_SCSI_F_CHANGE   2
> -
>  #define VIRTIO_SCSI_VQ_SIZE 128
>  #define VIRTIO_SCSI_CDB_SIZE32
>  #define VIRTIO_SCSI_SENSE_SIZE  96
> @@ -44,108 +36,14 @@
>  #define VIRTIO_SCSI_MAX_TARGET  255
>  #define VIRTIO_SCSI_MAX_LUN 16383
>  
> -/* Response codes */
> -#define VIRTIO_SCSI_S_OK   0
> -#define VIRTIO_SCSI_S_OVERRUN  1
> -#define VIRTIO_SCSI_S_ABORTED  2
> -#define VIRTIO_SCSI_S_BAD_TARGET   3
> -#define VIRTIO_SCSI_S_RESET4
> -#define VIRTIO_SCSI_S_BUSY 5
> -#define VIRTIO_SCSI_S_TRANSPORT_FAILURE6
> -#define VIRTIO_SCSI_S_TARGET_FAILURE   7
> -#define VIRTIO_SCSI_S_NEXUS_FAILURE8
> -#define VIRTIO_SCSI_S_FAILURE  9
> -#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED   10
> -#define VIRTIO_SCSI_S_FUNCTION_REJECTED11
> -#define VIRTIO_SCSI_S_INCORRECT_LUN12
> -
> -/* Controlq type codes.  */
> -#define VIRTIO_SCSI_T_TMF  0
> -#define VIRTIO_SCSI_T_AN_QUERY 1
> -#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
> -
> -/* Valid TMF subtypes.  */
> -#define VIRTIO_SCSI_T_TMF_ABORT_TASK   0
> -#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET   1
> -#define VIRTIO_SCSI_T_TMF_CLEAR_ACA2
> -#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET   3
> -#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET  4
> -#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET   5
> -#define VIRTIO_SCSI_T_TMF_QUERY_TASK   6
> -#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET   7
> -
> -/* Events.  */
> -#define VIRTIO_SCSI_T_EVENTS_MISSED0x8000
> -#define VIRTIO_SCSI_T_NO_EVENT 0
> -#define VIRTIO_SCSI_T_TRANSPORT_RESET  1
> -#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
> -#define VIRTIO_SCSI_T_PARAM_CHANGE 3
> -
> -/* Reasons for transport reset event */
> -#define VIRTIO_SCSI_EVT_RESET_HARD 0
> -#define VIRTIO_SCSI_EVT_RESET_RESCAN   1
> -#define VIRTIO_SCSI_EVT_RESET_REMOVED  2
> -
> -/* SCSI command request, followed by CDB and data-out */
> -typedef struct {
> -uint8_t lun[8];  /* Logical Unit Number */
> -uint64_t tag;/* Command identifier */
> -uint8_t task_attr;   /* Task attribute */
> -uint8_t prio;
> -uint8_t crn;
> -} QEMU_PACKED VirtIOSCSICmdReq;
> -
> -/* Response, followed by sense data and data-in */
> -typedef struct {
> -uint32_t sense_len;  /* Sense data length */
> -uint32_t resid;  /* Residual bytes in data buffer */
> -uint16_t status_qualifier;   /* Status qualifier */
> -uint8_t status;  /* Command completion status */
> -uint8_t response;/* Response values */
> -} QEMU_PACKED VirtIOSCSICmdResp;
> -
> -/* Task Management Request */
> -typedef struct {
> -uint32_t type;
> -uint32_t subtype;
> -uint8_t lun[8];
> -uint64_t tag;
> -} QEMU_PACKED VirtIOSCSICtrlTMFReq;
> -
> -typedef struct {
> -uint8_t response;
> -} QEMU_PACKED VirtIOSCSICtrlTMFResp;
> -
> -/* Asynchronous notification query/subscription */
> -typedef struct {
> -uint32_t type;
> -uint8_t lun[8];
> -uint32_t event_requested;
> -} QEMU_PACKED VirtIOSCSICtrlANReq;
> -
> -typedef struct {
> -uint32_t event_actual;
> -uint8_t response;
> -} QEMU_PACKED VirtIOSCSICtrlANResp;
> -
> -typedef struct {
> -uint32_t event;
> -uint8_t lun[8];
> -uint32_t reason;
> -} QEMU_PACKED VirtIOSCSIEvent;
> -
> -typedef struct {
> -uint32_t num_queues;
> -uint32_t seg_max;
> -uint32_t max_sectors;
> -uint32_t cmd_per_lun;
> -uint32_t event_info_size;
> -uint32_t sense_size;
> -uint32_t cdb_size;
> -uint16_t max_channel;
> -uint16_t max_target;
> -uint32_t max_lun;
> -} QEMU_PACKED VirtIOSCSICon

Re: [Qemu-devel] [PATCH] qcow2: Remove unused struct QCowCreateState

2015-02-17 Thread Max Reitz

On 2015-02-17 at 08:49, Kevin Wolf wrote:

The only user went away five years ago with commit a9420734 ('qcow2:
Simplify image creation'). It's about time to remove it.

Signed-off-by: Kevin Wolf 
---
  block/qcow2.h | 11 ---
  1 file changed, 11 deletions(-)


Reviewed-by: Max Reitz 



Re: [Qemu-devel] [PATCH 4/4] acpi-build: simplify rsdp management for legacy

2015-02-17 Thread Igor Mammedov
On Tue, 17 Feb 2015 11:05:45 +0100
"Michael S. Tsirkin"  wrote:

> For legacy machine types, rsdp is not in RAM, so we need a copy of rsdp
> for fw cfg. We previously used g_array_free with false parameter,
> but this seems to confuse people.
> This also wastes a bit of memory as the buffer is unused for new
> machine types.
> 
> Let's just use plain g_memdup, and free original memory together with
> the array.
> 
> TODO: rationalize tcpalog memory management, and get rid of the mfre
> parameter.
> 
> Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 

> ---
>  hw/i386/acpi-build.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index ffa3f00..f712277 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -1257,7 +1257,7 @@ static inline void 
> acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
>  {
>  void *linker_data = bios_linker_loader_cleanup(tables->linker);
>  g_free(linker_data);
> -g_array_free(tables->rsdp, mfre);
> +g_array_free(tables->rsdp, true);
>  g_array_free(tables->table_data, true);
>  g_array_free(tables->tcpalog, mfre);
>  }
> @@ -1560,12 +1560,14 @@ void acpi_setup(PcGuestInfo *guest_info)
>  /*
>   * Keep for compatibility with old machine types.
>   * Though RSDP is small, its contents isn't immutable, so
> - * update it along with the rest of tables on guest access.
> + * we'll update it along with the rest of tables on guest access.
>   */
> +uint32_t rsdp_size = acpi_data_len(tables.rsdp);
> +
> +build_state->rsdp = g_memdup(tables.rsdp->data, rsdp_size);
>  fw_cfg_add_file_callback(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
>   acpi_build_update, build_state,
> - tables.rsdp->data, 
> acpi_data_len(tables.rsdp));
> -build_state->rsdp = tables.rsdp->data;
> + build_state->rsdp, rsdp_size);
>  build_state->rsdp_ram = (ram_addr_t)-1;
>  } else {
>  build_state->rsdp = NULL;




Re: [Qemu-devel] [PATCH 0/6] migration: differentiate between pages and bytes

2015-02-17 Thread Dr. David Alan Gilbert
* Juan Quintela (quint...@redhat.com) wrote:
> Hi
> 
> (Li special edition)
> 
> Current migration code returns number of bytes transferred and from
> there we decide if we.have sent something or not.  Problem, we need
> two results: number of pages written, and number of bytes written
> (depending on compression, zero pages, etc, it is not possible to
> derive one value from the other).
> 
> So, I changed all relevant function to return the number of written
> pages, and then pass as uint64_t *bytes_transferred to update the
> written bytes.
> 
> On current code, makes things a bit easier to understand, but is not
> strictely necesary.  But for the compression patches from Li, it makes
> a big difference, we can return that we have written a page, even if
> we have just started the write, but having writtten in reality zero
> bytes.
> 
> Once there, I add doxygen documentation to all function that I touched
> (yes, I was long due).
> 
> save_block_hdr really saved headers for pages, not blocks.  Rename it,
> and simplify the interface.
> 
> Li, does this make your life easier?  I hope so.  Should make really
> easy to remove the one_bytes_sent "hack", and allow my other suggestions.
> 
> Comments?

I like it; it generally seems to make sense to separate the concept
of whether we've actually sent any pages from the actual byte counting.

While you're there though; do we actually care about bean counting
the individual header bytes?  For example the &bytes_transferred += 1 in the
RAM_SAVE_FLAG_COMPRESS case where it puts the 0, or the EOS mark where
we add 8 bytes?   Do we need to keep track of anything other than
stuff that's potentially big enough to make an impact on the
bandwidth calculations?

Dave

> 
> Later, Juan.
> 
> PD.  Code is obviously correct, but I run it through virt-test
>  anyways.  And it failed :-(  In despair, I tried virt-test on HEAD,
>  and it also failed, so   I add another thing to my ToDo list.
> 
> PD2.  Modifying ram_save_page() has become complicated, very
>   complicated. I think that know a couple of simplications, but
>   require touching RDMA code, and anyways, fixing migration in
>   "master" looks like a higher priority.
> 
> 
> Juan Quintela (6):
>   ram: make all save_page functions take a uint64_t parameter
>   ram_find_and_save_block:  change calling convention
>   ram_save_page: change calling covention
>   save_xbzrle_page: change calling convention
>   save_block_hdr: we can recalculate the cont parameter here
>   rename save_block_hdr to save_page_header
> 
>  arch_init.c   | 176 
> ++
>  include/migration/migration.h |   2 +-
>  include/migration/qemu-file.h |   2 +-
>  migration/qemu-file.c |   3 +-
>  migration/rdma.c  |   2 +-
>  5 files changed, 114 insertions(+), 71 deletions(-)
> 
> -- 
> 2.1.0
> 
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



[Qemu-devel] [RFC PATCH v2 04/15] cpu-model/s390: Introduce S390 CPU models

2015-02-17 Thread Michael Mueller
This patch implements the static part of the s390 cpu class definitions.
It defines s390 cpu models by means of virtual cpu ids (enum) which contain
information on the cpu generation, the machine class, the GA number and
the machine type. The cpu id is used to instantiate a cpu class per cpu
model.

In addition the patch introduces the QMP enumeration AccelId. It is used
to index certain cpu model poperties per accelerator.

Furthermore it extends the existing S390CPUClass by model related properties.

Signed-off-by: Michael Mueller 
Reviewed-by: Thomas Huth 
---
 qapi-schema.json   | 11 +++
 target-s390x/Makefile.objs |  1 +
 target-s390x/cpu-models.c  | 79 ++
 target-s390x/cpu-models.h  | 71 +
 target-s390x/cpu-qom.h | 22 +
 target-s390x/cpu.c |  2 ++
 6 files changed, 186 insertions(+)
 create mode 100644 target-s390x/cpu-models.c
 create mode 100644 target-s390x/cpu-models.h

diff --git a/qapi-schema.json b/qapi-schema.json
index e16f8eb..4d237c8 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2473,6 +2473,17 @@
 ##
 { 'command': 'query-machines', 'returns': ['MachineInfo'] }
 
+
+##
+# @AccelId
+#
+# Defines accelerator ids
+#
+# Since: 2.3.0
+##
+{ 'enum': 'AccelId',
+  'data': ['qtest', 'tcg', 'kvm', 'xen'  ] }
+
 ##
 # @CpuDefinitionInfo:
 #
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index 2c57494..9f55140 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -1,5 +1,6 @@
 obj-y += translate.o helper.o cpu.o interrupt.o
 obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o
 obj-y += gdbstub.o
+obj-y += cpu-models.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o
 obj-$(CONFIG_KVM) += kvm.o
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
new file mode 100644
index 000..4841553
--- /dev/null
+++ b/target-s390x/cpu-models.c
@@ -0,0 +1,79 @@
+/*
+ * CPU models for s390
+ *
+ * Copyright 2014,2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * 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.
+ */
+
+#include "qemu-common.h"
+#include "cpu-models.h"
+
+#define S390_PROC_DEF(_name, _cpu_id, _desc)\
+static void \
+glue(_cpu_id, _cpu_class_init)  \
+(ObjectClass *oc, void *data)   \
+{   \
+DeviceClass *dc = DEVICE_CLASS(oc); \
+S390CPUClass *cc = S390_CPU_CLASS(oc);  \
+\
+cc->is_active[ACCEL_ID_KVM] = true; \
+cc->mach= g_malloc0(sizeof(S390CPUMachineProps));   \
+cc->mach->ga= cpu_ga(_cpu_id);  \
+cc->mach->class = cpu_class(_cpu_id);   \
+cc->mach->order = cpu_order(_cpu_id);   \
+cc->proc= g_malloc0(sizeof(S390CPUProcessorProps)); \
+cc->proc->gen   = cpu_generation(_cpu_id);  \
+cc->proc->ver   = S390_DEF_VERSION; \
+cc->proc->id= S390_DEF_ID;  \
+cc->proc->type  = cpu_type(_cpu_id);\
+cc->proc->ibc   = S390_DEF_IBC; \
+dc->desc= _desc;\
+}   \
+static const TypeInfo   \
+glue(_cpu_id, _cpu_type_info) = {   \
+.name   = _name "-" TYPE_S390_CPU,  \
+.parent = TYPE_S390_CPU,\
+.class_init = glue(_cpu_id, _cpu_class_init),   \
+};  \
+static void \
+glue(_cpu_id, _cpu_register_types)(void)\
+{   \
+type_register_static(   \
+&glue(_cpu_id, _cpu_type_info));\
+}   \
+type_init(glue(_cpu_id, _cpu_register_types))
+
+/* define S390 CPU model classes */
+S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")
+S390_PROC_DEF("2064-ga2", CP

[Qemu-devel] [RFC PATCH v2 03/15] cpu-model: Introduce stub routine cpu_desc_avail

2015-02-17 Thread Michael Mueller
This patch introduces the function cpu_desc_avail() which returns by
default true if not architecture specific implemented. Its intention
is to indicate if the cpu model description is available for display
by list_cpus(). This change allows cpu model descriptions to become
dynamically created by evaluating the runtime context instead of
putting static cpu model information at display.

Signed-off-by: Michael Mueller 
Reviewed-by: Thomas Huth 
---
 include/qemu-common.h  | 2 ++
 stubs/Makefile.objs| 1 +
 stubs/cpu-desc-avail.c | 6 ++
 vl.c   | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 stubs/cpu-desc-avail.c

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 644b46d..45040f9 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -481,4 +481,6 @@ int parse_debug_env(const char *name, int max, int initial);
 
 const char *qemu_ether_ntoa(const MACAddr *mac);
 
+bool cpu_desc_avail(void);
+
 #endif
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 5e347d0..fd7a489 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -40,3 +40,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o
 stub-obj-y += cpus.o
 stub-obj-y += kvm.o
 stub-obj-y += qmp_pc_dimm_device_list.o
+stub-obj-y += cpu-desc-avail.o
diff --git a/stubs/cpu-desc-avail.c b/stubs/cpu-desc-avail.c
new file mode 100644
index 000..0cd594e
--- /dev/null
+++ b/stubs/cpu-desc-avail.c
@@ -0,0 +1,6 @@
+#include "qemu-common.h"
+
+bool cpu_desc_avail(void)
+{
+return true;
+}
diff --git a/vl.c b/vl.c
index 0fabc0b..130fb1e 100644
--- a/vl.c
+++ b/vl.c
@@ -3819,7 +3819,7 @@ int main(int argc, char **argv, char **envp)
  */
 cpudef_init();
 
-if (cpu_model && is_help_option(cpu_model)) {
+if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) {
 list_cpus(stdout, &fprintf, cpu_model);
 exit(0);
 }
-- 
1.8.3.1




  1   2   3   >