qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation
@ 2015-12-04  3:52 Tetsuya Mukawa
  2015-12-04 13:20 ` Marc-André Lureau
  2015-12-21  3:47 ` [Qemu-devel] [PATCH v2] " Tetsuya Mukawa
  0 siblings, 2 replies; 8+ messages in thread
From: Tetsuya Mukawa @ 2015-12-04  3:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Tetsuya Mukawa

If virtio-net driver allocates memory in vishmem shared memory,
vhost-net will work correctly, but vhost-user will not work because
a fd of shared memory will not be sent to vhost-user backend.
This patch fixes ivshmem to store file descriptor of shared memory.
It will be used when vhost-user negotiates vhost-user backend.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 exec.c                  | 10 ++++++++++
 hw/misc/ivshmem.c       |  9 +++++++--
 include/exec/ram_addr.h |  1 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/exec.c b/exec.c
index 0bf0a6e..908c4bf 100644
--- a/exec.c
+++ b/exec.c
@@ -1796,6 +1796,16 @@ int qemu_get_ram_fd(ram_addr_t addr)
     return fd;
 }
 
+void qemu_set_ram_fd(ram_addr_t addr, int fd)
+{
+    RAMBlock *block;
+
+    rcu_read_lock();
+    block = qemu_get_ram_block(addr);
+    block->fd = fd;
+    rcu_read_unlock();
+}
+
 void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
 {
     RAMBlock *block;
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index f73f0c2..df585de 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -29,6 +29,7 @@
 #include "sysemu/char.h"
 #include "sysemu/hostmem.h"
 #include "qapi/visitor.h"
+#include "exec/ram_addr.h"
 
 #include "hw/misc/ivshmem.h"
 
@@ -422,6 +423,7 @@ static int create_shared_memory_BAR(IVShmemState *s, int fd, uint8_t attr,
 
     memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2",
                                s->ivshmem_size, ptr);
+    qemu_set_ram_fd(s->ivshmem.ram_addr, fd);
     vmstate_register_ram(&s->ivshmem, DEVICE(s));
     memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
 
@@ -682,6 +684,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
         }
         memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s),
                                    "ivshmem.bar2", s->ivshmem_size, map_ptr);
+        qemu_set_ram_fd(s->ivshmem.ram_addr, incoming_fd);
         vmstate_register_ram(&s->ivshmem, DEVICE(s));
 
         IVSHMEM_DPRINTF("guest h/w addr = %p, size = %" PRIu64 "\n",
@@ -689,7 +692,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
 
         memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
 
-        close(incoming_fd);
         return;
     }
 
@@ -991,7 +993,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
         }
 
         create_shared_memory_BAR(s, fd, attr, errp);
-        close(fd);
     }
 }
 
@@ -1010,11 +1011,15 @@ static void pci_ivshmem_exit(PCIDevice *dev)
     if (memory_region_is_mapped(&s->ivshmem)) {
         if (!s->hostmem) {
             void *addr = memory_region_get_ram_ptr(&s->ivshmem);
+            int fd;
 
             if (munmap(addr, s->ivshmem_size) == -1) {
                 error_report("Failed to munmap shared memory %s",
                              strerror(errno));
             }
+
+            if ((fd = qemu_get_ram_fd(s->ivshmem.ram_addr)) != -1)
+                close(fd);
         }
 
         vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 7115154..9ca659a 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -72,6 +72,7 @@ ram_addr_t qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
                                                      void *host),
                                      MemoryRegion *mr, Error **errp);
 int qemu_get_ram_fd(ram_addr_t addr);
