[Qemu-devel] [PATCH] linux-user: Let user specify random seed

2014-10-09 Thread Magnus Reftel
This patch introduces the -seed command line option and the
QEMU_RAND_SEED environment variable for setting the random seed, which
is used for the AT_RANDOM ELF aux entry.

Signed-off-by: Magnus Reftel 
---
 linux-user/elfload.c |  1 -
 linux-user/main.c| 20 
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1c04fcf..f2e2197 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1539,7 +1539,6 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 
int envc,
  * Generate 16 random bytes for userspace PRNG seeding (not
  * cryptically secure but it's not the aim of QEMU).
  */
-srand((unsigned int) time(NULL));
 for (i = 0; i < 16; i++) {
 k_rand_bytes[i] = rand();
 }
diff --git a/linux-user/main.c b/linux-user/main.c
index 483eb3f..e80255c 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3546,6 +3546,18 @@ static void handle_arg_pagesize(const char *arg)
 }
 }
 
+static void handle_arg_randseed(const char *arg)
+{
+unsigned long seed;
+char* end;
+seed = strtoul(arg, &end, 0);
+if (end==arg || *end!='\0' || seed > UINT_MAX) {
+fprintf(stderr, "Invalid seed number: %s\n", arg);
+exit(1);
+}
+srand(seed);
+}
+
 static void handle_arg_gdb(const char *arg)
 {
 gdbstub_port = atoi(arg);
@@ -3674,6 +3686,8 @@ static const struct qemu_argument arg_table[] = {
  "",   "run in singlestep mode"},
 {"strace", "QEMU_STRACE",  false, handle_arg_strace,
  "",   "log system calls"},
+{"seed",   "QEMU_RAND_SEED",   true,  handle_arg_randseed,
+ "",   "Seed for pseudo-random number generator"},
 {"version","QEMU_VERSION", false, handle_arg_version,
  "",   "display version information and exit"},
 {NULL, NULL, false, NULL, NULL, NULL}
@@ -3856,6 +3870,8 @@ int main(int argc, char **argv, char **envp)
 cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
 #endif
 
+srand(time(NULL));
+
 optind = parse_args(argc, argv);
 
 /* Zero out regs */
@@ -3926,6 +3942,10 @@ int main(int argc, char **argv, char **envp)
 do_strace = 1;
 }
 
+if (getenv("QEMU_RAND_SEED")) {
+handle_arg_randseed(getenv("QEMU_RAND_SEED"));
+}
+
 target_environ = envlist_to_environ(envlist, NULL);
 envlist_free(envlist);
 
-- 
1.9.1




[Qemu-devel] [PATCH v2] linux-user: Let user specify random seed

2014-10-09 Thread Magnus Reftel
This patch introduces the -seed command line option and the
QEMU_RAND_SEED environment variable for setting the random seed, which
is used for the AT_RANDOM ELF aux entry.

This is an updated version of the patch, addressing review comments
from Eric Blake.



qemu-devel@nongnu.org

2014-10-09 Thread Fabien Chouteau
On 10/08/2014 05:38 PM, Andreas Färber wrote:
> Hi,
> 

Hi Andreas,

> Am 08.10.2014 um 16:19 schrieb Fabien Chouteau:
>> From: Jiri Gaisler 
>>
>> +
>> +#define TYPE_GRLIB_APB_PNP "grlib,apbpnp"
> 
> If you move the two TYPE_* constants to grlib.h, you can reuse them.
> 

Will do.

>> +#define GRLIB_APB_PNP(obj) \
>> +OBJECT_CHECK(APBPNP, (obj), TYPE_GRLIB_APB_PNP)
>> +
>> +typedef struct APBPNP {
>> +SysBusDevice parent_obj;
>> +MemoryRegion iomem;
>> +} APBPNP;
>> +
>> +static uint64_t grlib_apbpnp_read(void *opaque, hwaddr addr,
>> +   unsigned size)
> 
> Indentation is off by one for all read/write functions.
> 

Are you sure? The indentation is 4 spaces right? (checkpatch.pl didn't
raise any error).

>> +static int grlib_apbpnp_init(SysBusDevice *dev)
>> +{
>> +APBPNP *pnp = GRLIB_APB_PNP(dev);
>> +
>> +memory_region_init_io(&pnp->iomem, OBJECT(pnp), &grlib_apbpnp_ops, pnp,
>> +  "apbpnp", APBPNP_REG_SIZE);
>> +
>> +sysbus_init_mmio(dev, &pnp->iomem);
>
> APBPNP_REG_SIZE seems constant, so you could move both lines into an
> instance_init function.
>

Will do. I don't need a .class_init then.

>> +
>> +k->init = grlib_apbpnp_init;
>> +}
>> +
>> +static const TypeInfo grlib_apbpnp_info = {
>> +.name  = TYPE_GRLIB_APB_PNP,
>> +.parent= TYPE_SYS_BUS_DEVICE,
>> +.instance_size = sizeof(APBPNP),
>> +.class_init= grlib_apbpnp_class_init,
>> +};
>> +
>> +static void grlib_apbpnp_register_types(void)
>> +{
>> +type_register_static(&grlib_apbpnp_info);
>> +}
>> +
>> +type_init(grlib_apbpnp_register_types)
> 
> Please either split into two .c files here, ...
> 

>> 
> ... or if unavoidable use just one type_init and registration function.
> +

I will create one type init for both memory regions.

>> +static inline
>> +DeviceState *grlib_ahbpnp_create(hwaddr  base)
>> +{
>> +DeviceState *dev;
>> +
>> +dev = qdev_create(NULL, "grlib,ahbpnp");
>> +
>> +if (qdev_init(dev)) {
>> +return NULL;
>> +}
>> +
>> +sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
>> +
>> +return dev;
>> +}
>> +
>>  #endif /* ! _GRLIB_H_ */
> 
> Are these functions really needed? Can't you just inline them?
> Also note that the return value is never actually checked.
>

This is what we do for all GRLIB devices, I think it makes a cleaner
machine init.

Thanks for the review.



Re: [Qemu-devel] [PATCH v1 7/8] throttle: Add throttle group support

2014-10-09 Thread Fam Zheng
On Wed, 10/08 11:05, Benoît Canet wrote:
> On Wed, Oct 08, 2014 at 02:53:38PM +0800, Fam Zheng wrote:
> > 
> > Does this mean that after this series, all the throttle_states must be
> > contained inside its own throttle group? If so, we could embed ThrottleGroup
> > fields in ThrottleState.
> > 
> > It's weird when a function called throttle_group_compare takes a parameter 
> > of
> > ThrottleState pointer, and cast it back to ThrottleGroup with container_of.
> 
> It's done like this to fullfill a design goal: the throttle should be reusable
> without the groups and any reference to block related stuff.
> So it's just a way to split the responsabilities.

I see.

Having both ThrottleGroup and ThrottleState interfaces is more complicated than
just use ThrottleGroup, where a one-member group is exactly the same as
ThrottleState.

Fam



qemu-devel@nongnu.org

2014-10-09 Thread Fabien Chouteau
On 10/08/2014 09:43 PM, Jiri Gaisler wrote:
> On 10/08/2014 05:38 PM, Andreas Färber wrote:
>> Hi,
>>
>> Am 08.10.2014 um 16:19 schrieb Fabien Chouteau:
>>> From: Jiri Gaisler 
>>>
>>> AMBA plug&play is used by kernels to probe available devices (Timers,
>>> UART, etc...). This is a static declaration of devices implemented in
>>> QEMU. In the future, a more advanced version could compute those
>>> information directly from the device tree.
>>
>> Interesting. There's quite some magic numbers in the read functions; I
>> wonder if you could read them via QOM if you actually give the devices a
>> canonical path or search by type? You may want to peek at ACPI code.
> 
> 
> The plug&play area is similar in function to the PCI configuration
> space, indicating vendor/device ID's, address range, interrupt number
> etc. of on-chip IP cores. The 'magic' numbers could be generated by
> generic functions taking these parameters as inputs. This would
> certainly make the code more readable, and easily extended in the
> future. Would such a solution be acceptable?
> 
> 

That would be a great improvement, then we could try to plug it with the
QOM API to generate automatically the data.




Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and take effect after rebooting

2014-10-09 Thread Gerd Hoffmann
On Mi, 2014-10-08 at 19:00 +0800, Gonglei wrote:
> On 2014/10/7 16:00, Gonglei (Arei) wrote:
> 
> > From: Gonglei 
> > 
> > Changes since v10:
> >  1. add handler for virtio-blk-pci/s390/ccw in PATCH 28.
> >  2. add especial bootidnex setter/getter functions for usb-storage
> > device in PATCH 29.
> >  3. add bootindex qom property for nvma and ne2k_isa devices,
> > avoid regrassion in PATCH 30.
> >  4. change fprintf to error_report in bootdevice.c in PATCH 34.
> >  5. rebase on the latest qemu master tree.
> >  6. add 'Reviewed-by' in other patches. (Thanks, Gerd)
> > 
> 
> 
> Hi, Gerd
> 
> Could you please review the v11 and consider to merge this series in your 
> tree?
> I have no idea which maintainer can apply this series. It seems that only you
> and Eduardo  interested in and reviewed this patch series at present. :(

Yea, for these cross-tree changes it isn't always clear which way they
should be merged.  qom or pc would make sense I think.

I can prepare a pull request too, but I'd like to have a second opinion
on the stuff which is outside of my primary focus:

  * fw_cfg changes (mst?  paolo?)
  * qom bits (andreas?  paolo?, eduardo?)

I'll go take "no answer" as "no objections", but I'd prefer to apply one
or another "reviewed-by" to the series.

thanks,
  Gerd





Re: [Qemu-devel] [PATCH] block/migration: Disable cache invalidate for incoming migration

2014-10-09 Thread Paolo Bonzini
Il 09/10/2014 04:50, Alexey Kardashevskiy ha scritto:
> When migrated using libvirt with "--copy-storage-all", at the end of
> migration there is race between NBD mirroring task trying to do flush
> and migration completion, both end up invalidating cache. Since qcow2
> driver does not handle this situation very well, random crashes happen.
> 
> This disables the BDRV_O_INCOMING flag for the block device being migrated
> once the cache has been invalidated.
> 
> Signed-off-by: Alexey Kardashevskiy 
> ---
> Changes:
> v1 (v0 was RFC):
> * added a comment to nbd_export_new() as suggested by Stefan
> ---
>  block.c | 18 +-
>  migration.c |  1 -
>  nbd.c   |  6 ++
>  3 files changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/block.c b/block.c
> index c5a251c..6314af7 100644
> --- a/block.c
> +++ b/block.c
> @@ -5048,6 +5048,11 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error 
> **errp)
>  return;
>  }
>  
> +if (!(bs->open_flags & BDRV_O_INCOMING)) {
> +return;
> +}
> +bs->open_flags &= ~(BDRV_O_INCOMING);

Unnecessary parentheses.

> +
>  if (bs->drv->bdrv_invalidate_cache) {
>  bs->drv->bdrv_invalidate_cache(bs, &local_err);
>  } else if (bs->file) {
> @@ -5083,19 +5088,6 @@ void bdrv_invalidate_cache_all(Error **errp)
>  }
>  }
>  
> -void bdrv_clear_incoming_migration_all(void)
> -{
> -BlockDriverState *bs;
> -
> -QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
> -AioContext *aio_context = bdrv_get_aio_context(bs);
> -
> -aio_context_acquire(aio_context);
> -bs->open_flags = bs->open_flags & ~(BDRV_O_INCOMING);
> -aio_context_release(aio_context);
> -}
> -}
> -
>  int bdrv_flush(BlockDriverState *bs)
>  {
>  Coroutine *co;
> diff --git a/migration.c b/migration.c
> index 8d675b3..c49a05a 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -103,7 +103,6 @@ static void process_incoming_migration_co(void *opaque)
>  }
>  qemu_announce_self();
>  
> -bdrv_clear_incoming_migration_all();
>  /* Make sure all file formats flush their mutable metadata */
>  bdrv_invalidate_cache_all(&local_err);
>  if (local_err) {
> diff --git a/nbd.c b/nbd.c
> index e9b539b..a7bce45 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -972,6 +972,12 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t 
> dev_offset,
>  exp->ctx = bdrv_get_aio_context(bs);
>  bdrv_ref(bs);
>  bdrv_add_aio_context_notifier(bs, bs_aio_attached, bs_aio_detach, exp);
> +/*
> + * NBD exports are used for non-shared storage migration.  Make sure
> + * that BDRV_O_INCOMING is cleared and the image is ready for write
> + * access since the export could be available before migration handover.
> + */
> +bdrv_invalidate_cache(bs, NULL);
>  return exp;
>  }
>  
> 

Apart from the above style remark,

Reviewed-by: Paolo Bonzini 




Re: [Qemu-devel] [PATCH 3/3] qemu-sockets: Add error to non-blocking connect handler

