Re: [Qemu-devel] [PATCH v8 45/54] Host page!=target page: Cleanup bitmaps

2015-10-28 Thread Juan Quintela
"Dr. David Alan Gilbert (git)"  wrote:
> From: "Dr. David Alan Gilbert" 
>
> Prior to the start of postcopy, ensure that everything that will
> be transferred later is a whole host-page in size.
>
> This is accomplished by discarding partially transferred host pages
> and marking any that are partially dirty as fully dirty.
>
> Signed-off-by: Dr. David Alan Gilbert 
> +struct RAMBlock *block;
> +unsigned int host_ratio = qemu_host_page_size / TARGET_PAGE_SIZE;
> +
> +if (qemu_host_page_size == TARGET_PAGE_SIZE) {
> +/* Easy case - TPS==HPS - nothing to be done */
> +return 0;
> +}
> +
> +/* Easiest way to make sure we don't resume in the middle of a host-page 
> */
> +last_seen_block = NULL;
> +last_sent_block = NULL;
> +last_offset = 0;


It should be enough with the last one, right?  if you put
last_seen/sent_block to NULL, you will return from the beggining each
time that you do a migration bitmap sync, penalizing the pages on the
begining of the cycle.  Even better than:

last_offset = 0 is doing a:

last_offset &= HOST_PAGE_MASK

or whatever is the constant, no?



> +
> +QLIST_FOREACH_RCU(block, _list.blocks, next) {
> +unsigned long first = block->offset >> TARGET_PAGE_BITS;
> +unsigned long len = block->used_length >> TARGET_PAGE_BITS;
> +unsigned long last = first + (len - 1);
> +unsigned long found_set;
> +unsigned long search_start;

next_search?  search_next?


> +
> +PostcopyDiscardState *pds =
> + postcopy_discard_send_init(ms, first, block->idstr);
> +
> +/* First pass: Discard all partially sent host pages */
> +found_set = find_next_bit(ms->sentmap, last + 1, first);
> +while (found_set <= last) {
> +bool do_discard = false;
> +unsigned long discard_start_addr;
> +/*
> + * If the start of this run of pages is in the middle of a host
> + * page, then we need to discard this host page.
> + */
> +if (found_set % host_ratio) {
> +do_discard = true;
> +found_set -= found_set % host_ratio;

please, create a PAGE_HOST_ALIGN() macro, or whatever you want to call it?


> +discard_start_addr = found_set;
> +search_start = found_set + host_ratio;
> +} else {
> +/* Find the end of this run */
> +unsigned long found_zero;
> +found_zero = find_next_zero_bit(ms->sentmap, last + 1,
> +found_set + 1);
> +/*
> + * If the 0 isn't at the start of a host page, then the
> + * run of 1's doesn't finish at the end of a host page
> + * and we need to discard.
> + */
> +if (found_zero % host_ratio) {
> +do_discard = true;
> +discard_start_addr = found_zero - (found_zero % 
> host_ratio);
> +/*
> + * This host page has gone, the next loop iteration 
> starts
> + * from the next page with a 1 bit
> + */
> +search_start = discard_start_addr + host_ratio;
> +} else {
> +/*
> + * No discards on this iteration, next loop starts from
> + * next 1 bit
> + */
> +search_start = found_zero + 1;

change for this

found_set = found_zero + 1;

> +}
> +}
> +/* Find the next 1 for the next iteration */
> +found_set = find_next_bit(ms->sentmap, last + 1, search_start);


and move previous line to:

> +if (do_discard) {
> +unsigned long page;
> +
> +/* Tell the destination to discard this page */
> +postcopy_discard_send_range(ms, pds, discard_start_addr,
> + discard_start_addr + host_ratio - 1);
> +/* Clean up the bitmap */
> +for (page = discard_start_addr;
> + page < discard_start_addr + host_ratio; page++) {
> +/* All pages in this host page are now not sent */
> +clear_bit(page, ms->sentmap);
> +
> +/*
> + * Remark them as dirty, updating the count for any pages
> + * that weren't previously dirty.
> + */
> +migration_dirty_pages += !test_and_set_bit(page,
> + 
> migration_bitmap);
> +}


to here
   /* Find the next 1 for the next iteration */
   found_set = find_next_bit(ms->sentmap, last + 

Re: [Qemu-devel] [PATCH 5/6] virtio-scsi: convert to virtqueue_map

2015-10-28 Thread Igor Mammedov
On Tue, 27 Oct 2015 10:48:06 +0200
"Michael S. Tsirkin"  wrote:

> Note: virtqueue_map already validates input
> so virtio-scsi does not have to.
> 
> Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 

> ---
>  hw/scsi/virtio-scsi.c | 16 ++--
>  1 file changed, 2 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> index 1c33f14..33bd25a 100644
> --- a/hw/scsi/virtio-scsi.c
> +++ b/hw/scsi/virtio-scsi.c
> @@ -207,20 +207,8 @@ static void *virtio_scsi_load_request(QEMUFile *f, 
> SCSIRequest *sreq)
>  assert(n < vs->conf.num_queues);
>  req = virtio_scsi_init_req(s, vs->cmd_vqs[n]);
>  qemu_get_buffer(f, (unsigned char *)>elem, sizeof(req->elem));
> -/* TODO: add a way for SCSIBusInfo's load_request to fail,
> - * and fail migration instead of asserting here.
> - * When we do, we might be able to re-enable NDEBUG below.
> - */
> -#ifdef NDEBUG
> -#error building with NDEBUG is not supported
> -#endif
> -assert(req->elem.in_num <= ARRAY_SIZE(req->elem.in_sg));
> -assert(req->elem.out_num <= ARRAY_SIZE(req->elem.out_sg));
> -
> -virtqueue_map_sg(req->elem.in_sg, req->elem.in_addr,
> - req->elem.in_num, 1);
> -virtqueue_map_sg(req->elem.out_sg, req->elem.out_addr,
> - req->elem.out_num, 0);
> +
> +virtqueue_map(>elem);
>  
>  if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
>sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 
> 0) {




Re: [Qemu-devel] [PATCH 3/6] virtio-blk: convert to virtqueue_map

2015-10-28 Thread Igor Mammedov
On Tue, 27 Oct 2015 10:48:01 +0200
"Michael S. Tsirkin"  wrote:

> Drop deprecated use of virtqueue_map_sg.
> 
> Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 

> ---
>  hw/block/virtio-blk.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index 8beb26b..3e230de 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -839,10 +839,7 @@ static int virtio_blk_load_device(VirtIODevice *vdev, 
> QEMUFile *f,
>  req->next = s->rq;
>  s->rq = req;
>  
> -virtqueue_map_sg(req->elem.in_sg, req->elem.in_addr,
> -req->elem.in_num, 1);
> -virtqueue_map_sg(req->elem.out_sg, req->elem.out_addr,
> -req->elem.out_num, 0);
> +virtqueue_map(>elem);
>  }
>  
>  return 0;




Re: [Qemu-devel] [PATCH 1/6] virtio: introduce virtio_map

2015-10-28 Thread Igor Mammedov
On Tue, 27 Oct 2015 10:47:56 +0200
"Michael S. Tsirkin"  wrote:

> virtio_map_sg currently fails if one of the entries it's mapping is
> contigious in GPA but not HVA address space.  Introduce virtio_map which
> handles this by splitting sg entries.
> 
> This new API generally turns out to be a good idea since it's harder to
> misuse: at least in one case the existing one was used incorrectly.
> 
> This will still fail if there's no space left in the sg, but luckily max
> queue size in use is currently 256, while max sg size is 1024, so we
> should be OK even is all entries happen to cross a single DIMM boundary.
 ^^ S/is/if/
> 
> Won't work well with very small DIMM sizes, unfortunately:
> e.g. this will fail with 4K DIMMs where a single
> request might span a large number of DIMMs.
> 
> Let's hope these are uncommon - at least we are not breaking things.
> 
> Note: virtio-scsi calls virtio_map_sg on data loaded from network, and
> validates input, asserting on failure.  Copy the validating code here -
> it will be dropped from virtio-scsi in a follow-up patch.
> 
> Reported-by: Igor Mammedov 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  include/hw/virtio/virtio.h |  1 +
>  hw/virtio/virtio.c | 56 
> ++
>  2 files changed, 48 insertions(+), 9 deletions(-)
> 
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 9d09115..9d9abb4 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -153,6 +153,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement 
> *elem,
>  
>  void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
>  size_t num_sg, int is_write);
> +void virtqueue_map(VirtQueueElement *elem);
>  int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
>  int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
>unsigned int out_bytes);
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index d0bc72e..a6878c0 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -448,28 +448,66 @@ int virtqueue_avail_bytes(VirtQueue *vq, unsigned int 
> in_bytes,
>  return in_bytes <= in_total && out_bytes <= out_total;
>  }
>  
> -void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
> -size_t num_sg, int is_write)
> +static void virtqueue_map_iovec(struct iovec *sg, hwaddr *addr,
> +size_t *num_sg, size_t max_size,
> +int is_write)
this fails to build with:
hw/virtio/virtio.c:498:25: error: passing argument 3 of ‘virtqueue_map_iovec’ 
from incompatible pointer type [-Werror]

here is fixup:
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 10cd03a..ef42baa 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -449,7 +449,7 @@ int virtqueue_avail_bytes(VirtQueue *vq, unsigned int 
in_bytes,
 }
 
 static void virtqueue_map_iovec(struct iovec *sg, hwaddr *addr,
-size_t *num_sg, size_t max_size,
+unsigned int *num_sg, size_t max_size,
 int is_write)


>  {
>  unsigned int i;
>  hwaddr len;
>  
> -if (num_sg > VIRTQUEUE_MAX_SIZE) {
> -error_report("virtio: map attempt out of bounds: %zd > %d",
> - num_sg, VIRTQUEUE_MAX_SIZE);
> -exit(1);
> -}
> +/* Note: this function MUST validate input, some callers
> + * are passing in num_sg values received over the network.
> + */
> +/* TODO: teach all callers that this can fail, and return failure instead
> + * of asserting here.
> + * When we do, we might be able to re-enable NDEBUG below.
> + */
> +#ifdef NDEBUG
> +#error building with NDEBUG is not supported
> +#endif
> +assert(*num_sg <= max_size);
>  
> -for (i = 0; i < num_sg; i++) {
> +for (i = 0; i < *num_sg; i++) {
>  len = sg[i].iov_len;
>  sg[i].iov_base = cpu_physical_memory_map(addr[i], , is_write);
> -if (sg[i].iov_base == NULL || len != sg[i].iov_len) {
> +if (!sg[i].iov_base) {
>  error_report("virtio: error trying to map MMIO memory");
>  exit(1);
>  }
> +if (len == sg[i].iov_len) {
> +continue;
> +}
> +if (*num_sg >= max_size) {
> +error_report("virtio: memory split makes iovec too large");
> +exit(1);
> +}
> +memcpy(sg + i + 1, sg + i, sizeof(*sg) * (*num_sg - i));
> +memcpy(addr + i + 1, addr + i, sizeof(*addr) * (*num_sg - i));
> +assert(len < sg[i + 1].iov_len);
> +sg[i].iov_len = len;
> +addr[i + 1] += len;
> +sg[i + 1].iov_len -= len;
> +++*num_sg;
>  }
>  }
>  
> +/* Deprecated: don't use in new code */
> +void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
> +  size_t num_sg, int 

Re: [Qemu-devel] [PATCH 0/6] virtio: handle non contigious s/g entries

2015-10-28 Thread Igor Mammedov
On Tue, 27 Oct 2015 13:51:20 +0200
"Michael S. Tsirkin"  wrote:

> On Tue, Oct 27, 2015 at 10:47:54AM +0200, Michael S. Tsirkin wrote:
> > TL;DR:
> > This fixes virtio in a way transparent to guest.
> > We should now be able to revert commits aa8580cd and df0acded19ec which 
> > worked
> > around it in a way that's not transparent.
> 
> I didn't check dataplane BTW. Igor? Stefan?
verified that series fixes virtio-[blk|scsi|net], all of them
hit at least one descriptor(indirect) that crosses DIMM boundary
and QEMU survived it.

However as Stefan has said virtio-blk with dataplane enabled hangs
guest instead of QEMU crashing and QEMU prints following error:

"Failed to map descriptor addr 0x1045eb000 len 106496"

I've used following CLI:
qemu-system-x86_64 -enable-kvm -enable-kvm  -m 128M,slots=250,maxmem=32G  
-drive if=none,id=hd,file=rhel72.img,cache=none,aio=native,format=raw -device 
virtio-blk,drive=hd,scsi=off,config-wce=off,x-data-plane=on `for i in $(seq 0 
15); do echo -n "-object memory-backend-ram,id=m$i,size=10M -device 
pc-dimm,id=dimm$i,memdev=m$i "; done`

it hangs at boot time or on executing 'dd if=/dev/vda of=/dev/null bs 32M'






[Qemu-devel] [RFC PATCH v3] tests/vhost-user-bridge: add vhost-user bridge application

2015-10-28 Thread Victor Kaplansky
The test existing in QEMU for vhost-user feature is good for
testing the management protocol, but does not allow actual
traffic. This patch proposes Vhost-User Bridge application, which
can serve the QEMU community as a comprehensive test by running
real internet traffic by means of vhost-user interface.

Essentially the Vhost-User Bridge is a very basic vhost-user
backend for QEMU. It runs as a standalone user-level process.
For packet processing Vhost-User Bridge uses an additional QEMU
instance with a backend configured by "-net socket" as a shared
VLAN.  This way another QEMU virtual machine can effectively
serve as a shared bus by means of UDP communication.

For a more simple setup, the another QEMU instance running the
SLiRP backend can be the same QEMU instance running vhost-user
client.

This Vhost-User Bridge implementation is very preliminary.  It is
missing many features. I has been studying vhost-user protocol
internals, so I've written vhost-user-bridge bit by bit as I
progressed through the protocol.  Most probably its internal
architecture will change significantly.

To run Vhost-User Bridge application:

1. Build vhost-user-bridge with a regular procedure. This will
create a vhost-user-bridge executable under tests directory:

$ configure; make tests/vhost-user-bridge

2. Ensure the machine has hugepages enabled in kernel with
command line like:

default_hugepagesz=2M hugepagesz=2M hugepages=2048

3. Run Vhost-User Bridge with:

$ tests/vhost-user-bridge

The above will run vhost-user server listening for connections
on UNIX domain socket /tmp/vubr.sock, and will try to connect
by UDP to VLAN bridge to localhost:, while listening on
localhost:

Run qemu with a virtio-net backed by vhost-user:

$ qemu \
-enable-kvm -m 512 -smp 2 \
-object 
memory-backend-file,id=mem,size=512M,mem-path=/dev/hugepages,share=on \
-numa node,memdev=mem -mem-prealloc \
-chardev socket,id=char0,path=/tmp/vubr.sock \
-netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce \
-device virtio-net-pci,netdev=mynet1 \
-net none \
-net socket,vlan=0,udp=localhost:,localaddr=localhost: \
-net user,vlan=0 \
disk.img

vhost-user-bridge was tested very lightly: it's able to bringup a
linux on client VM with the virtio-net driver, and execute transmits
and receives to the internet. I tested with "wget redhat.com",
"dig redhat.com".

PS. I've consulted DPDK's code for vhost-user during Vhost-User
Bridge implementation.

Signed-off-by: Victor Kaplansky 
---
v3:
- Change debug printings to use conditional macro.
- Declarations moved to beginning of blocks.
- Handle correctly when no available descriptors in RX queue.
- Changed prefixes of functions to _vubr.
- Changed prefix of types to VubrDev.
- Changed the code to use atomic_mb_read() and atomic_mb_set() 
  instead of explicit memory barriers smp_mb().
- Other minor spelling fixes.
v2:
Cosmetic changes:
- Tabs expanded, trailing spaces removed.
- Removed use of architecture specific definitions starting with _
- Used header files available in qemu/includes.
- Rearranged source into single file.
- checkpatch.pl pacified.
- Added copyright note.
- Small spelling corrections.
- Removed _ prefixes in function names.
- Makefile incorporated into tests/Makefile.
- Error handling code changed to use die().
- Prefix "vubr" replaced by "vhost_user".
- Structures, enums and function type names renamed to
  comply with CODING_STYLE doc.
- Preprocessor tricks thrown away.
- Lines are no longer than 80.

Functional changes:
- Added memory barriers.
- Implemented SET_OWNER. (by doing nothing).
---
 tests/vhost-user-bridge.c | 1110 +
 tests/Makefile|1 +
 2 files changed,  insertions(+)
 create mode 100644 tests/vhost-user-bridge.c

diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
new file mode 100644
index 000..fa18ad5
--- /dev/null
+++ b/tests/vhost-user-bridge.c
@@ -0,0 +1,1110 @@
+/*
+ * Vhost User Bridge
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * Authors:
+ *  Victor Kaplansky 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+/*
+ * TODO:
+ * - main should get parameters from the command line.
+ * - implement all request handlers.
+ * - test for broken requests and virtqueue.
+ * - implement features defined by Virtio 1.0 spec.
+ * - support mergeable buffers and indirect descriptors.
+ * - implement RESET_DEVICE request.
+ * - implement clean shutdown.
+ * - implement non-blocking writes to UDP backend.
+ * - implement polling strategy.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 

Re: [Qemu-devel] [PATCH 2/6] virtio: switch to virtio_map

2015-10-28 Thread Igor Mammedov
On Tue, 27 Oct 2015 10:47:58 +0200
"Michael S. Tsirkin"  wrote:

> Drop use of the deprecated virtio_map_sg in virtio core.
> 
> Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 

> ---
>  hw/virtio/virtio.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index a6878c0..84e2320 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -569,8 +569,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
>  } while ((i = virtqueue_next_desc(vdev, desc_pa, i, max)) != max);
>  
>  /* Now map what we have collected */
> -virtqueue_map_sg(elem->in_sg, elem->in_addr, elem->in_num, 1);
> -virtqueue_map_sg(elem->out_sg, elem->out_addr, elem->out_num, 0);
> +virtqueue_map(elem);
>  
>  elem->index = head;
>  




Re: [Qemu-devel] [PATCH 4/6] virtio-serial: convert to virtio_map

2015-10-28 Thread Igor Mammedov
On Tue, 27 Oct 2015 10:48:03 +0200
"Michael S. Tsirkin"  wrote:

> This also fixes a minor bug:
> -virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr,
> - port->elem.out_num, 1);
> is wrong: out_sg is not written so should not be marked dirty.
> 
> Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 

> ---
>  hw/char/virtio-serial-bus.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index be97058..497b0af 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -705,10 +705,7 @@ static int fetch_active_ports_list(QEMUFile *f, int 
> version_id,
>  
>  qemu_get_buffer(f, (unsigned char *)>elem,
>  sizeof(port->elem));
> -virtqueue_map_sg(port->elem.in_sg, port->elem.in_addr,
> - port->elem.in_num, 1);
> -virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr,
> - port->elem.out_num, 1);
> +virtqueue_map(>elem);
>  
>  /*
>   *  Port was throttled on source machine.  Let's




Re: [Qemu-devel] [PATCH V10 RESEND 0/3]Move sdhci.h to include/hw/sd

2015-10-28 Thread Stefan Hajnoczi
On Thu, Oct 08, 2015 at 06:51:00PM +0530, Sai Pavan Boddu wrote:
> Move sdhci.h splitting it into common and internal.
> Create a new directory for sd in include/hw/.
> Correct paths of sd.h in at every instance of #include.
> Add sdhci to xlnx-zynqmp SOC.
> 
> Sai Pavan Boddu (3):
>   sd.h: Move sd.h to include/hw/sd/
>   sdhci: Split sdhci.h for public and internal device usage
>   target-arm: xlnx-zynqmp: Add sdhci support.
> 
>  hw/arm/xlnx-zynqmp.c| 28 +++
>  hw/sd/milkymist-memcard.c   |  2 +-
>  hw/sd/omap_mmc.c|  2 +-
>  hw/sd/pl181.c   |  2 +-
>  hw/sd/pxa2xx_mmci.c |  2 +-
>  hw/sd/sd.c  |  2 +-
>  hw/sd/{sdhci.h => sdhci-internal.h} | 71 ++--
>  hw/sd/sdhci.c   |  3 +-
>  hw/sd/ssi-sd.c  |  2 +-
>  include/hw/arm/xlnx-zynqmp.h|  3 ++
>  include/hw/{ => sd}/sd.h|  0
>  include/hw/sd/sdhci.h   | 92 
> +
>  12 files changed, 134 insertions(+), 75 deletions(-)
>  rename hw/sd/{sdhci.h => sdhci-internal.h} (75%)
>  rename include/hw/{ => sd}/sd.h (100%)
>  create mode 100644 include/hw/sd/sdhci.h

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 0/1] Test the reopening of overlay_bs in 'block-commit'

2015-10-28 Thread Alberto Garcia
On Wed 28 Oct 2015 10:33:01 AM CET, Kevin Wolf  wrote:

> I've applied your test case to my working branch so I won't forget
> about this. Maybe I should really try to get the series into 2.5 then.

Note that 2.4 is also affected by this. I guess for that version we can
simply swap the order of the bdrv_reopen_queue() calls. I can prepare a
patch if you're ok with that solution.

Berto



Re: [Qemu-devel] [PATCH v8 30/54] Avoid sending vmdescription during postcopy

2015-10-28 Thread Amit Shah
On (Tue) 29 Sep 2015 [09:37:54], Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> VMDescription is normally sent at the end, after all
> of the devices; however that's not the end for postcopy,
> so just don't send it when in postcopy.
> 
> Signed-off-by: Dr. David Alan Gilbert 

Reviewed-by: Amit Shah 

Amit



Re: [Qemu-devel] [PATCH v2] target-arm: Extract some external ARM CPU API

2015-10-28 Thread Shlomo Pongratz


-Original Message-
From: Pavel Fedin [mailto:p.fe...@samsung.com] 
Sent: 2015年10月28日 19:13
To: 'Peter Crosthwaite'; 'Paolo Bonzini'
Cc: 'Peter Maydell'; 'Shlomo Pongratz'; 'QEMU Developers'; Shlomo Pongratz
Subject: RE: [Qemu-devel] [PATCH v2] target-arm: Extract some external ARM CPU 
API

 Hello!

>  Ok, so decided. I will convert my code, test the build and send a 
> small patch for this soon, perhaps today.

 arm_gicv3_kvm.o is already in obj-y, and arm_gicv3_common.o does not use any 
of those definitions. So, nothing to move, there will be no patch.

 So far, we have only this small leftover: 
http://lists.nongnu.org/archive/html/qemu-devel/2015-10/msg02349.html. Needed 
both by live migration and SW emulation of GICv3.

 Shlomo: Just add your GICv3 code to obj-$(CONFIG_ARM_GIC), and you'll be able 
to include things you need.

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia


Hi Pavel,

Thanks, I'm currently in business trip to China.
I'll resume working on it in approx two weeks.
Also please excuse me for using outlook (if the mail is unreadable).

Best regards,

S.P.



Re: [Qemu-devel] [Qemu-block] [PATCH] block: Consider all child nodes in bdrv_requests_pending()

2015-10-28 Thread Jeff Cody
On Wed, Oct 28, 2015 at 11:46:51AM +0100, Kevin Wolf wrote:
> The function manually recursed into bs->file and bs->backing to check
> whether there were any requests pending, but it ignored other children.
> 
> There's no need to special case file and backing here, so just replace
> these two explicit recursions by a loop recursing for all child nodes.
> 
> Reported-by: Max Reitz 
> Signed-off-by: Kevin Wolf 
> ---
>  block/io.c | 13 -
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/block/io.c b/block/io.c
> index 5ac6256..8dcad3b 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -216,6 +216,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs)
>  /* Check if any requests are in-flight (including throttled requests) */
>  bool bdrv_requests_pending(BlockDriverState *bs)
>  {
> +BdrvChild *child;
> +
>  if (!QLIST_EMPTY(>tracked_requests)) {
>  return true;
>  }
> @@ -225,12 +227,13 @@ bool bdrv_requests_pending(BlockDriverState *bs)
>  if (!qemu_co_queue_empty(>throttled_reqs[1])) {
>  return true;
>  }
> -if (bs->file && bdrv_requests_pending(bs->file->bs)) {
> -return true;
> -}
> -if (bs->backing && bdrv_requests_pending(bs->backing->bs)) {
> -return true;
> +
> +QLIST_FOREACH(child, >children, next) {
> +if (bdrv_requests_pending(child->bs)) {
> +return true;
> +}
>  }
> +
>  return false;
>  }
>  
> -- 
> 1.8.3.1
> 
> 

Reviewed-by: Jeff Cody 



Re: [Qemu-devel] [PATCH v8 34/54] postcopy: ram_enable_notify to switch on userfault

2015-10-28 Thread Amit Shah
On (Tue) 29 Sep 2015 [09:37:58], Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> Mark the area of RAM as 'userfault'
> Start up a fault-thread to handle any userfaults we might receive
> from it (to be filled in later)
> 
> Signed-off-by: Dr. David Alan Gilbert 
> Reviewed-by: David Gibson 
> Reviewed-by: Juan Quintela 

Reviewed-by: Amit Shah 

(I'd also reviewed v7)

Amit



Re: [Qemu-devel] [PATCH] fixup! virtio: introduce virtio_map

2015-10-28 Thread Stefan Hajnoczi
On Tue, Oct 27, 2015 at 11:00:36PM +0200, Michael S. Tsirkin wrote:
> Stefan noticed that we must use memmove, not memcpy,
> as arguments overlap.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  hw/virtio/virtio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH 2/2] qemu-iotests: Test the reopening of overlay_bs in 'block-commit'

2015-10-28 Thread Alberto Garcia
The 'block-commit' command needs the overlay image of 'top' to
be opened in read-write mode in order to update the backing file
string. If 'top' is not the active layer or its backing file then its
overlay needs to be reopened during the block job.

This is a test case for that scenario.

Signed-off-by: Alberto Garcia 
---
 tests/qemu-iotests/040 | 30 ++
 tests/qemu-iotests/040.out |  4 ++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040
index ea2f98e..5bdaf3d 100755
--- a/tests/qemu-iotests/040
+++ b/tests/qemu-iotests/040
@@ -41,6 +41,7 @@ class ImageCommitTestCase(iotests.QMPTestCase):
 while not completed:
 for event in self.vm.get_qmp_events(wait=True):
 if event['event'] == 'BLOCK_JOB_COMPLETED':
+self.assert_qmp_absent(event, 'data/error')
 self.assert_qmp(event, 'data/type', 'commit')
 self.assert_qmp(event, 'data/device', 'drive0')
 self.assert_qmp(event, 'data/offset', event['data']['len'])
@@ -251,5 +252,34 @@ class TestSetSpeed(ImageCommitTestCase):
 class TestActiveZeroLengthImage(TestSingleDrive):
 image_len = 0
 
+class TestReopenOverlay(ImageCommitTestCase):
+image_len = 1024 * 1024
+img0 = os.path.join(iotests.test_dir, '0.img')
+img1 = os.path.join(iotests.test_dir, '1.img')
+img2 = os.path.join(iotests.test_dir, '2.img')
+img3 = os.path.join(iotests.test_dir, '3.img')
+
+def setUp(self):
+iotests.create_image(self.img0, self.image_len)
+qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
self.img0, self.img1)
+qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
self.img1, self.img2)
+qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
self.img2, self.img3)
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xab 0 128K', self.img1)
+self.vm = iotests.VM().add_drive(self.img3)
+self.vm.launch()
+
+def tearDown(self):
+self.vm.shutdown()
+os.remove(self.img0)
+os.remove(self.img1)
+os.remove(self.img2)
+os.remove(self.img3)
+
+# This tests what happens when the overlay image of the 'top' node
+# needs to be reopened in read-write mode in order to update the
+# backing image string.
+def test_reopen_overlay(self):
+self.run_commit_test(self.img1, self.img0)
+
 if __name__ == '__main__':
 iotests.main(supported_fmts=['qcow2', 'qed'])
diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out
index 42314e9..4fd1c2d 100644
--- a/tests/qemu-iotests/040.out
+++ b/tests/qemu-iotests/040.out
@@ -1,5 +1,5 @@
-
+.
 --
-Ran 24 tests
+Ran 25 tests
 
 OK
-- 
2.6.1




Re: [Qemu-devel] [PATCH v2] target-arm: Extract some external ARM CPU API

2015-10-28 Thread Pavel Fedin
 Hello!

>  Ok, so decided. I will convert my code, test the build and send a small 
> patch for this soon,
> perhaps today.

 arm_gicv3_kvm.o is already in obj-y, and arm_gicv3_common.o does not use any 
of those definitions. So, nothing to move, there will be no patch.

 So far, we have only this small leftover: 
http://lists.nongnu.org/archive/html/qemu-devel/2015-10/msg02349.html. Needed 
both by live migration and SW emulation of GICv3.

 Shlomo: Just add your GICv3 code to obj-$(CONFIG_ARM_GIC), and you'll be able 
to include things you need.

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia






Re: [Qemu-devel] [PATCH 3/4] ide: add support for cancelable read requests

2015-10-28 Thread Stefan Hajnoczi
On Tue, Oct 27, 2015 at 11:58:55AM +0100, Peter Lieven wrote:
> Am 26.10.2015 um 11:39 schrieb Stefan Hajnoczi:
> >On Mon, Oct 12, 2015 at 02:27:24PM +0200, Peter Lieven wrote:
> >>+BlockAIOCB *ide_readv_cancelable(IDEState *s, int64_t sector_num,
> >>+ QEMUIOVector *iov, int nb_sectors,
> >>+ BlockCompletionFunc *cb, void *opaque)
> >>+{
> >>+BlockAIOCB *aioreq;
> >>+IDECancelableRequest *req;
> >>+int c = 0;
> >>+
> >>+QLIST_FOREACH(req, >cancelable_requests, list) {
> >>+c++;
> >>+}
> >>+if (c > MAX_CANCELABLE_REQS) {
> >>+return NULL;
> >>+}
> >A BH is probably needed here to schedule an cb(-EIO) call since this
> >function isn't supposed to return NULL if it's a direct replacement for
> >blk_aio_readv().
> 
> You mean sth like:
> 
> acb = qemu_aio_get(_em_aiocb_info, bs, cb, opaque);
> acb->bh = aio_bh_new(bdrv_get_aio_context(bs), bdrv_aio_bh_cb, acb);
> acb->ret = -EIO;
> qemu_bh_schedule(acb->bh);
> 
> return >common;

Yes.

> As pointed out in my comment to your requestion about write/discard I think 
> it should
> be feasible to use buffered readv requests for all read-only IDE devices.
> Only thing I'm unsure about is reopening. A reopen seems to only flush the 
> device not
> drain all requests.

bdrv_reopen_prepare() callers should drain requests.  For example,
bdrv_reopen_multiple() (and indirectly bdrv_reopen()) call
bdrv_drain_all().  Is this what you mean?


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 1/6] virtio: introduce virtio_map

2015-10-28 Thread Stefan Hajnoczi
On Tue, Oct 27, 2015 at 08:34:32PM +0200, Michael S. Tsirkin wrote:
> On Tue, Oct 27, 2015 at 04:19:54PM +, Stefan Hajnoczi wrote:
> > On Tue, Oct 27, 2015 at 10:47:56AM +0200, Michael S. Tsirkin wrote:
> > > This will still fail if there's no space left in the sg, but luckily max
> > > queue size in use is currently 256, while max sg size is 1024, so we
> > > should be OK even is all entries happen to cross a single DIMM boundary.
> > 
> > Don't forget about indirect descriptors.  They can use all 1024 iovecs,
> > regardless of virtqueue size, so virtqueue size of 256 isn't the true
> > maximum.
> 
> Not according to the spec - virtio spec says vq size is the maximum size
> of a chain.
> 
> > I'm worried that we could now see failures due to non-contiguous HVAs.
> 
> Does linux guest create chains > vq size then? Does it actually
> have 1024 hardcoded somewhere?

You are correct, drivers/virtio/virtio_ring.c:virtqueue_add() says:

  BUG_ON(total_sg > vq->vring.num);

This also makes sense since it means there is a well-known maximum size
for indirect descriptor tables.

So this fix should work fine with indirect descriptors.

Stefan


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH] migration: Introduce migration_in_completion()

2015-10-28 Thread Pavel Fedin
 Hello!

> Power people have a similar problem with its hashed page tables, they
> integrated their own save_live implementation because they are too big
> for the last stage.  You can look there for inspiration.

 I examined their code. Interesting, and, indeed, it opens up a way for 
decreasing downtime by implementing iterative migration for
the ITS.
 However, this is not really what is necessary. This thing aims to produce own 
data chunk, and it's not good for ITS. ITS already
stores everything in system RAM, therefore savevm_ram_handlers take perfect 
care about these data. The only thing to do is to tell
the ITS to dump its state into RAM. This is what i currently do using 
migration_in_completion().
 An alternate, perhaps better approach, would be to be able to hook into 
ram_save_iterate() and ram_save_complete(). This way we
could kick ITS right before attempting to migrate RAM.
 Could we extend the infrastructure so that:
a) Handlers are prioritized, and we can determine order of their execution?
b) We can choose whether our handlers actually produce extra chunk or not?

 OTOH, what i've done is actually a way to hook up into save_live_complete 
before any other registered handlers get executed. What
is missing is one more notifier_list_notify() call right before 
qemu_savevm_state_iterate(), and a corresponding
migration_is_active() checker.

 What do you think ?

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia





Re: [Qemu-devel] [PATCH for-2.5 v1 3/4] arm: highbank: Implement PSCI and dummy monitor

2015-10-28 Thread Peter Maydell
On 27 October 2015 at 20:29, Rob Herring  wrote:
> Thanks for doing this. I'm not a big fan of how the machine code for
> boot code is embedded into C in qemu, but that's a separate issue.

FWIW, I'm becoming increasingly unhappy with the approach too...
it was straightforward when it was four asm instructions that
worked for any board, but it's been gradually accreting extra
complexity as we've gone along.

thanks
-- PMM



Re: [Qemu-devel] [PATCH 1/6] virtio: introduce virtio_map

2015-10-28 Thread Igor Mammedov
On Tue, 27 Oct 2015 10:47:56 +0200
"Michael S. Tsirkin"  wrote:

> virtio_map_sg currently fails if one of the entries it's mapping is
> contigious in GPA but not HVA address space.  Introduce virtio_map which
> handles this by splitting sg entries.
> 
> This new API generally turns out to be a good idea since it's harder to
> misuse: at least in one case the existing one was used incorrectly.
> 
> This will still fail if there's no space left in the sg, but luckily max
> queue size in use is currently 256, while max sg size is 1024, so we
> should be OK even is all entries happen to cross a single DIMM boundary.
> 
> Won't work well with very small DIMM sizes, unfortunately:
> e.g. this will fail with 4K DIMMs where a single
> request might span a large number of DIMMs.
> 
> Let's hope these are uncommon - at least we are not breaking things.
> 
> Note: virtio-scsi calls virtio_map_sg on data loaded from network, and
> validates input, asserting on failure.  Copy the validating code here -
> it will be dropped from virtio-scsi in a follow-up patch.
> 
> Reported-by: Igor Mammedov 
> Signed-off-by: Michael S. Tsirkin 

With fixup you've posted and build fix in this thread:
Reviewed-by: Igor Mammedov 

