Extend vhost to support VFIO based accelerator
cover Extend vhost to support VFIO based accelerator
This patch set introduces the VFIO based accelerator support for vhost. This is a new vhost user protocol feature to better support the vDPA device at the vhost user backend. It allows interrupts/notifications being delivered between the driver in guest and the device in host directly.
Dependencies:
1. This patch set depends on the below patch set for QEMU:
http://lists.nongnu.org/archive/html/qemu-devel/2018-01/msg06028.html
Some of the enum definitions in this patch set have been updated for the latest QEMU. A new patch set for QEMU will be sent out later.
2. This patch set depends on Zhihong's "selective datapath" patch set:
http://dpdk.org/ml/archives/dev/2018-March/091858.html
This patch set is generated on the latest master branch of dpdk-next-virtio with Zhihong's patches applied.
Best regards,
Tiwei Bie
Tiwei Bie (3):
vhost: do not generate signal when sendmsg fails
vhost: support sending fds via send_vhost_message()
vhost: support VFIO based accelerator
lib/librte_vhost/rte_vhost.h | 28 ++++++ lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/socket.c | 2 +- lib/librte_vhost/vhost_user.c | 174 ++++++++++++++++++++++++++++++++- lib/librte_vhost/vhost_user.h | 9 ++ 5 files changed, 209 insertions(+), 5 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/3 vhost: do not generate signal when sendmsg fails
--- lib/librte_vhost/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_vhost/socket.c +1 -1
@@ -181,7 +181,7 @@ send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) }do { - ret =sendmsg (sockfd, &msgh,0 ); + ret =sendmsg (sockfd, &msgh,MSG_NOSIGNAL ); }while (ret <0 && errno ==EINTR );if (ret <0 ) {
Signature · 1 line
2.11.0
Re: [PATCH 1/3] vhost: do not generate signal when sendmsg fails
Hi Tiwei,
Quoted 1 line · Tiwei Bie
Signed-off-by Tiwei Bie <[email protected]>
Could you please elaborate a bit more why this is needed? Is it fixing a real issue or just an improvement?
Thanks!
Maxime
Quoted 18 lines
--- lib/librte_vhost/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_vhost/socket.c +1
-1@@ -181,7 +181,7 @@ send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) }do { - ret =sendmsg (sockfd, &msgh,0 ); + ret =sendmsg (sockfd, &msgh,MSG_NOSIGNAL ); }while (ret <0 && errno ==EINTR );if (ret <0 ) {
Re: [PATCH 1/3] vhost: do not generate signal when sendmsg fails
Quoted 7 lines · Maxime Coquelin
Hi Tiwei,
Quoted 1 line · Tiwei Bie
Signed-off-by Tiwei Bie <[email protected]>Could you please elaborate a bit more why this is needed? Is it fixing a real issue or just an improvement?
My bad, I really should write a more useful commit log..
I saw your comments on this mail:
http://dpdk.org/ml/archives/dev/2018-March/094201.html
Thank you so much! :-)
It's fixing an issue I met when adding the vDPA support. SIGPIPE would be generated when sending messages via a closed slave fd, and it will terminate the process by default. But as a library, we shouldn't crash the process in this case, instead we just need to return with an error. I didn't meet this issue without my vDPA related changes, so I didn't put a fixline on it. That is to say, I'm treating it as an improvement.
Below is the commit log for your reference:
------ START HERE ------
vhost: do not generate signal when sendmsg fails
More precisely, do not generate a SIGPIPE signal if the peer has closed the connection. Otherwise, it will terminate the process by default. As a library, we should avoid terminating the application process when error happens and just need to return with an error.
------ END HERE ------
Thanks again! :-)
Best regards,
Tiwei Bie
Quoted 19 lines
Thanks!
MaximeQuoted 16 lines
--- lib/librte_vhost/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_vhost/socket.c +1
-1@@ -181,7 +181,7 @@ send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) }do { - ret =sendmsg (sockfd, &msgh,0 ); + ret =sendmsg (sockfd, &msgh,MSG_NOSIGNAL ); }while (ret <0 && errno ==EINTR );if (ret <0 ) {
Re: [PATCH 1/3] vhost: do not generate signal when sendmsg fails
Quoted 17 lines · Tiwei Bie
Quoted 7 lines · Maxime Coquelin
Hi Tiwei,
Quoted 1 line · Tiwei Bie
Signed-off-by Tiwei Bie <[email protected]>Could you please elaborate a bit more why this is needed? Is it fixing a real issue or just an improvement?
My bad, I really should write a more useful commit log..
I saw your comments on this mail:
http://dpdk.org/ml/archives/dev/2018-March/094201.html
Thank you so much! :-)
Quoted 8 lines
It's fixing an issue I met when adding the vDPA support. SIGPIPE would be generated when sending messages via a closed slave fd, and it will terminate the process by default. But as a library, we shouldn't crash the process in this case, instead we just need to return with an error. I didn't meet this issue without my vDPA related changes, so I didn't put a fixline on it. That is to say, I'm treating it as an improvement.
Great, thanks for the details!
I'll apply the patch with below commit message.
Maxime
Quoted 39 lines
Below is the commit log for your reference:
------ START HERE ------
vhost: do not generate signal when sendmsg fails
More precisely, do not generate a SIGPIPE signal if the peer has closed the connection. Otherwise, it will terminate the process by default. As a library, we should avoid terminating the application process when error happens and just need to return with an error.
------ END HERE ------
Thanks again! :-)
Best regards,
Tiwei BieQuoted 19 lines
Thanks!
MaximeQuoted 16 lines
--- lib/librte_vhost/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_vhost/socket.c +1
-1@@ -181,7 +181,7 @@ send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) }do { - ret =sendmsg (sockfd, &msgh,0 ); + ret =sendmsg (sockfd, &msgh,MSG_NOSIGNAL ); }while (ret <0 && errno ==EINTR );if (ret <0 ) {
Re: [PATCH 1/3] vhost: do not generate signal when sendmsg fails
Quoted 27 lines · Maxime Coquelin
Quoted 17 lines · Tiwei Bie
Quoted 7 lines · Maxime Coquelin
Hi Tiwei,
Quoted 1 line · Tiwei Bie
Signed-off-by Tiwei Bie <[email protected]>Could you please elaborate a bit more why this is needed? Is it fixing a real issue or just an improvement?
My bad, I really should write a more useful commit log..
I saw your comments on this mail:
http://dpdk.org/ml/archives/dev/2018-March/094201.html
Thank you so much! :-)
Quoted 8 lines
It's fixing an issue I met when adding the vDPA support. SIGPIPE would be generated when sending messages via a closed slave fd, and it will terminate the process by default. But as a library, we shouldn't crash the process in this case, instead we just need to return with an error. I didn't meet this issue without my vDPA related changes, so I didn't put a fixline on it. That is to say, I'm treating it as an improvement.
Quoted 2 lines
Great, thanks for the details!
I'll apply the patch with below commit message.
Thank you very much! :-)
Best regards,
Tiwei Bie
Quoted 41 lines
Maxime
Quoted 39 lines
Below is the commit log for your reference:
------ START HERE ------
vhost: do not generate signal when sendmsg fails
More precisely, do not generate a SIGPIPE signal if the peer has closed the connection. Otherwise, it will terminate the process by default. As a library, we should avoid terminating the application process when error happens and just need to return with an error.
------ END HERE ------
Thanks again! :-)
Best regards,
Tiwei BieQuoted 19 lines
Thanks!
MaximeQuoted 16 lines
--- lib/librte_vhost/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_vhost/socket.c +1
-1@@ -181,7 +181,7 @@ send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) }do { - ret =sendmsg (sockfd, &msgh,0 ); + ret =sendmsg (sockfd, &msgh,MSG_NOSIGNAL ); }while (ret <0 && errno ==EINTR );if (ret <0 ) {
Maxime Coquelin
AppliedRe: [PATCH 1/3] vhost: do not generate signal when sendmsg fails
In reply to Tiwei BieQuoted 11 lines · Tiwei Bie
Signed-off-by Tiwei Bie <[email protected]>--- lib/librte_vhost/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_vhost/socket.c +0
-0
lib/librte_vhost/socket.c send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) · line 187
Quoted 8 lines
lib/librte_vhost/socket.c +1
-1@@ -181,7 +181,7 @@ send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) }do { - ret =sendmsg (sockfd, &msgh,0 ); + ret =sendmsg (sockfd, &msgh,MSG_NOSIGNAL ); }while (ret <0 && errno ==EINTR );if (ret <0 ) {
Applied to dpdk-next-virtio/master with below commit message
------------------------------------------------------------
More precisely, do not generate a SIGPIPE signal if the peer has closed the connection. Otherwise, it will terminate the process by default. As a library, we should avoid terminating the application process when error happens and just need to return with an error.
------------------------------------------------------------
Thanks,
Maxime
PATCH 2/3 vhost: support sending fds via send_vhost_message()
In reply to Tiwei BieThis function will be used to send fds to QEMU via slave channel.
--- lib/librte_vhost/vhost_user.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/librte_vhost/vhost_user.c +4 -4
@@ -1308,13 +1308,13 @@ read_vhost_message(int sockfd, struct VhostUserMsg *msg) }static int -send_vhost_message (int sockfd,struct VhostUserMsg *msg) +send_vhost_message (int sockfd,struct VhostUserMsg *msg,int *fds,int fd_num) {if (!msg)return 0 ;return send_fd_message (sockfd, (char *)msg, -VHOST_USER_HDR_SIZE + msg->size,NULL ,0 ); +VHOST_USER_HDR_SIZE + msg->size, fds, fd_num); } static int
@@ -1328,7 +1328,7 @@ send_vhost_reply(int sockfd, struct VhostUserMsg *msg) msg->flags |=VHOST_USER_VERSION ; msg->flags |=VHOST_USER_REPLY_MASK ; -return send_vhost_message (sockfd, msg); +return send_vhost_message (sockfd, msg,NULL ,0 ); }/*
@@ -1643,7 +1643,7 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm) }, }; - ret =send_vhost_message (dev->slave_req_fd, &msg); + ret =send_vhost_message (dev->slave_req_fd, &msg,NULL ,0 );if (ret <0 ) { RTE_LOG(ERR, VHOST_CONFIG, "Failed to send IOTLB miss message (%d)\n",
Signature · 1 line
2.11.0
Re: [PATCH 2/3] vhost: support sending fds via send_vhost_message()
Quoted 3 lines · Tiwei Bie
This function will be used to send fds to QEMU via slave channel.
Signed-off-by Tiwei Bie <[email protected]>
Thanks,
Maxime
Quoted 43 lines
--- lib/librte_vhost/vhost_user.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)lib/librte_vhost/vhost_user.c +4
-4@@ -1308,13 +1308,13 @@ read_vhost_message(int sockfd, struct VhostUserMsg *msg) }static int -send_vhost_message (int sockfd,struct VhostUserMsg *msg) +send_vhost_message (int sockfd,struct VhostUserMsg *msg,int *fds,int fd_num) {if (!msg)return 0 ;return send_fd_message (sockfd, (char *)msg, -VHOST_USER_HDR_SIZE + msg->size,NULL ,0 ); +VHOST_USER_HDR_SIZE + msg->size, fds, fd_num); } static int@@ -1328,7 +1328,7 @@ send_vhost_reply(int sockfd, struct VhostUserMsg *msg) msg->flags |=VHOST_USER_VERSION ; msg->flags |=VHOST_USER_REPLY_MASK ; -return send_vhost_message (sockfd, msg); +return send_vhost_message (sockfd, msg,NULL ,0 ); }/* @@ -1643,7 +1643,7 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm) }, }; - ret =send_vhost_message (dev->slave_req_fd, &msg); + ret =send_vhost_message (dev->slave_req_fd, &msg,NULL ,0 );if (ret <0 ) { RTE_LOG(ERR, VHOST_CONFIG, "Failed to send IOTLB miss message (%d)\n",
Maxime Coquelin
AppliedRe: [PATCH 2/3] vhost: support sending fds via send_vhost_message()
In reply to Tiwei BieQuoted 6 lines · Tiwei Bie
This function will be used to send fds to QEMU via slave channel.
Signed-off-by Tiwei Bie <[email protected]>--- lib/librte_vhost/vhost_user.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Applied to dpdk-next-virtio/master, so this is one less patch to carry on when QEMU part will be accepted.
I'll apply patch 1 once you have provided more info on the reason of the change, no need to resubmit patch 1, I'll reword the commit message with your info.
Thanks,
Maxime
PATCH 3/3 vhost: support VFIO based accelerator
In reply to Tiwei BieThis commit adds the VFIO based accelerator support to vhost. A new API is provided to support asking QEMU to do further setup to allow notifications and interrupts being delivered directly between the driver in guest and the vDPA device in host.
--- lib/librte_vhost/rte_vhost.h | 28 ++++++ lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/vhost_user.c | 166 +++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.h | 9 ++ 4 files changed, 204 insertions(+)
lib/librte_vhost/rte_vhost.h +28 -0
@@ -35,6 +35,7 @@ extern "C" {#define RTE_VHOST_USER_PROTOCOL_F_REPLY_ACK 3#define RTE_VHOST_USER_PROTOCOL_F_NET_MTU 4#define RTE_VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 +#define RTE_VHOST_USER_PROTOCOL_F_VFIO 8#define RTE_VHOST_USER_F_PROTOCOL_FEATURES 30/**
@@ -591,6 +592,33 @@ rte_vhost_get_vdpa_eid(int vid); int __rte_experimentalrte_vhost_get_vdpa_did (int vid); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Enable or disable the VFIO based accelerator for vhost-user. +* +* This function is to ask QEMU to do further setup to better +* support the vDPA device at vhost user backend. With this +* setup, the notifications and interrupts will be delivered +* directly between the driver in guest and the vDPA device +* in host if platform supports e.g. EPT and Posted interrupt. +* It's nice to have, and not mandatory. +* +* @param vid +* vhost device ID +* @param int +* Enable or disable +* +* @return +* 0: success +* -ENODEV: no such vhost device +* -ENOTSUP: device does not support VFIO based accelerator feature +* -EINVAL: there is no accelerator assigned to this vhost device +* -EFAULT: failed to talk with QEMU +*/ +int rte_vhost_vfio_accelerator_ctrl (int vid,int enable); + #ifdef __cplusplus }#endif
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -72,6 +72,7 @@ EXPERIMENTAL { rte_vhost_set_vring_base; rte_vhost_get_vdpa_eid; rte_vhost_get_vdpa_did; + rte_vhost_vfio_accelerator_ctrl; rte_vdpa_register_engine; rte_vdpa_unregister_engine; rte_vdpa_find_engine_id;
lib/librte_vhost/vhost_user.c +166 -0
181 lines not on this page · raw message
lib/librte_vhost/vhost_user.h +9 -0
@@ -52,6 +52,8 @@ typedef enum VhostUserRequest {typedef enum VhostUserSlaveRequest {VHOST_USER_SLAVE_NONE =0 ,VHOST_USER_SLAVE_IOTLB_MSG =1 , +VHOST_USER_SLAVE_VRING_VFIO_GROUP_MSG =3 , +VHOST_USER_SLAVE_VRING_NOTIFY_AREA_MSG =4 ,VHOST_USER_SLAVE_MAX }VhostUserSlaveRequest ;
@@ -73,6 +75,12 @@ typedef struct VhostUserLog {uint64_t mmap_offset; } VhostUserLog; +typedef struct VhostUserVringArea { +uint64_t u64; +uint64_t size; +uint64_t offset; +}VhostUserVringArea ; + typedef struct VhostUserMsg { union { uint32_t master; /* a VhostUserRequest value */
@@ -93,6 +101,7 @@ typedef struct VhostUserMsg {VhostUserMemory memory;VhostUserLog log;struct vhost_iotlb_msg iotlb; +VhostUserVringArea area; } payload;int fds[VHOST_MEMORY_MAX_NREGIONS ]; } __attribute((packed)) VhostUserMsg;
Signature · 1 line
2.11.0
Re: [PATCH 3/3] vhost: support VFIO based accelerator
Quoted 113 lines · Tiwei Bie
This commit adds the VFIO based accelerator support to vhost. A new API is provided to support asking QEMU to do further setup to allow notifications and interrupts being delivered directly between the driver in guest and the vDPA device in host.
Signed-off-by Tiwei Bie <[email protected]>--- lib/librte_vhost/rte_vhost.h | 28 ++++++ lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/vhost_user.c | 166 +++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.h | 9 ++ 4 files changed, 204 insertions(+)lib/librte_vhost/rte_vhost.h +28
-0@@ -35,6 +35,7 @@ extern "C" {#define RTE_VHOST_USER_PROTOCOL_F_REPLY_ACK 3#define RTE_VHOST_USER_PROTOCOL_F_NET_MTU 4#define RTE_VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 +#define RTE_VHOST_USER_PROTOCOL_F_VFIO 8#define RTE_VHOST_USER_F_PROTOCOL_FEATURES 30/** @@ -591,6 +592,33 @@ rte_vhost_get_vdpa_eid(int vid); int __rte_experimentalrte_vhost_get_vdpa_did (int vid); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Enable or disable the VFIO based accelerator for vhost-user. +* +* This function is to ask QEMU to do further setup to better +* support the vDPA device at vhost user backend. With this +* setup, the notifications and interrupts will be delivered +* directly between the driver in guest and the vDPA device +* in host if platform supports e.g. EPT and Posted interrupt. +* It's nice to have, and not mandatory. +* +* @param vid +* vhost device ID +* @param int +* Enable or disable +* +* @return +* 0: success +* -ENODEV: no such vhost device +* -ENOTSUP: device does not support VFIO based accelerator feature +* -EINVAL: there is no accelerator assigned to this vhost device +* -EFAULT: failed to talk with QEMU +*/ +int rte_vhost_vfio_accelerator_ctrl (int vid,int enable); + #ifdef __cplusplus }#endif lib/librte_vhost/rte_vhost_version.map +1
-0@@ -72,6 +72,7 @@ EXPERIMENTAL { rte_vhost_set_vring_base; rte_vhost_get_vdpa_eid; rte_vhost_get_vdpa_did; + rte_vhost_vfio_accelerator_ctrl; rte_vdpa_register_engine; rte_vdpa_unregister_engine; rte_vdpa_find_engine_id;lib/librte_vhost/vhost_user.c +22
-0@@ -35,6 +35,7 @@#include <rte_common.h> #include <rte_malloc.h> #include <rte_log.h> +#include <rte_vhost.h> #include "iotlb.h" #include "vhost.h" @@ -1628,6 +1629,27 @@ vhost_user_msg_handler(int vid, int fd)return 0 ; } +static int process_slave_message_reply (struct virtio_net *dev, +const VhostUserMsg *msg) +{ +VhostUserMsg msg_reply; + +if ((msg->flags &VHOST_USER_NEED_REPLY ) ==0 ) +return 0 ; + +if (read_vhost_message (dev->slave_req_fd, &msg_reply) <0 ) +return -1 ; + +if (msg_reply.request.slave != msg->request.slave) { +RTE_LOG (ERR ,VHOST_CONFIG , +"received unexpected msg type (%u), expected %u\n" , + msg_reply.request.slave, msg->request.slave); +return -1 ; + } + +return msg_reply.payload.u64; +} +int vhost_user_iotlb_miss (struct virtio_net *dev,uint64_t iova,uint8_t perm) {
lib/librte_vhost/vhost_user.c vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm) · line 1681
Quoted 7 lines
lib/librte_vhost/vhost_user.c +4
-0@@ -1653,3 +1675,147 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)return 0 ; } + +static int vhost_user_slave_set_vring_file (struct virtio_net *dev, +uint32_t request, +struct vhost_vring_file *file)
Why passing the request as an argument?
It seems to be called only with the same request ID.
Quoted 17 lines
lib/librte_vhost/vhost_user.c +17
-0+{ +int *fdp =NULL ; +size_t fd_num =0 ; +int ret; +struct VhostUserMsg msg = { + .request.slave = request, + .flags =VHOST_USER_VERSION |VHOST_USER_NEED_REPLY , + .payload.u64 = file->index &VHOST_USER_VRING_IDX_MASK , + .size =sizeof (msg.payload.u64), + }; + +if (file->fd <0 ) + msg.payload.u64 |=VHOST_USER_VRING_NOFD_MASK ; +else { + fdp = &file->fd; + fd_num =1 ; + }
lib/librte_vhost/vhost_user.c vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm) · line 1708
Quoted 10 lines
lib/librte_vhost/vhost_user.c +10
-0+ + ret =send_vhost_message (dev->slave_req_fd, &msg, fdp, fd_num); +if (ret <0 ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"Failed to send slave message %u (%d)\n" , + request, ret); +return ret; + } + +return process_slave_message_reply (dev, &msg);
Maybe not needed right now, but we'll need a lock to avoid concurrent requests sending and waiting for reply.
Thanks,
Maxime
Re: [PATCH 3/3] vhost: support VFIO based accelerator
Quoted 1 line · Maxime Coquelin
On 03/06/2018 11:43 AM, Tiwei Bie wrote:
[...]
Quoted 6 lines
lib/librte_vhost/vhost_user.c vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm) · line 1681
Quoted 4 lines
lib/librte_vhost/vhost_user.c +4
-0+ +static int vhost_user_slave_set_vring_file (struct virtio_net *dev, +uint32_t request, +struct vhost_vring_file *file)Why passing the request as an argument?
It seems to be called only with the same request ID.
I thought there may be other requests that also need to send a file descriptor for a ring in the future. So I made this a common routine. Maybe it's not really helpful. I won't pass the request as an argument in next version.
Quoted 23 lines
Quoted 23 lines
lib/librte_vhost/vhost_user.c +22
-0+{ +int *fdp =NULL ; +size_t fd_num =0 ; +int ret; +struct VhostUserMsg msg = { + .request.slave = request, + .flags =VHOST_USER_VERSION |VHOST_USER_NEED_REPLY , + .payload.u64 = file->index &VHOST_USER_VRING_IDX_MASK , + .size =sizeof (msg.payload.u64), + }; + +if (file->fd <0 ) + msg.payload.u64 |=VHOST_USER_VRING_NOFD_MASK ; +else { + fdp = &file->fd; + fd_num =1 ; + } + + ret =send_vhost_message (dev->slave_req_fd, &msg, fdp, fd_num); +if (ret <0 ) { + RTE_LOG(ERR, VHOST_CONFIG, + "Failed to send slave message %u (%d)\n",
Quoted 8 lines
lib/librte_vhost/vhost_user.c vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm) · line 1708
Quoted 5 lines
lib/librte_vhost/vhost_user.c +5
-0+ request, ret); +return ret; + } + +return process_slave_message_reply (dev, &msg);Maybe not needed right now, but we'll need a lock to avoid concurrent requests sending and waiting for reply.
Yeah, probably, we need a lock for each slave channel. I didn't check the code of Linux. Maybe it will cause problems when two threads send e.g. below messages at the same time:
thread A:
IOTLB miss message
thread B:
VFIO group message which has a file descriptor
Thanks for the comments! :)
Best regards,
Tiwei Bie
PATCH v2 1/1 vhost: support VFIO based accelerator
In reply to Tiwei BieEnable the VFIO based accelerator support in vhost-user. When a vDPA device is attached, vhost user will try to ask QEMU to do further setup to allow the notifications to be delivered between the driver in the guest and the vDPA device in the host directly.
---
This patch depends on below patch set for QEMU:
http://lists.nongnu.org/archive/html/qemu-devel/2018-04/msg01779.html
v2:
- Address the changes in vDPA
- Address the changes in QEMU
- Add a lock protection (Maxime)
lib/librte_vhost/rte_vhost.h | 4 ++ lib/librte_vhost/vhost.c | 4 ++ lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/vhost_user.c | 146 +++++++++++++++++++++++++++++++++++++++++- lib/librte_vhost/vhost_user.h | 12 +++- 5 files changed, 165 insertions(+), 2 deletions(-)
lib/librte_vhost/rte_vhost.h +4 -0
@@ -58,6 +58,10 @@ extern "C" {#define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7#endif +#ifndef VHOST_USER_PROTOCOL_F_HOST_NOTIFIER +#define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 10 +#endif +/** Indicate whether protocol features negotiation is supported. */ #ifndef VHOST_USER_F_PROTOCOL_FEATURES #define VHOST_USER_F_PROTOCOL_FEATURES 30
lib/librte_vhost/vhost.c +4 -0
@@ -285,6 +285,8 @@ vhost_new_device(void) dev->slave_req_fd =-1 ; dev->vdpa_dev_id =-1 ; +rte_spinlock_init (&dev->slave_req_lock); +return i; }
@@ -339,6 +341,8 @@ vhost_detach_vdpa_device(int vid)if (dev ==NULL )return ; +vhost_user_vfio_accelerator_ctrl (vid, false); + dev->vdpa_dev_id =-1 ; }
lib/librte_vhost/vhost.h +1 -0
@@ -288,6 +288,7 @@ struct virtio_net {struct guest_page *guest_pages;int slave_req_fd; +rte_spinlock_t slave_req_lock;/* * Device id to identify a specific backend device.
lib/librte_vhost/vhost_user.c +145 -1
172 lines not on this page · raw message
lib/librte_vhost/vhost_user.h +11 -1
@@ -20,7 +20,8 @@ (1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK) | \ (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU) | \ (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \ - (1ULL << VHOST_USER_PROTOCOL_F_CRYPTO_SESSION)) + (1ULL << VHOST_USER_PROTOCOL_F_CRYPTO_SESSION) | \ + (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER)) typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
@@ -54,6 +55,7 @@ typedef enum VhostUserRequest {typedef enum VhostUserSlaveRequest {VHOST_USER_SLAVE_NONE =0 ,VHOST_USER_SLAVE_IOTLB_MSG =1 , +VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG =3 ,VHOST_USER_SLAVE_MAX }VhostUserSlaveRequest ;
@@ -99,6 +101,12 @@ typedef struct VhostUserCryptoSessionParam {uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; } VhostUserCryptoSessionParam; +typedef struct VhostUserVringArea { +uint64_t u64; +uint64_t size; +uint64_t offset; +}VhostUserVringArea ; + typedef struct VhostUserMsg { union { uint32_t master; /* a VhostUserRequest value */
@@ -120,6 +128,7 @@ typedef struct VhostUserMsg {VhostUserLog log;struct vhost_iotlb_msg iotlb;VhostUserCryptoSessionParam crypto_session; +VhostUserVringArea area; } payload;int fds[VHOST_MEMORY_MAX_NREGIONS ]; } __attribute((packed)) VhostUserMsg;
@@ -133,6 +142,7 @@ typedef struct VhostUserMsg {/* vhost_user.c */ int vhost_user_msg_handler (int vid,int fd);int vhost_user_iotlb_miss (struct virtio_net *dev,uint64_t iova,uint8_t perm); +int vhost_user_vfio_accelerator_ctrl (int vid,int enable);/* socket.c */ int read_fd_message (int sockfd,char *buf,int buflen,int *fds,int fd_num);
Signature · 1 line
2.11.0