2014-10-09 Thread Paolo Bonzini
Il 08/10/2014 14:11, miny...@acm.org ha scritto:
> From: Corey Minyard 
> 
> An error value here would be quite handy and more consistent
> with the rest of the code.
> 
> Corey Minyard 
> ---
>  include/qemu/sockets.h |  2 +-
>  migration-tcp.c|  4 ++--
>  migration-unix.c   |  4 ++--
>  qemu-char.c|  6 +++---
>  util/qemu-sockets.c| 19 ++-
>  5 files changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
> index fdbb196..f47dae6 100644
> --- a/include/qemu/sockets.h
> +++ b/include/qemu/sockets.h
> @@ -47,7 +47,7 @@ int recv_all(int fd, void *buf, int len1, bool single_read);
>  /* callback function for nonblocking connect
>   * valid fd on success, negative error code on failure
>   */
> -typedef void NonBlockingConnectHandler(int fd, void *opaque);
> +typedef void NonBlockingConnectHandler(int fd, Error *errp, void *opaque);
>  
>  InetSocketAddress *inet_parse(const char *str, Error **errp);
>  int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
> diff --git a/migration-tcp.c b/migration-tcp.c
> index 2e34517..91c9cf3 100644
> --- a/migration-tcp.c
> +++ b/migration-tcp.c
> @@ -33,12 +33,12 @@
>  do { } while (0)
>  #endif
>  
> -static void tcp_wait_for_connect(int fd, void *opaque)
> +static void tcp_wait_for_connect(int fd, Error *err, void *opaque)
>  {
>  MigrationState *s = opaque;
>  
>  if (fd < 0) {
> -DPRINTF("migrate connect error\n");
> +DPRINTF("migrate connect error: %s\n", error_get_pretty(err));
>  s->file = NULL;
>  migrate_fd_error(s);
>  } else {
> diff --git a/migration-unix.c b/migration-unix.c
> index 0a5f8a1..1cdadfb 100644
> --- a/migration-unix.c
> +++ b/migration-unix.c
> @@ -33,12 +33,12 @@
>  do { } while (0)
>  #endif
>  
> -static void unix_wait_for_connect(int fd, void *opaque)
> +static void unix_wait_for_connect(int fd, Error *err, void *opaque)
>  {
>  MigrationState *s = opaque;
>  
>  if (fd < 0) {
> -DPRINTF("migrate connect error\n");
> +DPRINTF("migrate connect error: %s\n", error_get_pretty(err));
>  s->file = NULL;
>  migrate_fd_error(s);
>  } else {
> diff --git a/qemu-char.c b/qemu-char.c
> index 83ff458..8f3af06 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -3061,14 +3061,14 @@ static void 
> qemu_chr_finish_socket_connection(CharDriverState *chr, int fd)
>  }
>  }
>  
> -static void qemu_chr_socket_connected(int fd, void *opaque)
> +static void qemu_chr_socket_connected(int fd, Error *err, void *opaque)
>  {
>  CharDriverState *chr = opaque;
>  TCPCharDriver *s = chr->opaque;
>  
>  if (fd < 0) {
> -check_report_connect_error(chr, "Unable to connect to socket %s",
> -   chr->label);
> +check_report_connect_error(chr, "Unable to connect to socket %s: %s",
> +   chr->label, error_get_pretty(err));
>  return;
>  }
>  
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index 1eef590..e6a9644 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -234,6 +234,7 @@ static void wait_for_connect(void *opaque)
>  int val = 0, rc = 0;
>  socklen_t valsize = sizeof(val);
>  bool in_progress;
> +Error *err = NULL;
>  
>  qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
>  
> @@ -248,6 +249,7 @@ static void wait_for_connect(void *opaque)
>  
>  /* connect error */
>  if (rc < 0) {
> +error_setg_errno(&err, errno, "Error connecting to socket");
>  closesocket(s->fd);
>  s->fd = rc;
>  }

This is missing above this hunk:

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index e6a9644..a76bb3c 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -245,6 +245,7 @@ static void wait_for_connect(void *opaque)
 /* update rc to contain error */
 if (!rc && val) {
 rc = -1;
+errno = val;
 }

 /* connect error */

> @@ -257,9 +259,14 @@ static void wait_for_connect(void *opaque)
>  while (s->current_addr->ai_next != NULL && s->fd < 0) {
>  s->current_addr = s->current_addr->ai_next;
>  s->fd = inet_connect_addr(s->current_addr, &in_progress, s, 
> NULL);
> +if (s->fd < 0) {
> +error_free(err);
> +err = NULL;
> +error_setg_errno(&err, errno, "Unable to start socket 
> connect");
> +}
>  /* connect in progress */
>  if (in_progress) {
> -return;
> +goto out;
>  }
>  }
>  
> @@ -267,9 +274,11 @@ static void wait_for_connect(void *opaque)
>  }
>  
>  if (s->callback) {
> -s->callback(s->fd, s->opaque);
> +s->callback(s->fd, err, s->opaque);
>  }
>  g_free(s);
> +out:
> +error_free(err);
>  }
>  
>  static int inet_connect_addr(str

[Qemu-devel] [PULL 00/28] Changes for 2014-10-09

2014-10-09 Thread Paolo Bonzini
The following changes since commit 1831e150606a221898bf46ffaf0453e9952cbbc4:

  Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging 
(2014-09-30 16:45:35 +0100)

are available in the git repository at:


  git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to e50fffc7209c9ce844dcb21a99f2d4b3f93900c0:

  qemu-char: Fix reconnect socket error reporting (2014-10-09 12:08:42 +0200)


Four changes here.  Polling for reconnection of character devices,
the QOMification of accelerators, a fix for -kernel support on x86, and one
for a recently-introduced virtio-scsi optimization.


Corey Minyard (9):
  qemu-char: Make the filename size for a chardev a #define
  qemu-char: Rework qemu_chr_open_socket() for reconnect
  qemu-char: Move some items into TCPCharDriver
  qemu-char: set socket filename to disconnected when not connected
  qemu-char: Add reconnecting to client sockets
  qemu-char: Print the remote and local addresses for a socket
  qemu-error: Add error_vreport()
  qemu-sockets: Add error to non-blocking connect handler
  qemu-char: Fix reconnect socket error reporting

Eduardo Habkost (17):
  vl.c: Small coding style fix
  accel: Move accel code to accel.c
  accel: Create AccelType typedef
  accel: Simplify configure_accelerator() using AccelType *acc variable
  accel: Move accel name lookup to separate function
  accel: Use QOM classes for accel types
  accel: Make AccelClass.available() optional
  accel: Report unknown accelerator as "not found" instead of "does not 
exist"
  accel: Move KVM accel registration to kvm-all.c
  accel: Move Xen registration code to xen-common.c
  accel: Move qtest accel registration to qtest.c
  accel: Remove tcg_available() function
  accel: Move accel init/allowed code to separate function
  accel: Rename 'init' method to 'init_machine'
  accel: Pass MachineState object to accel init functions
  accel: Create accel object when initializing machine
  kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

Paolo Bonzini (2):
  linuxboot: compute initrd loading address
  virtio-scsi: fix use-after-free of VirtIOSCSIReq

 Makefile.objs |   1 +
 accel.c   | 157 ++
 arch_init.c   |   5 -
 hw/scsi/virtio-scsi.c |   9 +-
 include/hw/boards.h   |   1 +
 include/hw/xen/xen.h  |   1 -
 include/qemu/error-report.h   |   1 +
 include/qemu/sockets.h|   2 +-
 include/qemu/typedefs.h   |   3 +
 include/sysemu/accel.h|  62 
 include/sysemu/arch_init.h|   1 -
 include/sysemu/kvm.h  |   2 -
 include/sysemu/qtest.h|   1 -
 kvm-all.c |  40 -
 kvm-stub.c|   5 -
 migration-tcp.c   |   4 +-
 migration-unix.c  |   4 +-
 pc-bios/linuxboot.bin | Bin 1024 -> 1024 bytes
 pc-bios/optionrom/linuxboot.S |  47 +-
 pc-bios/optionrom/optionrom.h |  21 ++-
 qapi-schema.json  |  15 +-
 qemu-char.c   | 359 --
 qemu-options.hx   |  20 ++-
 qtest.c   |  27 +++-
 util/qemu-error.c |  23 ++-
 util/qemu-sockets.c   |  20 ++-
 vl.c  |  83 +-
 xen-common-stub.c |   6 -
 xen-common.c  |  25 ++-
 29 files changed, 712 insertions(+), 233 deletions(-)
 create mode 100644 accel.c
 create mode 100644 include/sysemu/accel.h
-- 
1.8.3.1




[Qemu-devel] [PULL 04/28] qemu-char: set socket filename to disconnected when not connected

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

This way we can tell if the socket is connected or not.  It also splits
the string conversions out into separate functions to make this more
convenient.

Signed-off-by: Corey Minyard 
Reviewed-by: Paolo Bonzini 
Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 110 +++-
 1 file changed, 72 insertions(+), 38 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index a671d6b..549ebd8 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -117,6 +117,60 @@ static void qapi_copy_SocketAddress(SocketAddress **p_dest,
 qobject_decref(obj);
 }
 
+static int SocketAddress_to_str(char *dest, int max_len,
+const char *prefix, SocketAddress *addr,
+bool is_listen, bool is_telnet)
+{
+switch (addr->kind) {
+case SOCKET_ADDRESS_KIND_INET:
+return snprintf(dest, max_len, "%s%s:%s:%s%s", prefix,
+is_telnet ? "telnet" : "tcp", addr->inet->host,
+addr->inet->port, is_listen ? ",server" : "");
+break;
+case SOCKET_ADDRESS_KIND_UNIX:
+return snprintf(dest, max_len, "%sunix:%s%s", prefix,
+addr->q_unix->path, is_listen ? ",server" : "");
+break;
+case SOCKET_ADDRESS_KIND_FD:
+return snprintf(dest, max_len, "%sfd:%s%s", prefix, addr->fd->str,
+is_listen ? ",server" : "");
+break;
+default:
+abort();
+}
+}
+
+static int sockaddr_to_str(char *dest, int max_len,
+   struct sockaddr_storage *ss, socklen_t ss_len,
+   bool is_listen, bool is_telnet)
+{
+char host[NI_MAXHOST], serv[NI_MAXSERV];
+const char *left = "", *right = "";
+
+switch (ss->ss_family) {
+#ifndef _WIN32
+case AF_UNIX:
+return snprintf(dest, max_len, "unix:%s%s",
+((struct sockaddr_un *)(ss))->sun_path,
+is_listen ? ",server" : "");
+#endif
+case AF_INET6:
+left  = "[";
+right = "]";
+/* fall through */
+case AF_INET:
+getnameinfo((struct sockaddr *) ss, ss_len, host, sizeof(host),
+serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV);
+return snprintf(dest, max_len, "%s:%s%s%s:%s%s",
+is_telnet ? "telnet" : "tcp",
+left, host, right, serv,
+is_listen ? ",server" : "");
+
+default:
+return snprintf(dest, max_len, "unknown");
+}
+}
+
 /***/
 /* character device */
 
@@ -2727,6 +2781,8 @@ static void tcp_chr_disconnect(CharDriverState *chr)
 s->chan = NULL;
 closesocket(s->fd);
 s->fd = -1;
+SocketAddress_to_str(chr->filename, CHR_MAX_FILENAME_SIZE,
+ "disconnected:", s->addr, s->is_listen, s->is_telnet);
 qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
 }
 
@@ -2798,6 +2854,17 @@ static void tcp_chr_connect(void *opaque)
 {
 CharDriverState *chr = opaque;
 TCPCharDriver *s = chr->opaque;
+struct sockaddr_storage ss;
+socklen_t ss_len = sizeof(ss);
+
+memset(&ss, 0, ss_len);
+if (getsockname(s->fd, (struct sockaddr *) &ss, &ss_len) != 0) {
+snprintf(chr->filename, CHR_MAX_FILENAME_SIZE,
+ "Error in getsockname: %s\n", strerror(errno));
+} else {
+sockaddr_to_str(chr->filename, CHR_MAX_FILENAME_SIZE, &ss, ss_len,
+s->is_listen, s->is_telnet);
+}
 
 s->connected = 1;
 if (s->chan) {
@@ -2928,43 +2995,9 @@ static void tcp_chr_close(CharDriverState *chr)
 qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
 }
 
-static bool qemu_chr_finish_socket_connection(CharDriverState *chr, int fd,
-  Error **errp)
+static void qemu_chr_finish_socket_connection(CharDriverState *chr, int fd)
 {
 TCPCharDriver *s = chr->opaque;
-char host[NI_MAXHOST], serv[NI_MAXSERV];
-const char *left = "", *right = "";
-struct sockaddr_storage ss;
-socklen_t ss_len = sizeof(ss);
-
-memset(&ss, 0, ss_len);
-if (getsockname(fd, (struct sockaddr *) &ss, &ss_len) != 0) {
-closesocket(fd);
-error_setg_errno(errp, errno, "getsockname");
-return false;
-}
-
-switch (ss.ss_family) {
-#ifndef _WIN32
-case AF_UNIX:
-snprintf(chr->filename, CHR_MAX_FILENAME_SIZE, "unix:%s%s",
- ((struct sockaddr_un *)(&ss))->sun_path,
- s->is_listen ? ",server" : "");
-break;
-#endif
-case AF_INET6:
-left  = "[";
-right = "]";
-/* fall through */
-case AF_INET:
-getnameinfo((struct sockaddr *) &ss, ss_len, host, sizeof(host),
-serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV);
-snprintf(chr->filename, CHR_MAX_FILENAME_SIZE, "%s:%s%s%s:%s%s",
- 

[Qemu-devel] [PULL 01/28] qemu-char: Make the filename size for a chardev a #define

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

Signed-off-by: Corey Minyard 
Reviewed-by: Paolo Bonzini 
Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 8623c70..f9d2a02 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -84,6 +84,7 @@
 
 #define READ_BUF_LEN 4096
 #define READ_RETRIES 10
+#define CHR_MAX_FILENAME_SIZE 256
 
 /***/
 /* character device */
@@ -989,7 +990,8 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int 
fd_out)
 static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts)
 {
 int fd_in, fd_out;
-char filename_in[256], filename_out[256];
+char filename_in[CHR_MAX_FILENAME_SIZE];
+char filename_out[CHR_MAX_FILENAME_SIZE];
 const char *filename = opts->device;
 
 if (filename == NULL) {
@@ -997,8 +999,8 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev 
*opts)
 return NULL;
 }
 
-snprintf(filename_in, 256, "%s.in", filename);
-snprintf(filename_out, 256, "%s.out", filename);
+snprintf(filename_in, CHR_MAX_FILENAME_SIZE, "%s.in", filename);
+snprintf(filename_out, CHR_MAX_FILENAME_SIZE, "%s.out", filename);
 TFR(fd_in = qemu_open(filename_in, O_RDWR | O_BINARY));
 TFR(fd_out = qemu_open(filename_out, O_RDWR | O_BINARY));
 if (fd_in < 0 || fd_out < 0) {
@@ -1976,7 +1978,7 @@ static int win_chr_pipe_init(CharDriverState *chr, const 
char *filename)
 OVERLAPPED ov;
 int ret;
 DWORD size;
-char openname[256];
+char openname[CHR_MAX_FILENAME_SIZE];
 
 s->fpipe = TRUE;
 
@@ -2918,12 +2920,12 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 s->write_msgfds = 0;
 s->write_msgfds_num = 0;
 
-chr->filename = g_malloc(256);
+chr->filename = g_malloc(CHR_MAX_FILENAME_SIZE);
 switch (ss.ss_family) {
 #ifndef _WIN32
 case AF_UNIX:
 s->is_unix = 1;
-snprintf(chr->filename, 256, "unix:%s%s",
+snprintf(chr->filename, CHR_MAX_FILENAME_SIZE, "unix:%s%s",
  ((struct sockaddr_un *)(&ss))->sun_path,
  is_listen ? ",server" : "");
 break;
@@ -2936,7 +2938,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 s->do_nodelay = do_nodelay;
 getnameinfo((struct sockaddr *) &ss, ss_len, host, sizeof(host),
 serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV);
-snprintf(chr->filename, 256, "%s:%s%s%s:%s%s",
+snprintf(chr->filename, CHR_MAX_FILENAME_SIZE, "%s:%s%s%s:%s%s",
  is_telnet ? "telnet" : "tcp",
  left, host, right, serv,
  is_listen ? ",server" : "");
-- 
1.8.3.1





[Qemu-devel] [PULL 03/28] qemu-char: Move some items into TCPCharDriver

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

This keeps them from having to be passed around and makes them
available for later functions, like printing and reconnecting.

Signed-off-by: Corey Minyard 
Reviewed-by: Paolo Bonzini 
Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 65 -
 1 file changed, 51 insertions(+), 14 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index dcfeb73..a671d6b 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -28,6 +28,9 @@
 #include "sysemu/char.h"
 #include "hw/usb.h"
 #include "qmp-commands.h"
+#include "qapi/qmp-input-visitor.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi-visit.h"
 
 #include 
 #include 
@@ -87,6 +90,34 @@
 #define CHR_MAX_FILENAME_SIZE 256
 
 /***/
+/* Socket address helpers */
+static void qapi_copy_SocketAddress(SocketAddress **p_dest,
+SocketAddress *src)
+{
+QmpOutputVisitor *qov;
+QmpInputVisitor *qiv;
+Visitor *ov, *iv;
+QObject *obj;
+
+*p_dest = NULL;
+
+qov = qmp_output_visitor_new();
+ov = qmp_output_get_visitor(qov);
+visit_type_SocketAddress(ov, &src, NULL, &error_abort);
+obj = qmp_output_get_qobject(qov);
+qmp_output_visitor_cleanup(qov);
+if (!obj) {
+return;
+}
+
+qiv = qmp_input_visitor_new(obj);
+iv = qmp_input_get_visitor(qiv);
+visit_type_SocketAddress(iv, p_dest, NULL, &error_abort);
+qmp_input_visitor_cleanup(qiv);
+qobject_decref(obj);
+}
+
+/***/
 /* character device */
 
 static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
@@ -2412,6 +2443,10 @@ typedef struct {
 int read_msgfds_num;
 int *write_msgfds;
 int write_msgfds_num;
+
+SocketAddress *addr;
+bool is_listen;
+bool is_telnet;
 } TCPCharDriver;
 
 static gboolean tcp_chr_accept(GIOChannel *chan, GIOCondition cond, void 
*opaque);
@@ -2861,6 +2896,8 @@ static void tcp_chr_close(CharDriverState *chr)
 {
 TCPCharDriver *s = chr->opaque;
 int i;
+
+qapi_free_SocketAddress(s->addr);
 if (s->fd >= 0) {
 remove_fd_in_watch(chr);
 if (s->chan) {
@@ -2892,7 +2929,6 @@ static void tcp_chr_close(CharDriverState *chr)
 }
 
 static bool qemu_chr_finish_socket_connection(CharDriverState *chr, int fd,
-  bool is_listen, bool is_telnet,
   Error **errp)
 {
 TCPCharDriver *s = chr->opaque;
@@ -2913,7 +2949,7 @@ static bool 
qemu_chr_finish_socket_connection(CharDriverState *chr, int fd,
 case AF_UNIX:
 snprintf(chr->filename, CHR_MAX_FILENAME_SIZE, "unix:%s%s",
  ((struct sockaddr_un *)(&ss))->sun_path,
- is_listen ? ",server" : "");
+ s->is_listen ? ",server" : "");
 break;
 #endif
 case AF_INET6:
@@ -2924,13 +2960,13 @@ static bool 
qemu_chr_finish_socket_connection(CharDriverState *chr, int fd,
 getnameinfo((struct sockaddr *) &ss, ss_len, host, sizeof(host),
 serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV);
 snprintf(chr->filename, CHR_MAX_FILENAME_SIZE, "%s:%s%s%s:%s%s",
- is_telnet ? "telnet" : "tcp",
+ s->is_telnet ? "telnet" : "tcp",
  left, host, right, serv,
- is_listen ? ",server" : "");
+ s->is_listen ? ",server" : "");
 break;
 }
 
-if (is_listen) {
+if (s->is_listen) {
 s->listen_fd = fd;
 s->listen_chan = io_channel_from_socket(s->listen_fd);
 s->listen_tag = g_io_add_watch(s->listen_chan, G_IO_IN,
@@ -2946,23 +2982,21 @@ static bool 
qemu_chr_finish_socket_connection(CharDriverState *chr, int fd,
 return true;
 }
 
-static bool qemu_chr_open_socket_fd(CharDriverState *chr, SocketAddress *addr,
-bool is_listen, bool is_telnet,
-Error **errp)
+static bool qemu_chr_open_socket_fd(CharDriverState *chr, Error **errp)
 {
+TCPCharDriver *s = chr->opaque;
 int fd;
 
-if (is_listen) {
-fd = socket_listen(addr, errp);
+if (s->is_listen) {
+fd = socket_listen(s->addr, errp);
 } else  {
-fd = socket_connect(addr, errp, NULL, NULL);
+fd = socket_connect(s->addr, errp, NULL, NULL);
 }
 if (fd < 0) {
 return false;
 }
 
-return qemu_chr_finish_socket_connection(chr, fd, is_listen, is_telnet,
- errp);
+return qemu_chr_finish_socket_connection(chr, fd, errp);
 }
 
 /*/
@@ -3967,7 +4001,10 @@ static CharDriverState 
*qmp_chardev_open_socket(ChardevSocket *sock,
 s->fd = -1;
 s->listen_fd = -1;
 s->is_unix = addr->kind == SOCKET_ADDRESS_KIND_UNIX;
+s->is_listen = is_l

[Qemu-devel] [PULL 02/28] qemu-char: Rework qemu_chr_open_socket() for reconnect

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

Move all socket configuration to qmp_chardev_open_socket().
qemu_chr_open_socket_fd() just opens the socket.  This is getting ready
for the reconnect code, which will call open_sock_fd() on a reconnect
attempt.

Signed-off-by: Corey Minyard 
Reviewed-by: Paolo Bonzini 
Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 118 ++--
 1 file changed, 68 insertions(+), 50 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index f9d2a02..dcfeb73 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2891,13 +2891,11 @@ static void tcp_chr_close(CharDriverState *chr)
 qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
 }
 
-static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,
-bool is_listen, bool is_telnet,
-bool is_waitconnect,
-Error **errp)
+static bool qemu_chr_finish_socket_connection(CharDriverState *chr, int fd,
+  bool is_listen, bool is_telnet,
+  Error **errp)
 {
-CharDriverState *chr = NULL;
-TCPCharDriver *s = NULL;
+TCPCharDriver *s = chr->opaque;
 char host[NI_MAXHOST], serv[NI_MAXSERV];
 const char *left = "", *right = "";
 struct sockaddr_storage ss;
@@ -2905,26 +2903,14 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 
 memset(&ss, 0, ss_len);
 if (getsockname(fd, (struct sockaddr *) &ss, &ss_len) != 0) {
+closesocket(fd);
 error_setg_errno(errp, errno, "getsockname");
-return NULL;
+return false;
 }
 
-chr = qemu_chr_alloc();
-s = g_malloc0(sizeof(TCPCharDriver));
-
-s->connected = 0;
-s->fd = -1;
-s->listen_fd = -1;
-s->read_msgfds = 0;
-s->read_msgfds_num = 0;
-s->write_msgfds = 0;
-s->write_msgfds_num = 0;
-
-chr->filename = g_malloc(CHR_MAX_FILENAME_SIZE);
 switch (ss.ss_family) {
 #ifndef _WIN32
 case AF_UNIX:
-s->is_unix = 1;
 snprintf(chr->filename, CHR_MAX_FILENAME_SIZE, "unix:%s%s",
  ((struct sockaddr_un *)(&ss))->sun_path,
  is_listen ? ",server" : "");
@@ -2935,7 +2921,6 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 right = "]";
 /* fall through */
 case AF_INET:
-s->do_nodelay = do_nodelay;
 getnameinfo((struct sockaddr *) &ss, ss_len, host, sizeof(host),
 serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV);
 snprintf(chr->filename, CHR_MAX_FILENAME_SIZE, "%s:%s%s%s:%s%s",
@@ -2945,25 +2930,11 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 break;
 }
 
-chr->opaque = s;
-chr->chr_write = tcp_chr_write;
-chr->chr_sync_read = tcp_chr_sync_read;
-chr->chr_close = tcp_chr_close;
-chr->get_msgfds = tcp_get_msgfds;
-chr->set_msgfds = tcp_set_msgfds;
-chr->chr_add_client = tcp_chr_add_client;
-chr->chr_add_watch = tcp_chr_add_watch;
-chr->chr_update_read_handler = tcp_chr_update_read_handler;
-/* be isn't opened until we get a connection */
-chr->explicit_be_open = true;
-
 if (is_listen) {
 s->listen_fd = fd;
 s->listen_chan = io_channel_from_socket(s->listen_fd);
-s->listen_tag = g_io_add_watch(s->listen_chan, G_IO_IN, 
tcp_chr_accept, chr);
-if (is_telnet) {
-s->do_telnetopt = 1;
-}
+s->listen_tag = g_io_add_watch(s->listen_chan, G_IO_IN,
+   tcp_chr_accept, chr);
 } else {
 s->connected = 1;
 s->fd = fd;
@@ -2972,13 +2943,26 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 tcp_chr_connect(chr);
 }
 
-if (is_listen && is_waitconnect) {
-fprintf(stderr, "QEMU waiting for connection on: %s\n",
-chr->filename);
-tcp_chr_accept(s->listen_chan, G_IO_IN, chr);
-qemu_set_nonblock(s->listen_fd);
+return true;
+}
+
+static bool qemu_chr_open_socket_fd(CharDriverState *chr, SocketAddress *addr,
+bool is_listen, bool is_telnet,
+Error **errp)
+{
+int fd;
+
+if (is_listen) {
+fd = socket_listen(addr, errp);
+} else  {
+fd = socket_connect(addr, errp, NULL, NULL);
 }
-return chr;
+if (fd < 0) {
+return false;
+}
+
+return qemu_chr_finish_socket_connection(chr, fd, is_listen, is_telnet,
+ errp);
 }
 
 /*/
@@ -3969,23 +3953,57 @@ static CharDriverState 
*qmp_chardev_open_parallel(ChardevHostdev *parallel,
 static CharDriverState *qmp_chardev_open_socket(ChardevSocket *sock,

Re: [Qemu-devel] [PATCH v3] pc-dimm/numa: Fix stat of memory size in node when hotplug memory

2014-10-09 Thread zhanghailiang

On 2014/10/8 20:16, Igor Mammedov wrote:

On Wed, 8 Oct 2014 16:36:25 +0800
zhanghailiang  wrote:


On 2014/10/8 15:28, zhanghailiang wrote:

Hi Igor,

On 2014/9/26 19:53, Igor Mammedov wrote:

On Tue, 23 Sep 2014 16:11:25 +0800
zhanghailiang  wrote:


When do memory hotplug, if there is numa node, we should add
the memory size to the corresponding node memory size.

For now, it mainly affects the result of hmp command "info numa".

Signed-off-by: zhanghailiang 

please make sure that this doesn't breaks other targets.

PS:
to make test builds you can use travis-ci.org+github service



Sorry for the delayed response.;)

I have test the build as you suggested, and yes, it will break other targets.

The main reason here is, there is a compile switch for
memory hotplug (CONFIG_MEM_HOTPLUG), which is off for other targets, and
pc-dimm.c is not include when compile.

Here i also use the compile switch to fix this problem, and will send V4.



): Actually this macro (CONFIG_MEM_HOTPLUG) can't be automatically generated
like CONFIG_KVM in config-target.h, so i can't use this compile macro.

What's your suggestion? Thanks!

typically we add stab function in such cases.
However looking at pc_dimm_stat_node_mem() it does nothing that requires
access to PCDIMMDevice, i.e. size and node could be accessed as properties
of Device/Object.

I'd suggest to generalize pc_dimm_stat_node_mem() so it could in future
handle other types of memory devices and place it in numa.c, but for now
looking only for TYPE_PC_DIMM devices.

PS:
s/pc_dimm_stat_node_mem/numa_stat_memory_devices/



OK, I will modify it as you suggested, Thanks.




---
   v3:
- cold-plugged memory should not be excluded when stat memory size (Igor 
Mammedov)
   v2:
- Don't modify the numa_info.node_mem directly when treating hotplug memory,
fix the "info numa" instead (suggested by Igor Mammedov)
---
   hw/mem/pc-dimm.c | 30 ++
   include/hw/mem/pc-dimm.h |  2 ++
   include/sysemu/sysemu.h  |  1 +
   monitor.c|  6 +-
   numa.c   | 15 +++
   5 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 5bfc5b7..8e80d74 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -195,6 +195,36 @@ out:
   return ret;
   }

+static int pc_dimm_stat_mem_size(Object *obj, void *opaque)
+{
+uint64_t *node_mem = opaque;
+int ret;
+
+if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+DeviceState *dev = DEVICE(obj);
+
+if (dev->realized) {
+PCDIMMDevice *dimm = PC_DIMM(obj);
+int size;
+
+size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
+   NULL);
+if (size < 0) {
+return -1;
+}
+node_mem[dimm->node] += size;
+}
+}
+
+ret = object_child_foreach(obj, pc_dimm_stat_mem_size, opaque);
+return ret;
+}
+
+void pc_dimm_stat_node_mem(uint64_t *node_mem)
+{
+object_child_foreach(qdev_get_machine(), pc_dimm_stat_mem_size, node_mem);
+}
+
   static Property pc_dimm_properties[] = {
   DEFINE_PROP_UINT64(PC_DIMM_ADDR_PROP, PCDIMMDevice, addr, 0),
   DEFINE_PROP_UINT32(PC_DIMM_NODE_PROP, PCDIMMDevice, node, 0),
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 761eeef..0c9a8eb 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -78,4 +78,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
   int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);

   int qmp_pc_dimm_device_list(Object *obj, void *opaque);
+
+void pc_dimm_stat_node_mem(uint64_t *node_mem);
   #endif
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..cfc1592 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -160,6 +160,7 @@ typedef struct node_info {
   extern NodeInfo numa_info[MAX_NODES];
   void set_numa_nodes(void);
   void set_numa_modes(void);
+int query_numa_node_mem(uint64_t *node_mem);
   extern QemuOptsList qemu_numa_opts;
   int numa_init_func(QemuOpts *opts, void *opaque);

diff --git a/monitor.c b/monitor.c
index 7467521..c8c812f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1948,7 +1948,10 @@ static void do_info_numa(Monitor *mon, const QDict 
*qdict)
   {
   int i;
   CPUState *cpu;
+uint64_t *node_mem;

+node_mem = g_new0(uint64_t, nb_numa_nodes);
+query_numa_node_mem(node_mem);
   monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
   for (i = 0; i < nb_numa_nodes; i++) {
   monitor_printf(mon, "node %d cpus:", i);
@@ -1959,8 +1962,9 @@ static void do_info_numa(Monitor *mon, const QDict *qdict)
   }
   monitor_printf(mon, "\n");
   monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
-numa_info[i].node_mem >> 20);
+node_mem[i] >> 20);
   }
+g_free(node_mem);
   }

   #

[Qemu-devel] [PULL 06/28] qemu-char: Print the remote and local addresses for a socket

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

It seems that it might be a good idea to know what is at the remote
end of a socket for tracking down issues.  So add that to the
socket filename.

Signed-off-by: Corey Minyard 
Reviewed-by: Paolo Bonzini 
Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 27 ++-
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index aa15bd3..62af0ef 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -142,9 +142,11 @@ static int SocketAddress_to_str(char *dest, int max_len,
 
 static int sockaddr_to_str(char *dest, int max_len,
struct sockaddr_storage *ss, socklen_t ss_len,
+   struct sockaddr_storage *ps, socklen_t ps_len,
bool is_listen, bool is_telnet)
 {
-char host[NI_MAXHOST], serv[NI_MAXSERV];
+char shost[NI_MAXHOST], sserv[NI_MAXSERV];
+char phost[NI_MAXHOST], pserv[NI_MAXSERV];
 const char *left = "", *right = "";
 
 switch (ss->ss_family) {
@@ -159,12 +161,15 @@ static int sockaddr_to_str(char *dest, int max_len,
 right = "]";
 /* fall through */
 case AF_INET:
-getnameinfo((struct sockaddr *) ss, ss_len, host, sizeof(host),
-serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV);
-return snprintf(dest, max_len, "%s:%s%s%s:%s%s",
+getnameinfo((struct sockaddr *) ss, ss_len, shost, sizeof(shost),
+sserv, sizeof(sserv), NI_NUMERICHOST | NI_NUMERICSERV);
+getnameinfo((struct sockaddr *) ps, ps_len, phost, sizeof(phost),
+pserv, sizeof(pserv), NI_NUMERICHOST | NI_NUMERICSERV);
+return snprintf(dest, max_len, "%s:%s%s%s:%s%s <-> %s%s%s:%s",
 is_telnet ? "telnet" : "tcp",
-left, host, right, serv,
-is_listen ? ",server" : "");
+left, shost, right, sserv,
+is_listen ? ",server" : "",
+left, phost, right, pserv);
 
 default:
 return snprintf(dest, max_len, "unknown");
@@ -2870,15 +2875,19 @@ static void tcp_chr_connect(void *opaque)
 {
 CharDriverState *chr = opaque;
 TCPCharDriver *s = chr->opaque;
-struct sockaddr_storage ss;
-socklen_t ss_len = sizeof(ss);
+struct sockaddr_storage ss, ps;
+socklen_t ss_len = sizeof(ss), ps_len = sizeof(ps);
 
 memset(&ss, 0, ss_len);
 if (getsockname(s->fd, (struct sockaddr *) &ss, &ss_len) != 0) {
 snprintf(chr->filename, CHR_MAX_FILENAME_SIZE,
  "Error in getsockname: %s\n", strerror(errno));
+} else if (getpeername(s->fd, (struct sockaddr *) &ps, &ps_len) != 0) {
+snprintf(chr->filename, CHR_MAX_FILENAME_SIZE,
+ "Error in getpeername: %s\n", strerror(errno));
 } else {
-sockaddr_to_str(chr->filename, CHR_MAX_FILENAME_SIZE, &ss, ss_len,
+sockaddr_to_str(chr->filename, CHR_MAX_FILENAME_SIZE,
+&ss, ss_len, &ps, ps_len,
 s->is_listen, s->is_telnet);
 }
 
-- 
1.8.3.1





[Qemu-devel] [PULL 05/28] qemu-char: Add reconnecting to client sockets

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

Adds a "reconnect" option to socket backends that gives a reconnect
timeout.  This only applies to client sockets.  If the other end
of a socket closes the connection, qemu will attempt to reconnect
after the given number of seconds.

Signed-off-by: Corey Minyard 
Signed-off-by: Paolo Bonzini 
---
 qapi-schema.json | 15 +++
 qemu-char.c  | 78 
 qemu-options.hx  | 20 ++-
 3 files changed, 96 insertions(+), 17 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 4bfaf20..148097b 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2651,14 +2651,19 @@
 # @nodelay: #optional set TCP_NODELAY socket option (default: false)
 # @telnet: #optional enable telnet protocol on server
 #  sockets (default: false)
+# @reconnect: #optional For a client socket, if a socket is disconnected,
+#  then attempt a reconnect after the given number of seconds.
+#  Setting this to zero disables this function. (default: 0)
+#  (Since: 2.2)
 #
 # Since: 1.4
 ##
-{ 'type': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress',
- '*server'  : 'bool',
- '*wait': 'bool',
- '*nodelay' : 'bool',
- '*telnet'  : 'bool' } }
+{ 'type': 'ChardevSocket', 'data': { 'addr'   : 'SocketAddress',
+ '*server': 'bool',
+ '*wait'  : 'bool',
+ '*nodelay'   : 'bool',
+ '*telnet': 'bool',
+ '*reconnect' : 'int' } }
 
 ##
 # @ChardevUdp:
diff --git a/qemu-char.c b/qemu-char.c
index 549ebd8..aa15bd3 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2501,8 +2501,21 @@ typedef struct {
 SocketAddress *addr;
 bool is_listen;
 bool is_telnet;
+
+guint reconnect_timer;
+int64_t reconnect_time;
 } TCPCharDriver;
 
+static gboolean socket_reconnect_timeout(gpointer opaque);
+
+static void qemu_chr_socket_restart_timer(CharDriverState *chr)
+{
+TCPCharDriver *s = chr->opaque;
+assert(s->connected == 0);
+s->reconnect_timer = g_timeout_add_seconds(s->reconnect_time,
+   socket_reconnect_timeout, chr);
+}
+
 static gboolean tcp_chr_accept(GIOChannel *chan, GIOCondition cond, void 
*opaque);
 
 #ifndef _WIN32
@@ -2784,6 +2797,9 @@ static void tcp_chr_disconnect(CharDriverState *chr)
 SocketAddress_to_str(chr->filename, CHR_MAX_FILENAME_SIZE,
  "disconnected:", s->addr, s->is_listen, s->is_telnet);
 qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
+if (s->reconnect_time) {
+qemu_chr_socket_restart_timer(chr);
+}
 }
 
 static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)
@@ -2964,6 +2980,10 @@ static void tcp_chr_close(CharDriverState *chr)
 TCPCharDriver *s = chr->opaque;
 int i;
 
+if (s->reconnect_timer) {
+g_source_remove(s->reconnect_timer);
+s->reconnect_timer = 0;
+}
 qapi_free_SocketAddress(s->addr);
 if (s->fd >= 0) {
 remove_fd_in_watch(chr);
@@ -3013,6 +3033,18 @@ static void 
qemu_chr_finish_socket_connection(CharDriverState *chr, int fd)
 }
 }
 
+static void qemu_chr_socket_connected(int fd, void *opaque)
+{
+CharDriverState *chr = opaque;
+
+if (fd < 0) {
+qemu_chr_socket_restart_timer(chr);
+return;
+}
+
+qemu_chr_finish_socket_connection(chr, fd);
+}
+
 static bool qemu_chr_open_socket_fd(CharDriverState *chr, Error **errp)
 {
 TCPCharDriver *s = chr->opaque;
@@ -3020,7 +3052,10 @@ static bool qemu_chr_open_socket_fd(CharDriverState 
*chr, Error **errp)
 
 if (s->is_listen) {
 fd = socket_listen(s->addr, errp);
-} else  {
+} else if (s->reconnect_time) {
+fd = socket_connect(s->addr, errp, qemu_chr_socket_connected, chr);
+return fd >= 0;
+} else {
 fd = socket_connect(s->addr, errp, NULL, NULL);
 }
 if (fd < 0) {
@@ -3448,6 +3483,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, 
ChardevBackend *backend,
 bool is_waitconnect = is_listen && qemu_opt_get_bool(opts, "wait", true);
 bool is_telnet  = qemu_opt_get_bool(opts, "telnet", false);
 bool do_nodelay = !qemu_opt_get_bool(opts, "delay", true);
+int64_t reconnect   = qemu_opt_get_number(opts, "reconnect", 0);
 const char *path = qemu_opt_get(opts, "path");
 const char *host = qemu_opt_get(opts, "host");
 const char *port = qemu_opt_get(opts, "port");
@@ -3474,6 +3510,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, 
ChardevBackend *backend,
 backend->socket->telnet = is_telnet;
 backend->socket->has_wait = true;
 backend->socket->wait = is_waitconnect;
+backend->socket->

Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and take effect after rebooting

2014-10-09 Thread Gonglei
On 2014/10/9 17:47, Gerd Hoffmann wrote:

> On Mi, 2014-10-08 at 19:00 +0800, Gonglei wrote:
>> On 2014/10/7 16:00, Gonglei (Arei) wrote:
>>
>>> From: Gonglei 
>>>
>>> Changes since v10:
>>>  1. add handler for virtio-blk-pci/s390/ccw in PATCH 28.
>>>  2. add especial bootidnex setter/getter functions for usb-storage
>>> device in PATCH 29.
>>>  3. add bootindex qom property for nvma and ne2k_isa devices,
>>> avoid regrassion in PATCH 30.
>>>  4. change fprintf to error_report in bootdevice.c in PATCH 34.
>>>  5. rebase on the latest qemu master tree.
>>>  6. add 'Reviewed-by' in other patches. (Thanks, Gerd)
>>>
>>
>>
>> Hi, Gerd
>>
>> Could you please review the v11 and consider to merge this series in your 
>> tree?
>> I have no idea which maintainer can apply this series. It seems that only you
>> and Eduardo  interested in and reviewed this patch series at present. :(
> 
> Yea, for these cross-tree changes it isn't always clear which way they
> should be merged.  qom or pc would make sense I think.
> 
> I can prepare a pull request too, but I'd like to have a second opinion
> on the stuff which is outside of my primary focus:
> 

Thanks a lot!

>   * fw_cfg changes (mst?  paolo?)
>   * qom bits (andreas?  paolo?, eduardo?)
> 

I will appreciate for your review, guys :)

Best regards,
-Gonglei

> I'll go take "no answer" as "no objections", but I'd prefer to apply one
> or another "reviewed-by" to the series.
> 
> thanks,
>   Gerd
> 
> 







[Qemu-devel] [PULL 19/28] accel: Move accel init/allowed code to separate function

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/accel.c b/accel.c
index 0f3fcee..9241967 100644
--- a/accel.c
+++ b/accel.c
@@ -57,6 +57,17 @@ static AccelClass *accel_find(const char *opt_name)
 return ac;
 }
 
+static int accel_init(AccelClass *acc, MachineClass *mc)
+{
+int ret;
+*(acc->allowed) = true;
+ret = acc->init(mc);
+if (ret < 0) {
+*(acc->allowed) = false;
+}
+return ret;
+}
+
 int configure_accelerator(MachineClass *mc)
 {
 const char *p;
@@ -87,14 +98,12 @@ int configure_accelerator(MachineClass *mc)
acc->name);
 continue;
 }
-*(acc->allowed) = true;
-ret = acc->init(mc);
+ret = accel_init(acc, mc);
 if (ret < 0) {
 init_failed = true;
 fprintf(stderr, "failed to initialize %s: %s\n",
 acc->name,
 strerror(-ret));
-*(acc->allowed) = false;
 } else {
 accel_initialised = true;
 }
-- 
1.8.3.1





[Qemu-devel] [PULL 18/28] accel: Remove tcg_available() function

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

As the function always return 1, it is not needed anymore.

Signed-off-by: Eduardo Habkost 
Reviewed-by: Paolo Bonzini 
Signed-off-by: Paolo Bonzini 
---
 accel.c| 1 -
 arch_init.c| 5 -
 include/sysemu/arch_init.h | 1 -
 3 files changed, 7 deletions(-)

diff --git a/accel.c b/accel.c
index 2cf47337..0f3fcee 100644
--- a/accel.c
+++ b/accel.c
@@ -119,7 +119,6 @@ static void tcg_accel_class_init(ObjectClass *oc, void 
*data)
 {
 AccelClass *ac = ACCEL_CLASS(oc);
 ac->name = "tcg";
-ac->available = tcg_available;
 ac->init = tcg_init;
 ac->allowed = &tcg_allowed;
 }
diff --git a/arch_init.c b/arch_init.c
index c974f3f..9b3e25d 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1337,11 +1337,6 @@ void cpudef_init(void)
 #endif
 }
 
-int tcg_available(void)
-{
-return 1;
-}
-
 int kvm_available(void)
 {
 #ifdef CONFIG_KVM
diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 769ec06..54b36c1 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -33,7 +33,6 @@ void do_smbios_option(QemuOpts *opts);
 void ram_mig_init(void);
 void cpudef_init(void);
 void audio_init(void);
-int tcg_available(void);
 int kvm_available(void);
 int xen_available(void);
 
-- 
1.8.3.1





[Qemu-devel] [PULL 17/28] accel: Move qtest accel registration to qtest.c

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

As qtest_availble() returns 1 only when CONFIG_POSIX is set, keep
setting AccelClass.available to keep current behavior (this is different
from what we did for KVM and Xen).

This also allows us to make qtest_init_accel() static.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c| 18 --
 include/sysemu/qtest.h |  1 -
 qtest.c| 27 ++-
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/accel.c b/accel.c
index 2cefbb0..2cf47337 100644
--- a/accel.c
+++ b/accel.c
@@ -132,28 +132,10 @@ static const TypeInfo tcg_accel_type = {
 .class_init = tcg_accel_class_init,
 };
 
-static void qtest_accel_class_init(ObjectClass *oc, void *data)
-{
-AccelClass *ac = ACCEL_CLASS(oc);
-ac->name = "QTest";
-ac->available = qtest_available;
-ac->init = qtest_init_accel;
-ac->allowed = &qtest_allowed;
-}
-
-#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
-
-static const TypeInfo qtest_accel_type = {
-.name = TYPE_QTEST_ACCEL,
-.parent = TYPE_ACCEL,
-.class_init = qtest_accel_class_init,
-};
-
 static void register_accel_types(void)
 {
 type_register_static(&accel_type);
 type_register_static(&tcg_accel_type);
-type_register_static(&qtest_accel_type);
 }
 
 type_init(register_accel_types);
diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h
index 95c9ade..05473b7 100644
--- a/include/sysemu/qtest.h
+++ b/include/sysemu/qtest.h
@@ -26,7 +26,6 @@ static inline bool qtest_enabled(void)
 
 bool qtest_driver(void);
 
-int qtest_init_accel(MachineClass *mc);
 void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
 
 static inline int qtest_available(void)
diff --git a/qtest.c b/qtest.c
index ef0d991..0af8b74 100644
--- a/qtest.c
+++ b/qtest.c
@@ -17,6 +17,7 @@
 #include "exec/ioport.h"
 #include "exec/memory.h"
 #include "hw/irq.h"
+#include "sysemu/accel.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/cpus.h"
 #include "qemu/config-file.h"
@@ -519,7 +520,7 @@ static void configure_qtest_icount(const char *options)
 qemu_opts_del(opts);
 }
 
-int qtest_init_accel(MachineClass *mc)
+static int qtest_init_accel(MachineClass *mc)
 {
 configure_qtest_icount("0");
 return 0;
@@ -557,3 +558,27 @@ bool qtest_driver(void)
 {
 return qtest_chr;
 }
+
+static void qtest_accel_class_init(ObjectClass *oc, void *data)
+{
+AccelClass *ac = ACCEL_CLASS(oc);
+ac->name = "QTest";
+ac->available = qtest_available;
+ac->init = qtest_init_accel;
+ac->allowed = &qtest_allowed;
+}
+
+#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
+
+static const TypeInfo qtest_accel_type = {
+.name = TYPE_QTEST_ACCEL,
+.parent = TYPE_ACCEL,
+.class_init = qtest_accel_class_init,
+};
+
+static void qtest_type_init(void)
+{
+type_register_static(&qtest_accel_type);
+}
+
+type_init(qtest_type_init);
-- 
1.8.3.1





[Qemu-devel] [PULL 27/28] qemu-sockets: Add error to non-blocking connect handler

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

An error value here would be quite handy and more consistent
with the rest of the code.

Signed-off-by: Corey Minyard 
[Make sure SO_ERROR value is passed to error_setg_errno. - Paolo]
Signed-off-by: Paolo Bonzini 
---
 include/qemu/sockets.h |  2 +-
 migration-tcp.c|  4 ++--
 migration-unix.c   |  4 ++--
 qemu-char.c|  7 +--
 util/qemu-sockets.c| 20 +++-
 5 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index fdbb196..f47dae6 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -47,7 +47,7 @@ int recv_all(int fd, void *buf, int len1, bool single_read);
 /* callback function for nonblocking connect
  * valid fd on success, negative error code on failure
  */
-typedef void NonBlockingConnectHandler(int fd, void *opaque);
+typedef void NonBlockingConnectHandler(int fd, Error *errp, void *opaque);
 
 InetSocketAddress *inet_parse(const char *str, Error **errp);
 int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
diff --git a/migration-tcp.c b/migration-tcp.c
index 2e34517..91c9cf3 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -33,12 +33,12 @@
 do { } while (0)
 #endif
 
-static void tcp_wait_for_connect(int fd, void *opaque)
+static void tcp_wait_for_connect(int fd, Error *err, void *opaque)
 {
 MigrationState *s = opaque;
 
 if (fd < 0) {
-DPRINTF("migrate connect error\n");
+DPRINTF("migrate connect error: %s\n", error_get_pretty(err));
 s->file = NULL;
 migrate_fd_error(s);
 } else {
diff --git a/migration-unix.c b/migration-unix.c
index 0a5f8a1..1cdadfb 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -33,12 +33,12 @@
 do { } while (0)
 #endif
 
-static void unix_wait_for_connect(int fd, void *opaque)
+static void unix_wait_for_connect(int fd, Error *err, void *opaque)
 {
 MigrationState *s = opaque;
 
 if (fd < 0) {
-DPRINTF("migrate connect error\n");
+DPRINTF("migrate connect error: %s\n", error_get_pretty(err));
 s->file = NULL;
 migrate_fd_error(s);
 } else {
diff --git a/qemu-char.c b/qemu-char.c
index 62af0ef..c71805a 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3042,11 +3042,13 @@ static void 
qemu_chr_finish_socket_connection(CharDriverState *chr, int fd)
 }
 }
 
-static void qemu_chr_socket_connected(int fd, void *opaque)
+static void qemu_chr_socket_connected(int fd, Error *err, void *opaque)
 {
 CharDriverState *chr = opaque;
 
 if (fd < 0) {
+error_report("Unable to connect to char device %s: %s",
+ chr->label, error_get_pretty(err));
 qemu_chr_socket_restart_timer(chr);
 return;
 }
@@ -4079,7 +4081,8 @@ static gboolean socket_reconnect_timeout(gpointer opaque)
 }
 
 if (!qemu_chr_open_socket_fd(chr, &err)) {
-error_report("Unable to connect to char device %s\n", chr->label);
+error_report("Unable to connect to char device %s: %s\n",
+ chr->label, error_get_pretty(err));
 qemu_chr_socket_restart_timer(chr);
 }
 
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 1eef590..a76bb3c 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -234,6 +234,7 @@ static void wait_for_connect(void *opaque)
 int val = 0, rc = 0;
 socklen_t valsize = sizeof(val);
 bool in_progress;
+Error *err = NULL;
 
 qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
@@ -244,10 +245,12 @@ static void wait_for_connect(void *opaque)
 /* update rc to contain error */
 if (!rc && val) {
 rc = -1;
+errno = val;
 }
 
 /* connect error */
 if (rc < 0) {
+error_setg_errno(&err, errno, "Error connecting to socket");
 closesocket(s->fd);
 s->fd = rc;
 }
@@ -257,9 +260,14 @@ static void wait_for_connect(void *opaque)
 while (s->current_addr->ai_next != NULL && s->fd < 0) {
 s->current_addr = s->current_addr->ai_next;
 s->fd = inet_connect_addr(s->current_addr, &in_progress, s, NULL);
+if (s->fd < 0) {
+error_free(err);
+err = NULL;
+error_setg_errno(&err, errno, "Unable to start socket 
connect");
+}
 /* connect in progress */
 if (in_progress) {
-return;
+goto out;
 }
 }
 
@@ -267,9 +275,11 @@ static void wait_for_connect(void *opaque)
 }
 
 if (s->callback) {
-s->callback(s->fd, s->opaque);
+s->callback(s->fd, err, s->opaque);
 }
 g_free(s);
+out:
+error_free(err);
 }
 
 static int inet_connect_addr(struct addrinfo *addr, bool *in_progress,
@@ -401,7 +411,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp,
 return sock;
 } else {
 if (callback) {
-callback(sock, opaque);
+callbac

[Qemu-devel] [PULL 22/28] accel: Create accel object when initializing machine

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Create an actual TYPE_ACCEL object when initializing a machine. This
will allow accelerator classes to implement some initialization on
instance_init, and to save state on the TYPE_ACCEL object.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 7 +++
 include/hw/boards.h | 1 +
 include/qemu/typedefs.h | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/accel.c b/accel.c
index 6087ab3..74e41da 100644
--- a/accel.c
+++ b/accel.c
@@ -32,6 +32,7 @@
 #include "sysemu/qtest.h"
 #include "hw/xen/xen.h"
 #include "qom/object.h"
+#include "hw/boards.h"
 
 int tcg_tb_size;
 static bool tcg_allowed = true;
@@ -60,11 +61,17 @@ static AccelClass *accel_find(const char *opt_name)
 
 static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
+ObjectClass *oc = OBJECT_CLASS(acc);
+const char *cname = object_class_get_name(oc);
+AccelState *accel = ACCEL(object_new(cname));
 int ret;
+ms->accelerator = accel;
 *(acc->allowed) = true;
 ret = acc->init_machine(ms);
 if (ret < 0) {
+ms->accelerator = NULL;
 *(acc->allowed) = false;
+object_unref(OBJECT(accel));
 }
 return ret;
 }
diff --git a/include/hw/boards.h b/include/hw/boards.h
index dfb6718..8f0eeaf 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -133,6 +133,7 @@ struct MachineState {
 char *kernel_cmdline;
 char *initrd_filename;
 const char *cpu_model;
+AccelState *accelerator;
 };
 
 #endif
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 04df51b..446af93 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -30,6 +30,8 @@ typedef struct MemoryListener MemoryListener;
 
 typedef struct MemoryMappingList MemoryMappingList;
 
+typedef struct AccelState AccelState;
+
 typedef struct QEMUMachine QEMUMachine;
 typedef struct MachineClass MachineClass;
 typedef struct MachineState MachineState;
-- 
1.8.3.1





[Qemu-devel] [PULL 21/28] accel: Pass MachineState object to accel init functions

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Most of the machine options and machine state information is in the
MachineState object, not on the MachineClass. This will allow init
functions to use the MachineState object directly instead of
qemu_get_machine_opts() or the current_machine global.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 11 ++-
 include/qemu/typedefs.h |  1 +
 include/sysemu/accel.h  |  4 ++--
 kvm-all.c   |  3 ++-
 qtest.c |  2 +-
 vl.c|  2 +-
 xen-common.c|  2 +-
 7 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/accel.c b/accel.c
index b151d55..6087ab3 100644
--- a/accel.c
+++ b/accel.c
@@ -24,6 +24,7 @@
  */
 
 #include "sysemu/accel.h"
+#include "hw/boards.h"
 #include "qemu-common.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
@@ -35,7 +36,7 @@
 int tcg_tb_size;
 static bool tcg_allowed = true;
 
-static int tcg_init(MachineClass *mc)
+static int tcg_init(MachineState *ms)
 {
 tcg_exec_init(tcg_tb_size * 1024 * 1024);
 return 0;
@@ -57,18 +58,18 @@ static AccelClass *accel_find(const char *opt_name)
 return ac;
 }
 
-static int accel_init_machine(AccelClass *acc, MachineClass *mc)
+static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
 int ret;
 *(acc->allowed) = true;
-ret = acc->init_machine(mc);
+ret = acc->init_machine(ms);
 if (ret < 0) {
 *(acc->allowed) = false;
 }
 return ret;
 }
 
-int configure_accelerator(MachineClass *mc)
+int configure_accelerator(MachineState *ms)
 {
 const char *p;
 char buf[10];
@@ -98,7 +99,7 @@ int configure_accelerator(MachineClass *mc)
acc->name);
 continue;
 }
-ret = accel_init_machine(acc, mc);
+ret = accel_init_machine(acc, ms);
 if (ret < 0) {
 init_failed = true;
 fprintf(stderr, "failed to initialize %s: %s\n",
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 5f20b0e..04df51b 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -32,6 +32,7 @@ typedef struct MemoryMappingList MemoryMappingList;
 
 typedef struct QEMUMachine QEMUMachine;
 typedef struct MachineClass MachineClass;
+typedef struct MachineState MachineState;
 typedef struct NICInfo NICInfo;
 typedef struct HCIInfo HCIInfo;
 typedef struct AudioState AudioState;
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 8812cda..997720f 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -39,7 +39,7 @@ typedef struct AccelClass {
 const char *opt_name;
 const char *name;
 int (*available)(void);
-int (*init_machine)(MachineClass *mc);
+int (*init_machine)(MachineState *ms);
 bool *allowed;
 } AccelClass;
 
@@ -57,6 +57,6 @@ typedef struct AccelClass {
 
 extern int tcg_tb_size;
 
-int configure_accelerator(MachineClass *mc);
+int configure_accelerator(MachineState *ms);
 
 #endif
diff --git a/kvm-all.c b/kvm-all.c
index ce0e4c7..0a9de92 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1380,8 +1380,9 @@ static int kvm_max_vcpus(KVMState *s)
 return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-static int kvm_init(MachineClass *mc)
+static int kvm_init(MachineState *ms)
 {
+MachineClass *mc = MACHINE_GET_CLASS(ms);
 static const char upgrade_note[] =
 "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
 "(see http://sourceforge.net/projects/kvm).\n";
diff --git a/qtest.c b/qtest.c
index 18e26fc..4b85995 100644
--- a/qtest.c
+++ b/qtest.c
@@ -520,7 +520,7 @@ static void configure_qtest_icount(const char *options)
 qemu_opts_del(opts);
 }
 
-static int qtest_init_accel(MachineClass *mc)
+static int qtest_init_accel(MachineState *ms)
 {
 configure_qtest_icount("0");
 return 0;
diff --git a/vl.c b/vl.c
index c3def21..020b7c3 100644
--- a/vl.c
+++ b/vl.c
@@ -4179,7 +4179,7 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
-configure_accelerator(machine_class);
+configure_accelerator(current_machine);
 
 if (qtest_chrdev) {
 Error *local_err = NULL;
diff --git a/xen-common.c b/xen-common.c
index acb738f..56359ca 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -110,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int 
running,
 }
 }
 
-static int xen_init(MachineClass *mc)
+static int xen_init(MachineState *ms)
 {
 xen_xc = xen_xc_interface_open(0, 0, 0);
 if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
-- 
1.8.3.1





[Qemu-devel] [PULL 20/28] accel: Rename 'init' method to 'init_machine'

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Today, all accelerator init functions affect some global state:
* tcg_init() calls tcg_exec_init() and affects globals such as tcg_tcx,
  page size globals, and possibly others;
* kvm_init() changes the kvm_state global, cpu_interrupt_handler, and possibly
  others;
* xen_init() changes the xen_xc global, and registers a change state handler.

With the new accelerator QOM classes, initialization may now be split in two
steps:
* instance_init() will do basic initialization that doesn't affect any global
  state and don't need MachineState or MachineClass data. This will allow
  probing code to safely create multiple accelerator objects on the fly just
  for reporting host/accelerator capabilities, for example.
* accel_init_machine()/init_machine() will save the accelerator object in
  MachineState, and do initialization steps which still affect global state,
  machine state, or that need data from MachineClass or MachineState.

To clarify the difference between those two steps, rename init() to
init_machine().

Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c| 8 
 include/sysemu/accel.h | 2 +-
 kvm-all.c  | 2 +-
 qtest.c| 2 +-
 xen-common.c   | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/accel.c b/accel.c
index 9241967..b151d55 100644
--- a/accel.c
+++ b/accel.c
@@ -57,11 +57,11 @@ static AccelClass *accel_find(const char *opt_name)
 return ac;
 }
 
-static int accel_init(AccelClass *acc, MachineClass *mc)
+static int accel_init_machine(AccelClass *acc, MachineClass *mc)
 {
 int ret;
 *(acc->allowed) = true;
-ret = acc->init(mc);
+ret = acc->init_machine(mc);
 if (ret < 0) {
 *(acc->allowed) = false;
 }
@@ -98,7 +98,7 @@ int configure_accelerator(MachineClass *mc)
acc->name);
 continue;
 }
-ret = accel_init(acc, mc);
+ret = accel_init_machine(acc, mc);
 if (ret < 0) {
 init_failed = true;
 fprintf(stderr, "failed to initialize %s: %s\n",
@@ -128,7 +128,7 @@ static void tcg_accel_class_init(ObjectClass *oc, void 
*data)
 {
 AccelClass *ac = ACCEL_CLASS(oc);
 ac->name = "tcg";
-ac->init = tcg_init;
+ac->init_machine = tcg_init;
 ac->allowed = &tcg_allowed;
 }
 
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 120ca0e..8812cda 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -39,7 +39,7 @@ typedef struct AccelClass {
 const char *opt_name;
 const char *name;
 int (*available)(void);
-int (*init)(MachineClass *mc);
+int (*init_machine)(MachineClass *mc);
 bool *allowed;
 } AccelClass;
 
diff --git a/kvm-all.c b/kvm-all.c
index 18dcd45..ce0e4c7 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -2233,7 +2233,7 @@ static void kvm_accel_class_init(ObjectClass *oc, void 
*data)
 {
 AccelClass *ac = ACCEL_CLASS(oc);
 ac->name = "KVM";
-ac->init = kvm_init;
+ac->init_machine = kvm_init;
 ac->allowed = &kvm_allowed;
 }
 
diff --git a/qtest.c b/qtest.c
index 0af8b74..18e26fc 100644
--- a/qtest.c
+++ b/qtest.c
@@ -564,7 +564,7 @@ static void qtest_accel_class_init(ObjectClass *oc, void 
*data)
 AccelClass *ac = ACCEL_CLASS(oc);
 ac->name = "QTest";
 ac->available = qtest_available;
-ac->init = qtest_init_accel;
+ac->init_machine = qtest_init_accel;
 ac->allowed = &qtest_allowed;
 }
 
diff --git a/xen-common.c b/xen-common.c
index acc64d5..acb738f 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -126,7 +126,7 @@ static void xen_accel_class_init(ObjectClass *oc, void 
*data)
 {
 AccelClass *ac = ACCEL_CLASS(oc);
 ac->name = "Xen";
-ac->init = xen_init;
+ac->init_machine = xen_init;
 ac->allowed = &xen_allowed;
 }
 
-- 
1.8.3.1





[Qemu-devel] [PULL 23/28] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Now that we create an accel object before calling machine_init, we can
simply use the accel object to save all KVMState data, instead of
allocationg KVMState manually.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 kvm-all.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 0a9de92..e98a7c7 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -71,8 +71,10 @@ typedef struct KVMSlot
 
 typedef struct kvm_dirty_log KVMDirtyLog;
 
-struct KVMState
+typedef struct KVMState
 {
+AccelState parent_obj;
+
 KVMSlot *slots;
 int nr_slots;
 int fd;
@@ -105,10 +107,13 @@ struct KVMState
 QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
 bool direct_msi;
 #endif
-};
+} KVMState;
 
 #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
 
+#define KVM_STATE(obj) \
+OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL)
+
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
@@ -1401,7 +1406,7 @@ static int kvm_init(MachineState *ms)
 int i, type = 0;
 const char *kvm_type;
 
-s = g_malloc0(sizeof(KVMState));
+s = KVM_STATE(ms->accelerator);
 
 /*
  * On systems where the kernel can support different base page
@@ -1590,7 +1595,6 @@ err:
 close(s->fd);
 }
 g_free(s->slots);
-g_free(s);
 
 return ret;
 }
@@ -2242,6 +2246,7 @@ static const TypeInfo kvm_accel_type = {
 .name = TYPE_KVM_ACCEL,
 .parent = TYPE_ACCEL,
 .class_init = kvm_accel_class_init,
+.instance_size = sizeof(KVMState),
 };
 
 static void kvm_type_init(void)
-- 
1.8.3.1





[Qemu-devel] [PULL 26/28] qemu-error: Add error_vreport()

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

Needed to nicely print socket error reports.

Signed-off-by: Corey Minyard 
Signed-off-by: Paolo Bonzini 
---
 include/qemu/error-report.h |  1 +
 util/qemu-error.c   | 23 ++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 000eae3..7ab2355 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -38,6 +38,7 @@ void error_vprintf(const char *fmt, va_list ap) 
GCC_FMT_ATTR(1, 0);
 void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void error_set_progname(const char *argv0);
+void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 const char *error_get_progname(void);
 extern bool enable_timestamp_msg;
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 7b167fd..9bba5f5 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -199,14 +199,13 @@ static void error_print_loc(void)
 bool enable_timestamp_msg;
 /*
  * Print an error message to current monitor if we have one, else to stderr.
- * Format arguments like sprintf().  The result should not contain
+ * Format arguments like vsprintf().  The result should not contain
  * newlines.
  * Prepend the current location and append a newline.
  * It's wrong to call this in a QMP monitor.  Use qerror_report() there.
  */
-void error_report(const char *fmt, ...)
+void error_vreport(const char *fmt, va_list ap)
 {
-va_list ap;
 GTimeVal tv;
 gchar *timestr;
 
@@ -218,8 +217,22 @@ void error_report(const char *fmt, ...)
 }
 
 error_print_loc();
-va_start(ap, fmt);
 error_vprintf(fmt, ap);
-va_end(ap);
 error_printf("\n");
 }
+
+/*
+ * Print an error message to current monitor if we have one, else to stderr.
+ * Format arguments like sprintf().  The result should not contain
+ * newlines.
+ * Prepend the current location and append a newline.
+ * It's wrong to call this in a QMP monitor.  Use qerror_report() there.
+ */
+void error_report(const char *fmt, ...)
+{
+va_list ap;
+
+va_start(ap, fmt);
+error_vreport(fmt, ap);
+va_end(ap);
+}
-- 
1.8.3.1





[Qemu-devel] [PULL 28/28] qemu-char: Fix reconnect socket error reporting

2014-10-09 Thread Paolo Bonzini
From: Corey Minyard 

If reconnect was set, errors wouldn't always be reported.
Fix that and also only report a connect error once until a
connection has been made.

The primary purpose of this is to tell the user that a
connection failed so they can know they need to figure out
what went wrong.  So we don't want to spew too much
out here, just enough so they know.

Signed-off-by: Corey Minyard 
Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 52 ++--
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index c71805a..bd0709b 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2509,6 +2509,7 @@ typedef struct {
 
 guint reconnect_timer;
 int64_t reconnect_time;
+bool connect_err_reported;
 } TCPCharDriver;
 
 static gboolean socket_reconnect_timeout(gpointer opaque);
@@ -2521,6 +2522,19 @@ static void 
qemu_chr_socket_restart_timer(CharDriverState *chr)
socket_reconnect_timeout, chr);
 }
 
+static void check_report_connect_error(CharDriverState *chr,
+   Error *err)
+{
+TCPCharDriver *s = chr->opaque;
+
+if (!s->connect_err_reported) {
+error_report("Unable to connect character device %s: %s",
+ chr->label, error_get_pretty(err));
+s->connect_err_reported = true;
+}
+qemu_chr_socket_restart_timer(chr);
+}
+
 static gboolean tcp_chr_accept(GIOChannel *chan, GIOCondition cond, void 
*opaque);
 
 #ifndef _WIN32
@@ -3045,14 +3059,14 @@ static void 
qemu_chr_finish_socket_connection(CharDriverState *chr, int fd)
 static void qemu_chr_socket_connected(int fd, Error *err, void *opaque)
 {
 CharDriverState *chr = opaque;
+TCPCharDriver *s = chr->opaque;
 
 if (fd < 0) {
-error_report("Unable to connect to char device %s: %s",
- chr->label, error_get_pretty(err));
-qemu_chr_socket_restart_timer(chr);
+check_report_connect_error(chr, err);
 return;
 }
 
+s->connect_err_reported = false;
 qemu_chr_finish_socket_connection(chr, fd);
 }
 
@@ -4068,11 +4082,19 @@ static CharDriverState 
*qmp_chardev_open_parallel(ChardevHostdev *parallel,
 
 #endif /* WIN32 */
 
+static void socket_try_connect(CharDriverState *chr)
+{
+Error *err = NULL;
+
+if (!qemu_chr_open_socket_fd(chr, &err)) {
+check_report_connect_error(chr, err);
+}
+}
+
 static gboolean socket_reconnect_timeout(gpointer opaque)
 {
 CharDriverState *chr = opaque;
 TCPCharDriver *s = chr->opaque;
-Error *err;
 
 s->reconnect_timer = 0;
 
@@ -4080,11 +4102,7 @@ static gboolean socket_reconnect_timeout(gpointer opaque)
 return false;
 }
 
-if (!qemu_chr_open_socket_fd(chr, &err)) {
-error_report("Unable to connect to char device %s: %s\n",
- chr->label, error_get_pretty(err));
-qemu_chr_socket_restart_timer(chr);
-}
+socket_try_connect(chr);
 
 return false;
 }
@@ -4136,15 +4154,13 @@ static CharDriverState 
*qmp_chardev_open_socket(ChardevSocket *sock,
 s->reconnect_time = reconnect;
 }
 
-if (!qemu_chr_open_socket_fd(chr, errp)) {
-if (s->reconnect_time) {
-qemu_chr_socket_restart_timer(chr);
-} else {
-g_free(s);
-g_free(chr->filename);
-g_free(chr);
-return NULL;
-}
+if (s->reconnect_time) {
+socket_try_connect(chr);
+} else if (!qemu_chr_open_socket_fd(chr, errp)) {
+g_free(s);
+g_free(chr->filename);
+g_free(chr);
+return NULL;
 }
 
 if (is_listen && is_waitconnect) {
-- 
1.8.3.1




[Qemu-devel] [PULL 24/28] linuxboot: compute initrd loading address

2014-10-09 Thread Paolo Bonzini
Even though hw/i386/pc.c tries to compute a valid loading address for the
initrd, close to the top of RAM, this does not take into account other
data that is malloced into that memory by SeaBIOS.

Luckily we can easily look at the memory map to find out how much memory is
used up there.  This patch places the initrd in the first four gigabytes,
below the first hole (as returned by INT 15h, AX=e801h).

Without this patch:
[0.00] init_memory_mapping: [mem 0x0700-0x07fd]
[0.00] RAMDISK: [mem 0x0710a000-0x07fd7fff]

With this patch:
[0.00] init_memory_mapping: [mem 0x0700-0x07fd]
[0.00] RAMDISK: [mem 0x07112000-0x07fd]

So linuxboot is able to use the 64k that were added as padding for
QEMU <= 2.1.

Acked-by: Michael S. Tsirkin 
Signed-off-by: Paolo Bonzini 
---
 pc-bios/linuxboot.bin | Bin 1024 -> 1024 bytes
 pc-bios/optionrom/linuxboot.S |  47 ++
 pc-bios/optionrom/optionrom.h |  21 ---
 3 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/pc-bios/linuxboot.bin b/pc-bios/linuxboot.bin
index 
e7c36694f997c3c34f7f4af3c2923bd2ef6094e7..130103fb739228a6869aaf1b174b9d20c13378fc
 100644
GIT binary patch
delta 168
zcmZqRXyBNj#e9V67|eo$aa3kRw;nk>i|IC(Q;0c%?4;T_@=t7IoTF$qbirKj~bOE57or0rk;0)C|f
SJtz7Oyqvi?nJI*kF&F^X7ev$m

delta 107
zcmZqRXyBNj#azSGI8k@yWCKP?#+1okj0#LU*e5$O$xYtNXvD|`VlnOD22!$> 16, %dx  /* add 16 MB */
+   movzwl  %dx, %edi
+   shll$16, %edi /* convert to bytes */
+
+3:
+   read_fw FW_CFG_INITRD_SIZE
+   subl%eax, %edi
+   andl$-4096, %edi  /* EDI = start of initrd */
 
/* We need to load the kernel into memory we can't access in 16 bit
   mode, so let's get into 32 bit mode, write the kernel and jump
   back again. */
 
/* Reserve space on the stack for our GDT descriptor. */
-   mov %esp, %ebp
-   sub $16, %esp
+   mov %esp, %ebp
+   sub $16, %esp
 
/* Now create the GDT descriptor */
movw$((3 * 8) - 1), -16(%bp)
@@ -108,10 +139,18 @@ copy_kernel:
/* We're now running in 16-bit CS, but 32-bit ES! */
 
/* Load kernel and initrd */
+   pushl   %edi
+   read_fw_blob_addr32_edi(FW_CFG_INITRD)
read_fw_blob_addr32(FW_CFG_KERNEL)
-   read_fw_blob_addr32(FW_CFG_INITRD)
read_fw_blob_addr32(FW_CFG_CMDLINE)
-   read_fw_blob_addr32(FW_CFG_SETUP)
+
+   read_fw FW_CFG_SETUP_ADDR
+   mov %eax, %edi
+   mov %eax, %ebx
+   read_fw_blob_addr32_edi(FW_CFG_SETUP)
+
+   /* Update the header with the initrd address we chose above */
+   popl%es:0x218(%ebx)
 
/* And now jump into Linux! */
mov $0, %eax
diff --git a/pc-bios/optionrom/optionrom.h b/pc-bios/optionrom/optionrom.h
index ce43608..f1a9021 100644
--- a/pc-bios/optionrom/optionrom.h
+++ b/pc-bios/optionrom/optionrom.h
@@ -51,8 +51,6 @@
 .endm
 
 #define read_fw_blob_pre(var)  \
-   read_fw var ## _ADDR;   \
-   mov %eax, %edi; \
read_fw var ## _SIZE;   \
mov %eax, %ecx; \
mov $var ## _DATA, %ax; \
@@ -68,6 +66,8 @@
  * Clobbers:   %eax, %edx, %es, %ecx, %edi
  */
 #define read_fw_blob(var)  \
+   read_fw var ## _ADDR;   \
+   mov %eax, %edi; \
read_fw_blob_pre(var);  \
/* old as(1) doesn't like this insn so emit the bytes instead: \
rep insb(%dx), %es:(%edi);  \
@@ -80,7 +80,22 @@
  *
  * Clobbers:   %eax, %edx, %es, %ecx, %edi
  */
-#define read_fw_blob_addr32(var)   \
+#define read_fw_blob_addr32(var)   \
+   read_fw var ## _ADDR;   \
+   mov %eax, %edi; \
+   read_fw_blob_pre(var);  \
+   /* old as(1) doesn't like this insn so emit the bytes instead: \
+   addr32 rep insb (%dx), %es:(%edi);  \
+   */  \
+   .dc.b   0x67,0xf3,0x6c
+
+/*
+ * Read a blob from the fw_cfg device in forced addr32 mode, address is in 
%edi.
+ * Requires _SIZE and _DATA values for the parameter.
+ *
+ * Clobbers:   %eax, %edx, %edi, %es, %ecx
+ */
+#define read_fw_blob_addr32_edi(var)   \
read_fw_blob_pre(var);  \
/* old as(1) doesn't like this insn so emit the bytes instead: \
addr32 rep insb (%dx), %es:(%edi);  \
-- 
1.8.3.1





[Qemu-devel] [PULL 16/28] accel: Move Xen registration code to xen-common.c

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Note that this has an user-visible side-effect: instead of reporting
"Xen is not supported for this target", QEMU binaries not supporting Xen
will report "xen accelerator does not exist".

As xen_available() always return 1 when CONFIG_XEN is enabled, we don't
need to set AccelClass.available anymore. xen_enabled() is not being
removed yet, but only because vl.c is still using it.

This also allows us to make xen_init() static.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c  | 18 --
 include/hw/xen/xen.h |  1 -
 xen-common-stub.c|  6 --
 xen-common.c | 25 -
 4 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/accel.c b/accel.c
index a20e427..2cefbb0 100644
--- a/accel.c
+++ b/accel.c
@@ -132,23 +132,6 @@ static const TypeInfo tcg_accel_type = {
 .class_init = tcg_accel_class_init,
 };
 
-static void xen_accel_class_init(ObjectClass *oc, void *data)
-{
-AccelClass *ac = ACCEL_CLASS(oc);
-ac->name = "Xen";
-ac->available = xen_available;
-ac->init = xen_init;
-ac->allowed = &xen_allowed;
-}
-
-#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
-
-static const TypeInfo xen_accel_type = {
-.name = TYPE_XEN_ACCEL,
-.parent = TYPE_ACCEL,
-.class_init = xen_accel_class_init,
-};
-
 static void qtest_accel_class_init(ObjectClass *oc, void *data)
 {
 AccelClass *ac = ACCEL_CLASS(oc);
@@ -170,7 +153,6 @@ static void register_accel_types(void)
 {
 type_register_static(&accel_type);
 type_register_static(&tcg_accel_type);
-type_register_static(&xen_accel_type);
 type_register_static(&qtest_accel_type);
 }
 
diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
index f71f2d8..b0ed04c 100644
--- a/include/hw/xen/xen.h
+++ b/include/hw/xen/xen.h
@@ -36,7 +36,6 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);
 
 qemu_irq *xen_interrupt_controller_init(void);
 
-int xen_init(MachineClass *mc);
 void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 
 #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
diff --git a/xen-common-stub.c b/xen-common-stub.c
index bd56ca2..906f991 100644
--- a/xen-common-stub.c
+++ b/xen-common-stub.c
@@ -11,9 +11,3 @@
 void xenstore_store_pv_console_info(int i, CharDriverState *chr)
 {
 }
-
-int xen_init(MachineClass *mc)
-{
-return -ENOSYS;
-}
-
diff --git a/xen-common.c b/xen-common.c
index f07b35e..acc64d5 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -11,6 +11,7 @@
 #include "hw/xen/xen_backend.h"
 #include "qmp-commands.h"
 #include "sysemu/char.h"
+#include "sysemu/accel.h"
 
 //#define DEBUG_XEN
 
@@ -109,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int 
running,
 }
 }
 
-int xen_init(MachineClass *mc)
+static int xen_init(MachineClass *mc)
 {
 xen_xc = xen_xc_interface_open(0, 0, 0);
 if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
@@ -121,3 +122,25 @@ int xen_init(MachineClass *mc)
 return 0;
 }
 
+static void xen_accel_class_init(ObjectClass *oc, void *data)
+{
+AccelClass *ac = ACCEL_CLASS(oc);
+ac->name = "Xen";
+ac->init = xen_init;
+ac->allowed = &xen_allowed;
+}
+
+#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
+
+static const TypeInfo xen_accel_type = {
+.name = TYPE_XEN_ACCEL,
+.parent = TYPE_ACCEL,
+.class_init = xen_accel_class_init,
+};
+
+static void xen_type_init(void)
+{
+type_register_static(&xen_accel_type);
+}
+
+type_init(xen_type_init);
-- 
1.8.3.1





[Qemu-devel] [PULL 25/28] virtio-scsi: fix use-after-free of VirtIOSCSIReq

2014-10-09 Thread Paolo Bonzini
scsi_req_continue can complete the request and cause the VirtIOSCSIReq
to be freed.  Fetch req->sreq just once to avoid the bug.

Reported-by: Richard Jones 
Tested-by: Richard Jones 
Reviewed-by: Fam Zheng 
Signed-off-by: Paolo Bonzini 
---
 hw/scsi/virtio-scsi.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 203e624..6c02fe2 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -545,11 +545,12 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, 
VirtIOSCSIReq *req)
 
 void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req)
 {
-if (scsi_req_enqueue(req->sreq)) {
-scsi_req_continue(req->sreq);
+SCSIRequest *sreq = req->sreq;
+if (scsi_req_enqueue(sreq)) {
+scsi_req_continue(sreq);
 }
-bdrv_io_unplug(req->sreq->dev->conf.bs);
-scsi_req_unref(req->sreq);
+bdrv_io_unplug(sreq->dev->conf.bs);
+scsi_req_unref(sreq);
 }
 
 static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
-- 
1.8.3.1





[Qemu-devel] [PULL 07/28] vl.c: Small coding style fix

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Just to make checkpatch.pl happy when moving the code.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 vl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vl.c b/vl.c
index 9d2aaaf..72436cd 100644
--- a/vl.c
+++ b/vl.c
@@ -2712,7 +2712,7 @@ static int configure_accelerator(MachineClass *mc)
 if (*p == ':') {
 p++;
 }
-p = get_opt_name(buf, sizeof (buf), p, ':');
+p = get_opt_name(buf, sizeof(buf), p, ':');
 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
 if (strcmp(accel_list[i].opt_name, buf) == 0) {
 if (!accel_list[i].available()) {
-- 
1.8.3.1




[Qemu-devel] [PULL 15/28] accel: Move KVM accel registration to kvm-all.c

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Note that this has an user-visible side-effect: instead of reporting
"KVM is not supported for this target", QEMU binaries not supporting KVM
will report "kvm accelerator does not exist".

As kvm_availble() always return 1 when CONFIG_KVM is enabled, we don't
need to set AccelClass.available anymore. kvm_enabled() is not being
completely removed yet only because qmp_query_kvm() still uses it.

This also allows us to make kvm_init() static.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c  | 18 --
 include/sysemu/kvm.h |  2 --
 kvm-all.c| 26 +-
 kvm-stub.c   |  5 -
 4 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/accel.c b/accel.c
index fce6eab..a20e427 100644
--- a/accel.c
+++ b/accel.c
@@ -149,23 +149,6 @@ static const TypeInfo xen_accel_type = {
 .class_init = xen_accel_class_init,
 };
 
-static void kvm_accel_class_init(ObjectClass *oc, void *data)
-{
-AccelClass *ac = ACCEL_CLASS(oc);
-ac->name = "KVM";
-ac->available = kvm_available;
-ac->init = kvm_init;
-ac->allowed = &kvm_allowed;
-}
-
-#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
-
-static const TypeInfo kvm_accel_type = {
-.name = TYPE_KVM_ACCEL,
-.parent = TYPE_ACCEL,
-.class_init = kvm_accel_class_init,
-};
-
 static void qtest_accel_class_init(ObjectClass *oc, void *data)
 {
 AccelClass *ac = ACCEL_CLASS(oc);
@@ -188,7 +171,6 @@ static void register_accel_types(void)
 type_register_static(&accel_type);
 type_register_static(&tcg_accel_type);
 type_register_static(&xen_accel_type);
-type_register_static(&kvm_accel_type);
 type_register_static(&qtest_accel_type);
 }
 
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 77ee240..b0cd657 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -163,8 +163,6 @@ extern KVMState *kvm_state;
 
 /* external API */
 
-int kvm_init(MachineClass *mc);
-
 int kvm_has_sync_mmu(void);
 int kvm_has_vcpu_events(void);
 int kvm_has_robust_singlestep(void);
diff --git a/kvm-all.c b/kvm-all.c
index 4afcd05..18dcd45 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -25,6 +25,7 @@
 #include "qemu/option.h"
 #include "qemu/config-file.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/accel.h"
 #include "hw/hw.h"
 #include "hw/pci/msi.h"
 #include "hw/s390x/adapter.h"
@@ -106,6 +107,8 @@ struct KVMState
 #endif
 };
 
+#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
+
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
@@ -1377,7 +1380,7 @@ static int kvm_max_vcpus(KVMState *s)
 return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-int kvm_init(MachineClass *mc)
+static int kvm_init(MachineClass *mc)
 {
 static const char upgrade_note[] =
 "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
@@ -2225,3 +2228,24 @@ int kvm_get_one_reg(CPUState *cs, uint64_t id, void 
*target)
 }
 return r;
 }
+
+static void kvm_accel_class_init(ObjectClass *oc, void *data)
+{
+AccelClass *ac = ACCEL_CLASS(oc);
+ac->name = "KVM";
+ac->init = kvm_init;
+ac->allowed = &kvm_allowed;
+}
+
+static const TypeInfo kvm_accel_type = {
+.name = TYPE_KVM_ACCEL,
+.parent = TYPE_ACCEL,
+.class_init = kvm_accel_class_init,
+};
+
+static void kvm_type_init(void)
+{
+type_register_static(&kvm_accel_type);
+}
+
+type_init(kvm_type_init);
diff --git a/kvm-stub.c b/kvm-stub.c
index 8e7737c..43fc0dd 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -35,11 +35,6 @@ int kvm_init_vcpu(CPUState *cpu)
 return -ENOSYS;
 }
 
-int kvm_init(MachineClass *mc)
-{
-return -ENOSYS;
-}
-
 void kvm_flush_coalesced_mmio_buffer(void)
 {
 }
-- 
1.8.3.1





[Qemu-devel] [PULL 10/28] accel: Simplify configure_accelerator() using AccelType *acc variable

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/accel.c b/accel.c
index 3cefd74..fc8c551 100644
--- a/accel.c
+++ b/accel.c
@@ -62,6 +62,7 @@ int configure_accelerator(MachineClass *mc)
 int i, ret;
 bool accel_initialised = false;
 bool init_failed = false;
+AccelType *acc = NULL;
 
 p = qemu_opt_get(qemu_get_machine_opts(), "accel");
 if (p == NULL) {
@@ -75,20 +76,21 @@ int configure_accelerator(MachineClass *mc)
 }
 p = get_opt_name(buf, sizeof(buf), p, ':');
 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
-if (strcmp(accel_list[i].opt_name, buf) == 0) {
-if (!accel_list[i].available()) {
+acc = &accel_list[i];
+if (strcmp(acc->opt_name, buf) == 0) {
+if (!acc->available()) {
 printf("%s not supported for this target\n",
-   accel_list[i].name);
+   acc->name);
 break;
 }
-*(accel_list[i].allowed) = true;
-ret = accel_list[i].init(mc);
+*(acc->allowed) = true;
+ret = acc->init(mc);
 if (ret < 0) {
 init_failed = true;
 fprintf(stderr, "failed to initialize %s: %s\n",
-accel_list[i].name,
+acc->name,
 strerror(-ret));
-*(accel_list[i].allowed) = false;
+*(acc->allowed) = false;
 } else {
 accel_initialised = true;
 }
@@ -108,7 +110,7 @@ int configure_accelerator(MachineClass *mc)
 }
 
 if (init_failed) {
-fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
+fprintf(stderr, "Back to %s accelerator.\n", acc->name);
 }
 
 return !accel_initialised;
-- 
1.8.3.1





[Qemu-devel] [PULL 11/28] accel: Move accel name lookup to separate function

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 57 +
 1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/accel.c b/accel.c
index fc8c551..c752fcc 100644
--- a/accel.c
+++ b/accel.c
@@ -55,11 +55,24 @@ static AccelType accel_list[] = {
 { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
 };
 
+/* Lookup AccelType from opt_name. Returns NULL if not found */
+static AccelType *accel_find(const char *opt_name)
+{
+int i;
+for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
+AccelType *acc = &accel_list[i];
+if (acc->opt_name && strcmp(acc->opt_name, opt_name) == 0) {
+return acc;
+}
+}
+return NULL;
+}
+
 int configure_accelerator(MachineClass *mc)
 {
 const char *p;
 char buf[10];
-int i, ret;
+int ret;
 bool accel_initialised = false;
 bool init_failed = false;
 AccelType *acc = NULL;
@@ -75,30 +88,26 @@ int configure_accelerator(MachineClass *mc)
 p++;
 }
 p = get_opt_name(buf, sizeof(buf), p, ':');
-for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
-acc = &accel_list[i];
-if (strcmp(acc->opt_name, buf) == 0) {
-if (!acc->available()) {
-printf("%s not supported for this target\n",
-   acc->name);
-break;
-}
-*(acc->allowed) = true;
-ret = acc->init(mc);
-if (ret < 0) {
-init_failed = true;
-fprintf(stderr, "failed to initialize %s: %s\n",
-acc->name,
-strerror(-ret));
-*(acc->allowed) = false;
-} else {
-accel_initialised = true;
-}
-break;
-}
-}
-if (i == ARRAY_SIZE(accel_list)) {
+acc = accel_find(buf);
+if (!acc) {
 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
+continue;
+}
+if (!acc->available()) {
+printf("%s not supported for this target\n",
+   acc->name);
+continue;
+}
+*(acc->allowed) = true;
+ret = acc->init(mc);
+if (ret < 0) {
+init_failed = true;
+fprintf(stderr, "failed to initialize %s: %s\n",
+acc->name,
+strerror(-ret));
+*(acc->allowed) = false;
+} else {
+accel_initialised = true;
 }
 }
 
-- 
1.8.3.1





[Qemu-devel] [PULL 14/28] accel: Report unknown accelerator as "not found" instead of "does not exist"

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

As the accelerator classes won't be registered anymore if they are not
enabled at compile time, saying "does not exist" may be misleading, as
the accelerator may be simply disabled. Change the wording to just say
"not found".

Suggested-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/accel.c b/accel.c
index 85177f1..fce6eab 100644
--- a/accel.c
+++ b/accel.c
@@ -79,7 +79,7 @@ int configure_accelerator(MachineClass *mc)
 p = get_opt_name(buf, sizeof(buf), p, ':');
 acc = accel_find(buf);
 if (!acc) {
-fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
+fprintf(stderr, "\"%s\" accelerator not found.\n", buf);
 continue;
 }
 if (acc->available && !acc->available()) {
-- 
1.8.3.1





[Qemu-devel] [PULL 09/28] accel: Create AccelType typedef

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/accel.c b/accel.c
index 9424796..3cefd74 100644
--- a/accel.c
+++ b/accel.c
@@ -40,13 +40,15 @@ static int tcg_init(MachineClass *mc)
 return 0;
 }
 
-static struct {
+typedef struct AccelType {
 const char *opt_name;
 const char *name;
 int (*available)(void);
 int (*init)(MachineClass *mc);
 bool *allowed;
-} accel_list[] = {
+} AccelType;
+
+static AccelType accel_list[] = {
 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
-- 
1.8.3.1





[Qemu-devel] [PULL 12/28] accel: Use QOM classes for accel types

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Instead of having a static AccelType array, register a class for each
accelerator type, and use class name lookup to find accelerator
information.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c| 117 +++--
 include/sysemu/accel.h |  30 +
 2 files changed, 123 insertions(+), 24 deletions(-)

diff --git a/accel.c b/accel.c
index c752fcc..a3e2fd9 100644
--- a/accel.c
+++ b/accel.c
@@ -30,6 +30,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/qtest.h"
 #include "hw/xen/xen.h"
+#include "qom/object.h"
 
 int tcg_tb_size;
 static bool tcg_allowed = true;
@@ -40,32 +41,20 @@ static int tcg_init(MachineClass *mc)
 return 0;
 }
 
-typedef struct AccelType {
-const char *opt_name;
-const char *name;
-int (*available)(void);
-int (*init)(MachineClass *mc);
-bool *allowed;
-} AccelType;
-
-static AccelType accel_list[] = {
-{ "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
-{ "xen", "Xen", xen_available, xen_init, &xen_allowed },
-{ "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
-{ "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
+static const TypeInfo accel_type = {
+.name = TYPE_ACCEL,
+.parent = TYPE_OBJECT,
+.class_size = sizeof(AccelClass),
+.instance_size = sizeof(AccelState),
 };
 
-/* Lookup AccelType from opt_name. Returns NULL if not found */
-static AccelType *accel_find(const char *opt_name)
+/* Lookup AccelClass from opt_name. Returns NULL if not found */
+static AccelClass *accel_find(const char *opt_name)
 {
-int i;
-for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
-AccelType *acc = &accel_list[i];
-if (acc->opt_name && strcmp(acc->opt_name, opt_name) == 0) {
-return acc;
-}
-}
-return NULL;
+char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
+AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
+g_free(class_name);
+return ac;
 }
 
 int configure_accelerator(MachineClass *mc)
@@ -75,7 +64,7 @@ int configure_accelerator(MachineClass *mc)
 int ret;
 bool accel_initialised = false;
 bool init_failed = false;
-AccelType *acc = NULL;
+AccelClass *acc = NULL;
 
 p = qemu_opt_get(qemu_get_machine_opts(), "accel");
 if (p == NULL) {
@@ -124,3 +113,83 @@ int configure_accelerator(MachineClass *mc)
 
 return !accel_initialised;
 }
+
+
+static void tcg_accel_class_init(ObjectClass *oc, void *data)
+{
+AccelClass *ac = ACCEL_CLASS(oc);
+ac->name = "tcg";
+ac->available = tcg_available;
+ac->init = tcg_init;
+ac->allowed = &tcg_allowed;
+}
+
+#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg")
+
+static const TypeInfo tcg_accel_type = {
+.name = TYPE_TCG_ACCEL,
+.parent = TYPE_ACCEL,
+.class_init = tcg_accel_class_init,
+};
+
+static void xen_accel_class_init(ObjectClass *oc, void *data)
+{
+AccelClass *ac = ACCEL_CLASS(oc);
+ac->name = "Xen";
+ac->available = xen_available;
+ac->init = xen_init;
+ac->allowed = &xen_allowed;
+}
+
+#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
+
+static const TypeInfo xen_accel_type = {
+.name = TYPE_XEN_ACCEL,
+.parent = TYPE_ACCEL,
+.class_init = xen_accel_class_init,
+};
+
+static void kvm_accel_class_init(ObjectClass *oc, void *data)
+{
+AccelClass *ac = ACCEL_CLASS(oc);
+ac->name = "KVM";
+ac->available = kvm_available;
+ac->init = kvm_init;
+ac->allowed = &kvm_allowed;
+}
+
+#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
+
+static const TypeInfo kvm_accel_type = {
+.name = TYPE_KVM_ACCEL,
+.parent = TYPE_ACCEL,
+.class_init = kvm_accel_class_init,
+};
+
+static void qtest_accel_class_init(ObjectClass *oc, void *data)
+{
+AccelClass *ac = ACCEL_CLASS(oc);
+ac->name = "QTest";
+ac->available = qtest_available;
+ac->init = qtest_init_accel;
+ac->allowed = &qtest_allowed;
+}
+
+#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
+
+static const TypeInfo qtest_accel_type = {
+.name = TYPE_QTEST_ACCEL,
+.parent = TYPE_ACCEL,
+.class_init = qtest_accel_class_init,
+};
+
+static void register_accel_types(void)
+{
+type_register_static(&accel_type);
+type_register_static(&tcg_accel_type);
+type_register_static(&xen_accel_type);
+type_register_static(&kvm_accel_type);
+type_register_static(&qtest_accel_type);
+}
+
+type_init(register_accel_types);
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 5537d74..120ca0e 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -24,6 +24,36 @@
 #define HW_ACCEL_H
 
 #include "qemu/typedefs.h"
+#include "qom/object.h"
+
+typedef struct AccelState {
+/*< private >*/
+Object parent_obj;
+} AccelState;
+
+typedef struct AccelClass {
+/*< private >*/
+ObjectClass parent_class;
+/*< public >*/
+
+  

[Qemu-devel] [PULL 08/28] accel: Move accel code to accel.c

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 Makefile.objs  |   1 +
 accel.c| 113 +
 include/sysemu/accel.h |  32 ++
 vl.c   |  81 +--
 4 files changed, 147 insertions(+), 80 deletions(-)
 create mode 100644 accel.c
 create mode 100644 include/sysemu/accel.h

diff --git a/Makefile.objs b/Makefile.objs
index 97db978..add8375 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -62,6 +62,7 @@ common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
 
 common-obj-y += audio/
 common-obj-y += hw/
+common-obj-y += accel.o
 
 common-obj-y += ui/
 common-obj-y += bt-host.o bt-vhci.o
diff --git a/accel.c b/accel.c
new file mode 100644
index 000..9424796
--- /dev/null
+++ b/accel.c
@@ -0,0 +1,113 @@
+/*
+ * QEMU System Emulator, accelerator interfaces
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2014 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.
+ */
+
+#include "sysemu/accel.h"
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/kvm.h"
+#include "sysemu/qtest.h"
+#include "hw/xen/xen.h"
+
+int tcg_tb_size;
+static bool tcg_allowed = true;
+
+static int tcg_init(MachineClass *mc)
+{
+tcg_exec_init(tcg_tb_size * 1024 * 1024);
+return 0;
+}
+
+static struct {
+const char *opt_name;
+const char *name;
+int (*available)(void);
+int (*init)(MachineClass *mc);
+bool *allowed;
+} accel_list[] = {
+{ "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
+{ "xen", "Xen", xen_available, xen_init, &xen_allowed },
+{ "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
+{ "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
+};
+
+int configure_accelerator(MachineClass *mc)
+{
+const char *p;
+char buf[10];
+int i, ret;
+bool accel_initialised = false;
+bool init_failed = false;
+
+p = qemu_opt_get(qemu_get_machine_opts(), "accel");
+if (p == NULL) {
+/* Use the default "accelerator", tcg */
+p = "tcg";
+}
+
+while (!accel_initialised && *p != '\0') {
+if (*p == ':') {
+p++;
+}
+p = get_opt_name(buf, sizeof(buf), p, ':');
+for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
+if (strcmp(accel_list[i].opt_name, buf) == 0) {
+if (!accel_list[i].available()) {
+printf("%s not supported for this target\n",
+   accel_list[i].name);
+break;
+}
+*(accel_list[i].allowed) = true;
+ret = accel_list[i].init(mc);
+if (ret < 0) {
+init_failed = true;
+fprintf(stderr, "failed to initialize %s: %s\n",
+accel_list[i].name,
+strerror(-ret));
+*(accel_list[i].allowed) = false;
+} else {
+accel_initialised = true;
+}
+break;
+}
+}
+if (i == ARRAY_SIZE(accel_list)) {
+fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
+}
+}
+
+if (!accel_initialised) {
+if (!init_failed) {
+fprintf(stderr, "No accelerator found!\n");
+}
+exit(1);
+}
+
+if (init_failed) {
+fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
+}
+
+return !accel_initialised;
+}
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
new file mode 100644
index 000..5537d74
--- /dev/null
+++ b/include/sysemu/accel.h
@@ -0,0 +1,32 @@
+/* QEMU accelerator interfaces
+ *
+ * Copyright (c) 2014 Red Hat Inc
+ *
+ * Permission is hereby granted, free o

[Qemu-devel] [PULL 13/28] accel: Make AccelClass.available() optional

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

When we move accel classes outside accel.c, the available() function
won't be necessary anymore, because the classes will be registered only
if the accelerator code is really enabled at build time.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/accel.c b/accel.c
index a3e2fd9..85177f1 100644
--- a/accel.c
+++ b/accel.c
@@ -82,7 +82,7 @@ int configure_accelerator(MachineClass *mc)
 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
 continue;
 }
-if (!acc->available()) {
+if (acc->available && !acc->available()) {
 printf("%s not supported for this target\n",
acc->name);
 continue;
-- 
1.8.3.1





Re: [Qemu-devel] [PULL 00/28] Changes for 2014-10-09

2014-10-09 Thread Peter Maydell
On 9 October 2014 11:10, Paolo Bonzini  wrote:
> The following changes since commit 1831e150606a221898bf46ffaf0453e9952cbbc4:
>
>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into 
> staging (2014-09-30 16:45:35 +0100)
>
> are available in the git repository at:
>
>
>   git://github.com/bonzini/qemu.git tags/for-upstream
>
> for you to fetch changes up to e50fffc7209c9ce844dcb21a99f2d4b3f93900c0:
>
>   qemu-char: Fix reconnect socket error reporting (2014-10-09 12:08:42 +0200)
>
> 
> Four changes here.  Polling for reconnection of character devices,
> the QOMification of accelerators, a fix for -kernel support on x86, and one
> for a recently-introduced virtio-scsi optimization.

Hi. I'm afraid this doesn't build for w32:

  CCdevice-hotplug.o
In file included from /home/petmay01/linaro/qemu-for-merges/device-hotplug.c:26:
/home/petmay01/linaro/qemu-for-merges/include/hw/boards.h:12: error:
redefinition of typedef ‘MachineState’
/home/petmay01/linaro/qemu-for-merges/include/qemu/typedefs.h:37:
error: previous declaration of ‘MachineState’ was here

(No, I don't know why the gcc for w32 complains about
repeat identical typedefs and none of my other gcc do.)

thanks
-- PMM



Re: [Qemu-devel] [PULL 00/28] Changes for 2014-10-09

2014-10-09 Thread Paolo Bonzini
Il 09/10/2014 12:55, Peter Maydell ha scritto:
> (No, I don't know why the gcc for w32 complains about
> repeat identical typedefs and none of my other gcc do.)

Just an older version.  It comes up at least half a month.  Will send v2.

Paolo



qemu-devel@nongnu.org

2014-10-09 Thread Fabien Chouteau
From: Jiri Gaisler 

AMBA plug&play is used by kernels to probe available devices (Timers,
UART, etc...). This is a static declaration of devices implemented in
QEMU. In the future, a more advanced version could compute those
information directly from the device tree.

Signed-off-by: Fabien Chouteau 
---

V2:
 - AHB and APB PNP are now grouped in one device
 - Initialisation moved to .instance_init
 - Minor fixes

 hw/sparc/Makefile.objs   |1 +
 hw/sparc/grlib_ambapnp.c |  149 ++
 hw/sparc/leon3.c |3 +
 include/hw/sparc/grlib.h |   22 +++
 4 files changed, 175 insertions(+)
 create mode 100644 hw/sparc/grlib_ambapnp.c

diff --git a/hw/sparc/Makefile.objs b/hw/sparc/Makefile.objs
index c987b5b..e763701 100644
--- a/hw/sparc/Makefile.objs
+++ b/hw/sparc/Makefile.objs
@@ -1 +1,2 @@
 obj-y += sun4m.o leon3.o
+obj-$(CONFIG_GRLIB) += grlib_ambapnp.o
diff --git a/hw/sparc/grlib_ambapnp.c b/hw/sparc/grlib_ambapnp.c
new file mode 100644
index 000..dd53004
--- /dev/null
+++ b/hw/sparc/grlib_ambapnp.c
@@ -0,0 +1,149 @@
+/*
+ * QEMU GRLIB AMBA Plug&Play Emulator
+ *
+ * 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/sysbus.h"
+#include "hw/sparc/grlib.h"
+
+/* Size of memory mapped registers */
+#define APBPNP_REG_SIZE (4096 - 8)
+#define AHBPNP_REG_SIZE 4096
+
+#define GRLIB_AMBA_PNP(obj) \
+OBJECT_CHECK(AMBAPNP, (obj), TYPE_GRLIB_AMBA_PNP)
+
+typedef struct AMBAPNP {
+SysBusDevice parent_obj;
+MemoryRegion ahb_iomem;
+MemoryRegion apb_iomem;
+} AMBAPNP;
+
+/* APB PNP */
+
+static uint64_t grlib_apbpnp_read(void *opaque, hwaddr addr,
+   unsigned size)
+{
+uint64_t read_data;
+addr &= 0xfff;
+
+/* Unit registers */
+switch (addr & 0xffc) {
+case 0x00:
+read_data = 0x0400f000; /* Memory controller */
+break;
+case 0x04:
+read_data = 0xfff1;
+break;
+case 0x08:
+read_data = 0x0100c023; /* APBUART */
+break;
+case 0x0C:
+read_data = 0x0010fff1;
+break;
+case 0x10:
+read_data = 0x0100d040; /* IRQMP */
+break;
+case 0x14:
+read_data = 0x0020fff1;
+break;
+case 0x18:
+read_data = 0x01011006; /* GPTIMER */
+break;
+case 0x1C:
+read_data = 0x0030fff1;
+break;
+
+default:
+read_data = 0;
+}
+if (size == 1) {
+read_data >>= (24 - (addr & 3) * 8);
+read_data &= 0x0ff;
+}
+return read_data;
+}
+
+static const MemoryRegionOps grlib_apbpnp_ops = {
+.read   = grlib_apbpnp_read,
+.endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+/* AHB PNP */
+
+static uint64_t grlib_ahbpnp_read(void *opaque, hwaddr addr,
+   unsigned size)
+{
+addr &= 0xffc;
+
+/* Unit registers */
+switch (addr) {
+case 0:
+return 0x01003000;  /* LEON3 */
+case 0x800:
+return 0x0400f000;  /* Memory controller  */
+case 0x810:
+return 0x0003e002;
+case 0x814:
+return 0x2000e002;
+case 0x818:
+return 0x4003c002;
+case 0x820:
+return 0x01006000;  /* APB bridge @ 0x8000 */
+case 0x830:
+return 0x8000fff2;
+
+default:
+return 0;
+}
+}
+
+static const MemoryRegionOps grlib_ahbpnp_ops = {
+.read = grlib_ahbpnp_read,
+.endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static void grlib_ambapnp_init(Object *obj)
+{
+SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+AMBAPNP *pnp = GRLIB_AMBA_PNP(obj);
+
+memory_region_init_io(&pnp->ahb_iomem, OBJECT(pnp), &grlib_ahbpnp_ops, pnp,
+  "ahbpnp", AHBPNP_REG_SIZE);
+sysbus_init_mmio(sbd, &pnp->ahb_iomem);
+
+memory_region_init_io(&pnp->apb_iomem, OBJECT(pnp), &grlib_apbpnp_ops, pnp,
+  "apbpnp", APBPNP_REG_SIZE);
+sysbus_init_mmio(

Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and take effect after rebooting

2014-10-09 Thread Michael Mueller
On Thu, 09 Oct 2014 11:47:12 +0200
Gerd Hoffmann  wrote:

> On Mi, 2014-10-08 at 19:00 +0800, Gonglei wrote:
> > On 2014/10/7 16:00, Gonglei (Arei) wrote:
> > 
> > > From: Gonglei 
> > > 
> > > Changes since v10:
> > >  1. add handler for virtio-blk-pci/s390/ccw in PATCH 28.
> > >  2. add especial bootidnex setter/getter functions for usb-storage
> > > device in PATCH 29.
> > >  3. add bootindex qom property for nvma and ne2k_isa devices,
> > > avoid regrassion in PATCH 30.
> > >  4. change fprintf to error_report in bootdevice.c in PATCH 34.
> > >  5. rebase on the latest qemu master tree.
> > >  6. add 'Reviewed-by' in other patches. (Thanks, Gerd)
> > > 
> > 
> > 
> > Hi, Gerd
> > 
> > Could you please review the v11 and consider to merge this series in your 
> > tree?
> > I have no idea which maintainer can apply this series. It seems that only 
> > you
> > and Eduardo  interested in and reviewed this patch series at present. :(
> 
> Yea, for these cross-tree changes it isn't always clear which way they
> should be merged.  qom or pc would make sense I think.
> 
> I can prepare a pull request too, but I'd like to have a second opinion
> on the stuff which is outside of my primary focus:
> 
>   * fw_cfg changes (mst?  paolo?)
>   * qom bits (andreas?  paolo?, eduardo?)
> 
> I'll go take "no answer" as "no objections", but I'd prefer to apply one
> or another "reviewed-by" to the series.
> 
> thanks,
>   Gerd
> 

The s390x team is planning to use some functionality of this patch set as base 
for diag308
implementation. I'll give v11 a try on our platform.

Michael

> 
> 




Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and take effect after rebooting

2014-10-09 Thread Andreas Färber
Am 09.10.2014 um 12:09 schrieb Gonglei:
> On 2014/10/9 17:47, Gerd Hoffmann wrote:
> 
>> On Mi, 2014-10-08 at 19:00 +0800, Gonglei wrote:
>>> On 2014/10/7 16:00, Gonglei (Arei) wrote:
>>>
 From: Gonglei 

 Changes since v10:
  1. add handler for virtio-blk-pci/s390/ccw in PATCH 28.
  2. add especial bootidnex setter/getter functions for usb-storage
 device in PATCH 29.
  3. add bootindex qom property for nvma and ne2k_isa devices,
 avoid regrassion in PATCH 30.
  4. change fprintf to error_report in bootdevice.c in PATCH 34.
  5. rebase on the latest qemu master tree.
  6. add 'Reviewed-by' in other patches. (Thanks, Gerd)

>>>
>>>
>>> Hi, Gerd
>>>
>>> Could you please review the v11 and consider to merge this series in your 
>>> tree?
>>> I have no idea which maintainer can apply this series. It seems that only 
>>> you
>>> and Eduardo  interested in and reviewed this patch series at present. :(
>>
>> Yea, for these cross-tree changes it isn't always clear which way they
>> should be merged.  qom or pc would make sense I think.
>>
>> I can prepare a pull request too, but I'd like to have a second opinion
>> on the stuff which is outside of my primary focus:
>>
> 
> Thanks a lot!
> 
>>   * fw_cfg changes (mst?  paolo?)
>>   * qom bits (andreas?  paolo?, eduardo?)

I'll try to look at whatever QOM bits, but I don't have the time to take
another large series myself right now. Not everything using QOM (as
opposed to changing QOM) needs to go through qom-next. :)

Thanks,
Andreas

>>
> 
> I will appreciate for your review, guys :)
> 
> Best regards,
> -Gonglei
> 
>> I'll go take "no answer" as "no objections", but I'd prefer to apply one
>> or another "reviewed-by" to the series.
>>
>> thanks,
>>   Gerd
>>
>>
> 
> 
> 
> 


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



Re: [Qemu-devel] [PATCH v11 04/34] fw_cfg: add fw_cfg_machine_reset function

2014-10-09 Thread Paolo Bonzini
Il 07/10/2014 10:00, arei.gong...@huawei.com ha scritto:
> From: Gonglei 
> 
> We must assure that the changed bootindex can take effect
> when guest is rebooted. So we introduce fw_cfg_machine_reset(),
> which change the fw_cfg file's bootindex data using the new
> global fw_boot_order list.
> 
> Signed-off-by: Chenliang 
> Signed-off-by: Gonglei 
> Reviewed-by: Gerd Hoffmann 
> ---
>  hw/nvram/fw_cfg.c | 55 
> ---
>  include/hw/nvram/fw_cfg.h |  2 ++
>  2 files changed, 54 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> index b71d251..e7ed27e 100644
> --- a/hw/nvram/fw_cfg.c
> +++ b/hw/nvram/fw_cfg.c
> @@ -402,6 +402,26 @@ static void fw_cfg_add_bytes_read_callback(FWCfgState 
> *s, uint16_t key,
>  s->entries[arch][key].callback_opaque = callback_opaque;
>  }
>  
> +static void *fw_cfg_modify_bytes_read(FWCfgState *s, uint16_t key,
> +  void *data, size_t len)
> +{
> +void *ptr;
> +int arch = !!(key & FW_CFG_ARCH_LOCAL);
> +
> +key &= FW_CFG_ENTRY_MASK;
> +
> +assert(key < FW_CFG_MAX_ENTRY && len < UINT32_MAX);
> +
> +/* return the old data to the function caller, avoid memory leak */
> +ptr = s->entries[arch][key].data;
> +s->entries[arch][key].data = data;
> +s->entries[arch][key].len = len;
> +s->entries[arch][key].callback_opaque = NULL;
> +s->entries[arch][key].callback = NULL;
> +
> +return ptr;
> +}
> +
>  void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
>  {
>  fw_cfg_add_bytes_read_callback(s, key, NULL, NULL, data, len);
> @@ -499,13 +519,42 @@ void fw_cfg_add_file(FWCfgState *s,  const char 
> *filename,
>  fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len);
>  }
>  
> -static void fw_cfg_machine_ready(struct Notifier *n, void *data)
> +void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
> +void *data, size_t len)
> +{
> +int i, index;
> +
> +assert(s->files);
> +
> +index = be32_to_cpu(s->files->count);
> +assert(index < FW_CFG_FILE_SLOTS);
> +
> +for (i = 0; i < index; i++) {
> +if (strcmp(filename, s->files->f[i].name) == 0) {
> +return fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i,
> + data, len);
> +}
> +}
> +/* add new one */
> +fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len);
> +return NULL;
> +}
> +
> +static void fw_cfg_machine_reset(void *opaque)
>  {
> +void *ptr;
>  size_t len;
> -FWCfgState *s = container_of(n, FWCfgState, machine_ready);
> +FWCfgState *s = opaque;
>  char *bootindex = get_boot_devices_list(&len, false);
>  
> -fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len);
> +ptr = fw_cfg_modify_file(s, "bootorder", (uint8_t *)bootindex, len);
> +g_free(ptr);
> +}
> +
> +static void fw_cfg_machine_ready(struct Notifier *n, void *data)
> +{
> +FWCfgState *s = container_of(n, FWCfgState, machine_ready);
> +qemu_register_reset(fw_cfg_machine_reset, s);
>  }
>  
>  FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
> diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
> index 72b1549..56e1ed7 100644
> --- a/include/hw/nvram/fw_cfg.h
> +++ b/include/hw/nvram/fw_cfg.h
> @@ -76,6 +76,8 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, 
> void *data,
>  void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
>FWCfgReadCallback callback, void 
> *callback_opaque,
>void *data, size_t len);
> +void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
> + size_t len);
>  FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
>  hwaddr crl_addr, hwaddr data_addr);
>  
> 

Acked-by: Paolo Bonzini 



Re: [Qemu-devel] [PATCH v11 07/34] bootindex: add a setter/getter functions wrapper for bootindex property

2014-10-09 Thread Paolo Bonzini
Il 07/10/2014 10:00, arei.gong...@huawei.com ha scritto:
> From: Gonglei 
> 
> when we remove bootindex form qdev.property to qom.property,
> we can use those functions set/get bootindex property for all
> correlative devices. Meanwhile set the initial value of
> bootindex to -1.
> 
> Signed-off-by: Gonglei 
> Reviewed-by: Gerd Hoffmann 
> ---
>  bootdevice.c| 73 
> +
>  include/sysemu/sysemu.h |  3 ++
>  2 files changed, 76 insertions(+)
> 
> diff --git a/bootdevice.c b/bootdevice.c
> index a38479a..69cffd8 100644
> --- a/bootdevice.c
> +++ b/bootdevice.c
> @@ -23,6 +23,7 @@
>   */
>  
>  #include "sysemu/sysemu.h"
> +#include "qapi/visitor.h"
>  
>  typedef struct FWBootEntry FWBootEntry;
>  
> @@ -178,3 +179,75 @@ char *get_boot_devices_list(size_t *size, bool 
> ignore_suffixes)
>  }
>  return list;
>  }
> +
> +typedef struct {
> +int32_t *bootindex;
> +const char *suffix;
> +DeviceState *dev;
> +} BootIndexProperty;
> +
> +static void device_get_bootindex(Object *obj, Visitor *v, void *opaque,
> + const char *name, Error **errp)
> +{
> +BootIndexProperty *prop = opaque;
> +visit_type_int32(v, prop->bootindex, name, errp);
> +}
> +
> +static void device_set_bootindex(Object *obj, Visitor *v, void *opaque,
> + const char *name, Error **errp)
> +{
> +BootIndexProperty *prop = opaque;
> +int32_t boot_index;
> +Error *local_err = NULL;
> +
> +visit_type_int32(v, &boot_index, name, &local_err);
> +if (local_err) {
> +goto out;
> +}
> +/* check whether bootindex is present in fw_boot_order list  */
> +check_boot_index(boot_index, &local_err);
> +if (local_err) {
> +goto out;
> +}
> +/* change bootindex to a new one */
> +*prop->bootindex = boot_index;
> +
> +out:
> +if (local_err) {
> +error_propagate(errp, local_err);
> +}
> +}
> +
> +static void property_release_bootindex(Object *obj, const char *name,
> +   void *opaque)
> +
> +{
> +BootIndexProperty *prop = opaque;
> +g_free(prop);
> +}
> +
> +void device_add_bootindex_property(Object *obj, int32_t *bootindex,
> +   const char *name, const char *suffix,
> +   DeviceState *dev, Error **errp)
> +{
> +Error *local_err = NULL;
> +BootIndexProperty *prop = g_malloc0(sizeof(*prop));
> +
> +prop->bootindex = bootindex;
> +prop->suffix = suffix;
> +prop->dev = dev;
> +
> +object_property_add(obj, name, "int32",
> +device_get_bootindex,
> +device_set_bootindex,
> +property_release_bootindex,
> +prop, &local_err);
> +
> +if (local_err) {
> +error_propagate(errp, local_err);
> +g_free(prop);
> +return;
> +}
> +/* initialize devices' bootindex property to -1 */
> +object_property_set_int(obj, -1, name, NULL);
> +}
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index b3489be..0037a69 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -215,6 +215,9 @@ char *get_boot_devices_list(size_t *size, bool 
> ignore_suffixes);
>  DeviceState *get_boot_device(uint32_t position);
>  void check_boot_index(int32_t bootindex, Error **errp);
>  void del_boot_device_path(DeviceState *dev, const char *suffix);
> +void device_add_bootindex_property(Object *obj, int32_t *bootindex,
> +   const char *name, const char *suffix,
> +   DeviceState *dev, Error **errp);
>  
>  QemuOpts *qemu_get_machine_opts(void);
>  
> 

Acked-by: Paolo Bonzini 



Re: [Qemu-devel] [PATCH v11 17/34] net: remove bootindex property from qdev to qom

2014-10-09 Thread Paolo Bonzini
Il 07/10/2014 10:00, arei.gong...@huawei.com ha scritto:
> From: Gonglei 
> 
> Remove bootindex form qdev property to qom, things will
> continue to work just fine, and we can use qom features
> which are not supported by qdev property.
> 
> Signed-off-by: Gonglei 
> Reviewed-by: Gerd Hoffmann 
> ---
>  include/net/net.h | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/include/net/net.h b/include/net/net.h
> index ed594f9..008d610 100644
> --- a/include/net/net.h
> +++ b/include/net/net.h
> @@ -36,8 +36,7 @@ typedef struct NICConf {
>  #define DEFINE_NIC_PROPERTIES(_state, _conf)\
>  DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),\
>  DEFINE_PROP_VLAN("vlan", _state, _conf.peers),   \
> -DEFINE_PROP_NETDEV("netdev", _state, _conf.peers),   \
> -DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)
> +DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
>  
>  
>  /* Net clients */
> 

This is a bit of a pity, and it's caused by the different nature of QOM
properties (instance-based) vs. qdev properties (class-based).

I can live with that.

Paolo



Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and take effect after rebooting

2014-10-09 Thread Paolo Bonzini
Il 09/10/2014 11:47, Gerd Hoffmann ha scritto:
> On Mi, 2014-10-08 at 19:00 +0800, Gonglei wrote:
>> On 2014/10/7 16:00, Gonglei (Arei) wrote:
>>
>>> From: Gonglei 
>>>
>>> Changes since v10:
>>>  1. add handler for virtio-blk-pci/s390/ccw in PATCH 28.
>>>  2. add especial bootidnex setter/getter functions for usb-storage
>>> device in PATCH 29.
>>>  3. add bootindex qom property for nvma and ne2k_isa devices,
>>> avoid regrassion in PATCH 30.
>>>  4. change fprintf to error_report in bootdevice.c in PATCH 34.
>>>  5. rebase on the latest qemu master tree.
>>>  6. add 'Reviewed-by' in other patches. (Thanks, Gerd)
>>>
>>
>>
>> Hi, Gerd
>>
>> Could you please review the v11 and consider to merge this series in your 
>> tree?
>> I have no idea which maintainer can apply this series. It seems that only you
>> and Eduardo  interested in and reviewed this patch series at present. :(
> 
> Yea, for these cross-tree changes it isn't always clear which way they
> should be merged.  qom or pc would make sense I think.
> 
> I can prepare a pull request too, but I'd like to have a second opinion
> on the stuff which is outside of my primary focus:
> 
>   * fw_cfg changes (mst?  paolo?)
>   * qom bits (andreas?  paolo?, eduardo?)

I have not been looking at the series, you and Eduardo could do a better
job.  Anyway, I looked at the above pieces and they look good as far as
using/extending the API is concerned.

Paolo

> I'll go take "no answer" as "no objections", but I'd prefer to apply one
> or another "reviewed-by" to the series.
> 
> thanks,
>   Gerd
> 
> 
> 
> 




Re: [Qemu-devel] [PATCH v2 1/1] virtio: serial: expose a 'guest_writable' callback for users

2014-10-09 Thread Markus Armbruster
Amit Shah  writes:

> Users of virtio-serial may want to know when a port becomes writable.  A
> port can stop accepting writes if the guest port is open but not being
> read from.  In this case, data gets queued up in the virtqueue, and
> after the vq is full, writes to the port do not succeed.
>
> When the guest reads off a vq element, and adds a new one for the host
> to put data in, we can tell users the port is available for more writes,
> via the new ->guest_writable() callback.
>
> Signed-off-by: Amit Shah 
>
> ---
> v2: check for port != NULL (Peter Maydell)
> ---
>  hw/char/virtio-serial-bus.c   | 27 +++
>  include/hw/virtio/virtio-serial.h |  3 +++
>  2 files changed, 30 insertions(+)
>
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index 3931085..1c7acbf 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -465,6 +465,33 @@ static void handle_output(VirtIODevice *vdev, VirtQueue 
> *vq)
>  
>  static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
>  {
> +/*
> + * Users of virtio-serial would like to know when guest becomes
> + * writable again -- i.e. if a vq had stuff queued up and the
> + * guest wasn't reading at all, the host would not be able to
> + * write to the vq anymore.  Once the guest reads off something,
> + * we can start queueing things up again.
> + */
> +VirtIOSerial *vser;
> +VirtIOSerialPort *port;
> +VirtIOSerialPortClass *vsc;
> +
> +vser = VIRTIO_SERIAL(vdev);
> +port = find_port_by_vq(vser, vq);
> +
> +if (!port) {
> +return;
> +}
> +vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
> +
> +/*
> + * If guest_connected is false, this call is being made by the
> + * early-boot queueing up of descriptors, which is just noise for
> + * the host apps -- don't disturb them in that case.
> +*/
> +if (port->guest_connected && port->host_connected && 
> vsc->guest_writable) {
> +vsc->guest_writable(port);
> +}
>  }
>  
>  static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
> diff --git a/include/hw/virtio/virtio-serial.h 
> b/include/hw/virtio/virtio-serial.h
> index a679e54..b434f78 100644
> --- a/include/hw/virtio/virtio-serial.h
> +++ b/include/hw/virtio/virtio-serial.h
> @@ -98,6 +98,9 @@ typedef struct VirtIOSerialPortClass {
>  /* Guest is now ready to accept data (virtqueues set up). */
>  void (*guest_ready)(VirtIOSerialPort *port);
>  
> +/* Guest vq became writable again */
> +void (*guest_writable)(VirtIOSerialPort *port);
> +
>  /*
>   * Guest wrote some data to the port. This data is handed over to
>   * the app via this callback.  The app can return a size less than

The code should work, but whether it makes sense is hard to judge for
virtio noobs like me without a user of guest_writable.  The conditional
guarding vsc->guest_writable(port) in particular.

virtio_add_queue()'s callback being undocumented doesn't exactly help,
either.  Fun: the parameter is called handle_output, the argument is
handle_input.  Clear as mud!



Re: [Qemu-devel] [PATCH 0/8] pending s390x patches for 2.2

2014-10-09 Thread Christian Borntraeger
Am 07.10.2014 12:58, schrieb Cornelia Huck:
> Here's what I currently have on
> 
> git://github.com/cohuck/qemu s390-next
> 
> A headers update, cpu state handling in qemu and migration, and a
> vhost-scsi-ccw bugfix. The gdb patch needs further discussion.
> 
> I plan to send a pull request later this week.

FWIW, branch is
Tested-by: Christian Borntraeger 

> 
> Cornelia Huck (1):
>   s390x/virtio-ccw: fix vhost-scsi intialization
> 
> David Hildenbrand (5):
>   s390x/kvm: introduce proper states for s390 cpus
>   s390x/kvm: proper use of the cpu states OPERATING and STOPPED
>   s390x/kvm: propagate s390 cpu state to kvm
>   s390x/kvm: reuse kvm_s390_reset_vcpu() to get rid of ifdefs
>   s390x/kvm: synchronize the cpu state after SIGP (INITIAL) CPU RESET
> 
> Jens Freimann (1):
>   linux-headers: update to 3.17-rc7
> 
> Thomas Huth (1):
>   s390x/migration: migrate CPU state
> 
>  hw/s390x/ipl.c|2 +-
>  hw/s390x/s390-virtio.c|   32 ---
>  hw/s390x/virtio-ccw.c |2 +-
>  linux-headers/asm-mips/kvm_para.h |6 +-
>  linux-headers/asm-powerpc/kvm.h   |2 +
>  linux-headers/asm-x86/kvm.h   |3 +
>  linux-headers/linux/kvm.h |   13 ++-
>  linux-headers/linux/kvm_para.h|3 +
>  linux-headers/linux/vfio.h|   34 
>  linux-headers/linux/vhost.h   |2 +-
>  target-s390x/cpu.c|  168 
> +++--
>  target-s390x/cpu.h|   41 +++--
>  target-s390x/helper.c |   19 ++---
>  target-s390x/kvm.c|   58 +++--
>  trace-events  |6 ++
>  15 files changed, 299 insertions(+), 92 deletions(-)
> 




[Qemu-devel] [question] is it posssible that big-endian l1 table offset referenced by other I/O while updating l1 table offset in qcow2_update_snapshot_refcount?

2014-10-09 Thread Zhang Haoyu
Hi,
I encounter a problem that after deleting snaptshot, the qcow2 image size is 
very larger than that it should be displayed by ls command, 
but the virtual disk size is okay via qemu-img info.
I suspect that during updating l1 table offset, other I/O job reference the 
big-endian l1 table offset (very large value), so the file is truncated to very 
large.
Any ideas?

Thanks,
Zhang Haoyu




[Qemu-devel] [PULL v2 00/28] Changes for 2014-10-29

2014-10-09 Thread Paolo Bonzini
The following changes since commit 1831e150606a221898bf46ffaf0453e9952cbbc4:

  Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging 
(2014-09-30 16:45:35 +0100)

are available in the git repository at:


  git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to c8ee8cb6ed76d49412e5067aa1e3f7ce2d47ce46:

  qemu-char: Fix reconnect socket error reporting (2014-10-09 12:57:31 +0200)


Four changes here.  Polling for reconnection of character devices,
the QOMification of accelerators, a fix for -kernel support on x86, and one
for a recently-introduced virtio-scsi optimization.


Corey Minyard (9):
  qemu-char: Make the filename size for a chardev a #define
  qemu-char: Rework qemu_chr_open_socket() for reconnect
  qemu-char: Move some items into TCPCharDriver
  qemu-char: set socket filename to disconnected when not connected
  qemu-char: Add reconnecting to client sockets
  qemu-char: Print the remote and local addresses for a socket
  qemu-error: Add error_vreport()
  qemu-sockets: Add error to non-blocking connect handler
  qemu-char: Fix reconnect socket error reporting

Eduardo Habkost (17):
  vl.c: Small coding style fix
  accel: Move accel code to accel.c
  accel: Create AccelType typedef
  accel: Simplify configure_accelerator() using AccelType *acc variable
  accel: Move accel name lookup to separate function
  accel: Use QOM classes for accel types
  accel: Make AccelClass.available() optional
  accel: Report unknown accelerator as "not found" instead of "does not 
exist"
  accel: Move KVM accel registration to kvm-all.c
  accel: Move Xen registration code to xen-common.c
  accel: Move qtest accel registration to qtest.c
  accel: Remove tcg_available() function
  accel: Move accel init/allowed code to separate function
  accel: Rename 'init' method to 'init_machine'
  accel: Pass MachineState object to accel init functions
  accel: Create accel object when initializing machine
  kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

Paolo Bonzini (2):
  linuxboot: compute initrd loading address
  virtio-scsi: fix use-after-free of VirtIOSCSIReq

 Makefile.objs |   1 +
 accel.c   | 157 ++
 arch_init.c   |   5 -
 hw/scsi/virtio-scsi.c |   9 +-
 include/hw/boards.h   |   3 +-
 include/hw/xen/xen.h  |   1 -
 include/qemu/error-report.h   |   1 +
 include/qemu/sockets.h|   2 +-
 include/qemu/typedefs.h   |   3 +
 include/sysemu/accel.h|  62 
 include/sysemu/arch_init.h|   1 -
 include/sysemu/kvm.h  |   2 -
 include/sysemu/qtest.h|   1 -
 kvm-all.c |  40 -
 kvm-stub.c|   5 -
 migration-tcp.c   |   4 +-
 migration-unix.c  |   4 +-
 pc-bios/linuxboot.bin | Bin 1024 -> 1024 bytes
 pc-bios/optionrom/linuxboot.S |  47 +-
 pc-bios/optionrom/optionrom.h |  21 ++-
 qapi-schema.json  |  15 +-
 qemu-char.c   | 359 --
 qemu-options.hx   |  20 ++-
 qtest.c   |  27 +++-
 util/qemu-error.c |  23 ++-
 util/qemu-sockets.c   |  20 ++-
 vl.c  |  83 +-
 xen-common-stub.c |   6 -
 xen-common.c  |  25 ++-
 29 files changed, 712 insertions(+), 235 deletions(-)
 create mode 100644 accel.c
 create mode 100644 include/sysemu/accel.h




[Qemu-devel] [PULL v2 21/28] accel: Pass MachineState object to accel init functions

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Most of the machine options and machine state information is in the
MachineState object, not on the MachineClass. This will allow init
functions to use the MachineState object directly instead of
qemu_get_machine_opts() or the current_machine global.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 11 ++-
 include/hw/boards.h |  2 --
 include/qemu/typedefs.h |  1 +
 include/sysemu/accel.h  |  4 ++--
 kvm-all.c   |  3 ++-
 qtest.c |  2 +-
 vl.c|  2 +-
 xen-common.c|  2 +-
 8 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/accel.c b/accel.c
index b151d55..6087ab3 100644
--- a/accel.c
+++ b/accel.c
@@ -24,6 +24,7 @@
  */
 
 #include "sysemu/accel.h"
+#include "hw/boards.h"
 #include "qemu-common.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
@@ -35,7 +36,7 @@
 int tcg_tb_size;
 static bool tcg_allowed = true;
 
-static int tcg_init(MachineClass *mc)
+static int tcg_init(MachineState *ms)
 {
 tcg_exec_init(tcg_tb_size * 1024 * 1024);
 return 0;
@@ -57,18 +58,18 @@ static AccelClass *accel_find(const char *opt_name)
 return ac;
 }
 
-static int accel_init_machine(AccelClass *acc, MachineClass *mc)
+static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
 int ret;
 *(acc->allowed) = true;
-ret = acc->init_machine(mc);
+ret = acc->init_machine(ms);
 if (ret < 0) {
 *(acc->allowed) = false;
 }
 return ret;
 }
 
-int configure_accelerator(MachineClass *mc)
+int configure_accelerator(MachineState *ms)
 {
 const char *p;
 char buf[10];
@@ -98,7 +99,7 @@ int configure_accelerator(MachineClass *mc)
acc->name);
 continue;
 }
-ret = accel_init_machine(acc, mc);
+ret = accel_init_machine(acc, ms);
 if (ret < 0) {
 init_failed = true;
 fprintf(stderr, "failed to initialize %s: %s\n",
diff --git a/include/hw/boards.h b/include/hw/boards.h
index dfb6718..0058c49 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -9,8 +9,6 @@
 #include "qom/object.h"
 
 
-typedef struct MachineState MachineState;
-
 typedef void QEMUMachineInitFunc(MachineState *ms);
 
 typedef void QEMUMachineResetFunc(void);
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 5f20b0e..04df51b 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -32,6 +32,7 @@ typedef struct MemoryMappingList MemoryMappingList;
 
 typedef struct QEMUMachine QEMUMachine;
 typedef struct MachineClass MachineClass;
+typedef struct MachineState MachineState;
 typedef struct NICInfo NICInfo;
 typedef struct HCIInfo HCIInfo;
 typedef struct AudioState AudioState;
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 8812cda..997720f 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -39,7 +39,7 @@ typedef struct AccelClass {
 const char *opt_name;
 const char *name;
 int (*available)(void);
-int (*init_machine)(MachineClass *mc);
+int (*init_machine)(MachineState *ms);
 bool *allowed;
 } AccelClass;
 
@@ -57,6 +57,6 @@ typedef struct AccelClass {
 
 extern int tcg_tb_size;
 
-int configure_accelerator(MachineClass *mc);
+int configure_accelerator(MachineState *ms);
 
 #endif
diff --git a/kvm-all.c b/kvm-all.c
index ce0e4c7..0a9de92 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1380,8 +1380,9 @@ static int kvm_max_vcpus(KVMState *s)
 return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-static int kvm_init(MachineClass *mc)
+static int kvm_init(MachineState *ms)
 {
+MachineClass *mc = MACHINE_GET_CLASS(ms);
 static const char upgrade_note[] =
 "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
 "(see http://sourceforge.net/projects/kvm).\n";
diff --git a/qtest.c b/qtest.c
index 18e26fc..4b85995 100644
--- a/qtest.c
+++ b/qtest.c
@@ -520,7 +520,7 @@ static void configure_qtest_icount(const char *options)
 qemu_opts_del(opts);
 }
 
-static int qtest_init_accel(MachineClass *mc)
+static int qtest_init_accel(MachineState *ms)
 {
 configure_qtest_icount("0");
 return 0;
diff --git a/vl.c b/vl.c
index c3def21..020b7c3 100644
--- a/vl.c
+++ b/vl.c
@@ -4179,7 +4179,7 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
-configure_accelerator(machine_class);
+configure_accelerator(current_machine);
 
 if (qtest_chrdev) {
 Error *local_err = NULL;
diff --git a/xen-common.c b/xen-common.c
index acb738f..56359ca 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -110,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int 
running,
 }
 }
 
-static int xen_init(MachineClass *mc)
+static int xen_init(MachineState *ms)
 {
 xen_xc = xen_xc_interface_open(0, 0, 0);
 if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
-- 
1.8.3.1





Re: [Qemu-devel] [PATCH v5 0/5] add description field in ObjectProperty and PropertyInfo struct

2014-10-09 Thread Gonglei
Andreas, ping?

Best regards,
-Gonglei

> -Original Message-
> From: qemu-devel-bounces+arei.gonglei=hotmail@nongnu.org
> [mailto:qemu-devel-bounces+arei.gonglei=hotmail@nongnu.org] On
> Behalf Of Gonglei
> Sent: Wednesday, October 08, 2014 6:46 PM
> To: Paolo Bonzini
> Cc: Huangweidong (C); m...@redhat.com; Luonengjun; arm...@redhat.com;
> qemu-devel@nongnu.org; Huangpeng (Peter); lcapitul...@redhat.com;
> afaer...@suse.de
> Subject: Re: [Qemu-devel] [PATCH v5 0/5] add description field in
> ObjectProperty and PropertyInfo struct
> 
> On 2014/10/8 6:22, Paolo Bonzini wrote:
> 
> > Il 07/10/2014 08:33, arei.gong...@huawei.com ha scritto:
> >> From: Gonglei 
> >>
> >> v5 -> v4:
> >>  1. add some improvements by Michael's suggtion, Thanks. (Michael)
> >>  2. add 'Reviewed-by' tag (Paolo, Michael, Eric)
> >
> > Andreas, this series depends on patches in qom-next so you'll have to
> > take it.
> >
> 
> Yes, please. Thanks!
> 
> Best regards,
> -Gonglei
> 
> > Thanks,
> >
> > Paolo
> >
> >> v4 -> v3:
> >>  1. rebase on qom-next tree (Andreas)
> >>  2. fix memory leak in PATCH 2, move object_property_set_description
> calling
> >> in object_property_add_alias() from PATCH 3 to PATCH 2. (Paolo)
> >>  3. drop "?:" in PATCH 2, call g_strdup() directly
> >>  4. rework PATCH 4, change description as optional field,
> >> drop "?:" conditional express (Eric)
> >>
> >> v3 -> v2:
> >>  1. add a new "description" field to DevicePropertyInfo, and format
> >> it in qdev_device_help() in PATCH 6 (Paolo)
> >>
> >> v2 -> v1:
> >>  1. rename "fail" label to "out" in PATCH 1 (Andreas)
> >>  2. improve descriptions in PATCH 3 (Paolo, adding Signed-off-by Paolo in
> this patch)
> >>  3. rework PATCH 5, set description at qdev_property_add_static(),
> >> then copy the description of target_obj.property. (Paolo)
> >>  4. free description filed of ObjectProperty avoid memory leak in PATCH 4.
> >>
> >> This patch series based on qom-next tree:
> >>  https://github.com/afaerber/qemu-cpu/commits/qom-next
> >>
> >> Add a description field in both ObjectProperty and PropertyInfo struct.
> >> The descriptions can serve as documentation in the code,
> >> and they can be used to provide better help. For example:
> >>
> >> Before this patch series:
> >>
> >> $./qemu-system-x86_64 -device virtio-blk-pci,?
> >>
> >> virtio-blk-pci.iothread=link
> >> virtio-blk-pci.x-data-plane=bool
> >> virtio-blk-pci.scsi=bool
> >> virtio-blk-pci.config-wce=bool
> >> virtio-blk-pci.serial=str
> >> virtio-blk-pci.secs=uint32
> >> virtio-blk-pci.heads=uint32
> >> virtio-blk-pci.cyls=uint32
> >> virtio-blk-pci.discard_granularity=uint32
> >> virtio-blk-pci.bootindex=int32
> >> virtio-blk-pci.opt_io_size=uint32
> >> virtio-blk-pci.min_io_size=uint16
> >> virtio-blk-pci.physical_block_size=uint16
> >> virtio-blk-pci.logical_block_size=uint16
> >> virtio-blk-pci.drive=str
> >> virtio-blk-pci.virtio-backend=child
> >> virtio-blk-pci.command_serr_enable=on/off
> >> virtio-blk-pci.multifunction=on/off
> >> virtio-blk-pci.rombar=uint32
> >> virtio-blk-pci.romfile=str
> >> virtio-blk-pci.addr=pci-devfn
> >> virtio-blk-pci.event_idx=on/off
> >> virtio-blk-pci.indirect_desc=on/off
> >> virtio-blk-pci.vectors=uint32
> >> virtio-blk-pci.ioeventfd=on/off
> >> virtio-blk-pci.class=uint32
> >>
> >> After:
> >>
> >> $./qemu-system-x86_64 -device virtio-blk-pci,?
> >>
> >> virtio-blk-pci.iothread=link
> >> virtio-blk-pci.x-data-plane=bool (on/off)
> >> virtio-blk-pci.scsi=bool (on/off)
> >> virtio-blk-pci.config-wce=bool (on/off)
> >> virtio-blk-pci.serial=str
> >> virtio-blk-pci.secs=uint32
> >> virtio-blk-pci.heads=uint32
> >> virtio-blk-pci.cyls=uint32
> >> virtio-blk-pci.discard_granularity=uint32
> >> virtio-blk-pci.bootindex=int32
> >> virtio-blk-pci.opt_io_size=uint32
> >> virtio-blk-pci.min_io_size=uint16
> >> virtio-blk-pci.physical_block_size=uint16 (A power of two between 512 and
> 32768)
> >> virtio-blk-pci.logical_block_size=uint16 (A power of two between 512 and
> 32768)
> >> virtio-blk-pci.drive=str (ID of a drive to use as a backend)
> >> virtio-blk-pci.virtio-backend=child
> >> virtio-blk-pci.command_serr_enable=bool (on/off)
> >> virtio-blk-pci.multifunction=bool (on/off)
> >> virtio-blk-pci.rombar=uint32
> >> virtio-blk-pci.romfile=str
> >> virtio-blk-pci.addr=int32 (Slot and optional function number, example: 06.0
> or 06)
> >> virtio-blk-pci.event_idx=bool (on/off)
> >> virtio-blk-pci.indirect_desc=bool (on/off)
> >> virtio-blk-pci.vectors=uint32
> >> virtio-blk-pci.ioeventfd=bool (on/off)
> >> virtio-blk-pci.class=uint32
> >>
> >>
> >> Gonglei (5):
> >>   qdev: add description field in PropertyInfo struct
> >>   qom: add description field in ObjectProperty struct
> >>   qdev: set the object property's description to the qdev property's.
> >>   qmp: print descriptions of object properties
> >>   qdev: drop legacy_name from qdev properties
> >>
> >>  hw/core/qdev-properties-system.c |  8 
> >>  hw/core/qdev-properties.c 

Re: [Qemu-devel] [PATCH v11 17/34] net: remove bootindex property from qdev to qom

2014-10-09 Thread Gonglei
> Subject: Re: [Qemu-devel] [PATCH v11 17/34] net: remove bootindex property
> from qdev to qom
> 
> Il 07/10/2014 10:00, arei.gong...@huawei.com ha scritto:
> > From: Gonglei 
> >
> > Remove bootindex form qdev property to qom, things will
> > continue to work just fine, and we can use qom features
> > which are not supported by qdev property.
> >
> > Signed-off-by: Gonglei 
> > Reviewed-by: Gerd Hoffmann 
> > ---
> >  include/net/net.h | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/include/net/net.h b/include/net/net.h
> > index ed594f9..008d610 100644
> > --- a/include/net/net.h
> > +++ b/include/net/net.h
> > @@ -36,8 +36,7 @@ typedef struct NICConf {
> >  #define DEFINE_NIC_PROPERTIES(_state, _conf)
> \
> >  DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),
> \
> >  DEFINE_PROP_VLAN("vlan", _state, _conf.peers),
> \
> > -DEFINE_PROP_NETDEV("netdev", _state, _conf.peers),
> \
> > -DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)
> > +DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
> >
> >
> >  /* Net clients */
> >
> 
> This is a bit of a pity, and it's caused by the different nature of QOM
> properties (instance-based) vs. qdev properties (class-based).
> 
> I can live with that.
> 
> Paolo

Hmm... Thanks :)

Best regards,
-Gonglei




Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and take effect after rebooting

2014-10-09 Thread Gonglei
> Subject: Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and
> take effect after rebooting
> 
> On Thu, 09 Oct 2014 11:47:12 +0200
> Gerd Hoffmann  wrote:
> 
> > On Mi, 2014-10-08 at 19:00 +0800, Gonglei wrote:
> > > On 2014/10/7 16:00, Gonglei (Arei) wrote:
> > >
> > > > From: Gonglei 
> > > >
> > > > Changes since v10:
> > > >  1. add handler for virtio-blk-pci/s390/ccw in PATCH 28.
> > > >  2. add especial bootidnex setter/getter functions for usb-storage
> > > > device in PATCH 29.
> > > >  3. add bootindex qom property for nvma and ne2k_isa devices,
> > > > avoid regrassion in PATCH 30.
> > > >  4. change fprintf to error_report in bootdevice.c in PATCH 34.
> > > >  5. rebase on the latest qemu master tree.
> > > >  6. add 'Reviewed-by' in other patches. (Thanks, Gerd)
> > > >
> > >
> > >
> > > Hi, Gerd
> > >
> > > Could you please review the v11 and consider to merge this series in your
> tree?
> > > I have no idea which maintainer can apply this series. It seems that only 
> > > you
> > > and Eduardo  interested in and reviewed this patch series at present. :(
> >
> > Yea, for these cross-tree changes it isn't always clear which way they
> > should be merged.  qom or pc would make sense I think.
> >
> > I can prepare a pull request too, but I'd like to have a second opinion
> > on the stuff which is outside of my primary focus:
> >
> >   * fw_cfg changes (mst?  paolo?)
> >   * qom bits (andreas?  paolo?, eduardo?)
> >
> > I'll go take "no answer" as "no objections", but I'd prefer to apply one
> > or another "reviewed-by" to the series.
> >
> > thanks,
> >   Gerd
> >
> 
> The s390x team is planning to use some functionality of this patch set as base
> for diag308
> implementation. I'll give v11 a try on our platform.
> 
> Michael
> 
Great! 

Please let us know your results. Thanks :)

Best regards,
-Gonglei




Re: [Qemu-devel] [PATCH v2 1/1] virtio: serial: expose a 'guest_writable' callback for users

2014-10-09 Thread Amit Shah
On (Thu) 09 Oct 2014 [13:18:16], Markus Armbruster wrote:
> Amit Shah  writes:
> 
> > Users of virtio-serial may want to know when a port becomes writable.  A
> > port can stop accepting writes if the guest port is open but not being
> > read from.  In this case, data gets queued up in the virtqueue, and
> > after the vq is full, writes to the port do not succeed.
> >
> > When the guest reads off a vq element, and adds a new one for the host
> > to put data in, we can tell users the port is available for more writes,
> > via the new ->guest_writable() callback.
> >
> > Signed-off-by: Amit Shah 
> >
> > ---
> > v2: check for port != NULL (Peter Maydell)
> > ---
> >  hw/char/virtio-serial-bus.c   | 27 +++
> >  include/hw/virtio/virtio-serial.h |  3 +++
> >  2 files changed, 30 insertions(+)
> >
> > diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> > index 3931085..1c7acbf 100644
> > --- a/hw/char/virtio-serial-bus.c
> > +++ b/hw/char/virtio-serial-bus.c
> > @@ -465,6 +465,33 @@ static void handle_output(VirtIODevice *vdev, 
> > VirtQueue *vq)
> >  
> >  static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
> >  {
> > +/*
> > + * Users of virtio-serial would like to know when guest becomes
> > + * writable again -- i.e. if a vq had stuff queued up and the
> > + * guest wasn't reading at all, the host would not be able to
> > + * write to the vq anymore.  Once the guest reads off something,
> > + * we can start queueing things up again.
> > + */
> > +VirtIOSerial *vser;
> > +VirtIOSerialPort *port;
> > +VirtIOSerialPortClass *vsc;
> > +
> > +vser = VIRTIO_SERIAL(vdev);
> > +port = find_port_by_vq(vser, vq);
> > +
> > +if (!port) {
> > +return;
> > +}
> > +vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
> > +
> > +/*
> > + * If guest_connected is false, this call is being made by the
> > + * early-boot queueing up of descriptors, which is just noise for
> > + * the host apps -- don't disturb them in that case.
> > +*/
> > +if (port->guest_connected && port->host_connected && 
> > vsc->guest_writable) {
> > +vsc->guest_writable(port);
> > +}
> >  }
> >  
> >  static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
> > diff --git a/include/hw/virtio/virtio-serial.h 
> > b/include/hw/virtio/virtio-serial.h
> > index a679e54..b434f78 100644
> > --- a/include/hw/virtio/virtio-serial.h
> > +++ b/include/hw/virtio/virtio-serial.h
> > @@ -98,6 +98,9 @@ typedef struct VirtIOSerialPortClass {
> >  /* Guest is now ready to accept data (virtqueues set up). */
> >  void (*guest_ready)(VirtIOSerialPort *port);
> >  
> > +/* Guest vq became writable again */
> > +void (*guest_writable)(VirtIOSerialPort *port);
> > +
> >  /*
> >   * Guest wrote some data to the port. This data is handed over to
> >   * the app via this callback.  The app can return a size less than
> 
> The code should work, but whether it makes sense is hard to judge for
> virtio noobs like me without a user of guest_writable.  The conditional
> guarding vsc->guest_writable(port) in particular.

Right.  This was originally requested by the spice folks, and they
don't yet have a user implemented (waiting for the spice-char
implementation).  But Peter came up with a user; so I posted this w/o
the spice part of it.  But looks like Peter has lost the code for his
user, so this patch will have to wait ;-)

> virtio_add_queue()'s callback being undocumented doesn't exactly help,
> either.  Fun: the parameter is called handle_output, the argument is
> handle_input.  Clear as mud!

Yea - some things in virtio are from the guest's POV so it makes these
things really confusing in qemu.

Amit



[Qemu-devel] [Bug 1354167] Re: On VM restart: Could not open 'poppy.qcow2': Could not read snapshots: File too large

2014-10-09 Thread Rob Schultz
I had the exact same issue with a VM after upgrading the host from 12.04
to 14.04.

Thank you Todd for the workaround. It would have been more work than I
cared for to reassemble that machine (even if it was just a test
machine).

I'm not sure what the status of this bug is? Is this something that is
already fixed but was an exisiting issue from a previous version?

I've attached the qemu-img I compiled. It may help someone else recover
a bit quicker - getting everything in place to compile the binary wasted
a good couple of hours as I had to modify several dependancies, install
additional packages, etc. But of course, the safer method is to build
yourself.

FWIW I had to install:
 sudo apt-get install autoconf automake autopoint autotools-dev dh-autoreconf 
libltdl-dev libtool m4 libglib2.0-0-dbg  libglib2.0-bin libglib2.0-dev 
libpcre3-dev libpcrecpp0

( I think I could have just done autoconf rather than dh-autoreconf)

After the installation of libglib2.0-0-dbg remember to re-run
./configure

If you compile yourself you can kill the make process after the build of
the qemu-img binary.



** Attachment added: "qemu-img version 1.7.2 compiled on Ubuntu Trusty Thar 
(Ubuntu 14.04.1 LTS)"
   
https://bugs.launchpad.net/qemu/+bug/1354167/+attachment/4229538/+files/qemu-img

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

Title:
  On VM restart: Could not open 'poppy.qcow2': Could not read snapshots:
  File too large

Status in QEMU:
  New

Bug description:
  I'm unable to restart a VM.   virt-manager is giving me:

  Error starting domain: internal error: process exited while connecting
  to monitor: qemu-system-x86_64: -drive
  file=/var/lib/libvirt/images/poppy.qcow2,if=none,id=drive-virtio-
  disk0,format=qcow2: could not open disk image
  /var/lib/libvirt/images/poppy.qcow2: Could not read snapshots: File
  too large

  
  From the command line trying to check the image also gives me:
  qemu-img check poppy.qcow2
  qemu-img: Could not open 'poppy.qcow2': Could not read snapshots: File too 
large

  
  This bug appears with both the default install of qemu for ubuntu 14.04:
  qemu-img version 2.0.0, Copyright (c) 2004-2008 Fabrice Bellard

  And the latest version.
  qemu-img version 2.1.50, Copyright (c) 2004-2008 Fabrice Bellard

  
  Host: 
  Dual E5-2650 v2 @ 2.60GHz
  32GB Memory
  4TB Disk space (2.1TB Free) 

  Host OS: Ubuntu 14.04.1 LTS 64bit

  Guest:
  Ubuntu 14.04 64bit
  Storage Size: 500gb

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



[Qemu-devel] [PATCH v4] pc-dimm/numa: Fix stat of memory size in node when hotplug memory

2014-10-09 Thread zhanghailiang
When do memory hotplug, if there is numa node, we should add
the memory size to the corresponding node memory size.

For now, it mainly affects the result of hmp command "info numa".

Signed-off-by: zhanghailiang 
---
 v4:
- s/pc_dimm_stat_node_mem/numa_stat_memory_devices/ (Igor Mammedov)
- rewrite numa_stat_memory_devices as Igor's suggestion, and this will also fix 
compile 
  error for targets that don't support memory hotplug
 v3:
- cold-plugged memory should not be excluded (Igor Mammedov)
 v2:
- Don't modify the numa_info.node_mem directly when treating hotplug memory,
  fix the "info numa" instead (Igor Mammedov)

Thanks for review!;)
---
 include/sysemu/sysemu.h |  1 +
 monitor.c   |  6 +-
 numa.c  | 43 +++
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..cfc1592 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -160,6 +160,7 @@ typedef struct node_info {
 extern NodeInfo numa_info[MAX_NODES];
 void set_numa_nodes(void);
 void set_numa_modes(void);
+int query_numa_node_mem(uint64_t *node_mem);
 extern QemuOptsList qemu_numa_opts;
 int numa_init_func(QemuOpts *opts, void *opaque);
 
diff --git a/monitor.c b/monitor.c
index 2d14f39..d45b0a3 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1949,7 +1949,10 @@ static void do_info_numa(Monitor *mon, const QDict 
*qdict)
 {
 int i;
 CPUState *cpu;
+uint64_t *node_mem;
 
+node_mem = g_new0(uint64_t, nb_numa_nodes);
+query_numa_node_mem(node_mem);
 monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
 for (i = 0; i < nb_numa_nodes; i++) {
 monitor_printf(mon, "node %d cpus:", i);
@@ -1960,8 +1963,9 @@ static void do_info_numa(Monitor *mon, const QDict *qdict)
 }
 monitor_printf(mon, "\n");
 monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
-numa_info[i].node_mem >> 20);
+   node_mem[i] >> 20);
 }
+g_free(node_mem);
 }
 
 #ifdef CONFIG_PROFILER
diff --git a/numa.c b/numa.c
index 3b98135..f8ea327 100644
--- a/numa.c
+++ b/numa.c
@@ -35,6 +35,7 @@
 #include "hw/boards.h"
 #include "sysemu/hostmem.h"
 #include "qmp-commands.h"
+#include "hw/mem/pc-dimm.h"
 
 QemuOptsList qemu_numa_opts = {
 .name = "numa",
@@ -315,6 +316,48 @@ void memory_region_allocate_system_memory(MemoryRegion 
*mr, Object *owner,
 }
 }
 
+static void numa_stat_memory_devices(uint64_t *node_mem)
+{
+MemoryDeviceInfoList *info_list = NULL;
+MemoryDeviceInfoList **prev = &info_list;
+MemoryDeviceInfoList *info;
+
+qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
+for (info = info_list; info; info = info->next) {
+MemoryDeviceInfo *value = info->value;
+
+if (value) {
+switch (value->kind) {
+case MEMORY_DEVICE_INFO_KIND_DIMM:{
+PCDIMMDeviceInfo *di = value->dimm;
+
+node_mem[di->node] += di->size;
+break;
+}
+default:
+break;
+}
+}
+}
+
+qapi_free_MemoryDeviceInfoList(info_list);
+}
+
+int query_numa_node_mem(uint64_t *node_mem)
+{
+int i;
+
+if (nb_numa_nodes <= 0) {
+return 0;
+}
+
+numa_stat_memory_devices(node_mem);
+for (i = 0; i < nb_numa_nodes; i++) {
+node_mem[i] += numa_info[i].node_mem;
+}
+return 0;
+}
+
 static int query_memdev(Object *obj, void *opaque)
 {
 MemdevList **list = opaque;
-- 
1.7.12.4





Re: [Qemu-devel] NBD TLS support in QEMU

2014-10-09 Thread Paolo Bonzini
Il 08/10/2014 20:16, Wouter Verhelst ha scritto:
> @@ -242,10 +242,13 @@ Option types
>  * NBD_OPT_EXPORT_NAME (1)
>Choose the export which the client would like to use, and end option
>haggling. Data: name of the export, free-form UTF8 text (subject to
>limitations by server implementation). If the chosen export does not
>exist, the server closes the connection.
> +  A special, "empty", name (i.e., the length field is zero and no name
> +  is specified), is reserved for a "default" export, to be used in cases
> +  where explicitly specifying an export name makes no sense.

Thanks, this looks good!

Paolo



[Qemu-devel] [PATCH] arm_gic: remove unused parameter.

2014-10-09 Thread fred . konrad
From: KONRAD Frederic 

This removes num_irq parameter from gic_init_irqs_and_distributor as it is not
used.

Signed-off-by: KONRAD Frederic 
---
 hw/intc/arm_gic.c  | 4 ++--
 hw/intc/armv7m_nvic.c  | 2 +-
 hw/intc/gic_internal.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
index db9110c..270ce05 100644
--- a/hw/intc/arm_gic.c
+++ b/hw/intc/arm_gic.c
@@ -769,7 +769,7 @@ static const MemoryRegionOps gic_cpu_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-void gic_init_irqs_and_distributor(GICState *s, int num_irq)
+void gic_init_irqs_and_distributor(GICState *s)
 {
 SysBusDevice *sbd = SYS_BUS_DEVICE(s);
 int i;
@@ -808,7 +808,7 @@ static void arm_gic_realize(DeviceState *dev, Error **errp)
 return;
 }
 
-gic_init_irqs_and_distributor(s, s->num_irq);
+gic_init_irqs_and_distributor(s);
 
 /* Memory regions for the CPU interfaces (NVIC doesn't have these):
  * a region for "CPU interface for this core", then a region for
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
index 1a7af45..d0543d4 100644
--- a/hw/intc/armv7m_nvic.c
+++ b/hw/intc/armv7m_nvic.c
@@ -488,7 +488,7 @@ static void armv7m_nvic_realize(DeviceState *dev, Error 
**errp)
 error_propagate(errp, local_err);
 return;
 }
-gic_init_irqs_and_distributor(&s->gic, s->num_irq);
+gic_init_irqs_and_distributor(&s->gic);
 /* The NVIC and system controller register area looks like this:
  *  0..0xff : system control registers, including systick
  *  0x100..0xcff : GIC-like registers
diff --git a/hw/intc/gic_internal.h b/hw/intc/gic_internal.h
index 48a58d7..e87ef36 100644
--- a/hw/intc/gic_internal.h
+++ b/hw/intc/gic_internal.h
@@ -59,7 +59,7 @@ void gic_set_pending_private(GICState *s, int cpu, int irq);
 uint32_t gic_acknowledge_irq(GICState *s, int cpu);
 void gic_complete_irq(GICState *s, int cpu, int irq);
 void gic_update(GICState *s);
-void gic_init_irqs_and_distributor(GICState *s, int num_irq);
+void gic_init_irqs_and_distributor(GICState *s);
 void gic_set_priority(GICState *s, int cpu, int irq, uint8_t val);
 
 static inline bool gic_test_pending(GICState *s, int irq, int cm)
-- 
1.9.0




Re: [Qemu-devel] [PATCH v2 1/1] virtio: serial: expose a 'guest_writable' callback for users

2014-10-09 Thread Peter Maydell
On 9 October 2014 13:17, Amit Shah  wrote:
> On (Thu) 09 Oct 2014 [13:18:16], Markus Armbruster wrote:
>> The code should work, but whether it makes sense is hard to judge for
>> virtio noobs like me without a user of guest_writable.  The conditional
>> guarding vsc->guest_writable(port) in particular.
>
> Right.  This was originally requested by the spice folks, and they
> don't yet have a user implemented (waiting for the spice-char
> implementation).  But Peter came up with a user; so I posted this w/o
> the spice part of it.  But looks like Peter has lost the code for his
> user, so this patch will have to wait ;-)

I have the QEMU code...

https://git.linaro.org/people/peter.maydell/qemu-arm.git/patch/33895359ddee3696bb24eac24cf8ee4cd697c72c

...I just lost the bit of userspace code I was using to test it
It's not very interesting as a use case though since it's
just an echo-back-everything-you-say test backend (but it
does demonstrate that there are basic things you can't do
at all without some variation on this API).

What I would like to see in this patch is a comment giving
much clearer definition of the semantics of the guest_writable
call: for instance, is it always called when the guest is
writable, or is it only guaranteed to be called if the
QEMU backend has previously tried to do virtio_serial_write
and got back a return code indicating an incomplete write?

thanks
-- PMM



Re: [Qemu-devel] [PULL v2 00/28] Changes for 2014-10-29

2014-10-09 Thread Peter Maydell
On 9 October 2014 12:40, Paolo Bonzini  wrote:
> The following changes since commit 1831e150606a221898bf46ffaf0453e9952cbbc4:
>
>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into 
> staging (2014-09-30 16:45:35 +0100)
>
> are available in the git repository at:
>
>
>   git://github.com/bonzini/qemu.git tags/for-upstream
>
> for you to fetch changes up to c8ee8cb6ed76d49412e5067aa1e3f7ce2d47ce46:
>
>   qemu-char: Fix reconnect socket error reporting (2014-10-09 12:57:31 +0200)

This one falls over a bit later on:

In file included from /home/petmay01/linaro/qemu-for-merges/vl.c:64:
/home/petmay01/linaro/qemu-for-merges/include/sysemu/accel.h:32:
error: redefinition of typedef ‘AccelState’
/home/petmay01/linaro/qemu-for-merges/include/qemu/typedefs.h:33:
error: previous declaration of ‘AccelState’ was here

'make -k' says that's the last one, though.

thanks
-- PMM



[Qemu-devel] [PULL 2/8] s390x/kvm: introduce proper states for s390 cpus

2014-10-09 Thread Cornelia Huck
From: David Hildenbrand 

Until now, when a s390 cpu was stopped or halted, the number of running
CPUs was tracked in a global variable. This was problematic for migration,
so Jason came up with a per-cpu running state.
As it turns out, we want to track the full logical state of a target vcpu,
so we need real s390 cpu states.

This patch is based on an initial patch by Jason Herne, but was heavily
rewritten when adding the cpu states STOPPED and OPERATING. On the way we
move add_del_running to cpu.c (the declaration is already in cpu.h) and
modify the users where appropriate.

Please note that the cpu is still set to be stopped when it is
halted, which is wrong. This will be fixed in the next patch. The LOAD and
CHECK-STOP state will not be used in the first step.

Signed-off-by: David Hildenbrand 
[folded Jason's patch into David's patch to avoid add/remove same lines]
Signed-off-by: Jens Freimann 
Reviewed-by: Cornelia Huck 
Reviewed-by: Christian Borntraeger 
CC: Andreas Faerber 
Tested-by: Christian Borntraeger 
Signed-off-by: Cornelia Huck 
---
 hw/s390x/s390-virtio.c |   32 
 target-s390x/cpu.c |   43 +++
 target-s390x/cpu.h |   14 ++
 3 files changed, 57 insertions(+), 32 deletions(-)

diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index 9c61246..af0004a 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -125,38 +125,6 @@ static void s390_virtio_register_hcalls(void)
s390_virtio_hcall_set_status);
 }
 
-/*
- * The number of running CPUs. On s390 a shutdown is the state of all CPUs
- * being either stopped or disabled (for interrupts) waiting. We have to
- * track this number to call the shutdown sequence accordingly. This
- * number is modified either on startup or while holding the big qemu lock.
- */
-static unsigned s390_running_cpus;
-
-void s390_add_running_cpu(S390CPU *cpu)
-{
-CPUState *cs = CPU(cpu);
-
-if (cs->halted) {
-s390_running_cpus++;
-cs->halted = 0;
-cs->exception_index = -1;
-}
-}
-
-unsigned s390_del_running_cpu(S390CPU *cpu)
-{
-CPUState *cs = CPU(cpu);
-
-if (cs->halted == 0) {
-assert(s390_running_cpus >= 1);
-s390_running_cpus--;
-cs->halted = 1;
-cs->exception_index = EXCP_HLT;
-}
-return s390_running_cpus;
-}
-
 void s390_init_ipl_dev(const char *kernel_filename,
const char *kernel_cmdline,
const char *initrd_filename,
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 2cfeb82..03cab74 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -229,6 +229,49 @@ static void s390_cpu_finalize(Object *obj)
 #endif
 }
 
+#if !defined(CONFIG_USER_ONLY)
+static unsigned s390_count_running_cpus(void)
+{
+CPUState *cpu;
+int nr_running = 0;
+
+CPU_FOREACH(cpu) {
+uint8_t state = S390_CPU(cpu)->env.cpu_state;
+if (state == CPU_STATE_OPERATING ||
+state == CPU_STATE_LOAD) {
+nr_running++;
+}
+}
+
+return nr_running;
+}
+
+void s390_add_running_cpu(S390CPU *cpu)
+{
+CPUState *cs = CPU(cpu);
+
+if (cs->halted) {
+cpu->env.cpu_state = CPU_STATE_OPERATING;
+cs->halted = 0;
+cs->exception_index = -1;
+}
+}
+
+unsigned s390_del_running_cpu(S390CPU *cpu)
+{
+CPUState *cs = CPU(cpu);
+
+if (cs->halted == 0) {
+assert(s390_count_running_cpus() >= 1);
+cpu->env.cpu_state = CPU_STATE_STOPPED;
+cs->halted = 1;
+cs->exception_index = EXCP_HLT;
+}
+
+return s390_count_running_cpus();
+}
+#endif
+
 static const VMStateDescription vmstate_s390_cpu = {
 .name = "cpu",
 .unmigratable = 1,
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 62940c3..f1a3ad2 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -141,6 +141,20 @@ typedef struct CPUS390XState {
 QEMUTimer *tod_timer;
 
 QEMUTimer *cpu_timer;
+
+/*
+ * The cpu state represents the logical state of a cpu. In contrast to 
other
+ * architectures, there is a difference between a halt and a stop on s390.
+ * If all cpus are either stopped (including check stop) or in the disabled
+ * wait state, the vm can be shut down.
+ */
+#define CPU_STATE_UNINITIALIZED0x00
+#define CPU_STATE_STOPPED  0x01
+#define CPU_STATE_CHECK_STOP   0x02
+#define CPU_STATE_OPERATING0x03
+#define CPU_STATE_LOAD 0x04
+uint8_t cpu_state;
+
 } CPUS390XState;
 
 #include "cpu-qom.h"
-- 
1.7.9.5




[Qemu-devel] [PULL 6/8] s390x/kvm: synchronize the cpu state after SIGP (INITIAL) CPU RESET

2014-10-09 Thread Cornelia Huck
From: David Hildenbrand 

We need to synchronize registers after a reset has been performed. The
current code does that in qemu_system_reset(), load_normal_reset() and
modified_clear_reset() for all vcpus. After SIGP (INITIAL) CPU RESET,
this needs to be done for the targeted vcpu as well, so let's call
cpu_synchronize_post_reset() in the respective handlers.

Signed-off-by: David Hildenbrand 
Signed-off-by: Jens Freimann 
Reviewed-by: Cornelia Huck 
CC: Andreas Faerber 
Tested-by: Christian Borntraeger 
Signed-off-by: Cornelia Huck 
---
 target-s390x/kvm.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index e4c4c8d..5b10a25 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -952,6 +952,7 @@ static void sigp_initial_cpu_reset(void *arg)
 
 cpu_synchronize_state(cpu);
 scc->initial_cpu_reset(cpu);
+cpu_synchronize_post_reset(cpu);
 }
 
 static void sigp_cpu_reset(void *arg)
@@ -961,6 +962,7 @@ static void sigp_cpu_reset(void *arg)
 
 cpu_synchronize_state(cpu);
 scc->cpu_reset(cpu);
+cpu_synchronize_post_reset(cpu);
 }
 
 #define SIGP_ORDER_MASK 0x00ff
-- 
1.7.9.5




[Qemu-devel] [PULL 5/8] s390x/kvm: reuse kvm_s390_reset_vcpu() to get rid of ifdefs

2014-10-09 Thread Cornelia Huck
From: David Hildenbrand 

This patch reuses kvm_s390_reset_vcpu() to get rid of some CONFIG_KVM and
CONFIG_USER_ONLY ifdefs in cpu.c.

In order to get rid of CONFIG_USER_ONLY, kvm_s390_reset_vcpu() has to provide a
dummy implementation - the two definitions are moved to the proper section in
cpu.h.

Signed-off-by: David Hildenbrand 
Signed-off-by: Jens Freimann 
Reviewed-by: Cornelia Huck 
CC: Andreas Faerber 
Tested-by: Christian Borntraeger 
Signed-off-by: Cornelia Huck 
---
 target-s390x/cpu.c |9 ++---
 target-s390x/cpu.h |8 
 target-s390x/kvm.c |2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 9dbb0df..ec7df90 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -117,14 +117,10 @@ static void s390_cpu_initial_reset(CPUState *s)
 
 env->pfault_token = -1UL;
 
-#if defined(CONFIG_KVM)
 /* Reset state inside the kernel that we cannot access yet from QEMU. */
 if (kvm_enabled()) {
-if (kvm_vcpu_ioctl(s, KVM_S390_INITIAL_RESET, NULL)) {
-perror("Initial CPU reset failed");
-}
+kvm_s390_reset_vcpu(cpu);
 }
-#endif
 }
 
 /* CPUClass:reset() */
@@ -145,11 +141,10 @@ static void s390_cpu_full_reset(CPUState *s)
 
 env->pfault_token = -1UL;
 
-#if !defined(CONFIG_USER_ONLY)
+/* Reset state inside the kernel that we cannot access yet from QEMU. */
 if (kvm_enabled()) {
 kvm_s390_reset_vcpu(cpu);
 }
-#endif
 tlb_flush(s, 1);
 }
 
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 6b3aaed..fe2f95d 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -389,16 +389,12 @@ int s390_virtio_hypercall(CPUS390XState *env);
 void s390_virtio_irq(int config_change, uint64_t token);
 
 #ifdef CONFIG_KVM
-void kvm_s390_reset_vcpu(S390CPU *cpu);
 void kvm_s390_virtio_irq(int config_change, uint64_t token);
 void kvm_s390_service_interrupt(uint32_t parm);
 void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq);
 void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq);
 int kvm_s390_inject_flic(struct kvm_s390_irq *irq);
 #else
-static inline void kvm_s390_reset_vcpu(S390CPU *cpu)
-{
-}
 static inline void kvm_s390_virtio_irq(int config_change, uint64_t token)
 {
 }
@@ -1073,6 +1069,7 @@ int kvm_s390_cpu_restart(S390CPU *cpu);
 int kvm_s390_get_memslot_count(KVMState *s);
 void kvm_s390_clear_cmma_callback(void *opaque);
 int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);
+void kvm_s390_reset_vcpu(S390CPU *cpu);
 #else
 static inline void kvm_s390_io_interrupt(uint16_t subchannel_id,
 uint16_t subchannel_nr,
@@ -1107,6 +1104,9 @@ static inline int kvm_s390_set_cpu_state(S390CPU *cpu, 
uint8_t cpu_state)
 {
 return -ENOSYS;
 }
+static inline void kvm_s390_reset_vcpu(S390CPU *cpu)
+{
+}
 #endif
 
 static inline void cmma_reset(S390CPU *cpu)
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 7c90b18..e4c4c8d 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -198,7 +198,7 @@ void kvm_s390_reset_vcpu(S390CPU *cpu)
  * Before this ioctl cpu_synchronize_state() is called in common kvm
  * code (kvm-all) */
 if (kvm_vcpu_ioctl(cs, KVM_S390_INITIAL_RESET, NULL)) {
-perror("Can't reset vcpu\n");
+error_report("Initial CPU reset failed on CPU %i\n", cs->cpu_index);
 }
 }
 
-- 
1.7.9.5




[Qemu-devel] [PULL 0/8] s390x patches for 2.2

2014-10-09 Thread Cornelia Huck
The following changes since commit b6011bd8a57c1eda81a857d21adeb9b66e58b1b0:

  Merge remote-tracking branch 'remotes/riku/tags/pull-linux-user-20141006-2' 
into staging (2014-10-07 10:41:48 +0100)

are available in the git repository at:


  git://github.com/cohuck/qemu.git tags/s390x-20141009

for you to fetch changes up to 2adf6bbb8ad7e53f602d10b2b30d22cd831f79a6:

  s390x/virtio-ccw: fix vhost-scsi intialization (2014-10-09 14:22:47 +0200)


various s390x updates:
- cpu state handling in qemu and migration
- vhost-scsi-ccw bugfix



Cornelia Huck (1):
  s390x/virtio-ccw: fix vhost-scsi intialization

David Hildenbrand (5):
  s390x/kvm: introduce proper states for s390 cpus
  s390x/kvm: proper use of the cpu states OPERATING and STOPPED
  s390x/kvm: propagate s390 cpu state to kvm
  s390x/kvm: reuse kvm_s390_reset_vcpu() to get rid of ifdefs
  s390x/kvm: synchronize the cpu state after SIGP (INITIAL) CPU RESET

Jens Freimann (1):
  linux-headers: update to 3.17-rc7

Thomas Huth (1):
  s390x/migration: migrate CPU state

 hw/s390x/ipl.c|2 +-
 hw/s390x/s390-virtio.c|   32 ---
 hw/s390x/virtio-ccw.c |2 +-
 linux-headers/asm-mips/kvm_para.h |6 +-
 linux-headers/asm-powerpc/kvm.h   |2 +
 linux-headers/asm-x86/kvm.h   |3 +
 linux-headers/linux/kvm.h |   13 ++-
 linux-headers/linux/kvm_para.h|3 +
 linux-headers/linux/vfio.h|   34 
 linux-headers/linux/vhost.h   |2 +-
 target-s390x/cpu.c|  168 +++--
 target-s390x/cpu.h|   41 +++--
 target-s390x/helper.c |   19 ++---
 target-s390x/kvm.c|   58 +++--
 trace-events  |6 ++
 15 files changed, 299 insertions(+), 92 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [PULL 3/8] s390x/kvm: proper use of the cpu states OPERATING and STOPPED

2014-10-09 Thread Cornelia Huck
From: David Hildenbrand 

This patch makes sure that halting a cpu and stopping a cpu are two different
things. Stopping a cpu will also set the cpu halted - this is needed for common
infrastructure to work (note that the stop and stopped flag cannot be used for
our purpose because they are already used by other mechanisms).

A cpu can be halted ("waiting") when it is operating. If interrupts are
disabled, this is called a "disabled wait", as it can't be woken up anymore. A
stopped cpu is treated like a "disabled wait" cpu, but in order to prepare for a
proper cpu state synchronization with the kvm part, we need to track the real
logical state of a cpu.

Signed-off-by: David Hildenbrand 
Signed-off-by: Jens Freimann 
Reviewed-by: Cornelia Huck 
Reviewed-by: Christian Borntraeger 
CC: Andreas Faerber 
Tested-by: Christian Borntraeger 
Signed-off-by: Cornelia Huck 
---
 hw/s390x/ipl.c|2 +-
 target-s390x/cpu.c|   78 +++--
 target-s390x/cpu.h|   14 ++---
 target-s390x/helper.c |   19 +---
 target-s390x/kvm.c|   11 +++
 trace-events  |5 
 6 files changed, 79 insertions(+), 50 deletions(-)

diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
index 4fa9cff..3b77c9a 100644
--- a/hw/s390x/ipl.c
+++ b/hw/s390x/ipl.c
@@ -176,7 +176,7 @@ static void s390_ipl_reset(DeviceState *dev)
 }
 }
 
-s390_add_running_cpu(cpu);
+s390_cpu_set_state(CPU_STATE_OPERATING, cpu);
 }
 
 static void s390_ipl_class_init(ObjectClass *klass, void *data)
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 03cab74..dc89eb3 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -26,7 +26,9 @@
 #include "cpu.h"
 #include "qemu-common.h"
 #include "qemu/timer.h"
+#include "qemu/error-report.h"
 #include "hw/hw.h"
+#include "trace.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
@@ -81,7 +83,7 @@ static void s390_cpu_load_normal(CPUState *s)
 S390CPU *cpu = S390_CPU(s);
 cpu->env.psw.addr = ldl_phys(s->as, 4) & PSW_MASK_ESA_ADDR;
 cpu->env.psw.mask = PSW_MASK_32 | PSW_MASK_64;
-s390_add_running_cpu(cpu);
+s390_cpu_set_state(CPU_STATE_OPERATING, cpu);
 }
 #endif
 
@@ -93,11 +95,8 @@ static void s390_cpu_reset(CPUState *s)
 CPUS390XState *env = &cpu->env;
 
 env->pfault_token = -1UL;
-s390_del_running_cpu(cpu);
 scc->parent_reset(s);
-#if !defined(CONFIG_USER_ONLY)
-s->halted = 1;
-#endif
+s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
 tlb_flush(s, 1);
 }
 
@@ -135,9 +134,8 @@ static void s390_cpu_full_reset(CPUState *s)
 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
 CPUS390XState *env = &cpu->env;
 
-s390_del_running_cpu(cpu);
-
 scc->parent_reset(s);
+s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
 
 memset(env, 0, offsetof(CPUS390XState, cpu_num));
 
@@ -147,12 +145,7 @@ static void s390_cpu_full_reset(CPUState *s)
 
 env->pfault_token = -1UL;
 
-/* set halted to 1 to make sure we can add the cpu in
- * s390_ipl_cpu code, where CPUState::halted is set back to 0
- * after incrementing the cpu counter */
 #if !defined(CONFIG_USER_ONLY)
-s->halted = 1;
-
 if (kvm_enabled()) {
 kvm_s390_reset_vcpu(cpu);
 }
@@ -206,10 +199,7 @@ static void s390_cpu_initfn(Object *obj)
 env->tod_basetime = 0;
 env->tod_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_tod_timer, cpu);
 env->cpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_cpu_timer, cpu);
