vhost-user: modify SET_LOG_BASE to pass mmap size and offset
PATCH 1/1 vhost-user: modify SET_LOG_BASE to pass mmap size and offset
Unlike the kernel, vhost-user application accesses log table by mmaping it to its user space. This change adds two new fields to VhostUserMsg payload: mmap_size, and mmap_offset and make QEMU to pass the to vhost-user application in VHOST_USER_SET_LOG_BASE request.
--- hw/virtio/vhost-user.c | 11 +++++++++-- tests/vhost-user-test.c | 8 ++++++++ docs/specs/vhost-user.txt | 8 +++++++- 3 files changed, 24 insertions(+), 3 deletions(-)
hw/virtio/vhost-user.c +9 -2
@@ -75,6 +75,11 @@ typedef struct VhostUserMemory {VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS ]; } VhostUserMemory; +typedef struct VhostUserLog { +uint64_t mmap_size; +uint64_t mmap_offset; +}VhostUserLog ; + typedef struct VhostUserMsg { VhostUserRequest request;
@@ -89,6 +94,7 @@ typedef struct VhostUserMsg {struct vhost_vring_state state;struct vhost_vring_addr addr;VhostUserMemory memory; +VhostUserLog log; } payload; }QEMU_PACKED VhostUserMsg;
@@ -200,8 +206,9 @@ static int vhost_user_set_log_base(struct vhost_dev *dev, uint64_t base,VhostUserMsg msg = { .request =VHOST_USER_SET_LOG_BASE , .flags =VHOST_USER_VERSION , - .payload.u64 = base, - .size =sizeof (msg.payload.u64), + .payload.log.mmap_size = log->size, + .payload.log.mmap_offset =0 , + .size =sizeof (msg.payload.log), };if (shmfd && log->fd !=-1 ) {
tests/vhost-user-test.c +8 -0
@@ -86,6 +86,11 @@ typedef struct VhostUserMemory {VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS ]; } VhostUserMemory; +typedef struct VhostUserLog { +uint64_t mmap_size; +uint64_t mmap_offset; +}VhostUserLog ; + typedef struct VhostUserMsg { VhostUserRequest request;
@@ -94,10 +99,13 @@ typedef struct VhostUserMsg {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;
docs/specs/vhost-user.txt +7 -1
@@ -98,6 +98,7 @@ typedef struct VhostUserMsg { struct vhost_vring_state state; struct vhost_vring_addr addr; VhostUserMemory memory; + VhostUserLog log; }; } QEMU_PACKED VhostUserMsg;
@@ -282,7 +283,12 @@ Message types Master payload: u64 Slave payload: N/A - Sets the logging base address. + Sets logging shared memory space. + When slave has VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol + feature, the log memory fd is provided in the ancillary data of + VHOST_USER_SET_LOG_BASE message, the size and offset of shared + memory area provided in the message. + * VHOST_USER_SET_LOG_FD
Signature · 1 line
--Victor
Hi
----- Original Message -----
Quoted 7 lines
Unlike the kernel, vhost-user application accesses log table by mmaping it to its user space. This change adds two new fields to VhostUserMsg payload:
mmap_size, andmmap_offsetand make QEMU to pass the to vhost-user application inVHOST_USER_SET_LOG_BASErequest.Signed-off-by Victor Kaplansky <[email protected]>
What's the motivation for doing this? The offset is always 0, and the size must at least match the size of VM memory.
Quoted 103 lines
--- hw/virtio/vhost-user.c | 11 +++++++++-- tests/vhost-user-test.c | 8 ++++++++ docs/specs/vhost-user.txt | 8 +++++++- 3 files changed, 24 insertions(+), 3 deletions(-)hw/virtio/vhost-user.c +9
-2@@ -75,6 +75,11 @@ typedef struct VhostUserMemory {VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS ]; } VhostUserMemory; +typedef struct VhostUserLog { +uint64_t mmap_size; +uint64_t mmap_offset; +}VhostUserLog ; + typedef struct VhostUserMsg { VhostUserRequest request;@@ -89,6 +94,7 @@ typedef struct VhostUserMsg {struct vhost_vring_state state;struct vhost_vring_addr addr;VhostUserMemory memory; +VhostUserLog log; } payload; }QEMU_PACKED VhostUserMsg;@@ -200,8 +206,9 @@ static int vhost_user_set_log_base(struct vhost_dev *dev,uint64_t base, VhostUserMsg msg = { .request =VHOST_USER_SET_LOG_BASE , .flags =VHOST_USER_VERSION , - .payload.u64 = base, - .size =sizeof (msg.payload.u64), + .payload.log.mmap_size = log->size, + .payload.log.mmap_offset =0 , + .size =sizeof (msg.payload.log), };if (shmfd && log->fd != -1) {tests/vhost-user-test.c +8
-0@@ -86,6 +86,11 @@ typedef struct VhostUserMemory {VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS ]; } VhostUserMemory; +typedef struct VhostUserLog { +uint64_t mmap_size; +uint64_t mmap_offset; +}VhostUserLog ; + typedef struct VhostUserMsg { VhostUserRequest request;@@ -94,10 +99,13 @@ typedef struct VhostUserMsg {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;docs/specs/vhost-user.txt +7
-3@@ -98,6 +98,7 @@ typedef struct VhostUserMsg { struct vhost_vring_state state; struct vhost_vring_addr addr; VhostUserMemory memory; + VhostUserLog log; }; } QEMU_PACKED VhostUserMsg;@@ -282,7 +283,12 @@ Message types Master payload: u64 Slave payload: N/A - Sets the logging base address. + Sets logging shared memory space. + When slave has VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol + feature, the log memory fd is provided in the ancillary data of + VHOST_USER_SET_LOG_BASE message, the size and offset of shared + memory area provided in the message. + * VHOST_USER_SET_LOG_FD -- --Victor
Quoted 9 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 6 lines
Unlike the kernel, vhost-user application accesses log table by mmaping it to its user space. This change adds two new fields to VhostUserMsg payload:
mmap_size, andmmap_offsetand make QEMU to pass the to vhost-user application inVHOST_USER_SET_LOG_BASErequest.
Quoted 3 lines
Quoted 1 line
Signed-off-by Victor Kaplansky <[email protected]>What's the motivation for doing this? The offset is always 0, and the size must at least match the size of VM memory.
Remote doesn't know the size though, and offset is only there in the current implementation.
Quoted 103 lines
Quoted 103 lines
--- hw/virtio/vhost-user.c | 11 +++++++++-- tests/vhost-user-test.c | 8 ++++++++ docs/specs/vhost-user.txt | 8 +++++++- 3 files changed, 24 insertions(+), 3 deletions(-)hw/virtio/vhost-user.c +9
-2@@ -75,6 +75,11 @@ typedef struct VhostUserMemory {VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS ]; } VhostUserMemory; +typedef struct VhostUserLog { +uint64_t mmap_size; +uint64_t mmap_offset; +}VhostUserLog ; + typedef struct VhostUserMsg { VhostUserRequest request;@@ -89,6 +94,7 @@ typedef struct VhostUserMsg {struct vhost_vring_state state;struct vhost_vring_addr addr;VhostUserMemory memory; +VhostUserLog log; } payload; }QEMU_PACKED VhostUserMsg;@@ -200,8 +206,9 @@ static int vhost_user_set_log_base(struct vhost_dev *dev,uint64_t base, VhostUserMsg msg = { .request =VHOST_USER_SET_LOG_BASE , .flags =VHOST_USER_VERSION , - .payload.u64 = base, - .size =sizeof (msg.payload.u64), + .payload.log.mmap_size = log->size, + .payload.log.mmap_offset =0 , + .size =sizeof (msg.payload.log), };if (shmfd && log->fd != -1) {tests/vhost-user-test.c +8
-0@@ -86,6 +86,11 @@ typedef struct VhostUserMemory {VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS ]; } VhostUserMemory; +typedef struct VhostUserLog { +uint64_t mmap_size; +uint64_t mmap_offset; +}VhostUserLog ; + typedef struct VhostUserMsg { VhostUserRequest request;@@ -94,10 +99,13 @@ typedef struct VhostUserMsg {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;docs/specs/vhost-user.txt +7
-3@@ -98,6 +98,7 @@ typedef struct VhostUserMsg { struct vhost_vring_state state; struct vhost_vring_addr addr; VhostUserMemory memory; + VhostUserLog log; }; } QEMU_PACKED VhostUserMsg;@@ -282,7 +283,12 @@ Message types Master payload: u64 Slave payload: N/A - Sets the logging base address. + Sets logging shared memory space. + When slave has VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol + feature, the log memory fd is provided in the ancillary data of + VHOST_USER_SET_LOG_BASE message, the size and offset of shared + memory area provided in the message. + * VHOST_USER_SET_LOG_FD -- --Victor
Hi
Quoted 2 lines · Michael S. Tsirkin
Remote doesn't know the size though, and offset is only there in the current implementation.
It can compute the size based on the mem tables. But it could be more future-proof to add these informations.
Signature · 1 line
Marc-André Lureau
Quoted 8 lines · Marc-André Lureau
Hi
Quoted 2 lines · Michael S. Tsirkin
Remote doesn't know the size though, and offset is only there in the current implementation.
It can compute the size based on the mem tables. But it could be more future-proof to add these informations.
Right. Doing it now means we won't need a separate feature flag for it.
Quoted 2 lines
Signature · 1 line
Marc-André Lureau
Hi
docs/specs/vhost-user.txt Message types · line 290
Quoted 7 lines · Victor Kaplansky
docs/specs/vhost-user.txt +5
-1- Sets the logging base address. + Sets logging shared memory space. + When slave has VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol + feature, the log memory fd is provided in the ancillary data of + VHOST_USER_SET_LOG_BASE message, the size and offset of shared + memory area provided in the message.
I think this extra payload needs a better description, in payload description above. Something like
* A pair of 64-bit integers
-------------
| u64 | u64 |
-------------
u64: a 64-bit unsigned integer
"the size and offset of shared memory area provided in the message as a pair of 64-bit integers."
Signature · 1 line
Marc-André Lureau
Quoted 19 lines · Marc-André Lureau
Hi
docs/specs/vhost-user.txt Message types · line 290
Quoted 7 lines · Victor Kaplansky
docs/specs/vhost-user.txt +5
-1- Sets the logging base address. + Sets logging shared memory space. + When slave has VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol + feature, the log memory fd is provided in the ancillary data of + VHOST_USER_SET_LOG_BASE message, the size and offset of shared + memory area provided in the message.I think this extra payload needs a better description, in payload description above. Something like
* A pair of 64-bit integers
-------------
| u64 | u64 |
-------------
Quoted 4 lines
u64: a 64-bit unsigned integer
"the size and offset of shared memory area provided in the message as a pair of 64-bit integers."
Sounds good. I've queued this one up, pls tweak docs with patches on top.
Quoted 2 lines
Signature · 1 line
Marc-André Lureau