> ---
>  include/hw/virtio/virtio.h |  1 +
>  hw/virtio/virtio.c | 56 
> ++
>  2 files changed, 48 insertions(+), 9 deletions(-)
> 
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 9d09115..9d9abb4 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -153,6 +153,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement 
> *elem,
>  
>  void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
>  size_t num_sg, int is_write);
> +void virtqueue_map(VirtQueueElement *elem);
>  int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
>  int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
>unsigned int out_bytes);
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index d0bc72e..a6878c0 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -448,28 +448,66 @@ int virtqueue_avail_bytes(VirtQueue *vq, unsigned int 
> in_bytes,
>  return in_bytes <= in_total && out_bytes <= out_total;
>  }
>  
> -void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
> -size_t num_sg, int is_write)
> +static void virtqueue_map_iovec(struct iovec *sg, hwaddr *addr,
> +size_t *num_sg, size_t max_size,
> +int is_write)
>  {
>  unsigned int i;
>  hwaddr len;
>  
> -if (num_sg > VIRTQUEUE_MAX_SIZE) {
> -error_report("virtio: map attempt out of bounds: %zd > %d",
> - num_sg, VIRTQUEUE_MAX_SIZE);
> -exit(1);
> -}
> +/* Note: this function MUST validate input, some callers
> + * are passing in num_sg values received over the network.
> + */
> +/* TODO: teach all callers that this can fail, and return failure instead
> + * of asserting here.
> + * When we do, we might be able to re-enable NDEBUG below.
> + */
> +#ifdef NDEBUG
> +#error building with NDEBUG is not supported
> +#endif
> +assert(*num_sg <= max_size);
>  
> -for (i = 0; i < num_sg; i++) {
> +for (i = 0; i < *num_sg; i++) {
>  len = sg[i].iov_len;
>  sg[i].iov_base = cpu_physical_memory_map(addr[i], , is_write);
> -if (sg[i].iov_base == NULL || len != sg[i].iov_len) {
> +if (!sg[i].iov_base) {
>  error_report("virtio: error trying to map MMIO memory");
>  exit(1);
>  }
> +if (len == sg[i].iov_len) {
> +continue;
> +}
> +if (*num_sg >= max_size) {
> +error_report("virtio: memory split makes iovec too large");
> +exit(1);
> +}
> +memcpy(sg + i + 1, sg + i, sizeof(*sg) * (*num_sg - i));
> +memcpy(addr + i + 1, addr + i, sizeof(*addr) * (*num_sg - i));
> +assert(len < sg[i + 1].iov_len);
> +sg[i].iov_len = len;
> +addr[i + 1] += len;
> +sg[i + 1].iov_len -= len;
> +++*num_sg;
>  }
>  }
>  
> +/* Deprecated: don't use in new code */
> +void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
> +  size_t num_sg, int is_write)
> +{
> +virtqueue_map_iovec(sg, addr, _sg, num_sg, is_write);
> +}
> +
> +void virtqueue_map(VirtQueueElement *elem)
> +{
> +virtqueue_map_iovec(elem->in_sg, elem->in_addr, >in_num,
> +MIN(ARRAY_SIZE(elem->in_sg), 
> ARRAY_SIZE(elem->in_addr)),
> +1);
> +virtqueue_map_iovec(elem->out_sg, elem->out_addr, >out_num,
> +MIN(ARRAY_SIZE(elem->out_sg), 
> ARRAY_SIZE(elem->out_addr)),
> +0);
> +}
> +
>  int virtqueue_pop(VirtQueue *vq, VirtQueueElement 

Re: [Qemu-devel] [PATCH v8 41/54] postcopy_ram.c: place_page and helpers

2015-10-28 Thread Dr. David Alan Gilbert
* Juan Quintela (quint...@redhat.com) wrote:
> "Dr. David Alan Gilbert (git)"  wrote:
> > From: "Dr. David Alan Gilbert" 
> >
> > postcopy_place_page (etc) provide a way for postcopy to place a page
> > into guests memory atomically (using the copy ioctl on the ufd).
> >
> > Signed-off-by: Dr. David Alan Gilbert 
> > Reviewed-by: Amit Shah 
> 
> 
> Reviewed-by: Juan Quintela 
> 
> > +int postcopy_place_page_zero(MigrationIncomingState *mis, void *host)
> > +{
> > +struct uffdio_zeropage zero_struct;
> > +
> > +zero_struct.range.start = (uint64_t)(uintptr_t)host;
> > +zero_struct.range.len = getpagesize();
> > +zero_struct.mode = 0;
> > +
> > +if (ioctl(mis->userfault_fd, UFFDIO_ZEROPAGE, _struct)) {
> > +int e = errno;
> > +error_report("%s: %s zero host: %p",
> > + __func__, strerror(e), host);
> > +
> > +return -e;
> > +}
> > +
> > +trace_postcopy_place_page_zero(host);
> > +return 0;
> > +}
> 
> Would this be faster than normal precopy way of just copying a zero page?

For postcopy we have to do an ioctl anyway (to release any paused tasks
waiting on the page), and we can't just write to the page because it's not
mapped yet.  We could do a UFFDIO_COPY of a zero page but that would
take a copy; here the kernel maps the zero page and releases the paused task
without needing a zero page to copy from.

Dave

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



[Qemu-devel] [PATCH 0/2] Fix the reopening of images in 'block-commit'

2015-10-28 Thread Alberto Garcia
This series fixes a bug in the 'block-commit' operation under the
following scenario:

   [A] <- [B] <- [C] <- [D]

If we do block-commit top=B base=A, the contents of [B] will be
written into [A] resulting in this chain:

   [A] <- [C] <- [D]

In order to perform this operation, [A] must be reopened in read-write
mode but so does [C] because its backing file string needs to be
updated to point at [A].

There's a bug in the current code that makes [A] read-only again when
[C] is reopened. This series includes a fix for that bug plus a test
case for the scenario.

This affects both master and the 2.4 branch.

Berto

Alberto Garcia (2):
  commit: reopen overlay_bs before base
  qemu-iotests: Test the reopening of overlay_bs in 'block-commit'

 block/commit.c |  8 
 tests/qemu-iotests/040 | 30 ++
 tests/qemu-iotests/040.out |  4 ++--
 3 files changed, 36 insertions(+), 6 deletions(-)

-- 
2.6.1




[Qemu-devel] [PATCH 1/2] commit: reopen overlay_bs before base

2015-10-28 Thread Alberto Garcia
'block-commit' needs write access to two different nodes of the chain:

- 'base', because that's where the data is written to.
- the overlay of 'top', because it needs to update the backing file
  string to point to 'base' after the operation.

Both images have to be opened in read-write mode, and commit_start()
takes care of reopening them if necessary.

With the current implementation, however, when overlay_bs is reopened
in read-write mode it has the side effect of making 'base' read-only
again, eventually making 'block-commit' fail.

This needs to be fixed in bdrv_reopen(), but until we get to that it
can be worked around simply by swapping the order of base and
overlay_bs in the reopen queue.

In order to reproduce this bug, overlay_bs needs to be initially in
read-only mode. That is: the 'top' parameter of 'block-commit' cannot
be the active layer nor its immediate backing chain.

Signed-off-by: Alberto Garcia 
---
 block/commit.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/commit.c b/block/commit.c
index 7312a5b..85a2604 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -235,14 +235,14 @@ void commit_start(BlockDriverState *bs, BlockDriverState 
*base,
 orig_overlay_flags = bdrv_get_flags(overlay_bs);
 
 /* convert base & overlay_bs to r/w, if necessary */
-if (!(orig_base_flags & BDRV_O_RDWR)) {
-reopen_queue = bdrv_reopen_queue(reopen_queue, base,
- orig_base_flags | BDRV_O_RDWR);
-}
 if (!(orig_overlay_flags & BDRV_O_RDWR)) {
 reopen_queue = bdrv_reopen_queue(reopen_queue, overlay_bs,
  orig_overlay_flags | BDRV_O_RDWR);
 }
+if (!(orig_base_flags & BDRV_O_RDWR)) {
+reopen_queue = bdrv_reopen_queue(reopen_queue, base,
+ orig_base_flags | BDRV_O_RDWR);
+}
 if (reopen_queue) {
 bdrv_reopen_multiple(reopen_queue, _err);
 if (local_err != NULL) {
-- 
2.6.1




[Qemu-devel] qemu-2.2 using trace event

2015-10-28 Thread ??????
Hi,here is my problem
1 ./configure --enable-trace-backends=simple
make
make install
echo virtio_notity > /tmp/events
echo virtio_queue_notify >> /tmp/events
2  I use a xml file run a virtual machine
3  qemu-system_x86_64 -trace events=/tmp/events 
4   ./scripts/simpletrace.py trace-events trace-*


But do not get trace.log. and when i check trace-* using 'vim' i find the file 
is almost empty.
I tried many times, including reinstall qemu,but still don't work.
when i use qemu -trace -m 2048 ... commandline create virtual machine 
,the vm become very slow and still no trace.log.
I am a green hand, help!

Re: [Qemu-devel] [PATCH v8 46/54] postcopy: Check order of received target pages

2015-10-28 Thread Juan Quintela
"Dr. David Alan Gilbert (git)"  wrote:
> From: "Dr. David Alan Gilbert" 
>
> Ensure that target pages received within a host page are in order.
> This shouldn't trigger, but in the cases where the sender goes
> wrong and sends stuff out of order it produces a corruption that's
> really nasty to debug.
>
> Signed-off-by: Dr. David Alan Gilbert 

Reviewed-by: Juan Quintela 




Re: [Qemu-devel] [PATCH V2 0/4] ide: avoid main-loop hang on CDROM/NFS failure

2015-10-28 Thread Stefan Hajnoczi
On Mon, Oct 26, 2015 at 11:56:26AM +0100, Peter Lieven wrote:
> Am 26.10.2015 um 11:42 schrieb Stefan Hajnoczi:
> >On Mon, Oct 12, 2015 at 02:27:21PM +0200, Peter Lieven wrote:
> >>This series aims at avoiding a hanging main-loop if a vserver has a
> >>CDROM image mounted from a NFS share and that NFS share goes down.
> >>Typical situation is that users mount an CDROM ISO to install something
> >>and then forget to eject that CDROM afterwards.
> >>As a consequence this mounted CD is able to bring down the
> >>whole vserver if the backend NFS share is unreachable. This is bad
> >>especially if the CDROM itself is not needed anymore at this point.
> >>
> >>This series aims at fixing 2 blocking I/O operations that would
> >>hang if the NFS server is unavailable:
> >>  - ATAPI PIO read requests used sync calls to blk_read, convert
> >>them to an async variant where possible.
> >>  - If a busmaster DMA request is cancelled all requests are drained.
> >>Convert the drain to an async request canceling.
> >>
> >>v1->v2: - fix offset for 2352 byte sector size [Kevin]
> >> - use a sync request if we continue an elementary transfer.
> >>   As John pointed out we enter a race condition between next
> >>   IDE command and async transfer otherwise. This is sill not
> >>   optimal, but it fixes the NFS down problems for all cases where
> >>   the NFS server goes down while there is no PIO CD activity.
> >>   Of course, it could still happen during a PIO transfer, but I
> >>   expect this to be the unlikelier case.
> >>   I spent some effort trying to read more sectors at once and
> >>   avoiding continuation of elementary transfers, but with
> >>   whatever I came up it was destroying migration between different
> >>   Qemu versions. I have a quite hackish patch that works and
> >>   should survive migration, but I am not happy with it. So I
> >>   would like to start with this version as it is a big improvement
> >>   already.
> >> - Dropped Patch 5 because it is upstream meanwhile.
> >>
> >>Peter Lieven (4):
> >>   ide/atapi: make PIO read requests async
> >>   ide/atapi: blk_aio_readv may return NULL
> >>   ide: add support for cancelable read requests
> >>   ide/atapi: enable cancelable requests
> >>
> >>  hw/ide/atapi.c| 99 
> >> +--
> >>  hw/ide/core.c | 55 +++
> >>  hw/ide/internal.h | 16 +
> >>  hw/ide/pci.c  | 42 +++
> >>  4 files changed, 188 insertions(+), 24 deletions(-)
> >Any reason why write and discard requests aren't covered in this series?
> >
> >If this is a good idea for CD-ROM it should be a good idea for all PCI
> >IDE devices.
> >
> >Having a specialized code path is often a sign that it hasn't been
> >tested enough.  Can we get confident enough to enable this everywhere?
> 
> The reason is that the buffered request trick does only work for
> read-only devices (like a CDROM). A write request that is completed
> on the backend storage at a later point (after the OS thinks the request
> is canceled) can cause damage to the filesystem.

Of course, you are right.

This is really annoying because it means a guest cannot reboot if writes
are pending...

Stefan


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH] hw/usb/dev-audio.c: make USB audio card sound perfect

2015-10-28 Thread Gerd Hoffmann
  Hi,

> Is the problem the host sound API, QEMU's audio/mixing infrastructure,
> or guest responsiveness?

Didn't check in deep this time, but usually none of the above.

Latency problems *anywhere* in qemu can cause this, because the latency
spikes cause the guest not being scheduled for too long so it can't fill
the sound buffers in time.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 0/1] Test the reopening of overlay_bs in 'block-commit'

2015-10-28 Thread Kevin Wolf
Am 28.10.2015 um 12:20 hat Alberto Garcia geschrieben:
> On Wed 28 Oct 2015 10:33:01 AM CET, Kevin Wolf  wrote:
> 
> > I've applied your test case to my working branch so I won't forget
> > about this. Maybe I should really try to get the series into 2.5 then.
> 
> Note that 2.4 is also affected by this. I guess for that version we can
> simply swap the order of the bdrv_reopen_queue() calls. I can prepare a
> patch if you're ok with that solution.

Okay. Then I'd suggest that you send a series with the swap and the test
case, CC qemu-stable, and we'll just apply that for now. And I'll keep a
note to look into the bdrv_reopen() part.

Kevin



Re: [Qemu-devel] [Qemu-block] [PATCH] block: Consider all child nodes in bdrv_requests_pending()

2015-10-28 Thread Alberto Garcia
On Wed 28 Oct 2015 11:46:51 AM CET, Kevin Wolf wrote:
> The function manually recursed into bs->file and bs->backing to check
> whether there were any requests pending, but it ignored other children.
>
> There's no need to special case file and backing here, so just replace
> these two explicit recursions by a loop recursing for all child nodes.
>
> Reported-by: Max Reitz 
> Signed-off-by: Kevin Wolf 
Reviewed-by: Alberto Garcia 

Berto



Re: [Qemu-devel] [PATCH v8 28/54] migrate_start_postcopy: Command to trigger transition to postcopy

2015-10-28 Thread Amit Shah
On (Tue) 29 Sep 2015 [09:37:52], Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> Once postcopy is enabled (with migrate_set_capability), the migration
> will still start on precopy mode.  To cause a transition into postcopy
> the:
> 
>   migrate_start_postcopy
> 
> command must be issued.  Postcopy will start sometime after this
> (when it's next checked in the migration loop).
> 
> Issuing the command before migration has started will error,
> and issuing after it has finished is ignored.
> 
> Signed-off-by: Dr. David Alan Gilbert 
> Reviewed-by: Eric Blake 

Reviewed-by: Amit Shah 

Amit



Re: [Qemu-devel] [PATCH v8 47/54] Round up RAMBlock sizes to host page sizes

2015-10-28 Thread Juan Quintela
"Dr. David Alan Gilbert (git)"  wrote:
> From: "Dr. David Alan Gilbert" 
>
> RAMBlocks that are not a multiple of host pages in length
> cause problems for postcopy (I've seen an ACPI table on aarch64
> be 5k in length - i.e. 5x target-page), so round RAMBlock sizes
> up to a host-page.
>
> This potentially breaks migration compatibility due to changes
> in RAMBlock sizes; however:
>1) x86 and s390 I think always have host=target page size
>2) When I've tried on Power the block sizes already seem aligned.
>3) I don't think there's anything else that maintains per-version
>   machine-types for compatibility.
>
> Signed-off-by: Dr. David Alan Gilbert 

Reviewed-by: Juan Quintela 

We had this problem on the past when we moved the machines to be
Megabyte rounded size, some machines where not.  But in this particular
case, I will clame that having a size that is _not_ of the size of the
host pages is just asking for trouble.



Re: [Qemu-devel] [PATCH 6/6] virtio: drop virtqueue_map_sg

2015-10-28 Thread Igor Mammedov
On Tue, 27 Oct 2015 10:48:08 +0200
"Michael S. Tsirkin"  wrote:

> Deprecated in favor of virtqueue_map.
> 
> Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 

> ---
>  include/hw/virtio/virtio.h | 2 --
>  hw/virtio/virtio.c | 7 ---
>  2 files changed, 9 deletions(-)
> 
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 9d9abb4..205fadf 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -151,8 +151,6 @@ void virtqueue_discard(VirtQueue *vq, const 
> VirtQueueElement *elem,
>  void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
>  unsigned int len, unsigned int idx);
>  
> -void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
> -size_t num_sg, int is_write);
>  void virtqueue_map(VirtQueueElement *elem);
>  int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
>  int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 84e2320..be32145 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -491,13 +491,6 @@ static void virtqueue_map_iovec(struct iovec *sg, hwaddr 
> *addr,
>  }
>  }
>  
> -/* Deprecated: don't use in new code */
> -void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
> -  size_t num_sg, int is_write)
> -{
> -virtqueue_map_iovec(sg, addr, _sg, num_sg, is_write);
> -}
> -
>  void virtqueue_map(VirtQueueElement *elem)
>  {
>  virtqueue_map_iovec(elem->in_sg, elem->in_addr, >in_num,




[Qemu-devel] [PULL 2/2] target-i386: Enable "check" mode by default

2015-10-28 Thread Eduardo Habkost
Current default behavior of QEMU is to silently disable features that
are not supported by the host when a CPU model is requested in the
command-line. This means that in addition to risking breaking guest ABI
by default, we are silent about it.

I would like to enable "enforce" by default, but this can easily break
existing production systems because of the way libvirt makes assumptions
about CPU models today (this will change in the future, once QEMU
provide a proper interface for checking if a CPU model is runnable).

But there's no reason we should be silent about it. So, change
target-i386 to enable "check" mode by default so at least we have some
warning printed to stderr (and hopefully logged somewhere) when QEMU
disables a feature that is not supported by the host system.

Reviewed-by: Igor Mammedov 
Signed-off-by: Eduardo Habkost 
---
 target-i386/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index c1a9e09..9280bfc 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3141,7 +3141,7 @@ static Property x86_cpu_properties[] = {
 DEFINE_PROP_BOOL("hv-reset", X86CPU, hyperv_reset, false),
 DEFINE_PROP_BOOL("hv-vpindex", X86CPU, hyperv_vpindex, false),
 DEFINE_PROP_BOOL("hv-runtime", X86CPU, hyperv_runtime, false),
-DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, false),
+DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true),
 DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
 DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
 DEFINE_PROP_UINT32("level", X86CPU, env.cpuid_level, 0),
-- 
2.1.0




[Qemu-devel] [PULL 1/2] target-i386: Don't left shift negative constant

2015-10-28 Thread Eduardo Habkost
Left shift of negative values is undefined behavior. Detected by clang:
  qemu/target-i386/translate.c:2423:26: runtime error:
left shift of negative value -8

This changes the code to reverse the sign after the left shift.

Signed-off-by: Eduardo Habkost 
---
 target-i386/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index 764b1e4..862f8e0 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -2432,7 +2432,7 @@ static void gen_pusha(DisasContext *s)
 {
 int i;
 gen_op_movl_A0_reg(R_ESP);
-gen_op_addl_A0_im(-8 << s->dflag);
+gen_op_addl_A0_im(-(8 << s->dflag));
 if (!s->ss32)
 tcg_gen_ext16u_tl(cpu_A0, cpu_A0);
 tcg_gen_mov_tl(cpu_T[1], cpu_A0);
-- 
2.1.0




[Qemu-devel] [PATCH v5 21/33] nvdimm: implement NVDIMM device abstract

2015-10-28 Thread Xiao Guangrong
Introduce "nvdimm" device which is based on dimm device type

128K memory region which is the minimum namespace label size
required by NVDIMM Namespace Spec locates at the end of
backend memory device is reserved for label data

We can use "-m 1G,maxmem=100G,slots=10 -object memory-backend-file,
id=mem1,size=1G,mem-path=/dev/pmem0 -device nvdimm,memdev=mem1" to
create NVDIMM device for guest

Signed-off-by: Xiao Guangrong 
---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 hw/acpi/memory_hotplug.c   |   6 ++
 hw/mem/Makefile.objs   |   1 +
 hw/mem/nvdimm.c| 113 +
 include/hw/mem/nvdimm.h|  83 +++
 6 files changed, 205 insertions(+)
 create mode 100644 hw/mem/nvdimm.c
 create mode 100644 include/hw/mem/nvdimm.h

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 3ece8bb..4e84a1c 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -47,6 +47,7 @@ CONFIG_APIC=y
 CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_NVDIMM=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
diff --git a/default-configs/x86_64-softmmu.mak 
b/default-configs/x86_64-softmmu.mak
index 92ea7c1..e877a86 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -47,6 +47,7 @@ CONFIG_APIC=y
 CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_NVDIMM=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index e232641..92cd973 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -1,6 +1,7 @@
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/pc-hotplug.h"
 #include "hw/mem/dimm.h"
+#include "hw/mem/nvdimm.h"
 #include "hw/boards.h"
 #include "hw/qdev-core.h"
 #include "trace.h"
@@ -231,6 +232,11 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 {
 MemStatus *mdev;
 
+/* Currently, NVDIMM hotplug has not been supported yet. */
+if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
+return;
+}
+
 mdev = acpi_memory_slot_status(mem_st, dev, errp);
 if (!mdev) {
 return;
diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs
index cebb4b1..12d9b72 100644
--- a/hw/mem/Makefile.objs
+++ b/hw/mem/Makefile.objs
@@ -1,2 +1,3 @@
 common-obj-$(CONFIG_DIMM) += dimm.o
 common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o
+common-obj-$(CONFIG_NVDIMM) += nvdimm.o
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
new file mode 100644
index 000..825d664
--- /dev/null
+++ b/hw/mem/nvdimm.c
@@ -0,0 +1,113 @@
+/*
+ * Non-Volatile Dual In-line Memory Module Virtualization Implementation
+ *
+ * Copyright(C) 2015 Intel Corporation.
+ *
+ * Author:
+ *  Xiao Guangrong 
+ *
+ * Currently, it only supports PMEM Virtualization.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see 
+ */
+
+#include "qapi/visitor.h"
+#include "hw/mem/nvdimm.h"
+
+static MemoryRegion *nvdimm_get_memory_region(DIMMDevice *dimm)
+{
+NVDIMMDevice *nvdimm = NVDIMM(dimm);
+
+return memory_region_size(>nvdimm_mr) ? >nvdimm_mr : NULL;
+}
+
+static void nvdimm_realize(DIMMDevice *dimm, Error **errp)
+{
+MemoryRegion *mr;
+NVDIMMDevice *nvdimm = NVDIMM(dimm);
+uint64_t size;
+
+nvdimm->label_size = MIN_NAMESPACE_LABEL_SIZE;
+
+mr = host_memory_backend_get_memory(dimm->hostmem, errp);
+size = memory_region_size(mr);
+
+if (size <= nvdimm->label_size) {
+char *path = 
object_get_canonical_path_component(OBJECT(dimm->hostmem));
+error_setg(errp, "the size of memdev %s (0x%" PRIx64 ") is too small"
+   " to contain nvdimm namespace label (0x%" PRIx64 ")", path,
+   memory_region_size(mr), nvdimm->label_size);
+return;
+}
+
+memory_region_init_alias(>nvdimm_mr, OBJECT(dimm), "nvdimm-memory",
+ mr, 0, size - nvdimm->label_size);
+nvdimm->label_data = memory_region_get_ram_ptr(mr) +
+ memory_region_size(>nvdimm_mr);
+}
+
+static void nvdimm_read_label_data(NVDIMMDevice *nvdimm, void *buf,
+   

[Qemu-devel] [PATCH v5 09/33] exec: allow file_ram_alloc to work on file

2015-10-28 Thread Xiao Guangrong
Currently, file_ram_alloc() only works on directory - it creates a file
under @path and do mmap on it

This patch tries to allow it to work on file directly, if @path is a
directory it works as before, otherwise it treats @path as the target
file then directly allocate memory from it

Signed-off-by: Xiao Guangrong 
---
 exec.c | 80 ++
 1 file changed, 51 insertions(+), 29 deletions(-)

diff --git a/exec.c b/exec.c
index d2a3357..09e9938 100644
--- a/exec.c
+++ b/exec.c
@@ -1157,14 +1157,60 @@ void qemu_mutex_unlock_ramlist(void)
 }
 
 #ifdef __linux__
+static bool path_is_dir(const char *path)
+{
+struct stat fs;
+
+return stat(path, ) == 0 && S_ISDIR(fs.st_mode);
+}
+
+static int open_file_path(RAMBlock *block, const char *path, size_t size)
+{
+char *filename;
+char *sanitized_name;
+char *c;
+int fd;
+
+if (!path_is_dir(path)) {
+int flags = (block->flags & RAM_SHARED) ? O_RDWR : O_RDONLY;
+
+flags |= O_EXCL;
+return open(path, flags);
+}
+
+/* Make name safe to use with mkstemp by replacing '/' with '_'. */
+sanitized_name = g_strdup(memory_region_name(block->mr));
+for (c = sanitized_name; *c != '\0'; c++) {
+if (*c == '/') {
+*c = '_';
+}
+}
+filename = g_strdup_printf("%s/qemu_back_mem.%s.XX", path,
+   sanitized_name);
+g_free(sanitized_name);
+fd = mkstemp(filename);
+if (fd >= 0) {
+unlink(filename);
+/*
+ * ftruncate is not supported by hugetlbfs in older
+ * hosts, so don't bother bailing out on errors.
+ * If anything goes wrong with it under other filesystems,
+ * mmap will fail.
+ */
+if (ftruncate(fd, size)) {
+perror("ftruncate");
+}
+}
+g_free(filename);
+
+return fd;
+}
+
 static void *file_ram_alloc(RAMBlock *block,
 ram_addr_t memory,
 const char *path,
 Error **errp)
 {
-char *filename;
-char *sanitized_name;
-char *c;
 void *area;
 int fd;
 uint64_t pagesize;
@@ -1194,38 +1240,14 @@ static void *file_ram_alloc(RAMBlock *block,
 goto error;
 }
 
-/* Make name safe to use with mkstemp by replacing '/' with '_'. */
-sanitized_name = g_strdup(memory_region_name(block->mr));
-for (c = sanitized_name; *c != '\0'; c++) {
-if (*c == '/')
-*c = '_';
-}
-
-filename = g_strdup_printf("%s/qemu_back_mem.%s.XX", path,
-   sanitized_name);
-g_free(sanitized_name);
+memory = ROUND_UP(memory, pagesize);
 
-fd = mkstemp(filename);
+fd = open_file_path(block, path, memory);
 if (fd < 0) {
 error_setg_errno(errp, errno,
  "unable to create backing store for path %s", path);
-g_free(filename);
 goto error;
 }
-unlink(filename);
-g_free(filename);
-
-memory = ROUND_UP(memory, pagesize);
-
-/*
- * ftruncate is not supported by hugetlbfs in older
- * hosts, so don't bother bailing out on errors.
- * If anything goes wrong with it under other filesystems,
- * mmap will fail.
- */
-if (ftruncate(fd, memory)) {
-perror("ftruncate");
-}
 
 area = qemu_ram_mmap(fd, memory, pagesize, block->flags & RAM_SHARED);
 if (area == MAP_FAILED) {
-- 
1.8.3.1




Re: [Qemu-devel] [PULL for-2.5] Update OpenBIOS images

2015-10-28 Thread Peter Maydell
On 28 October 2015 at 00:32, Mark Cave-Ayland
 wrote:
> The following changes since commit 7e038b94e74e1c2d1b3598e2e4b0b5c8b79a7278:
>
>   Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into 
> staging (2015-10-27 10:10:46 +)
>
> are available in the git repository at:
>
>
>   https://github.com/mcayland/qemu.git tags/qemu-openbios-signed
>
> for you to fetch changes up to 637016c2603d15d01957eb57f64387262e3ba830:
>
>   Update OpenBIOS images (2015-10-28 00:01:28 +)
>
> 
> Update OpenBIOS images
>
> 
> Mark Cave-Ayland (1):
>   Update OpenBIOS images
>
>  pc-bios/openbios-ppc |  Bin 746588 -> 746588 bytes
>  pc-bios/openbios-sparc32 |  Bin 381512 -> 381584 bytes
>  pc-bios/openbios-sparc64 |  Bin 1616768 -> 1616864 bytes
>  roms/openbios|2 +-
>  4 files changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

-- PMM



[Qemu-devel] [PATCH v4 for 2.5 0/3] qga: non-blocking fd cleanups

2015-10-28 Thread Denis V. Lunev
This patchset is reincarnation of one patch discussed in the scope of
QEMU 2.4 and rejected for that time. Actually we should use
non-blocking descriptors in QGA on Windows in guest-file-open exactly
like was done for Posix.

Changes from v3:
- handle_set_nonblocking now is local function in qga/commands-win32.c
  It works only in one way - set handle nonblocking.

Changes from v2:
- added fix for wrong argument to CloseHandle
- switched setting non-block for pipes to use separate function

Changes from v1:
- call to qemu_fd_register is moved to a proper place
- moved declaration of opt to a proper place

Signed-off-by: Denis V. Lunev 
Signed-off-by: Olga Krishtal 
CC: Yuri Pudgorodskiy 
CC: Michael Roth 

Denis V. Lunev (1):
  qga: drop hand-made guest_file_toggle_flags helper

Olga Krishtal (2):
  qga: fixed CloseHandle in qmp_guest_file_open
  qga: set file descriptor in qmp_guest_file_open non-blocking on Win32

 qga/commands-posix.c | 27 ++-
 qga/commands-win32.c | 29 -
 2 files changed, 30 insertions(+), 26 deletions(-)

-- 
2.1.4




[Qemu-devel] [PATCH 2/3] qga: fixed CloseHandle in qmp_guest_file_open

2015-10-28 Thread Denis V. Lunev
From: Olga Krishtal 

CloseHandle use HANDLE as an argument, but not *HANDLE

Signed-off-by: Olga Krishtal 
Signed-off-by: Denis V. Lunev 
Reviewed-by: Stefan Weil 
CC: Michael Roth 
---
 qga/commands-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d9de23b..97f19d5 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -160,7 +160,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode,
 
 fd = guest_file_handle_add(fh, errp);
 if (fd < 0) {
-CloseHandle();
+CloseHandle(fh);
 error_setg(errp, "failed to add handle to qmp handle table");
 return -1;
 }
-- 
2.1.4




[Qemu-devel] [PATCH 1/3] qga: drop hand-made guest_file_toggle_flags helper

2015-10-28 Thread Denis V. Lunev
We'd better use generic qemu_set_nonblock directly.

Signed-off-by: Denis V. Lunev 
Reviewed-by: Yuri Pudgorodskiy 
Reviewed-by: Eric Blake 
CC: Michael Roth 
---
 qga/commands-posix.c | 27 ++-
 1 file changed, 2 insertions(+), 25 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 67a173a..0ebd473 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -28,6 +28,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/queue.h"
 #include "qemu/host-utils.h"
+#include "qemu/sockets.h"
 
 #ifndef CONFIG_HAS_ENVIRON
 #ifdef __APPLE__
@@ -385,27 +386,6 @@ safe_open_or_create(const char *path, const char *mode, 
Error **errp)
 return NULL;
 }
 
-static int guest_file_toggle_flags(int fd, int flags, bool set, Error **err)
-{
-int ret, old_flags;
-
-old_flags = fcntl(fd, F_GETFL);
-if (old_flags == -1) {
-error_setg_errno(err, errno, QERR_QGA_COMMAND_FAILED,
- "failed to fetch filehandle flags");
-return -1;
-}
-
-ret = fcntl(fd, F_SETFL, set ? (old_flags | flags) : (old_flags & ~flags));
-if (ret == -1) {
-error_setg_errno(err, errno, QERR_QGA_COMMAND_FAILED,
- "failed to set filehandle flags");
-return -1;
-}
-
-return ret;
-}
-
 int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode,
 Error **errp)
 {
@@ -426,10 +406,7 @@ int64_t qmp_guest_file_open(const char *path, bool 
has_mode, const char *mode,
 /* set fd non-blocking to avoid common use cases (like reading from a
  * named pipe) from hanging the agent
  */
-if (guest_file_toggle_flags(fileno(fh), O_NONBLOCK, true, errp) < 0) {
-fclose(fh);
-return -1;
-}
+qemu_set_nonblock(fileno(fh));
 
 handle = guest_file_handle_add(fh, errp);
 if (handle < 0) {
-- 
2.1.4




Re: [Qemu-devel] proposal: new qemu-arm mailing list

2015-10-28 Thread John Snow


On 10/28/2015 02:49 AM, Pavel Fedin wrote:
>  Hello!
> 
>> Just to jump on and bead a dead horse, I am not OK with the idea of a
>> mailing list where patches might get reviewed and staged for pull
>> without the general population of qemu-devel being able to look first.
> 
>  Ok ok, i don't object, Peter has already explained a similar thing to me, 
> and i silently agreed.
> 
> Kind regards,
> Pavel Fedin
> Expert Engineer
> Samsung Electronics Research center Russia
> 
> 

Sorry :)

I am of course in favor of the list in general. qemu-block has been very
useful for us.

--js



[Qemu-devel] [PATCH v5 18/33] dimm: get mapped memory region from DIMMDeviceClass->get_memory_region

2015-10-28 Thread Xiao Guangrong
Curretly, the memory region of backed memory is directly mapped to
guest's address space, however, it is not true for nvdimm device

This patch let dimm device realize this fact and use
DIMMDeviceClass->get_memory_region method to get the mapped memory
region

Signed-off-by: Xiao Guangrong 
---
 hw/mem/dimm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index 23d5daa..9e0403a 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -380,8 +380,9 @@ static void dimm_get_size(Object *obj, Visitor *v, void 
*opaque,
 int64_t value;
 MemoryRegion *mr;
 DIMMDevice *dimm = DIMM(obj);
+DIMMDeviceClass *ddc = DIMM_GET_CLASS(obj);
 
-mr = host_memory_backend_get_memory(dimm->hostmem, errp);
+mr = ddc->get_memory_region(dimm);
 value = memory_region_size(mr);
 
 visit_type_int(v, , name, errp);
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 04/33] acpi: add aml_concatenate

2015-10-28 Thread Xiao Guangrong
Implement Concatenate term which is used by NVDIMM _DSM method
in later patch

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/aml-build.c | 14 ++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 9fe5e7b..efc06ab 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1164,6 +1164,20 @@ Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, 
const char *name)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefConcat */
+Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target)
+{
+Aml *var = aml_opcode(0x73 /* ConcatOp */);
+aml_append(var, source1);
+aml_append(var, source2);
+
+if (target) {
+aml_append(var, target);
+}
+
+return var;
+}
+
 void
 build_header(GArray *linker, GArray *table_data,
  AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 7e1c43b..325782d 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -277,6 +277,7 @@ Aml *aml_unicode(const char *str);
 Aml *aml_derefof(Aml *arg);
 Aml *aml_sizeof(Aml *arg);
 Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name);
+Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target);
 
 void
 build_header(GArray *linker, GArray *table_data,
-- 
1.8.3.1




[Qemu-devel] [PATCH 0/2] trace: fix Makefile dependencies

2015-10-28 Thread Stefan Hajnoczi
Issues with trace/Makefile.objs:

1. Generated code is not recreated when patches modify scripts/tracetool/*.py.
   Typically such patches also modify trace/*.[ch] and the result is build
   failures when new C code compiles against stale generated code.

2. The timestamp mechanism used to avoid unnecessary rebuilding is broken, it
   currently requires two make invocations for a full build.

Stefan Hajnoczi (2):
  trace: fix make foo-timestamp rules
  trace: add make dependencies on tracetool source

 trace/Makefile.objs | 50 ++
 1 file changed, 30 insertions(+), 20 deletions(-)

-- 
2.4.3




[Qemu-devel] [PATCH 3/3] qga: set file descriptor in qmp_guest_file_open non-blocking on Win32

2015-10-28 Thread Denis V. Lunev
From: Olga Krishtal 

Set fd non-blocking to avoid common use cases (like reading from a
named pipe) from hanging the agent. This was missed in the original
code.

The patch introduces qemu_set_handle_nonoblocking, the local analog
of qemu_set_nonblock for HANDLES.
The usage of handles in qemu_set_non/block is impossible, because for
win32 there is a difference between file discriptors and file handles,
and all file ops are made via Win32 api.

Signed-off-by: Olga Krishtal 
Signed-off-by: Denis V. Lunev 
CC: Michael Roth 
CC: Stefan Weil 
---
 qga/commands-win32.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 97f19d5..a5306e7 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -128,6 +128,28 @@ static GuestFileHandle *guest_file_handle_find(int64_t id, 
Error **errp)
 return NULL;
 }
 
+static void handle_set_nonblocking(HANDLE fh)
+{
+DWORD file_type, pipe_state;
+file_type = GetFileType(fh);
+if (file_type != FILE_TYPE_PIPE) {
+return;
+}
+/* If file_type == FILE_TYPE_PIPE, according to MSDN
+ * the specified file is socket or named pipe */
+if (!GetNamedPipeHandleState(fh, _state, NULL,
+ NULL, NULL, NULL, 0)) {
+return;
+}
+/* The fd is named pipe fd */
+if (pipe_state & PIPE_NOWAIT) {
+return;
+}
+
+pipe_state |= PIPE_NOWAIT;
+SetNamedPipeHandleState(fh, _state, NULL, NULL);
+}
+
 int64_t qmp_guest_file_open(const char *path, bool has_mode,
 const char *mode, Error **errp)
 {
@@ -158,6 +180,11 @@ int64_t qmp_guest_file_open(const char *path, bool 
has_mode,
 return -1;
 }
 
+/* set fd non-blocking to avoid common use cases (like reading from a
+ * named pipe) from hanging the agent
+ */
+handle_set_nonblocking(fh);
+
 fd = guest_file_handle_add(fh, errp);
 if (fd < 0) {
 CloseHandle(fh);
-- 
2.1.4




Re: [Qemu-devel] [PATCH 01/11] trace: fix documentation

2015-10-28 Thread Denis V. Lunev

On 10/26/2015 11:05 PM, Christian Borntraeger wrote:

Am 26.10.2015 um 18:10 schrieb Denis V. Lunev:

From: Paolo Bonzini 

Mention the ftrace backend too.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Denis V. Lunev 
Reviewed-by: Christian Borntraeger 

Can you make that
Acked-by: Christian Borntraeger 
?

I agree with the series, but have not fully reviewed it
:-)

Christian


should I re-submit?

Den



Re: [Qemu-devel] [PULL v2 00/14] QMP and QObject patches

2015-10-28 Thread Eric Blake
On 10/28/2015 09:07 AM, Peter Maydell wrote:

>>   glib: add compatibility interface for g_hash_table_add()
>>   monitor: Turn monitor_qapi_event_state[] into a hash table

> 
>   CCqga/commands-posix.o
> In file included from /Users/pm215/src/qemu-for-merges/qga/main.c:25:
> In file included from
> /Users/pm215/src/qemu-for-merges/include/qapi/qmp/json-parser.h:17:
> In file included from 
> /Users/pm215/src/qemu-for-merges/include/qemu-common.h:25:
> /Users/pm215/src/qemu-for-merges/include/glib-compat.h:171:12: error:
> returning 'void' from a function with incompatible result type
> 'gboolean' (aka 'int')
> return g_hash_table_replace(hash_table, key, key)
>^~
> 
> Looks like g_hash_table_replace was originally a 'void' return
> and switched to 'gboolean' return at some later date:
> 
> https://github.com/GNOME/glib/commit/910191597a6c2e5d5d460e9ce9efb4f47d9cc63c

This patch series isn't using the return value of g_hash_table_add, so
our glib replacement could be changed to return void.

On the other hand, would it be better to proactively retrofit the return
type into ALL of the g_hash_table_* functions that were swapped to
return a value, so that future uses of the functions with qemu can make
use of the modern contract, even though this series doesn't use it?

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v3 3/6] e1000: Fixing the received/transmitted packets' counters

2015-10-28 Thread Leonid Bloch
According to Intel's specs, these counters (as the other Statistic
registers) stick at 0x when this maximal value is reached.
Previously, they would reset after the max. value.

Signed-off-by: Leonid Bloch 
Signed-off-by: Dmitry Fleytman 
---
 hw/net/e1000.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index fa65e79..f55a3f6 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -575,6 +575,14 @@ putsum(uint8_t *data, uint32_t n, uint32_t sloc, uint32_t 
css, uint32_t cse)
 }
 }
 
+static inline void
+inc_reg_if_not_full(E1000State *s, int index)
+{
+if (s->mac_reg[index] != 0x) {
+s->mac_reg[index]++;
+}
+}
+
 static inline int
 vlan_enabled(E1000State *s)
 {
@@ -671,8 +679,8 @@ xmit_seg(E1000State *s)
 e1000_send_packet(s, tp->data, tp->size);
 }
 
-s->mac_reg[TPT]++;
-s->mac_reg[GPTC]++;
+inc_reg_if_not_full(s, TPT);
+s->mac_reg[GPTC] = s->mac_reg[TPT];
 n = s->mac_reg[TOTL];
 if ((s->mac_reg[TOTL] += s->tx.size) < n)
 s->mac_reg[TOTH]++;
@@ -1085,8 +1093,8 @@ e1000_receive_iov(NetClientState *nc, const struct iovec 
*iov, int iovcnt)
 }
 } while (desc_offset < total_size);
 