-/* set CPUState::halted state to 1 to avoid decrementing the running
- * cpu counter in s390_cpu_reset to a negative number at
- * initial ipl */
-cs->halted = 1;
+s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
 #endif
 env->cpu_num = cpu_num++;
 env->ext_index = -1;
@@ -230,6 +220,12 @@ static void s390_cpu_finalize(Object *obj)
 }
 
 #if !defined(CONFIG_USER_ONLY)
+static bool disabled_wait(CPUState *cpu)
+{
+return cpu->halted && !(S390_CPU(cpu)->env.psw.mask &
+(PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK));
+}
+
 static unsigned s390_count_running_cpus(void)
 {
 CPUState *cpu;
@@ -239,34 +235,60 @@ static unsigned s390_count_running_cpus(void)
 uint8_t state = S390_CPU(cpu)->env.cpu_state;
 if (state == CPU_STATE_OPERATING ||
 state == CPU_STATE_LOAD) {
-nr_running++;
+if (!disabled_wait(cpu)) {
+nr_running++;
+}
 }
 }
 
 return nr_running;
 }
 
-void s390_add_running_cpu(S390CPU *cpu)
+unsigned int s390_cpu_halt(S390CPU *cpu)
 {
 CPUState *cs = CPU(cpu);
+trace_cpu_halt(cs->cpu_index);
 
-if (cs->halted) {
-cpu->env.cpu_state = CPU_STATE_OPERATING;
-cs->halted = 0;
-cs->exception_index = -1;
+if (!cs->halted) {
+cs->halted = 1;
+cs->exception_index = EXCP_HLT;
 }
+
+return s390_count_running_cpus();
 }
 
-unsigned s390_del_running_cpu(S39

[Qemu-devel] [PULL 4/8] s390x/kvm: propagate s390 cpu state to kvm

2014-10-09 Thread Cornelia Huck
From: David Hildenbrand 

Let QEMU propagate the cpu state to kvm. If kvm doesn't yet support it, it is
silently ignored as kvm will still handle the cpu state itself in that case.

The state is not synced back, thus kvm won't have a chance to actively modify
the cpu state. To do so, control has to be given back to QEMU (which is already
done so in all relevant cases).

Setting of the cpu state can fail either because kvm doesn't support the
interface yet, or because the state is invalid/not supported. Failed attempts
will be traced

Signed-off-by: David Hildenbrand 
Signed-off-by: Jens Freimann 
Reviewed-by: Thomas Huth 
Reviewed-by: Cornelia Huck 
CC: Andreas Faerber 
Tested-by: Christian Borntraeger 
Signed-off-by: Cornelia Huck 
---
 target-s390x/cpu.c |3 +++
 target-s390x/cpu.h |5 +
 target-s390x/kvm.c |   43 +--
 trace-events   |1 +
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index dc89eb3..9dbb0df 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -288,6 +288,9 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU 
*cpu)
  cpu_state);
 exit(1);
 }