+void qemu_set_ram_fd(ram_addr_t addr, int fd);
 void *qemu_get_ram_block_host_ptr(ram_addr_t addr);
 void *qemu_get_ram_ptr(ram_addr_t addr);
 void qemu_ram_free(ram_addr_t addr);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation
  2015-12-04  3:52 [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation Tetsuya Mukawa
@ 2015-12-04 13:20 ` Marc-André Lureau
  2015-12-04 14:55   ` Tetsuya Mukawa
  2015-12-21  3:47 ` [Qemu-devel] [PATCH v2] " Tetsuya Mukawa
  1 sibling, 1 reply; 8+ messages in thread
From: Marc-André Lureau @ 2015-12-04 13:20 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: QEMU

Hi

On Fri, Dec 4, 2015 at 4:52 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
> If virtio-net driver allocates memory in vishmem shared memory,

s/vishmem/ivshmem

How can virtio-net allocate memory in ivshmem memory bar?

What's the use case or test case?

> vhost-net will work correctly, but vhost-user will not work because
> a fd of shared memory will not be sent to vhost-user backend.
> This patch fixes ivshmem to store file descriptor of shared memory.
> It will be used when vhost-user negotiates vhost-user backend.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  exec.c                  | 10 ++++++++++
>  hw/misc/ivshmem.c       |  9 +++++++--
>  include/exec/ram_addr.h |  1 +
>  3 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index 0bf0a6e..908c4bf 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1796,6 +1796,16 @@ int qemu_get_ram_fd(ram_addr_t addr)
>      return fd;
>  }
>
> +void qemu_set_ram_fd(ram_addr_t addr, int fd)
> +{
> +    RAMBlock *block;
> +
> +    rcu_read_lock();
> +    block = qemu_get_ram_block(addr);
> +    block->fd = fd;
> +    rcu_read_unlock();
> +}
> +
>  void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
>  {
>      RAMBlock *block;
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index f73f0c2..df585de 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -29,6 +29,7 @@
>  #include "sysemu/char.h"
>  #include "sysemu/hostmem.h"
>  #include "qapi/visitor.h"
> +#include "exec/ram_addr.h"
>
>  #include "hw/misc/ivshmem.h"
>
> @@ -422,6 +423,7 @@ static int create_shared_memory_BAR(IVShmemState *s, int fd, uint8_t attr,
>
>      memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2",
>                                 s->ivshmem_size, ptr);
> +    qemu_set_ram_fd(s->ivshmem.ram_addr, fd);
>      vmstate_register_ram(&s->ivshmem, DEVICE(s));
>      memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
>
> @@ -682,6 +684,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
>          }
>          memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s),
>                                     "ivshmem.bar2", s->ivshmem_size, map_ptr);
> +        qemu_set_ram_fd(s->ivshmem.ram_addr, incoming_fd);
>          vmstate_register_ram(&s->ivshmem, DEVICE(s));
>
>          IVSHMEM_DPRINTF("guest h/w addr = %p, size = %" PRIu64 "\n",
> @@ -689,7 +692,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
>
>          memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
>
> -        close(incoming_fd);
>          return;
>      }
>
> @@ -991,7 +993,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
>          }
>
>          create_shared_memory_BAR(s, fd, attr, errp);
> -        close(fd);
>      }
>  }
>
> @@ -1010,11 +1011,15 @@ static void pci_ivshmem_exit(PCIDevice *dev)
>      if (memory_region_is_mapped(&s->ivshmem)) {
>          if (!s->hostmem) {
>              void *addr = memory_region_get_ram_ptr(&s->ivshmem);
> +            int fd;
>
>              if (munmap(addr, s->ivshmem_size) == -1) {
>                  error_report("Failed to munmap shared memory %s",
>                               strerror(errno));
>              }
> +
> +            if ((fd = qemu_get_ram_fd(s->ivshmem.ram_addr)) != -1)
> +                close(fd);
>          }
>
>          vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index 7115154..9ca659a 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -72,6 +72,7 @@ ram_addr_t qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
>                                                       void *host),
>                                       MemoryRegion *mr, Error **errp);
>  int qemu_get_ram_fd(ram_addr_t addr);
> +void qemu_set_ram_fd(ram_addr_t addr, int fd);
>  void *qemu_get_ram_block_host_ptr(ram_addr_t addr);
>  void *qemu_get_ram_ptr(ram_addr_t addr);
>  void qemu_ram_free(ram_addr_t addr);
> --
> 2.1.4
>
>



-- 
Marc-André Lureau

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation
  2015-12-04 13:20 ` Marc-André Lureau
@ 2015-12-04 14:55   ` Tetsuya Mukawa
  2015-12-07 11:31     ` Marc-André Lureau
  0 siblings, 1 reply; 8+ messages in thread
From: Tetsuya Mukawa @ 2015-12-04 14:55 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: QEMU

2015-12-04 22:20 GMT+09:00 Marc-André Lureau <marcandre.lureau@gmail.com>:
> Hi
>
> On Fri, Dec 4, 2015 at 4:52 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>> If virtio-net driver allocates memory in vishmem shared memory,
>
> s/vishmem/ivshmem

Thanks, I will fix it.

>
> How can virtio-net allocate memory in ivshmem memory bar?
>
> What's the use case or test case?

One of example is userspace device driver like DPDK PMD.
Actually, I've found this fd related behavior using DPDK virtio-net PMD.
Could you please check below to know my use case more?
http://thread.gmane.org/gmane.comp.networking.dpdk.devel/28467/focus=28493

Tetsuya,

>
>> vhost-net will work correctly, but vhost-user will not work because
>> a fd of shared memory will not be sent to vhost-user backend.
>> This patch fixes ivshmem to store file descriptor of shared memory.
>> It will be used when vhost-user negotiates vhost-user backend.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  exec.c                  | 10 ++++++++++
>>  hw/misc/ivshmem.c       |  9 +++++++--
>>  include/exec/ram_addr.h |  1 +
>>  3 files changed, 18 insertions(+), 2 deletions(-)
>>
>> diff --git a/exec.c b/exec.c
>> index 0bf0a6e..908c4bf 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -1796,6 +1796,16 @@ int qemu_get_ram_fd(ram_addr_t addr)
>>      return fd;
>>  }
>>
>> +void qemu_set_ram_fd(ram_addr_t addr, int fd)
>> +{
>> +    RAMBlock *block;
>> +
>> +    rcu_read_lock();
>> +    block = qemu_get_ram_block(addr);
>> +    block->fd = fd;
>> +    rcu_read_unlock();
>> +}
>> +
>>  void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
>>  {
>>      RAMBlock *block;
>> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
>> index f73f0c2..df585de 100644
>> --- a/hw/misc/ivshmem.c
>> +++ b/hw/misc/ivshmem.c
>> @@ -29,6 +29,7 @@
>>  #include "sysemu/char.h"
>>  #include "sysemu/hostmem.h"
>>  #include "qapi/visitor.h"
>> +#include "exec/ram_addr.h"
>>
>>  #include "hw/misc/ivshmem.h"
>>
>> @@ -422,6 +423,7 @@ static int create_shared_memory_BAR(IVShmemState *s, int fd, uint8_t attr,
>>
>>      memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2",
>>                                 s->ivshmem_size, ptr);
>> +    qemu_set_ram_fd(s->ivshmem.ram_addr, fd);
>>      vmstate_register_ram(&s->ivshmem, DEVICE(s));
>>      memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
>>
>> @@ -682,6 +684,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
>>          }
>>          memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s),
>>                                     "ivshmem.bar2", s->ivshmem_size, map_ptr);
>> +        qemu_set_ram_fd(s->ivshmem.ram_addr, incoming_fd);
>>          vmstate_register_ram(&s->ivshmem, DEVICE(s));
>>
>>          IVSHMEM_DPRINTF("guest h/w addr = %p, size = %" PRIu64 "\n",
>> @@ -689,7 +692,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
>>
>>          memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
>>
>> -        close(incoming_fd);
>>          return;
>>      }
>>
>> @@ -991,7 +993,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
>>          }
>>
>>          create_shared_memory_BAR(s, fd, attr, errp);
>> -        close(fd);
>>      }
>>  }
>>
>> @@ -1010,11 +1011,15 @@ static void pci_ivshmem_exit(PCIDevice *dev)
>>      if (memory_region_is_mapped(&s->ivshmem)) {
>>          if (!s->hostmem) {
>>              void *addr = memory_region_get_ram_ptr(&s->ivshmem);
>> +            int fd;
>>
>>              if (munmap(addr, s->ivshmem_size) == -1) {
>>                  error_report("Failed to munmap shared memory %s",
>>                               strerror(errno));
>>              }
>> +
>> +            if ((fd = qemu_get_ram_fd(s->ivshmem.ram_addr)) != -1)
>> +                close(fd);
>>          }
>>
>>          vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
>> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
>> index 7115154..9ca659a 100644
>> --- a/include/exec/ram_addr.h
>> +++ b/include/exec/ram_addr.h
>> @@ -72,6 +72,7 @@ ram_addr_t qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
>>                                                       void *host),
>>                                       MemoryRegion *mr, Error **errp);
>>  int qemu_get_ram_fd(ram_addr_t addr);
>> +void qemu_set_ram_fd(ram_addr_t addr, int fd);
>>  void *qemu_get_ram_block_host_ptr(ram_addr_t addr);
>>  void *qemu_get_ram_ptr(ram_addr_t addr);
>>  void qemu_ram_free(ram_addr_t addr);
>> --
>> 2.1.4
>>
>>
>
>
>
> --
> Marc-André Lureau

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation
  2015-12-04 14:55   ` Tetsuya Mukawa
@ 2015-12-07 11:31     ` Marc-André Lureau
  2015-12-07 13:04       ` Tetsuya Mukawa
  2016-01-11 19:20       ` Markus Armbruster
  0 siblings, 2 replies; 8+ messages in thread