-s->mac_reg[GPRC]++;
-s->mac_reg[TPR]++;
+inc_reg_if_not_full(s, TPR);
+s->mac_reg[GPRC] = s->mac_reg[TPR];
 /* TOR - Total Octets Received:
  * This register includes bytes received in a packet from the  field through the  field, inclusively.
-- 
2.4.3




[Qemu-devel] [PATCH v4 01/21] xen_disk: Account for flush operations

2015-10-28 Thread Alberto Garcia
Currently both BLKIF_OP_WRITE and BLKIF_OP_FLUSH_DISKCACHE are being
accounted as write operations.

Signed-off-by: Alberto Garcia 
Reviewed-by: Stefan Hajnoczi 
---
 hw/block/xen_disk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 1bbc111..4869518 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -576,7 +576,9 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
 }
 
 block_acct_start(blk_get_stats(blkdev->blk), >acct,
- ioreq->v.size, BLOCK_ACCT_WRITE);
+ ioreq->v.size,
+ ioreq->req.operation == BLKIF_OP_WRITE ?
+ BLOCK_ACCT_WRITE : BLOCK_ACCT_FLUSH);
 ioreq->aio_inflight++;
 blk_aio_writev(blkdev->blk, ioreq->start / BLOCK_SIZE,
>v, ioreq->v.size / BLOCK_SIZE,
-- 
2.6.1




[Qemu-devel] [PATCH v4 03/21] block: define 'clock_type' for the accounting code

2015-10-28 Thread Alberto Garcia
Its value is still QEMU_CLOCK_REALTIME, but having it in a variable will
allow us to change its value easily in the future when running in qtest
mode.

Signed-off-by: Alberto Garcia 
Reviewed-by: Stefan Hajnoczi 
---
 block/accounting.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/block/accounting.c b/block/accounting.c
index a423560..6f4c0f1 100644
--- a/block/accounting.c
+++ b/block/accounting.c
@@ -26,13 +26,15 @@
 #include "block/block_int.h"
 #include "qemu/timer.h"
 
+static QEMUClockType clock_type = QEMU_CLOCK_REALTIME;
+
 void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
   int64_t bytes, enum BlockAcctType type)
 {
 assert(type < BLOCK_MAX_IOTYPE);
 
 cookie->bytes = bytes;
-cookie->start_time_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+cookie->start_time_ns = qemu_clock_get_ns(clock_type);
 cookie->type = type;
 }
 
@@ -43,7 +45,7 @@ void block_acct_done(BlockAcctStats *stats, BlockAcctCookie 
*cookie)
 stats->nr_bytes[cookie->type] += cookie->bytes;
 stats->nr_ops[cookie->type]++;
 stats->total_time_ns[cookie->type] +=
-qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - cookie->start_time_ns;
+qemu_clock_get_ns(clock_type) - cookie->start_time_ns;
 }
 
 
-- 
2.6.1




[Qemu-devel] [PATCH v4 00/21] Extended I/O accounting

2015-10-28 Thread Alberto Garcia
Here's v4 of the series that implements extended I/O accounting for
block devices.

Since part of Max's BlockBackend series has already been merged, this
series can now be applied cleanly on top of the master branch without
additional dependencies.

Here's the summary of what this series provides:

 - New block_acct_failed() and block_acct_invalid() calls.
   We keep track now of the number of successful, failed and invalid
   operations (each one separated into read, write and flush). So from
   the API point of view, BlockDeviceStats contains 6 new fields for
   those.

 - idle_time_ns: time since the last I/O operation.

 - New BlockDeviceTimedStats struct: it has statistics for the I/O
   during a given interval of time. It keeps minimum, maximum and
   average latencies for read, write and flush operations.

   It also keeps the average read and write queue depths.

 - New 'stats-intervals' option that allows the user to define the
   intervals used to keep the aforementioned statistics. An arbitrary
   number of intervals can be specified, the length of each one is in
   seconds.

   For the API I opted for a colon-separated list of numbers,

  stats-intervals=60:3600:86400

   I also considered something a different syntax,

  stats-intervals.0.length=60,
  stats-intervals.1.length=3600,
  stats-intervals.2.length=86400

   This one could be useful if we want to specify any other attribute
   for each interval, but I couldn't come up with any, so I chose the
   simpler solution.

 - Two new options, stats-account-invalid and stats-account-failed,
   which allow the user to decide whether to count invalid and failed
   operations when computing the idle time and total latency.

Regards,

Berto

v4:
- Rebase on top of the current master. This series no longer depends
  on any other.
- patch 8: clarify that interval_length is in seconds [Stefan]
- patch 9: rewrite timed_average_sum() so it does not call
  qemu_clock_get_ns() twice [Stefan]

v3: https://lists.gnu.org/archive/html/qemu-block/2015-10/msg00785.html
- Rebased on top of the current master and on Max's BlockBackend
  series v7
- patch 4: minor documentation fixes [Stefan]
- patch 5: s/miliseconds/nanoseconds/ [Stefan]
- patch 6: dropped, there's no "supports_stats" anymore [Stefan]
- patch 7 (now 6): explain why block_acct_invalid() does not update
  total_time_ns[] [Stefan]
- patch 12 (now 11): don't initialize BlockAcctCookie to { 0 }, it's
   not needed.

v2: https://lists.gnu.org/archive/html/qemu-block/2015-10/msg00161.html
- First complete implementation of the new statistics

v1: https://lists.gnu.org/archive/html/qemu-devel/2015-06/msg03321.html
- Initial series containing only the timed average infrastructure.

Alberto Garcia (21):
  xen_disk: Account for flush operations
  ide: Account for write operations correctly
  block: define 'clock_type' for the accounting code
  util: Infrastructure for computing recent averages
  block: Add idle_time_ns to BlockDeviceStats
  block: Add statistics for failed and invalid I/O operations
  block: Allow configuring whether to account failed and invalid ops
  block: Compute minimum, maximum and average I/O latencies
  block: Add average I/O queue depth to BlockDeviceTimedStats
  block: New option to define the intervals for collecting I/O
statistics
  qemu-io: Account for failed, invalid and flush operations
  block: Use QEMU_CLOCK_VIRTUAL for the accounting code in qtest mode
  iotests: Add test for the block device statistics
  nvme: Account for failed and invalid operations
  virtio-blk: Account for failed and invalid operations
  xen_disk: Account for failed and invalid operations
  atapi: Account for failed and invalid operations
  ide: Account for failed and invalid operations
  macio: Account for failed operations
  scsi-disk: Account for failed operations
  block: Update copyright of the accounting code

 block/accounting.c   | 123 ++-
 block/block-backend.c|   1 +
 block/qapi.c |  51 +++
 blockdev.c   |  53 +++
 hmp.c|   4 +-
 hw/block/nvme.c  |  11 +-
 hw/block/virtio-blk.c|   4 +-
 hw/block/xen_disk.c  |  27 +++-
 hw/ide/atapi.c   |  31 ++--
 hw/ide/core.c|  12 +-
 hw/ide/macio.c   |  12 +-
 hw/scsi/scsi-disk.c  |  46 --
 include/block/accounting.h   |  28 
 include/qemu/timed-average.h |  64 
 qapi/block-core.json | 103 -
 qemu-io-cmds.c   |   9 ++
 qmp-commands.hx  |  80 +-
 tests/Makefile   |   4 +
 tests/qemu-iotests/136   | 349 +++
 tests/qemu-iotests/136.out   |   5 +
 tests/qemu-iotests/group |   1 +
 tests/test-timed-average.c   |  90 +++
 util/Makefile.objs   |   1 +
 util/timed-average.c | 231 
 24 

[Qemu-devel] [PATCH v5 01/33] acpi: add aml_derefof

2015-10-28 Thread Xiao Guangrong
Implement DeRefOf term which is used by NVDIMM _DSM method in later patch

Reviewed-by: Igor Mammedov 
Signed-off-by: Xiao Guangrong 
---
 hw/acpi/aml-build.c | 8 
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 0d4b324..cbd53f4 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1135,6 +1135,14 @@ Aml *aml_unicode(const char *str)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefDerefOf */
+Aml *aml_derefof(Aml *arg)
+{
+Aml *var = aml_opcode(0x83 /* DerefOfOp */);
+aml_append(var, arg);
+return var;
+}
+
 void
 build_header(GArray *linker, GArray *table_data,
  AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 1b632dc..5a03d33 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -274,6 +274,7 @@ Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const 
char *name);
 Aml *aml_varpackage(uint32_t num_elements);
 Aml *aml_touuid(const char *uuid);
 Aml *aml_unicode(const char *str);
+Aml *aml_derefof(Aml *arg);
 
 void
 build_header(GArray *linker, GArray *table_data,
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 06/33] acpi: add aml_method_serialized

2015-10-28 Thread Xiao Guangrong
It avoid explicit Mutex and will be used by NVDIMM ACPI

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/aml-build.c | 26 --
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 9f792ab..8bee8b2 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -696,14 +696,36 @@ Aml *aml_while(Aml *predicate)
 }
 
 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */
-Aml *aml_method(const char *name, int arg_count)
+static Aml *__aml_method(const char *name, int arg_count, bool serialized)
 {
 Aml *var = aml_bundle(0x14 /* MethodOp */, AML_PACKAGE);
+int methodflags;
+
+/*
+ * MethodFlags:
+ *   bit 0-2: ArgCount (0-7)
+ *   bit 3: SerializeFlag
+ * 0: NotSerialized
+ * 1: Serialized
+ *   bit 4-7: reserved (must be 0)
+ */
+assert(!(arg_count & ~7));
+methodflags = arg_count | (serialized << 3);
 build_append_namestring(var->buf, "%s", name);
-build_append_byte(var->buf, arg_count); /* MethodFlags: ArgCount */
+build_append_byte(var->buf, methodflags);
 return var;
 }
 
+Aml *aml_method(const char *name, int arg_count)
+{
+return __aml_method(name, arg_count, false);
+}
+
+Aml *aml_method_serialized(const char *name, int arg_count)
+{
+return __aml_method(name, arg_count, true);
+}
+
 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefDevice */
 Aml *aml_device(const char *name_format, ...)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 5b8a118..00cf40e 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -263,6 +263,7 @@ Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_method(const char *name, int arg_count);
+Aml *aml_method_serialized(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
 Aml *aml_else(void);
 Aml *aml_while(Aml *predicate);
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 30/33] nvdimm acpi: support Set Namespace Label Data function

2015-10-28 Thread Xiao Guangrong
Function 6 is used to set Namespace Label Data

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/nvdimm.c | 41 +
 1 file changed, 41 insertions(+)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 5b621ed..5e72ca8 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -572,6 +572,44 @@ exit:
 nvdimm_dsm_write_status(out, status);
 }
 
+/*
+ * DSM Spec Rev1 4.6 Set Namespace Label Data (Function Index 6).
+ */
+static void nvdimm_dsm_func_set_label_data(NVDIMMDevice *nvdimm,
+   nvdimm_dsm_in *in, GArray *out)
+{
+NVDIMMClass *nvc = NVDIMM_GET_CLASS(nvdimm);
+nvdimm_func_in_set_label_data *set_label_data = >func_set_label_data;
+uint32_t status;
+
+le32_to_cpus(_label_data->offset);
+le32_to_cpus(_label_data->length);
+
+nvdimm_debug("Write Label Data: offset %#x length %#x.\n",
+ set_label_data->offset, set_label_data->length);
+
+if (nvdimm->label_size < set_label_data->offset + set_label_data->length) {
+nvdimm_debug("position %#x is beyond label data (len = %#lx).\n",
+ set_label_data->offset + set_label_data->length,
+ nvdimm->label_size);
+status = NVDIMM_DSM_DEV_STATUS_INVALID_PARAS;
+goto exit;
+}
+
+if (set_label_data->length > nvdimm_get_max_xfer_label_size()) {
+nvdimm_debug("set length (%#x) is larger than max_xfer (%#x).\n",
+ set_label_data->length, nvdimm_get_max_xfer_label_size());
+status = NVDIMM_DSM_DEV_STATUS_INVALID_PARAS;
+goto exit;
+}
+
+status = NVDIMM_DSM_STATUS_SUCCESS;
+nvc->write_label_data(nvdimm, set_label_data->in_buf,
+  set_label_data->length, set_label_data->offset);
+exit:
+nvdimm_dsm_write_status(out, status);
+}
+
 static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray *out)
 {
 GSList *list = nvdimm_get_plugged_device_list();
@@ -602,6 +640,9 @@ static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray 
*out)
 case 0x5 /* Get Namespace Label Data */:
 nvdimm_dsm_func_get_label_data(nvdimm, in, out);
 goto free;
+case 0x6 /* Set Namespace Label Data */:
+nvdimm_dsm_func_set_label_data(nvdimm, in, out);
+goto free;
 default:
 status = NVDIMM_DSM_STATUS_NOT_SUPPORTED;
 };
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 05/33] acpi: add aml_object_type

2015-10-28 Thread Xiao Guangrong
Implement ObjectType which is used by NVDIMM _DSM method in
later patch

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/aml-build.c | 8 
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index efc06ab..9f792ab 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1178,6 +1178,14 @@ Aml *aml_concatenate(Aml *source1, Aml *source2, Aml 
*target)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefObjectType */
+Aml *aml_object_type(Aml *object)
+{
+Aml *var = aml_opcode(0x8E /* ObjectTypeOp */);
+aml_append(var, object);
+return var;
+}
+
 void
 build_header(GArray *linker, GArray *table_data,
  AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 325782d..5b8a118 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -278,6 +278,7 @@ Aml *aml_derefof(Aml *arg);
 Aml *aml_sizeof(Aml *arg);
 Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name);
 Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target);
+Aml *aml_object_type(Aml *object);
 
 void
 build_header(GArray *linker, GArray *table_data,
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 19/33] dimm: keep the state of the whole backend memory

2015-10-28 Thread Xiao Guangrong
QEMU keeps the state of memory of dimm device during live migration,
however, it is not enough for nvdimm device as its memory does not
contain its label data, so that we should protect the whole backend
memory instead

Signed-off-by: Xiao Guangrong 
---
 hw/mem/dimm.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index 9e0403a..478cacd 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -135,9 +135,16 @@ void dimm_memory_plug(DeviceState *dev, MemoryHotplugState 
*hpms,
 }
 
 memory_region_add_subregion(>mr, addr - hpms->base, mr);
-vmstate_register_ram(mr, dev);
 numa_set_mem_node_id(addr, memory_region_size(mr), dimm->node);
 
+/*
+ * save the state only for @mr is not enough as it does not contain
+ * the label data of NVDIMM device, so that we keep the state of
+ * whole hostmem instead.
+ */
+vmstate_register_ram(host_memory_backend_get_memory(dimm->hostmem, errp),
+ dev);
+
 out:
 error_propagate(errp, local_err);
 }
@@ -146,10 +153,13 @@ void dimm_memory_unplug(DeviceState *dev, 
MemoryHotplugState *hpms,
MemoryRegion *mr)
 {
 DIMMDevice *dimm = DIMM(dev);
+MemoryRegion *backend_mr;
+
+backend_mr = host_memory_backend_get_memory(dimm->hostmem, _abort);
 
 numa_unset_mem_node_id(dimm->addr, memory_region_size(mr), dimm->node);
 memory_region_del_subregion(>mr, mr);
-vmstate_unregister_ram(mr, dev);
+vmstate_unregister_ram(backend_mr, dev);
 }
 
 int qmp_dimm_device_list(Object *obj, void *opaque)
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 26/33] nvdimm acpi: save arg3 for NVDIMM device _DSM method