+if (kvm_enabled() && cpu->env.cpu_state != cpu_state) {
+kvm_s390_set_cpu_state(cpu, cpu_state);
+}
 cpu->env.cpu_state = cpu_state;
 
 return s390_count_running_cpus();
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 7b9300e..6b3aaed 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -1072,6 +1072,7 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier 
*notifier, uint32_t sch,
 int kvm_s390_cpu_restart(S390CPU *cpu);
 int kvm_s390_get_memslot_count(KVMState *s);
 void kvm_s390_clear_cmma_callback(void *opaque);
+int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);
 #else
 static inline void kvm_s390_io_interrupt(uint16_t subchannel_id,
 uint16_t subchannel_nr,
@@ -1102,6 +1103,10 @@ static inline int kvm_s390_get_memslot_count(KVMState *s)
 {
   return MAX_AVAIL_SLOTS;
 }
+static inline int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)
+{
+return -ENOSYS;
+}
 #endif
 
 static inline void cmma_reset(S390CPU *cpu)
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 415baea..7c90b18 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -181,9 +181,10 @@ unsigned long kvm_arch_vcpu_id(CPUState *cpu)
 return cpu->cpu_index;
 }
 
-int kvm_arch_init_vcpu(CPUState *cpu)
+int kvm_arch_init_vcpu(CPUState *cs)
 {
-/* nothing todo yet */
+S390CPU *cpu = S390_CPU(cs);
+kvm_s390_set_cpu_state(cpu, cpu->env.cpu_state);
 return 0;
 }
 
