vhost-user: support SET_MEM_TABLE waite the result of mmap
PATCH 1/2 vhost-user: support SET_MEM_TABLE waite the result of mmap
From: Linhaifeng <[email protected]>
Slave should reply to master and set u64 to 0 if
mmap all regions success otherwise set u64 to 1.
--- docs/specs/vhost-user.txt | 1 + 1 file changed, 1 insertion(+)
docs/specs/vhost-user.txt +1 -0
@@ -171,6 +171,7 @@ Message types Id: 5 Equivalent ioctl: VHOST_SET_MEM_TABLE Master payload: memory regions description + Slave payload: u64 (0:success >0:failed) Sets the memory map regions on the slave so it can translate the vring addresses. In the ancillary data there is an array of file descriptors
Signature · 1 line
1.7.12.4
PATCH 2/2 vhost-user: add reply for set_mem_table
From: Linhaifeng <[email protected]>
If u64 is not 0 we should return -1 to tell qemu not going on.
Remove some unnecessary '\n' in error_report.
--- hw/virtio/vhost-user.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
hw/virtio/vhost-user.c +22 -11
@@ -128,7 +128,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) r =qemu_chr_fe_read_all (chr, p, size);if (r != size) { -error_report ("Failed to read msg header. Read %d instead of %d.\n" , r, +error_report ("Failed to read msg header. Read %d instead of %d." , r, size); goto fail; }
@@ -136,7 +136,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)/* validate received flags */ if (msg->flags != (VHOST_USER_REPLY_MASK |VHOST_USER_VERSION )) {error_report ("Failed to read msg header." -" Flags 0x%x instead of 0x%x.\n" , msg->flags, +" Flags 0x%x instead of 0x%x." , msg->flags,VHOST_USER_REPLY_MASK |VHOST_USER_VERSION ); goto fail; }
@@ -144,7 +144,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)/* validate message size is sane */ if (msg->size >VHOST_USER_PAYLOAD_SIZE ) {error_report ("Failed to read msg header." -" Size %d exceeds the maximum %zu.\n" , msg->size, +" Size %d exceeds the maximum %zu." , msg->size,VHOST_USER_PAYLOAD_SIZE ); goto fail; }
@@ -155,7 +155,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) r =qemu_chr_fe_read_all (chr, p, size);if (r != size) {error_report ("Failed to read msg payload." -" Read %d instead of %d.\n" , r, msg->size); +" Read %d instead of %d." , r, msg->size); goto fail; } }
@@ -236,14 +236,14 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,if (!fd_num) {error_report ("Failed initializing vhost-user memory map\n" -"consider using -object memory-backend-file share=on\n" ); +"consider using -object memory-backend-file share=on" );return -1 ; } msg.size =sizeof (m.memory.nregions); msg.size +=sizeof (m.memory.padding); msg.size += fd_num *sizeof (VhostUserMemoryRegion); - + need_reply =1 ;break ;case VHOST_SET_LOG_FD :
@@ -280,7 +280,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request, }break ;default : -error_report ("vhost-user trying to send unhandled ioctl\n" ); +error_report ("vhost-user trying to send unhandled ioctl" );return -1 ;break ; }
@@ -296,27 +296,38 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,if (msg_request != msg.request) {error_report ("Received unexpected msg type." -" Expected %d received %d\n" , msg_request, msg.request); +" Expected %d received %d" , msg_request, msg.request);return -1 ; }switch (msg_request) {case VHOST_USER_GET_FEATURES :if (msg.size !=sizeof (m.u64)) { -error_report ("Received bad msg size.\n" ); +error_report ("Received bad msg size." );return -1 ; } *((__u64 *) arg) = msg.u64;break ;case VHOST_USER_GET_VRING_BASE :if (msg.size !=sizeof (m.state)) { -error_report ("Received bad msg size.\n" ); +error_report ("Received bad msg size." );return -1 ; }memcpy (arg, &msg.state,sizeof (struct vhost_vring_state ));break ; +case VHOST_SET_MEM_TABLE : +if (msg.size !=sizeof (m.u64)) { +error_report ("Received bad msg size." ); +return -1 ; + }else { +if (m.u64) { +error_report ("Failed to set memory table." ); +return -1 ; + } + } +break ;default : -error_report ("Received unexpected msg type.\n" ); +error_report ("Received unexpected msg type." );return -1 ;break ; }
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH v1 2/2] vhost-user: add reply for set_mem_table
Quoted 5 lines · linhaifeng
From: Linhaifeng <[email protected]>
If u64 is not 0 we should return -1 to tell qemu not going on.
Remove some unnecessary '\n' in
error_report.
Hi, haifeng:
You'd better split a single patch to do this work,
and using '--cover' argument for patch series when git format-patch . :)
Regards,
-Gonglei
Quoted 5 lines
Signed-off-by Linhaifeng <[email protected]>--- hw/virtio/vhost-user.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
Re: [Qemu-devel] [PATCH v1 2/2] vhost-user: add reply for set_mem_table
Quoted 11 lines · Gonglei
Quoted 5 lines · linhaifeng
From: Linhaifeng <[email protected]>
If u64 is not 0 we should return -1 to tell qemu not going on.
Remove some unnecessary '\n' in
error_report.Hi, haifeng:
You'd better split a single patch to do this work,
and using '--cover' argument for patch series when git format-patch . :)
good idea!
Quoted 12 lines
Regards,
-GongleiQuoted 5 lines
Signed-off-by Linhaifeng <[email protected]>--- hw/virtio/vhost-user.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-).
Signature · 2 lines
Regards, Haifeng
Quoted 6 lines · linhaifeng
From: Linhaifeng <[email protected]>
Slave should reply to master and set u64 to 0 if
mmap all regions success otherwise set u64 to 1.Signed-off-by Linhaifeng <[email protected]>
How does this work with existig slaves though?
Quoted 19 lines
--- docs/specs/vhost-user.txt | 1 + 1 file changed, 1 insertion(+)docs/specs/vhost-user.txt +1
-0@@ -171,6 +171,7 @@ Message types Id: 5 Equivalent ioctl: VHOST_SET_MEM_TABLE Master payload: memory regions description + Slave payload: u64 (0:success >0:failed) Sets the memory map regions on the slave so it can translate the vring addresses. In the ancillary data there is an array of file descriptorsSignature · 1 line
1.7.12.4
Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · linhaifeng
From: Linhaifeng <[email protected]>
Slave should reply to master and set u64 to 0 if
mmap all regions success otherwise set u64 to 1.Signed-off-by Linhaifeng <[email protected]>How does this work with existig slaves though?
Slaves should work like this:
int set_mem_table(...)
{
....
for (idx = 0, i = 0; idx < memory.nregions; idx++) {
....
mem = mmap(..);
if (MAP_FAILED == mem) {
msg->msg.u64 = 1;
msg->msg.size = MEMB_SIZE(VhostUserMsg, u64);
return 1;
}
}
....
msg->msg.u64 = 0;
msg->msg.size = MEMB_SIZE(VhostUserMsg, u64);
return 1;
}If slaves not reply QEMU will always wait.
Quoted 21 lines
Quoted 19 lines
--- docs/specs/vhost-user.txt | 1 + 1 file changed, 1 insertion(+)docs/specs/vhost-user.txt +1
-0@@ -171,6 +171,7 @@ Message types Id: 5 Equivalent ioctl: VHOST_SET_MEM_TABLE Master payload: memory regions description + Slave payload: u64 (0:success >0:failed) Sets the memory map regions on the slave so it can translate the vring addresses. In the ancillary data there is an array of file descriptorsSignature · 1 line
1.7.12.4
Signature · 2 lines
Regards, Haifeng
Quoted 36 lines · Linhaifeng
Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · linhaifeng
From: Linhaifeng <[email protected]>
Slave should reply to master and set u64 to 0 if
mmap all regions success otherwise set u64 to 1.Signed-off-by Linhaifeng <[email protected]>How does this work with existig slaves though?
Slaves should work like this:
int
set_mem_table(...){ .... for (idx = 0, i = 0; idx < memory.nregions; idx++) { .... mem = mmap(..); if (MAP_FAILED == mem) { msg->msg.u64 = 1; msg->msg.size = MEMB_SIZE(VhostUserMsg, u64); return 1; } } .... msg->msg.u64 = 0; msg->msg.size = MEMB_SIZE(VhostUserMsg, u64); return 1; }
Quoted 1 line
If slaves not reply QEMU will always wait.
Are you sure existing slaves reply?
Quoted 25 lines
Quoted 21 lines
Quoted 19 lines
--- docs/specs/vhost-user.txt | 1 + 1 file changed, 1 insertion(+)docs/specs/vhost-user.txt +1
-0@@ -171,6 +171,7 @@ Message types Id: 5 Equivalent ioctl: VHOST_SET_MEM_TABLE Master payload: memory regions description + Slave payload: u64 (0:success >0:failed) Sets the memory map regions on the slave so it can translate the vring addresses. In the ancillary data there is an array of file descriptorsSignature · 1 line
1.7.12.4Signature · 2 lines
Regards, Haifeng
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Linhaifeng
Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · linhaifeng
From: Linhaifeng <[email protected]>
Slave should reply to master and set u64 to 0 if
mmap all regions success otherwise set u64 to 1.Signed-off-by Linhaifeng <[email protected]>How does this work with existig slaves though?
Slaves should work like this:
int
set_mem_table(...){ .... for (idx = 0, i = 0; idx < memory.nregions; idx++) { .... mem = mmap(..); if (MAP_FAILED == mem) { msg->msg.u64 = 1; msg->msg.size = MEMB_SIZE(VhostUserMsg, u64); return 1; } } ....
Quoted 8 lines
Quoted 6 lines
msg->msg.u64 = 0; msg->msg.size = MEMB_SIZE(VhostUserMsg, u64); return 1; }If slaves not reply QEMU will always wait.
Are you sure existing slaves reply?
No.May be the existing slaves need add reply in their codes.
Quoted 29 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
--- docs/specs/vhost-user.txt | 1 + 1 file changed, 1 insertion(+)docs/specs/vhost-user.txt +1
-0@@ -171,6 +171,7 @@ Message types Id: 5 Equivalent ioctl: VHOST_SET_MEM_TABLE Master payload: memory regions description + Slave payload: u64 (0:success >0:failed)Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
docs/specs/vhost-user.txt +0
-0Sets the memory map regions on the slave so it can translate the vring addresses. In the ancillary data there is an array of file descriptorsSignature · 1 line
1.7.12.4Signature · 2 lines
Regards, Haifeng.
Signature · 2 lines
Regards, Haifeng
Quoted 40 lines · Linhaifeng
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Linhaifeng
Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · linhaifeng
From: Linhaifeng <[email protected]>
Slave should reply to master and set u64 to 0 if
mmap all regions success otherwise set u64 to 1.Signed-off-by Linhaifeng <[email protected]>How does this work with existig slaves though?
Slaves should work like this:
int
set_mem_table(...){ .... for (idx = 0, i = 0; idx < memory.nregions; idx++) { .... mem = mmap(..); if (MAP_FAILED == mem) { msg->msg.u64 = 1; msg->msg.size = MEMB_SIZE(VhostUserMsg, u64); return 1; } } .... msg->msg.u64 = 0; msg->msg.size = MEMB_SIZE(VhostUserMsg, u64); return 1; }
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
If slaves not reply QEMU will always wait.
Are you sure existing slaves reply?
No.May be the existing slaves need add reply in their codes.
So that's not good. We need a way to negotiate the capability, we can't just deadlock with legacy slaves.
Quoted 33 lines
Quoted 29 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
--- docs/specs/vhost-user.txt | 1 + 1 file changed, 1 insertion(+)docs/specs/vhost-user.txt +1
-0@@ -171,6 +171,7 @@ Message types Id: 5 Equivalent ioctl: VHOST_SET_MEM_TABLE Master payload: memory regions description + Slave payload: u64 (0:success >0:failed)Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
docs/specs/vhost-user.txt +0
-0Sets the memory map regions on the slave so it can translate the vring addresses. In the ancillary data there is an array of file descriptorsSignature · 1 line
1.7.12.4Signature · 2 lines
Regards, Haifeng.
Signature · 2 lines
Regards, Haifeng
Quoted 2 lines · Michael S. Tsirkin
So that's not good. We need a way to negotiate the capability, we can't just deadlock with legacy slaves.
Should we wait many seconds if slave not reply we just return error?
Signature · 2 lines
Regards, Haifeng
Quoted 7 lines · Linhaifeng
Quoted 2 lines · Michael S. Tsirkin
So that's not good. We need a way to negotiate the capability, we can't just deadlock with legacy slaves.
Should we wait many seconds if slave not reply we just return error?
I would prefer something more robust.
Isn't there a version field we can use?
Quoted 3 lines
Signature · 2 lines
Regards, Haifeng
Quoted 2 lines · Michael S. Tsirkin
So that's not good. We need a way to negotiate the capability, we can't just deadlock with legacy slaves.
Or add a new message to query slaves' version if slaves not reply we don't wait otherwise if the version as same as QEMU we wait the reply.
Mostly the same as iotcl may be all messages need reply.
Signature · 2 lines
Regards, Haifeng
Quoted 7 lines
Quoted 3 lines
No.May be the existing slaves need add reply in their codes.
So that's not good. We need a way to negotiate the capability, we can't just deadlock with legacy slaves.
Hi,Michael
Do you have any suggestions?