2015-10-28 Thread Xiao Guangrong
Check if the input Arg3 is valid then store it into dsm_in if needed

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/nvdimm.c | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 8412be3..69de4f6 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -524,13 +524,38 @@ static void nvdimm_build_acpi_devices(GSList 
*device_list, Aml *sb_scope)
 
 method = aml_method_serialized("NCAL", 4);
 {
-Aml *buffer_size = aml_local(0);
+Aml *ifctx, *pckg, *buffer_size = aml_local(0);
 
 aml_append(method, aml_store(aml_arg(0), aml_name("HDLE")));
 aml_append(method, aml_store(aml_arg(1), aml_name("REVS")));
 aml_append(method, aml_store(aml_arg(2), aml_name("FUNC")));
 
 /*
+ * The fourth parameter (Arg3) of _DSM is a package which contains
+ * a buffer, the layout of the buffer is specified by UUID (Arg0),
+ * Revision ID (Arg1) and Function Index (Arg2) which are documented
+ * in the DSM Spec.
+ */
+pckg = aml_arg(3);
+ifctx = aml_if(aml_and(aml_equal(aml_object_type(pckg),
+ aml_int(4 /* Package */)),
+   aml_equal(aml_sizeof(pckg),
+ aml_int(1;
+{
+Aml *pckg_index, *pckg_buf;
+
+pckg_index = aml_local(2);
+pckg_buf = aml_local(3);
+
+aml_append(ifctx, aml_store(aml_index(pckg, aml_int(0)),
+pckg_index));
+aml_append(ifctx, aml_store(aml_derefof(pckg_index),
+pckg_buf));
+aml_append(ifctx, aml_store(pckg_buf, aml_name("ARG3")));
+}
+aml_append(method, ifctx);
+
+/*
  * transfer control to QEMU and the buffer size filled by
  * QEMU is returned.
  */
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 16/33] pc-dimm: rename pc-dimm.c and pc-dimm.h

2015-10-28 Thread Xiao Guangrong
Rename:
   pc-dimm.c => dimm.c
   pc-dimm.h => dimm.h

It prepares the work which abstracts dimm device type for both pc-dimm and
nvdimm

Signed-off-by: Xiao Guangrong 
---
 hw/Makefile.objs | 2 +-
 hw/acpi/ich9.c   | 2 +-
 hw/acpi/memory_hotplug.c | 4 ++--
 hw/acpi/piix4.c  | 2 +-
 hw/i386/pc.c | 2 +-
 hw/mem/Makefile.objs | 2 +-
 hw/mem/{pc-dimm.c => dimm.c} | 2 +-
 hw/ppc/spapr.c   | 2 +-
 include/hw/i386/pc.h | 2 +-
 include/hw/mem/{pc-dimm.h => dimm.h} | 0
 include/hw/ppc/spapr.h   | 2 +-
 numa.c   | 2 +-
 qmp.c| 2 +-
 stubs/qmp_dimm_device_list.c | 2 +-
 14 files changed, 14 insertions(+), 14 deletions(-)
 rename hw/mem/{pc-dimm.c => dimm.c} (99%)
 rename include/hw/mem/{pc-dimm.h => dimm.h} (100%)

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index 7e7c241..12ecda9 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -30,8 +30,8 @@ devices-dirs-$(CONFIG_SOFTMMU) += vfio/
 devices-dirs-$(CONFIG_VIRTIO) += virtio/
 devices-dirs-$(CONFIG_SOFTMMU) += watchdog/
 devices-dirs-$(CONFIG_SOFTMMU) += xen/
-devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/
 devices-dirs-$(CONFIG_SMBIOS) += smbios/
+devices-dirs-y += mem/
 devices-dirs-y += core/
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index b0d6a67..1e9ae20 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -35,7 +35,7 @@
 #include "exec/address-spaces.h"
 
 #include "hw/i386/ich9.h"
-#include "hw/mem/pc-dimm.h"
+#include "hw/mem/dimm.h"
 
 //#define DEBUG
 
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 1f6..e232641 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -1,6 +1,6 @@
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/pc-hotplug.h"
-#include "hw/mem/pc-dimm.h"
+#include "hw/mem/dimm.h"
 #include "hw/boards.h"
 #include "hw/qdev-core.h"
 #include "trace.h"
@@ -148,7 +148,7 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr 
addr, uint64_t data,
 
 dev = DEVICE(mdev->dimm);
 hotplug_ctrl = qdev_get_hotplug_handler(dev);
-/* call pc-dimm unplug cb */
+/* call dimm unplug cb */
 hotplug_handler_unplug(hotplug_ctrl, dev, _err);
 if (local_err) {
 trace_mhp_acpi_dimm_delete_failed(mem_st->selector);
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 0b2cb6e..b2f5b2c 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -33,7 +33,7 @@
 #include "hw/acpi/pcihp.h"
 #include "hw/acpi/cpu_hotplug.h"
 #include "hw/hotplug.h"
-#include "hw/mem/pc-dimm.h"
+#include "hw/mem/dimm.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/acpi_dev_interface.h"
 #include "hw/xen/xen.h"
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d8732f3..b8584d7 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -62,7 +62,7 @@
 #include "hw/boards.h"
 #include "hw/pci/pci_host.h"
 #include "acpi-build.h"
-#include "hw/mem/pc-dimm.h"
+#include "hw/mem/dimm.h"
 #include "qapi/visitor.h"
 #include "qapi-visit.h"
 
diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs
index b000fb4..7563ef5 100644
--- a/hw/mem/Makefile.objs
+++ b/hw/mem/Makefile.objs
@@ -1 +1 @@
-common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o
+common-obj-$(CONFIG_MEM_HOTPLUG) += dimm.o
diff --git a/hw/mem/pc-dimm.c b/hw/mem/dimm.c
similarity index 99%
rename from hw/mem/pc-dimm.c
rename to hw/mem/dimm.c
index 51f737f..6c1ea98 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/dimm.c
@@ -18,7 +18,7 @@
  * License along with this library; if not, see 
  */
 
-#include "hw/mem/pc-dimm.h"
+#include "hw/mem/dimm.h"
 #include "qemu/config-file.h"
 #include "qapi/visitor.h"
 #include "qemu/range.h"
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 4fb91a5..171fa77 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2138,7 +2138,7 @@ static void spapr_machine_device_plug(HotplugHandler 
*hotplug_dev,
  *
  * - Memory gets hotplugged to a different node than what the user
  *   specified.
- * - Since pc-dimm subsystem in QEMU still thinks that memory belongs
+ * - Since dimm subsystem in QEMU still thinks that memory belongs
  *   to memory-less node, a reboot will set things accordingly
  *   and the previously hotplugged memory now ends in the right node.
  *   This appears as if some memory moved from one node to another.
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index c5961d7..7dfb50f 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -16,7 +16,7 @@
 #include "hw/pci/pci.h"
 #include "hw/boards.h"
 #include "hw/compat.h"
-#include "hw/mem/pc-dimm.h"
+#include "hw/mem/dimm.h"
 
 #define HPET_INTCAP "hpet-intcap"
 
diff --git 

[Qemu-devel] [PATCH v5 25/33] nvdimm acpi: build ACPI nvdimm devices

2015-10-28 Thread Xiao Guangrong
NVDIMM devices is defined in ACPI 6.0 9.20 NVDIMM Devices

There is a root device under \_SB and specified NVDIMM devices are under the
root device. Each NVDIMM device has _ADR which returns its handle used to
associate MEMDEV structure in NFIT

We reserve handle 0 for root device. In this patch, we save handle, handle,
arg1 and arg2 to dsm memory. Arg3 is conditionally saved in later patch

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/nvdimm.c | 184 +++
 1 file changed, 184 insertions(+)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 3fc82e1..8412be3 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -368,6 +368,15 @@ static void nvdimm_build_nfit(GSList *device_list, GArray 
*table_offsets,
 g_array_free(structures, true);
 }
 
+struct nvdimm_dsm_in {
+uint32_t handle;
+uint32_t revision;
+uint32_t function;
+   /* the remaining size in the page is used by arg3. */
+uint8_t arg3[0];
+} QEMU_PACKED;
+typedef struct nvdimm_dsm_in nvdimm_dsm_in;
+
 static uint64_t
 nvdimm_dsm_read(void *opaque, hwaddr addr, unsigned size)
 {
@@ -377,6 +386,7 @@ nvdimm_dsm_read(void *opaque, hwaddr addr, unsigned size)
 static void
 nvdimm_dsm_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
 {
+fprintf(stderr, "BUG: we never write DSM notification IO Port.\n");
 }
 
 static const MemoryRegionOps nvdimm_dsm_ops = {
@@ -402,6 +412,179 @@ void nvdimm_init_acpi_state(MemoryRegion *memory, 
MemoryRegion *io,
 memory_region_add_subregion(io, NVDIMM_ACPI_IO_BASE, >io_mr);
 }
 
+#define BUILD_STA_METHOD(_dev_, _method_)  \
+do {   \
+_method_ = aml_method("_STA", 0);  \
+aml_append(_method_, aml_return(aml_int(0x0f)));   \
+aml_append(_dev_, _method_);   \
+} while (0)
+
+#define BUILD_DSM_METHOD(_dev_, _method_, _handle_, _uuid_)\
+do {   \
+Aml *ifctx, *uuid; \
+_method_ = aml_method("_DSM", 4);  \
+/* check UUID if it is we expect, return the errorcode if not.*/   \
+uuid = aml_touuid(_uuid_); \
+ifctx = aml_if(aml_lnot(aml_equal(aml_arg(0), uuid))); \
+aml_append(ifctx, aml_return(aml_int(1 /* Not Supported */))); \
+aml_append(method, ifctx); \
+aml_append(method, aml_return(aml_call4("NCAL", aml_int(_handle_), \
+   aml_arg(1), aml_arg(2), aml_arg(3;  \
+aml_append(_dev_, _method_);   \
+} while (0)
+
+#define BUILD_FIELD_UNIT_SIZE(_field_, _byte_, _name_) \
+aml_append(_field_, aml_named_field(_name_, (_byte_) * BITS_PER_BYTE))
+
+#define BUILD_FIELD_UNIT_STRUCT(_field_, _s_, _f_, _name_) \
+BUILD_FIELD_UNIT_SIZE(_field_, sizeof(typeof_field(_s_, _f_)), _name_)
+
+static void build_nvdimm_devices(GSList *device_list, Aml *root_dev)
+{
+for (; device_list; device_list = device_list->next) {
+NVDIMMDevice *nvdimm = device_list->data;
+int slot = object_property_get_int(OBJECT(nvdimm), DIMM_SLOT_PROP,
+   NULL);
+uint32_t handle = nvdimm_slot_to_handle(slot);
+Aml *dev, *method;
+
+dev = aml_device("NV%02X", slot);
+aml_append(dev, aml_name_decl("_ADR", aml_int(handle)));
+
+BUILD_STA_METHOD(dev, method);
+
+/*
+ * Chapter 4: _DSM Interface for NVDIMM Device (non-root) - Example
+ * in DSM Spec Rev1.
+ */
+BUILD_DSM_METHOD(dev, method,
+ handle /* NVDIMM Device Handle */,
+ "4309AC30-0D11-11E4-9191-0800200C9A66"
+ /* UUID for NVDIMM Devices. */);
+
+aml_append(root_dev, dev);
+}
+}
+
+static void nvdimm_build_acpi_devices(GSList *device_list, Aml *sb_scope)
+{
+Aml *dev, *method, *field;
+uint64_t page_size = getpagesize();
+
+dev = aml_device("NVDR");
+aml_append(dev, aml_name_decl("_HID", aml_string("ACPI0012")));
+
+/* map DSM memory and IO into ACPI namespace. */
+aml_append(dev, aml_operation_region("NPIO", AML_SYSTEM_IO,
+   NVDIMM_ACPI_IO_BASE, NVDIMM_ACPI_IO_LEN));
+aml_append(dev, aml_operation_region("NRAM", AML_SYSTEM_MEMORY,
+   NVDIMM_ACPI_MEM_BASE, page_size));
+
+/*
+ * DSM notifier:
+ * @NOTI: Read it will notify QEMU that _DSM method is being
+ *called and the parameters can be found in nvdimm_dsm_in.
+ *The value 

Re: [Qemu-devel] [PATCH] vnc: fix bug: vnc server can't start when 'to' is specified

2015-10-28 Thread Gerd Hoffmann
On Di, 2015-10-27 at 14:10 +0800, Yang Hongyang wrote:
> commit e0d03b8ceb52 converted VNC startup to use SocketAddress,
> the interface socket_listen don't have a port_offset param, so
> we need to add the port offset (5900) to both 'port' and 'to' opts.
> currently only 'port' is added by offset.
> This patch add the port offset to 'to' opts.

added to vnc patch queue.

thanks,
  Gerd




[Qemu-devel] [PATCH v5 20/33] dimm: introduce realize callback

2015-10-28 Thread Xiao Guangrong
nvdimm need check if the backend memory is large enough to contain label
data and init its memory region when the device is realized, so introduce
realize callback which is called after common dimm has been realize

Signed-off-by: Xiao Guangrong 
---
 hw/mem/dimm.c | 5 +
 include/hw/mem/dimm.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index 478cacd..3d06cb9 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -429,6 +429,7 @@ static void dimm_init(Object *obj)
 static void dimm_realize(DeviceState *dev, Error **errp)
 {
 DIMMDevice *dimm = DIMM(dev);
+DIMMDeviceClass *ddc = DIMM_GET_CLASS(dimm);
 
 if (!dimm->hostmem) {
 error_setg(errp, "'" DIMM_MEMDEV_PROP "' property is not set");
@@ -441,6 +442,10 @@ static void dimm_realize(DeviceState *dev, Error **errp)
dimm->node, nb_numa_nodes ? nb_numa_nodes : 1);
 return;
 }
+
+if (ddc->realize) {
+ddc->realize(dimm, errp);
+}
 }
 
 static void dimm_class_init(ObjectClass *oc, void *data)
diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h
index 84a62ed..663288d 100644
--- a/include/hw/mem/dimm.h
+++ b/include/hw/mem/dimm.h
@@ -65,6 +65,7 @@ typedef struct DIMMDeviceClass {
 DeviceClass parent_class;
 
 /* public */
+void (*realize)(DIMMDevice *dimm, Error **errp);
 MemoryRegion *(*get_memory_region)(DIMMDevice *dimm);
 } DIMMDeviceClass;
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 28/33] nvdimm acpi: support Get Namespace Label Size function

2015-10-28 Thread Xiao Guangrong
Function 4 is used to get Namespace label size

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/nvdimm.c | 87 +++-
 1 file changed, 86 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 8efa640..72203d2 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -407,15 +407,48 @@ enum {
 NVDIMM_DSM_DEV_STATUS_VENDOR_SPECIFIC_ERROR = 4,
 };
 
+struct nvdimm_func_in_get_label_data {
+uint32_t offset; /* the offset in the namespace label data area. */
+uint32_t length; /* the size of data is to be read via the function. */
+} QEMU_PACKED;
+typedef struct nvdimm_func_in_get_label_data nvdimm_func_in_get_label_data;
+
+struct nvdimm_func_in_set_label_data {
+uint32_t offset; /* the offset in the namespace label data area. */
+uint32_t length; /* the size of data is to be written via the function. */
+uint8_t in_buf[0]; /* the data written to label data area. */
+} QEMU_PACKED;
+typedef struct nvdimm_func_in_set_label_data nvdimm_func_in_set_label_data;
+
 struct nvdimm_dsm_in {
 uint32_t handle;
 uint32_t revision;
 uint32_t function;
/* the remaining size in the page is used by arg3. */
-uint8_t arg3[0];
+union {
+uint8_t arg3[0];
+nvdimm_func_in_set_label_data func_set_label_data;
+};
 } QEMU_PACKED;
 typedef struct nvdimm_dsm_in nvdimm_dsm_in;
 
+struct nvdimm_func_out_label_size {
+uint32_t status; /* return status code. */
+uint32_t label_size; /* the size of label data area. */
+/*
+ * Maximum size of the namespace label data length supported by
+ * the platform in Get/Set Namespace Label Data functions.
+ */
+uint32_t max_xfer;
+} QEMU_PACKED;
+typedef struct nvdimm_func_out_label_size nvdimm_func_out_label_size;
+
+struct nvdimm_func_out_get_label_data {
+uint32_t status;/*return status code. */
+uint8_t out_buf[0]; /* the data got via Get Namesapce Label function. */
+} QEMU_PACKED;
+typedef struct nvdimm_func_out_get_label_data nvdimm_func_out_get_label_data;
+
 static void nvdimm_dsm_write_status(GArray *out, uint32_t status)
 {
 status = cpu_to_le32(status);
@@ -445,6 +478,55 @@ static void nvdimm_dsm_root(nvdimm_dsm_in *in, GArray *out)
 nvdimm_dsm_write_status(out, status);
 }
 
+/*
+ * the max transfer size is the max size transferred by both a
+ * 'Get Namespace Label Data' function and a 'Set Namespace Label Data'
+ * function.
+ */
+static uint32_t nvdimm_get_max_xfer_label_size(void)
+{
+nvdimm_dsm_in *in;
+uint32_t max_get_size, max_set_size, dsm_memory_size = getpagesize();
+
+/*
+ * the max data ACPI can read one time which is transferred by
+ * the response of 'Get Namespace Label Data' function.
+ */
+max_get_size = dsm_memory_size - sizeof(nvdimm_func_out_get_label_data);
+
+/*
+ * the max data ACPI can write one time which is transferred by
+ * 'Set Namespace Label Data' function.
+ */
+max_set_size = dsm_memory_size - offsetof(nvdimm_dsm_in, arg3) -
+   sizeof(in->func_set_label_data);
+
+return MIN(max_get_size, max_set_size);
+}
+
+/*
+ * DSM Spec Rev1 4.4 Get Namespace Label Size (Function Index 4).
+ *
+ * It gets the size of Namespace Label data area and the max data size
+ * that Get/Set Namespace Label Data functions can transfer.
+ */
+static void nvdimm_dsm_func_label_size(NVDIMMDevice *nvdimm, GArray *out)
+{
+nvdimm_func_out_label_size func_label_size;
+uint32_t label_size, mxfer;
+
+label_size = nvdimm->label_size;
+mxfer = nvdimm_get_max_xfer_label_size();
+
+nvdimm_debug("label_size %#x, max_xfer %#x.\n", label_size, mxfer);
+
+func_label_size.status = cpu_to_le32(NVDIMM_DSM_STATUS_SUCCESS);
+func_label_size.label_size = cpu_to_le32(label_size);
+func_label_size.max_xfer = cpu_to_le32(mxfer);
+
+g_array_append_vals(out, _label_size, sizeof(func_label_size));
+}
+
 static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray *out)
 {
 GSList *list = nvdimm_get_plugged_device_list();
@@ -469,6 +551,9 @@ static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray 
*out)
1 << 6 /* Set Namespace Label Data */);
 build_append_int_noprefix(out, cmd_list, sizeof(cmd_list));
 goto free;
+case 0x4 /* Get Namespace Label Size */:
+nvdimm_dsm_func_label_size(nvdimm, out);
+goto free;
 default:
 status = NVDIMM_DSM_STATUS_NOT_SUPPORTED;
 };
-- 
1.8.3.1




[Qemu-devel] [PATCH 4/4] migration: add missed aio_context_acquire into HMP snapshot code

2015-10-28 Thread Denis V. Lunev
aio_context should be locked in the similar way as was done in QMP
snapshot creation in the other case there are a lot of possible
troubles if native AIO mode is enabled for disk.

- the command can hang (HMP thread) with missed wakeup (the operation is
  actually complete)
io_submit
ioq_submit
laio_submit
raw_aio_submit
raw_aio_readv
bdrv_co_io_em
bdrv_co_readv_em
bdrv_aligned_preadv
bdrv_co_do_preadv
bdrv_co_do_readv
bdrv_co_readv
qcow2_co_readv
bdrv_aligned_preadv
bdrv_co_do_pwritev
bdrv_rw_co_entry

- QEMU can assert in coroutine re-enter
__GI_abort
qemu_coroutine_enter
bdrv_co_io_em_complete
qemu_laio_process_completion
qemu_laio_completion_bh
aio_bh_poll
aio_dispatch
aio_poll
iothread_run

qemu_fopen_bdrv and bdrv_fclose are used in real snapshot operations only
along with block drivers. This change should influence only HMP snapshot
operations.

AioContext lock is reqursive. Thus nested locking should not be a problem.

Signed-off-by: Denis V. Lunev 
CC: Stefan Hajnoczi 
CC: Paolo Bonzini 
CC: Juan Quintela 
CC: Amit Shah 
---
 block/snapshot.c   |  5 +
 migration/savevm.c | 18 +++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/block/snapshot.c b/block/snapshot.c
index 89500f2..f6fa17a 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -259,6 +259,9 @@ void bdrv_snapshot_delete_by_id_or_name(BlockDriverState 
*bs,
 {
 int ret;
 Error *local_err = NULL;
+AioContext *aio_context = bdrv_get_aio_context(bs);
+
+aio_context_acquire(aio_context);
 
 ret = bdrv_snapshot_delete(bs, id_or_name, NULL, _err);
 if (ret == -ENOENT || ret == -EINVAL) {
@@ -267,6 +270,8 @@ void bdrv_snapshot_delete_by_id_or_name(BlockDriverState 
*bs,
 ret = bdrv_snapshot_delete(bs, NULL, id_or_name, _err);
 }
 
+aio_context_release(aio_context);
+
 if (ret < 0) {
 error_propagate(errp, local_err);
 }
diff --git a/migration/savevm.c b/migration/savevm.c
index dbcc39a..1653f56 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -153,7 +153,11 @@ static ssize_t block_get_buffer(void *opaque, uint8_t 
*buf, int64_t pos,
 
 static int bdrv_fclose(void *opaque)
 {
-return bdrv_flush(opaque);
+BlockDriverState *bs = (BlockDriverState *)opaque;
+int ret = bdrv_flush(bs);
+
+aio_context_release(bdrv_get_aio_context(bs));
+return ret;
 }
 
 static const QEMUFileOps bdrv_read_ops = {
@@ -169,10 +173,18 @@ static const QEMUFileOps bdrv_write_ops = {
 
 static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable)
 {
+QEMUFile *file;
+
 if (is_writable) {
-return qemu_fopen_ops(bs, _write_ops);
+file = qemu_fopen_ops(bs, _write_ops);
+} else {
+file = qemu_fopen_ops(bs, _read_ops);
+}
+
+if (file != NULL) {
+aio_context_acquire(bdrv_get_aio_context(bs));
 }
-return qemu_fopen_ops(bs, _read_ops);
+return file;
 }
 
 
-- 
2.1.4




[Qemu-devel] [PATCH v5 02/33] acpi: add aml_sizeof

2015-10-28 Thread Xiao Guangrong
Implement SizeOf term which is used by NVDIMM _DSM method in later patch

Reviewed-by: Igor Mammedov 
Signed-off-by: Xiao Guangrong 
---
 hw/acpi/aml-build.c | 8 
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cbd53f4..a72214d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1143,6 +1143,14 @@ Aml *aml_derefof(Aml *arg)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefSizeOf */
+Aml *aml_sizeof(Aml *arg)
+{
+Aml *var = aml_opcode(0x87 /* SizeOfOp */);
+aml_append(var, arg);
+return var;
+}
+
 void
 build_header(GArray *linker, GArray *table_data,
  AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 5a03d33..7296efb 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -275,6 +275,7 @@ Aml *aml_varpackage(uint32_t num_elements);
 Aml *aml_touuid(const char *uuid);
 Aml *aml_unicode(const char *str);
 Aml *aml_derefof(Aml *arg);
+Aml *aml_sizeof(Aml *arg);
 
 void
 build_header(GArray *linker, GArray *table_data,
-- 
1.8.3.1




[Qemu-devel] [PATCH v4 02/21] ide: Account for write operations correctly

2015-10-28 Thread Alberto Garcia
Signed-off-by: Alberto Garcia 
Reviewed-by: Stefan Hajnoczi 
---
 hw/ide/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 317406d..b559f1b 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -895,7 +895,7 @@ static void ide_sector_write(IDEState *s)
 qemu_iovec_init_external(>qiov, >iov, 1);
 
 block_acct_start(blk_get_stats(s->blk), >acct,
- n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
+ n * BDRV_SECTOR_SIZE, BLOCK_ACCT_WRITE);
 s->pio_aiocb = blk_aio_writev(s->blk, sector_num, >qiov, n,
   ide_sector_write_cb, s);
 }
-- 
2.6.1




Re: [Qemu-devel] [PATCH 06/17] qcow: add a 'keyid' parameter to qcow options

2015-10-28 Thread Eric Blake
On 10/19/2015 09:09 AM, Daniel P. Berrange wrote:
> Add a 'keyid' parameter that refers to the ID of a
> QCryptoSecret instance that provides the encryption key.
> eg
> 
>  $QEMU \
> -object secret,id=sec0,filename=/home/berrange/encrypted.pw \
> -drive file=/home/berrange/encrypted.qcow,keyid=sec0
> 
> Signed-off-by: Daniel P. Berrange 
> ---
>  block/qcow.c | 94 
> +++-
>  qapi/block-core.json | 17 +-
>  2 files changed, 87 insertions(+), 24 deletions(-)
> 

> +static QCryptoCipher *qcow_get_cipher_from_key(const char *key,
> +   Error **errp)
> +{
> +uint8_t keybuf[16];
> +int len, i;
> +
> +memset(keybuf, 0, 16);
> +len = strlen(key);
> +if (len > 16) {
> +len = 16;
> +}
> +/* XXX: we could compress the chars to 7 bits to increase
> +   entropy */
> +for (i = 0; i < len; i++) {
> +keybuf[i] = key[i];
> +}

Would memcpy() be more efficient?


> @@ -261,33 +331,11 @@ static int qcow_reopen_prepare(BDRVReopenState *state,
>  static int qcow_set_key(BlockDriverState *bs, const char *key)
>  {
>  BDRVQcowState *s = bs->opaque;
> -uint8_t keybuf[16];
> -int len, i;
> -Error *err;
>  
> -memset(keybuf, 0, 16);
> -len = strlen(key);
> -if (len > 16)
> -len = 16;
> -/* XXX: we could compress the chars to 7 bits to increase
> -   entropy */
> -for(i = 0;i < len;i++) {
> -keybuf[i] = key[i];
> -}

Oh, I see - code motion.

> +++ b/qapi/block-core.json
> @@ -1562,6 +1562,21 @@
>  'mode':  'Qcow2OverlapCheckMode' } }
>  
>  ##
> +# @BlockdevOptionsQcow
> +#
> +# Driver specific block device options for qcow.
> +#
> +# @keyid: #optional ID of the "secret" object providing the
> +# AES decryption key.
> +#

That's a lot of whitespace, but it doesn't hurt.

> +# Since: 2.5
> +##
> +{ 'struct': 'BlockdevOptionsQcow',
> +  'base': 'BlockdevOptionsGenericCOWFormat',
> +  'data': { '*keyid': 'str' } }

Interface looks fine.

Reviewed-by: Eric Blake 

-- 
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] vl.c: Replace fprintf(stderr) with error_report()

2015-10-28 Thread Andrew Jones
On Tue, Oct 27, 2015 at 08:36:07PM +0100, Laszlo Ersek wrote:
> On 10/27/15 20:25, Eduardo Habkost wrote:
> > On Tue, Oct 27, 2015 at 08:30:38AM +0100, Andrew Jones wrote:
> >> In addition to Markus' and Eric's comments, I think we should
> >>
> >> 1. make sure the first word's case is correct. Lowercase for phrases,
> >>uppercase for sentences and proper nouns.
> > 
> > I think I can understand this in the more obvious cases, but I don't
> > know how I could convert the following instance:
> > 
> > [...]
> >>>  case QEMU_OPTION_no_kvm_pit: {
> >>> -fprintf(stderr, "Warning: KVM PIT can no longer be 
> >>> disabled "
> >>> -"separately.\n");
> >>> +error_report("Warning: KVM PIT can no longer be disabled 
> >>> "
> >>> + "separately.");
> >>
> >> Could change this from a sentence into a phrase. Also, we need a consistent
> >> 'warning' prefix. Should we make a error_report_warn variant?
> > 
> > Converting that sentence to a phrase is beyond my non-native english
> > speaker skills. Do you have any suggestions? :)
> > 
> 
> easy-peasy, "KVM PIT no longer disableable separately"!
> 
> /me hides ;)
As well you should with a word like "disableable" :-)

How about

  Warning: ignoring deprecated option no-kvm-pit

drew

> 



[Qemu-devel] [PATCH v5 33/33] nvdimm: add maintain info

2015-10-28 Thread Xiao Guangrong
Add NVDIMM maintainer

Signed-off-by: Xiao Guangrong 
---
 MAINTAINERS | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9bd2b8f..a3c38cc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -868,6 +868,13 @@ M: Jiri Pirko 
 S: Maintained
 F: hw/net/rocker/
 
+NVDIMM
+M: Xiao Guangrong 
+S: Maintained
+F: hw/acpi/nvdimm.c
+F: hw/mem/nvdimm.c
+F: include/hw/mem/nvdimm.h
+
 Subsystems
 --
 Audio
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH for-2.5 0/2] trace: decrease overhead of simpletrace and stderr backends

2015-10-28 Thread Stefan Hajnoczi
On Wed, Oct 28, 2015 at 07:06:25AM +0100, Paolo Bonzini wrote:
> This patch series makes it faster for simpletrace and stderr backends
> to discard disabled events.  This is done in two ways: patch 1 makes
> the common case of no enabled events faster; patch 2 makes the other
> case less heavy on the data cache by packing the "tracepoint enabled"
> flag and avoiding useless pointer chasing.
> 
> This should decrease the impact of changing the default tracing backend
> to stderr aka log, which Peter suggested could be a problem.
> 
> Paolo
> 
> Paolo Bonzini (2):
>   trace: count number of enabled events
>   trace: track enabled events in a separate array
> 
>  scripts/tracetool/format/events_c.py |  2 +-
>  trace/control-internal.h | 15 ---
>  trace/control.c  |  3 +++
>  trace/control.h  |  2 +-
>  trace/event-internal.h   |  2 --
>  5 files changed, 17 insertions(+), 7 deletions(-)

Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v5 29/33] nvdimm acpi: support Get Namespace Label Data function

2015-10-28 Thread Xiao Guangrong
Function 5 is used to get Namespace Label Data

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/nvdimm.c | 48 
 1 file changed, 48 insertions(+)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 72203d2..5b621ed 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -428,6 +428,7 @@ struct nvdimm_dsm_in {
 union {
 uint8_t arg3[0];
 nvdimm_func_in_set_label_data func_set_label_data;
+nvdimm_func_in_get_label_data func_get_label_data;
 };
 } QEMU_PACKED;
 typedef struct nvdimm_dsm_in nvdimm_dsm_in;
@@ -527,6 +528,50 @@ static void nvdimm_dsm_func_label_size(NVDIMMDevice 
*nvdimm, GArray *out)
 g_array_append_vals(out, _label_size, sizeof(func_label_size));
 }
 
+/*
+ * DSM Spec Rev1 4.5 Get Namespace Label Data (Function Index 5).
+ */
+static void nvdimm_dsm_func_get_label_data(NVDIMMDevice *nvdimm,
+   nvdimm_dsm_in *in, GArray *out)
+{
+NVDIMMClass *nvc = NVDIMM_GET_CLASS(nvdimm);
+nvdimm_func_in_get_label_data *get_label_data = >func_get_label_data;
+void *buf;
+uint32_t status = NVDIMM_DSM_STATUS_SUCCESS;
+
+le32_to_cpus(_label_data->offset);
+le32_to_cpus(_label_data->length);
+
+nvdimm_debug("Read Label Data: offset %#x length %#x.\n",
+ get_label_data->offset, get_label_data->length);
+
+if (nvdimm->label_size < get_label_data->offset + get_label_data->length) {
+nvdimm_debug("position %#x is beyond label data (len = %#lx).\n",
+ get_label_data->offset + get_label_data->length,
+ nvdimm->label_size);
+status = NVDIMM_DSM_DEV_STATUS_INVALID_PARAS;
+goto exit;
+}
+
+if (get_label_data->length > nvdimm_get_max_xfer_label_size()) {
+nvdimm_debug("get length (%#x) is larger than max_xfer (%#x).\n",
+ get_label_data->length, nvdimm_get_max_xfer_label_size());
+status = NVDIMM_DSM_DEV_STATUS_INVALID_PARAS;
+goto exit;
+}
+
+/* write nvdimm_func_out_get_label_data.status. */
+nvdimm_dsm_write_status(out, status);
+/* write nvdimm_func_out_get_label_data.out_buf. */
+buf = acpi_data_push(out, get_label_data->length);
+nvc->read_label_data(nvdimm, buf, get_label_data->length,
+ get_label_data->offset);
+return;
+
+exit:
+nvdimm_dsm_write_status(out, status);
+}
+
 static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray *out)
 {
 GSList *list = nvdimm_get_plugged_device_list();
@@ -554,6 +599,9 @@ static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray 
*out)
 case 0x4 /* Get Namespace Label Size */:
 nvdimm_dsm_func_label_size(nvdimm, out);
 goto free;
+case 0x5 /* Get Namespace Label Data */:
+nvdimm_dsm_func_get_label_data(nvdimm, in, out);
+goto free;
 default:
 status = NVDIMM_DSM_STATUS_NOT_SUPPORTED;
 };
-- 
1.8.3.1




[Qemu-devel] [PATCH 3/4] io: add locking constraints check into bdrv_drain to ensure locking

2015-10-28 Thread Denis V. Lunev
as described in the comment of the function

Signed-off-by: Denis V. Lunev 
CC: Stefan Hajnoczi 
CC: Paolo Bonzini 
---
 block/io.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/block/io.c b/block/io.c
index 5ac6256..2e98d45 100644
--- a/block/io.c
+++ b/block/io.c
@@ -247,12 +247,15 @@ bool bdrv_requests_pending(BlockDriverState *bs)
 void bdrv_drain(BlockDriverState *bs)
 {
 bool busy = true;
+AioContext *aio_context = bdrv_get_aio_context(bs);
+
+assert(aio_context_is_locked(aio_context));
 
 while (busy) {
 /* Keep iterating */
  bdrv_flush_io_queue(bs);
  busy = bdrv_requests_pending(bs);
- busy |= aio_poll(bdrv_get_aio_context(bs), busy);
+ busy |= aio_poll(aio_context, busy);
 }
 }
 
-- 
2.1.4




[Qemu-devel] [PATCH v4 16/21] xen_disk: Account for failed and invalid operations

2015-10-28 Thread Alberto Garcia
Signed-off-by: Alberto Garcia 
---
 hw/block/xen_disk.c | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 4869518..02eda6e 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -537,7 +537,11 @@ static void qemu_aio_complete(void *opaque, int ret)
 break;
 }
 case BLKIF_OP_READ:
-block_acct_done(blk_get_stats(ioreq->blkdev->blk), >acct);
+if (ioreq->status == BLKIF_RSP_OKAY) {
+block_acct_done(blk_get_stats(ioreq->blkdev->blk), >acct);
+} else {
+block_acct_failed(blk_get_stats(ioreq->blkdev->blk), >acct);
+}
 break;
 case BLKIF_OP_DISCARD:
 default:
@@ -722,6 +726,23 @@ static void blk_handle_requests(struct XenBlkDev *blkdev)
 
 /* parse them */
 if (ioreq_parse(ioreq) != 0) {
+
+switch (ioreq->req.operation) {
+case BLKIF_OP_READ:
+block_acct_invalid(blk_get_stats(blkdev->blk),
+   BLOCK_ACCT_READ);
+break;
+case BLKIF_OP_WRITE:
+block_acct_invalid(blk_get_stats(blkdev->blk),
+   BLOCK_ACCT_WRITE);
+break;
+case BLKIF_OP_FLUSH_DISKCACHE:
+block_acct_invalid(blk_get_stats(blkdev->blk),
+   BLOCK_ACCT_FLUSH);
+default:
+break;
+};
+
 if (blk_send_response_one(ioreq)) {
 xen_be_send_notify(>xendev);
 }
-- 
2.6.1




Re: [Qemu-devel] [PULL v2 00/27] target-arm queue

2015-10-28 Thread Peter Maydell
On 27 October 2015 at 16:07, Peter Maydell  wrote:
> Version 2, with a fix for a 32-bit build failure squashed in.
>
> thanks
> -- PMM
>
>
>
> The following changes since commit 7e038b94e74e1c2d1b3598e2e4b0b5c8b79a7278:
>
>   Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into 
> staging (2015-10-27 10:10:46 +)
>
> are available in the git repository at:
>
>
>   git://git.linaro.org/people/pmaydell/qemu-arm.git 
> tags/pull-target-arm-20151027-1
>
> for you to fetch changes up to 9b539263faa5c1b7fce2551092b5c7b6eea92081:
>
>   target-arm: Add support for S1 + S2 MMU translations (2015-10-27 15:59:47 
> +)
>
> 
> target-arm queue:
>  * more EL2 preparation: handling for stage 2 translations
>  * standardize debug macros in i.MX devices
>  * improve error message in a corner case for virt board
>  * disable live migration of KVM GIC if the kernel can't handle it
>  * add SPSR_(ABT|UND|IRQ|FIQ) registers
>  * handle non-executable page-straddling Thumb instructions
>  * fix a "no 64-bit EL2" assumption in arm_excp_unmasked()
>
> 

Applied, thanks.

-- PMM



[Qemu-devel] [PULL 0/2] target-i386: Finally enable "check" mode by default

2015-10-28 Thread Eduardo Habkost
We now have fixed the issues that caused unnecessary warnings in TCG mode and
on "make check", and I am applying the check-mode patch again.

The following changes since commit 7e038b94e74e1c2d1b3598e2e4b0b5c8b79a7278:

  Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into 
staging (2015-10-27 10:10:46 +)

are available in the git repository at:

  git://github.com/ehabkost/qemu.git tags/x86-pull-request

for you to fetch changes up to 15e41345906d29a319cc9cdf566347bf79134d24:

  target-i386: Enable "check" mode by default (2015-10-27 16:12:15 -0200)


target-i386: finally enable "check" mode by default



Eduardo Habkost (2):
  target-i386: Don't left shift negative constant
  target-i386: Enable "check" mode by default

 target-i386/cpu.c   | 2 +-
 target-i386/translate.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.1.0




[Qemu-devel] [PATCH v5 31/33] nvdimm: allow using whole backend memory as pmem

2015-10-28 Thread Xiao Guangrong
Introduce a parameter, named "reserve-label-data", if it is
false which indicates that QEMU does not reserve any region
on the backend memory to support label data. It is a
'label-less' NVDIMM device mode that linux will use whole
memory on the device as a single namesapce

This is useful for the users who want to pass whole nvdimm
device and make its data completely be visible to guest

The parameter is false on default

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/nvdimm.c| 20 
 hw/mem/nvdimm.c | 37 -
 include/hw/mem/nvdimm.h |  6 ++
 3 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 5e72ca8..c5a50ea 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -545,6 +545,13 @@ static void nvdimm_dsm_func_get_label_data(NVDIMMDevice 
*nvdimm,
 nvdimm_debug("Read Label Data: offset %#x length %#x.\n",
  get_label_data->offset, get_label_data->length);
 
+if (!nvdimm->reserve_label_data) {
+nvdimm_debug("read label request on the device without "
+ "label data reserved.\n");
+status = NVDIMM_DSM_STATUS_NOT_SUPPORTED;
+goto exit;
+}
+
 if (nvdimm->label_size < get_label_data->offset + get_label_data->length) {
 nvdimm_debug("position %#x is beyond label data (len = %#lx).\n",
  get_label_data->offset + get_label_data->length,
@@ -588,6 +595,13 @@ static void nvdimm_dsm_func_set_label_data(NVDIMMDevice 
*nvdimm,
 nvdimm_debug("Write Label Data: offset %#x length %#x.\n",
  set_label_data->offset, set_label_data->length);
 
+if (!nvdimm->reserve_label_data) {
+nvdimm_debug("write label request on the device without "
+ "label data reserved.\n");
+status = NVDIMM_DSM_STATUS_NOT_SUPPORTED;
+goto exit;
+}
+
 if (nvdimm->label_size < set_label_data->offset + set_label_data->length) {
 nvdimm_debug("position %#x is beyond label data (len = %#lx).\n",
  set_label_data->offset + set_label_data->length,
@@ -632,6 +646,12 @@ static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray 
*out)
1 << 4 /* Get Namespace Label Size */ |
1 << 5 /* Get Namespace Label Data */ |
1 << 6 /* Set Namespace Label Data */);
+
+/* no function support if the device does not have label data. */
+if (!nvdimm->reserve_label_data) {
+cmd_list = cpu_to_le64(0);
+}
+
 build_append_int_noprefix(out, cmd_list, sizeof(cmd_list));
 goto free;
 case 0x4 /* Get Namespace Label Size */:
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index 825d664..27dbfbd 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -36,14 +36,15 @@ static void nvdimm_realize(DIMMDevice *dimm, Error **errp)
 {
 MemoryRegion *mr;
 NVDIMMDevice *nvdimm = NVDIMM(dimm);
-uint64_t size;
+uint64_t reserved_label_size, size;
 
 nvdimm->label_size = MIN_NAMESPACE_LABEL_SIZE;
+reserved_label_size = nvdimm->reserve_label_data ? nvdimm->label_size : 0;
 
 mr = host_memory_backend_get_memory(dimm->hostmem, errp);
 size = memory_region_size(mr);
 
-if (size <= nvdimm->label_size) {
+if (size <= reserved_label_size) {
 char *path = 
object_get_canonical_path_component(OBJECT(dimm->hostmem));
 error_setg(errp, "the size of memdev %s (0x%" PRIx64 ") is too small"
" to contain nvdimm namespace label (0x%" PRIx64 ")", path,
@@ -52,9 +53,12 @@ static void nvdimm_realize(DIMMDevice *dimm, Error **errp)
 }
 
 memory_region_init_alias(>nvdimm_mr, OBJECT(dimm), "nvdimm-memory",
- mr, 0, size - nvdimm->label_size);
-nvdimm->label_data = memory_region_get_ram_ptr(mr) +
- memory_region_size(>nvdimm_mr);
+ mr, 0, size - reserved_label_size);
+
+if (reserved_label_size) {
+nvdimm->label_data = memory_region_get_ram_ptr(mr) +
+ memory_region_size(>nvdimm_mr);
+}
 }
 
 static void nvdimm_read_label_data(NVDIMMDevice *nvdimm, void *buf,
@@ -97,10 +101,33 @@ static void nvdimm_class_init(ObjectClass *oc, void *data)
 nvc->write_label_data = nvdimm_write_label_data;
 }
 
+static bool nvdimm_get_reserve_label_data(Object *obj, Error **errp)
+{
+NVDIMMDevice *nvdimm = NVDIMM(obj);
+
+return nvdimm->reserve_label_data;
+}
+
+static void
+nvdimm_set_reserve_label_data(Object *obj, bool value, Error **errp)
+{
+NVDIMMDevice *nvdimm = NVDIMM(obj);
+
+nvdimm->reserve_label_data = value;
+}
+
+static void nvdimm_init(Object *obj)
+{
+object_property_add_bool(obj, "reserve-label-data",
+ nvdimm_get_reserve_label_data,
+ 

[Qemu-devel] [PATCH 1/2] trace: fix make foo-timestamp rules

2015-10-28 Thread Stefan Hajnoczi
The Makefile uses intermediate timestamp files to avoid rebuilding if
tracetool output is unchanged.

Timestamps are implemented incorrectly.  This was fixed for rules.mak in
commit 4b25966ab976f3a7fd9008193b2defcc82f8f04d ("rules.mak: cleanup
config generation rules") but never fixed in trace/Makefile.objs.

The problem with the old timestamp implementation was that make doesn't
notice the updated file modification time until the next time it is run.
It was necessary to run make twice in a row to achieve a full rebuild.

Signed-off-by: Stefan Hajnoczi 
---
 trace/Makefile.objs | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/trace/Makefile.objs b/trace/Makefile.objs
index 32f7a32..73bec38 100644
--- a/trace/Makefile.objs
+++ b/trace/Makefile.objs
@@ -5,20 +5,20 @@
 
 ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust)
 $(obj)/generated-ust-provider.h: $(obj)/generated-ust-provider.h-timestamp
+   @cmp $< $@ >/dev/null 2>&1 || cp $< $@
 $(obj)/generated-ust-provider.h-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=ust-events-h \
--backends=$(TRACE_BACKENDS) \
< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
-   @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst 
%-timestamp,%,$@)
 
 $(obj)/generated-ust.c: $(obj)/generated-ust.c-timestamp 
$(BUILD_DIR)/config-host.mak
+   @cmp $< $@ >/dev/null 2>&1 || cp $< $@
 $(obj)/generated-ust.c-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=ust-events-c \
--backends=$(TRACE_BACKENDS) \
< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
-   @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst 
%-timestamp,%,$@)
 
 $(obj)/generated-events.h: $(obj)/generated-ust-provider.h
 $(obj)/generated-events.c: $(obj)/generated-ust.c
@@ -28,20 +28,20 @@ endif
 # Auto-generated event descriptions
 
 $(obj)/generated-events.h: $(obj)/generated-events.h-timestamp
+   @cmp $< $@ >/dev/null 2>&1 || cp $< $@
 $(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=events-h \
--backends=$(TRACE_BACKENDS) \
< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
-   @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst 
%-timestamp,%,$@)
 
 $(obj)/generated-events.c: $(obj)/generated-events.c-timestamp 
$(BUILD_DIR)/config-host.mak
+   @cmp $< $@ >/dev/null 2>&1 || cp $< $@
 $(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=events-c \
--backends=$(TRACE_BACKENDS) \
< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
-   @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst 
%-timestamp,%,$@)
 
 util-obj-y += generated-events.o
 
@@ -81,12 +81,12 @@ $(obj)/generated-tracers.o: $(obj)/generated-tracers.c 
$(obj)/generated-tracers.
 # rule file. So we use '.dtrace' instead
 ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace)
 $(obj)/generated-tracers-dtrace.dtrace: 
$(obj)/generated-tracers-dtrace.dtrace-timestamp
+   @cmp $< $@ >/dev/null 2>&1 || cp $< $@
 $(obj)/generated-tracers-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
$(call quiet-command,$(TRACETOOL) \
--format=d \
--backends=$(TRACE_BACKENDS) \
< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
-   @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst 
%-timestamp,%,$@)
 
 $(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers-dtrace.dtrace
$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   $@")
@@ -100,28 +100,28 @@ endif
 # Translation level
 
 $(obj)/generated-helpers-wrappers.h: 
$(obj)/generated-helpers-wrappers.h-timestamp
+   @cmp $< $@ >/dev/null 2>&1 || cp $< $@
 $(obj)/generated-helpers-wrappers.h-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
$(call quiet-command,$(TRACETOOL) \
--format=tcg-helper-wrapper-h \
--backend=$(TRACE_BACKENDS) \
< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
-   @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst 
%-timestamp,%,$@)
 
 $(obj)/generated-helpers.h: $(obj)/generated-helpers.h-timestamp
+   @cmp $< $@ >/dev/null 2>&1 || cp $< $@
 $(obj)/generated-helpers.h-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
$(call quiet-command,$(TRACETOOL) \
--format=tcg-helper-h \
--backend=$(TRACE_BACKENDS) \
< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
-   @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst 
%-timestamp,%,$@)
 
 $(obj)/generated-helpers.c: $(obj)/generated-helpers.c-timestamp
+ 

[Qemu-devel] [PATCH 2/2] trace: add make dependencies on tracetool source

2015-10-28 Thread Stefan Hajnoczi
Patches that change tracetool can break the build if old build output
files are lying around.

This happens because the Makefile does not specify dependencies on
tracetool.  The build will use old object files that do not match the
current source code.

Signed-off-by: Stefan Hajnoczi 
---
 trace/Makefile.objs | 32 +---
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/trace/Makefile.objs b/trace/Makefile.objs
index 73bec38..ed2ca38 100644
--- a/trace/Makefile.objs
+++ b/trace/Makefile.objs
@@ -1,12 +1,22 @@
 # -*- mode: makefile -*-
 
 ##
+# tracetool source files
+# Every rule that invokes tracetool must depend on this so code is regenerated
+# if tracetool itself changes.
+
+tracetool-y = $(SRC_PATH)/scripts/tracetool.py
+tracetool-y += $(SRC_PATH)/scripts/tracetool/*.py
+tracetool-y += $(SRC_PATH)/scripts/tracetool/backend/*.py
+tracetool-y += $(SRC_PATH)/scripts/tracetool/format/*.py
+
+##
 # Auto-generated event descriptions for LTTng ust code
 
 ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust)
 $(obj)/generated-ust-provider.h: $(obj)/generated-ust-provider.h-timestamp
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
-$(obj)/generated-ust-provider.h-timestamp: $(SRC_PATH)/trace-events
+$(obj)/generated-ust-provider.h-timestamp: $(SRC_PATH)/trace-events 
$(tracetool-y)
$(call quiet-command,$(TRACETOOL) \
--format=ust-events-h \
--backends=$(TRACE_BACKENDS) \
@@ -14,7 +24,7 @@ $(obj)/generated-ust-provider.h-timestamp: 
$(SRC_PATH)/trace-events
 
 $(obj)/generated-ust.c: $(obj)/generated-ust.c-timestamp 
$(BUILD_DIR)/config-host.mak
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
-$(obj)/generated-ust.c-timestamp: $(SRC_PATH)/trace-events
+$(obj)/generated-ust.c-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
$(call quiet-command,$(TRACETOOL) \
--format=ust-events-c \
--backends=$(TRACE_BACKENDS) \
@@ -29,7 +39,7 @@ endif
 
 $(obj)/generated-events.h: $(obj)/generated-events.h-timestamp
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
-$(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events
+$(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
$(call quiet-command,$(TRACETOOL) \
--format=events-h \
--backends=$(TRACE_BACKENDS) \
@@ -37,7 +47,7 @@ $(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events
 
 $(obj)/generated-events.c: $(obj)/generated-events.c-timestamp 
$(BUILD_DIR)/config-host.mak
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
-$(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events
+$(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
$(call quiet-command,$(TRACETOOL) \
--format=events-c \
--backends=$(TRACE_BACKENDS) \
@@ -54,7 +64,7 @@ util-obj-y += generated-events.o
 
 $(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp
@cmp -s $< $@ || cp $< $@
-$(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
+$(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak $(tracetool-y)
$(call quiet-command,$(TRACETOOL) \
--format=h \
--backends=$(TRACE_BACKENDS) \
@@ -65,7 +75,7 @@ $(obj)/generated-tracers.h-timestamp: 
$(SRC_PATH)/trace-events $(BUILD_DIR)/conf
 
 $(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp
@cmp -s $< $@ || cp $< $@
-$(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
+$(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak $(tracetool-y)
$(call quiet-command,$(TRACETOOL) \
--format=c \
--backends=$(TRACE_BACKENDS) \
@@ -82,7 +92,7 @@ $(obj)/generated-tracers.o: $(obj)/generated-tracers.c 
$(obj)/generated-tracers.
 ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace)
 $(obj)/generated-tracers-dtrace.dtrace: 
$(obj)/generated-tracers-dtrace.dtrace-timestamp
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
-$(obj)/generated-tracers-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
+$(obj)/generated-tracers-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak $(tracetool-y)
$(call quiet-command,$(TRACETOOL) \
--format=d \
--backends=$(TRACE_BACKENDS) \
@@ -101,7 +111,7 @@ endif
 
 $(obj)/generated-helpers-wrappers.h: 
$(obj)/generated-helpers-wrappers.h-timestamp
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
-$(obj)/generated-helpers-wrappers.h-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
+$(obj)/generated-helpers-wrappers.h-timestamp: $(SRC_PATH)/trace-events 

Re: [Qemu-devel] [PATCH 07/17] qcow2: add a 'keyid' parameter to qcow2 options

2015-10-28 Thread Eric Blake
On 10/19/2015 05:29 PM, Eric Blake wrote:
> On 10/19/2015 09:09 AM, Daniel P. Berrange wrote:
>> Add a 'keyid' parameter that refers to the ID of a
>> QCryptoSecret instance that provides the encryption key.
>>
>> $QEMU \
>> -object secret,id=sec0,filename=/home/berrange/encrypted.pw \
>> -drive file=/home/berrange/encrypted.qcow2,keyid=sec0
>>
>> Signed-off-by: Daniel P. Berrange 
>> ---
>>  block/qcow2.c| 80 
>> +---
>>  block/qcow2.h|  1 +
>>  qapi/block-core.json |  8 --
>>  3 files changed, 64 insertions(+), 25 deletions(-)
>>
> 
>> +++ b/qapi/block-core.json
>> @@ -1567,7 +1567,7 @@
>>  # Driver specific block device options for qcow.
>>  #
>>  # @keyid: #optional ID of the "secret" object providing the
>> -# AES decryption key.
>> +# AES decryption key (since 2.5)
> 
> Looks like this line...
> 
>>  #
>>  # Since: 2.5
>>  ##
>> @@ -1611,6 +1611,9 @@
>>  # caches. The interval is in seconds. The default 
>> value
>>  # is 0 and it disables this feature (since 2.5)
>>  #
>> +# @keyid: #optional ID of the "secret" object providing the
>> +# AES decryption key.
> 
> ...and this line should be swapped.
> 

Also, do you want to change BlockdevOptionsQcow2 to have a base class of
BlockdevOptionsQcow, and get keyid by inheritance rather than by direct
declaration?  Doesn't matter in the long run (once my qapi patches land
that provide the information without going through an extra 'base->' layer).

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v5 22/33] docs: add NVDIMM ACPI documentation

2015-10-28 Thread Xiao Guangrong
It describes the basic concepts of NVDIMM ACPI and the interface
between QEMU and the ACPI BIOS

Signed-off-by: Xiao Guangrong 
---
 docs/specs/acpi_nvdimm.txt | 179 +
 1 file changed, 179 insertions(+)
 create mode 100644 docs/specs/acpi_nvdimm.txt

diff --git a/docs/specs/acpi_nvdimm.txt b/docs/specs/acpi_nvdimm.txt
new file mode 100644
index 000..cc5db2c
--- /dev/null
+++ b/docs/specs/acpi_nvdimm.txt
@@ -0,0 +1,179 @@
+QEMU<->ACPI BIOS NVDIMM interface
+-
+
+QEMU supports NVDIMM via ACPI. This document describes the basic concepts of
+NVDIMM ACPI and the interface between QEMU and the ACPI BIOS.
+
+NVDIMM ACPI Background
+--
+NVDIMM is introduced in ACPI 6.0 which defines an NVDIMM root device under
+_SB scope with a _HID of “ACPI0012”. For each NVDIMM present or intended
+to be supported by platform, platform firmware also exposes an ACPI
+Namespace Device under the root device.
+
+The NVDIMM child devices under the NVDIMM root device are defined with _ADR
+corresponding to the NFIT device handle. The NVDIMM root device and the
+NVDIMM devices can have device specific methods (_DSM) to provide additional
+functions specific to a particular NVDIMM implementation.
+
+This is an example from ACPI 6.0, a platform contains one NVDIMM:
+
+Scope (\_SB){
+   Device (NVDR) // Root device
+   {
+  Name (_HID, “ACPI0012”)
+  Method (_STA) {...}
+  Method (_FIT) {...}
+  Method (_DSM, ...) {...}
+  Device (NVD)
+  {
+ Name(_ADR, h) //where h is NFIT Device Handle for this NVDIMM
+ Method (_DSM, ...) {...}
+  }
+   }
+}
+
+Methods supported on both NVDIMM root device and NVDIMM device are
+1) _STA(Status)
+   It returns the current status of a device, which can be one of the
+   following: enabled, disabled, or removed.
+
+   Arguments: None
+
+   Return Value:
+   It returns an An Integer which is defined as followings:
+   Bit [0] – Set if the device is present.
+   Bit [1] – Set if the device is enabled and decoding its resources.
+   Bit [2] – Set if the device should be shown in the UI.
+   Bit [3] – Set if the device is functioning properly (cleared if device
+ failed its diagnostics).
+   Bit [4] – Set if the battery is present.
+   Bits [31:5] – Reserved (must be cleared).
+
+2) _DSM (Device Specific Method)
+   It is a control method that enables devices to provide device specific
+   control functions that are consumed by the device driver.
+   The NVDIMM DSM specification can be found at:
+http://pmem.io/documents/NVDIMM_DSM_Interface_Example.pdf
+
+   Arguments:
+   Arg0 – A Buffer containing a UUID (16 Bytes)
+   Arg1 – An Integer containing the Revision ID (4 Bytes)
+   Arg2 – An Integer containing the Function Index (4 Bytes)
+   Arg3 – A package containing parameters for the function specified by the
+  UUID, Revision ID, and Function Index
+
+   Return Value:
+   If Function Index = 0, a Buffer containing a function index bitfield.
+   Otherwise, the return value and type depends on the UUID, revision ID
+   and function index which are described in the DSM specification.
+
+Methods on NVDIMM ROOT Device
+_FIT(Firmware Interface Table)
+   It evaluates to a buffer returning data in the format of a series of NFIT
+   Type Structure.
+
+   Arguments: None
+
+   Return Value:
+   A Buffer containing a list of NFIT Type structure entries.
+
+   The detailed definition of the structure can be found at ACPI 6.0: 5.2.25
+   NVDIMM Firmware Interface Table (NFIT).
+
+QEMU NVDIMM Implemention
+
+QEMU reserves a page starting from 0xFF0 and 4 bytes IO Port starting
+from 0x0a18 for NVDIMM ACPI.
+
+Memory 0xFF0 - 0xFF00FFF:
+   This page is RAM-based and it is used to transfer data between _DSM
+   method and QEMU. If ACPI has control, this pages is owned by ACPI which
+   writes _DSM input data to it, otherwise, it is owned by QEMU which
+   emulates _DSM access and writes the output data to it.
+
+   ACPI Writes _DSM Input Data:
+   [0xFF0 - 0xFF3]: 4 bytes, NVDIMM Devcie Handle, 0 is reserved
+for NVDIMM Root device.
+   [0xFF4 - 0xFF7]: 4 bytes, Revision ID, that is the Arg1 of _DSM
+method.
+   [0xFF8 - 0xFFB]: 4 bytes. Function Index, that is the Arg2 of
+_DSM method.
+   [0xFFC - 0xFF00FFF]: 4084 bytes, the Arg3 of _DSM method
+
+   QEMU Writes Output Data:
+   [0xFF0 - 0xFF00FFF]: the DSM return result filled by QEMU
+
+IO Port 0x0a18 - 0xa1b:
+   ACPI uses it to transfer control from guest to QEMU and read the size
+   of return result filled by QEMU
+
+   Read Access:
+   [0x0a18 - 0xa1b]: 4 bytes, the buffer size of _DSM output data.
+
+_DSM process diagram:
+-
+The page, 0xFF0 - 0xFF00FFF, is used by _DSM Virtualization.
+

[Qemu-devel] [PATCH v5 10/33] hostmem-file: clean up memory allocation

2015-10-28 Thread Xiao Guangrong
- hostmem-file.c is compiled only if CONFIG_LINUX is enabled so that is
  unnecessary to do the same check in the source file

- the interface, HostMemoryBackendClass->alloc(), is not called many
  times, do not need to check if the memory-region is initialized

Signed-off-by: Xiao Guangrong 
---
 backends/hostmem-file.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index e9b6d21..9097a57 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -46,17 +46,12 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error 
**errp)
 error_setg(errp, "mem-path property not set");
 return;
 }
-#ifndef CONFIG_LINUX
-error_setg(errp, "-mem-path not supported on this host");
-#else
-if (!memory_region_size(>mr)) {
-backend->force_prealloc = mem_prealloc;
-memory_region_init_ram_from_file(>mr, OBJECT(backend),
+
+backend->force_prealloc = mem_prealloc;
+memory_region_init_ram_from_file(>mr, OBJECT(backend),
  object_get_canonical_path(OBJECT(backend)),
  backend->size, fb->share,
  fb->mem_path, errp);
-}
-#endif
 }
 
 static void
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 03/33] acpi: add aml_create_field

2015-10-28 Thread Xiao Guangrong
Implement CreateField term which is used by NVDIMM _DSM method in later patch

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/aml-build.c | 13 +
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index a72214d..9fe5e7b 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1151,6 +1151,19 @@ Aml *aml_sizeof(Aml *arg)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefCreateField */
+Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name)
+{
+Aml *var = aml_alloc();
+build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */
+build_append_byte(var->buf, 0x13); /* CreateFieldOp */
+aml_append(var, srcbuf);
+aml_append(var, index);
+aml_append(var, len);
+build_append_namestring(var->buf, "%s", name);
+return var;
+}
+
 void
 build_header(GArray *linker, GArray *table_data,
  AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 7296efb..7e1c43b 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -276,6 +276,7 @@ Aml *aml_touuid(const char *uuid);
 Aml *aml_unicode(const char *str);
 Aml *aml_derefof(Aml *arg);
 Aml *aml_sizeof(Aml *arg);
+Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name);
 
 void
 build_header(GArray *linker, GArray *table_data,
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 15/33] stubs: rename qmp_pc_dimm_device_list.c

2015-10-28 Thread Xiao Guangrong
Rename qmp_pc_dimm_device_list.c to qmp_dimm_device_list.c

Signed-off-by: Xiao Guangrong 
---
 stubs/Makefile.objs | 2 +-
 stubs/{qmp_pc_dimm_device_list.c => qmp_dimm_device_list.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename stubs/{qmp_pc_dimm_device_list.c => qmp_dimm_device_list.c} (100%)

diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index ce6ce11..e28af50 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -37,6 +37,6 @@ stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
 stub-obj-y += cpus.o
 stub-obj-y += kvm.o
-stub-obj-y += qmp_pc_dimm_device_list.o
+stub-obj-y += qmp_dimm_device_list.o
 stub-obj-y += target-monitor-defs.o
 stub-obj-y += vhost.o
diff --git a/stubs/qmp_pc_dimm_device_list.c b/stubs/qmp_dimm_device_list.c
similarity index 100%
rename from stubs/qmp_pc_dimm_device_list.c
rename to stubs/qmp_dimm_device_list.c
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 24/33] nvdimm acpi: build ACPI NFIT table

2015-10-28 Thread Xiao Guangrong
NFIT is defined in ACPI 6.0: 5.2.25 NVDIMM Firmware Interface Table (NFIT)

Currently, we only support PMEM mode. Each device has 3 structures:
- SPA structure, defines the PMEM region info

- MEM DEV structure, it has the @handle which is used to associate specified
  ACPI NVDIMM  device we will introduce in later patch.
  Also we can happily ignored the memory device's interleave, the real
  nvdimm hardware access is hidden behind host

- DCR structure, it defines vendor ID used to associate specified vendor
  nvdimm driver. Since we only implement PMEM mode this time, Command
  window and Data window are not needed

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/nvdimm.c| 355 
 hw/i386/acpi-build.c|   6 +
 include/hw/mem/nvdimm.h |  10 ++
 3 files changed, 371 insertions(+)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 647a5dd..3fc82e1 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -26,8 +26,348 @@
  * License along with this library; if not, see 
  */
 
+#include "hw/acpi/acpi.h"
+#include "hw/acpi/aml-build.h"
 #include "hw/mem/nvdimm.h"
 
+static int nvdimm_plugged_device_list(Object *obj, void *opaque)
+{
+GSList **list = opaque;
+
+if (object_dynamic_cast(obj, TYPE_NVDIMM)) {
+NVDIMMDevice *nvdimm = NVDIMM(obj);
+
+if (memory_region_is_mapped(>nvdimm_mr)) {
+*list = g_slist_append(*list, DEVICE(obj));
+}
+}
+
+object_child_foreach(obj, nvdimm_plugged_device_list, opaque);
+return 0;
+}
+
+/*
+ * inquire plugged NVDIMM devices and link them into the list which is
+ * returned to the caller.
+ *
+ * Note: it is the caller's responsibility to free the list to avoid
+ * memory leak.
+ */
+static GSList *nvdimm_get_plugged_device_list(void)
+{
+GSList *list = NULL;
+
+object_child_foreach(qdev_get_machine(), nvdimm_plugged_device_list,
+ );
+return list;
+}
+
+#define NVDIMM_UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
+   { (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
+ (b) & 0xff, ((b) >> 8) & 0xff, (c) & 0xff, ((c) >> 8) & 0xff,  \
+ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }
+/*
+ * define Byte Addressable Persistent Memory (PM) Region according to
+ * ACPI 6.0: 5.2.25.1 System Physical Address Range Structure.
+ */
+static const uint8_t nvdimm_nfit_spa_uuid_pm[] =
+  NVDIMM_UUID_LE(0x66f0d379, 0xb4f3, 0x4074, 0xac, 0x43, 0x0d, 0x33,
+ 0x18, 0xb7, 0x8c, 0xdb);
+
+/*
+ * NVDIMM Firmware Interface Table
+ * @signature: "NFIT"
+ *
+ * It provides information that allows OSPM to enumerate NVDIMM present in
+ * the platform and associate system physical address ranges created by the
+ * NVDIMMs.
+ *
+ * It is defined in ACPI 6.0: 5.2.25 NVDIMM Firmware Interface Table (NFIT)
+ */
+struct nvdimm_nfit {
+ACPI_TABLE_HEADER_DEF
+uint32_t reserved;
+} QEMU_PACKED;
+typedef struct nvdimm_nfit nvdimm_nfit;
+
+/*
+ * define NFIT structures according to ACPI 6.0: 5.2.25 NVDIMM Firmware
+ * Interface Table (NFIT).
+ */
+
+/*
+ * System Physical Address Range Structure
+ *
+ * It describes the system physical address ranges occupied by NVDIMMs and
+ * the types of the regions.
+ */
+struct nvdimm_nfit_spa {
+uint16_t type;
+uint16_t length;
+uint16_t spa_index;
+uint16_t flags;
+uint32_t reserved;
+uint32_t proximity_domain;
+uint8_t type_guid[16];
+uint64_t spa_base;
+uint64_t spa_length;
+uint64_t mem_attr;
+} QEMU_PACKED;
+typedef struct nvdimm_nfit_spa nvdimm_nfit_spa;
+
+/*
+ * Memory Device to System Physical Address Range Mapping Structure
+ *
+ * It enables identifying each NVDIMM region and the corresponding SPA
+ * describing the memory interleave
+ */
+struct nvdimm_nfit_memdev {
+uint16_t type;
+uint16_t length;
+uint32_t nfit_handle;
+uint16_t phys_id;
+uint16_t region_id;
+uint16_t spa_index;
+uint16_t dcr_index;
+uint64_t region_len;
+uint64_t region_offset;
+uint64_t region_dpa;
+uint16_t interleave_index;
+uint16_t interleave_ways;
+uint16_t flags;
+uint16_t reserved;
+} QEMU_PACKED;
+typedef struct nvdimm_nfit_memdev nvdimm_nfit_memdev;
+
+/*
+ * NVDIMM Control Region Structure
+ *
+ * It describes the NVDIMM and if applicable, Block Control Window.
+ */
+struct nvdimm_nfit_dcr {
+uint16_t type;
+uint16_t length;
+uint16_t dcr_index;
+uint16_t vendor_id;
+uint16_t device_id;
+uint16_t revision_id;
+uint16_t sub_vendor_id;
+uint16_t sub_device_id;
+uint16_t sub_revision_id;
+uint8_t reserved[6];
+uint32_t serial_number;
+uint16_t fic;
+uint16_t num_bcw;
+uint64_t bcw_size;
+uint64_t cmd_offset;
+uint64_t cmd_size;
+uint64_t status_offset;
+uint64_t status_size;
+uint16_t flags;
+uint8_t reserved2[6];

[Qemu-devel] [PATCH v5 27/33] nvdimm acpi: support function 0

2015-10-28 Thread Xiao Guangrong
__DSM is defined in ACPI 6.0: 9.14.1 _DSM (Device Specific Method)

Function 0 is a query function. We do not support any function on root
device and only 3 functions are support for NVDIMM device, Get Namespace
Label Size, Get Namespace Label Data and Set Namespace Label Data, that
means we currently only allow to access device's Label Namespace

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/aml-build.c |   2 +-
 hw/acpi/nvdimm.c| 156 +++-
 include/hw/acpi/aml-build.h |   1 +
 3 files changed, 157 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 8bee8b2..90229c5 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -231,7 +231,7 @@ static void build_extop_package(GArray *package, uint8_t op)
 build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
 }
 
-static void build_append_int_noprefix(GArray *table, uint64_t value, int size)
+void build_append_int_noprefix(GArray *table, uint64_t value, int size)
 {
 int i;
 
diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 69de4f6..8efa640 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -212,6 +212,22 @@ static uint32_t nvdimm_slot_to_dcr_index(int slot)
 return nvdimm_slot_to_spa_index(slot) + 1;
 }
 
+static NVDIMMDevice
+*nvdimm_get_device_by_handle(GSList *list, uint32_t handle)
+{
+for (; list; list = list->next) {
+NVDIMMDevice *nvdimm = list->data;
+int slot = object_property_get_int(OBJECT(nvdimm), DIMM_SLOT_PROP,
+   NULL);
+
+if (nvdimm_slot_to_handle(slot) == handle) {
+return nvdimm;
+}
+}
+
+return NULL;
+}
+
 /* ACPI 6.0: 5.2.25.1 System Physical Address Range Structure */
 static void
 nvdimm_build_structure_spa(GArray *structures, NVDIMMDevice *nvdimm)
@@ -368,6 +384,29 @@ static void nvdimm_build_nfit(GSList *device_list, GArray 
*table_offsets,
 g_array_free(structures, true);
 }
 
+/* define NVDIMM DSM return status codes according to DSM Spec Rev1. */
+enum {
+/* Common return status codes. */
+/* Success */
+NVDIMM_DSM_STATUS_SUCCESS = 0,
+/* Not Supported */
+NVDIMM_DSM_STATUS_NOT_SUPPORTED = 1,
+
+/* NVDIMM Root Device _DSM function return status codes*/
+/* Invalid Input Parameters */
+NVDIMM_DSM_ROOT_DEV_STATUS_INVALID_PARAS = 2,
+/* Function-Specific Error */
+NVDIMM_DSM_ROOT_DEV_STATUS_FUNCTION_SPECIFIC_ERROR = 3,
+
+/* NVDIMM Device (non-root) _DSM function return status codes*/
+/* Non-Existing Memory Device */
+NVDIMM_DSM_DEV_STATUS_NON_EXISTING_MEM_DEV = 2,
+/* Invalid Input Parameters */
+NVDIMM_DSM_DEV_STATUS_INVALID_PARAS = 3,
+/* Vendor Specific Error */
+NVDIMM_DSM_DEV_STATUS_VENDOR_SPECIFIC_ERROR = 4,
+};
+
 struct nvdimm_dsm_in {
 uint32_t handle;
 uint32_t revision;
@@ -377,10 +416,125 @@ struct nvdimm_dsm_in {
 } QEMU_PACKED;
 typedef struct nvdimm_dsm_in nvdimm_dsm_in;
 
+static void nvdimm_dsm_write_status(GArray *out, uint32_t status)
+{
+status = cpu_to_le32(status);
+build_append_int_noprefix(out, status, sizeof(status));
+}
+
+static void nvdimm_dsm_root(nvdimm_dsm_in *in, GArray *out)
+{
+uint32_t status = NVDIMM_DSM_STATUS_NOT_SUPPORTED;
+
+/*
+ * Query command implemented per ACPI Specification, it is defined in
+ * ACPI 6.0: 9.14.1 _DSM (Device Specific Method).
+ */
+if (in->function == 0x0) {
+/*
+ * Set it to zero to indicate no function is supported for NVDIMM
+ * root.
+ */
+uint64_t cmd_list = cpu_to_le64(0);
+
+build_append_int_noprefix(out, cmd_list, sizeof(cmd_list));
+return;
+}
+
+nvdimm_debug("Return status %#x.\n", status);
+nvdimm_dsm_write_status(out, status);
+}
+
+static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray *out)
+{
+GSList *list = nvdimm_get_plugged_device_list();
+NVDIMMDevice *nvdimm = nvdimm_get_device_by_handle(list, in->handle);
+uint32_t status = NVDIMM_DSM_DEV_STATUS_NON_EXISTING_MEM_DEV;
+uint64_t cmd_list;
+
+if (!nvdimm) {
+goto set_status_free;
+}
+
+/* Encode DSM function according to DSM Spec Rev1. */
+switch (in->function) {
+/* see comments in nvdimm_dsm_root(). */
+case 0x0:
+cmd_list = cpu_to_le64(0x1 /* Bit 0 indicates whether there is
+  support for any functions other
+  than function 0.
+*/   |
+   1 << 4 /* Get Namespace Label Size */ |
+   1 << 5 /* Get Namespace Label Data */ |
+   1 << 6 /* Set Namespace Label Data */);
+build_append_int_noprefix(out, cmd_list, sizeof(cmd_list));
+goto free;
+default:
+status = 

[Qemu-devel] [PATCH v5 12/33] pc-dimm: remove DEFAULT_PC_DIMMSIZE

2015-10-28 Thread Xiao Guangrong
It's not used any more

Signed-off-by: Xiao Guangrong 
---
 include/hw/mem/pc-dimm.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index c1ee7b0..15590f1 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -20,8 +20,6 @@
 #include "sysemu/hostmem.h"
 #include "hw/qdev.h"
 
-#define DEFAULT_PC_DIMMSIZE (1024*1024*1024)
-
 #define TYPE_PC_DIMM "pc-dimm"
 #define PC_DIMM(obj) \
 OBJECT_CHECK(PCDIMMDevice, (obj), TYPE_PC_DIMM)
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH 3/3] qga: set file descriptor in qmp_guest_file_open non-blocking on Win32

2015-10-28 Thread Denis V. Lunev

On 10/27/2015 10:49 PM, Michael Roth wrote:

Quoting Denis V. Lunev (2015-10-27 14:13:57)

On 10/27/2015 10:11 PM, Michael Roth wrote:

Quoting Denis V. Lunev (2015-10-27 12:48:43)

From: Olga Krishtal 

Set fd non-blocking to avoid common use cases (like reading from a
named pipe) from hanging the agent. This was missed in the original
code.

The patch introduces analog of qemu_set_non/block for HANDLES.
The usage of handles in qemu_set_non/block is impossible, because for
win32 there is a difference between file discriptors and file handles,
and all file ops are made via Win32 api.

If this is specific to HANDLEs, why do we need to cast back and forth
between int64_t and HANDLE? I haven't build tested, but it seems like
this would break for 32-bit mingw builds.

I would define these as qemu_set_*_by_handle(HANDLE fh, ...) instead
and make them win32 only. If someone wants to introduce a FILE*
variant for posix they can introduce it as
qemu_set_*_by_handle(FILE *fh, ...) rather than us needing to
abstract away the handle type.

may be it would be better to add static function for this in QGA for now?

I'd be fine with either approach. It could be generally useful for
other w32 users. But if we're thinking about dropping the QGA
use case soon then maybe having it live in QGA is best.


I am eager to drop this code at once for Posix and Windows and
switch to GLIB like was done for guest exec.

You mean switching all the guest-file-* interfaces to glib? I
took a stab at it once for w32 guest-file-* implementation, but
one issue I hit was that I couldn't figure out how to implement
guest-file-seek to report back the absolute position in the
file, or whether or not we'd hit EOF. You can set position
via g_io_channel_seek_position(), but if they hit EOF, or are
using relative offsets via G_SEEK_CUR, you don't really know
the position and glib doesn't seem to provide a way to query
that. We could maybe work around it by tracking it manually
via guest-file-* calls but that sounds terrible.

Hopefully I just missed something though. Also couldn't figure
out how you can get glib to report that you'd already seeked
to EOF. I had some comments about it in my WIP:

https://github.com/mdroth/qemu/commit/8b2e5c69266bb48e492af9826122c2aaa4a82197#diff-7f29c3e51a7b387cc7717e7be4f6e205R525


I see. Then we can have platform specific open code and use FILE*
interface for the rest. According to Olga HANDLE -> fd -> FILE*
transition is possible.

At least we will try :)

Den



[Qemu-devel] [PATCH v3 2/6] e1000: Trivial implementation of various MAC registers

2015-10-28 Thread Leonid Bloch
These registers appear in Intel's specs, but were not implemented.
These registers are now implemented trivially, i.e. they are initiated
with zero values, and if they are RW, they can be written or read by the
driver, or read only if they are R (essentially retaining their zero
values). For these registers no other procedures are performed.

For the trivially implemented Diagnostic registers, a debug warning is
produced on read/write attempts.

The registers implemented here are:

Transmit:
RW: AIT

Management:
RW: WUC WUS IPAVIP6AT*  IP4AT*  FFLT*   WUPM*   FFMT*   FFVT*

Diagnostic:
RW: RDFHRDFTRDFHS   RDFTS   RDFPC   PBM*TDFHTDFTTDFHS
TDFTS   TDFPC

Statistic:
RW: FCRUC
R:  RNBCTSCTFC  MGTPRC  MGTPDC  MGTPTC  RFC RJC SCC ECOL
LATECOL MCC COLCDC  TNCRS   SEC CEXTERR RLECXONRXC
XONTXC  XOFFRXC XOFFTXC

Signed-off-by: Leonid Bloch 
Signed-off-by: Dmitry Fleytman 
---
 hw/net/e1000.c  | 154 +++-
 hw/net/e1000_regs.h |   6 ++
 2 files changed, 157 insertions(+), 3 deletions(-)

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index 232edf1..fa65e79 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -168,7 +168,17 @@ enum {
 defreg(TPR), defreg(TPT), defreg(TXDCTL),  defreg(WUFC),
 defreg(RA),  defreg(MTA), defreg(CRCERRS), defreg(VFTA),
 defreg(VET), defreg(RDTR),defreg(RADV),defreg(TADV),
-defreg(ITR),
+defreg(ITR), defreg(FCRUC),   defreg(TDFH),defreg(TDFT),
+defreg(TDFHS),   defreg(TDFTS),   defreg(TDFPC),   defreg(RDFH),
+defreg(RDFT),defreg(RDFHS),   defreg(RDFTS),   defreg(RDFPC),
+defreg(IPAV),defreg(WUC), defreg(WUS), defreg(AIT),
+defreg(IP6AT),   defreg(IP4AT),   defreg(FFLT),defreg(FFMT),
+defreg(FFVT),defreg(WUPM),defreg(PBM), defreg(SCC),
+defreg(ECOL),defreg(MCC), defreg(LATECOL), defreg(COLC),
+defreg(DC),  defreg(TNCRS),   defreg(SEC), defreg(CEXTERR),
+defreg(RLEC),defreg(XONRXC),  defreg(XONTXC),  defreg(XOFFRXC),
+defreg(XOFFTXC), defreg(RFC), defreg(RJC), defreg(RNBC),
+defreg(TSCTFC),  defreg(MGTPRC),  defreg(MGTPDC),  defreg(MGTPTC)
 };
 
 static void
@@ -1116,6 +1126,48 @@ mac_readreg(E1000State *s, int index)
 }
 
 static uint32_t
+mac_readreg_prt(E1000State *s, int index)
+{
+DBGOUT(GENERAL, "Reading register at offset: 0x%08x. "
+   "It is not fully implemented.\n", index<<2);
+return s->mac_reg[index];
+}
+
+static uint32_t
+mac_low4_read(E1000State *s, int index)
+{
+return s->mac_reg[index] & 0xf;
+}
+
+static uint32_t
+mac_low11_read(E1000State *s, int index)
+{
+return s->mac_reg[index] & 0x7ff;
+}
+
+static uint32_t
+mac_low11_read_prt(E1000State *s, int index)
+{
+DBGOUT(GENERAL, "Reading register at offset: 0x%08x. "
+   "It is not fully implemented.\n", index<<2);
+return s->mac_reg[index] & 0x7ff;
+}
+
+static uint32_t
+mac_low13_read_prt(E1000State *s, int index)
+{
+DBGOUT(GENERAL, "Reading register at offset: 0x%08x. "
+   "It is not fully implemented.\n", index<<2);
+return s->mac_reg[index] & 0x1fff;
+}
+
+static uint32_t
+mac_low16_read(E1000State *s, int index)
+{
+return s->mac_reg[index] & 0x;
+}
+
+static uint32_t
 mac_icr_read(E1000State *s, int index)
 {
 uint32_t ret = s->mac_reg[ICR];
@@ -1159,6 +1211,14 @@ mac_writereg(E1000State *s, int index, uint32_t val)
 }
 
 static void
+mac_writereg_prt(E1000State *s, int index, uint32_t val)
+{
+DBGOUT(GENERAL, "Writing to register at offset: 0x%08x. "
+   "It is not fully implemented.\n", index<<2);
+s->mac_reg[index] = val;
+}
+
+static void
 set_rdt(E1000State *s, int index, uint32_t val)
 {
 s->mac_reg[index] = val & 0x;
@@ -1217,25 +1277,49 @@ static uint32_t (*macreg_readops[])(E1000State *, int) 
= {
 getreg(RDH),  getreg(RDT),  getreg(VET),  getreg(ICS),
 getreg(TDBAL),getreg(TDBAH),getreg(RDBAH),getreg(RDBAL),
 getreg(TDLEN),getreg(RDLEN),getreg(RDTR), getreg(RADV),
-getreg(TADV), getreg(ITR),
+getreg(TADV), getreg(ITR),  getreg(FCRUC),getreg(IPAV),
+getreg(WUC),  getreg(WUS),  getreg(SCC),  getreg(ECOL),
+getreg(MCC),  getreg(LATECOL),  getreg(COLC), getreg(DC),
+getreg(TNCRS),getreg(SEC),  getreg(CEXTERR),  getreg(RLEC),
+getreg(XONRXC),   getreg(XONTXC),   getreg(XOFFRXC),  getreg(XOFFTXC),
+getreg(RFC),  getreg(RJC),  getreg(RNBC), getreg(TSCTFC),
+getreg(MGTPRC),   getreg(MGTPDC),   getreg(MGTPTC),
 
 [TOTH] = mac_read_clr8,   [TORH] = mac_read_clr8,
 [GPRC] = mac_read_clr4,   [GPTC] = mac_read_clr4,
 [TPT] = mac_read_clr4,[TPR] = mac_read_clr4,
 [ICR] = mac_icr_read, [EECD] = get_eecd,
 

[Qemu-devel] [PATCH v3 6/6] e1000: Implementing various counters

2015-10-28 Thread Leonid Bloch
This implements the following Statistic registers (various counters)
according to Intel's specs:

TSCTC  GOTCL  GOTCH  GORCL  GORCH  MPRC   BPRC   RUCROC
BPTC   MPTC   PTC... PRC...

Signed-off-by: Leonid Bloch 
Signed-off-by: Dmitry Fleytman 
---
 hw/net/e1000.c | 117 ++---
 1 file changed, 112 insertions(+), 5 deletions(-)

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index 2f83a9e..c24cd24 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -37,6 +37,8 @@
 
 #include "e1000_regs.h"
 
+static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+
 #define E1000_DEBUG
 
 #ifdef E1000_DEBUG
@@ -178,7 +180,13 @@ enum {
 defreg(DC),  defreg(TNCRS),   defreg(SEC), defreg(CEXTERR),
 defreg(RLEC),defreg(XONRXC),  defreg(XONTXC),  defreg(XOFFRXC),
 defreg(XOFFTXC), defreg(RFC), defreg(RJC), defreg(RNBC),
-defreg(TSCTFC),  defreg(MGTPRC),  defreg(MGTPDC),  defreg(MGTPTC)
+defreg(TSCTFC),  defreg(MGTPRC),  defreg(MGTPDC),  defreg(MGTPTC),
+defreg(RUC), defreg(ROC), defreg(GORCL),   defreg(GORCH),
+defreg(GOTCL),   defreg(GOTCH),   defreg(BPRC),defreg(MPRC),
+defreg(TSCTC),   defreg(PRC64),   defreg(PRC127),  defreg(PRC255),
+defreg(PRC511),  defreg(PRC1023), defreg(PRC1522), defreg(PTC64),
+defreg(PTC127),  defreg(PTC255),  defreg(PTC511),  defreg(PTC1023),
+defreg(PTC1522), defreg(MPTC),defreg(BPTC)
 };
 
 static void
@@ -583,6 +591,16 @@ inc_reg_if_not_full(E1000State *s, int index)
 }
 }
 
+static inline void
+inc_tx_bcast_or_mcast_count(E1000State *s, const unsigned char *arr)
+{
+if (!memcmp(arr, bcast, sizeof bcast)) {
+inc_reg_if_not_full(s, BPTC);
+} else if (arr[0] & 1) {
+inc_reg_if_not_full(s, MPTC);
+}
+}
+
 static void
 grow_8reg_if_not_full(E1000State *s, int index, int size)
 {
@@ -597,6 +615,24 @@ grow_8reg_if_not_full(E1000State *s, int index, int size)
 s->mac_reg[index+1] = sum >> 32;
 }
 
+static void
+increase_size_stats(E1000State *s, const int *size_regs, int size)
+{
+if (size > 1023) {
+inc_reg_if_not_full(s, size_regs[5]);
+} else if (size > 511) {
+inc_reg_if_not_full(s, size_regs[4]);
+} else if (size > 255) {
+inc_reg_if_not_full(s, size_regs[3]);
+} else if (size > 127) {
+inc_reg_if_not_full(s, size_regs[2]);
+} else if (size > 64) {
+inc_reg_if_not_full(s, size_regs[1]);
+} else if (size == 64) {
+inc_reg_if_not_full(s, size_regs[0]);
+}
+}
+
 static inline int
 vlan_enabled(E1000State *s)
 {
@@ -634,12 +670,17 @@ fcs_len(E1000State *s)
 static void
 e1000_send_packet(E1000State *s, const uint8_t *buf, int size)
 {
+static const int PTCregs[6] = { PTC64, PTC127, PTC255, PTC511,
+PTC1023, PTC1522 };
+
 NetClientState *nc = qemu_get_queue(s->nic);
 if (s->phy_reg[PHY_CTRL] & MII_CR_LOOPBACK) {
 nc->info->receive(nc, buf, size);
 } else {
 qemu_send_packet(nc, buf, size);
 }
+inc_tx_bcast_or_mcast_count(s, buf);
+increase_size_stats(s, PTCregs, size);
 }
 
 static void
@@ -665,8 +706,11 @@ xmit_seg(E1000State *s)
 if (tp->tcp) {
 sofar = frames * tp->mss;
 stl_be_p(tp->data+css+4, ldl_be_p(tp->data+css+4)+sofar); /* seq */
-if (tp->paylen - sofar > tp->mss)
+if (tp->paylen - sofar > tp->mss) {
 tp->data[css + 13] &= ~9;/* PSH, FIN */
+} else if (frames) {
+inc_reg_if_not_full(s, TSCTC);
+}
 } else/* UDP */
 stw_be_p(tp->data+css+4, len);
 if (tp->sum_needed & E1000_TXD_POPTS_TXSM) {
@@ -696,6 +740,8 @@ xmit_seg(E1000State *s)
 inc_reg_if_not_full(s, TPT);
 grow_8reg_if_not_full(s, TOTL, s->tx.size);
 s->mac_reg[GPTC] = s->mac_reg[TPT];
+s->mac_reg[GOTCL] = s->mac_reg[TOTL];
+s->mac_reg[GOTCH] = s->mac_reg[TOTH];
 }
 
 static void
@@ -863,7 +909,6 @@ start_xmit(E1000State *s)
 static int
 receive_filter(E1000State *s, const uint8_t *buf, int size)
 {
-static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 static const int mta_shift[] = {4, 3, 2, 0};
 uint32_t f, rctl = s->mac_reg[RCTL], ra[2], *rp;
 int isbcast = !memcmp(buf, bcast, sizeof bcast), ismcast = (buf[0] & 1);
@@ -881,10 +926,12 @@ receive_filter(E1000State *s, const uint8_t *buf, int 
size)
 }
 
 if (ismcast && (rctl & E1000_RCTL_MPE)) {  /* promiscuous mcast */
+inc_reg_if_not_full(s, MPRC);
 return 1;
 }
 
 if (isbcast && (rctl & E1000_RCTL_BAM)) {  /* broadcast enabled */
+inc_reg_if_not_full(s, BPRC);
 return 1;
 }
 
@@ -906,8 +953,10 @@ receive_filter(E1000State *s, const uint8_t *buf, int size)
 
 f = mta_shift[(rctl >> E1000_RCTL_MO_SHIFT) & 3];
 f 

[Qemu-devel] [PATCH v4 21/21] block: Update copyright of the accounting code

2015-10-28 Thread Alberto Garcia
Signed-off-by: Alberto Garcia 
---
 block/accounting.c | 1 +
 include/block/accounting.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/block/accounting.c b/block/accounting.c
index 05a5c5f..185025e 100644
--- a/block/accounting.c
+++ b/block/accounting.c
@@ -2,6 +2,7 @@
  * QEMU System Emulator block accounting
  *
  * Copyright (c) 2011 Christoph Hellwig
+ * Copyright (c) 2015 Igalia, S.L.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to 
deal
diff --git a/include/block/accounting.h b/include/block/accounting.h
index 482926b..0f46cb4 100644
--- a/include/block/accounting.h
+++ b/include/block/accounting.h
@@ -2,6 +2,7 @@
  * QEMU System Emulator block accounting
  *
  * Copyright (c) 2011 Christoph Hellwig
+ * Copyright (c) 2015 Igalia, S.L.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to 
deal
-- 
2.6.1




[Qemu-devel] [PATCH v4 06/21] block: Add statistics for failed and invalid I/O operations

2015-10-28 Thread Alberto Garcia
This patch adds the block_acct_failed() and block_acct_invalid()
functions to allow keeping track of failed and invalid I/O operations.

The number of failed and invalid operations is exposed in
BlockDeviceStats.

We don't keep track of the time spent on invalid operations because
they are cancelled immediately when they are started.

Signed-off-by: Alberto Garcia 
---
 block/accounting.c | 23 +++
 block/qapi.c   | 10 ++
 include/block/accounting.h |  4 
 qapi/block-core.json   | 23 ++-
 qmp-commands.hx| 12 
 5 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/block/accounting.c b/block/accounting.c
index d427fa8..49a9444 100644
--- a/block/accounting.c
+++ b/block/accounting.c
@@ -51,6 +51,29 @@ void block_acct_done(BlockAcctStats *stats, BlockAcctCookie 
*cookie)
 stats->last_access_time_ns = time_ns;
 }
 
+void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie)
+{
+int64_t time_ns = qemu_clock_get_ns(clock_type);
+
+assert(cookie->type < BLOCK_MAX_IOTYPE);
+
+stats->failed_ops[cookie->type]++;
+stats->total_time_ns[cookie->type] += time_ns - cookie->start_time_ns;
+stats->last_access_time_ns = time_ns;
+}
+
+void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type)
+{
+assert(type < BLOCK_MAX_IOTYPE);
+
+/* block_acct_done() and block_acct_failed() update
+ * total_time_ns[], but this one does not. The reason is that
+ * invalid requests are accounted during their submission,
+ * therefore there's no actual I/O involved. */
+
+stats->invalid_ops[type]++;
+stats->last_access_time_ns = qemu_clock_get_ns(clock_type);
+}
 
 void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type,
   int num_requests)
diff --git a/block/qapi.c b/block/qapi.c
index 539c2e3..84d8412 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -351,6 +351,16 @@ static BlockStats *bdrv_query_stats(const BlockDriverState 
*bs,
 s->stats->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE];
 s->stats->rd_operations = stats->nr_ops[BLOCK_ACCT_READ];
 s->stats->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE];
+
+s->stats->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ];
+s->stats->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE];
+s->stats->failed_flush_operations = 
stats->failed_ops[BLOCK_ACCT_FLUSH];
+
+s->stats->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ];
+s->stats->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE];
+s->stats->invalid_flush_operations =
+stats->invalid_ops[BLOCK_ACCT_FLUSH];
+
 s->stats->rd_merged = stats->merged[BLOCK_ACCT_READ];
 s->stats->wr_merged = stats->merged[BLOCK_ACCT_WRITE];
 s->stats->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH];
diff --git a/include/block/accounting.h b/include/block/accounting.h
index 4b2b999..b50e3cc 100644
--- a/include/block/accounting.h
+++ b/include/block/accounting.h
@@ -38,6 +38,8 @@ enum BlockAcctType {
 typedef struct BlockAcctStats {
 uint64_t nr_bytes[BLOCK_MAX_IOTYPE];
 uint64_t nr_ops[BLOCK_MAX_IOTYPE];
+uint64_t invalid_ops[BLOCK_MAX_IOTYPE];
+uint64_t failed_ops[BLOCK_MAX_IOTYPE];
 uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
 uint64_t merged[BLOCK_MAX_IOTYPE];
 int64_t last_access_time_ns;
@@ -52,6 +54,8 @@ typedef struct BlockAcctCookie {
 void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
   int64_t bytes, enum BlockAcctType type);
 void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie);
+void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie);
+void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type);
 void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type,
int num_requests);
 int64_t block_acct_idle_time_ns(BlockAcctStats *stats);