@@ -1321,3 +1322,41 @@ int kvm_s390_get_memslot_count(KVMState *s)
 {
 return kvm_check_extension(s, KVM_CAP_NR_MEMSLOTS);
 }
+
+int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)
+{
+struct kvm_mp_state mp_state = {};
+int ret;
+
+/* the kvm part might not have been initialized yet */
+if (CPU(cpu)->kvm_state == NULL) {
+return 0;
+}
+
+switch (cpu_state) {
+case CPU_STATE_STOPPED:
+mp_state.mp_state = KVM_MP_STATE_STOPPED;
+break;
+case CPU_STATE_CHECK_STOP:
+mp_state.mp_state = KVM_MP_STATE_CHECK_STOP;
+break;
+case CPU_STATE_OPERATING:
+mp_state.mp_state = KVM_MP_STATE_OPERATING;
+break;
+case CPU_STATE_LOAD:
+mp_state.mp_state = KVM_MP_STATE_LOAD;
+break;
+default:
+error_report("Requested CPU state is not a valid S390 CPU state: %u",
+ cpu_state);
+exit(1);
+}
+
+ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MP_STATE, &mp_state);
+if (ret) {
+trace_kvm_failed_cpu_state_set(CPU(cpu)->cpu_index, cpu_state,
+   strerror(-ret));
+}
+
+return ret;
+}
diff --git a/trace-events b/trace-events
index 5202f20..5290806 100644
--- a/trace-events
+++ b/trace-events
@@ -1369,6 +1369,7 @@ mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
 # target-s390x/kvm.c
 kvm_enable_cmma(int rc) "CMMA: enabling with result code %d"
 kvm_clear_cmma(int rc) "CMMA: clearing with result code %d"