From: Marc-André Lureau @ 2015-12-07 11:31 UTC (permalink / raw)
  To: Tetsuya Mukawa, Michael S. Tsirkin; +Cc: QEMU

Hi

On Fri, Dec 4, 2015 at 3:55 PM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>> What's the use case or test case?
>
> One of example is userspace device driver like DPDK PMD.
> Actually, I've found this fd related behavior using DPDK virtio-net PMD.
> Could you please check below to know my use case more?
> http://thread.gmane.org/gmane.comp.networking.dpdk.devel/28467/focus=28493

Thanks. Why not use memory-backend-file with share=on ? I think I
understand you want to use the same BAR address as the host shared
memory location to avoid extra offset computation. I don't know about
the limitations here. Is this extra offset really worth saving?
Finally, I wonder what qemu is really doing in the end ;)

Michael, could you comment about this vhost-user use case? (see above
linked thread)


-- 
Marc-André Lureau

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation
  2015-12-07 11:31     ` Marc-André Lureau
@ 2015-12-07 13:04       ` Tetsuya Mukawa
  2016-01-11 19:20       ` Markus Armbruster
  1 sibling, 0 replies; 8+ messages in thread
From: Tetsuya Mukawa @ 2015-12-07 13:04 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: QEMU, Michael S. Tsirkin

2015-12-07 20:31 GMT+09:00 Marc-André Lureau <marcandre.lureau@gmail.com>:
> Hi
>
> On Fri, Dec 4, 2015 at 3:55 PM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>>> What's the use case or test case?
>>
>> One of example is userspace device driver like DPDK PMD.
>> Actually, I've found this fd related behavior using DPDK virtio-net PMD.
>> Could you please check below to know my use case more?
>> http://thread.gmane.org/gmane.comp.networking.dpdk.devel/28467/focus=28493
>
> Thanks. Why not use memory-backend-file with share=on ?

Thanks for commenting.
I guess you suggest me to use memory-backend file as guest main memory.
Is this correct?
If so, it might not work because first 1MB of QEMU main memory is
reserved by others like BIOS.
To work it with DPDK process, I may need to to fix DPDK memory
management not to use first 1MB.

> I think I understand you want to use the same BAR address as the host shared
> memory location to avoid extra offset computation. I don't know about
> the limitations here. Is this extra offset really worth saving?

Yes, I don't need to change DPDK virtio-net PMD a lot, because a
physical memory region that virtio-net PMD on host uses can be valid
and has same physical memory address in QEMU guest.
This is the trick I can use almost same virtio-net driver on guest and host.

Tetsuya,

> Finally, I wonder what qemu is really doing in the end ;)
>
> Michael, could you comment about this vhost-user use case? (see above
> linked thread)
>
>
> --
> Marc-André Lureau

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2] ivshmem: Store file descriptor for vhost-user negotiation
  2015-12-04  3:52 [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation Tetsuya Mukawa
  2015-12-04 13:20 ` Marc-André Lureau