diff --git a/qapi/block-core.json b/qapi/block-core.json
index b00be46..0718243 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -452,6 +452,24 @@
 #nanoseconds. If the field is absent it means that
 #there haven't been any operations yet (Since 2.5).
 #
+# @failed_rd_operations: The number of failed read operations
+#performed by the device (Since 2.5)
+#
+# @failed_wr_operations: The number of failed write operations
+#performed by the device (Since 2.5)
+#
+# @failed_flush_operations: The number of failed flush operations
+#   performed by the device (Since 2.5)
+#
+# @invalid_rd_operations: The number of invalid read operations
+#  performed by the device (Since 2.5)
+#
+# @invalid_wr_operations: The number of invalid write operations
+#

[Qemu-devel] [PATCH v5 13/33] pc-dimm: make pc_existing_dimms_capacity static and rename it

2015-10-28 Thread Xiao Guangrong
pc_existing_dimms_capacity() can be static since it is not used out of
pc-dimm.c and drop the pc_ prefix to prepare the work which abstracts
dimm device type from pc-dimm

Signed-off-by: Xiao Guangrong 
---
 hw/mem/pc-dimm.c | 73 
 include/hw/mem/pc-dimm.h |  1 -
 2 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 2bae994..425f627 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -32,6 +32,38 @@ typedef struct pc_dimms_capacity {
  Error**errp;
 } pc_dimms_capacity;
 