+kvm_failed_cpu_state_set(int cpu_index, uint8_t state, const char *msg) 
"Warning: Unable to set cpu %d state %" PRIu8 " to KVM: %s"
 
 # hw/dma/i8257.c
 i8257_unregistered_dma(int nchan, int dma_pos, int dma_len) "unregistered DMA 
channel used nchan=%d dma_pos=%d dma_len=%d"
-- 
1.7.9.5




[Qemu-devel] [PULL 7/8] s390x/migration: migrate CPU state

2014-10-09 Thread Cornelia Huck
From: Thomas Huth 

This patch provides the cpu save information for dumps and later life
migration and enables migration of the CPU state. The code is based on
earlier work from Christian Borntraeger and Jason Herne.

Signed-off-by: Thomas Huth 
Signed-off-by: David Hildenbrand 
[provide cpu_post_load()]
Signed-off-by: Jens Freimann 
CC: Andreas Faerber 
CC: Christian Borntraeger 
CC: Jason J. Herne 
Tested-by: Christian Borntraeger 
Signed-off-by: Cornelia Huck 
---
 target-s390x/cpu.c |   59 ++--
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index ec7df90..c9c237f 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -292,9 +292,64 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU 
*cpu)
 }
 #endif
 
+static int cpu_post_load(void *opaque, int version_id)
+{
+S390CPU *cpu = opaque;
+
+/* the cpu state is fine for QEMU - we just need to push it to kvm */
+if (kvm_enabled()) {
+kvm_s390_set_cpu_state(cpu, cpu->env.cpu_state);
+}
+
+return 0;
+}
+
 static const VMStateDescription vmstate_s390_cpu = {
 .name = "cpu",
-.unmigratable = 1,
+.post_load = cpu_post_load,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField[]) {
+VMSTATE_UINT64(env.fregs[0].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[1].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[2].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[3].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[4].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[5].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[6].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[7].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[8].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[9].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[10].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[11].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[12].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[13].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[14].ll, S390CPU),
+VMSTATE_UINT64(env.fregs[15].ll, S390CPU),
+VMSTATE_UINT64_ARRAY(env.regs, S390CPU, 16),
+VMSTATE_UINT64(env.psw.mask, S390CPU),
+VMSTATE_UINT64(env.psw.addr, S390CPU),
+VMSTATE_UINT64(env.psa, S390CPU),
+VMSTATE_UINT32(env.fpc, S390CPU),
+VMSTATE_UINT32(env.todpr, S390CPU),
+VMSTATE_UINT64(env.pfault_token, S390CPU),
+VMSTATE_UINT64(env.pfault_compare, S390CPU),
+VMSTATE_UINT64(env.pfault_select, S390CPU),
+VMSTATE_UINT64(env.cputm, S390CPU),
+VMSTATE_UINT64(env.ckc, S390CPU),
+VMSTATE_UINT64(env.gbea, S390CPU),
+VMSTATE_UINT64(env.pp, S390CPU),
+VMSTATE_UINT32_ARRAY(env.aregs, S390CPU, 16),
+VMSTATE_UINT64_ARRAY(env.cregs, S390CPU, 16),
+VMSTATE_UINT8(env.cpu_state, S390CPU),
+VMSTATE_END_OF_LIST()
+ },
+.subsections = (VMStateSubsection[]) {
+{
+/* empty */
+}
+}
 };
 
 static void s390_cpu_class_init(ObjectClass *oc, void *data)
@@ -323,11 +378,11 @@ static void s390_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->handle_mmu_fault = s390_cpu_handle_mmu_fault;
 #else
 cc->get_phys_page_debug = s390_cpu_get_phys_page_debug;
+cc->vmsd = &vmstate_s390_cpu;
 cc->write_elf64_note = s390_cpu_write_elf64_note;
 cc->write_elf64_qemunote = s390_cpu_write_elf64_qemunote;
 cc->cpu_exec_interrupt = s390_cpu_exec_interrupt;
 #endif
-dc->vmsd = &vmstate_s390_cpu;
 cc->gdb_num_core_regs = S390_NUM_CORE_REGS;
 cc->gdb_core_xml_file = "s390x-core64.xml";
 }
-- 
1.7.9.5




[Qemu-devel] [PULL 8/8] s390x/virtio-ccw: fix vhost-scsi intialization

2014-10-09 Thread Cornelia Huck
The vhost-scsi-ccw backend is of type VHostSCSICcw, not VirtIOSCSICcw.

This fixes a segfault when invoking

qemu-system-s390x -device vhost-scsi-ccw,?

Reviewed-by: Thomas Huth 
Tested-by: Christian Borntraeger 
Signed-off-by: Cornelia Huck 
---
 hw/s390x/virtio-ccw.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index e7d3ea1..18ba29f 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -1528,7 +1528,7 @@ static void vhost_ccw_scsi_class_init(ObjectClass *klass, 
void *data)
 static const TypeInfo vhost_ccw_scsi = {
 .name  = TYPE_VHOST_SCSI_CCW,
 .parent= TYPE_VIRTIO_CCW_DEVICE,
-.instance_size = sizeof(VirtIOSCSICcw),
+.instance_size = sizeof(VHostSCSICcw),
 .instance_init = vhost_ccw_scsi_instance_init,
 .class_init= vhost_ccw_scsi_class_init,
 };
-- 
1.7.9.5




[Qemu-devel] [PULL 1/8] linux-headers: update to 3.17-rc7

2014-10-09 Thread Cornelia Huck
From: Jens Freimann 

Sync headers with 3.17-rc7

Acked-by: Paolo Bonzini 
Signed-off-by: Jens Freimann 
Signed-off-by: Cornelia Huck 
---
 linux-headers/asm-mips/kvm_para.h |6 +-
 linux-headers/asm-powerpc/kvm.h   |2 ++
 linux-headers/asm-x86/kvm.h   |3 +++
 linux-headers/linux/kvm.h |   13 ++---
 linux-headers/linux/kvm_para.h|3 +++
 linux-headers/linux/vfio.h|   34 ++
 linux-headers/linux/vhost.h   |2 +-
 7 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/linux-headers/asm-mips/kvm_para.h 