@ 2015-12-21  3:47 ` Tetsuya Mukawa
  1 sibling, 0 replies; 8+ messages in thread
From: Tetsuya Mukawa @ 2015-12-21  3:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Tetsuya Mukawa, marcandre.lureau, mst

If virtio-net driver allocates memory in ivshmem shared memory,
vhost-net will work correctly, but vhost-user will not work because
a fd of shared memory will not be sent to vhost-user backend.
This patch fixes ivshmem to store file descriptor of shared memory.
It will be used when vhost-user negotiates vhost-user backend.

v2:
* Fixed typo.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 exec.c                  | 10 ++++++++++
 hw/misc/ivshmem.c       |  9 +++++++--
 include/exec/ram_addr.h |  1 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/exec.c b/exec.c
index 8718a75..7f0ce42 100644
--- a/exec.c
+++ b/exec.c
@@ -1757,6 +1757,16 @@ int qemu_get_ram_fd(ram_addr_t addr)
     return fd;
 }
 
+void qemu_set_ram_fd(ram_addr_t addr, int fd)
+{
+    RAMBlock *block;
+
+    rcu_read_lock();
+    block = qemu_get_ram_block(addr);
+    block->fd = fd;
+    rcu_read_unlock();
+}
+
 void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
 {
     RAMBlock *block;
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index f73f0c2..df585de 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -29,6 +29,7 @@
 #include "sysemu/char.h"
 #include "sysemu/hostmem.h"
 #include "qapi/visitor.h"
+#include "exec/ram_addr.h"
 
 #include "hw/misc/ivshmem.h"
 
@@ -422,6 +423,7 @@ static int create_shared_memory_BAR(IVShmemState *s, int fd, uint8_t attr,
 
     memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2",
                                s->ivshmem_size, ptr);
+    qemu_set_ram_fd(s->ivshmem.ram_addr, fd);
     vmstate_register_ram(&s->ivshmem, DEVICE(s));
     memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
 
@@ -682,6 +684,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
         }
         memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s),
                                    "ivshmem.bar2", s->ivshmem_size, map_ptr);
+        qemu_set_ram_fd(s->ivshmem.ram_addr, incoming_fd);
         vmstate_register_ram(&s->ivshmem, DEVICE(s));
 
         IVSHMEM_DPRINTF("guest h/w addr = %p, size = %" PRIu64 "\n",
@@ -689,7 +692,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
 
         memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
 
-        close(incoming_fd);
         return;
     }
 
@@ -991,7 +993,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
         }
 
         create_shared_memory_BAR(s, fd, attr, errp);
-        close(fd);
     }
 }
 
@@ -1010,11 +1011,15 @@ static void pci_ivshmem_exit(PCIDevice *dev)
     if (memory_region_is_mapped(&s->ivshmem)) {
         if (!s->hostmem) {
             void *addr = memory_region_get_ram_ptr(&s->ivshmem);
+            int fd;
 
             if (munmap(addr, s->ivshmem_size) == -1) {
                 error_report("Failed to munmap shared memory %s",
                              strerror(errno));
             }
+
+            if ((fd = qemu_get_ram_fd(s->ivshmem.ram_addr)) != -1)
+                close(fd);
         }
 
         vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index ba4c04d..ef1489d 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -72,6 +72,7 @@ ram_addr_t qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
                                                      void *host),
                                      MemoryRegion *mr, Error **errp);
 int qemu_get_ram_fd(ram_addr_t addr);
+void qemu_set_ram_fd(ram_addr_t addr, int fd);
 void *qemu_get_ram_block_host_ptr(ram_addr_t addr);
 void qemu_ram_free(ram_addr_t addr);
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation
  2015-12-07 11:31     ` Marc-André Lureau
  2015-12-07 13:04       ` Tetsuya Mukawa
@ 2016-01-11 19:20       ` Markus Armbruster
  2016-01-12  4:26         ` Tetsuya Mukawa
  1 sibling, 1 reply; 8+ messages in thread
From: Markus Armbruster @ 2016-01-11 19:20 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: Tetsuya Mukawa, QEMU, Michael S. Tsirkin

Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> Hi
>
> On Fri, Dec 4, 2015 at 3:55 PM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>>> What's the use case or test case?
>>
>> One of example is userspace device driver like DPDK PMD.
>> Actually, I've found this fd related behavior using DPDK virtio-net PMD.
>> Could you please check below to know my use case more?
>> http://thread.gmane.org/gmane.comp.networking.dpdk.devel/28467/focus=28493
>
> Thanks. Why not use memory-backend-file with share=on ? I think I
> understand you want to use the same BAR address as the host shared
> memory location to avoid extra offset computation. I don't know about
> the limitations here. Is this extra offset really worth saving?
> Finally, I wonder what qemu is really doing in the end ;)

Tetsuya, I still don't understand what you're trying to accomplish.

I concur with Marc-André that -object memory-backend-FOO is how we
allocate a memory object for something else to use.

> Michael, could you comment about this vhost-user use case? (see above
> linked thread)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation
  2016-01-11 19:20       ` Markus Armbruster
