Re: [Qemu-devel] [PATCH 1/2] vmxnet3: Convert ring values to uint32_t's

2016-12-17 Thread Dmitry Fleytman

Acked-by: Dmitry Fleytman 

> On 15 Dec 2016, at 22:05 PM, Dr. David Alan Gilbert (git) 
>  wrote:
> 
> From: "Dr. David Alan Gilbert" 
> 
> The index's in the Vmxnet3Ring were migrated as 32bit ints
> yet are declared as size_t's.  They appear to be derived
> from 32bit values loaded from guest memory, so actually
> store them as that.
> 
> Signed-off-by: Dr. David Alan Gilbert 
> ---
> hw/net/vmxnet3.c | 12 ++--
> 1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
> index 2cb2731..7853174 100644
> --- a/hw/net/vmxnet3.c
> +++ b/hw/net/vmxnet3.c
> @@ -141,17 +141,17 @@ typedef struct VMXNET3Class {
> /* Cyclic ring abstraction */
> typedef struct {
> hwaddr pa;
> -size_t size;
> -size_t cell_size;
> -size_t next;
> +uint32_t size;
> +uint32_t cell_size;
> +uint32_t next;
> uint8_t gen;
> } Vmxnet3Ring;
> 
> static inline void vmxnet3_ring_init(PCIDevice *d,
>Vmxnet3Ring *ring,
>  hwaddr pa,
> - size_t size,
> - size_t cell_size,
> + uint32_t size,
> + uint32_t cell_size,
>  bool zero_region)
> {
> ring->pa = pa;
> @@ -166,7 +166,7 @@ static inline void vmxnet3_ring_init(PCIDevice *d,
> }
> 
> #define VMXNET3_RING_DUMP(macro, ring_name, ridx, r) \
> -macro("%s#%d: base %" PRIx64 " size %zu cell_size %zu gen %d next %zu",  
> \
> +macro("%s#%d: base %" PRIx64 " size %u cell_size %u gen %d next %u",  \
>   (ring_name), (ridx),   \
>   (r)->pa, (r)->size, (r)->cell_size, (r)->gen, (r)->next)
> 
> -- 
> 2.9.3
> 




Re: [Qemu-devel] [PATCH 2/2] vmxnet3: VMStatify rx/tx q_descr and int_state

2016-12-17 Thread Dmitry Fleytman
> 
> On 16 Dec 2016, at 14:19 PM, Dr. David Alan Gilbert  
> wrote:
> 
> * Dr. David Alan Gilbert (git) (dgilb...@redhat.com) wrote:
>> From: "Dr. David Alan Gilbert" 
>> 
>> Fairly simple mechanical conversion of all fields.
>> 
>> TODO
>> The problem is vmxnet3-ring size/cell_size/next are declared as size_t
>> but written as 32bit.
> 
> Oops, I should have removed that warning in the commit message when
> I added the 1st patch in.



Acked-by: Dmitry Fleytman 

> 
> Dave
> 
>> Signed-off-by: Dr. David Alan Gilbert 
>> ---
>> hw/net/vmxnet3.c | 272 
>> ++-
>> 1 file changed, 90 insertions(+), 182 deletions(-)
>> 
>> diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
>> index 7853174..4f7dbaf 100644
>> --- a/hw/net/vmxnet3.c
>> +++ b/hw/net/vmxnet3.c
>> @@ -2403,155 +2403,87 @@ static const VMStateDescription 
>> vmxstate_vmxnet3_mcast_list = {
>> }
>> };
>> 
>> -static void vmxnet3_get_ring_from_file(QEMUFile *f, Vmxnet3Ring *r)
>> -{
>> -r->pa = qemu_get_be64(f);
>> -r->size = qemu_get_be32(f);
>> -r->cell_size = qemu_get_be32(f);
>> -r->next = qemu_get_be32(f);
>> -r->gen = qemu_get_byte(f);
>> -}
>> -
>> -static void vmxnet3_put_ring_to_file(QEMUFile *f, Vmxnet3Ring *r)
>> -{
>> -qemu_put_be64(f, r->pa);
>> -qemu_put_be32(f, r->size);
>> -qemu_put_be32(f, r->cell_size);
>> -qemu_put_be32(f, r->next);
>> -qemu_put_byte(f, r->gen);
>> -}
>> -
>> -static void vmxnet3_get_tx_stats_from_file(QEMUFile *f,
>> -struct UPT1_TxStats *tx_stat)
>> -{
>> -tx_stat->TSOPktsTxOK = qemu_get_be64(f);
>> -tx_stat->TSOBytesTxOK = qemu_get_be64(f);
>> -tx_stat->ucastPktsTxOK = qemu_get_be64(f);
>> -tx_stat->ucastBytesTxOK = qemu_get_be64(f);
>> -tx_stat->mcastPktsTxOK = qemu_get_be64(f);
>> -tx_stat->mcastBytesTxOK = qemu_get_be64(f);
>> -tx_stat->bcastPktsTxOK = qemu_get_be64(f);
>> -tx_stat->bcastBytesTxOK = qemu_get_be64(f);
>> -tx_stat->pktsTxError = qemu_get_be64(f);
>> -tx_stat->pktsTxDiscard = qemu_get_be64(f);
>> -}
>> -
>> -static void vmxnet3_put_tx_stats_to_file(QEMUFile *f,
>> -struct UPT1_TxStats *tx_stat)
>> -{
>> -qemu_put_be64(f, tx_stat->TSOPktsTxOK);
>> -qemu_put_be64(f, tx_stat->TSOBytesTxOK);
>> -qemu_put_be64(f, tx_stat->ucastPktsTxOK);
>> -qemu_put_be64(f, tx_stat->ucastBytesTxOK);
>> -qemu_put_be64(f, tx_stat->mcastPktsTxOK);
>> -qemu_put_be64(f, tx_stat->mcastBytesTxOK);
>> -qemu_put_be64(f, tx_stat->bcastPktsTxOK);
>> -qemu_put_be64(f, tx_stat->bcastBytesTxOK);
>> -qemu_put_be64(f, tx_stat->pktsTxError);
>> -qemu_put_be64(f, tx_stat->pktsTxDiscard);
>> -}
>> -
>> -static int vmxnet3_get_txq_descr(QEMUFile *f, void *pv, size_t size,
>> -VMStateField *field)
>> -{
>> -Vmxnet3TxqDescr *r = pv;
>> -
>> -vmxnet3_get_ring_from_file(f, >tx_ring);
>> -vmxnet3_get_ring_from_file(f, >comp_ring);
>> -r->intr_idx = qemu_get_byte(f);
>> -r->tx_stats_pa = qemu_get_be64(f);
>> -
>> -vmxnet3_get_tx_stats_from_file(f, >txq_stats);
>> -
>> -return 0;
>> -}
>> -
>> -static int vmxnet3_put_txq_descr(QEMUFile *f, void *pv, size_t size,
>> - VMStateField *field, QJSON *vmdesc)
>> -{
>> -Vmxnet3TxqDescr *r = pv;
>> -
>> -vmxnet3_put_ring_to_file(f, >tx_ring);
>> -vmxnet3_put_ring_to_file(f, >comp_ring);
>> -qemu_put_byte(f, r->intr_idx);
>> -qemu_put_be64(f, r->tx_stats_pa);
>> -vmxnet3_put_tx_stats_to_file(f, >txq_stats);
>> -
>> -return 0;
>> -}
>> -
>> -static const VMStateInfo txq_descr_info = {
>> -.name = "txq_descr",
>> -.get = vmxnet3_get_txq_descr,
>> -.put = vmxnet3_put_txq_descr
>> +static const VMStateDescription vmstate_vmxnet3_ring = {
>> +.name = "vmxnet3-ring",
>> +.version_id = 0,
>> +.fields = (VMStateField[]) {
>> +VMSTATE_UINT64(pa, Vmxnet3Ring),
>> +VMSTATE_UINT32(size, Vmxnet3Ring),
>> +VMSTATE_UINT32(cell_size, Vmxnet3Ring),
>> +VMSTATE_UINT32(next, Vmxnet3Ring),
>> +VMSTATE_UINT8(gen, Vmxnet3Ring),
>> +VMSTATE_END_OF_LIST()
>> +}
>> };
>> 
>> -static void vmxnet3_get_rx_stats_from_file(QEMUFile *f,
>> -struct UPT1_RxStats *rx_stat)
>> -{
>> -rx_stat->LROPktsRxOK = qemu_get_be64(f);
>> -rx_stat->LROBytesRxOK = qemu_get_be64(f);
>> -rx_stat->ucastPktsRxOK = qemu_get_be64(f);
>> -rx_stat->ucastBytesRxOK = qemu_get_be64(f);
>> -rx_stat->mcastPktsRxOK = qemu_get_be64(f);
>> -rx_stat->mcastBytesRxOK = qemu_get_be64(f);
>> -rx_stat->bcastPktsRxOK = qemu_get_be64(f);
>> -rx_stat->bcastBytesRxOK = qemu_get_be64(f);
>> -rx_stat->pktsRxOutOfBuf = qemu_get_be64(f);
>> -rx_stat->pktsRxError = qemu_get_be64(f);
>> -}
>> -
>> -static void vmxnet3_put_rx_stats_to_file(QEMUFile *f,
>> -struct UPT1_RxStats *rx_stat)
>> -{
>> -

Re: [Qemu-devel] [PATCH 00/26] New hppa-linux-user target

2016-12-17 Thread Thomas Huth
On 16.12.2016 20:13, Richard Henderson wrote:
> This is a linux-user only port, emulating a 32-bit only version of a
> pa-2.0 cpu.  This is good enough to do well with both the gcc and glibc
> testsuites.  Helge Deller has provided invaluable assistance testing 
> with a more complete debian chroot.
> 
> What's missing:
>   * Space registers.  Since Linux sets them all equal (for a flat
> address space) and uses them like address-space identifiers,
> we can simply set them all to 0 and ignore them.
> 
>   * Architecture subsets.  There's no markup for running a pure pa1.0
> or pa1.1 cpu.  I happily accept everything up to pa2.0 at the moment.
> 
>   * Wide mode.  While I have pa2.0 instructions, I don't support running
> in 64-bit mode.  Since neither the linux kernel nor glibc support a
> 64-bit userland, it would be a lot more work than just adding the insns.
> 
>   * Multimedia instructions.  These are tied to wide mode, so...
> 
> When squashing the patches down from my development tree, I wanted to
> preserve Helge's contributions, so the linux-user part is more patches
> than I would normally have preserved.
> 
> 
> r~
> 
> 
> Helge Deller (3):
>   linux-user: Handle TIOCSTART and TIOCSTOP
>   linux-user: Add SIOCGPGRP, SIOCGSTAMP, SIOCGSTAMPNS
>   linux-user: Add some hppa ioctls
> 
> Richard Henderson (23):
>   Revert "Remove remainders of HPPA backend"
>   linux-user: Support stack-grows-up in elfload.c
>   linux-user: Handle ERFKILL and EHWPOISON
>   linux-user: Handle more IPV6 sockopts
>   linux-user: Add HPPA socket.h definitions
>   linux-user: Add HPPA syscall numbers
>   linux-user: Add HPPA termbits.h
>   linux-user: Add HPPA target_syscall.h
>   linux-user: Add HPPA definitions to syscall_defs.h
>   linux-user: Add HPPA target_structs.h
>   linux-user: Add HPPA target_signal.h and target_cpu.h
>   linux-user: Add HPPA signal handling
>   linux-user: Add HPPA startup and main loop
>   target-hppa: Add softfloat specializations
>   target-hppa: Add framework and enable compilation
>   target-hppa: Add nullification framework
>   target-hppa: Implement basic arithmetic
>   target-hppa: Implement branches
>   target-hppa: Implement linux-user gateway page
>   target-hppa: Implement shifts and deposits
>   target-hppa: Implement loads and stores
>   target-hppa: Implement system and memory-management insns
>   target-hppa: Implement floating-point insns
> 
>  configure   |7 +-
>  default-configs/hppa-linux-user.mak |1 +
>  disas.c |2 +
>  disas/Makefile.objs |1 +
>  disas/hppa.c| 2832 +
>  fpu/softfloat-specialize.h  |   20 +-
>  linux-user/alpha/target_syscall.h   |2 +
>  linux-user/elfload.c|  259 ++-
>  linux-user/errno_defs.h |3 +
>  linux-user/hppa/sockbits.h  |   97 +
>  linux-user/hppa/syscall_nr.h|  353 
>  linux-user/hppa/target_cpu.h|   35 +
>  linux-user/hppa/target_signal.h |   29 +
>  linux-user/hppa/target_structs.h|   54 +
>  linux-user/hppa/target_syscall.h|  237 +++
>  linux-user/hppa/termbits.h  |  219 ++
>  linux-user/ioctls.h |8 +
>  linux-user/main.c   |  185 +-
>  linux-user/mips/target_syscall.h|5 +
>  linux-user/mips64/target_syscall.h  |5 +
>  linux-user/qemu.h   |3 +
>  linux-user/signal.c |  191 +-
>  linux-user/socket.h |2 +
>  linux-user/syscall.c|   41 +-
>  linux-user/syscall_defs.h   |  154 +-
>  linux-user/syscall_types.h  |6 +
>  target-hppa/Makefile.objs   |1 +
>  target-hppa/cpu-qom.h   |   52 +
>  target-hppa/cpu.c   |  165 ++
>  target-hppa/cpu.h   |  144 ++
>  target-hppa/gdbstub.c   |  111 +
>  target-hppa/helper.c|  137 ++
>  target-hppa/helper.h|   66 +
>  target-hppa/op_helper.c |  570 +
>  target-hppa/translate.c | 3946 
> +++
>  35 files changed, 9864 insertions(+), 79 deletions(-)
>  create mode 100644 default-configs/hppa-linux-user.mak
>  create mode 100644 disas/hppa.c
>  create mode 100644 linux-user/hppa/sockbits.h
>  create mode 100644 linux-user/hppa/syscall_nr.h
>  create mode 100644 linux-user/hppa/target_cpu.h
>  create mode 100644 linux-user/hppa/target_signal.h
>  create mode 100644 linux-user/hppa/target_structs.h
>  create mode 100644 linux-user/hppa/target_syscall.h
>  create mode 100644 linux-user/hppa/termbits.h
>  create mode 100644 target-hppa/Makefile.objs
>  create mode 100644 target-hppa/cpu-qom.h
>  create mode 100644 target-hppa/cpu.c
>  create mode 100644 target-hppa/cpu.h
>  create mode 100644 target-hppa/gdbstub.c
>  create mode 100644 target-hppa/helper.c
>  create mode 100644 

[Qemu-devel] [Bug 786440] Re: qcow2 double free

2016-12-17 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

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

Title:
  qcow2 double free

Status in QEMU:
  Expired

Bug description:
  version 0.14.1 when using qcow2 images, after some time, glibc detects
  a double free or corruption.

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



Re: [Qemu-devel] [PATCH 01/26] Revert "Remove remainders of HPPA backend"

2016-12-17 Thread Richard Henderson

On 12/17/2016 03:59 AM, Peter Maydell wrote:

On 16 December 2016 at 19:13, Richard Henderson  wrote:

This reverts commit d41f3c3cc7a5fb9de144cc4022da14a9ff010671.


Missing signed-off-by.


Oops.


+elif check_define __hppa__ ; then
+  cpu="hppa"
 else
   cpu=$(uname -m)
 fi


This if-ladder is for detecting hppa host CPUs, so you
don't want it for just adding the hppa target support.
Or do you clean this up later in the series so that this
commit is a pure revert?


I do remove this again in patch 18 (target-hppa: Add framework and enable 
compilation).  So, yes, this is pure revert.



r~




Re: [Qemu-devel] [PATCH 13/21] qcow2: add .bdrv_store_persistent_dirty_bitmaps()

2016-12-17 Thread Vladimir Sementsov-Ogievskiy

09.12.2016 20:05, Max Reitz wrote:

On 22.11.2016 18:26, Vladimir Sementsov-Ogievskiy wrote:

Realize block bitmap storing interface, to allow qcow2 images store
persistent bitmaps.

Signed-off-by: Vladimir Sementsov-Ogievskiy
---
  block/qcow2-bitmap.c | 451 +++
  block/qcow2.c|   1 +


[...]


+
+/* store_bitmap_data()
+ * Store bitmap to image, filling bitmap table accordingly.
+ */
+static uint64_t *store_bitmap_data(BlockDriverState *bs,
+   BdrvDirtyBitmap *bitmap,
+   uint32_t *bitmap_table_size, Error **errp)
+{
+int ret;
+BDRVQcow2State *s = bs->opaque;
+int64_t sector;
+uint64_t dsc;
+uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap);
+const char *bm_name = bdrv_dirty_bitmap_name(bitmap);
+uint8_t *buf = NULL;
+BdrvDirtyBitmapIter *dbi;
+uint64_t *tb;
+uint64_t tb_size =
+size_to_clusters(s,
+bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size));
+
+if (tb_size > BME_MAX_TABLE_SIZE ||
+tb_size * s->cluster_size > BME_MAX_PHYS_SIZE) {

Alignment to the opening parenthesis, please.


+error_setg(errp, "Bitmap '%s' is too big", bm_name);
+return NULL;
+}
+
+tb = g_try_new0(uint64_t, tb_size);
+if (tb == NULL) {
+error_setg(errp, "No memory");
+return NULL;
+}
+
+dbi = bdrv_dirty_iter_new(bitmap, 0);
+buf = g_malloc(s->cluster_size);
+dsc = disk_sectors_in_bitmap_cluster(s, bitmap);
+
+while ((sector = bdrv_dirty_iter_next(dbi)) != -1) {
+uint64_t cluster = sector / dsc;
+uint64_t end, write_size;
+int64_t off;
+
+sector = cluster * dsc;
+end = MIN(bm_size, sector + dsc);
+write_size =
+bdrv_dirty_bitmap_serialization_size(bitmap, sector, end - sector);
+
+off = qcow2_alloc_clusters(bs, s->cluster_size);
+if (off < 0) {
+error_setg_errno(errp, -off,
+ "Failed to allocate clusters for bitmap '%s'",
+ bm_name);
+goto fail;
+}
+tb[cluster] = off;

Somehow I would feel better with either an assert(cluster < tb_size);
here or an assert(bdrv_nb_sectors(bs) / dsc == tb_size); (plus the error
handling for bdrv_nb_sectors()) above the loop.


assert((bm_size - 1) / dsc == tb_size - 1) seems ok. and no additional 
error handling. Right?



+
+bdrv_dirty_bitmap_serialize_part(bitmap, buf, sector, end - sector);
+if (write_size < s->cluster_size) {
+memset(buf + write_size, 0, s->cluster_size - write_size);
+}

Should we assert that write_size <= s->cluster_size?


Ok

[...].




+const char *name = bdrv_dirty_bitmap_name(bitmap);
+uint32_t granularity = bdrv_dirty_bitmap_granularity(bitmap);
+Qcow2Bitmap *bm;
+
+if (!bdrv_dirty_bitmap_get_persistance(bitmap)) {
+continue;
+}
+
+if (++new_nb_bitmaps > QCOW2_MAX_BITMAPS) {
+error_setg(errp, "Too many persistent bitmaps");
+goto fail;
+}
+
+new_dir_size += calc_dir_entry_size(strlen(name), 0);
+if (new_dir_size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) {
+error_setg(errp, "Too large bitmap directory");
+goto fail;
+}

You only need to increment new_nb_bitmaps and increase new_dir_size if
the bitmap does not already exist in the image (i.e. if
find_bitmap_by_name() below returns NULL).


Why? No, I need to check the whole sum and the whole size.




+
+if (check_constraints_on_bitmap(bs, name, granularity) < 0) {
+error_setg(errp, "Bitmap '%s' doesn't satisfy the constraints",
+   name);
+goto fail;
+}
+
+bm = find_bitmap_by_name(bm_list, name);
+if (bm == NULL) {
+bm = g_new0(Qcow2Bitmap, 1);
+bm->name = g_strdup(name);
+QSIMPLEQ_INSERT_TAIL(bm_list, bm, entry);
+} else {
+if (!(bm->flags & BME_FLAG_IN_USE) && can_write(bs)) {

Shouldn't we error out right at the beginning of this function if
can_write(bs) is false?


Hmm, right.

[...]

--
Best regards,
Vladimir



Re: [Qemu-devel] [PATCH kernel v5 0/5] Extend virtio-balloon for fast (de)inflating & fast live migration

2016-12-17 Thread Li, Liang Z
> Subject: Re: [Qemu-devel] [PATCH kernel v5 0/5] Extend virtio-balloon for
> fast (de)inflating & fast live migration
> 
> On Thu, Dec 15, 2016 at 05:40:45PM -0800, Dave Hansen wrote:
> > On 12/15/2016 05:38 PM, Li, Liang Z wrote:
> > >
> > > Use 52 bits for 'pfn', 12 bits for 'length', when the 12 bits is not long
> enough for the 'length'
> > > Set the 'length' to a special value to indicate the "actual length in 
> > > next 8
> bytes".
> > >
> > > That will be much more simple. Right?
> >
> > Sounds fine to me.
> >
> 
> Sounds fine to me too indeed.
> 
> I'm only wondering what is the major point for compressing gpfn+len in
> 8 bytes in the common case, you already use sg_init_table to send down two
> pages, we could send three as well and avoid all math and bit shifts and ors,
> or not?
> 

Yes, we can use more pages for that.

> I agree with the above because from a performance prospective I tend to
> think the above proposal will run at least theoretically faster because the
> other way is to waste double amount of CPU cache, and bit mangling in the
> encoding and the later decoding on qemu side should be faster than
> accessing an array of double size, but then I'm not sure if it's measurable
> optimization. So I'd be curious to know the exact motivation and if it is to
> reduce the CPU cache usage or if there's some other fundamental reason to
> compress it.
> The header already tells qemu how big is the array payload, couldn't we just
> add more pages if one isn't enough?
> 

The original intention to compress the PFN and length it's to reduce the memory 
required.
Even the code was changed a lot from the previous versions, I think this is 
still true.

Now we allocate a specified buffer size to save the 'PFN|length', when the 
buffer is not big
enough to save all the page info for a specified order. A double size buffer 
will be allocated.
This is what we want to avoid because the allocation may fail and allocation 
takes some time,
for fast live migration, time is a critical factor we have to consider, more 
time takes means
more unnecessary pages are sent, because live migration starts before the 
request for unused
 pages get response. 

Thanks

Liang

> Thanks,
> Andrea



Re: [Qemu-devel] [PATCH 01/26] Revert "Remove remainders of HPPA backend"

2016-12-17 Thread Peter Maydell
On 16 December 2016 at 19:13, Richard Henderson  wrote:
> This reverts commit d41f3c3cc7a5fb9de144cc4022da14a9ff010671.

Missing signed-off-by.

> ---
>  configure |5 +
>  disas.c   |2 +
>  disas/Makefile.objs   |1 +
>  disas/hppa.c  | 2832 
> +
>  linux-user/syscall_defs.h |4 +-
>  5 files changed, 2842 insertions(+), 2 deletions(-)
>  create mode 100644 disas/hppa.c
>
> diff --git a/configure b/configure
> index f2ba343..6a3ecff 100755
> --- a/configure
> +++ b/configure
> @@ -511,6 +511,8 @@ elif check_define __arm__ ; then
>cpu="arm"
>  elif check_define __aarch64__ ; then
>cpu="aarch64"
> +elif check_define __hppa__ ; then
> +  cpu="hppa"
>  else
>cpu=$(uname -m)
>  fi

This if-ladder is for detecting hppa host CPUs, so you
don't want it for just adding the hppa target support.
Or do you clean this up later in the series so that this
commit is a pure revert?

thanks
-- PMM



Re: [Qemu-devel] [PATCH kernel v5 0/5] Extend virtio-balloon for fast (de)inflating & fast live migration

2016-12-17 Thread Li, Liang Z
> On Fri, Dec 16, 2016 at 01:12:21AM +, Li, Liang Z wrote:
> > There still exist the case if the MAX_ORDER is configured to a large
> > value, e.g. 36 for a system with huge amount of memory, then there is only
> 28 bits left for the pfn, which is not enough.
> 
> Not related to the balloon but how would it help to set MAX_ORDER to 36?
> 

My point here is  MAX_ORDER may be configured to a big value.

> What the MAX_ORDER affects is that you won't be able to ask the kernel
> page allocator for contiguous memory bigger than 1<<(MAX_ORDER-1), but
> that's a driver issue not relevant to the amount of RAM. Drivers won't
> suddenly start to ask the kernel allocator to allocate compound pages at
> orders >= 11 just because more RAM was added.
> 
> The higher the MAX_ORDER the slower the kernel runs simply so the smaller
> the MAX_ORDER the better.
> 
> > Should  we limit the MAX_ORDER? I don't think so.
> 
> We shouldn't strictly depend on MAX_ORDER value but it's mostly limited
> already even if configurable at build time.
> 

I didn't know that and will take a look, thanks for your information.


Liang
> We definitely need it to reach at least the hugepage size, then it's mostly
> driver issue, but drivers requiring large contiguous allocations should rely 
> on
> CMA only or vmalloc if they only require it virtually contiguous, and not rely
> on larger MAX_ORDER that would slowdown all kernel allocations/freeing.



Re: [Qemu-devel] [PATCH v1 00/37] Implementation of vhost-pci for inter-vm commucation

2016-12-17 Thread no-reply
Hi,

Your series failed automatic build test. Please find the testing commands and
their output below. If you have docker installed, you can probably reproduce it
locally.

Type: series
Subject: [Qemu-devel] [PATCH v1 00/37] Implementation of vhost-pci for inter-vm 
commucation
Message-id: 1481971427-11094-1-git-send-email-wei.w.w...@intel.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash
set -e
git submodule update --init dtc
# Let docker tests dump environment info
export SHOW_ENV=1
export J=16
make docker-test-quick@centos6
make docker-test-mingw@fedora
make docker-test-build@min-glib
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
b0804ed vl: enable vhost-pci-slave
6817843 vhost-user/msg: handling VHOST_USER_SET_FEATURES
5625ffb vhost-pci-net: start the vhost-pci-net device
a234ebe vhost-pci-slave: add "peer_reset"
2de6ab3 vhost-pci-net: send the negotiated feature bits to the master
4d698f6 vhost-user: add asynchronous read for the vhost-user master
25162f6 vhost-user/msg: send VHOST_USER_SET_VHOST_PCI (start/stop)
bafef20 vhost-pci-slave/msg: VHOST_USER_SET_VHOST_PCI (stop)
7d9fcd4 vhost-pci-slave/msg: VHOST_USER_SET_VHOST_PCI (start)
e037343 vhost-pci-net: pass the mem and vring info to the driver
9518b5d vhost-pci-net: pass the info collected by vp_slave to the device
99b1f40 vhost-pci-slave/msg: VHOST_USER_GET_VRING_BASE
976ac97 vhost-pci-slave/msg: VHOST_USER_SEND_RARP
683f514 vhost-pci-slave/msg: VHOST_USER_SET_LOG_FD
ec7ff39 vhost-pci-slave/msg: VHOST_USER_SET_LOG_BASE
597e3d1 vhost-pci-slave/msg: VHOST_USER_SET_VRING_ENABLE
96d8ed7 vhost-pci-slave/msg: VHOST_USER_SET_VRING_CALL
7bea32f vhost-pci-slave/msg: VHOST_USER_SET_VRING_KICK
78e4d19 vhost-pci-slave/msg: VHOST_USER_SET_VRING_ADDR
cad137a vhost-user: send guest physical address of virtqueues to the slave
06ca090 vhost-pci-slave/msg: VHOST_USER_SET_VRING_BASE
450f521 vhost-pci-slave/msg: VHOST_USER_SET_VRING_NUM
396bda9 vhost-pci-slave/msg: VHOST_USER_SET_MEM_TABLE
9b22d68 vhost-pci-slave/msg: VHOST_USER_SET_OWNER
c8f6463 vhost-pci-slave/msg: VHOST_USER_GET_QUEUE_NUM
2971089 vhost-pci-slave/msg: VHOST_USER_SET_DEVICE_ID
ad3e6ee vhost-user/msg: VHOST_USER_PROTOCOL_F_SET_DEVICE_ID
c1cd46a vhost-pci-slave/msg: VHOST_USER_SET_PROTOCOL_FEATURES
ec6ae04 vhost-pci-slave/msg: VHOST_USER_GET_PROTOCOL_FEATURES
35242dd vhost-pci-slave/msg: VHOST_USER_SET_FEATURES
ddda2fb vhost-pci-slave/msg: VHOST_USER_GET_FEATURES
b168748 vhost-pci-slave: set up the fundamental handlers for the server socket
9eaf436 vhost-pci-slave: start the implementation of vhost-pci-slave
798c50f vl: add the vhost-pci-slave command line option
2b7ed80 vhost-user: share the vhost-user protocol related structures
6b83939 vhost-pci-net: the fundamental implementation of vhost-pci-net-pci
94d5a87 vhost-pci-net: the fundamental vhost-pci-net device emulation

=== OUTPUT BEGIN ===
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc'
Cloning into 'dtc'...
Submodule path 'dtc': checked out '65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf'
  BUILD   centos6
make[1]: Entering directory `/var/tmp/patchew-tester-tmp-ff527md2/src'
  ARCHIVE qemu.tgz
  ARCHIVE dtc.tgz
  COPYRUNNER
RUN test-quick in qemu:centos6 
Packages installed:
SDL-devel-1.2.14-7.el6_7.1.x86_64
ccache-3.1.6-2.el6.x86_64
epel-release-6-8.noarch
gcc-4.4.7-17.el6.x86_64
git-1.7.1-4.el6_7.1.x86_64
glib2-devel-2.28.8-5.el6.x86_64
libfdt-devel-1.4.0-1.el6.x86_64
make-3.81-23.el6.x86_64
package g++ is not installed
pixman-devel-0.32.8-1.el6.x86_64
tar-1.23-15.el6_8.x86_64
zlib-devel-1.2.3-29.el6.x86_64

Environment variables:
PACKAGES=libfdt-devel ccache tar git make gcc g++ zlib-devel 
glib2-devel SDL-devel pixman-devel epel-release
HOSTNAME=583fb81d8e2e
TERM=xterm
MAKEFLAGS= -j16
HISTSIZE=1000
J=16
USER=root
CCACHE_DIR=/var/tmp/ccache
EXTRA_CONFIGURE_OPTS=
V=
SHOW_ENV=1
MAIL=/var/spool/mail/root
PATH=/usr/lib/ccache:/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
LANG=en_US.UTF-8
TARGET_LIST=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
TEST_DIR=/tmp/qemu-test
LOGNAME=root
LESSOPEN=||/usr/bin/lesspipe.sh %s
FEATURES= dtc
DEBUG=
G_BROKEN_FILENAMES=1
CCACHE_HASHDIR=
_=/usr/bin/env

Configure options:
--enable-werror --target-list=x86_64-softmmu,aarch64-softmmu 
--prefix=/var/tmp/qemu-build/install
No C++ compiler available; disabling C++ specific optional code
Install prefix/var/tmp/qemu-build/install
BIOS directory/var/tmp/qemu-build/install/share/qemu
binary directory  /var/tmp/qemu-build/install/bin
library directory /var/tmp/qemu-build/install/lib
module directory  /var/tmp/qemu-build/install/lib/qemu
libexec directory /var/tmp/qemu-build/install/libexec
include directory /var/tmp/qemu-build/install/include
config directory  /var/tmp/qemu-build/install/etc
local state directory   /var/tmp/qemu-build/install/var
Manual directory  /var/tmp/qemu-build/install/share/man
ELF interp prefix 

Re: [Qemu-devel] [PATCH v1 00/37] Implementation of vhost-pci for inter-vm commucation

2016-12-17 Thread no-reply
Hi,

Your series seems to have some coding style problems. See output below for
more information:

Type: series
Subject: [Qemu-devel] [PATCH v1 00/37] Implementation of vhost-pci for inter-vm 
commucation
Message-id: 1481971427-11094-1-git-send-email-wei.w.w...@intel.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag] 
patchew/1481971427-11094-1-git-send-email-wei.w.w...@intel.com -> 
patchew/1481971427-11094-1-git-send-email-wei.w.w...@intel.com
Switched to a new branch 'test'
b0804ed vl: enable vhost-pci-slave
6817843 vhost-user/msg: handling VHOST_USER_SET_FEATURES
5625ffb vhost-pci-net: start the vhost-pci-net device
a234ebe vhost-pci-slave: add "peer_reset"
2de6ab3 vhost-pci-net: send the negotiated feature bits to the master
4d698f6 vhost-user: add asynchronous read for the vhost-user master
25162f6 vhost-user/msg: send VHOST_USER_SET_VHOST_PCI (start/stop)
bafef20 vhost-pci-slave/msg: VHOST_USER_SET_VHOST_PCI (stop)
7d9fcd4 vhost-pci-slave/msg: VHOST_USER_SET_VHOST_PCI (start)
e037343 vhost-pci-net: pass the mem and vring info to the driver
9518b5d vhost-pci-net: pass the info collected by vp_slave to the device
99b1f40 vhost-pci-slave/msg: VHOST_USER_GET_VRING_BASE
976ac97 vhost-pci-slave/msg: VHOST_USER_SEND_RARP
683f514 vhost-pci-slave/msg: VHOST_USER_SET_LOG_FD
ec7ff39 vhost-pci-slave/msg: VHOST_USER_SET_LOG_BASE
597e3d1 vhost-pci-slave/msg: VHOST_USER_SET_VRING_ENABLE
96d8ed7 vhost-pci-slave/msg: VHOST_USER_SET_VRING_CALL
7bea32f vhost-pci-slave/msg: VHOST_USER_SET_VRING_KICK
78e4d19 vhost-pci-slave/msg: VHOST_USER_SET_VRING_ADDR
cad137a vhost-user: send guest physical address of virtqueues to the slave
06ca090 vhost-pci-slave/msg: VHOST_USER_SET_VRING_BASE
450f521 vhost-pci-slave/msg: VHOST_USER_SET_VRING_NUM
396bda9 vhost-pci-slave/msg: VHOST_USER_SET_MEM_TABLE
9b22d68 vhost-pci-slave/msg: VHOST_USER_SET_OWNER
c8f6463 vhost-pci-slave/msg: VHOST_USER_GET_QUEUE_NUM
2971089 vhost-pci-slave/msg: VHOST_USER_SET_DEVICE_ID
ad3e6ee vhost-user/msg: VHOST_USER_PROTOCOL_F_SET_DEVICE_ID
c1cd46a vhost-pci-slave/msg: VHOST_USER_SET_PROTOCOL_FEATURES
ec6ae04 vhost-pci-slave/msg: VHOST_USER_GET_PROTOCOL_FEATURES
35242dd vhost-pci-slave/msg: VHOST_USER_SET_FEATURES
ddda2fb vhost-pci-slave/msg: VHOST_USER_GET_FEATURES
b168748 vhost-pci-slave: set up the fundamental handlers for the server socket
9eaf436 vhost-pci-slave: start the implementation of vhost-pci-slave
798c50f vl: add the vhost-pci-slave command line option
2b7ed80 vhost-user: share the vhost-user protocol related structures
6b83939 vhost-pci-net: the fundamental implementation of vhost-pci-net-pci
94d5a87 vhost-pci-net: the fundamental vhost-pci-net device emulation

=== OUTPUT BEGIN ===
Checking PATCH 1/37: vhost-pci-net: the fundamental vhost-pci-net device 
emulation...
WARNING: line over 80 characters
#64: FILE: hw/net/vhost-pci-net.c:35:
+static uint64_t vpnet_get_features(VirtIODevice *vdev, uint64_t features, 
Error **errp)

ERROR: space required after that ',' (ctx:VxV)
#103: FILE: hw/net/vhost-pci-net.c:74:
+vpnet->rqs[i] = virtio_add_queue(vdev,VPNET_RQ_SIZE,
  ^

ERROR: braces {} are necessary even for single statement blocks
#115: FILE: hw/net/vhost-pci-net.c:86:
+for (i = 0; i < rq_num + 2; i++)
+virtio_del_queue(vdev, i);

total: 2 errors, 1 warnings, 256 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 2/37: vhost-pci-net: the fundamental implementation of 
vhost-pci-net-pci...
Checking PATCH 3/37: vhost-user: share the vhost-user protocol related 
structures...
ERROR: spaces required around that '<<' (ctx:VxV)
#189: FILE: include/hw/virtio/vhost-user.h:66:
+#define VHOST_USER_REPLY_MASK   (0x1<<2)
 ^

ERROR: spaces required around that '<<' (ctx:VxV)
#195: FILE: include/hw/virtio/vhost-user.h:72:
+#define VHOST_USER_VRING_NOFD_MASK  (0x1<<8)
 ^

total: 2 errors, 0 warnings, 200 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 4/37: vl: add the vhost-pci-slave command line option...
ERROR: line over 90 characters
#67: FILE: vl.c:4063:
+

[Qemu-devel] [PATCH v1 37/37] vl: enable vhost-pci-slave

2016-12-17 Thread Wei Wang
Enable vhost-pci-slave in vl.c

Signed-off-by: Wei Wang 
---
 vl.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/vl.c b/vl.c
index 10d7f89..6959dba 100644
--- a/vl.c
+++ b/vl.c
@@ -123,6 +123,7 @@ int main(int argc, char **argv)
 #include "sysemu/replay.h"
 #include "qapi/qmp/qerror.h"
 #include "sysemu/iothread.h"
+#include "hw/virtio/vhost-pci-slave.h"
 
 #define MAX_VIRTIO_CONSOLES 1
 #define MAX_SCLP_CONSOLES 1
@@ -180,6 +181,7 @@ bool boot_strict;
 uint8_t *boot_splash_filedata;
 size_t boot_splash_filedata_size;
 uint8_t qemu_extra_params_fw[2];
+bool vhost_pci_slave_enabled;
 
 int icount_align_option;
 
@@ -4064,6 +4066,7 @@ int main(int argc, char **argv, char **envp)
 if (!opts) {
 exit(1);
 }
+vhost_pci_slave_enabled = true;
 break;
 default:
 os_parse_cmd_args(popt->index, optarg);
@@ -4581,6 +4584,16 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
+/* check if the vhost-pci-server is enabled */
+if (vhost_pci_slave_enabled) {
+int ret;
+ret = vhost_pci_slave_init(qemu_opts_find(
+qemu_find_opts("vhost-pci-slave"),
+NULL));
+if (ret < 0)
+exit(1);
+}
+
 /* init USB devices */
 if (machine_usb(current_machine)) {
 if (foreach_device_config(DEV_USB, usb_parse) < 0)
@@ -4710,6 +4723,13 @@ int main(int argc, char **argv, char **envp)
 pause_all_vcpus();
 res_free();
 
+if (vhost_pci_slave_enabled) {
+int ret;
+ret = vhost_pci_slave_cleanup();
+if (ret < 0)
+exit(1);
+}
+
 /* vhost-user must be cleaned up before chardevs.  */
 net_cleanup();
 audio_cleanup();
-- 
2.7.4




[Qemu-devel] [PATCH v1 34/37] vhost-pci-slave: add "peer_reset"

2016-12-17 Thread Wei Wang
Setting "peer_reset" flags that the peer device is about to be reset.
This happens when the slave side device driver only accepts a subset
of the feature bits offered by the peer device.

The peer device is expected to have a second run of the vhost-user
protocol for the re-setup.

Signed-off-by: Wei Wang 
---
 hw/net/vhost-pci-net.c  |  4 
 hw/virtio/vhost-pci-slave.c | 17 +++--
 include/hw/virtio/vhost-pci-slave.h |  1 +
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c
index 567fb86..6d4db6c 100644
--- a/hw/net/vhost-pci-net.c
+++ b/hw/net/vhost-pci-net.c
@@ -141,6 +141,10 @@ static void vpnet_set_features(VirtIODevice *vdev, 
uint64_t features)
 int ret;
 
 if (need_send) {
+if (vp_slave->feature_bits != features) {
+vp_slave->feature_bits = features;
+vp_slave->peer_reset = 1;
+}
 need_send = 0;
 ret = vp_slave_send_feature_bits(features);
 if (ret < 0)
diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index d3c3443..5cfa335 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -37,6 +37,14 @@ static void vp_slave_cleanup(void)
 if (!vp_slave->vdev)
 return;
 
+/*
+ * if this cleanup is not invoked due to peer reset, re-initialize
+ * the feature bits, so that the slave can work with a new master
+ */
+if (!vp_slave->peer_reset)
+vp_slave->feature_bits =
+1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
+
 nregions = vp_slave->pmem_msg.nregions;
 for (i = 0; i < nregions; i++) {
 ret = munmap(vp_slave->mr_map_base[i], vp_slave->mr_map_size[i]);
@@ -163,8 +171,10 @@ static void vp_slave_set_device_type(VhostUserMsg *msg)
 
 switch (vp_slave->dev_type) {
 case VIRTIO_ID_NET:
-vp_slave->feature_bits |= (VHOST_PCI_FEATURE_BITS
-   | VHOST_PCI_NET_FEATURE_BITS);
+/* Don't initialize the feature bits if they have been negotiated */
+if (!vp_slave->peer_reset)
+vp_slave->feature_bits |= (VHOST_PCI_FEATURE_BITS
+   | VHOST_PCI_NET_FEATURE_BITS);
 break;
 default:
 error_report("device type %d is not supported", vp_slave->dev_type);
@@ -351,6 +361,8 @@ static int vp_slave_set_vhost_pci(CharBackend *chr_be, 
VhostUserMsg *msg)
 
 switch (cmd) {
 case VHOST_USER_SET_VHOST_PCI_start:
+if (vp_slave->peer_reset)
+vp_slave->peer_reset = 0;
 ret = vp_slave_device_create(vp_slave->dev_type);
 if (ret < 0)
 return ret;
@@ -519,6 +531,7 @@ int vhost_pci_slave_init(QemuOpts *opts)
 vp_slave->sub_mr = NULL;
 QLIST_INIT(_slave->pvq_list);
 vp_slave->pvq_num = 0;
+vp_slave->peer_reset = 0;
 qemu_chr_fe_init(_slave->chr_be, chr, _abort);
 qemu_chr_fe_set_handlers(_slave->chr_be, vp_slave_can_read,
  vp_slave_read, vp_slave_event,
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index e60580a..dd78ed4 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -21,6 +21,7 @@ typedef struct VhostPCISlave {
 CharBackend chr_be;
 /* Ponnter to the slave device */
 VirtIODevice *vdev;
+bool peer_reset;
 uint16_t dev_type;
 uint64_t feature_bits;
 /* hotplugged memory should be mapped following the offset */
-- 
2.7.4




[Qemu-devel] [PATCH v1 36/37] vhost-user/msg: handling VHOST_USER_SET_FEATURES

2016-12-17 Thread Wei Wang
If the featuer bits sent by the slave are not equal to the ones that
were sent by the master, perform a reset of the master device.

Signed-off-by: Wei Wang 
---
 hw/net/vhost_net.c   |  2 ++
 hw/virtio/vhost-user.c   | 19 +++
 hw/virtio/virtio-pci.c   | 20 
 hw/virtio/virtio-pci.h   |  2 ++
 include/net/vhost-user.h | 14 ++
 net/vhost-user.c | 14 +-
 6 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 7f64be3..b8dbc61 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -348,6 +348,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 goto err_start;
 }
 
+vhost_user_set_master_dev(ncs[0].peer, dev);
+
 return 0;
 
 err_start:
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 800b8ed..08d5e86 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -12,6 +12,7 @@
 #include "qapi/error.h"
 #include "hw/virtio/vhost.h"
 #include "hw/virtio/vhost-backend.h"
+#include "hw/virtio/virtio-pci.h"
 #include "hw/virtio/vhost-user.h"
 #include "hw/virtio/virtio-net.h"
 #include "net/vhost-user.h"
@@ -75,6 +76,21 @@ fail:
 return -1;
 }
 
+static void handle_slave_acked_features(const char *name, VhostUserMsg *msg)
+{
+CharBackend *chr_be = net_name_to_chr_be(name);
+VhostUserState *s = container_of(chr_be, VhostUserState, chr);
+VirtIODevice *vdev = s->vdev;
+uint64_t master_features, slave_features;
+
+master_features = vhost_net_get_acked_features(s->vhost_net)
+  & ~(1 << VHOST_USER_F_PROTOCOL_FEATURES);
+slave_features = msg->payload.u64;
+
+if (master_features != slave_features)
+master_reset_virtio_net(vdev);
+}
+
 int vhost_user_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -108,6 +124,9 @@ void vhost_user_asyn_read(void *opaque, const uint8_t *buf, 
int size)
 error_report("vhost-user master read incorrect msg \n");
 
 switch(msg.request) {
+case VHOST_USER_SET_FEATURES:
+handle_slave_acked_features(name, );
+break;
 default:
 error_report("vhost-user master does not support msg request = %d\n",
  msg.request);
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 20cbefc..82b2920 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -38,6 +38,7 @@
 #include "qemu/range.h"
 #include "hw/virtio/virtio-bus.h"
 #include "qapi/visitor.h"
+#include "monitor/qdev.h"
 
 #define VIRTIO_PCI_REGION_SIZE(dev) 
VIRTIO_PCI_CONFIG_OFF(msix_present(dev))
 
@@ -2257,6 +2258,25 @@ static const TypeInfo virtio_serial_pci_info = {
 
 /* virtio-net-pci */
 
+void master_reset_virtio_net(VirtIODevice *vdev)
+{
+VirtIONet *net = VIRTIO_NET(vdev);
+VirtIONetPCI *net_pci = container_of(net, VirtIONetPCI, vdev);
+VirtIOPCIProxy *proxy = _pci->parent_obj;
+DeviceState *qdev = DEVICE(proxy);
+DeviceState *qdev_new;
+Error *err = NULL;
+
+virtio_pci_reset(qdev);
+qdev_unplug(qdev, );
+qdev->realized = false;
+qdev_new = qdev_device_add(qdev->opts, );
+if (!qdev_new) {
+qemu_opts_del(qdev->opts);
+}
+object_unref(OBJECT(qdev));
+}
+
 static Property virtio_net_properties[] = {
 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 0b4b04f..c41c621 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -383,4 +383,6 @@ struct VirtIOCryptoPCI {
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION  0
 
+void master_reset_virtio_net(VirtIODevice *vdev);
+
 #endif
diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h
index 1bb5f1a..4cd14c9 100644
--- a/include/net/vhost-user.h
+++ b/include/net/vhost-user.h
@@ -12,6 +12,18 @@
 #define NET_VHOST_USER_H
 
 #include "sysemu/char.h"
+#include "net/vhost_net.h"
+
+typedef struct VhostUserState {
+NetClientState nc;
+CharBackend chr; /* only queue index 0 */
+VHostNetState *vhost_net;
+guint watch;
+uint64_t acked_features;
+bool started;
+/* Pointer to the master device */
+VirtIODevice *vdev;
+} VhostUserState;
 
 struct vhost_net;
 struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc);
@@ -19,4 +31,6 @@ uint64_t vhost_user_get_acked_features(NetClientState *nc);
 
 CharBackend *net_name_to_chr_be(const char *name);
 
+void vhost_user_set_master_dev(NetClientState *nc, VirtIODevice *vdev);
+
 #endif /* VHOST_USER_H */
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 58eee6a..5f4b568 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -10,7 +10,6 @@
 
 #include "qemu/osdep.h"
 #include "clients.h"
-#include "net/vhost_net.h"
 #include "net/vhost-user.h"
 #include 

[Qemu-devel] [PATCH v1 35/37] vhost-pci-net: start the vhost-pci-net device

2016-12-17 Thread Wei Wang
If the peer device on the other side doesn't need to be reset, then
start the device when DRIVER_OK is received.

Signed-off-by: Wei Wang 
---
 hw/net/vhost-pci-net.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c
index 6d4db6c..75ee72c 100644
--- a/hw/net/vhost-pci-net.c
+++ b/hw/net/vhost-pci-net.c
@@ -22,6 +22,16 @@
 #define VPNET_CQ_SIZE 32
 #define VPNET_RQ_SIZE 256
 
+static void vpnet_set_link_up(VhostPCINet *vpnet)
+{
+VirtIODevice *vdev = VIRTIO_DEVICE(vpnet);
+uint16_t old_status = vpnet->status;
+
+vpnet->status |= VPNET_S_LINK_UP;
+if (vpnet->status != old_status)
+virtio_notify_config(vdev);
+}
+
 void vpnet_set_peer_vq_num(VhostPCINet *vpnet, uint16_t num)
 {
 vpnet->peer_vq_num = num;
@@ -125,6 +135,11 @@ static void vpnet_set_status(struct VirtIODevice *vdev, 
uint8_t status)
 if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
 vpnet_send_peer_mem_msg(vpnet);
 vpnet_send_peer_vq_msg(vpnet);
+/* If the peer device is not reset, start the device now */
+if (!vp_slave->peer_reset) {
+vdev->status = status;
+vpnet_set_link_up(vpnet);
+}
 }
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH v1 26/37] vhost-pci-slave/msg: VHOST_USER_GET_VRING_BASE

2016-12-17 Thread Wei Wang
Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 1957d3f..cdeb710 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -217,6 +217,16 @@ static void vp_slave_set_vring_base(VhostUserMsg *msg)
 pvq_node->last_avail_idx = msg->payload.u64;
 }
 
+static int vp_slave_get_vring_base(CharBackend *chr_be, VhostUserMsg *msg)
+{
+/* send back vring base to qemu */
+msg->flags |= VHOST_USER_REPLY_MASK;
+msg->size = sizeof(m.payload.state);
+msg->payload.state.num = 0;
+
+return vp_slave_write(chr_be, msg);
+}
+
 static void vp_slave_set_vring_addr(VhostUserMsg *msg)
 {
 PeerVqNode *pvq_node = QLIST_FIRST(_slave->pvq_list);
@@ -319,6 +329,11 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
 case VHOST_USER_SET_VRING_BASE:
 vp_slave_set_vring_base();
 break;
+case VHOST_USER_GET_VRING_BASE:
+ret = vp_slave_get_vring_base(chr_be, );
+if (ret < 0)
+goto err_handling;
+break;
 case VHOST_USER_SET_VRING_ADDR:
 vp_slave_set_vring_addr();
 break;
-- 
2.7.4




[Qemu-devel] [PATCH v1 33/37] vhost-pci-net: send the negotiated feature bits to the master

2016-12-17 Thread Wei Wang
The slave actively sends the negotiated feature bits to the master.
"need_send" is used to detect if the 64-bit feature bits are ready to
be sent.

Signed-off-by: Wei Wang 
---
 hw/net/vhost-pci-net.c  | 12 
 hw/virtio/vhost-pci-slave.c | 21 +
 include/hw/virtio/vhost-pci-slave.h |  2 ++
 3 files changed, 35 insertions(+)

diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c
index 0198686..567fb86 100644
--- a/hw/net/vhost-pci-net.c
+++ b/hw/net/vhost-pci-net.c
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/iov.h"
+#include "qemu/error-report.h"
 #include "hw/virtio/virtio-access.h"
 #include "hw/virtio/vhost-pci-net.h"
 
@@ -136,6 +137,17 @@ static uint64_t vpnet_get_features(VirtIODevice *vdev, 
uint64_t features, Error
 
 static void vpnet_set_features(VirtIODevice *vdev, uint64_t features)
 {
+static bool need_send;
+int ret;
+
+if (need_send) {
+need_send = 0;
+ret = vp_slave_send_feature_bits(features);
+if (ret < 0)
+error_report("failed to send feature bits to the master");
+} else {
+need_send = 1;
+}
 }
 
 static void vpnet_get_config(VirtIODevice *vdev, uint8_t *config)
diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 427d618..d3c3443 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -85,6 +85,27 @@ static void vp_slave_set_features(VhostUserMsg *msg)
  & ~(1 << VHOST_USER_F_PROTOCOL_FEATURES);
 }
 
+static int vp_slave_send_u64(int request, uint64_t u64)
+{
+VhostUserMsg msg = {
+.request = request,
+.flags = VHOST_USER_VERSION,
+.payload.u64 = u64,
+.size = sizeof(msg.payload.u64),
+};
+
+if (vp_slave_write(_slave->chr_be, ) < 0) {
+return -1;
+}
+
+return 0;
+}
+
+int vp_slave_send_feature_bits(uint64_t features)
+{
+return vp_slave_send_u64(VHOST_USER_SET_FEATURES, features);
+}
+
 static DeviceState *virtio_to_pci_dev(VirtIODevice *vdev, uint16_t virtio_id)
 {
 DeviceState *qdev;
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index 79e1ffd..e60580a 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -40,4 +40,6 @@ extern int vhost_pci_slave_init(QemuOpts *opts);
 
 extern int vhost_pci_slave_cleanup(void);
 
+extern int vp_slave_send_feature_bits(uint64_t features);
+
 #endif
-- 
2.7.4




[Qemu-devel] [PATCH v1 32/37] vhost-user: add asynchronous read for the vhost-user master

2016-12-17 Thread Wei Wang
Enable the vhost-user master to asynchronously receive messages
from the slave.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-user.c | 42 +-
 include/hw/virtio/vhost-user.h |  4 
 include/net/vhost-user.h   |  4 
 net/vhost-user.c   | 20 ++--
 4 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index ce92140..800b8ed 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -14,7 +14,7 @@
 #include "hw/virtio/vhost-backend.h"
 #include "hw/virtio/vhost-user.h"
 #include "hw/virtio/virtio-net.h"
-#include "sysemu/char.h"
+#include "net/vhost-user.h"
 #include "sysemu/kvm.h"
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
@@ -75,6 +75,46 @@ fail:
 return -1;
 }
 
+int vhost_user_can_read(void *opaque)
+{
+return VHOST_USER_HDR_SIZE;
+}
+
+void vhost_user_asyn_read(void *opaque, const uint8_t *buf, int size)
+{
+const char *name = opaque;
+VhostUserMsg msg;
+uint8_t *p = (uint8_t *) 
+CharBackend *chr_be = net_name_to_chr_be(name);
+
+if (size != VHOST_USER_HDR_SIZE) {
+error_report("Wrong message size received %d\n", size);
+return;
+}
+
+memcpy(p, buf, VHOST_USER_HDR_SIZE);
+
+if (msg.size) {
+p += VHOST_USER_HDR_SIZE;
+size = qemu_chr_fe_read_all(chr_be, p, msg.size);
+if (size != msg.size) {
+error_report("Wrong message size received %d != %d\n",
+   size, msg.size);
+return;
+}
+}
+
+if (msg.request > VHOST_USER_MAX)
+error_report("vhost-user master read incorrect msg \n");
+
+switch(msg.request) {
+default:
+error_report("vhost-user master does not support msg request = %d\n",
+ msg.request);
+break;
+}
+}
+
 static int process_message_reply(struct vhost_dev *dev,
  VhostUserRequest request)
 {
diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h
index 12e4dc9..142ea52 100644
--- a/include/hw/virtio/vhost-user.h
+++ b/include/hw/virtio/vhost-user.h
@@ -102,4 +102,8 @@ static VhostUserMsg m __attribute__ ((unused));
 /* The version of the protocol we support */
 #define VHOST_USER_VERSION(0x1)
 
+int vhost_user_can_read(void *opaque);
+
+void vhost_user_asyn_read(void *opaque, const uint8_t *buf, int size);
+
 #endif
diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h
index d9e328d..1bb5f1a 100644
--- a/include/net/vhost-user.h
+++ b/include/net/vhost-user.h
@@ -11,8 +11,12 @@
 #ifndef NET_VHOST_USER_H
 #define NET_VHOST_USER_H
 
+#include "sysemu/char.h"
+
 struct vhost_net;
 struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc);
 uint64_t vhost_user_get_acked_features(NetClientState *nc);
 
+CharBackend *net_name_to_chr_be(const char *name);
+
 #endif /* VHOST_USER_H */
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 7aff77e..58eee6a 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -12,7 +12,7 @@
 #include "clients.h"
 #include "net/vhost_net.h"
 #include "net/vhost-user.h"
-#include "sysemu/char.h"
+#include "hw/virtio/vhost-user.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "qmp-commands.h"
@@ -190,6 +190,22 @@ static gboolean net_vhost_user_watch(GIOChannel *chan, 
GIOCondition cond,
 return FALSE;
 }
 
+CharBackend *net_name_to_chr_be(const char *name)
+{
+NetClientState *ncs[MAX_QUEUE_NUM];
+VhostUserState *s;
+int queues;
+
+queues = qemu_find_net_clients_except(name, ncs,
+  NET_CLIENT_DRIVER_NIC,
+  MAX_QUEUE_NUM);
+assert(queues < MAX_QUEUE_NUM);
+
+s = DO_UPCAST(VhostUserState, nc, ncs[0]);
+
+return >chr;
+}
+
 static void net_vhost_user_event(void *opaque, int event)
 {
 const char *name = opaque;
@@ -265,7 +281,7 @@ static int net_vhost_user_init(NetClientState *peer, const 
char *device,
 error_report_err(err);
 return -1;
 }
-qemu_chr_fe_set_handlers(>chr, NULL, NULL,
+qemu_chr_fe_set_handlers(>chr, vhost_user_can_read, 
vhost_user_asyn_read,
  net_vhost_user_event, nc0->name, NULL, true);
 } while (!s->started);
 
-- 
2.7.4




[Qemu-devel] [PATCH v1 21/37] vhost-pci-slave/msg: VHOST_USER_SET_VRING_CALL

2016-12-17 Thread Wei Wang
Update the callfd to the head node in the list.

This version of vhost-pci expects the master device to use polling
to receive packets, so callfd is recorded here for tomorrow's
implementation.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 18 ++
 include/hw/virtio/vhost-pci-slave.h |  1 +
 2 files changed, 19 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index dff1c88..e176d59 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -231,6 +231,13 @@ static void vp_slave_set_vring_kick(int fd)
 pvq_node->kickfd = fd;
 }
 
+static void vp_slave_set_vring_call(int fd)
+{
+PeerVqNode *pvq_node = QLIST_FIRST(_slave->pvq_list);
+if (pvq_node)
+pvq_node->callfd = fd;
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -314,6 +321,17 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
  */
 qemu_set_nonblock(fds[0]);
 break;
+case VHOST_USER_SET_VRING_CALL:
+/* consume the fd */
+qemu_chr_fe_get_msgfds(chr_be, fds, 1);
+vp_slave_set_vring_call(fds[0]);
+/*
+ * This is a non-blocking eventfd.
+ * The receive function forces it to be blocking,
+ * so revert it back to non-blocking.
+ */
+qemu_set_nonblock(fds[0]);
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index 4b6b213..f6206a1 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -11,6 +11,7 @@ typedef struct PeerVqNode {
 uint16_t last_avail_idx;
 uint32_t vring_num;
 int kickfd;
+int callfd;
 struct vhost_vring_addr addr;
 QLIST_ENTRY(PeerVqNode) node;
 } PeerVqNode;
-- 
2.7.4




Re: [Qemu-devel] [PULL for-2.9 0/9] virtio, vhost, pc: fixes

2016-12-17 Thread Peter Maydell
On 16 December 2016 at 21:32,   wrote:
> Your series seems to have some coding style problems. See output below for
> more information:
>
> Type: series
> Subject: [Qemu-devel] [PULL for-2.9 0/9] virtio, vhost, pc: fixes
> Message-id: 1481922841-4324-1-git-send-email-...@redhat.com

> Checking PATCH 5/9: contrib: add libvhost-user...
> ERROR: Invalid UTF-8, patch and commit message should be encoded in UTF-8
> #75: FILE: contrib/libvhost-user/libvhost-user.c:9:
> + *  Marc-Andr Lureau 
>   ^
>
> ERROR: Invalid UTF-8, patch and commit message should be encoded in UTF-8
> #1579: FILE: contrib/libvhost-user/libvhost-user.h:8:
> + *  Marc-Andr Lureau 
>   ^
>
> total: 2 errors, 0 warnings, 1950 lines checked

Michael, could you check the encoding in that file and respin
the patchset if necessary, please?

thanks
-- PMM



[Qemu-devel] [PATCH v1 30/37] vhost-pci-slave/msg: VHOST_USER_SET_VHOST_PCI (stop)

2016-12-17 Thread Wei Wang
The slave removes the slave device when receiving the request with the
stop command.

In the case that the master side guest crashes, the crashed guest, typically,
will be killed by the admin. This event will be captured via the close of the
socket connection, so we can remove the vhost-pci device and free the related
resources there.

Signed-off-by: Wei Wang 
---
 hw/net/vhost-pci-net.c  |  1 +
 hw/virtio/vhost-pci-slave.c | 40 +
 include/hw/virtio/vhost-pci-slave.h |  2 ++
 3 files changed, 43 insertions(+)

diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c
index d8b13c8..0198686 100644
--- a/hw/net/vhost-pci-net.c
+++ b/hw/net/vhost-pci-net.c
@@ -170,6 +170,7 @@ static void vpnet_device_realize(DeviceState *dev, Error 
**errp)
  vpnet_handle_rq);
 }
 vpnet->status = 0;
+vp_slave->vdev = vdev;
 }
 
 static void vpnet_device_unrealize(DeviceState *dev, Error **errp)
diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 73d3f71..427d618 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -34,6 +34,9 @@ static void vp_slave_cleanup(void)
 uint32_t i, nregions;
 PeerVqNode *pvq_node;
 
+if (!vp_slave->vdev)
+return;
+
 nregions = vp_slave->pmem_msg.nregions;
 for (i = 0; i < nregions; i++) {
 ret = munmap(vp_slave->mr_map_base[i], vp_slave->mr_map_size[i]);
@@ -48,6 +51,7 @@ static void vp_slave_cleanup(void)
 }
 QLIST_INIT(_slave->pvq_list);
 vp_slave->pvq_num = 0;
+vp_slave->vdev = NULL;
 }
 
 static int vp_slave_write(CharBackend *chr_be, VhostUserMsg *msg)
@@ -81,12 +85,44 @@ static void vp_slave_set_features(VhostUserMsg *msg)
  & ~(1 << VHOST_USER_F_PROTOCOL_FEATURES);
 }
 
+static DeviceState *virtio_to_pci_dev(VirtIODevice *vdev, uint16_t virtio_id)
+{
+DeviceState *qdev;
+VhostPCINet *vpnet;
+VhostPCINetPCI *netpci;
+
+switch (virtio_id) {
+case VIRTIO_ID_NET:
+vpnet = VHOST_PCI_NET(vdev);
+netpci = container_of(vpnet, VhostPCINetPCI, vdev);
+qdev = >parent_obj.pci_dev.qdev;
+break;
+default:
+error_report("virtio_to_pci_dev: device type %d not supported",
+ virtio_id);
+}
+
+return qdev;
+}
+
+static void vp_slave_device_del(VirtIODevice *vdev)
+{
+Error *errp = NULL;
+DeviceState *qdev = virtio_to_pci_dev(vdev, vp_slave->dev_type);
+
+if (vdev != NULL) {
+qdev_unplug(qdev, );
+vp_slave_cleanup();
+}
+}
+
 static void vp_slave_event(void *opaque, int event)
 {
 switch (event) {
 case CHR_EVENT_OPENED:
 break;
 case CHR_EVENT_CLOSED:
+vp_slave_device_del(vp_slave->vdev);
 break;
 }
 }
@@ -298,6 +334,10 @@ static int vp_slave_set_vhost_pci(CharBackend *chr_be, 
VhostUserMsg *msg)
 if (ret < 0)
 return ret;
 break;
+case VHOST_USER_SET_VHOST_PCI_stop:
+vp_slave_device_del(vp_slave->vdev);
+ret = 0;
+break;
 default:
 error_report("slave pconnection: cmd %d not supported yet", cmd);
 return -1;
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index 3e0f4c7..79e1ffd 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -19,6 +19,8 @@ typedef struct PeerVqNode {
 
 typedef struct VhostPCISlave {
 CharBackend chr_be;
+/* Ponnter to the slave device */
+VirtIODevice *vdev;
 uint16_t dev_type;
 uint64_t feature_bits;
 /* hotplugged memory should be mapped following the offset */
-- 
2.7.4




[Qemu-devel] [PATCH v1 28/37] vhost-pci-net: pass the mem and vring info to the driver

2016-12-17 Thread Wei Wang
When DRIVER_OK, the device sends the mem and vring info to the driver
via the controlq.

Signed-off-by: Wei Wang 
---
 hw/net/vhost-pci-net.c | 68 ++
 include/standard-headers/linux/vhost_pci_net.h | 17 +++
 2 files changed, 85 insertions(+)

diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c
index 38f69d1..d8b13c8 100644
--- a/hw/net/vhost-pci-net.c
+++ b/hw/net/vhost-pci-net.c
@@ -14,6 +14,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/iov.h"
 #include "hw/virtio/virtio-access.h"
 #include "hw/virtio/vhost-pci-net.h"
 
@@ -55,8 +56,75 @@ static void vpnet_handle_crq(VirtIODevice *vdev, VirtQueue 
*vq)
 {
 }
 
+static size_t vpnet_send_crq_msg(VhostPCINet *vpnet,
+ struct vpnet_controlq_msg *msg)
+{
+VirtQueueElement *elem;
+VirtQueue *vq;
+size_t msg_len = VPNET_CQ_MSG_HDR_SIZE + msg->size;
+
+vq = vpnet->crq;
+if (!virtio_queue_ready(vq)) {
+return 0;
+}
+
+elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
+if (!elem) {
+return 0;
+}
+
+/* TODO: detect a buffer that's too short, set NEEDS_RESET */
+iov_from_buf(elem->in_sg, elem->in_num, 0, msg, msg_len);
+
+virtqueue_push(vq, elem, msg_len);
+virtio_notify(VIRTIO_DEVICE(vpnet), vq);
+g_free(elem);
+
+return msg_len;
+}
+
+static void vpnet_send_peer_mem_msg(VhostPCINet *vpnet)
+{
+struct vpnet_controlq_msg msg = {
+.class = VHOST_PCI_CTRL_PEER_MEM_MSG,
+.size = sizeof(struct peer_mem_msg),
+};
+memcpy(_msg, _slave->pmem_msg, msg.size);
+vpnet_send_crq_msg(vpnet, );
+}
+
+static void vpnet_send_peer_vq_msg(VhostPCINet *vpnet)
+{
+struct vpnet_controlq_msg *msg;
+struct peer_vqs_msg *pvqs_msg;
+struct peer_vq_msg *pvq_msg;
+uint16_t pvq_num, msg_size, payload_size;
+
+pvq_num = vpnet->peer_vq_num;
+payload_size = sizeof(struct peer_vqs_msg)
+   + sizeof(struct peer_vq_msg) * pvq_num;
+msg_size = VPNET_CQ_MSG_HDR_SIZE + payload_size;
+msg = g_malloc(msg_size);
+msg->class = VHOST_PCI_CTRL_PEER_VQ_MSG,
+msg->size = msg_size;
+
+pvqs_msg = >payload.pvqs_msg;
+pvqs_msg->nvqs = pvq_num;
+pvq_msg = pvqs_msg->pvq_msg;
+memcpy(pvq_msg, vpnet->pvq_msg, payload_size);
+
+vpnet_send_crq_msg(vpnet, msg);
+g_free(msg);
+}
+
 static void vpnet_set_status(struct VirtIODevice *vdev, uint8_t status)
 {
+VhostPCINet *vpnet = VHOST_PCI_NET(vdev);
+
+if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
+vpnet_send_peer_mem_msg(vpnet);
+vpnet_send_peer_vq_msg(vpnet);
+}
 }
 
 static uint64_t vpnet_get_features(VirtIODevice *vdev, uint64_t features, 
Error **errp)
diff --git a/include/standard-headers/linux/vhost_pci_net.h 
b/include/standard-headers/linux/vhost_pci_net.h
index e525569..770171e 100644
--- a/include/standard-headers/linux/vhost_pci_net.h
+++ b/include/standard-headers/linux/vhost_pci_net.h
@@ -65,4 +65,21 @@ struct peer_vqs_msg {
struct peer_vq_msg pvq_msg[];
 };
 
+#define VHOST_PCI_CTRL_PEER_MEM_MSG0
+#define VHOST_PCI_CTRL_PEER_VQ_MSG 1
+struct vpnet_controlq_msg {
+   uint8_t class;
+   uint8_t cmd;
+   uint16_t size;
+union {
+   struct peer_mem_msg pmem_msg;
+   struct peer_vqs_msg pvqs_msg;
+   } payload;
+} __attribute__((packed));
+
+static struct vpnet_controlq_msg vpnet_msg __attribute__ ((unused));
+#define VPNET_CQ_MSG_HDR_SIZE (sizeof(vpnet_msg.class) \
+ + sizeof(vpnet_msg.cmd)  \
+ + sizeof(vpnet_msg.size))
+
 #endif
-- 
2.7.4




[Qemu-devel] [PATCH v1 31/37] vhost-user/msg: send VHOST_USER_SET_VHOST_PCI (start/stop)

2016-12-17 Thread Wei Wang
The master requests the slave to create or destroy a vhost-pci device.

Signed-off-by: Wei Wang 
---
 hw/net/vhost_net.c| 34 ++
 hw/virtio/vhost-user.c| 17 +
 include/hw/virtio/vhost-backend.h |  2 ++
 include/net/vhost_net.h   |  2 ++
 4 files changed, 55 insertions(+)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 6524503..7f64be3 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -18,6 +18,7 @@
 #include "net/tap.h"
 #include "net/vhost-user.h"
 
+#include "hw/virtio/vhost-user.h"
 #include "hw/virtio/virtio-net.h"
 #include "net/vhost_net.h"
 #include "qemu/error-report.h"
@@ -293,6 +294,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
 VirtioBusState *vbus = VIRTIO_BUS(qbus);
 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+struct vhost_net *last_net;
 int r, e, i;
 
 if (!k->set_guest_notifiers) {
@@ -338,6 +340,14 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 }
 }
 
+last_net = get_vhost_net(ncs[total_queues-1].peer);
+if (vhost_pci_enabled(_net->dev)) {
+r = vhost_set_vhost_pci(ncs[total_queues-1].peer,
+  VHOST_USER_SET_VHOST_PCI_start);
+if (r < 0)
+goto err_start;
+}
+
 return 0;
 
 err_start:
@@ -359,8 +369,14 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
 VirtioBusState *vbus = VIRTIO_BUS(qbus);
 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+struct vhost_net *last_net;
 int i, r;
 
+last_net = get_vhost_net(ncs[total_queues-1].peer);
+if (vhost_pci_enabled(_net->dev))
+vhost_set_vhost_pci(ncs[total_queues-1].peer,
+  VHOST_USER_SET_VHOST_PCI_stop);
+
 for (i = 0; i < total_queues; i++) {
 vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
 }
@@ -436,6 +452,18 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
 return 0;
 }
 
+int vhost_set_vhost_pci(NetClientState *nc, uint8_t cmd)
+{
+VHostNetState *net = get_vhost_net(nc);
+const VhostOps *vhost_ops = net->dev.vhost_ops;
+
+if (vhost_ops && vhost_ops->vhost_set_vhost_pci) {
+return vhost_ops->vhost_set_vhost_pci(>dev, cmd);
+}
+
+return 0;
+}
+
 #else
 uint64_t vhost_net_get_max_queues(VHostNetState *net)
 {
@@ -502,4 +530,10 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
 {
 return 0;
 }
+
+int vhost_set_vhost_pci(NetClientState *nc, uint8_t cmd)
+{
+return 0;
+}
+
 #endif
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 8b5ac0b..ce92140 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -312,6 +312,22 @@ static int vhost_user_set_vring_enable(struct vhost_dev 
*dev, int enable)
 return 0;
 }
 
+static int vhost_user_set_vhost_pci(struct vhost_dev *dev, uint8_t cmd)
+{
+VhostUserMsg msg = {
+.request = VHOST_USER_SET_VHOST_PCI,
+.flags = VHOST_USER_VERSION,
+.payload.u64 = (uint64_t)cmd,
+.size = sizeof(msg.payload.u64),
+};
+
+if (vhost_user_write(dev, , NULL, 0) < 0) {
+return -1;
+}
+
+return 0;
+}
+
 static int vhost_user_get_vring_base(struct vhost_dev *dev,
  struct vhost_vring_state *ring)
 {
@@ -639,6 +655,7 @@ const VhostOps user_ops = {
 .vhost_reset_device = vhost_user_reset_device,
 .vhost_get_vq_index = vhost_user_get_vq_index,
 .vhost_set_vring_enable = vhost_user_set_vring_enable,
+.vhost_set_vhost_pci = vhost_user_set_vhost_pci,
 .vhost_requires_shm_log = vhost_user_requires_shm_log,
 .vhost_migration_done = vhost_user_migration_done,
 .vhost_backend_can_merge = vhost_user_can_merge,
diff --git a/include/hw/virtio/vhost-backend.h 
b/include/hw/virtio/vhost-backend.h
index 6e90703..60c0833 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -67,6 +67,7 @@ typedef int (*vhost_reset_device_op)(struct vhost_dev *dev);
 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);
 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev,
  int enable);
+typedef int (*vhost_set_vhost_pci_op)(struct vhost_dev *dev, uint8_t cmd);
 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
char *mac_addr);
@@ -102,6 +103,7 @@ typedef struct VhostOps {
 vhost_reset_device_op vhost_reset_device;
 vhost_get_vq_index_op vhost_get_vq_index;
 vhost_set_vring_enable_op vhost_set_vring_enable;
+vhost_set_vhost_pci_op vhost_set_vhost_pci;
 vhost_requires_shm_log_op vhost_requires_shm_log;
 

[Qemu-devel] [PATCH v1 27/37] vhost-pci-net: pass the info collected by vp_slave to the device

2016-12-17 Thread Wei Wang
When the device is realized, pass the vring info to the device from
the slave maintained list. The device uses bar2 to hold the peer VM
memory.

Signed-off-by: Wei Wang 
---
 hw/net/vhost-pci-net.c | 27 ++
 hw/virtio/virtio-pci.c | 14 +
 include/hw/virtio/vhost-pci-net.h  |  9 +
 include/standard-headers/linux/vhost_pci_net.h | 14 +
 4 files changed, 64 insertions(+)

diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c
index 2050e5f..38f69d1 100644
--- a/hw/net/vhost-pci-net.c
+++ b/hw/net/vhost-pci-net.c
@@ -20,6 +20,33 @@
 #define VPNET_CQ_SIZE 32
 #define VPNET_RQ_SIZE 256
 
+void vpnet_set_peer_vq_num(VhostPCINet *vpnet, uint16_t num)
+{
+vpnet->peer_vq_num = num;
+}
+
+void vpnet_init_device_features(VhostPCINet *vpnet, uint64_t features)
+{
+vpnet->device_features = features;
+}
+
+void vpnet_set_peer_vq_msg(VhostPCINet *vpnet, PeerVqNode *vq_node)
+{
+struct peer_vq_msg *pvq_msg;
+uint32_t vring_num = vq_node->vring_num;
+
+if (vpnet->pvq_msg == NULL)
+vpnet->pvq_msg = g_malloc0(sizeof(struct peer_vq_msg) * (vring_num + 
1));
+
+pvq_msg = vpnet->pvq_msg + vring_num;
+pvq_msg->last_avail_idx = vq_node->last_avail_idx;
+pvq_msg->vring_num = vring_num;
+pvq_msg->vring_enable = vq_node->enabled;
+pvq_msg->desc_gpa = vq_node->addr.desc_user_addr;
+pvq_msg->avail_gpa = vq_node->addr.avail_user_addr;
+pvq_msg->used_gpa = vq_node->addr.used_user_addr;
+}
+
 static void vpnet_handle_rq(VirtIODevice *vdev, VirtQueue *vq)
 {
 }
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index baf70b4..20cbefc 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2320,7 +2320,21 @@ static void vpnet_pci_realize(VirtIOPCIProxy *vpci_dev, 
Error **errp)
 {
 VhostPCINetPCI *dev = VHOST_PCI_NET_PCI(vpci_dev);
 DeviceState *vdev = DEVICE(>vdev);
+int bar_id = 2;
+PeerVqNode *vq_node;
 
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+
+pci_register_bar(_dev->pci_dev, bar_id,
+  PCI_BASE_ADDRESS_SPACE_MEMORY |
+  PCI_BASE_ADDRESS_MEM_PREFETCH |
+  PCI_BASE_ADDRESS_MEM_TYPE_64,
+  vp_slave->bar_mr);
+vpnet_set_peer_vq_num(>vdev, vp_slave->pvq_num);
+vpnet_init_device_features(>vdev, vp_slave->feature_bits);
+QLIST_FOREACH(vq_node, _slave->pvq_list, node) {
+vpnet_set_peer_vq_msg(>vdev, vq_node);
+}
 object_property_set_bool(OBJECT(vdev), true, "realized", errp);
 }
 
diff --git a/include/hw/virtio/vhost-pci-net.h 
b/include/hw/virtio/vhost-pci-net.h
index 8f2e65f..e813119 100644
--- a/include/hw/virtio/vhost-pci-net.h
+++ b/include/hw/virtio/vhost-pci-net.h
@@ -16,6 +16,7 @@
 
 #include "standard-headers/linux/vhost_pci_net.h"
 #include "hw/virtio/virtio.h"
+#include "hw/virtio/vhost-pci-slave.h"
 
 #define TYPE_VHOST_PCI_NET "vhost-pci-net-device"
 #define VHOST_PCI_NET(obj) \
@@ -31,6 +32,14 @@ typedef struct VhostPCINet {
 uint16_t peer_vq_num;
 size_t config_size;
 uint64_t device_features;
+struct peer_mem_msg pmem_msg;
+struct peer_vq_msg *pvq_msg;
 } VhostPCINet;
 
+void vpnet_set_peer_vq_num(VhostPCINet *vpnet, uint16_t num);
+
+void vpnet_init_device_features(VhostPCINet *vpnet, uint64_t features);
+
+void vpnet_set_peer_vq_msg(VhostPCINet *vpnet, PeerVqNode *vq_node);
+
 #endif
diff --git a/include/standard-headers/linux/vhost_pci_net.h 
b/include/standard-headers/linux/vhost_pci_net.h
index f4c8d0b..e525569 100644
--- a/include/standard-headers/linux/vhost_pci_net.h
+++ b/include/standard-headers/linux/vhost_pci_net.h
@@ -51,4 +51,18 @@ struct vhost_pci_net_config {
uint16_t status;
 } QEMU_PACKED;
 
+struct peer_vq_msg {
+   uint16_t last_avail_idx;
+int32_t  vring_enable;
+   uint32_t vring_num;
+   uint64_t desc_gpa;
+   uint64_t avail_gpa;
+   uint64_t used_gpa;
+};
+
+struct peer_vqs_msg {
+   uint32_t nvqs;
+   struct peer_vq_msg pvq_msg[];
+};
+
 #endif
-- 
2.7.4




[Qemu-devel] [PATCH v1 25/37] vhost-pci-slave/msg: VHOST_USER_SEND_RARP

2016-12-17 Thread Wei Wang
Not implemented in this version.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 4e99fd9..1957d3f 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -353,6 +353,8 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 qemu_chr_fe_get_msgfds(chr_be, fds, 1);
 close(fds[0]);
 break;
+case VHOST_USER_SEND_RARP:
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
-- 
2.7.4




[Qemu-devel] [PATCH v1 15/37] vhost-pci-slave/msg: VHOST_USER_SET_MEM_TABLE

2016-12-17 Thread Wei Wang
Map the peer memory in QEMU, and prepare the memory for the guest using
MemoryRegion. The controlq message of the memory info is constructed
here, and it will be sent to the guest when the guest controlq is ready. With 
the
the peer memory info reveived in the message, the guest will be able to
translate any peer guest physical address to its own guest physical
address.

Also add a cleanup function to free the related memory that has been
set up.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c| 91 +-
 include/hw/virtio/vhost-pci-slave.h|  9 +++
 include/standard-headers/linux/vhost_pci_net.h | 11 
 3 files changed, 110 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 9b854b1..5170ab5 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -26,6 +26,20 @@
 
 VhostPCISlave *vp_slave;
 
+static void vp_slave_cleanup(void)
+{
+int ret;
+uint32_t i, nregions;
+
+nregions = vp_slave->pmem_msg.nregions;
+for (i = 0; i < nregions; i++) {
+ret = munmap(vp_slave->mr_map_base[i], vp_slave->mr_map_size[i]);
+if (ret < 0)
+error_report("cleanup: failed to unmap mr");
+memory_region_del_subregion(vp_slave->bar_mr, vp_slave->sub_mr+i);
+}
+}
+
 static int vp_slave_write(CharBackend *chr_be, VhostUserMsg *msg)
 {
 int size;
@@ -107,6 +121,72 @@ static int vp_slave_get_queue_num(CharBackend *chr_be, 
VhostUserMsg *msg)
 return vp_slave_write(chr_be, msg);
 }
 
+static uint64_t vp_slave_peer_mem_size_get(VhostUserMemory *pmem)
+{
+int i;
+uint64_t total_size = 0;
+uint32_t nregions = pmem->nregions;
+VhostUserMemoryRegion *pmem_regions = pmem->regions;
+
+for (i = 0; i < nregions; i++) {
+total_size += pmem_regions[i].memory_size;
+}
+
+return total_size;
+}
+
+static int vp_slave_set_mem_table(VhostUserMsg *msg, int *fds, int fd_num)
+{
+VhostUserMemory *pmem = >payload.memory;
+VhostUserMemoryRegion *pmem_region = pmem->regions;
+uint32_t i, nregions = pmem->nregions;
+struct peer_mem_msg *pmem_msg = _slave->pmem_msg;
+pmem_msg->nregions = nregions;
+MemoryRegion *bar_mr, *sub_mr;
+uint64_t bar_size, bar_map_offset = 0;
+void *mr_qva;
+
+/* Sanity Check */
+if (fd_num != nregions)
+error_report("SET_MEM_TABLE: fd num doesn't match region num");
+
+if (vp_slave->bar_mr == NULL)
+vp_slave->bar_mr = g_malloc(sizeof(MemoryRegion));
+if (vp_slave->sub_mr == NULL)
+vp_slave->sub_mr = g_malloc(nregions * sizeof(MemoryRegion));
+bar_mr = vp_slave->bar_mr;
+sub_mr = vp_slave->sub_mr;
+
+/*
+ * The top half of the bar area holds the peer memory, and the bottom
+ * half is reserved for memory hotplug
+ */
+bar_size = 2 * vp_slave_peer_mem_size_get(pmem);
+bar_size = pow2ceil(bar_size);
+memory_region_init(bar_mr, NULL, "Peer Memory", bar_size);
+for (i = 0; i < nregions; i++) {
+vp_slave->mr_map_size[i] = pmem_region[i].memory_size
+   + pmem_region[i].mmap_offset;
+vp_slave->mr_map_base[i] = mmap(NULL, vp_slave->mr_map_size[i],
+  PROT_READ | PROT_WRITE, MAP_SHARED, fds[i], 0);
+if (vp_slave->mr_map_base[i] == MAP_FAILED) {
+error_report("SET_MEM_TABLE: map peer memory region %d failed", i);
+return -1;
+}
+
+mr_qva = vp_slave->mr_map_base[i] + pmem_region[i].mmap_offset;
+memory_region_init_ram_ptr(_mr[i], NULL, "Peer Memory",
+   pmem_region[i].memory_size, mr_qva);
+memory_region_add_subregion(bar_mr, bar_map_offset, _mr[i]);
+bar_map_offset += pmem_region[i].memory_size;
+pmem_msg->regions[i].gpa = pmem_region[i].guest_phys_addr;
+pmem_msg->regions[i].size = pmem_region[i].memory_size;
+}
+vp_slave->bar_map_offset = bar_map_offset;
+
+return 0;
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -114,7 +194,7 @@ static int vp_slave_can_read(void *opaque)
 
 static void vp_slave_read(void *opaque, const uint8_t *buf, int size)
 {
-int ret;
+int ret, fd_num, fds[MAX_GUEST_REGION];
 VhostUserMsg msg;
 uint8_t *p = (uint8_t *) 
 CharBackend *chr_be = (CharBackend *)opaque;
@@ -165,6 +245,10 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
 break;
 case VHOST_USER_SET_OWNER:
 break;
+case VHOST_USER_SET_MEM_TABLE:
+fd_num = qemu_chr_fe_get_msgfds(chr_be, fds, sizeof(fds) / 
sizeof(int));
+vp_slave_set_mem_table(, fds, fd_num);
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
@@ -198,6 +282,8 @@ int vhost_pci_slave_init(QemuOpts *opts)
 

[Qemu-devel] [PATCH v1 23/37] vhost-pci-slave/msg: VHOST_USER_SET_LOG_BASE

2016-12-17 Thread Wei Wang
Live migration is not supported in this version, so do nothing here.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 3e00e35..61299e4 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -347,6 +347,8 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 case VHOST_USER_SET_VRING_ENABLE:
 vp_slave_set_vring_enable();
 break;
+case VHOST_USER_SET_LOG_BASE:
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
-- 
2.7.4




[Qemu-devel] [PATCH v1 14/37] vhost-pci-slave/msg: VHOST_USER_SET_OWNER

2016-12-17 Thread Wei Wang
Do nothing currently.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 8e5ecf8..9b854b1 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -163,6 +163,8 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 if (ret < 0)
 goto err_handling;
 break;
+case VHOST_USER_SET_OWNER:
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
-- 
2.7.4




[Qemu-devel] [PATCH v1 29/37] vhost-pci-slave/msg: VHOST_USER_SET_VHOST_PCI (start)

2016-12-17 Thread Wei Wang
The VHOST_USER_SET_VHOST_PCI msg is used to request the start or
stop of the vhost-pci device.

This patch handles the start commandin the slave. When receiving
the SET_VHOST_PCI request with the start command, the slave creates
a vhost-pci device based on the previously received virtio_id.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c| 51 ++
 include/hw/virtio/vhost-user.h |  5 +
 2 files changed, 56 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index cdeb710..73d3f71 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 
+#include "monitor/qdev.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/virtio/virtio-pci.h"
@@ -260,6 +261,51 @@ static void vp_slave_set_vring_enable(VhostUserMsg *msg)
 }
 }
 
+static int vp_slave_device_create(uint16_t virtio_id)
+{
+Error *local_err = NULL;
+QemuOpts *opts;
+DeviceState *dev;
+char params[50];
+
+switch (virtio_id) {
+case VIRTIO_ID_NET:
+strcpy(params, "driver=vhost-pci-net-pci,id=vhost-pci-0");
+break;
+default:
+error_report("vhost-pci device create: device type %d not supported",
+ virtio_id);
+}
+
+opts = qemu_opts_parse_noisily(qemu_find_opts("device"), params, true);
+dev = qdev_device_add(opts, _err);
+if (!dev) {
+qemu_opts_del(opts);
+return -1;
+}
+object_unref(OBJECT(dev));
+return 0;
+}
+
+static int vp_slave_set_vhost_pci(CharBackend *chr_be, VhostUserMsg *msg)
+{
+int ret;
+uint8_t cmd = (uint8_t)msg->payload.u64;
+
+switch (cmd) {
+case VHOST_USER_SET_VHOST_PCI_start:
+ret = vp_slave_device_create(vp_slave->dev_type);
+if (ret < 0)
+return ret;
+break;
+default:
+error_report("slave pconnection: cmd %d not supported yet", cmd);
+return -1;
+}
+
+return ret;
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -370,6 +416,11 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
 break;
 case VHOST_USER_SEND_RARP:
 break;
+case VHOST_USER_SET_VHOST_PCI:
+ret = vp_slave_set_vhost_pci(chr_be, );
+if (ret < 0)
+goto err_handling;
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h
index 45f11be..12e4dc9 100644
--- a/include/hw/virtio/vhost-user.h
+++ b/include/hw/virtio/vhost-user.h
@@ -25,6 +25,10 @@ enum VhostUserProtocolFeature {
   (1ULL << 
VHOST_USER_PROTOCOL_F_VHOST_PCI) | \
   (1ULL << 
VHOST_USER_PROTOCOL_F_SET_DEVICE_ID)
 
+/* control/status of the vhost-pci device */
+#define VHOST_USER_SET_VHOST_PCI_start0
+#define VHOST_USER_SET_VHOST_PCI_stop 1
+
 typedef enum VhostUserRequest {
 VHOST_USER_NONE = 0,
 VHOST_USER_GET_FEATURES = 1,
@@ -47,6 +51,7 @@ typedef enum VhostUserRequest {
 VHOST_USER_SET_VRING_ENABLE = 18,
 VHOST_USER_SEND_RARP = 19,
 VHOST_USER_SET_DEVICE_ID = 20,
+VHOST_USER_SET_VHOST_PCI = 21,
 VHOST_USER_MAX
 } VhostUserRequest;
 
-- 
2.7.4




[Qemu-devel] [PATCH v1 17/37] vhost-pci-slave/msg: VHOST_USER_SET_VRING_BASE

2016-12-17 Thread Wei Wang
Update last_avail_idx to the head node in the list.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 10 ++
 include/hw/virtio/vhost-pci-slave.h |  1 +
 2 files changed, 11 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 0deab2d..e33c59e 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -209,6 +209,13 @@ static void vp_slave_set_vring_num(VhostUserMsg *msg)
 pvq_node->vring_num = msg->payload.u64;
 }
 
+static void vp_slave_set_vring_base(VhostUserMsg *msg)
+{
+PeerVqNode *pvq_node = QLIST_FIRST(_slave->pvq_list);
+
+pvq_node->last_avail_idx = msg->payload.u64;
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -275,6 +282,9 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 vp_slave_alloc_pvq_node();
 vp_slave_set_vring_num();
 break;
+case VHOST_USER_SET_VRING_BASE:
+vp_slave_set_vring_base();
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index fe4824c..cfe4107 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -6,6 +6,7 @@
 #include "standard-headers/linux/vhost_pci_net.h"
 
 typedef struct PeerVqNode {
+uint16_t last_avail_idx;
 uint32_t vring_num;
 QLIST_ENTRY(PeerVqNode) node;
 } PeerVqNode;
-- 
2.7.4




[Qemu-devel] [PATCH v1 24/37] vhost-pci-slave/msg: VHOST_USER_SET_LOG_FD

2016-12-17 Thread Wei Wang
Not implemented in this version.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 61299e4..4e99fd9 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -349,6 +349,10 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
 break;
 case VHOST_USER_SET_LOG_BASE:
 break;
+case VHOST_USER_SET_LOG_FD:
+qemu_chr_fe_get_msgfds(chr_be, fds, 1);
+close(fds[0]);
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
-- 
2.7.4




[Qemu-devel] [PATCH v1 16/37] vhost-pci-slave/msg: VHOST_USER_SET_VRING_NUM

2016-12-17 Thread Wei Wang
The protocol doesn't have a message to tell the slave how many virtqueues
that the master device has. So, the slave side implementation uses a list to
manage the virtqueue info sent from the master. SET_VRING_NUM is the
first virtqueue info passed from the master, so the slave allocates a node
when receiving this message, and inserts the node to the head of the
list. Subsequent virtqueue info (e.g. base, addresses) will be updated
to the head node.

The list of virtqueue info will be packed together and delievered to the
driver via the controlq.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 28 
 include/hw/virtio/vhost-pci-slave.h |  7 +++
 2 files changed, 35 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 5170ab5..0deab2d 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -30,6 +30,7 @@ static void vp_slave_cleanup(void)
 {
 int ret;
 uint32_t i, nregions;
+PeerVqNode *pvq_node;
 
 nregions = vp_slave->pmem_msg.nregions;
 for (i = 0; i < nregions; i++) {
@@ -38,6 +39,13 @@ static void vp_slave_cleanup(void)
 error_report("cleanup: failed to unmap mr");
 memory_region_del_subregion(vp_slave->bar_mr, vp_slave->sub_mr+i);
 }
+
+if (!QLIST_EMPTY(_slave->pvq_list)) {
+QLIST_FOREACH(pvq_node, _slave->pvq_list, node)
+g_free(pvq_node);
+}
+QLIST_INIT(_slave->pvq_list);
+vp_slave->pvq_num = 0;
 }
 
 static int vp_slave_write(CharBackend *chr_be, VhostUserMsg *msg)
@@ -187,6 +195,20 @@ static int vp_slave_set_mem_table(VhostUserMsg *msg, int 
*fds, int fd_num)
 return 0;
 }
 
+static void vp_slave_alloc_pvq_node(void)
+{
+PeerVqNode *pvq_node = g_malloc0(sizeof(PeerVqNode));
+QLIST_INSERT_HEAD(_slave->pvq_list, pvq_node, node);
+vp_slave->pvq_num++;
+}
+
+static void vp_slave_set_vring_num(VhostUserMsg *msg)
+{
+PeerVqNode *pvq_node = QLIST_FIRST(_slave->pvq_list);
+
+pvq_node->vring_num = msg->payload.u64;
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -249,6 +271,10 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
 fd_num = qemu_chr_fe_get_msgfds(chr_be, fds, sizeof(fds) / 
sizeof(int));
 vp_slave_set_mem_table(, fds, fd_num);
 break;
+case VHOST_USER_SET_VRING_NUM:
+vp_slave_alloc_pvq_node();
+vp_slave_set_vring_num();
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
@@ -284,6 +310,8 @@ int vhost_pci_slave_init(QemuOpts *opts)
 vp_slave->feature_bits =  1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
 vp_slave->bar_mr = NULL;
 vp_slave->sub_mr = NULL;
+QLIST_INIT(_slave->pvq_list);
+vp_slave->pvq_num = 0;
 qemu_chr_fe_init(_slave->chr_be, chr, _abort);
 qemu_chr_fe_set_handlers(_slave->chr_be, vp_slave_can_read,
  vp_slave_read, vp_slave_event,
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index 03e23eb..fe4824c 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -5,6 +5,11 @@
 #include "exec/memory.h"
 #include "standard-headers/linux/vhost_pci_net.h"
 
+typedef struct PeerVqNode {
+uint32_t vring_num;
+QLIST_ENTRY(PeerVqNode) node;
+} PeerVqNode;
+
 typedef struct VhostPCISlave {
 CharBackend chr_be;
 uint16_t dev_type;
@@ -16,6 +21,8 @@ typedef struct VhostPCISlave {
 void *mr_map_base[MAX_GUEST_REGION];
 uint64_t mr_map_size[MAX_GUEST_REGION];
 struct peer_mem_msg pmem_msg;
+uint16_t pvq_num;
+QLIST_HEAD(, PeerVqNode) pvq_list;
 } VhostPCISlave;
 
 extern VhostPCISlave *vp_slave;
-- 
2.7.4




[Qemu-devel] [PATCH v1 10/37] vhost-pci-slave/msg: VHOST_USER_SET_PROTOCOL_FEATURES

2016-12-17 Thread Wei Wang
Not used currently.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index ac9deae..ef2b66a 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -122,6 +122,8 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 if (ret < 0)
 goto err_handling;
 break;
+case VHOST_USER_SET_PROTOCOL_FEATURES:
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
-- 
2.7.4




[Qemu-devel] [PATCH v1 19/37] vhost-pci-slave/msg: VHOST_USER_SET_VRING_ADDR

2016-12-17 Thread Wei Wang
Update the virtqueue addresses to the head node of the list.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 10 ++
 include/hw/virtio/vhost-pci-slave.h |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index e33c59e..a55861a 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -216,6 +216,13 @@ static void vp_slave_set_vring_base(VhostUserMsg *msg)
 pvq_node->last_avail_idx = msg->payload.u64;
 }
 
+static void vp_slave_set_vring_addr(VhostUserMsg *msg)
+{
+PeerVqNode *pvq_node = QLIST_FIRST(_slave->pvq_list);
+memcpy(_node->addr, >payload.addr,
+   sizeof(struct vhost_vring_addr));
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -285,6 +292,9 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 case VHOST_USER_SET_VRING_BASE:
 vp_slave_set_vring_base();
 break;
+case VHOST_USER_SET_VRING_ADDR:
+vp_slave_set_vring_addr();
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index cfe4107..439198d 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -1,6 +1,8 @@
 #ifndef QEMU_VHOST_PCI_SLAVE_H
 #define QEMU_VHOST_PCI_SLAVE_H
 
+#include 
+
 #include "sysemu/char.h"
 #include "exec/memory.h"
 #include "standard-headers/linux/vhost_pci_net.h"
@@ -8,6 +10,7 @@
 typedef struct PeerVqNode {
 uint16_t last_avail_idx;
 uint32_t vring_num;
+struct vhost_vring_addr addr;
 QLIST_ENTRY(PeerVqNode) node;
 } PeerVqNode;
 
-- 
2.7.4




[Qemu-devel] [PATCH v1 18/37] vhost-user: send guest physical address of virtqueues to the slave

2016-12-17 Thread Wei Wang
In the vhost-pci case, the slave needs the master side guest physical
address, rather than the qemu virtual address.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost.c | 61 ---
 include/hw/virtio/vhost.h |  2 ++
 2 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index f7f7023..df04375 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/migration.h"
+#include "hw/virtio/vhost-user.h"
 
 /* enabled until disconnected backend stabilizes */
 #define _VHOST_DEBUG 1
@@ -858,6 +859,12 @@ static int vhost_virtqueue_set_vring_endian_legacy(struct 
vhost_dev *dev,
 return -errno;
 }
 
+bool vhost_pci_enabled(struct vhost_dev *dev)
+{
+return ((dev->protocol_features &
+(1ULL << VHOST_USER_PROTOCOL_F_VHOST_PCI)) != 0);
+}
+
 static int vhost_virtqueue_start(struct vhost_dev *dev,
 struct VirtIODevice *vdev,
 struct vhost_virtqueue *vq,
@@ -901,26 +908,40 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
 }
 }
 
-vq->desc_size = s = l = virtio_queue_get_desc_size(vdev, idx);
 vq->desc_phys = a = virtio_queue_get_desc_addr(vdev, idx);
-vq->desc = cpu_physical_memory_map(a, , 0);
-if (!vq->desc || l != s) {
-r = -ENOMEM;
-goto fail_alloc_desc;
+if (vhost_pci_enabled(dev)) {
+vq->desc = (void *)a;
+} else {
+vq->desc_size = s = l = virtio_queue_get_desc_size(vdev, idx);
+vq->desc = cpu_physical_memory_map(a, , 0);
+if (!vq->desc || l != s) {
+r = -ENOMEM;
+goto fail_alloc_desc;
+}
 }
+
 vq->avail_size = s = l = virtio_queue_get_avail_size(vdev, idx);
 vq->avail_phys = a = virtio_queue_get_avail_addr(vdev, idx);
-vq->avail = cpu_physical_memory_map(a, , 0);
-if (!vq->avail || l != s) {
-r = -ENOMEM;
-goto fail_alloc_avail;
+if (vhost_pci_enabled(dev)) {
+vq->avail = (void *)a;
+} else {
+vq->avail = cpu_physical_memory_map(a, , 0);
+if (!vq->avail || l != s) {
+r = -ENOMEM;
+goto fail_alloc_avail;
+}
 }
+
 vq->used_size = s = l = virtio_queue_get_used_size(vdev, idx);
 vq->used_phys = a = virtio_queue_get_used_addr(vdev, idx);
-vq->used = cpu_physical_memory_map(a, , 1);
-if (!vq->used || l != s) {
-r = -ENOMEM;
-goto fail_alloc_used;
+if (vhost_pci_enabled(dev)) {
+vq->used = (void *)a;
+} else {
+vq->used = cpu_physical_memory_map(a, , 1);
+if (!vq->used || l != s) {
+r = -ENOMEM;
+goto fail_alloc_used;
+}
 }
 
 r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled);
@@ -1003,12 +1024,14 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev,
 vhost_vq_index);
 }
 
-cpu_physical_memory_unmap(vq->used, virtio_queue_get_used_size(vdev, idx),
-  1, virtio_queue_get_used_size(vdev, idx));
-cpu_physical_memory_unmap(vq->avail, virtio_queue_get_avail_size(vdev, 
idx),
-  0, virtio_queue_get_avail_size(vdev, idx));
-cpu_physical_memory_unmap(vq->desc, virtio_queue_get_desc_size(vdev, idx),
-  0, virtio_queue_get_desc_size(vdev, idx));
+if (!vhost_pci_enabled(dev)) {
+cpu_physical_memory_unmap(vq->used, virtio_queue_get_used_size(vdev, 
idx),
+  1, virtio_queue_get_used_size(vdev, idx));
+cpu_physical_memory_unmap(vq->avail, virtio_queue_get_avail_size(vdev, 
idx),
+  0, virtio_queue_get_avail_size(vdev, idx));
+cpu_physical_memory_unmap(vq->desc, virtio_queue_get_desc_size(vdev, 
idx),
+  0, virtio_queue_get_desc_size(vdev, idx));
+}
 }
 
 static void vhost_eventfd_add(MemoryListener *listener,
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 9cf32e2..9955e07 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -92,4 +92,6 @@ bool vhost_has_free_slot(void);
 int vhost_net_set_backend(struct vhost_dev *hdev,
   struct vhost_vring_file *file);
 
+bool vhost_pci_enabled(struct vhost_dev *dev);
+
 #endif
-- 
2.7.4




[Qemu-devel] [PATCH v1 06/37] vhost-pci-slave: set up the fundamental handlers for the server socket

2016-12-17 Thread Wei Wang
Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 53 +
 1 file changed, 53 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 5ff9a09..2278f63 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -15,9 +15,59 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/virtio/vhost-pci-slave.h"
+#include "hw/virtio/vhost-user.h"
 
 VhostPCISlave *vp_slave;
 
+static void vp_slave_event(void *opaque, int event)
+{
+switch (event) {
+case CHR_EVENT_OPENED:
+break;
+case CHR_EVENT_CLOSED:
+break;
+}
+}
+
+static int vp_slave_can_read(void *opaque)
+{
+return VHOST_USER_HDR_SIZE;
+}
+
+static void vp_slave_read(void *opaque, const uint8_t *buf, int size)
+{
+VhostUserMsg msg;
+uint8_t *p = (uint8_t *) 
+CharBackend *chr_be = (CharBackend *)opaque;
+
+if (size != VHOST_USER_HDR_SIZE) {
+error_report("Wrong message size received %d", size);
+return;
+}
+
+memcpy(p, buf, VHOST_USER_HDR_SIZE);
+
+if (msg.size) {
+p += VHOST_USER_HDR_SIZE;
+size = qemu_chr_fe_read_all(chr_be, p, msg.size);
+if (size != msg.size) {
+error_report("Wrong message size received %d != %d",
+   size, msg.size);
+return;
+}
+}
+
+if (msg.request > VHOST_USER_MAX)
+error_report("vhost-pci-slave read incorrect msg");
+
+switch(msg.request) {
+default:
+error_report("vhost-pci-slave does not support msg request = %d",
+ msg.request);
+break;
+}
+}
+
 static CharDriverState *vp_slave_parse_chardev(const char *id)
 {
 CharDriverState *chr = qemu_chr_find(id);
@@ -40,6 +90,9 @@ int vhost_pci_slave_init(QemuOpts *opts)
 return -1;
 }
 qemu_chr_fe_init(_slave->chr_be, chr, _abort);
+qemu_chr_fe_set_handlers(_slave->chr_be, vp_slave_can_read,
+ vp_slave_read, vp_slave_event,
+ _slave->chr_be, NULL, true);
 
 return 0;
 }
-- 
2.7.4




[Qemu-devel] [PATCH v1 22/37] vhost-pci-slave/msg: VHOST_USER_SET_VRING_ENABLE

2016-12-17 Thread Wei Wang
Enable/Disable the corresponding virtqueue pairs in the list.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 15 +++
 include/hw/virtio/vhost-pci-slave.h |  1 +
 2 files changed, 16 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index e176d59..3e00e35 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -238,6 +238,18 @@ static void vp_slave_set_vring_call(int fd)
 pvq_node->callfd = fd;
 }
 
+static void vp_slave_set_vring_enable(VhostUserMsg *msg)
+{
+struct vhost_vring_state *state = >payload.state;
+PeerVqNode *pvq_node;
+QLIST_FOREACH(pvq_node, _slave->pvq_list, node) {
+if (pvq_node->vring_num == state->index) {
+pvq_node->enabled = (int)state->num;
+break;
+}
+}
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -332,6 +344,9 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
  */
 qemu_set_nonblock(fds[0]);
 break;
+case VHOST_USER_SET_VRING_ENABLE:
+vp_slave_set_vring_enable();
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index f6206a1..3e0f4c7 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -12,6 +12,7 @@ typedef struct PeerVqNode {
 uint32_t vring_num;
 int kickfd;
 int callfd;
+int enabled;
 struct vhost_vring_addr addr;
 QLIST_ENTRY(PeerVqNode) node;
 } PeerVqNode;
-- 
2.7.4




[Qemu-devel] [PATCH v1 12/37] vhost-pci-slave/msg: VHOST_USER_SET_DEVICE_ID

2016-12-17 Thread Wei Wang
Initialize the feature bits according to the device type.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 17 +
 include/hw/virtio/vhost-pci-slave.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index ef2b66a..9b00be4 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -76,6 +76,20 @@ static int vp_slave_get_protocol_features(CharBackend 
*chr_be, VhostUserMsg *msg
 return vp_slave_write(chr_be, msg);
 }
 
+static void vp_slave_set_device_type(VhostUserMsg *msg)
+{
+vp_slave->dev_type = (uint16_t)msg->payload.u64;
+
+switch (vp_slave->dev_type) {
+case VIRTIO_ID_NET:
+vp_slave->feature_bits |= (VHOST_PCI_FEATURE_BITS
+   | VHOST_PCI_NET_FEATURE_BITS);
+break;
+default:
+error_report("device type %d is not supported", vp_slave->dev_type);
+}
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -124,6 +138,9 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 break;
 case VHOST_USER_SET_PROTOCOL_FEATURES:
 break;
+case VHOST_USER_SET_DEVICE_ID:
+vp_slave_set_device_type();
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index 4ec25d4..8b162dc 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -5,6 +5,7 @@
 
 typedef struct VhostPCISlave {
 CharBackend chr_be;
+uint16_t dev_type;
 uint64_t feature_bits;
 } VhostPCISlave;
 
-- 
2.7.4




[Qemu-devel] [PATCH v1 13/37] vhost-pci-slave/msg: VHOST_USER_GET_QUEUE_NUM

2016-12-17 Thread Wei Wang
Send the max supported queue num according to the device type back to
the master.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 9b00be4..8e5ecf8 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -90,6 +90,23 @@ static void vp_slave_set_device_type(VhostUserMsg *msg)
 }
 }
 
+static int vp_slave_get_queue_num(CharBackend *chr_be, VhostUserMsg *msg)
+{
+switch (vp_slave->dev_type) {
+case VIRTIO_ID_NET:
+msg->payload.u64 = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX;
+break;
+default:
+error_report("GET_QUEUE_NUM: device type %d is not supported",
+ vp_slave->dev_type);
+return -1;
+}
+msg->size = sizeof(msg->payload.u64);
+msg->flags |= VHOST_USER_REPLY_MASK;
+
+return vp_slave_write(chr_be, msg);
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -141,6 +158,11 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
 case VHOST_USER_SET_DEVICE_ID:
 vp_slave_set_device_type();
 break;
+case VHOST_USER_GET_QUEUE_NUM:
+ret = vp_slave_get_queue_num(chr_be, );
+if (ret < 0)
+goto err_handling;
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
-- 
2.7.4




[Qemu-devel] [PATCH v1 08/37] vhost-pci-slave/msg: VHOST_USER_SET_FEATURES

2016-12-17 Thread Wei Wang
Store the feature bits that have been negotiated between the master device
and driver. The feature bits will be negotiated with the slave driver.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 4f445c2..bc6120c 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -50,6 +50,13 @@ static int vp_slave_get_features(CharBackend *chr_be, 
VhostUserMsg *msg)
 return vp_slave_write(chr_be, msg);
 }
 
+static void vp_slave_set_features(VhostUserMsg *msg)
+{
+   /* Clear the protocol feature bit, which is useless for the device */
+vp_slave->feature_bits = msg->payload.u64
+ & ~(1 << VHOST_USER_F_PROTOCOL_FEATURES);
+}
+
 static void vp_slave_event(void *opaque, int event)
 {
 switch (event) {
@@ -98,6 +105,9 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 if (ret < 0)
 goto err_handling;
 break;
+case VHOST_USER_SET_FEATURES:
+vp_slave_set_features();
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
-- 
2.7.4




[Qemu-devel] [PATCH v1 20/37] vhost-pci-slave/msg: VHOST_USER_SET_VRING_KICK

2016-12-17 Thread Wei Wang
Update the kickfd to the head node in the list.

This version of vhost-pci expects the driver to use polling to receive
packets. So, other than storing the kickfd, we don't do anything more.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 19 +++
 include/hw/virtio/vhost-pci-slave.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index a55861a..dff1c88 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -11,6 +11,7 @@
  */
 
 #include 
+#include 
 
 #include "qapi/error.h"
 #include "qemu/error-report.h"
@@ -223,6 +224,13 @@ static void vp_slave_set_vring_addr(VhostUserMsg *msg)
sizeof(struct vhost_vring_addr));
 }
 
+static void vp_slave_set_vring_kick(int fd)
+{
+PeerVqNode *pvq_node = QLIST_FIRST(_slave->pvq_list);
+if (!pvq_node)
+pvq_node->kickfd = fd;
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -295,6 +303,17 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
 case VHOST_USER_SET_VRING_ADDR:
 vp_slave_set_vring_addr();
 break;
+case VHOST_USER_SET_VRING_KICK:
+/* consume the fd */
+qemu_chr_fe_get_msgfds(chr_be, fds, 1);
+vp_slave_set_vring_kick(fds[0]);
+/*
+ * This is a non-blocking eventfd.
+ * The receive function forces it to be blocking,
+ * so revert it back to non-blocking.
+ */
+qemu_set_nonblock(fds[0]);
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index 439198d..4b6b213 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -10,6 +10,7 @@
 typedef struct PeerVqNode {
 uint16_t last_avail_idx;
 uint32_t vring_num;
+int kickfd;
 struct vhost_vring_addr addr;
 QLIST_ENTRY(PeerVqNode) node;
 } PeerVqNode;
-- 
2.7.4




[Qemu-devel] [PATCH v1 04/37] vl: add the vhost-pci-slave command line option

2016-12-17 Thread Wei Wang
An example of the command line option to create a vhost-pci-slave is:

-chardev socket,id=slave1,server,wait=off,path=/opt/vhost-pci-slave
-vhost-pci-slave socket,chardev=slave1

Signed-off-by: Wei Wang 
---
 qemu-options.hx |  4 
 vl.c| 21 +
 2 files changed, 25 insertions(+)

diff --git a/qemu-options.hx b/qemu-options.hx
index c534a2f..5d60a1d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4068,6 +4068,10 @@ contents of @code{iv.b64} to the second secret
 
 ETEXI
 
+DEF("vhost-pci-slave", HAS_ARG, QEMU_OPTION_vhost_pci_slave,
+"-vhost-pci-slave socket,chrdev={id}\n"
+"  creates a vhost-pci-slave",
+QEMU_ARCH_I386)
 
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
diff --git a/vl.c b/vl.c
index d77dd86..10d7f89 100644
--- a/vl.c
+++ b/vl.c
@@ -509,6 +509,20 @@ static QemuOptsList qemu_fw_cfg_opts = {
 },
 };
 
+static QemuOptsList qemu_vhost_pci_slave_opts = {
+.name = "vhost-pci-slave",
+.implied_opt_name = "chardev",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_vhost_pci_slave_opts.head),
+.desc = {
+/*
+ * no elements => accept any
+ * sanity checking will happen later
+ * when setting device properties
+ */
+{ /* end of list */ }
+},
+};
+
 #ifdef CONFIG_LIBISCSI
 static QemuOptsList qemu_iscsi_opts = {
 .name = "iscsi",
@@ -3073,6 +3087,7 @@ int main(int argc, char **argv, char **envp)
 qemu_add_opts(_icount_opts);
 qemu_add_opts(_semihosting_config_opts);
 qemu_add_opts(_fw_cfg_opts);
+qemu_add_opts(_vhost_pci_slave_opts);
 #ifdef CONFIG_LIBISCSI
 qemu_add_opts(_iscsi_opts);
 #endif
@@ -4044,6 +4059,12 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 break;
+case QEMU_OPTION_vhost_pci_slave:
+opts = 
qemu_opts_parse_noisily(qemu_find_opts("vhost-pci-slave"), optarg, false);
+if (!opts) {
+exit(1);
+}
+break;
 default:
 os_parse_cmd_args(popt->index, optarg);
 }
-- 
2.7.4




[Qemu-devel] [PATCH v1 05/37] vhost-pci-slave: start the implementation of vhost-pci-slave

2016-12-17 Thread Wei Wang
Vhost-pci-slave uses a QEMU socket to talk to the master. This patch
associates the slave with the qemu sever socket.

Signed-off-by: Wei Wang 
---
 hw/virtio/Makefile.objs |  1 +
 hw/virtio/vhost-pci-slave.c | 53 +
 include/hw/virtio/vhost-pci-slave.h | 16 +++
 3 files changed, 70 insertions(+)
 create mode 100644 hw/virtio/vhost-pci-slave.c
 create mode 100644 include/hw/virtio/vhost-pci-slave.h

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 95c4c30..3af6787 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -2,6 +2,7 @@ common-obj-y += virtio-rng.o
 common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 common-obj-y += virtio-bus.o
 common-obj-y += virtio-mmio.o
+common-obj-y += vhost-pci-slave.o
 
 obj-y += virtio.o virtio-balloon.o 
 obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
new file mode 100644
index 000..5ff9a09
--- /dev/null
+++ b/hw/virtio/vhost-pci-slave.c
@@ -0,0 +1,53 @@
+/*
+ * Vhost-pci Slave
+ *
+ * Copyright Intel Corp. 2016
+ *
+ * Authors:
+ * Wei Wang
+ *
+ * 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 "qapi/error.h"
+#include "qemu/error-report.h"
+#include "hw/virtio/vhost-pci-slave.h"
+
+VhostPCISlave *vp_slave;
+
+static CharDriverState *vp_slave_parse_chardev(const char *id)
+{
+CharDriverState *chr = qemu_chr_find(id);
+if (chr == NULL) {
+error_report("chardev \"%s\" not found", id);
+return NULL;
+}
+
+return chr;
+}
+
+int vhost_pci_slave_init(QemuOpts *opts)
+{
+CharDriverState *chr;
+const char *chardev_id = qemu_opt_get(opts, "chardev");
+
+vp_slave = (VhostPCISlave *)g_malloc(sizeof(VhostPCISlave));
+chr = vp_slave_parse_chardev(chardev_id);
+if (!chr) {
+return -1;
+}
+qemu_chr_fe_init(_slave->chr_be, chr, _abort);
+
+return 0;
+}
+
+int vhost_pci_slave_cleanup(void)
+{
+qemu_chr_fe_deinit(_slave->chr_be);
+g_free(vp_slave);
+
+return 0;
+}
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
new file mode 100644
index 000..c82c775
--- /dev/null
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -0,0 +1,16 @@
+#ifndef QEMU_VHOST_PCI_SLAVE_H
+#define QEMU_VHOST_PCI_SLAVE_H
+
+#include "sysemu/char.h"
+
+typedef struct VhostPCISlave {
+CharBackend chr_be;
+} VhostPCISlave;
+
+extern VhostPCISlave *vp_slave;
+
+extern int vhost_pci_slave_init(QemuOpts *opts);
+
+extern int vhost_pci_slave_cleanup(void);
+
+#endif
-- 
2.7.4




[Qemu-devel] [PATCH v1 01/37] vhost-pci-net: the fundamental vhost-pci-net device emulation

2016-12-17 Thread Wei Wang
This patch introduces the fundamental parts of the device emulation.

Signed-off-by: Wei Wang 
---
 hw/net/Makefile.objs   |   2 +-
 hw/net/vhost-pci-net.c | 136 +
 include/hw/virtio/vhost-pci-net.h  |  36 +++
 include/standard-headers/linux/vhost_pci_net.h |  43 
 include/standard-headers/linux/virtio_ids.h|  29 +++---
 5 files changed, 231 insertions(+), 15 deletions(-)
 create mode 100644 hw/net/vhost-pci-net.c
 create mode 100644 include/hw/virtio/vhost-pci-net.h
 create mode 100644 include/standard-headers/linux/vhost_pci_net.h

diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs
index 610ed3e..71d6d2e 100644
--- a/hw/net/Makefile.objs
+++ b/hw/net/Makefile.objs
@@ -33,7 +33,7 @@ obj-$(CONFIG_MILKYMIST) += milkymist-minimac2.o
 obj-$(CONFIG_PSERIES) += spapr_llan.o
 obj-$(CONFIG_XILINX_ETHLITE) += xilinx_ethlite.o
 
-obj-$(CONFIG_VIRTIO) += virtio-net.o
+obj-$(CONFIG_VIRTIO) += virtio-net.o vhost-pci-net.o
 obj-y += vhost_net.o
 
 obj-$(CONFIG_ETSEC) += fsl_etsec/etsec.o fsl_etsec/registers.o \
diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c
new file mode 100644
index 000..2050e5f
--- /dev/null
+++ b/hw/net/vhost-pci-net.c
@@ -0,0 +1,136 @@
+/*
+ * vhost-pci-net support
+ *
+ * Copyright Intel, Inc. 2016
+ *
+ * Authors:
+ *  Wei Wang 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/virtio/virtio-access.h"
+#include "hw/virtio/vhost-pci-net.h"
+
+#define VPNET_CQ_SIZE 32
+#define VPNET_RQ_SIZE 256
+
+static void vpnet_handle_rq(VirtIODevice *vdev, VirtQueue *vq)
+{
+}
+
+static void vpnet_handle_crq(VirtIODevice *vdev, VirtQueue *vq)
+{
+}
+
+static void vpnet_set_status(struct VirtIODevice *vdev, uint8_t status)
+{
+}
+
+static uint64_t vpnet_get_features(VirtIODevice *vdev, uint64_t features, 
Error **errp)
+{
+VhostPCINet *vpnet = VHOST_PCI_NET(vdev);
+
+return vpnet->device_features;
+}
+
+static void vpnet_set_features(VirtIODevice *vdev, uint64_t features)
+{
+}
+
+static void vpnet_get_config(VirtIODevice *vdev, uint8_t *config)
+{
+VhostPCINet *vpnet = VHOST_PCI_NET(vdev);
+struct vhost_pci_net_config netcfg;
+
+virtio_stw_p(vdev, , vpnet->status);
+virtio_stw_p(vdev, _vq_num, vpnet->peer_vq_num);
+memcpy(config, , vpnet->config_size);
+}
+
+static void vpnet_set_config(VirtIODevice *vdev, const uint8_t *config)
+{
+}
+
+static void vpnet_device_realize(DeviceState *dev, Error **errp)
+{
+VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+VhostPCINet *vpnet = VHOST_PCI_NET(vdev);
+uint16_t i, rq_num = vpnet->peer_vq_num / 2;
+
+virtio_init(vdev, "vhost-pci-net", VIRTIO_ID_VHOST_PCI_NET,
+vpnet->config_size);
+
+/* control receive quque: host to guest */
+vpnet->crq = virtio_add_queue(vdev, VPNET_CQ_SIZE, vpnet_handle_crq);
+/* datapath receive queue */
+vpnet->rqs = g_malloc0(sizeof(VirtQueue *) * rq_num);
+for (i = 0; i < rq_num; i++) {
+vpnet->rqs[i] = virtio_add_queue(vdev,VPNET_RQ_SIZE,
+ vpnet_handle_rq);
+}
+vpnet->status = 0;
+}
+
+static void vpnet_device_unrealize(DeviceState *dev, Error **errp)
+{
+VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+VhostPCINet *vpnet = VHOST_PCI_NET(vdev);
+uint16_t i, rq_num = vpnet->peer_vq_num / 2;
+
+for (i = 0; i < rq_num + 2; i++)
+virtio_del_queue(vdev, i);
+
+g_free(vpnet->rqs);
+}
+
+static Property vpnet_properties[] = {
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vpnet_instance_init(Object *obj)
+{
+VhostPCINet *vpnet = VHOST_PCI_NET(obj);
+
+/*
+ * The default config_size is sizeof(struct vhost_pci_net_config).
+ * Can be overriden with vpnet_set_config_size.
+ */
+vpnet->config_size = sizeof(struct vhost_pci_net_config);
+}
+
+static void vpnet_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+
+dc->props = vpnet_properties;
+set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
+vdc->realize = vpnet_device_realize;
+vdc->unrealize = vpnet_device_unrealize;
+vdc->get_config = vpnet_get_config;
+vdc->set_config = vpnet_set_config;
+vdc->get_features = vpnet_get_features;
+vdc->set_features = vpnet_set_features;
+vdc->set_status = vpnet_set_status;
+}
+
+static const TypeInfo vpnet_info = {
+.name = TYPE_VHOST_PCI_NET,
+.parent = TYPE_VIRTIO_DEVICE,
+.instance_size = sizeof(VhostPCINet),
+.instance_init = vpnet_instance_init,
+.class_init = vpnet_class_init,
+};
+
+static void 

[Qemu-devel] [PATCH v1 11/37] vhost-user/msg: VHOST_USER_PROTOCOL_F_SET_DEVICE_ID

2016-12-17 Thread Wei Wang
The feature, VHOST_USER_PROTOCOL_F_SET_DEVICE_ID, indicates that the
slave side implementation supports different types of devices. The
master tells the slave what type of device to create by sending the
VHOST_USER_SET_DEVICE_ID message. Currently, only the net type is
supported.

Signed-off-by: Wei Wang 
---
 hw/net/vhost_net.c |  1 +
 hw/virtio/vhost-user.c | 19 +++
 include/hw/virtio/vhost-user.h |  5 -
 include/hw/virtio/vhost.h  |  1 +
 4 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index f2d49ad..6524503 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -152,6 +152,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
 net->dev.max_queues = 1;
 net->dev.nvqs = 2;
 net->dev.vqs = net->vqs;
+net->dev.dev_type = VIRTIO_ID_NET;
 
 if (backend_kernel) {
 r = vhost_net_get_fd(options->net_backend);
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 9e089d4..8b5ac0b 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -452,6 +452,18 @@ static int vhost_user_get_features(struct vhost_dev *dev, 
uint64_t *features)
 return vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features);
 }
 
+static int vhost_user_set_dev_id(struct vhost_dev *dev, uint16_t virtio_id)
+{
+VhostUserMsg msg = {
+.request = VHOST_USER_SET_DEVICE_ID,
+.flags = VHOST_USER_VERSION,
+.payload.u64 = virtio_id,
+.size = sizeof(msg.payload.u64),
+};
+
+return vhost_user_write(dev, , NULL, 0);
+}
+
 static int vhost_user_set_owner(struct vhost_dev *dev)
 {
 VhostUserMsg msg = {
@@ -509,6 +521,13 @@ static int vhost_user_init(struct vhost_dev *dev, void 
*opaque)
 return err;
 }
 
+if (dev->protocol_features & (1ULL << 
VHOST_USER_PROTOCOL_F_SET_DEVICE_ID)) {
+err = vhost_user_set_dev_id(dev, dev->dev_type);
+if (err < 0) {
+return err;
+}
+}
+
 /* query the max queues we support if backend supports Multiple Queue 
*/
 if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) {
 err = vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM,
diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h
index a303513..45f11be 100644
--- a/include/hw/virtio/vhost-user.h
+++ b/include/hw/virtio/vhost-user.h
@@ -12,6 +12,7 @@ enum VhostUserProtocolFeature {
 VHOST_USER_PROTOCOL_F_RARP = 2,
 VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
 VHOST_USER_PROTOCOL_F_VHOST_PCI =4,
+VHOST_USER_PROTOCOL_F_SET_DEVICE_ID = 5,
 
 VHOST_USER_PROTOCOL_F_MAX
 };
@@ -21,7 +22,8 @@ enum VhostUserProtocolFeature {
 #define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
   (1ULL << 
VHOST_USER_PROTOCOL_F_LOG_SHMFD) | \
   (1ULL << VHOST_USER_PROTOCOL_F_RARP)) | \
-  (1ULL << VHOST_USER_PROTOCOL_F_VHOST_PCI)
+  (1ULL << 
VHOST_USER_PROTOCOL_F_VHOST_PCI) | \
+  (1ULL << 
VHOST_USER_PROTOCOL_F_SET_DEVICE_ID)
 
 typedef enum VhostUserRequest {
 VHOST_USER_NONE = 0,
@@ -44,6 +46,7 @@ typedef enum VhostUserRequest {
 VHOST_USER_GET_QUEUE_NUM = 17,
 VHOST_USER_SET_VRING_ENABLE = 18,
 VHOST_USER_SEND_RARP = 19,
+VHOST_USER_SET_DEVICE_ID = 20,
 VHOST_USER_MAX
 } VhostUserRequest;
 
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 1fe5aad..9cf32e2 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -43,6 +43,7 @@ struct vhost_dev {
 int n_mem_sections;
 MemoryRegionSection *mem_sections;
 struct vhost_virtqueue *vqs;
+uint16_t dev_type;
 int nvqs;
 /* the first virtqueue which would be used by this vhost dev */
 int vq_index;
-- 
2.7.4




[Qemu-devel] [PATCH v1 09/37] vhost-pci-slave/msg: VHOST_USER_GET_PROTOCOL_FEATURES

2016-12-17 Thread Wei Wang
Add a new protocol feature, VHOST_USER_PROTOCOL_F_VHOST_PCI. This
feature indicates the support of the vhost-pci extension for inter-vm
communiaction.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c| 14 ++
 include/hw/virtio/vhost-user.h |  6 ++
 2 files changed, 20 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index bc6120c..ac9deae 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -67,6 +67,15 @@ static void vp_slave_event(void *opaque, int event)
 }
 }
 
+static int vp_slave_get_protocol_features(CharBackend *chr_be, VhostUserMsg 
*msg)
+{
+msg->payload.u64 = VHOST_USER_PROTOCOL_FEATURES;
+msg->size = sizeof(msg->payload.u64);
+msg->flags |= VHOST_USER_REPLY_MASK;
+
+return vp_slave_write(chr_be, msg);
+}
+
 static int vp_slave_can_read(void *opaque)
 {
 return VHOST_USER_HDR_SIZE;
@@ -108,6 +117,11 @@ static void vp_slave_read(void *opaque, const uint8_t 
*buf, int size)
 case VHOST_USER_SET_FEATURES:
 vp_slave_set_features();
 break;
+case VHOST_USER_GET_PROTOCOL_FEATURES:
+ret = vp_slave_get_protocol_features(chr_be, );
+if (ret < 0)
+goto err_handling;
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h
index c189b26..a303513 100644
--- a/include/hw/virtio/vhost-user.h
+++ b/include/hw/virtio/vhost-user.h
@@ -11,12 +11,18 @@ enum VhostUserProtocolFeature {
 VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
 VHOST_USER_PROTOCOL_F_RARP = 2,
 VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
+VHOST_USER_PROTOCOL_F_VHOST_PCI =4,
 
 VHOST_USER_PROTOCOL_F_MAX
 };
 
 #define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX) - 1)
 
+#define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
+  (1ULL << 
VHOST_USER_PROTOCOL_F_LOG_SHMFD) | \
+  (1ULL << VHOST_USER_PROTOCOL_F_RARP)) | \
+  (1ULL << VHOST_USER_PROTOCOL_F_VHOST_PCI)
+
 typedef enum VhostUserRequest {
 VHOST_USER_NONE = 0,
 VHOST_USER_GET_FEATURES = 1,
-- 
2.7.4




[Qemu-devel] [PATCH v1 07/37] vhost-pci-slave/msg: VHOST_USER_GET_FEATURES

2016-12-17 Thread Wei Wang
Offer the initial feature bits, which haven't been negotiated with the slave
driver, to the master.

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-pci-slave.c | 42 +
 include/hw/virtio/vhost-pci-slave.h |  1 +
 2 files changed, 43 insertions(+)

diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c
index 2278f63..4f445c2 100644
--- a/hw/virtio/vhost-pci-slave.c
+++ b/hw/virtio/vhost-pci-slave.c
@@ -14,11 +14,42 @@
 
 #include "qapi/error.h"
 #include "qemu/error-report.h"
+#include "hw/virtio/virtio-pci.h"
 #include "hw/virtio/vhost-pci-slave.h"
 #include "hw/virtio/vhost-user.h"
 
+#define VHOST_PCI_FEATURE_BITS (1ULL << VIRTIO_F_VERSION_1)
+
+#define VHOST_PCI_NET_FEATURE_BITS (1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
+   (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
+   (1ULL << VIRTIO_NET_F_MQ)
+
 VhostPCISlave *vp_slave;
 
+static int vp_slave_write(CharBackend *chr_be, VhostUserMsg *msg)
+{
+int size;
+
+if (!msg)
+return 0;
+
+size = msg->size + VHOST_USER_HDR_SIZE;
+msg->flags &= ~VHOST_USER_VERSION_MASK;
+msg->flags |= VHOST_USER_VERSION;
+
+return qemu_chr_fe_write_all(chr_be, (const uint8_t *)msg, size)
+   == size ? 0 : -1;
+}
+
+static int vp_slave_get_features(CharBackend *chr_be, VhostUserMsg *msg)
+{
+msg->payload.u64 = vp_slave->feature_bits;
+msg->size = sizeof(msg->payload.u64);
+msg->flags |= VHOST_USER_REPLY_MASK;
+
+return vp_slave_write(chr_be, msg);
+}
+
 static void vp_slave_event(void *opaque, int event)
 {
 switch (event) {
@@ -36,6 +67,7 @@ static int vp_slave_can_read(void *opaque)
 
 static void vp_slave_read(void *opaque, const uint8_t *buf, int size)
 {
+int ret;
 VhostUserMsg msg;
 uint8_t *p = (uint8_t *) 
 CharBackend *chr_be = (CharBackend *)opaque;
@@ -61,11 +93,20 @@ static void vp_slave_read(void *opaque, const uint8_t *buf, 
int size)
 error_report("vhost-pci-slave read incorrect msg");
 
 switch(msg.request) {
+case VHOST_USER_GET_FEATURES:
+ret = vp_slave_get_features(chr_be, );
+if (ret < 0)
+goto err_handling;
+break;
 default:
 error_report("vhost-pci-slave does not support msg request = %d",
  msg.request);
 break;
 }
+return;
+
+err_handling:
+error_report("vhost-pci-slave handle request %d failed", msg.request);
 }
 
 static CharDriverState *vp_slave_parse_chardev(const char *id)
@@ -89,6 +130,7 @@ int vhost_pci_slave_init(QemuOpts *opts)
 if (!chr) {
 return -1;
 }
+vp_slave->feature_bits =  1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
 qemu_chr_fe_init(_slave->chr_be, chr, _abort);
 qemu_chr_fe_set_handlers(_slave->chr_be, vp_slave_can_read,
  vp_slave_read, vp_slave_event,
diff --git a/include/hw/virtio/vhost-pci-slave.h 
b/include/hw/virtio/vhost-pci-slave.h
index c82c775..4ec25d4 100644
--- a/include/hw/virtio/vhost-pci-slave.h
+++ b/include/hw/virtio/vhost-pci-slave.h
@@ -5,6 +5,7 @@
 
 typedef struct VhostPCISlave {
 CharBackend chr_be;
+uint64_t feature_bits;
 } VhostPCISlave;
 
 extern VhostPCISlave *vp_slave;
-- 
2.7.4




[Qemu-devel] [PATCH v1 02/37] vhost-pci-net: the fundamental implementation of vhost-pci-net-pci

2016-12-17 Thread Wei Wang
Signed-off-by: Wei Wang 
---
 hw/virtio/virtio-pci.c | 46 ++
 hw/virtio/virtio-pci.h | 14 ++
 include/hw/pci/pci.h   |  1 +
 3 files changed, 61 insertions(+)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 21c2b9d..baf70b4 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -21,6 +21,7 @@
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
+#include "hw/virtio/vhost-pci-net.h"
 #include "hw/virtio/virtio-serial.h"
 #include "hw/virtio/virtio-scsi.h"
 #include "hw/virtio/virtio-balloon.h"
@@ -2309,6 +2310,50 @@ static const TypeInfo virtio_net_pci_info = {
 .class_init= virtio_net_pci_class_init,
 };
 
+/* vhost-pci-net */
+
+static Property vpnet_pci_properties[] = {
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vpnet_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VhostPCINetPCI *dev = VHOST_PCI_NET_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void vpnet_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass);
+
+k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+k->device_id = PCI_DEVICE_ID_VHOST_PCI_NET;
+k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
+dc->props = vpnet_pci_properties;
+vpciklass->realize = vpnet_pci_realize;
+}
+
+static void vpnet_pci_instance_init(Object *obj)
+{
+VhostPCINetPCI *dev = VHOST_PCI_NET_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VHOST_PCI_NET);
+}
+
+static const TypeInfo vpnet_pci_info = {
+.name  = TYPE_VHOST_PCI_NET_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VhostPCINetPCI),
+.instance_init = vpnet_pci_instance_init,
+.class_init= vpnet_pci_class_init,
+};
+
 /* virtio-rng-pci */
 
 static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
@@ -2537,6 +2582,7 @@ static void virtio_pci_register_types(void)
 type_register_static(_keyboard_pci_info);
 type_register_static(_mouse_pci_info);
 type_register_static(_tablet_pci_info);
+type_register_static(_pci_info);
 #ifdef CONFIG_LINUX
 type_register_static(_host_pci_info);
 #endif
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 5e07886..0b4b04f 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -18,6 +18,7 @@
 #include "hw/pci/msi.h"
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
+#include "hw/virtio/vhost-pci-net.h"
 #include "hw/virtio/virtio-rng.h"
 #include "hw/virtio/virtio-serial.h"
 #include "hw/virtio/virtio-scsi.h"
@@ -43,6 +44,7 @@ typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
 typedef struct VirtIONetPCI VirtIONetPCI;
+typedef struct VhostPCINetPCI VhostPCINetPCI;
 typedef struct VHostSCSIPCI VHostSCSIPCI;
 typedef struct VirtIORngPCI VirtIORngPCI;
 typedef struct VirtIOInputPCI VirtIOInputPCI;
@@ -262,6 +264,18 @@ struct VirtIONetPCI {
 VirtIONet vdev;
 };
 
+ /*
+ * vhost-pci-net-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VHOST_PCI_NET_PCI "vhost-pci-net-pci"
+#define VHOST_PCI_NET_PCI(obj) \
+OBJECT_CHECK(VhostPCINetPCI, (obj), TYPE_VHOST_PCI_NET_PCI)
+
+struct VhostPCINetPCI {
+VirtIOPCIProxy parent_obj;
+VhostPCINet vdev;
+};
+
 /*
  * virtio-9p-pci: This extends VirtioPCIProxy.
  */
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 772692f..ef8468b 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -83,6 +83,7 @@
 #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P  0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK   0x1012
+#define PCI_DEVICE_ID_VHOST_PCI_NET  0x1014
 
 #define PCI_VENDOR_ID_REDHAT 0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE  0x0001
-- 
2.7.4




[Qemu-devel] [PATCH v1 03/37] vhost-user: share the vhost-user protocol related structures

2016-12-17 Thread Wei Wang
Put the vhost-user protocol related data structures into vhost-user.h,
so that they can be used in other implementations (e.g. a slave
implementation).

Signed-off-by: Wei Wang 
---
 hw/virtio/vhost-user.c | 87 +---
 include/hw/virtio/vhost-user.h | 91 ++
 include/net/vhost-user.h   |  4 +-
 3 files changed, 94 insertions(+), 88 deletions(-)
 create mode 100644 include/hw/virtio/vhost-user.h

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 7ee92b3..9e089d4 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -12,6 +12,7 @@
 #include "qapi/error.h"
 #include "hw/virtio/vhost.h"
 #include "hw/virtio/vhost-backend.h"
+#include "hw/virtio/vhost-user.h"
 #include "hw/virtio/virtio-net.h"
 #include "sysemu/char.h"
 #include "sysemu/kvm.h"
@@ -22,92 +23,6 @@
 #include 
 #include 
 #include 
-#include 
-
-#define VHOST_MEMORY_MAX_NREGIONS8
-#define VHOST_USER_F_PROTOCOL_FEATURES 30
-
-enum VhostUserProtocolFeature {
-VHOST_USER_PROTOCOL_F_MQ = 0,
-VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
-VHOST_USER_PROTOCOL_F_RARP = 2,
-VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
-
-VHOST_USER_PROTOCOL_F_MAX
-};
-
-#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX) - 1)
-
-typedef enum VhostUserRequest {
-VHOST_USER_NONE = 0,
-VHOST_USER_GET_FEATURES = 1,
-VHOST_USER_SET_FEATURES = 2,
-VHOST_USER_SET_OWNER = 3,
-VHOST_USER_RESET_OWNER = 4,
-VHOST_USER_SET_MEM_TABLE = 5,
-VHOST_USER_SET_LOG_BASE = 6,
-VHOST_USER_SET_LOG_FD = 7,
-VHOST_USER_SET_VRING_NUM = 8,
-VHOST_USER_SET_VRING_ADDR = 9,
-VHOST_USER_SET_VRING_BASE = 10,
-VHOST_USER_GET_VRING_BASE = 11,
-VHOST_USER_SET_VRING_KICK = 12,
-VHOST_USER_SET_VRING_CALL = 13,
-VHOST_USER_SET_VRING_ERR = 14,
-VHOST_USER_GET_PROTOCOL_FEATURES = 15,
-VHOST_USER_SET_PROTOCOL_FEATURES = 16,
-VHOST_USER_GET_QUEUE_NUM = 17,
-VHOST_USER_SET_VRING_ENABLE = 18,
-VHOST_USER_SEND_RARP = 19,
-VHOST_USER_MAX
-} VhostUserRequest;
-
-typedef struct VhostUserMemoryRegion {
-uint64_t guest_phys_addr;
-uint64_t memory_size;
-uint64_t userspace_addr;
-uint64_t mmap_offset;
-} VhostUserMemoryRegion;
-
-typedef struct VhostUserMemory {
-uint32_t nregions;
-uint32_t padding;
-VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS];
-} VhostUserMemory;
-
-typedef struct VhostUserLog {
-uint64_t mmap_size;
-uint64_t mmap_offset;
-} VhostUserLog;
-
-typedef struct VhostUserMsg {
-VhostUserRequest request;
-
-#define VHOST_USER_VERSION_MASK (0x3)
-#define VHOST_USER_REPLY_MASK   (0x1<<2)
-#define VHOST_USER_NEED_REPLY_MASK  (0x1 << 3)
-uint32_t flags;
-uint32_t size; /* the following payload size */
-union {
-#define VHOST_USER_VRING_IDX_MASK   (0xff)
-#define VHOST_USER_VRING_NOFD_MASK  (0x1<<8)
-uint64_t u64;
-struct vhost_vring_state state;
-struct vhost_vring_addr addr;
-VhostUserMemory memory;
-VhostUserLog log;
-} payload;
-} QEMU_PACKED VhostUserMsg;
-
-static VhostUserMsg m __attribute__ ((unused));
-#define VHOST_USER_HDR_SIZE (sizeof(m.request) \
-+ sizeof(m.flags) \
-+ sizeof(m.size))
-
-#define VHOST_USER_PAYLOAD_SIZE (sizeof(m) - VHOST_USER_HDR_SIZE)
-
-/* The version of the protocol we support */
-#define VHOST_USER_VERSION(0x1)
 
 static bool ioeventfd_enabled(void)
 {
diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h
new file mode 100644
index 000..c189b26
--- /dev/null
+++ b/include/hw/virtio/vhost-user.h
@@ -0,0 +1,91 @@
+#ifndef VHOST_USER_H
+#define VHOST_USER_H
+
+#include 
+
+#define VHOST_MEMORY_MAX_NREGIONS8
+#define VHOST_USER_F_PROTOCOL_FEATURES 30
+
+enum VhostUserProtocolFeature {
+VHOST_USER_PROTOCOL_F_MQ = 0,
+VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
+VHOST_USER_PROTOCOL_F_RARP = 2,
+VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
+
+VHOST_USER_PROTOCOL_F_MAX
+};
+
+#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX) - 1)
+
+typedef enum VhostUserRequest {
+VHOST_USER_NONE = 0,
+VHOST_USER_GET_FEATURES = 1,
+VHOST_USER_SET_FEATURES = 2,
+VHOST_USER_SET_OWNER = 3,
+VHOST_USER_RESET_OWNER = 4,
+VHOST_USER_SET_MEM_TABLE = 5,
+VHOST_USER_SET_LOG_BASE = 6,
+VHOST_USER_SET_LOG_FD = 7,
+VHOST_USER_SET_VRING_NUM = 8,
+VHOST_USER_SET_VRING_ADDR = 9,
+VHOST_USER_SET_VRING_BASE = 10,
+VHOST_USER_GET_VRING_BASE = 11,
+VHOST_USER_SET_VRING_KICK = 12,
+VHOST_USER_SET_VRING_CALL = 13,
+VHOST_USER_SET_VRING_ERR = 14,
+VHOST_USER_GET_PROTOCOL_FEATURES = 15,
+VHOST_USER_SET_PROTOCOL_FEATURES = 16,
+VHOST_USER_GET_QUEUE_NUM = 17,
+VHOST_USER_SET_VRING_ENABLE = 18,
+VHOST_USER_SEND_RARP = 19,
+VHOST_USER_MAX
+} VhostUserRequest;
+

[Qemu-devel] [PATCH v1 00/37] Implementation of vhost-pci for inter-vm commucation

2016-12-17 Thread Wei Wang
This patch series implements vhost-pci, which is a point-to-point based inter-vm
communication solution. The QEMU side implementation includes the vhost-user
extension, vhost-pci device emulation and management. The current device part
implementation is based on virtio 1.0, but it can be easily upgraded to support
the upcoming virtio 1.1. 

The current QEMU implementation supports the polling mode driver on both sides
to receive packets. More features, such as interrupt support, live migration
support, protection memory accesses will be added later.


Wei Wang (37):
  vhost-pci-net: the fundamental vhost-pci-net device emulation
  vhost-pci-net: the fundamental implementation of vhost-pci-net-pci
  vhost-user: share the vhost-user protocol related structures
  vl: add the vhost-pci-slave command line option
  vhost-pci-slave: start the implementation of vhost-pci-slave
  vhost-pci-slave: set up the fundamental handlers for the server socket
  vhost-pci-slave/msg: VHOST_USER_GET_FEATURES
  vhost-pci-slave/msg: VHOST_USER_SET_FEATURES
  vhost-pci-slave/msg: VHOST_USER_GET_PROTOCOL_FEATURES
  vhost-pci-slave/msg: VHOST_USER_SET_PROTOCOL_FEATURES
  vhost-user/msg: VHOST_USER_PROTOCOL_F_SET_DEVICE_ID
  vhost-pci-slave/msg: VHOST_USER_SET_DEVICE_ID
  vhost-pci-slave/msg: VHOST_USER_GET_QUEUE_NUM
  vhost-pci-slave/msg: VHOST_USER_SET_OWNER
  vhost-pci-slave/msg: VHOST_USER_SET_MEM_TABLE
  vhost-pci-slave/msg: VHOST_USER_SET_VRING_NUM
  vhost-pci-slave/msg: VHOST_USER_SET_VRING_BASE
  vhost-user: send guest physical address of virtqueues to the slave
  vhost-pci-slave/msg: VHOST_USER_SET_VRING_ADDR
  vhost-pci-slave/msg: VHOST_USER_SET_VRING_KICK
  vhost-pci-slave/msg: VHOST_USER_SET_VRING_CALL
  vhost-pci-slave/msg: VHOST_USER_SET_VRING_ENABLE
  vhost-pci-slave/msg: VHOST_USER_SET_LOG_BASE
  vhost-pci-slave/msg: VHOST_USER_SET_LOG_FD
  vhost-pci-slave/msg: VHOST_USER_SEND_RARP
  vhost-pci-slave/msg: VHOST_USER_GET_VRING_BASE
  vhost-pci-net: pass the info collected by vp_slave to the device
  vhost-pci-net: pass the mem and vring info to the driver
  vhost-pci-slave/msg: VHOST_USER_SET_VHOST_PCI (start)
  vhost-pci-slave/msg: VHOST_USER_SET_VHOST_PCI (stop)
  vhost-user/msg: send VHOST_USER_SET_VHOST_PCI (start/stop)
  vhost-user: add asynchronous read for the vhost-user master
  vhost-pci-net: send the negotiated feature bits to the master
  vhost-pci-slave: add "peer_reset"
  vhost-pci-net: start the vhost-pci-net device
  vhost-user/msg: handling VHOST_USER_SET_FEATURES
  vl: enable vhost-pci-slave

 hw/net/Makefile.objs   |   2 +-
 hw/net/vhost-pci-net.c | 263 
 hw/net/vhost_net.c |  37 ++
 hw/virtio/Makefile.objs|   1 +
 hw/virtio/vhost-pci-slave.c| 552 +
 hw/virtio/vhost-user.c | 184 +
 hw/virtio/vhost.c  |  61 ++-
 hw/virtio/virtio-pci.c |  80 
 hw/virtio/virtio-pci.h |  16 +
 include/hw/pci/pci.h   |   1 +
 include/hw/virtio/vhost-backend.h  |   2 +
 include/hw/virtio/vhost-pci-net.h  |  45 ++
 include/hw/virtio/vhost-pci-slave.h|  46 +++
 include/hw/virtio/vhost-user.h | 109 +
 include/hw/virtio/vhost.h  |   3 +
 include/net/vhost-user.h   |  22 +-
 include/net/vhost_net.h|   2 +
 include/standard-headers/linux/vhost_pci_net.h |  85 
 include/standard-headers/linux/virtio_ids.h|  29 +-
 net/vhost-user.c   |  34 +-
 qemu-options.hx|   4 +
 vl.c   |  41 ++
 22 files changed, 1485 insertions(+), 134 deletions(-)
 create mode 100644 hw/net/vhost-pci-net.c
 create mode 100644 hw/virtio/vhost-pci-slave.c
 create mode 100644 include/hw/virtio/vhost-pci-net.h
 create mode 100644 include/hw/virtio/vhost-pci-slave.h
 create mode 100644 include/hw/virtio/vhost-user.h
 create mode 100644 include/standard-headers/linux/vhost_pci_net.h

-- 
2.7.4




Re: [Qemu-devel] [Nbd] [PATCH] Further tidy-up on block status

2016-12-17 Thread Alex Bligh

> On 17 Dec 2016, at 08:34, Wouter Verhelst  wrote:
> 
> I've therefore removed that restriction as well as the "255 bytes max"
> one that you added, since I don't think they make much sense. That
> doesn't mean I can't be convinced otherwise by good arguments, but
> they'd have to be very good ones ;-)

But we were at cross purposes. I was talking about the return from
queries, and you've adjusted namespaces (in toto). I've fixed up
your edit slightly, and brought the return for queries in line
with it. I hope this nit is now dead!

-- 
Alex Bligh







Re: [Qemu-devel] [Nbd] [PATCH] Further tidy-up on block status

2016-12-17 Thread Wouter Verhelst
On Fri, Dec 16, 2016 at 04:25:27PM +, Alex Bligh wrote:
> 
> > On 16 Dec 2016, at 15:52, Wouter Verhelst  wrote:
> > 
> > On Thu, Dec 15, 2016 at 05:34:48PM +, Alex Bligh wrote:
> >> 
> >>> On 15 Dec 2016, at 16:49, Wouter Verhelst  wrote:
> >>> 
>  Because the namespaces and leaf-names are already restricted to
>  non-whitespace characters. I thought having tabs, line feeds,
>  returns, em-space, en-space etc. was not particularly useful.
>  I could be persuaded to relent re spaces.
> >>> 
> >>> I could imagine that the context might include as part of its name a
> >>> user-defined bit. If we're going to disallow whitespace, then that would
> >>> mean namespaces would have to do all sorts of escaping etc. I don't
> >>> think that's a good idea.
> >> 
> >> So to be clear do you want to include all whitespace
> >> everywhere? Or just to the right of the colon in queries?
> > 
> > Just in queries. I agree that in namespace names, it doesn't make much
> > sense.
> 
> I've changed it so the returns from queries can now have spaces to
> the right of the colon if they aren't returning complete context names.
> Obviously if they are returning context names, by the definition of
> leaf-names they can't have spaces in the leaf-name.

Sorry, that still doesn't alleviate my concerns.

Why are we restricting what metadata contexts can use for their names?
We don't restrict what export names can use either, and I could imagine
a metadata context wanting to use an export name as a metadata context
name (e.g., "provide a bitmap on the diff between this export and the
export defined by name XYZ").

As soon as we get to the right of the colon, what sits there is defined
by the namespace, not by us. It doesn't feel right to add too many
restrictions.

I think the whole query string should be a "string" as laid out earlier
in the document. Here, it actually *does* make sense for a string to be
very long, because it's not meant to be human-readable.

I've therefore removed that restriction as well as the "255 bytes max"
one that you added, since I don't think they make much sense. That
doesn't mean I can't be convinced otherwise by good arguments, but
they'd have to be very good ones ;-)

> The queries themselves can consist of anything (currently),
> save that they must begin with a namespace and a colon.

Sure.

-- 
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
   people in the world who think they really understand all of its rules,
   and pretty much all of them are just lying to themselves too.
 -- #debian-devel, OFTC, 2016-02-12