+static int existing_dimms_capacity_internal(Object *obj, void *opaque)
+{
+pc_dimms_capacity *cap = opaque;
+uint64_t *size = >size;
+
+if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+DeviceState *dev = DEVICE(obj);
+
+if (dev->realized) {
+(*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP,
+cap->errp);
+}
+
+if (cap->errp && *cap->errp) {
+return 1;
+}
+}
+object_child_foreach(obj, existing_dimms_capacity_internal, opaque);
+return 0;
+}
+
+static uint64_t existing_dimms_capacity(Error **errp)
+{
+pc_dimms_capacity cap;
+
+cap.size = 0;
+cap.errp = errp;
+
+existing_dimms_capacity_internal(qdev_get_machine(), );
+return cap.size;
+}
+
 void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
  MemoryRegion *mr, uint64_t align, bool gap,
  Error **errp)
@@ -40,7 +72,7 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState 
*hpms,
 MachineState *machine = MACHINE(qdev_get_machine());
 PCDIMMDevice *dimm = PC_DIMM(dev);
 Error *local_err = NULL;
-uint64_t existing_dimms_capacity = 0;
+uint64_t dimms_capacity = 0;
 uint64_t addr;
 
 addr = object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, 
_err);
@@ -56,17 +88,16 @@ void pc_dimm_memory_plug(DeviceState *dev, 
MemoryHotplugState *hpms,
 goto out;
 }
 