@ 2016-01-12  4:26         ` Tetsuya Mukawa
  0 siblings, 0 replies; 8+ messages in thread
From: Tetsuya Mukawa @ 2016-01-12  4:26 UTC (permalink / raw)
  To: Markus Armbruster, Marc-André Lureau; +Cc: QEMU, Michael S. Tsirkin

On 2016/01/12 4:20, Markus Armbruster wrote:
> Marc-André Lureau <marcandre.lureau@gmail.com> writes:
>
>> Hi
>>
>> On Fri, Dec 4, 2015 at 3:55 PM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>>>> What's the use case or test case?
>>> One of example is userspace device driver like DPDK PMD.
>>> Actually, I've found this fd related behavior using DPDK virtio-net PMD.
>>> Could you please check below to know my use case more?
>>> http://thread.gmane.org/gmane.comp.networking.dpdk.devel/28467/focus=28493
>> Thanks. Why not use memory-backend-file with share=on ? I think I
>> understand you want to use the same BAR address as the host shared
>> memory location to avoid extra offset computation. I don't know about
>> the limitations here. Is this extra offset really worth saving?
>> Finally, I wonder what qemu is really doing in the end ;)
> Tetsuya, I still don't understand what you're trying to accomplish.

Hi Markus,

Please let me describe it more.

We have below test program for vhost-user.
 - ./tests/vhost-user-test.c

This program doesn't share memory between test process and QEMU process.
So all memory accesses are sent as qtest command.
If both process has a shared memory that can be accessed using same
address by both processes, we can reduce above memory accessing overhead.
This is what I want to do.

So far, when vhost-user is used, the memory will not be shared because
fd isn't kept.
This is what I want to fix.

> I concur with Marc-André that -object memory-backend-FOO is how we
> allocate a memory object for something else to use.

I am not so familiar with QEMU memory architecture. So please let me
make sure.
Does vhost-user only works with memory backend objects?

If it's correct, in my case, I want to use an unix domain socket to
transfer fd of the shared memory.
To do that, do you suggest me to add 'chardev' parameter to
./backend/hostmem-file.c?

Tetsuya

>
>> Michael, could you comment about this vhost-user use case? (see above
>> linked thread)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-01-12  4:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04  3:52 [Qemu-devel] [PATCH] ivshmem: Store file descriptor for vhost-user negotiation Tetsuya Mukawa
2015-12-04 13:20 ` Marc-André Lureau
2015-12-04 14:55   ` Tetsuya Mukawa
2015-12-07 11:31     ` Marc-André Lureau
2015-12-07 13:04       ` Tetsuya Mukawa
2016-01-11 19:20       ` Markus Armbruster
2016-01-12  4:26         ` Tetsuya Mukawa
2015-12-21  3:47 ` [Qemu-devel] [PATCH v2] " Tetsuya Mukawa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).