b/linux-headers/asm-mips/kvm_para.h
index 14fab8f..dbb2464 100644
--- a/linux-headers/asm-mips/kvm_para.h
+++ b/linux-headers/asm-mips/kvm_para.h
@@ -1 +1,5 @@
-#include 
+#ifndef _ASM_MIPS_KVM_PARA_H
+#define _ASM_MIPS_KVM_PARA_H
+
+
+#endif /* _ASM_MIPS_KVM_PARA_H */
diff --git a/linux-headers/asm-powerpc/kvm.h b/linux-headers/asm-powerpc/kvm.h
index 2bc4a94..e0e49db 100644
--- a/linux-headers/asm-powerpc/kvm.h
+++ b/linux-headers/asm-powerpc/kvm.h
@@ -548,6 +548,7 @@ struct kvm_get_htab_header {
 
 #define KVM_REG_PPC_VRSAVE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb4)
 #define KVM_REG_PPC_LPCR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5)
+#define KVM_REG_PPC_LPCR_64(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb5)
 #define KVM_REG_PPC_PPR(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb6)
 
 /* Architecture compatibility level */
@@ -555,6 +556,7 @@ struct kvm_get_htab_header {
 
 #define KVM_REG_PPC_DABRX  (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb8)
 #define KVM_REG_PPC_WORT   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb9)
+#define KVM_REG_PPC_SPRG9  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xba)
 
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h
index d3a8778..d7dcef5 100644
--- a/linux-headers/asm-x86/kvm.h
+++ b/linux-headers/asm-x86/kvm.h
@@ -23,7 +23,10 @@
 #define GP_VECTOR 13
 #define PF_VECTOR 14
 #define MF_VECTOR 16
+#define AC_VECTOR 17
 #define MC_VECTOR 18
+#define XM_VECTOR 19
+#define VE_VECTOR 20
 
 /* Select x86 specific features in  */
 #define __KVM_HAVE_PIT
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index f5d2c38..2669938 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -162,7 +162,7 @@ struct kvm_pit_config {
 #define KVM_EXIT_TPR_ACCESS   12
 #define KVM_EXIT_S390_SIEIC   13
 #define KVM_EXIT_S390_RESET   14
-#define KVM_EXIT_DCR  15
+#define KVM_EXIT_DCR  15 /* deprecated */
 #define KVM_EXIT_NMI  16
 #define KVM_EXIT_INTERNAL_ERROR   17
 #define KVM_EXIT_OSI  18
@@ -268,7 +268,7 @@ struct kvm_run {
__u64 trans_exc_code;
__u32 pgm_code;
} s390_ucontrol;
-   /* KVM_EXIT_DCR */
+   /* KVM_EXIT_DCR (deprecated) */
struct {
__u32 dcrn;
__u32 data;
@@ -399,13 +399,18 @@ struct kvm_vapic_addr {
__u64 vapic_addr;
 };
 
-/* for KVM_SET_MPSTATE */
+/* for KVM_SET_MP_STATE */
 
+/* not all states are valid on all architectures */
 #define KVM_MP_STATE_RUNNABLE  0
 #define KVM_MP_STATE_UNINITIALIZED 1
 #define KVM_MP_STATE_INIT_RECEIVED 2
 #define KVM_MP_STATE_HALTED3
 #define KVM_MP_STATE_SIPI_RECEIVED 4
+#define KVM_MP_STATE_STOPPED   5
+#define KVM_MP_STATE_CHECK_STOP6
+#define KVM_MP_STATE_OPERATING 7
+#define KVM_MP_STATE_LOAD  8
 
 struct kvm_mp_state {
__u32 mp_state;
@@ -758,6 +763,8 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_VM_ATTRIBUTES 101
 #define KVM_CAP_ARM_PSCI_0_2 102
 #define KVM_CAP_PPC_FIXUP_HCALL 103
+#define KVM_CAP_PPC_ENABLE_HCALL 104
+#define KVM_CAP_CHECK_EXTENSION_VM 105
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
diff --git a/linux-headers/linux/kvm_para.h b/linux-headers/linux/kvm_para.h
index 2dff783..e61661e 100644
--- a/linux-headers/linux/kvm_para.h
+++ b/linux-headers/linux/kvm_para.h
@@ -20,6 +20,9 @@
 #define KVM_HC_FEATURES3
 #define KVM_HC_PPC_MAP_MAGIC_PAGE  4
 #define KVM_HC_KICK_CPU5
+#define KVM_HC_MIPS_GET_CLOCK_FREQ 6
+#define KVM_HC_MIPS_EXIT_VM7
+#define KVM_HC_MIPS_CONSOLE_OUTPUT 8
 
 /*
  * hypercalls use architecture specific
diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
index 26c218e..95b591b 100644
--- a/linux-headers/linux/vfio.h
+++ b/linux-headers/linux/vfio.h
@@ -30,6 +30,9 @@
  */
 #define VFIO_DMA_CC_IOMMU  4
 
+/* Check if EEH is supported */
+#define VFIO_EEH   5
+
 /*
  * The IOCTL interface is designed for extensibility by embedding the
  * structure length (argsz) and flags into structures passed between
@@ -455,6 +458,37 @@ struct vfio_iommu_spapr_tce_info {
 
 #define

[Qemu-devel] [PULL v3 00/28] Changes for 2014-10-09

2014-10-09 Thread Paolo Bonzini
The following changes since commit 1831e150606a221898bf46ffaf0453e9952cbbc4:

  Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging 
(2014-09-30 16:45:35 +0100)

are available in the git repository at:


  git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to 5008e5b7b817b5ea2b788203122cd50e7c16e599:

  qemu-char: Fix reconnect socket error reporting (2014-10-09 15:36:15 +0200)


Four changes here.  Polling for reconnection of character devices,
the QOMification of accelerators, a fix for -kernel support on x86, and one
for a recently-introduced virtio-scsi optimization.


Corey Minyard (9):
  qemu-char: Make the filename size for a chardev a #define
  qemu-char: Rework qemu_chr_open_socket() for reconnect
  qemu-char: Move some items into TCPCharDriver
  qemu-char: set socket filename to disconnected when not connected
  qemu-char: Add reconnecting to client sockets
  qemu-char: Print the remote and local addresses for a socket
  qemu-error: Add error_vreport()
  qemu-sockets: Add error to non-blocking connect handler
  qemu-char: Fix reconnect socket error reporting

Eduardo Habkost (17):
  vl.c: Small coding style fix
  accel: Move accel code to accel.c
  accel: Create AccelType typedef
  accel: Simplify configure_accelerator() using AccelType *acc variable
  accel: Move accel name lookup to separate function
  accel: Use QOM classes for accel types
  accel: Make AccelClass.available() optional
  accel: Report unknown accelerator as "not found" instead of "does not 
exist"
  accel: Move KVM accel registration to kvm-all.c
  accel: Move Xen registration code to xen-common.c
  accel: Move qtest accel registration to qtest.c
  accel: Remove tcg_available() function
  accel: Move accel init/allowed code to separate function
  accel: Rename 'init' method to 'init_machine'
  accel: Pass MachineState object to accel init functions
  accel: Create accel object when initializing machine
  kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

Paolo Bonzini (2):
  linuxboot: compute initrd loading address
  virtio-scsi: fix use-after-free of VirtIOSCSIReq

 Makefile.objs |   1 +
 accel.c   | 157 ++
 arch_init.c   |   5 -
 hw/scsi/virtio-scsi.c |   9 +-
 include/hw/boards.h   |   4 +-
 include/hw/xen/xen.h  |   1 -
 include/qemu/error-report.h   |   1 +
 include/qemu/sockets.h|   2 +-
 include/qemu/typedefs.h   |   1 +
 include/sysemu/accel.h|  62 
 include/sysemu/arch_init.h|   1 -
 include/sysemu/kvm.h  |   2 -
 include/sysemu/qtest.h|   1 -
 kvm-all.c |  40 -
 kvm-stub.c|   5 -
 migration-tcp.c   |   4 +-
 migration-unix.c  |   4 +-
 pc-bios/linuxboot.bin | Bin 1024 -> 1024 bytes
 pc-bios/optionrom/linuxboot.S |  47 +-
 pc-bios/optionrom/optionrom.h |  21 ++-
 qapi-schema.json  |  15 +-
 qemu-char.c   | 359 --
 qemu-options.hx   |  20 ++-
 qtest.c   |  27 +++-
 util/qemu-error.c |  23 ++-
 util/qemu-sockets.c   |  20 ++-
 vl.c  |  83 +-
 xen-common-stub.c |   6 -
 xen-common.c  |  25 ++-
 29 files changed, 711 insertions(+), 235 deletions(-)
 create mode 100644 accel.c
 create mode 100644 include/sysemu/accel.h
-- 
1.8.3.1




[Qemu-devel] [PULL v3 22/28] accel: Create accel object when initializing machine

2014-10-09 Thread Paolo Bonzini
From: Eduardo Habkost 

Create an actual TYPE_ACCEL object when initializing a machine. This
will allow accelerator classes to implement some initialization on
instance_init, and to save state on the TYPE_ACCEL object.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 accel.c | 7 +++
 include/hw/boards.h | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/accel.c b/accel.c
index 6087ab3..74e41da 100644
--- a/accel.c
+++ b/accel.c
@@ -32,6 +32,7 @@
 #include "sysemu/qtest.h"
 #include "hw/xen/xen.h"
 #include "qom/object.h"
+#include "hw/boards.h"
 
 int tcg_tb_size;
 static bool tcg_allowed = true;
@@ -60,11 +61,17 @@ static AccelClass *accel_find(const char *opt_name)
 
 static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
+ObjectClass *oc = OBJECT_CLASS(acc);
+const char *cname = object_class_get_name(oc);
+AccelState *accel = ACCEL(object_new(cname));
 int ret;
+ms->accelerator = accel;
 *(acc->allowed) = true;
 ret = acc->init_machine(ms);
 if (ret < 0) {
+ms->accelerator = NULL;
 *(acc->allowed) = false;
+object_unref(OBJECT(accel));
 }
 return ret;
 }
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 0058c49..6a60c3c 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -5,6 +5,7 @@
 
 #include "qemu/typedefs.h"
 #include "sysemu/blockdev.h"
+#include "sysemu/accel.h"
 #include "hw/qdev.h"
 #include "qom/object.h"
 
@@ -131,6 +132,7 @@ struct MachineState {
 char *kernel_cmdline;
 char *initrd_filename;
 const char *cpu_model;
+AccelState *accelerator;
 };
 
 #endif
-- 
1.8.3.1





[Qemu-devel] [PATCH] disas/libvixl/a64/instructions-a64.h: Remove useless varialbe to avoid building break with '-Werror'

2014-10-09 Thread Chen Gang
The related variables are useless, need be removed, or can not pass
microblaze building, after fix it, can build microblaze, successfully.

The related configuration:

 ./configure --target-list="arm-softmmu,microblazeel-softmmu" --enable-fdt 
--disable-kvm

The related compiling error:

CXX   disas/arm-a64.o
  In file included from /upstream/qemu/disas/libvixl/a64/disasm-a64.h:32:0,
   from disas/arm-a64.cc:20:
  disas/libvixl/a64/instructions-a64.h:98:13: error: 
'vixl::kFP32PositiveInfinity' defined but not used [-Werror=unused-variable]
   const float kFP32PositiveInfinity = rawbits_to_float(0x7f80);
   ^
  disas/libvixl/a64/instructions-a64.h:99:13: error: 
'vixl::kFP32NegativeInfinity' defined but not used [-Werror=unused-variable]
   const float kFP32NegativeInfinity = rawbits_to_float(0xff80);
   ^
  disas/libvixl/a64/instructions-a64.h:100:14: error: 
'vixl::kFP64PositiveInfinity' defined but not used [-Werror=unused-variable]
   const double kFP64PositiveInfinity =
^
  disas/libvixl/a64/instructions-a64.h:102:14: error: 
'vixl::kFP64NegativeInfinity' defined but not used [-Werror=unused-variable]
   const double kFP64NegativeInfinity =
^
  disas/libvixl/a64/instructions-a64.h:107:21: error: 
'vixl::kFP64SignallingNaN' defined but not used [-Werror=unused-variable]
   static const double kFP64SignallingNaN =
   ^
  disas/libvixl/a64/instructions-a64.h:109:20: error: 
'vixl::kFP32SignallingNaN' defined but not used [-Werror=unused-variable]
   static const float kFP32SignallingNaN = rawbits_to_float(0x7f81);
  ^
  disas/libvixl/a64/instructions-a64.h:112:21: error: 'vixl::kFP64QuietNaN' 
defined but not used [-Werror=unused-variable]
   static const double kFP64QuietNaN =
   ^
  disas/libvixl/a64/instructions-a64.h:114:20: error: 'vixl::kFP32QuietNaN' 
defined but not used [-Werror=unused-variable]
   static const float kFP32QuietNaN = rawbits_to_float(0x7fc1);
  ^
  disas/libvixl/a64/instructions-a64.h:117:21: error: 'vixl::kFP64DefaultNaN' 
defined but not used [-Werror=unused-variable]
   static const double kFP64DefaultNaN =
   ^
  disas/libvixl/a64/instructions-a64.h:119:20: error: 'vixl::kFP32DefaultNaN' 
defined but not used [-Werror=unused-variable]
   static const float kFP32DefaultNaN = rawbits_to_float(0x7fc0);
  ^
  cc1plus: all warnings being treated as errors
  make: *** [disas/arm-a64.o] Error 1


Signed-off-by: Chen Gang 
---
 disas/libvixl/a64/instructions-a64.h | 24 
 1 file changed, 24 deletions(-)

diff --git a/disas/libvixl/a64/instructions-a64.h 
b/disas/libvixl/a64/instructions-a64.h
index d5b90c5..1eea851 100644
--- a/disas/libvixl/a64/instructions-a64.h
+++ b/disas/libvixl/a64/instructions-a64.h
@@ -95,30 +95,6 @@ const unsigned kDoubleExponentBits = 11;
 const unsigned kFloatMantissaBits = 23;
 const unsigned kFloatExponentBits = 8;
 
-const float kFP32PositiveInfinity = rawbits_to_float(0x7f80);
-const float kFP32NegativeInfinity = rawbits_to_float(0xff80);
-const double kFP64PositiveInfinity =
-rawbits_to_double(UINT64_C(0x7ff0));
-const double kFP64NegativeInfinity =
-rawbits_to_double(UINT64_C(0xfff0));
-
-// This value is a signalling NaN as both a double and as a float (taking the
-// least-significant word).
-static const double kFP64SignallingNaN =
-rawbits_to_double(UINT64_C(0x7ff07f81));
-static const float kFP32SignallingNaN = rawbits_to_float(0x7f81);
-
-// A similar value, but as a quiet NaN.
-static const double kFP64QuietNaN =
-rawbits_to_double(UINT64_C(0x7ff87fc1));
-static const float kFP32QuietNaN = rawbits_to_float(0x7fc1);
-
-// The default NaN values (for FPCR.DN=1).
-static const double kFP64DefaultNaN =
-rawbits_to_double(UINT64_C(0x7ff8));
-static const float kFP32DefaultNaN = rawbits_to_float(0x7fc0);
-
-
 enum LSDataSize {
   LSByte= 0,
   LSHalfword= 1,
-- 
1.9.3



Re: [Qemu-devel] [PATCH] virtio-balloon: Tweak recent fix for integer overflow

2014-10-09 Thread Luiz Capitulino
On Wed,  1 Oct 2014 18:43:44 +0200
Markus Armbruster  wrote:

> Commit 1f9296b avoids "other kinds of overflow" by limiting the
> polling interval to UINT_MAX.  The computations to protect are done in
> 64 bits.  This is indeed safe when unsigned is 32 bits, as it commonly
> is.  It isn't when unsigned is 64 bits.  Purely theoretical; I'm not
> aware of such a system.  Limit it to UINT32_MAX instead.
> 
> Signed-off-by: Markus Armbruster 

Applied to the qmp branch, thanks.

> ---
>  hw/virtio/virtio-balloon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> index b5cf7ca..7bfbb75 100644
> --- a/hw/virtio/virtio-balloon.c
> +++ b/hw/virtio/virtio-balloon.c
> @@ -170,7 +170,7 @@ static void balloon_stats_set_poll_interval(Object *obj, 
> struct Visitor *v,
>  return;
>  }
>  
> -if (value > UINT_MAX) {
> +if (value > UINT32_MAX) {
>  error_setg(errp, "timer value is too big");
>  return;
>  }




[Qemu-devel] [RFC][PATCH v2x prototype 1/1] xen-hvm.c: Add support for Xen access to vmport

2014-10-09 Thread Don Slutz
This adds synchronisation of the 6 vcpu registers (only 32bits of
them) that vmport.c needs between Xen and QEMU.

This is to avoid a 2nd and 3rd exchange between QEMU and Xen to
fetch and put these 6 vcpu registers used by the code in vmport.c
and vmmouse.c

Add new array to XenIOState that allows selection of current_cpu by
ioreq_id.

Now pass XenIOState to handle_ioreq().

Add new routines regs_to_cpu(), regs_from_cpu(), and
handle_vmport_ioreq().

Signed-off-by: Don Slutz 
---
As requested by Paul Durrant 

Here is a prototype of the QEMU change using a 2nd shared page.
I picked adding HVM_PARAM_VMPORT_IOREQ_PFN as the simple and
fast way to handle QEMU building on older Xen versions.


 xen-hvm.c | 128 +++---
 1 file changed, 123 insertions(+), 5 deletions(-)

diff --git a/xen-hvm.c b/xen-hvm.c
index 05e522c..5e80159 100644
--- a/xen-hvm.c
+++ b/xen-hvm.c
@@ -41,6 +41,29 @@ static MemoryRegion *framebuffer;
 static bool xen_in_migration;
 
 /* Compatibility with older version */
+
+/* This allows QEMU to build on a system that has Xen 4.5 or earlier
+ * installed.  This here (not in hw/xen/xen_common.h) because xen/hvm/ioreq.h
+ * needs to be included before this block and hw/xen/xen_common.h needs to
+ * be included before xen/hvm/ioreq.h
+ */
+#ifndef IOREQ_TYPE_VMWARE_PORT
+#define IOREQ_TYPE_VMWARE_PORT  3
+struct vmware_ioreq {
+uint32_t esi;
+uint32_t edi;
+uint32_t ebx;
+uint32_t ecx;
+uint32_t edx;
+};
+typedef struct vmware_ioreq vmware_ioreq_t;
+
+struct shared_vmport_iopage {
+struct vmware_ioreq vcpu_vmport_ioreq[1];
+};
+typedef struct shared_vmport_iopage shared_vmport_iopage_t;
+#endif
+
 #if __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a
 static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i)
 {
@@ -79,8 +102,10 @@ typedef struct XenPhysmap {
 
 typedef struct XenIOState {
 shared_iopage_t *shared_page;
+shared_vmport_iopage_t *shared_vmport_page;
 buffered_iopage_t *buffered_io_page;
 QEMUTimer *buffered_io_timer;
+CPUState **cpu_by_ioreq_id;
 /* the evtchn port for polling the notification, */
 evtchn_port_t *ioreq_local_port;
 /* evtchn local port for buffered io */
@@ -101,6 +126,8 @@ typedef struct XenIOState {
 Notifier wakeup;
 } XenIOState;
 
+static void handle_ioreq(XenIOState *state, ioreq_t *req);
+
 /* Xen specific function for piix pci */
 
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
@@ -610,6 +637,20 @@ static ioreq_t 
*cpu_get_ioreq_from_shared_memory(XenIOState *state, int vcpu)
 return req;
 }
 
+/* get the vmport ioreq packets from share mem */
+static vmware_ioreq_t *cpu_get_vmport_ioreq_from_shared_memory(
+XenIOState *state, int vcpu)
+{
+vmware_ioreq_t *vmport_req;
+
+assert(state->shared_vmport_page);
+vmport_req = &state->shared_vmport_page->vcpu_vmport_ioreq[vcpu];
+
+xen_rmb(); /* see IOREQ_READY /then/ read contents of ioreq */
+
+return vmport_req;
+}
+
 /* use poll to get the port notification */
 /* ioreq_vec--out,the */
 /* retval--the number of ioreq packet */
@@ -773,7 +814,51 @@ static void cpu_ioreq_move(ioreq_t *req)
 }
 }
 
-static void handle_ioreq(ioreq_t *req)
+static void regs_to_cpu(XenIOState *state, vmware_ioreq_t *vmport_req,
+ioreq_t *req)
+{
+X86CPU *cpu;
+CPUX86State *env;
+
+current_cpu = state->cpu_by_ioreq_id[state->send_vcpu];
+cpu = X86_CPU(current_cpu);
+env = &cpu->env;
+env->regs[R_EAX] = req->data;
+env->regs[R_EBX] = vmport_req->ebx;
+env->regs[R_ECX] = vmport_req->ecx;
+env->regs[R_EDX] = vmport_req->edx;
+env->regs[R_ESI] = vmport_req->esi;
+env->regs[R_EDI] = vmport_req->edi;
+}
+
+static void regs_from_cpu(XenIOState *state, vmware_ioreq_t *vmport_req,
+  ioreq_t *req)
+{
+X86CPU *cpu = X86_CPU(current_cpu);
+CPUX86State *env = &cpu->env;
+
+assert(sizeof(*vmport_req) <= sizeof(*req));
+
+req->data = env->regs[R_EAX];
+vmport_req->ebx = env->regs[R_EBX];
+vmport_req->ecx = env->regs[R_ECX];
+vmport_req->edx = env->regs[R_EDX];
+vmport_req->esi = env->regs[R_ESI];
+vmport_req->edi = env->regs[R_EDI];
+current_cpu = NULL;
+}
+
+static void handle_vmport_ioreq(XenIOState *state, ioreq_t *req)
+{
+vmware_ioreq_t *vmport_req =
+cpu_get_vmport_ioreq_from_shared_memory(state, state->send_vcpu);
+
+regs_to_cpu(state, vmport_req, req);
+cpu_ioreq_pio(req);
+regs_from_cpu(state, vmport_req, req);
+}
+
+static void handle_ioreq(XenIOState *state, ioreq_t *req)
 {
 if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
 (req->size < sizeof (target_ulong))) {
@@ -787,6 +872,9 @@ static void handle_ioreq(ioreq_t *req)
 case IOREQ_TYPE_COPY:
 cpu_ioreq_move(req);
 break;
+case IOREQ_TYPE_VMWARE_PORT:
+handle_vmport_ioreq(state, req);
+ 

Re: [Qemu-devel] [PATCH v8 0/2] Return error reasons to caller when calling qmp_dump_guest_memory

2014-10-09 Thread Luiz Capitulino
On Thu, 9 Oct 2014 14:13:09 +0800
zhanghailiang  wrote:

> In original code, Function dump_error ignores its second parameter which 
> contains
> error reason, it is better to return the error message to the caller.
> 
> Here we use error_setg to return the error info to caller.
> And at the same time, we turn functions like write_elf64_note() to void,
> Because functions shouldn't return an error code _and_ an Error object.
> After this modification the code will be more clean. 

Applied to the qmp branch, thanks.

> 
> v7 -> v8
> - fixes for Eric's findings
> - Add Reviewed-by
> v6 -> v7
> - Change the commit message for the first patch (Markus Armbruster)
> - Add Reviewed-by
> - Remove redundant check for local_err (Markus Armbruster)
> v5 -> v6
> - Don't check *errp directly, if errp is NULL, there will be an error,
>   Instead, check a local variable *local_err (Markus Armbruster) 
> v4 -> v5:
> - Turn functions like write_elf64_note() to void (Luiz Capitulino)
> v3 -> v4:
> - Adjust the errp argument to the end 
> - Remove trailing '.' in error messages
> v2 -> v3:
> - Drop the '\n' in the message when call dump_error (Eric Blake) 
> v1 -> v2:
> - Return the error reason to the caller (Luiz Capitulino)
> 
> Thanks for review!;)
> 
> zhanghailiang (2):
>   dump: Propagate errors into qmp_dump_guest_memory()
>   dump: Turn some functions to void to make code cleaner
> 
>  dump.c | 383 
> ++---
>  1 file changed, 177 insertions(+), 206 deletions(-)
> 




[Qemu-devel] [PATCH v5 4/7] target-arm: Handle SMC/HVC undef-if-no-ELx in pre_* helpers

2014-10-09 Thread Peter Maydell
SMC must UNDEF if EL3 is not implemented; similarly HVC UNDEFs
if EL2 is not implemented. Move the handling of this from
translate-a64.c into the pre_smc and pre_hvc helper functions.
This is necessary because use of these instructions for PSCI
takes precedence over this UNDEF case, and we can't tell if
this is a PSCI call until runtime.

Signed-off-by: Peter Maydell 
---
 target-arm/op_helper.c | 17 ++---
 target-arm/translate-a64.c |  4 ++--
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c
index 03ac92a..5652096 100644
--- a/target-arm/op_helper.c
+++ b/target-arm/op_helper.c
@@ -392,10 +392,11 @@ void HELPER(pre_hvc)(CPUARMState *env)
 bool secure = false;
 bool undef;
 
-/* We've already checked that EL2 exists at translation time.
- * EL3.HCE has priority over EL2.HCD.
- */
-if (arm_feature(env, ARM_FEATURE_EL3)) {
+if (!arm_feature(env, ARM_FEATURE_EL2)) {
+/* If EL2 doesn't exist, HVC always UNDEFs */
+undef = true;
+} else if (arm_feature(env, ARM_FEATURE_EL3)) {
+/* EL3.HCE has priority over EL2.HCD. */
 undef = !(env->cp15.scr_el3 & SCR_HCE);
 } else {
 undef = env->cp15.hcr_el2 & HCR_HCD;
@@ -429,13 +430,15 @@ void HELPER(pre_smc)(CPUARMState *env, uint32_t syndrome)
  */
 bool undef = is_a64(env) ? smd : (!secure && smd);
 
-/* In NS EL1, HCR controlled routing to EL2 has priority over SMD.  */
-if (!secure && cur_el == 1 && (env->cp15.hcr_el2 & HCR_TSC)) {
+if (!arm_feature(env, ARM_FEATURE_EL3)) {
+/* If we have no EL3 then SMC always UNDEFs */
+undef = true;
+} else if (!secure && cur_el == 1 && (env->cp15.hcr_el2 & HCR_TSC)) {
+/* In NS EL1, HCR controlled routing to EL2 has priority over SMD. */
 env->exception.syndrome = syndrome;
 raise_exception(env, EXCP_HYP_TRAP);
 }
 
-/* We've already checked that EL3 exists at translation time.  */
 if (undef) {
 env->exception.syndrome = syn_uncategorized();
 raise_exception(env, EXCP_UDEF);
diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
index 35ae3ea..b15261b 100644
--- a/target-arm/translate-a64.c
+++ b/target-arm/translate-a64.c
@@ -1485,7 +1485,7 @@ static void disas_exc(DisasContext *s, uint32_t insn)
 gen_exception_insn(s, 0, EXCP_SWI, syn_aa64_svc(imm16));
 break;
 case 2:
-if (!arm_dc_feature(s, ARM_FEATURE_EL2) || s->current_pl == 0) {
+if (s->current_pl == 0) {
 unallocated_encoding(s);
 break;
 }
@@ -1498,7 +1498,7 @@ static void disas_exc(DisasContext *s, uint32_t insn)
 gen_exception_insn(s, 0, EXCP_HVC, syn_aa64_hvc(imm16));
 break;
 case 3:
-if (!arm_dc_feature(s, ARM_FEATURE_EL3) || s->current_pl == 0) {
+if (s->current_pl == 0) {
 unallocated_encoding(s);
 break;
 }
-- 
1.9.1




[Qemu-devel] [PATCH v5 0/7] ARM: add PSCI 0.2 support in TCG mode

2014-10-09 Thread Peter Maydell
This series adds PSCI support to ARM and AArch64 system emulation
when running in TCG mode. It's an update of the patchsent Ard
sent out earlier in September which in turn is based on work
by Rob Herring.

Changes v5->v6:
 * minor rebasing
 * redid the way that PSCI is plumbed into SMC/HVC handling,
   to fit into the support for EL2/EL3 which has landed since
   v5. In particular we now test for whether this is a PSCI
   call as a separate step from actually doing the call, since
   we want to prefer doing PSCI to UNDEF, but UNDEF will happen
   first if it happens at all.

NB: this works for the virt board for both 32 bit and 64 bit
CPUs. There is one bug I've seen where if you have an SMP
configuration of 32 bit CPUs and do a guest reset then the
guest misbehaves (segfaults, etc) after the reboot when it
gets up to userspace. I'm not sure if this is the fault of
these patches or just a revealed bug, so I'm sending them
out for review anyway and will investigate further...

thanks
-- PMM

Ard Biesheuvel (1):
  target-arm: add missing PSCI constants needed for PSCI emulation

Peter Maydell (2):
  target-arm: Handle SMC/HVC undef-if-no-ELx in pre_* helpers
  target-arm: Add support for A32 and T32 HVC and SMC insns

Rob Herring (4):
  target-arm: add powered off cpu state
  target-arm: do not set do_interrupt handlers for ARM and AArch64 user
modes
  target-arm: add emulation of PSCI calls for system emulation
  arm/virt: enable PSCI emulation support for system emulation

 hw/arm/virt.c  |  82 +++
 target-arm/Makefile.objs   |   1 +
 target-arm/cpu-qom.h   |   7 ++
 target-arm/cpu.c   |  20 +++-
 target-arm/cpu.h   |   6 ++
 target-arm/cpu64.c |   2 +
 target-arm/helper-a64.c|   9 ++
 target-arm/helper.c|  11 ++-
 target-arm/internals.h |  22 +
 target-arm/kvm-consts.h|  40 
 target-arm/machine.c   |   5 +-
 target-arm/op_helper.c |  33 +--
 target-arm/psci.c  | 242 +
 target-arm/translate-a64.c |   4 +-
 target-arm/translate.c | 103 ---
 target-arm/translate.h |   2 +
 16 files changed, 513 insertions(+), 76 deletions(-)
 create mode 100644 target-arm/psci.c

-- 
1.9.1




[Qemu-devel] [PATCH v5 1/7] target-arm: add powered off cpu state

2014-10-09 Thread Peter Maydell
From: Rob Herring 

Add tracking of cpu power state in order to support powering off of
cores in system emuluation. The initial state is determined by the
start-powered-off QOM property.

Signed-off-by: Rob Herring 
Reviewed-by: Peter Maydell 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Peter Maydell 
---
 target-arm/cpu-qom.h | 2 ++
 target-arm/cpu.c | 8 +++-
 target-arm/machine.c | 5 +++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/target-arm/cpu-qom.h b/target-arm/cpu-qom.h
index 96a3da9..aeb7e1d 100644
--- a/target-arm/cpu-qom.h
+++ b/target-arm/cpu-qom.h
@@ -98,6 +98,8 @@ typedef struct ARMCPU {
 
 /* Should CPU start in PSCI powered-off state? */
 bool start_powered_off;
+/* CPU currently in PSCI powered-off state */
+bool powered_off;
 
 /* [QEMU_]KVM_ARM_TARGET_* constant for this CPU, or
  * QEMU_KVM_ARM_TARGET_NONE if the kernel doesn't support this CPU type.
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index edfd586..67cd176 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -40,7 +40,10 @@ static void arm_cpu_set_pc(CPUState *cs, vaddr value)
 
 static bool arm_cpu_has_work(CPUState *cs)
 {
-return cs->interrupt_request &
+ARMCPU *cpu = ARM_CPU(cs);
+
+return !cpu->powered_off
+&& cs->interrupt_request &
 (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD
  | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ
  | CPU_INTERRUPT_EXITTB);
@@ -93,6 +96,9 @@ static void arm_cpu_reset(CPUState *s)
 env->vfp.xregs[ARM_VFP_MVFR1] = cpu->mvfr1;
 env->vfp.xregs[ARM_VFP_MVFR2] = cpu->mvfr2;
 
+cpu->powered_off = cpu->start_powered_off;
+s->halted = cpu->start_powered_off;
+
 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
 env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
 }
diff --git a/target-arm/machine.c b/target-arm/machine.c
index ddb7d05..5776ee0 100644
--- a/target-arm/machine.c
+++ b/target-arm/machine.c
@@ -222,8 +222,8 @@ static int cpu_post_load(void *opaque, int version_id)
 
 const VMStateDescription vmstate_arm_cpu = {
 .name = "cpu",
-.version_id = 20,
-.minimum_version_id = 20,
+.version_id = 21,
+.minimum_version_id = 21,
 .pre_save = cpu_pre_save,
 .post_load = cpu_post_load,
 .fields = (VMStateField[]) {
@@ -263,6 +263,7 @@ const VMStateDescription vmstate_arm_cpu = {
 VMSTATE_UINT64(env.exception.vaddress, ARMCPU),
 VMSTATE_TIMER(gt_timer[GTIMER_PHYS], ARMCPU),
 VMSTATE_TIMER(gt_timer[GTIMER_VIRT], ARMCPU),
+VMSTATE_BOOL(powered_off, ARMCPU),
 VMSTATE_END_OF_LIST()
 },
 .subsections = (VMStateSubsection[]) {
-- 
1.9.1




[Qemu-devel] [PATCH v5 7/7] arm/virt: enable PSCI emulation support for system emulation

2014-10-09 Thread Peter Maydell
From: Rob Herring 

Now that we have PSCI emulation, enable it for the virt platform.
This simplifies the virt machine a bit now that PSCI no longer
needs to be a KVM only feature.

Signed-off-by: Rob Herring 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Peter Maydell 
---
 hw/arm/virt.c | 82 +++
 1 file changed, 38 insertions(+), 44 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 8c6b171..6cfd4bf 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -190,47 +190,48 @@ static void create_fdt(VirtBoardInfo *vbi)
 
 static void fdt_add_psci_node(const VirtBoardInfo *vbi)
 {
+uint32_t cpu_suspend_fn;
+uint32_t cpu_off_fn;
+uint32_t cpu_on_fn;
+uint32_t migrate_fn;
 void *fdt = vbi->fdt;
 ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0));
 
-/* No PSCI for TCG yet */
-if (kvm_enabled()) {
-uint32_t cpu_suspend_fn;
-uint32_t cpu_off_fn;
-uint32_t cpu_on_fn;
-uint32_t migrate_fn;
-
-qemu_fdt_add_subnode(fdt, "/psci");
-if (armcpu->psci_version == 2) {
-const char comp[] = "arm,psci-0.2\0arm,psci";
-qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp));
-
-cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF;
-if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) {
-cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND;
-cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON;
-migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE;
-} else {
-cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND;
-cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON;
-migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE;
-}
-} else {
-qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci");
+qemu_fdt_add_subnode(fdt, "/psci");
+if (armcpu->psci_version == 2) {
+const char comp[] = "arm,psci-0.2\0arm,psci";
+qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp));
 
-cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND;
-cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF;
-cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON;
-migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE;
+cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF;
+if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) {
+cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND;
+cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON;
+migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE;
+} else {
+cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND;
+cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON;
+migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE;
 }
+} else {
+qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci");
 
-qemu_fdt_setprop_string(fdt, "/psci", "method", "hvc");
-
-qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn);
-qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn);
-qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn);
-qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn);
+cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND;
+cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF;
+cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON;
+migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE;
 }
+
+/* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer
+ * to the instruction that should be used to invoke PSCI functions.
+ * However, the device tree binding uses 'method' instead, so that is
+ * what we should use here.
+ */
+qemu_fdt_setprop_string(fdt, "/psci", "method", "hvc");
+
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn);
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn);
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn);
+qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn);
 }
 
 static void fdt_add_timer_nodes(const VirtBoardInfo *vbi)
@@ -537,16 +538,6 @@ static void machvirt_init(MachineState *machine)
 
 vbi->smp_cpus = smp_cpus;
 
-/*
- * Only supported method of starting secondary CPUs is PSCI and
- * PSCI is not yet supported with TCG, so limit smp_cpus to 1
- * if we're not using KVM.
- */
-if (!kvm_enabled() && smp_cpus > 1) {
-error_report("mach-virt: must enable KVM to use multiple CPUs");
-exit(1);
-}
-
 if (machine->ram_size > vbi->memmap[VIRT_MEM].size) {
 error_report("mach-virt: cannot model more than 30GB RAM");
 exit(1);
@@ -565,6 +556,9 @@ static void machvirt_init(MachineState *machine)
 }
 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 */
 if (n > 0) {
 object_property_

[Qemu-devel] [PATCH v5 5/7] target-arm: Add support for A32 and T32 HVC and SMC insns

2014-10-09 Thread Peter Maydell
Add support for HVC and SMC instructions to the A32 and
T32 decoder. Using these for real exceptions to EL2 or EL3
is currently not supported (the do_interrupt routine does
not handle them) but we require the instruction support to
implement PSCI.

Signed-off-by: Peter Maydell 
---
 target-arm/internals.h |  10 +
 target-arm/translate.c | 103 +++--
 target-arm/translate.h |   2 +
 3 files changed, 104 insertions(+), 11 deletions(-)

diff --git a/target-arm/internals.h b/target-arm/internals.h
index b7547bb..e46de71 100644
--- a/target-arm/internals.h
+++ b/target-arm/internals.h
@@ -236,6 +236,16 @@ static inline uint32_t syn_aa32_svc(uint32_t imm16, bool 
is_thumb)
 | (is_thumb ? 0 : ARM_EL_IL);
 }
 
+static inline uint32_t syn_aa32_hvc(uint32_t imm16)
+{
+return (EC_AA32_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0x);
+}
+
+static inline uint32_t syn_aa32_smc(void)
+{
+return (EC_AA32_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL;
+}
+
 static inline uint32_t syn_aa64_bkpt(uint32_t imm16)
 {
 return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0x);
diff --git a/target-arm/translate.c b/target-arm/translate.c
index 8a2994f..4e764d3 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -941,6 +941,39 @@ static inline void gen_set_pc_im(DisasContext *s, 
target_ulong val)
 tcg_gen_movi_i32(cpu_R[15], val);
 }
 