-existing_dimms_capacity = pc_existing_dimms_capacity(_err);
+dimms_capacity = existing_dimms_capacity(_err);
 if (local_err) {
 goto out;
 }
 
-if (existing_dimms_capacity + memory_region_size(mr) >
+if (dimms_capacity + memory_region_size(mr) >
 machine->maxram_size - machine->ram_size) {
 error_setg(_err, "not enough space, currently 0x%" PRIx64
" in use of total hot pluggable 0x" RAM_ADDR_FMT,
-   existing_dimms_capacity,
-   machine->maxram_size - machine->ram_size);
+   dimms_capacity, machine->maxram_size - machine->ram_size);
 goto out;
 }
 
@@ -121,38 +152,6 @@ void pc_dimm_memory_unplug(DeviceState *dev, 
MemoryHotplugState *hpms,
 vmstate_unregister_ram(mr, dev);
 }
 
-static int pc_existing_dimms_capacity_internal(Object *obj, void *opaque)
-{
-pc_dimms_capacity *cap = opaque;
-uint64_t *size = >size;
-
-if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
-DeviceState *dev = DEVICE(obj);
-
-if (dev->realized) {
-(*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP,
-cap->errp);
-}
-
-if (cap->errp && *cap->errp) {
-return 1;
-}
-}
-object_child_foreach(obj, pc_existing_dimms_capacity_internal, opaque);
-return 0;
-}
-
-uint64_t pc_existing_dimms_capacity(Error **errp)
-{
-pc_dimms_capacity cap;
-
-cap.size = 0;
-cap.errp = errp;
-
-pc_existing_dimms_capacity_internal(qdev_get_machine(), );
-return cap.size;
-}
-
 int qmp_pc_dimm_device_list(Object *obj, void *opaque)
 {
 MemoryDeviceInfoList ***prev = opaque;
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 15590f1..c1e5774 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -87,7 +87,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);
-uint64_t pc_existing_dimms_capacity(Error **errp);
 void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
  MemoryRegion *mr, uint64_t align, bool gap,
  Error **errp);
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 00/33] implement vNVDIMM

2015-10-28 Thread Xiao Guangrong
This patchset can be found at:
  https://github.com/xiaogr/qemu.git nvdimm-v5

It is based on pci branch on Michael's tree and the top commit is:
commit 04040096 (tests: re-enable vhost-user-test).

Changelog in v5:
- changes from Michael's comments:
  1) prefix nvdimm_ to everything in NVDIMM source files
  2) make parsing _DSM Arg3 more clear
  3) comment style fix
  5) drop single used definition
  6) fix dirty dsm buffer lost due to memory write happened on host
  7) check dsm buffer if it is big enough to contain input data
  8) use build_append_int_noprefix to store single value to GArray

- changes from Michael's and Igor's comments:
  1) introduce 'nvdimm-support' parameter to control nvdimm
 enablement and it is disabled for 2.4 and its earlier versions
 to make live migration compatible
  2) only reserve 1 RAM page and 4 bytes IO Port for NVDIMM ACPI
 virtualization

- changes from Stefan's comments:
  1) do endian adjustment for the buffer length

- changes from Bharata B Rao's comments:
  1) fix compile on ppc

- others:
  1) the buffer length is directly got from IO read rather than got
 from dsm memory
  2) fix dirty label data lost due to memory write happened on host

Changelog in v4:
- changes from Michael's comments:
  1) show the message, "Memory is not allocated from HugeTlbfs", if file
 based memory is not allocated from hugetlbfs.
  2) introduce function, acpi_get_nvdimm_state(), to get NVDIMMState
 from Machine.
  3) statically define UUID and make its operation more clear
  4) use GArray to build device structures to avoid potential buffer
 overflow
  4) improve comments in the code
  5) improve code style

- changes from Igor's comments:
  1) add NVDIMM ACPI spec document
  2) use serialized method to avoid Mutex
  3) move NVDIMM ACPI's code to hw/acpi/nvdimm.c
  4) introduce a common ASL method used by _DSM for all devices to reduce
 ACPI size
  5) handle UUID in ACPI AML code. BTW, i'd keep handling revision in QEMU
 it's better to upgrade QEMU to support Rev2 in the future

- changes from Stefan's comments:
  1) copy input data from DSM memory to local buffer to avoid potential
 issues as DSM memory is visible to guest. Output data is handled
 in a similar way

- changes from Dan's comments:
  1) drop static namespace as Linux has already supported label-less
 nvdimm devices

- changes from Vladimir's comments:
  1) print better message, "failed to get file size for %s, can't create
 backend on it", if any file operation filed to obtain file size

- others:
  create a git repo on github.com for better review/test

Also, thanks for Eric Blake's review on QAPI's side.

Thank all of you to review this patchset.

Changelog in v3:
There is huge change in this version, thank Igor, Stefan, Paolo, Eduardo,
Michael for their valuable comments, the patchset finally gets better shape.
- changes from Igor's comments:
  1) abstract dimm device type from pc-dimm and create nvdimm device based on
 dimm, then it uses memory backend device as nvdimm's memory and NUMA has
 easily been implemented.
  2) let file-backend device support any kind of filesystem not only for
 hugetlbfs and let it work on file not only for directory which is
 achieved by extending 'mem-path' - if it's a directory then it works as
 current behavior, otherwise if it's file then directly allocates memory
 from it.
  3) we figure out a unused memory hole below 4G that is 0xFF0 ~ 
 0xFFF0, this range is large enough for NVDIMM ACPI as build 64-bit
 ACPI SSDT/DSDT table will break windows XP.
 BTW, only make SSDT.rev = 2 can not work since the width is only depended
 on DSDT.rev based on 19.6.28 DefinitionBlock (Declare Definition Block)
 in ACPI spec:
| Note: For compatibility with ACPI versions before ACPI 2.0, the bit 
| width of Integer objects is dependent on the ComplianceRevision of the DSDT.
| If the ComplianceRevision is less than 2, all integers are restricted to 32 
| bits. Otherwise, full 64-bit integers are used. The version of the DSDT sets 
| the global integer width for all integers, including integers in SSDTs.
  4) use the lowest ACPI spec version to document AML terms.
  5) use "nvdimm" as nvdimm device name instead of "pc-nvdimm"

- changes from Stefan's comments:
  1) do not do endian adjustment in-place since _DSM memory is visible to guest
  2) use target platform's target page size instead of fixed PAGE_SIZE
 definition
  3) lots of code style improvement and typo fixes.
  4) live migration fix
- changes from Paolo's comments:
  1) improve the name of memory region
  
- other changes:
  1) return exact buffer size for _DSM method instead of the page size.
  2) introduce mutex in NVDIMM ACPI as the _DSM memory is shared by all nvdimm
 devices.
  3) NUMA support
  4) implement _FIT method
  5) rename "configdata" to "reserve-label-data"
  6) simplify _DSM arg3 determination
  7) main 

[Qemu-devel] [PATCH v5 17/33] dimm: abstract dimm device from pc-dimm

2015-10-28 Thread Xiao Guangrong
A base device, dimm, is abstracted from pc-dimm, so that we can
build nvdimm device based on dimm in the later patch

Signed-off-by: Xiao Guangrong 
---
 default-configs/i386-softmmu.mak   |  1 +
 default-configs/ppc64-softmmu.mak  |  1 +
 default-configs/x86_64-softmmu.mak |  1 +
 hw/mem/Makefile.objs   |  3 ++-
 hw/mem/dimm.c  | 11 ++---
 hw/mem/pc-dimm.c   | 46 ++
 include/hw/mem/dimm.h  |  4 ++--
 include/hw/mem/pc-dimm.h   |  7 ++
 8 files changed, 62 insertions(+), 12 deletions(-)
 create mode 100644 hw/mem/pc-dimm.c
 create mode 100644 include/hw/mem/pc-dimm.h

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 43c96d1..3ece8bb 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -18,6 +18,7 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_X86_ICH=y
+CONFIG_DIMM=y
 CONFIG_ACPI_MEMORY_HOTPLUG=y
 CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
diff --git a/default-configs/ppc64-softmmu.mak 
b/default-configs/ppc64-softmmu.mak
index e77cb1a..a1a9c36 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -53,3 +53,4 @@ CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM))
 CONFIG_MC146818RTC=y
 CONFIG_ISA_TESTDEV=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_DIMM=y
diff --git a/default-configs/x86_64-softmmu.mak 
b/default-configs/x86_64-softmmu.mak
index dfb8095..92ea7c1 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -18,6 +18,7 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_X86_ICH=y
+CONFIG_DIMM=y
 CONFIG_ACPI_MEMORY_HOTPLUG=y
 CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs
index 7563ef5..cebb4b1 100644
--- a/hw/mem/Makefile.objs
+++ b/hw/mem/Makefile.objs
@@ -1 +1,2 @@
-common-obj-$(CONFIG_MEM_HOTPLUG) += dimm.o
+common-obj-$(CONFIG_DIMM) += dimm.o
+common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o
diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index 6c1ea98..23d5daa 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -1,5 +1,5 @@
 /*
- * Dimm device for Memory Hotplug
+ * Dimm device abstraction
  *
  * Copyright ProfitBricks GmbH 2012
  * Copyright (C) 2014 Red Hat Inc
@@ -432,21 +432,13 @@ static void dimm_realize(DeviceState *dev, Error **errp)
 }
 }
 
-static MemoryRegion *dimm_get_memory_region(DIMMDevice *dimm)
-{
-return host_memory_backend_get_memory(dimm->hostmem, _abort);
-}
-
 static void dimm_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
-DIMMDeviceClass *ddc = DIMM_CLASS(oc);
 
 dc->realize = dimm_realize;
 dc->props = dimm_properties;
 dc->desc = "DIMM memory module";
-
-ddc->get_memory_region = dimm_get_memory_region;
 }
 
 static TypeInfo dimm_info = {
@@ -456,6 +448,7 @@ static TypeInfo dimm_info = {
 .instance_init = dimm_init,
 .class_init= dimm_class_init,
 .class_size= sizeof(DIMMDeviceClass),
+.abstract  = true,
 };
 
 static void dimm_register_types(void)
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
new file mode 100644
index 000..38323e9
--- /dev/null
+++ b/hw/mem/pc-dimm.c
@@ -0,0 +1,46 @@
+/*
+ * Dimm device for Memory Hotplug
+ *
+ * Copyright ProfitBricks GmbH 2012
+ * Copyright (C) 2014 Red Hat Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see 
+ */
+
+#include "hw/mem/pc-dimm.h"
+
+static MemoryRegion *pc_dimm_get_memory_region(DIMMDevice *dimm)
+{
+return host_memory_backend_get_memory(dimm->hostmem, _abort);
+}
+
+static void pc_dimm_class_init(ObjectClass *oc, void *data)
+{
+DIMMDeviceClass *ddc = DIMM_CLASS(oc);
+
+ddc->get_memory_region = pc_dimm_get_memory_region;
+}
+
+static TypeInfo pc_dimm_info = {
+.name  = TYPE_PC_DIMM,
+.parent= TYPE_DIMM,
+.class_init= pc_dimm_class_init,
+};
+
+static void pc_dimm_register_types(void)
+{
+type_register_static(_dimm_info);
+}
+
+type_init(pc_dimm_register_types)
diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h
index 5ddbf08..84a62ed 100644
--- a/include/hw/mem/dimm.h
+++ b/include/hw/mem/dimm.h
@@ -1,5 +1,5 @@
 /*
- * PC DIMM device
+ * Dimm device abstraction
  *
  * Copyright ProfitBricks GmbH 2012
  * 

Re: [Qemu-devel] [PATCH v4 17/33] dimm: abstract dimm device from pc-dimm

2015-10-28 Thread Xiao Guangrong



On 10/24/2015 11:20 AM, Bharata B Rao wrote:


  CONFIG_ACPI_X86_ICH=y
+CONFIG_DIMM=y


Same change needs to be done in default-configs/ppc64-softmmu.mak too.


I have fixed it in v5 which cat be found at:
   http://marc.info/?l=kvm=144604272221080=2

Bharata, thank you very much for your review.



[Qemu-devel] [PATCH v5 11/33] hostmem-file: use whole file size if possible

2015-10-28 Thread Xiao Guangrong
Use the whole file size if @size is not specified which is useful
if we want to directly pass a file to guest

Signed-off-by: Xiao Guangrong 
---
 backends/hostmem-file.c | 48 
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 9097a57..e1bc9ff 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -9,6 +9,9 @@
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
  */
+#include 
+#include 
+
 #include "qemu-common.h"
 #include "sysemu/hostmem.h"
 #include "sysemu/sysemu.h"
@@ -33,20 +36,57 @@ struct HostMemoryBackendFile {
 char *mem_path;
 };
 
+static uint64_t get_file_size(const char *file)
+{
+struct stat stat_buf;
+uint64_t size = 0;
+int fd;
+
+fd = open(file, O_RDONLY);
+if (fd < 0) {
+return 0;
+}
+
+if (stat(file, _buf) < 0) {
+goto exit;
+}
+
+if ((S_ISBLK(stat_buf.st_mode)) && !ioctl(fd, BLKGETSIZE64, )) {
+goto exit;
+}
+
+size = lseek(fd, 0, SEEK_END);
+if (size == -1) {
+size = 0;
+}
+exit:
+close(fd);
+return size;
+}
+
 static void
 file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
 {
 HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend);
 
-if (!backend->size) {
-error_setg(errp, "can't create backend with size 0");
-return;
-}
 if (!fb->mem_path) {
 error_setg(errp, "mem-path property not set");
 return;
 }
 
+if (!backend->size) {
+/*
+ * use the whole file size if @size is not specified.
+ */
+backend->size = get_file_size(fb->mem_path);
+}
+
+if (!backend->size) {
+error_setg(errp, "failed to get file size for %s, can't create "
+ "backend on it", mem_path);
+return;
+}
+
 backend->force_prealloc = mem_prealloc;
 memory_region_init_ram_from_file(>mr, OBJECT(backend),
  object_get_canonical_path(OBJECT(backend)),
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 23/33] nvdimm acpi: init the resource used by NVDIMM ACPI

2015-10-28 Thread Xiao Guangrong
A page staring from 0xFF0 and IO port 0x0a18 - 0xa1b in guest are
reserved for NVDIMM ACPI emulation, refer to docs/specs/acpi_nvdimm.txt
for detailed design

A parameter, 'nvdimm-support', is introduced for PIIX4_PM and ICH9-LPC
that controls if nvdimm support is enabled, it is true on default and
it is false on 2.4 and its earlier version to keep compatibility

Signed-off-by: Xiao Guangrong 
---
 default-configs/i386-softmmu.mak |  1 +
 default-configs/mips-softmmu.mak |  1 +
 default-configs/mips64-softmmu.mak   |  1 +
 default-configs/mips64el-softmmu.mak |  1 +
 default-configs/mipsel-softmmu.mak   |  1 +
 default-configs/x86_64-softmmu.mak   |  1 +
 hw/acpi/Makefile.objs|  1 +
 hw/acpi/ich9.c   | 24 ++
 hw/acpi/nvdimm.c | 63 
 hw/acpi/piix4.c  | 27 
 include/hw/acpi/ich9.h   |  3 ++
 include/hw/i386/pc.h | 10 ++
 include/hw/mem/nvdimm.h  | 34 +++
 13 files changed, 161 insertions(+), 7 deletions(-)
 create mode 100644 hw/acpi/nvdimm.c

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 4e84a1c..51e71d4 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -48,6 +48,7 @@ CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
 CONFIG_NVDIMM=y
+CONFIG_ACPI_NVDIMM=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
diff --git a/default-configs/mips-softmmu.mak b/default-configs/mips-softmmu.mak
index 44467c3..6b8b70e 100644
--- a/default-configs/mips-softmmu.mak
+++ b/default-configs/mips-softmmu.mak
@@ -17,6 +17,7 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_NVDIMM=y
 CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
diff --git a/default-configs/mips64-softmmu.mak 
b/default-configs/mips64-softmmu.mak
index 66ed5f9..ea820f6 100644
--- a/default-configs/mips64-softmmu.mak
+++ b/default-configs/mips64-softmmu.mak
@@ -17,6 +17,7 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_NVDIMM=y
 CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
diff --git a/default-configs/mips64el-softmmu.mak 
b/default-configs/mips64el-softmmu.mak
index bfca2b2..8993851 100644
--- a/default-configs/mips64el-softmmu.mak
+++ b/default-configs/mips64el-softmmu.mak
@@ -17,6 +17,7 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_NVDIMM=y
 CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
diff --git a/default-configs/mipsel-softmmu.mak 
b/default-configs/mipsel-softmmu.mak
index 0162ef0..87ab964 100644
--- a/default-configs/mipsel-softmmu.mak
+++ b/default-configs/mipsel-softmmu.mak
@@ -17,6 +17,7 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_NVDIMM=y
 CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
diff --git a/default-configs/x86_64-softmmu.mak 
b/default-configs/x86_64-softmmu.mak
index e877a86..0a7dc10 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -48,6 +48,7 @@ CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
 CONFIG_NVDIMM=y
+CONFIG_ACPI_NVDIMM=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 7d3230c..095597f 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -2,6 +2,7 @@ common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o
 common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o
 common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
 common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
+common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
 common-obj-$(CONFIG_ACPI) += acpi_interface.o
 common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
 common-obj-$(CONFIG_ACPI) += aml-build.o
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 1e9ae20..603c1bd 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -280,6 +280,12 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
  >acpi_memory_hotplug);
 }
+
+if (pm->acpi_nvdimm_state.is_enabled) {
+nvdimm_init_acpi_state(pci_address_space(lpc_pci),
+   pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+   >acpi_nvdimm_state);
+}
 }
 
 static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
@@ -307,6 +313,20 @@ static void ich9_pm_set_memory_hotplug_support(Object 
*obj, bool value,
 s->pm.acpi_memory_hotplug.is_enabled = value;
 }
 
+static bool ich9_pm_get_nvdimm_support(Object *obj, Error **errp)
+{
+ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+return s->pm.acpi_nvdimm_state.is_enabled;
+}
+
+static void 

[Qemu-devel] [PATCH v5 07/33] util: introduce qemu_file_get_page_size()

2015-10-28 Thread Xiao Guangrong
There are three places use the some logic to get the page size on
the file path or file fd

This patch introduces qemu_file_get_page_size() to unify the code

Signed-off-by: Xiao Guangrong 
---
 include/qemu/osdep.h |  1 +
 target-ppc/kvm.c | 21 +++--
 util/oslib-posix.c   | 16 
 util/oslib-win32.c   |  5 +
 4 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index ef21efb..9c8c0c4 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -286,4 +286,5 @@ void os_mem_prealloc(int fd, char *area, size_t sz);
 
 int qemu_read_password(char *buf, int buf_size);
 
+size_t qemu_file_get_page_size(const char *mem_path);
 #endif
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 7276299..0b68a7a 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -306,28 +306,13 @@ static void kvm_get_smmu_info(PowerPCCPU *cpu, struct 
kvm_ppc_smmu_info *info)
 
 static long gethugepagesize(const char *mem_path)
 {
-struct statfs fs;
-int ret;
-
-do {
-ret = statfs(mem_path, );
-} while (ret != 0 && errno == EINTR);
+long size = qemu_file_get_page_size(mem_path);
 
-if (ret != 0) {
-fprintf(stderr, "Couldn't statfs() memory path: %s\n",
-strerror(errno));
+if (!size) {
 exit(1);
 }
 
-#define HUGETLBFS_MAGIC   0x958458f6
-
-if (fs.f_type != HUGETLBFS_MAGIC) {
-/* Explicit mempath, but it's ordinary pages */
-return getpagesize();
-}
-
-/* It's hugepage, return the huge page size */
-return fs.f_bsize;
+return size;
 }
 
 static int find_max_supported_pagesize(Object *obj, void *opaque)
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 892d2d8..32b4d1f 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -360,6 +360,22 @@ static size_t fd_getpagesize(int fd)
 return getpagesize();
 }
 
+size_t qemu_file_get_page_size(const char *path)
+{
+size_t size = 0;
+int fd = qemu_open(path, O_RDONLY);
+
+if (fd < 0) {
+fprintf(stderr, "Could not open %s.\n", path);
+goto exit;
+}
+
+size = fd_getpagesize(fd);
+qemu_close(fd);
+exit:
+return size;
+}
+
 void os_mem_prealloc(int fd, char *area, size_t memory)
 {
 int ret;
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 08f5a9c..1ff1fae 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -462,6 +462,11 @@ size_t getpagesize(void)
 return system_info.dwPageSize;
 }
 
+size_t qemu_file_get_page_size(const char *path)
+{
+return getpagesize();
+}
+
 void os_mem_prealloc(int fd, char *area, size_t memory)
 {
 int i;
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 32/33] nvdimm acpi: support _FIT method

2015-10-28 Thread Xiao Guangrong
FIT buffer is not completely mapped into guest address space, so a new
function, Read FIT, function index 0x, is reserved by QEMU to
read the piece of FIT buffer. The buffer is concatenated before _FIT
return

Refer to docs/specs/acpi-nvdimm.txt for detailed design

Signed-off-by: Xiao Guangrong 
---
 hw/acpi/nvdimm.c | 168 +--
 1 file changed, 164 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index c5a50ea..e1ae6c5 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -384,6 +384,18 @@ static void nvdimm_build_nfit(GSList *device_list, GArray 
*table_offsets,
 g_array_free(structures, true);
 }
 
+/*
+ * define UUID for NVDIMM Root Device according to Chapter 3 DSM Interface
+ * for NVDIMM Root Device - Example in DSM Spec Rev1.
+ */
+#define NVDIMM_DSM_ROOT_UUID "2F10E7A4-9E91-11E4-89D3-123B93F75CBA"
+
+/*
+ * Read FIT Function, which is a QEMU internal use only function, more detail
+ * refer to docs/specs/acpi_nvdimm.txt
+ */
+#define NVDIMM_DSM_FUNC_READ_FIT 0x
+
 /* define NVDIMM DSM return status codes according to DSM Spec Rev1. */
 enum {
 /* Common return status codes. */
@@ -420,6 +432,11 @@ struct nvdimm_func_in_set_label_data {
 } QEMU_PACKED;
 typedef struct nvdimm_func_in_set_label_data nvdimm_func_in_set_label_data;
 
+struct nvdimm_func_in_read_fit {
+uint32_t offset; /* fit offset */
+} QEMU_PACKED;
+typedef struct nvdimm_func_in_read_fit nvdimm_func_in_read_fit;
+
 struct nvdimm_dsm_in {
 uint32_t handle;
 uint32_t revision;
@@ -429,6 +446,7 @@ struct nvdimm_dsm_in {
 uint8_t arg3[0];
 nvdimm_func_in_set_label_data func_set_label_data;
 nvdimm_func_in_get_label_data func_get_label_data;
+nvdimm_func_in_read_fit func_read_fit;
 };
 } QEMU_PACKED;
 typedef struct nvdimm_dsm_in nvdimm_dsm_in;
@@ -450,13 +468,71 @@ struct nvdimm_func_out_get_label_data {
 } QEMU_PACKED;
 typedef struct nvdimm_func_out_get_label_data nvdimm_func_out_get_label_data;
 
+struct nvdimm_func_out_read_fit {
+uint32_t status;/* return status code. */
+uint32_t length;/* the length of fit data we read. */
+uint8_t fit_data[0]; /* fit data. */
+} QEMU_PACKED;
+typedef struct nvdimm_func_out_read_fit nvdimm_func_out_read_fit;
+
 static void nvdimm_dsm_write_status(GArray *out, uint32_t status)
 {
 status = cpu_to_le32(status);
 build_append_int_noprefix(out, status, sizeof(status));
 }
 
-static void nvdimm_dsm_root(nvdimm_dsm_in *in, GArray *out)
+/* Build fit memory which is presented to guest via _FIT method. */
+static void nvdimm_build_fit(AcpiNVDIMMState *state)
+{
+if (!state->fit) {
+GSList *device_list = nvdimm_get_plugged_device_list();
+
+nvdimm_debug("Rebuild FIT...\n");
+state->fit = nvdimm_build_device_structure(device_list);
+g_slist_free(device_list);
+}
+}
+
+/* Read FIT data, defined in docs/specs/acpi_nvdimm.txt. */
+static void nvdimm_dsm_func_read_fit(AcpiNVDIMMState *state,
+ nvdimm_dsm_in *in, GArray *out)
+{
+nvdimm_func_in_read_fit *read_fit = >func_read_fit;
+nvdimm_func_out_read_fit fit_out;
+uint32_t read_length = getpagesize() - sizeof(nvdimm_func_out_read_fit);
+uint32_t status = NVDIMM_DSM_ROOT_DEV_STATUS_INVALID_PARAS;
+
+nvdimm_build_fit(state);
+
+le32_to_cpus(_fit->offset);
+
+nvdimm_debug("Read FIT offset %#x.\n", read_fit->offset);
+
+if (read_fit->offset > state->fit->len) {
+nvdimm_debug("offset %#x is beyond fit size (%#x).\n",
+ read_fit->offset, state->fit->len);
+goto exit;
+}
+
+read_length = MIN(read_length, state->fit->len - read_fit->offset);
+nvdimm_debug("read length %#x.\n", read_length);
+
+fit_out.status = cpu_to_le32(NVDIMM_DSM_STATUS_SUCCESS);
+fit_out.length = cpu_to_le32(read_length);
+g_array_append_vals(out, _out, sizeof(fit_out));
+
+if (read_length) {
+g_array_append_vals(out, state->fit->data + read_fit->offset,
+read_length);
+}
+return;
+
+exit:
+nvdimm_dsm_write_status(out, status);
+}
+
+static void nvdimm_dsm_root(AcpiNVDIMMState *state, nvdimm_dsm_in *in,
+GArray *out)
 {
 uint32_t status = NVDIMM_DSM_STATUS_NOT_SUPPORTED;
 
@@ -475,6 +551,10 @@ static void nvdimm_dsm_root(nvdimm_dsm_in *in, GArray *out)
 return;
 }
 
+if (in->function == NVDIMM_DSM_FUNC_READ_FIT /* FIT Read */) {
+return nvdimm_dsm_func_read_fit(state, in, out);
+}
+
 nvdimm_debug("Return status %#x.\n", status);
 nvdimm_dsm_write_status(out, status);
 }
@@ -713,7 +793,7 @@ nvdimm_dsm_read(void *opaque, hwaddr addr, unsigned size)
 
 /* Handle 0 is reserved for NVDIMM Root Device. */
 if (!in->handle) {
-nvdimm_dsm_root(in, out);
+nvdimm_dsm_root(state, in, out);

  1   2   3   4   >