+static inline void gen_hvc(DisasContext *s, int imm16)
+{
+/* The pre HVC helper handles cases when HVC gets trapped
+ * as an undefined insn by runtime configuration (ie before
+ * the insn really executes).
+ */
+gen_set_pc_im(s, s->pc - 4);
+gen_helper_pre_hvc(cpu_env);
+/* Otherwise we will treat this as a real exception which
+ * happens after execution of the insn. (The distinction matters
+ * for the PC value reported to the exception handler and also
+ * for single stepping.)
+ */
+s->svc_imm = imm16;
+gen_set_pc_im(s, s->pc);
+s->is_jmp = DISAS_HVC;
+}
+
+static inline void gen_smc(DisasContext *s)
+{
+/* As with HVC, we may take an exception either before or after
+ * the insn executes.
+ */
+TCGv_i32 tmp;
+
+gen_set_pc_im(s, s->pc - 4);
+tmp = tcg_const_i32(syn_aa32_smc());
+gen_helper_pre_smc(cpu_env, tmp);
+tcg_temp_free_i32(tmp);
+gen_set_pc_im(s, s->pc);
+s->is_jmp = DISAS_SMC;
+}
+
 static inline void
 gen_set_condexec (DisasContext *s)
 {
@@ -7872,15 +7905,32 @@ static void disas_arm_insn(CPUARMState * env, 
DisasContext *s)
 case 7:
 {
 int imm16 = extract32(insn, 0, 4) | (extract32(insn, 8, 12) << 4);
-/* SMC instruction (op1 == 3)
-   and undefined instructions (op1 == 0 || op1 == 2)
-   will trap */
-if (op1 != 1) {
+switch (op1) {
+case 1:
+/* bkpt */
+ARCH(5);
+gen_exception_insn(s, 4, EXCP_BKPT,
+   syn_aa32_bkpt(imm16, false));
+break;
+case 2:
+/* Hypervisor call (v7) */
+ARCH(7);
+if (IS_USER(s)) {
+goto illegal_op;
+}
+gen_hvc(s, imm16);
+break;
+case 3:
+/* Secure monitor call (v6+) */
+ARCH(6K);
+if (IS_USER(s)) {
+goto illegal_op;
+}
+gen_smc(s);
+break;
+default:
 goto illegal_op;
 }
-/* bkpt */
-ARCH(5);
-gen_exception_insn(s, 4, EXCP_BKPT, syn_aa32_bkpt(imm16, false));
 break;
 }
 case 0x8: /* signed multiply */
@@ -9710,10 +9760,23 @@ static int disas_thumb2_insn(CPUARMState *env, 
DisasContext *s, uint16_t insn_hw
 goto illegal_op;
 
 if (insn & (1 << 26)) {
-/* Secure monitor call (v6Z) */
-qemu_log_mask(LOG_UNIMP,
-  "arm: unimplemented secure monitor call\n");
-goto illegal_op; /* not implemented.  */
+if (!(insn & (1 << 20))) {
+/* Hypervisor call (v7) */
+int imm16 = extract32(insn, 16, 4) << 12
+| extract32(insn, 0, 12);
+ARCH(7);
+if (IS_USER(s)) {
+goto illegal_op;
+}
+gen_hvc(s, imm16);
+} else {
+/* Secure monitor call (v6+) */
+ARCH(6K);
+if (IS_USER(s)) {
+goto illegal_op;
+}
+gen_smc(s);
+   

[Qemu-devel] [PATCH v5 6/7] target-arm: add emulation of PSCI calls for system emulation

2014-10-09 Thread Peter Maydell
From: Rob Herring 

Add support for handling PSCI calls in system emulation. Both version
0.1 and 0.2 of the PSCI spec are supported. Platforms can enable support
by setting the "psci-conduit" QOM property on the cpus to SMC or HVC
emulation and having a PSCI binding in their dtb.

Signed-off-by: Rob Herring 
Signed-off-by: Ard Biesheuvel 
[PMM: made system reset/off PSCI functions power down the CPU so
 we obey the PSCI API requirement never to return from them;
 rearranged how the code is plumbed into the exception system,
 so that we split "is this a valid call?" from "do the call"]
Signed-off-by: Peter Maydell 
---
 target-arm/Makefile.objs |   1 +
 target-arm/cpu-qom.h |   5 +
 target-arm/cpu.c |  10 +-
 target-arm/cpu.h |   6 ++
 target-arm/helper-a64.c  |   6 ++
 target-arm/helper.c  |   6 ++
 target-arm/internals.h   |  12 +++
 target-arm/op_helper.c   |  16 
 target-arm/psci.c| 242 +++
 9 files changed, 301 insertions(+), 3 deletions(-)
 create mode 100644 target-arm/psci.c

diff --git a/target-arm/Makefile.objs b/target-arm/Makefile.objs
index dcd167e..9460b40 100644
--- a/target-arm/Makefile.objs
+++ b/target-arm/Makefile.objs
@@ -7,5 +7,6 @@ obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
 obj-y += translate.o op_helper.o helper.o cpu.o
 obj-y += neon_helper.o iwmmxt_helper.o
 obj-y += gdbstub.o
+obj-$(CONFIG_SOFTMMU) += psci.o
 obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o
 obj-y += crypto_helper.o
diff --git a/target-arm/cpu-qom.h b/target-arm/cpu-qom.h
index aeb7e1d..dcfda7d 100644
--- a/target-arm/cpu-qom.h
+++ b/target-arm/cpu-qom.h
@@ -101,6 +101,11 @@ typedef struct ARMCPU {
 /* CPU currently in PSCI powered-off state */
 bool powered_off;
 
+/* PSCI conduit used to invoke PSCI methods
+ * 0 - disabled, 1 - smc, 2 - hvc
+ */
+uint32_t psci_conduit;
+
 /* [QEMU_]KVM_ARM_TARGET_* constant for this CPU, or
  * QEMU_KVM_ARM_TARGET_NONE if the kernel doesn't support this CPU type.
  */
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 2061cb7..e837f64 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -334,9 +334,12 @@ static void arm_cpu_initfn(Object *obj)
 cpu->psci_version = 1; /* By default assume PSCI v0.1 */
 cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
 
-if (tcg_enabled() && !inited) {
-inited = true;
-arm_translate_init();
+if (tcg_enabled()) {
+cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
+if (!inited) {
+inited = true;
+arm_translate_init();
+}
 }
 }
 
@@ -1090,6 +1093,7 @@ static const ARMCPUInfo arm_cpus[] = {
 
 static Property arm_cpu_properties[] = {
 DEFINE_PROP_BOOL("start-powered-off", ARMCPU, start_powered_off, false),
+DEFINE_PROP_UINT32("psci-conduit", ARMCPU, psci_conduit, 0),
 DEFINE_PROP_UINT32("midr", ARMCPU, midr, 0),
 DEFINE_PROP_END_OF_LIST()
 };
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 65a3417..690686c 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -1484,4 +1484,10 @@ static inline void cpu_pc_from_tb(CPUARMState *env, 
TranslationBlock *tb)
 }
 }
 
+enum {
+QEMU_PSCI_CONDUIT_DISABLED = 0,
+QEMU_PSCI_CONDUIT_SMC = 1,
+QEMU_PSCI_CONDUIT_HVC = 2,
+};
+
 #endif
diff --git a/target-arm/helper-a64.c b/target-arm/helper-a64.c
index 7ae84f6..daf5adc 100644
--- a/target-arm/helper-a64.c
+++ b/target-arm/helper-a64.c
@@ -468,6 +468,12 @@ void aarch64_cpu_do_interrupt(CPUState *cs)
   env->exception.syndrome);
 }
 
+if (arm_is_psci_call(cpu, cs->exception_index)) {
+arm_handle_psci_call(cpu);
+qemu_log_mask(CPU_LOG_INT, "...handled as PSCI call\n");
+return;
+}
+
 switch (cs->exception_index) {
 case EXCP_PREFETCH_ABORT:
 case EXCP_DATA_ABORT:
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 497178a..d837820 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -3970,6 +3970,12 @@ void arm_cpu_do_interrupt(CPUState *cs)
 
 arm_log_exception(cs->exception_index);
 
+if (arm_is_psci_call(cpu, cs->exception_index)) {
+arm_handle_psci_call(cpu);
+qemu_log_mask(CPU_LOG_INT, "...handled as PSCI call\n");
+return;
+}
+
 /* If this is a debug exception we must update the DBGDSCR.MOE bits */
 switch (env->exception.syndrome >> ARM_EL_EC_SHIFT) {
 case EC_BREAKPOINT:
diff --git a/target-arm/internals.h b/target-arm/internals.h
index e46de71..51c5c16 100644
--- a/target-arm/internals.h
+++ b/target-arm/internals.h
@@ -366,4 +366,16 @@ void hw_breakpoint_update_all(ARMCPU *cpu);
 /* Callback function for when a watchpoint or breakpoint triggers. */
 void arm_debug_excp_handler(CPUState *cs);
 
+#ifdef CONFIG_USER_ONLY
+static inline bool arm_is_psci_call(ARMCPU *cpu, int excp_type)
+{
+return false;
+}
+#else
+/* Return true if the r0/x0 value indicates t

[Qemu-devel] [PATCH v5 3/7] target-arm: add missing PSCI constants needed for PSCI emulation

2014-10-09 Thread Peter Maydell
From: Ard Biesheuvel 

This adds some PSCI function IDs and symbolic return codes that are needed
to implement PSCI emulation in TCG mode.

Reviewed-by: Peter Maydell 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Peter Maydell 
---
 target-arm/kvm-consts.h | 40 
 1 file changed, 40 insertions(+)

diff --git a/target-arm/kvm-consts.h b/target-arm/kvm-consts.h
index 091c126..aea12f1 100644
--- a/target-arm/kvm-consts.h
+++ b/target-arm/kvm-consts.h
@@ -59,14 +59,21 @@ MISMATCH_CHECK(QEMU_PSCI_0_1_FN_MIGRATE, 
KVM_PSCI_FN_MIGRATE)
 (QEMU_PSCI_0_2_FN_BASE + QEMU_PSCI_0_2_64BIT)
 #define QEMU_PSCI_0_2_FN64(n) (QEMU_PSCI_0_2_FN64_BASE + (n))
 
+#define QEMU_PSCI_0_2_FN_PSCI_VERSION QEMU_PSCI_0_2_FN(0)
 #define QEMU_PSCI_0_2_FN_CPU_SUSPEND QEMU_PSCI_0_2_FN(1)
 #define QEMU_PSCI_0_2_FN_CPU_OFF QEMU_PSCI_0_2_FN(2)
 #define QEMU_PSCI_0_2_FN_CPU_ON QEMU_PSCI_0_2_FN(3)
+#define QEMU_PSCI_0_2_FN_AFFINITY_INFO QEMU_PSCI_0_2_FN(4)
 #define QEMU_PSCI_0_2_FN_MIGRATE QEMU_PSCI_0_2_FN(5)
+#define QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE QEMU_PSCI_0_2_FN(6)
+#define QEMU_PSCI_0_2_FN_MIGRATE_INFO_UP_CPU QEMU_PSCI_0_2_FN(7)
+#define QEMU_PSCI_0_2_FN_SYSTEM_OFF QEMU_PSCI_0_2_FN(8)
+#define QEMU_PSCI_0_2_FN_SYSTEM_RESET QEMU_PSCI_0_2_FN(9)
 
 #define QEMU_PSCI_0_2_FN64_CPU_SUSPEND QEMU_PSCI_0_2_FN64(1)
 #define QEMU_PSCI_0_2_FN64_CPU_OFF QEMU_PSCI_0_2_FN64(2)
 #define QEMU_PSCI_0_2_FN64_CPU_ON QEMU_PSCI_0_2_FN64(3)
+#define QEMU_PSCI_0_2_FN64_AFFINITY_INFO QEMU_PSCI_0_2_FN64(4)
 #define QEMU_PSCI_0_2_FN64_MIGRATE QEMU_PSCI_0_2_FN64(5)
 
 MISMATCH_CHECK(QEMU_PSCI_0_2_FN_CPU_SUSPEND, PSCI_0_2_FN_CPU_SUSPEND)
@@ -77,6 +84,39 @@ MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_SUSPEND, 
PSCI_0_2_FN64_CPU_SUSPEND)
 MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_ON, PSCI_0_2_FN64_CPU_ON)
 MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE, PSCI_0_2_FN64_MIGRATE)
 
+/* PSCI v0.2 return values used by TCG emulation of PSCI */
+
+/* No Trusted OS migration to worry about when offlining CPUs */
+#define QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED2
+
+/* We implement version 0.2 only */
+#define QEMU_PSCI_0_2_RET_VERSION_0_2   2
+
+MISMATCH_CHECK(QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED, PSCI_0_2_TOS_MP)
+MISMATCH_CHECK(QEMU_PSCI_0_2_RET_VERSION_0_2,
+   (PSCI_VERSION_MAJOR(0) | PSCI_VERSION_MINOR(2)))
+
+/* PSCI return values (inclusive of all PSCI versions) */
+#define QEMU_PSCI_RET_SUCCESS 0
+#define QEMU_PSCI_RET_NOT_SUPPORTED   -1
+#define QEMU_PSCI_RET_INVALID_PARAMS  -2
+#define QEMU_PSCI_RET_DENIED  -3
+#define QEMU_PSCI_RET_ALREADY_ON  -4
+#define QEMU_PSCI_RET_ON_PENDING  -5
+#define QEMU_PSCI_RET_INTERNAL_FAILURE-6
+#define QEMU_PSCI_RET_NOT_PRESENT -7
+#define QEMU_PSCI_RET_DISABLED-8
+
+MISMATCH_CHECK(QEMU_PSCI_RET_SUCCESS, PSCI_RET_SUCCESS)
+MISMATCH_CHECK(QEMU_PSCI_RET_NOT_SUPPORTED, PSCI_RET_NOT_SUPPORTED)
+MISMATCH_CHECK(QEMU_PSCI_RET_INVALID_PARAMS, PSCI_RET_INVALID_PARAMS)
+MISMATCH_CHECK(QEMU_PSCI_RET_DENIED, PSCI_RET_DENIED)
+MISMATCH_CHECK(QEMU_PSCI_RET_ALREADY_ON, PSCI_RET_ALREADY_ON)
+MISMATCH_CHECK(QEMU_PSCI_RET_ON_PENDING, PSCI_RET_ON_PENDING)
+MISMATCH_CHECK(QEMU_PSCI_RET_INTERNAL_FAILURE, PSCI_RET_INTERNAL_FAILURE)
+MISMATCH_CHECK(QEMU_PSCI_RET_NOT_PRESENT, PSCI_RET_NOT_PRESENT)
+MISMATCH_CHECK(QEMU_PSCI_RET_DISABLED, PSCI_RET_DISABLED)
+
 /* Note that KVM uses overlapping values for AArch32 and AArch64
  * target CPU numbers. AArch32 targets:
  */
-- 
1.9.1




[Qemu-devel] [PATCH v5 2/7] target-arm: do not set do_interrupt handlers for ARM and AArch64 user modes

2014-10-09 Thread Peter Maydell
From: Rob Herring 

User mode emulation should never get interrupts and thus should not
use the system emulation exception handler function. Remove the reference,
and '#ifndef USER_MODE_ONLY' the function itself as well, so that we can add
system mode only functionality to it.

Signed-off-by: Rob Herring 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Peter Maydell 
---
 target-arm/cpu.c| 2 +-
 target-arm/cpu64.c  | 2 ++
 target-arm/helper-a64.c | 3 +++
 target-arm/helper.c | 5 -
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 67cd176..2061cb7 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -1109,7 +1109,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void 
*data)
 
 cc->class_by_name = arm_cpu_class_by_name;
 cc->has_work = arm_cpu_has_work;
-cc->do_interrupt = arm_cpu_do_interrupt;
 cc->cpu_exec_interrupt = arm_cpu_exec_interrupt;
 cc->dump_state = arm_cpu_dump_state;
 cc->set_pc = arm_cpu_set_pc;
@@ -1118,6 +1117,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void 
*data)
 #ifdef CONFIG_USER_ONLY
 cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
 #else
+cc->do_interrupt = arm_cpu_do_interrupt;
 cc->get_phys_page_debug = arm_cpu_get_phys_page_debug;
 cc->vmsd = &vmstate_arm_cpu;
 #endif
diff --git a/target-arm/cpu64.c b/target-arm/cpu64.c
index c30f47e..a95367a 100644
--- a/target-arm/cpu64.c
+++ b/target-arm/cpu64.c
@@ -196,7 +196,9 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void 
*data)
 {
 CPUClass *cc = CPU_CLASS(oc);
 
+#if !defined(CONFIG_USER_ONLY)
 cc->do_interrupt = aarch64_cpu_do_interrupt;
+#endif
 cc->cpu_exec_interrupt = arm_cpu_exec_interrupt;
 cc->set_pc = aarch64_cpu_set_pc;
 cc->gdb_read_register = aarch64_cpu_gdb_read_register;
diff --git a/target-arm/helper-a64.c b/target-arm/helper-a64.c
index 8228e29..7ae84f6 100644
--- a/target-arm/helper-a64.c
+++ b/target-arm/helper-a64.c
@@ -438,6 +438,8 @@ uint64_t HELPER(crc32c_64)(uint64_t acc, uint64_t val, 
uint32_t bytes)
 return crc32c(acc, buf, bytes) ^ 0x;
 }
 
+#if !defined(CONFIG_USER_ONLY)
+
 /* Handle a CPU exception.  */
 void aarch64_cpu_do_interrupt(CPUState *cs)
 {
@@ -518,3 +520,4 @@ void aarch64_cpu_do_interrupt(CPUState *cs)
 env->pc = addr;
 cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
 }
+#endif
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 2669e15..497178a 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -3644,11 +3644,6 @@ uint32_t HELPER(rbit)(uint32_t x)
 
 #if defined(CONFIG_USER_ONLY)
 
-void arm_cpu_do_interrupt(CPUState *cs)
-{
-cs->exception_index = -1;
-}
-
 int arm_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
  int mmu_idx)
 {
-- 
1.9.1




Re: [Qemu-devel] [PATCH] disas/libvixl/a64/instructions-a64.h: Remove useless varialbe to avoid building break with '-Werror'

2014-10-09 Thread Peter Maydell
On 9 October 2014 15:00, Chen Gang  wrote:
> The related variables are useless, need be removed, or can not pass
> microblaze building, after fix it, can build microblaze, successfully.
>
> The related configuration:
>
>  ./configure --target-list="arm-softmmu,microblazeel-softmmu" --enable-fdt 
> --disable-kvm
>
> The related compiling error:

I build this code with both these targets enabled without any
problems.

There is an odd compiler thing where if you have any *other*
compilation issues then these warnings will also be emitted,
but once you've fixed that other compiler error then these
warnings are no longer produced. Maybe you ran into that?

The reason I'm reluctant to make changes to these files is
that they're pulled in from a different upstream project
(libvixl) so we should only fix critical problems in them,
or it makes new versions harder to update to.

thanks
-- PMM



Re: [Qemu-devel] [PATCH 1/1] hmp: Remove "info pcmcia"

2014-10-09 Thread Luiz Capitulino
On Wed, 01 Oct 2014 10:54:44 +0200
Markus Armbruster  wrote:

> Ping?
> 
> Markus Armbruster  writes:
> 
> > This command lists PCMCIA sockets and cards.  Only a few ARM boards
> > have sockets (akita, borzoi, connex, mainstone, spitz, terrier, tosa,
> > verdex, z2), the only card is the DSCM-1 Hitachi Microdrive (qdev
> > "microdrive"), and it is only inserted during machine init, if ever.
> > So this command doesn't really tell anybody anything new so far.
> >
> > Moreover, pcmcia_socket_unregister() has a use-after-free bug, flagged
> > by Coverity.  Has never been used, because there has never been code
> > to eject a PCMCIA card.
> >
> > Not worth fixing & converting to QMP.  Remove it.

Sorry for the long delay on this one. But this patch is more about PCMCIA
support in QEMU than HMP, so I can provide my ACK, but I don't think this
is HMP material.

Acked-by: Luiz Capitulino 



Re: [Qemu-devel] [PATCH] hw/arm/virt: mark timer in fdt as v8-compatible

2014-10-09 Thread Claudio Fontana
Hello Peter,

are you ok with this one?

Thanks,

Claudio

On 26 September 2014 15:09,   wrote:
> From: Claudio Fontana 
>
> check if the first cpu is an armv8 cpu, and if so, put
> arm,armv8-timer in the compatible string list.
>
> Note that due to this check, this patch moves the creation
> of the timer fdt node to after the cpu creation loop.
>
> Signed-off-by: Claudio Fontana 
> ---
>  hw/arm/virt.c | 15 ---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 8c6b171..eeb3105 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -239,14 +239,23 @@ static void fdt_add_timer_nodes(const VirtBoardInfo 
> *vbi)
>   * but for the GIC implementation provided by both QEMU and KVM
>   * they are edge-triggered.
>   */
> +ARMCPU *armcpu;
>  uint32_t irqflags = GIC_FDT_IRQ_FLAGS_EDGE_LO_HI;
>
>  irqflags = deposit32(irqflags, GIC_FDT_IRQ_PPI_CPU_START,
>   GIC_FDT_IRQ_PPI_CPU_WIDTH, (1 << vbi->smp_cpus) - 
> 1);
>
>  qemu_fdt_add_subnode(vbi->fdt, "/timer");
> -qemu_fdt_setprop_string(vbi->fdt, "/timer",
> -"compatible", "arm,armv7-timer");
> +
> +armcpu = ARM_CPU(qemu_get_cpu(0));
> +if (arm_feature(&armcpu->env, ARM_FEATURE_V8)) {
> +const char compat[] = "arm,armv7-timer\0arm,armv8-timer";
> +qemu_fdt_setprop(vbi->fdt, "/timer", "compatible",
> + compat, sizeof(compat));
> +} else {
> +qemu_fdt_setprop_string(vbi->fdt, "/timer", "compatible",
> +"arm,armv7-timer");
> +}
>  qemu_fdt_setprop_cells(vbi->fdt, "/timer", "interrupts",
> GIC_FDT_IRQ_TYPE_PPI, 13, irqflags,
> GIC_FDT_IRQ_TYPE_PPI, 14, irqflags,
> @@ -553,7 +562,6 @@ static void machvirt_init(MachineState *machine)
>  }
>
>  create_fdt(vbi);
> -fdt_add_timer_nodes(vbi);
>
>  for (n = 0; n < smp_cpus; n++) {
>  ObjectClass *oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
> @@ -577,6 +585,7 @@ static void machvirt_init(MachineState *machine)
>
>  object_property_set_bool(cpuobj, true, "realized", NULL);
>  }
> +fdt_add_timer_nodes(vbi);
>  fdt_add_cpu_nodes(vbi);
>  fdt_add_psci_node(vbi);
>
> --
> 1.8.5.3
>



Re: [Qemu-devel] [PATCH 1/1] hmp: Remove "info pcmcia"

2014-10-09 Thread Andreas Färber
Am 09.10.2014 um 15:47 schrieb Luiz Capitulino:
> On Wed, 01 Oct 2014 10:54:44 +0200
> Markus Armbruster  wrote:
> 
>> Ping?
>>
>> Markus Armbruster  writes:
>>
>>> This command lists PCMCIA sockets and cards.  Only a few ARM boards
>>> have sockets (akita, borzoi, connex, mainstone, spitz, terrier, tosa,
>>> verdex, z2), the only card is the DSCM-1 Hitachi Microdrive (qdev
>>> "microdrive"), and it is only inserted during machine init, if ever.
>>> So this command doesn't really tell anybody anything new so far.
>>>
>>> Moreover, pcmcia_socket_unregister() has a use-after-free bug, flagged
>>> by Coverity.  Has never been used, because there has never been code
>>> to eject a PCMCIA card.
>>>
>>> Not worth fixing & converting to QMP.  Remove it.
> 
> Sorry for the long delay on this one. But this patch is more about PCMCIA
> support in QEMU than HMP, so I can provide my ACK, but I don't think this
> is HMP material.
> 
> Acked-by: Luiz Capitulino 

As the probably last one to have touched the ugly PCMCIA code,

Acked-by: Andreas Färber 

Maybe take it through the arm queue due to affected machines, Peter?

Regards,
Andreas

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



Re: [Qemu-devel] [PATCH] disas/libvixl/a64/instructions-a64.h: Remove useless varialbe to avoid building break with '-Werror'

2014-10-09 Thread Eric Blake
On 10/09/2014 08:00 AM, Chen Gang wrote:

That's a very long subject line.  Try to keep subjects around 60
characters or so ('git shortlog -30' can give you an idea of reasonable
subjects).  Also, s/varialbe/variable/ in the subject.

> The related variables are useless, need be removed, or can not pass
> microblaze building, after fix it, can build microblaze, successfully.
> 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [question] is it posssible that big-endian l1 table offset referenced by other I/O while updating l1 table offset in qcow2_update_snapshot_refcount?

2014-10-09 Thread Eric Blake
On 10/09/2014 05:17 AM, Zhang Haoyu wrote:
> Hi,
> I encounter a problem that after deleting snaptshot, the qcow2 image size is 
> very larger than that it should be displayed by ls command, 
> but the virtual disk size is okay via qemu-img info.
> I suspect that during updating l1 table offset, other I/O job reference the 
> big-endian l1 table offset (very large value), so the file is truncated to 
> very large.

Not quite.  Rather, all the data that the snapshot used to occupy is
still consuming holes in the file; the maximum offset of the file is
still unchanged, even if the file is no longer using as many referenced
clusters.  Recent changes have gone in to sparsify the file when
possible (punching holes if your kernel and file system is new enough to
support that), so that it is not consuming the amount of disk space that
a mere ls reports.  But if what you are asking for is a way to compact
the file back down, then you'll need to submit a patch.  The idea of
having an online defragmenter for qcow2 files has been kicked around
before, but it is complex enough that no one has attempted a patch yet.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 1/1] hmp: Remove "info pcmcia"

2014-10-09 Thread Peter Maydell
On 9 October 2014 15:41, Andreas Färber  wrote:
> Am 09.10.2014 um 15:47 schrieb Luiz Capitulino:
>> On Wed, 01 Oct 2014 10:54:44 +0200
>> Markus Armbruster  wrote:
>>
>>> Ping?
>>>
>>> Markus Armbruster  writes:
>>>
 This command lists PCMCIA sockets and cards.  Only a few ARM boards
 have sockets (akita, borzoi, connex, mainstone, spitz, terrier, tosa,
 verdex, z2), the only card is the DSCM-1 Hitachi Microdrive (qdev
 "microdrive"), and it is only inserted during machine init, if ever.
 So this command doesn't really tell anybody anything new so far.

 Moreover, pcmcia_socket_unregister() has a use-after-free bug, flagged
 by Coverity.  Has never been used, because there has never been code
 to eject a PCMCIA card.

 Not worth fixing & converting to QMP.  Remove it.
>>
>> Sorry for the long delay on this one. But this patch is more about PCMCIA
>> support in QEMU than HMP, so I can provide my ACK, but I don't think this
>> is HMP material.
>>
>> Acked-by: Luiz Capitulino 
>
> As the probably last one to have touched the ugly PCMCIA code,
>
> Acked-by: Andreas Färber 
>
> Maybe take it through the arm queue due to affected machines, Peter?

I don't particularly care -- the machines in question are near-dead
so there's not much chance of conflicts. I can take it if that's
easiest for everybody I guess?

-- PMM



Re: [Qemu-devel] [PATCH 1/1] hmp: Remove "info pcmcia"

2014-10-09 Thread Markus Armbruster
Peter Maydell  writes:

> On 9 October 2014 15:41, Andreas Färber  wrote:
>> Am 09.10.2014 um 15:47 schrieb Luiz Capitulino:
>>> On Wed, 01 Oct 2014 10:54:44 +0200
>>> Markus Armbruster  wrote:
>>>
 Ping?

 Markus Armbruster  writes:

> This command lists PCMCIA sockets and cards.  Only a few ARM boards
> have sockets (akita, borzoi, connex, mainstone, spitz, terrier, tosa,
> verdex, z2), the only card is the DSCM-1 Hitachi Microdrive (qdev
> "microdrive"), and it is only inserted during machine init, if ever.
> So this command doesn't really tell anybody anything new so far.
>
> Moreover, pcmcia_socket_unregister() has a use-after-free bug, flagged
> by Coverity.  Has never been used, because there has never been code
> to eject a PCMCIA card.
>
> Not worth fixing & converting to QMP.  Remove it.
>>>
>>> Sorry for the long delay on this one. But this patch is more about PCMCIA
>>> support in QEMU than HMP, so I can provide my ACK, but I don't think this
>>> is HMP material.
>>>
>>> Acked-by: Luiz Capitulino 
>>
>> As the probably last one to have touched the ugly PCMCIA code,
>>
>> Acked-by: Andreas Färber 
>>
>> Maybe take it through the arm queue due to affected machines, Peter?
>
> I don't particularly care -- the machines in question are near-dead
> so there's not much chance of conflicts. I can take it if that's
> easiest for everybody I guess?

Yes, please!



Re: [Qemu-devel] [PATCH] linux-user: Let user specify random seed

2014-10-09 Thread Eric Blake
On 10/09/2014 02:36 AM, Magnus Reftel wrote:
> This patch introduces the -seed command line option and the
> QEMU_RAND_SEED environment variable for setting the random seed, which
> is used for the AT_RANDOM ELF aux entry.
> 
> Signed-off-by: Magnus Reftel 
> ---

>  
> +static void handle_arg_randseed(const char *arg)
> +{
> +unsigned long seed;
> +char* end;

Style: we prefer:

char *end;

> +seed = strtoul(arg, &end, 0);
> +if (end==arg || *end!='\0' || seed > UINT_MAX) {

Style: spaces around operators:

if (end == arg || *end || seed > UINT_MAX) {

Bug: strtoul() sometimes reports error via errno; the only safe way to
use it is to first prime errno = 0, then do strtoul, then check if errno
was changed.

Reimplementation: util/cutils.c already provides parse_uint() that takes
care of calling strtoul safely (hmm, that version only parses 64-bit
numbers; maybe we should expand it to also parse 32-bit numbers?)

Surprising behavior: your code behaves differently on 32-bit hosts than
it does on 64-bit hosts.  Seriously.  strotoul() has the annoying
specification of requiring twos-complement wraparound according to the
size of long, which means "-1" on a 32-bit platform parses as 0x
(accepted), while on a 64-bit platform parses it as 0x
(which you reject as > UINT_MAX); conversely "-18446744073709551615"
fails to parse due to overflow on a 32-bit platform, while successfully
being parsed as 1 on 64-bit.

> +fprintf(stderr, "Invalid seed number: %s\n", arg);
> +exit(1);
> +}
> +srand(seed);
> +}
> +
>  static void handle_arg_gdb(const char *arg)
>  {
>  gdbstub_port = atoi(arg);
> @@ -3674,6 +3686,8 @@ static const struct qemu_argument arg_table[] = {
>   "",   "run in singlestep mode"},
>  {"strace", "QEMU_STRACE",  false, handle_arg_strace,
>   "",   "log system calls"},
> +{"seed",   "QEMU_RAND_SEED",   true,  handle_arg_randseed,
> + "",   "Seed for pseudo-random number generator"},
>  {"version","QEMU_VERSION", false, handle_arg_version,
>   "",   "display version information and exit"},
>  {NULL, NULL, false, NULL, NULL, NULL}
> @@ -3856,6 +3870,8 @@ int main(int argc, char **argv, char **envp)
>  cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
>  #endif
>  
> +srand(time(NULL));
> +
>  optind = parse_args(argc, argv);
>  
>  /* Zero out regs */
> @@ -3926,6 +3942,10 @@ int main(int argc, char **argv, char **envp)
>  do_strace = 1;
>  }
>  
> +if (getenv("QEMU_RAND_SEED")) {
> +handle_arg_randseed(getenv("QEMU_RAND_SEED"));
> +}

Now that you have exactly one caller of the static function, it might
make sense to just inline the body of that function here.

> +
>  target_environ = envlist_to_environ(envlist, NULL);
>  envlist_free(envlist);
>  
> 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


qemu-devel@nongnu.org

2014-10-09 Thread Jiri Gaisler

I am a bit against the merge of AHB and APB initialization into
the same function. A grlib system can have any number of AHB and APB
buses, so there really should be a separate init routine per bus
as in the original patch.

Jiri.

On 10/09/2014 01:05 PM, Fabien Chouteau wrote:
> From: Jiri Gaisler 
> 
> AMBA plug&play is used by kernels to probe available devices (Timers,
> UART, etc...). This is a static declaration of devices implemented in
> QEMU. In the future, a more advanced version could compute those
> information directly from the device tree.
> 
> Signed-off-by: Fabien Chouteau 
> ---
> 
> V2:
>  - AHB and APB PNP are now grouped in one device
>  - Initialisation moved to .instance_init
>  - Minor fixes
> 
>  hw/sparc/Makefile.objs   |1 +
>  hw/sparc/grlib_ambapnp.c |  149 
> ++
>  hw/sparc/leon3.c |3 +
>  include/hw/sparc/grlib.h |   22 +++
>  4 files changed, 175 insertions(+)
>  create mode 100644 hw/sparc/grlib_ambapnp.c
> 
> diff --git a/hw/sparc/Makefile.objs b/hw/sparc/Makefile.objs
> index c987b5b..e763701 100644
> --- a/hw/sparc/Makefile.objs
> +++ b/hw/sparc/Makefile.objs
> @@ -1 +1,2 @@
>  obj-y += sun4m.o leon3.o
> +obj-$(CONFIG_GRLIB) += grlib_ambapnp.o
> diff --git a/hw/sparc/grlib_ambapnp.c b/hw/sparc/grlib_ambapnp.c
> new file mode 100644
> index 000..dd53004
> --- /dev/null
> +++ b/hw/sparc/grlib_ambapnp.c
> @@ -0,0 +1,149 @@
> +/*
> + * QEMU GRLIB AMBA Plug&Play Emulator
> + *
> + * 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/sysbus.h"
> +#include "hw/sparc/grlib.h"
> +
> +/* Size of memory mapped registers */
> +#define APBPNP_REG_SIZE (4096 - 8)
> +#define AHBPNP_REG_SIZE 4096
> +
> +#define GRLIB_AMBA_PNP(obj) \
> +OBJECT_CHECK(AMBAPNP, (obj), TYPE_GRLIB_AMBA_PNP)
> +
> +typedef struct AMBAPNP {
> +SysBusDevice parent_obj;
> +MemoryRegion ahb_iomem;
> +MemoryRegion apb_iomem;
> +} AMBAPNP;
> +
> +/* APB PNP */
> +
> +static uint64_t grlib_apbpnp_read(void *opaque, hwaddr addr,
> +   unsigned size)
> +{
> +uint64_t read_data;
> +addr &= 0xfff;
> +
> +/* Unit registers */
> +switch (addr & 0xffc) {
> +case 0x00:
> +read_data = 0x0400f000; /* Memory controller */
> +break;
> +case 0x04:
> +read_data = 0xfff1;
> +break;
> +case 0x08:
> +read_data = 0x0100c023; /* APBUART */
> +break;
> +case 0x0C:
> +read_data = 0x0010fff1;
> +break;
> +case 0x10:
> +read_data = 0x0100d040; /* IRQMP */
> +break;
> +case 0x14:
> +read_data = 0x0020fff1;
> +break;
> +case 0x18:
> +read_data = 0x01011006; /* GPTIMER */
> +break;
> +case 0x1C:
> +read_data = 0x0030fff1;
> +break;
> +
> +default:
> +read_data = 0;
> +}
> +if (size == 1) {
> +read_data >>= (24 - (addr & 3) * 8);
> +read_data &= 0x0ff;
> +}
> +return read_data;
> +}
> +
> +static const MemoryRegionOps grlib_apbpnp_ops = {
> +.read   = grlib_apbpnp_read,
> +.endianness = DEVICE_NATIVE_ENDIAN,
> +};
> +
> +/* AHB PNP */
> +
> +static uint64_t grlib_ahbpnp_read(void *opaque, hwaddr addr,
> +   unsigned size)
> +{
> +addr &= 0xffc;
> +
> +/* Unit registers */
> +switch (addr) {
> +case 0:
> +return 0x01003000;  /* LEON3 */
> +case 0x800:
> +return 0x0400f000;  /* Memory controller  */
> +case 0x810:
> +return 0x0003e002;
> +case 0x814:
> +return 0x2000e002;
> +case 0x818:
> +return 0x4003c002;
> +case 0x820:
> +return 0x01006000;  /* APB bridge @ 0x8000 */
> +case 0x830:
> +return 0x8000fff2;
> +
> +default:
> +return 0;
> +}
> +}
> +
> +static c

[Qemu-devel] qemu is missing monitor

2014-10-09 Thread Jiri Slaby
Hi guys,

qemu in opensuse latest (factory) does not have monitor. Despite
libvte-devel is installed, it is not detected by qemu. The problem is
that configure looks for vte-2.90, but we have vte-2.91 in factory. The
attached patch fixes that for factory, but it's dirty, of course.

Any better idea?

thanks,
-- 
js
suse labs



vte-2.91-for-factory.patch
Description: application/mbox


Re: [Qemu-devel] [PULL v3 00/28] Changes for 2014-10-09

2014-10-09 Thread Peter Maydell
On 9 October 2014 14:40, Paolo Bonzini  wrote:
> The following changes since commit 1831e150606a221898bf46ffaf0453e9952cbbc4:
>
>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into 
> staging (2014-09-30 16:45:35 +0100)
>
> are available in the git repository at:
>
>
>   git://github.com/bonzini/qemu.git tags/for-upstream
>
> for you to fetch changes up to 5008e5b7b817b5ea2b788203122cd50e7c16e599:
>
>   qemu-char: Fix reconnect socket error reporting (2014-10-09 15:36:15 +0200)
>
> 
> Four changes here.  Polling for reconnection of character devices,
> the QOMification of accelerators, a fix for -kernel support on x86, and one
> for a recently-introduced virtio-scsi optimization.
>
> 

Applied, thanks. PS: where we end up doing multiple versions
of a pullreq it would be helpful to add a version indication
to the tag name or the tag commit message or both, so it's
easier for me to be sure I have the right one (and it gets
recorded in the git commit history).

thanks
-- PMM



Re: [Qemu-devel] qemu is missing monitor

2014-10-09 Thread Peter Maydell
On 9 October 2014 14:37, Jiri Slaby  wrote:
> Hi guys,
>
> qemu in opensuse latest (factory) does not have monitor. Despite
> libvte-devel is installed, it is not detected by qemu. The problem is
> that configure looks for vte-2.90, but we have vte-2.91 in factory. The
> attached patch fixes that for factory, but it's dirty, of course.

Why the heck have the GTK folk made point releases end up
needing their own pkg-config library name??

-- PMM



Re: [Qemu-devel] [PULL 0/8] s390x patches for 2.2

2014-10-09 Thread Peter Maydell
On 9 October 2014 14:35, Cornelia Huck  wrote:
> The following changes since commit b6011bd8a57c1eda81a857d21adeb9b66e58b1b0:
>
>   Merge remote-tracking branch 'remotes/riku/tags/pull-linux-user-20141006-2' 
> into staging (2014-10-07 10:41:48 +0100)
>
> are available in the git repository at:
>
>
>   git://github.com/cohuck/qemu.git tags/s390x-20141009
>
> for you to fetch changes up to 2adf6bbb8ad7e53f602d10b2b30d22cd831f79a6:
>
>   s390x/virtio-ccw: fix vhost-scsi intialization (2014-10-09 14:22:47 +0200)
>
> 
> various s390x updates:
> - cpu state handling in qemu and migration
> - vhost-scsi-ccw bugfix

Hi. I'm afraid this fails to link the linux-user target:

  LINK  s390x-linux-user/qemu-s390x
target-s390x/cpu.o:(.data+0xbc): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0xec): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x11c): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x14c): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x17c): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x1ac): more undefined references to
`vmstate_info_uint64' follow
target-s390x/cpu.o:(.data+0x47c): undefined reference to `vmstate_info_uint32'
target-s390x/cpu.o:(.data+0x4ac): undefined reference to `vmstate_info_uint32'
target-s390x/cpu.o:(.data+0x4dc): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x50c): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x53c): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x56c): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x59c): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x5cc): more undefined references to
`vmstate_info_uint64' follow
target-s390x/cpu.o:(.data+0x62c): undefined reference to `vmstate_info_uint32'
target-s390x/cpu.o:(.data+0x65c): undefined reference to `vmstate_info_uint64'
target-s390x/cpu.o:(.data+0x68c): undefined reference to `vmstate_info_uint8'
collect2: error: ld returned 1 exit status

-- PMM



  1   2   >