vhost: generic vhost API
cover vhost: generic vhost API
This is a first attempt to make DPDK vhost library be generic enough, so that user could built its own vhost-user drivers on top of it. For example, SPDK (Storage Performance Development Kit) is trying to enable vhost-user SCSI.
The basic idea is, let DPDK vhost be a vhost-user agent. It stores all the info about the virtio device (i.e. vring address, negotiated features, etc) and let the specific vhost-user driver to fetch them (by the API provided by DPDK vhost lib). With those info being provided, the vhost-user driver then could get/put vring entries, thus, it could exchange data between the guest and host.
The last patch demonstrates how to use these new APIs to implement a very simple vhost-user net driver, without any fancy features enabled.
API/ABI Changes summary
=======================
- some renames
* "struct virtio_net_device_ops" ==> "struct vhost_device_ops"
* "rte_virtio_net.h" ==> "rte_vhost.h"
- driver related APIs are bond with the socket file
* rte_vhost_driver_set_features(socket_file, features);
* rte_vhost_driver_get_features(socket_file, features);
* rte_vhost_driver_enable_features(socket_file, features)
* rte_vhost_driver_disable_features(socket_file, features)
* rte_vhost_driver_callback_register(socket_file, notify_ops);
- new APIs to fetch guest and vring info
* rte_vhost_get_vhost_memory(int vid, struct rte_vhost_memory **mem);
* rte_vhost_get_negotiated_features(int vid);
* rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
struct rte_vhost_vring *vring);
- new exported structures
* struct rte_vhost_vring
* struct rte_vhost_mem_region
* struct rte_vhost_memory
Some design choices
===================
While making this patchset, I met quite few design choices and here are two of them, with the issue and the reason I made such choices provided. Please let me know if you have any comments (or better ideas).
Export public structures or not
-------------------------------
I made an ABI refactor last time (v16.07): move all the structures internally and let applications use a "vid" to reference the internal struct. With that, I hope we could never worry about the annoying ABI issues.
It works great (and as expected) since then, as far as we only support virito-net, as far as we can handle all the descs inside vhost lib. It becomes problematic when a user wants to implement a vhost-user driver somewhere. For example, it needs do the GPA to VVA translation. Without any structs exported, some functions like gpa_to_vva() can't be inlined. Calling it would be costly, especially it's a function we have to invoke for processing each vring desc.
For that reason, the guest memory regions are exported. With that, the gpa_to_vva could be inlined.
Add helper functions to fetch/update descs or not
-------------------------------------------------
I intended to do it like this way: introduce one function to get @count of descs from a specific vring and another one to update the used descs. It's something like
rte_vhost_vring_get_descs(vid, vring_idx, count, offset, iov, descs);
rte_vhost_vring_update_used_descs(vid, vring_idx, count, offset, descs);With that, vhost-user driver programmer's task would be easier, as he/she doesn't have to parse the descs any more (such as to handle indirect desc).
But judging that virtio 1.1 is just emerged and it proposes a completely ring layout, and most importantly, the vring desc structure is also changed, I'd like to hold to introduce such two functions. Otherwise, it's very likely the two will be invalid when virtio 1.1 is out. Though I think it may could be addressed with a care design, something like making the IOV generic enough:
struct rte_vhost_iov {
uint64_t gpa;
uint64_t vva;
uint64_t len;
};Instead, I go with the other way: introduce few APIs to export all the vring infos (vring size, vring addr, callfd, etc), and let the vhost-user driver read and update the descs. Those info could be passed to vhost-user driver by introducing one API for each, but for saving few APIs and reducing few calls for the programmer, I packed few key fields into a new structure, so that it can be fetched with one call:
struct rte_vhost_vring {
struct vring_desc *desc;
struct vring_avail *avail;
struct vring_used *used;
uint64_t log_guest_addr;
int callfd;
int kickfd;
uint16_t size;
};When virtio 1.1 comes out, likely a simple change like following would just work:
struct rte_vhost_vring {
union {
struct {
struct vring_desc *desc;
struct vring_avail *avail;
struct vring_used *used;
uint64_t log_guest_addr;
};
struct desc *desc_1_1; /* vring addr for virtio 1.1 */
};
int callfd;
int kickfd;
uint16_t size;
};AFAIK, it's not an ABI breakage. Even if it does, we could introduce a new API to get the virtio 1.1 ring address.
Those fields are the minimum set I got for a specific vring, with the mind it would bring the minimum chance to break ABI for future extension. If we need more info, we could introduce a new API.
OTOH, for getting the best performance, the two functions also have to be inlined ("vid + vring_idx" combo is replaced with "vring"):
rte_vhost_vring_get_descs(vring, count, offset, iov, descs);
rte_vhost_vring_update_used_descs(vring, count, offset, descs);That said, one way or another, we have to export rte_vhost_vring struct. For this reason, I didn't rush into introducing the two APIs.
TODOs
=====
This series still got few small items to finish, and they are:
- update release note
- fill API comments
- set protocol features
--yliu
---
Yuanhan Liu (17):
vhost: introduce driver features related APIs net/vhost: remove feature related APIs
vhost: use new APIs to handle features
vhost: make notify ops per vhost driver
vhost: export guest memory regions
vhost: introduce API to fetch negotiated features
vhost: export vhost vring info
vhost: export API to translate gpa to vva
vhost: turn queue pair to vring
vhost: export the number of vrings
vhost: move the device ready check at proper place
vhost: drop the Rx and Tx queue macro
vhost: do not include net specific headers
vhost: rename device ops struct
vhost: rename virtio-net to vhost
vhost: rename header file
examples/vhost: demonstrate the new generic vhost APIs
doc/guides/rel_notes/deprecation.rst | 9 - drivers/net/vhost/rte_eth_vhost.c | 51 ++-- drivers/net/vhost/rte_eth_vhost.h | 32 +-- drivers/net/vhost/rte_pmd_vhost_version.map | 3 - examples/tep_termination/main.c | 11 +- examples/tep_termination/main.h | 2 + examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/Makefile | 2 +- examples/vhost/main.c | 88 ++++-- examples/vhost/main.h | 33 ++- examples/vhost/virtio_net.c | 405 ++++++++++++++++++++++++++++ lib/librte_vhost/Makefile | 4 +- lib/librte_vhost/rte_vhost.h | 259 ++++++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 18 +- lib/librte_vhost/rte_virtio_net.h | 193 ------------- lib/librte_vhost/socket.c | 143 ++++++++++ lib/librte_vhost/vhost.c | 209 +++++++------- lib/librte_vhost/vhost.h | 82 +++--- lib/librte_vhost/vhost_user.c | 91 +++---- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 35 +-- 21 files changed, 1140 insertions(+), 534 deletions(-) create mode 100644 examples/vhost/virtio_net.c create mode 100644 lib/librte_vhost/rte_vhost.h delete mode 100644 lib/librte_vhost/rte_virtio_net.h
Signature · 1 line
1.9.0
PATCH 1/17 vhost: introduce driver features related APIs
Introduce few APIs to set/get/enable/disable driver features.
--- lib/librte_vhost/rte_vhost_version.map | 10 ++++ lib/librte_vhost/rte_virtio_net.h | 9 ++++ lib/librte_vhost/socket.c | 90 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+)
lib/librte_vhost/rte_vhost_version.map +10 -0
@@ -30,3 +30,13 @@ DPDK_16.07 { rte_vhost_get_queue_num; } DPDK_2.1; + +DPDK_17.05 { + global: + + rte_vhost_driver_disable_features; + rte_vhost_driver_enable_features; + rte_vhost_driver_get_features; + rte_vhost_driver_set_features; + +} DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +9 -0
@@ -94,6 +94,15 @@ struct virtio_net_device_ops {/* Unregister vhost driver. This is only meaningful to vhost user. */ int rte_vhost_driver_unregister (const char *path); +/** +* Set feature bits the vhost driver supports. +*/ +int rte_vhost_driver_set_features (const char *path,uint64_t features); +uint64_t rte_vhost_driver_get_features (const char *path); + +int rte_vhost_driver_enable_features (const char *path,uint64_t features); +int rte_vhost_driver_disable_features (const char *path,uint64_t features); +/* Register callbacks. */ int rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const );/* Start vhost driver session blocking loop. */
lib/librte_vhost/socket.c +90 -0
102 lines not on this page · raw message
Signature · 1 line
1.9.0
Re: [PATCH 01/17] vhost: introduce driver features related APIs
Quoted 8 lines · Yuanhan Liu
Introduce few APIs to set/get/enable/disable driver features.
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost_version.map | 10 ++++ lib/librte_vhost/rte_virtio_net.h | 9 ++++ lib/librte_vhost/socket.c | 90 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+)
Nice!
I wonder whether we could protect from setting/enabling/disabling features once negotiation is done?
Thanks,
Maxime
Re: [PATCH 01/17] vhost: introduce driver features related APIs
Quoted 13 lines · Maxime Coquelin
Quoted 9 lines · Yuanhan Liu
Introduce few APIs to set/get/enable/disable driver features.
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost_version.map | 10 ++++ lib/librte_vhost/rte_virtio_net.h | 9 ++++ lib/librte_vhost/socket.c | 90 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+)
Quoted 5 lines
Nice!
Reviewed-by Maxime Coquelin <[email protected]>I wonder whether we could protect from setting/enabling/disabling features once negotiation is done?
Oh, I forgot one comment on this patch.
Since these new functions are part to the API, shouldn't them be documented?
Maxime
Re: [PATCH 01/17] vhost: introduce driver features related APIs
Quoted 16 lines · Maxime Coquelin
Quoted 13 lines · Maxime Coquelin
Quoted 9 lines · Yuanhan Liu
Introduce few APIs to set/get/enable/disable driver features.
Signed-off-by Yuanhan Liu <[email protected]>---
lib/librte_vhost/rte_vhost_version.map | 10 ++++ lib/librte_vhost/rte_virtio_net.h | 9 ++++ lib/librte_vhost/socket.c | 90 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+)
Quoted 5 lines
Quoted 5 lines
Nice!
Reviewed-by Maxime Coquelin <[email protected]>I wonder whether we could protect from setting/enabling/disabling features once negotiation is done?
Those APIs won't be able to change the negotiated features. They are just some interfaces before the vhost-user connection is established.
Ideally, we could/should get rid of the enabling/disabling functions:
let the vhost-user driver to handle the features directly (say, for vhost-user pmd, we could use vdev options to disable/enable few specific features). Once that is done, use the rte_vhost_driver_set_features() set the features once.
The reason I introduced the enable/disable_features() is to keep the compatability with the builtin vhost-user net driver (virtio_net.c). If there is a plan to move it into vhost-pmd, they won't be needed. And I don't think that will happen soon.
Quoted 3 lines
Oh, I forgot one comment on this patch.
Since these new functions are part to the API, shouldn't them be documented?
Yes, indeed, it's also noted in my cover letter.
--yliu
Re: [PATCH 01/17] vhost: introduce driver features related APIs
Quoted 17 lines · Yuanhan Liu
Quoted 16 lines · Maxime Coquelin
Quoted 13 lines · Maxime Coquelin
Quoted 9 lines · Yuanhan Liu
Introduce few APIs to set/get/enable/disable driver features.
Signed-off-by Yuanhan Liu <[email protected]>---
lib/librte_vhost/rte_vhost_version.map | 10 ++++ lib/librte_vhost/rte_virtio_net.h | 9 ++++ lib/librte_vhost/socket.c | 90 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+)
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Nice!
Reviewed-by Maxime Coquelin <[email protected]>I wonder whether we could protect from setting/enabling/disabling features once negotiation is done?
Those APIs won't be able to change the negotiated features. They are just some interfaces before the vhost-user connection is established.
Right.
I meant it could return an error is the connection is already established. Else, the caller might think the feature has been successfully enabled/disabled, whereas it is not the case. But this is maybe over-engineering to handle this case.
Quoted 5 lines
Ideally, we could/should get rid of the enabling/disabling functions:
let the vhost-user driver to handle the features directly (say, for vhost-user pmd, we could use vdev options to disable/enable few specific features). Once that is done, use therte_vhost_driver_set_features()set the features once.
Ok, but what about vhost lib users and TSO (I'm thinking of OVS).
Quoted 4 lines
The reason I introduced the enable/disable_features() is to keep the compatability with the builtin vhost-user net driver (
virtio_net.c). If there is a plan to move it into vhost-pmd, they won't be needed. And I don't think that will happen soon.
I agree with you that would be ideal, but unlikely to happen soon.
Quoted 5 lines
Quoted 3 lines
Oh, I forgot one comment on this patch.
Since these new functions are part to the API, shouldn't them be documented?Yes, indeed, it's also noted in my cover letter.
Oops, I missed that!
Thanks,
Maxime
Quoted 2 lines
--yliu
Re: [PATCH 01/17] vhost: introduce driver features related APIs
Quoted 35 lines · Maxime Coquelin
Quoted 17 lines · Yuanhan Liu
Quoted 16 lines · Maxime Coquelin
Quoted 13 lines · Maxime Coquelin
Quoted 9 lines · Yuanhan Liu
Introduce few APIs to set/get/enable/disable driver features.
Signed-off-by Yuanhan Liu <[email protected]>---
lib/librte_vhost/rte_vhost_version.map | 10 ++++ lib/librte_vhost/rte_virtio_net.h | 9 ++++ lib/librte_vhost/socket.c | 90 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+)Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Nice!
Reviewed-by Maxime Coquelin <[email protected]>I wonder whether we could protect from setting/enabling/disabling features once negotiation is done?
Those APIs won't be able to change the negotiated features. They are just some interfaces before the vhost-user connection is established.
Right.
I meant it could return an error is the connection is already established. Else, the caller might think the feature has been successfully enabled/disabled, whereas it is not the case. But this is maybe over-engineering to handle this case.
Quoted 7 lines
Quoted 5 lines
Ideally, we could/should get rid of the enabling/disabling functions:
let the vhost-user driver to handle the features directly (say, for vhost-user pmd, we could use vdev options to disable/enable few specific features). Once that is done, use therte_vhost_driver_set_features()set the features once.Ok, but what about vhost lib users and TSO (I'm thinking of OVS).
Yes, that's why I kept them :)
--yliu
Quoted 20 lines
Quoted 5 lines
The reason I introduced the enable/disable_features() is to keep the compatability with the builtin vhost-user net driver (
virtio_net.c). If there is a plan to move it into vhost-pmd, they won't be needed. And I don't think that will happen soon.I agree with you that would be ideal, but unlikely to happen soon.
Quoted 5 lines
Quoted 3 lines
Oh, I forgot one comment on this patch.
Since these new functions are part to the API, shouldn't them be documented?Yes, indeed, it's also noted in my cover letter.
Oops, I missed that!
Thanks,
MaximeQuoted 2 lines
--yliu
PATCH 2/17 net/vhost: remove feature related APIs
In reply to Yuanhan Liuvdev options is better for disabling/enabling some features.
--- drivers/net/vhost/rte_eth_vhost.c | 25 ------------------------ drivers/net/vhost/rte_eth_vhost.h | 30 ----------------------------- drivers/net/vhost/rte_pmd_vhost_version.map | 3 --- 3 files changed, 58 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +0 -25
@@ -963,31 +963,6 @@ struct vhost_xstats_name_off {return 0 ; } -/** -* Disable features in feature_mask. Returns 0 on success. -*/ -int -rte_eth_vhost_feature_disable (uint64_t feature_mask) -{ -return rte_vhost_feature_disable (feature_mask); -} - -/** -* Enable features in feature_mask. Returns 0 on success. -*/ -int -rte_eth_vhost_feature_enable (uint64_t feature_mask) -{ -return rte_vhost_feature_enable (feature_mask); -} - -/* Returns currently supported vhost features */ -uint64_t -rte_eth_vhost_feature_get (void ) -{ -return rte_vhost_feature_get (); -} -static const struct eth_dev_ops ops = { .dev_start = eth_dev_start, .dev_stop = eth_dev_stop,
drivers/net/vhost/rte_eth_vhost.h +0 -30
@@ -43,36 +43,6 @@#include <rte_virtio_net.h> -/** -* Disable features in feature_mask. -* -* @param feature_mask -* Vhost features defined in "linux/virtio_net.h". -* @return -* - On success, zero. -* - On failure, a negative value. -*/ -int rte_eth_vhost_feature_disable (uint64_t feature_mask); - -/** -* Enable features in feature_mask. -* -* @param feature_mask -* Vhost features defined in "linux/virtio_net.h". -* @return -* - On success, zero. -* - On failure, a negative value. -*/ -int rte_eth_vhost_feature_enable (uint64_t feature_mask); - -/** -* Returns currently supported vhost features. -* -* @return -* Vhost features defined in "linux/virtio_net.h". -*/ -uint64_t rte_eth_vhost_feature_get (void ); -/* * Event description. */
drivers/net/vhost/rte_pmd_vhost_version.map +0 -3
@@ -1,9 +1,6 @@ DPDK_16.04 { global: - rte_eth_vhost_feature_disable; - rte_eth_vhost_feature_enable; - rte_eth_vhost_feature_get; rte_eth_vhost_get_queue_event; local: *;
Signature · 1 line
1.9.0
Re: [PATCH 02/17] net/vhost: remove feature related APIs
Quoted 8 lines · Yuanhan Liu
vdev options is better for disabling/enabling some features.
Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 25 ------------------------ drivers/net/vhost/rte_eth_vhost.h | 30 ----------------------------- drivers/net/vhost/rte_pmd_vhost_version.map | 3 --- 3 files changed, 58 deletions(-)
Thanks,
Maxime
PATCH 3/17 vhost: use new APIs to handle features
In reply to Yuanhan Liu--- examples/tep_termination/main.c | 4 +++- examples/vhost/main.c | 43 +++++++++++++++++++++------------- lib/librte_vhost/rte_vhost_version.map | 3 --- lib/librte_vhost/rte_virtio_net.h | 13 ---------- lib/librte_vhost/socket.c | 23 +++++++++++++++++- lib/librte_vhost/vhost.c | 41 -------------------------------- lib/librte_vhost/vhost.h | 20 ++++++++++++++++ lib/librte_vhost/vhost_user.c | 8 +++---- 8 files changed, 76 insertions(+), 79 deletions(-)
examples/tep_termination/main.c +3 -1
@@ -1250,12 +1250,14 @@ static inline void __attribute__((always_inline))rte_eal_remote_launch (switch_worker, mbuf_pool, lcore_id); } -rte_vhost_feature_disable (1ULL <<VIRTIO_NET_F_MRG_RXBUF ); ret =rte_vhost_driver_register ((char *)&dev_basename,0 );if (ret !=0 )rte_exit (EXIT_FAILURE ,"failed to register vhost driver.\n" ); +rte_vhost_driver_disable_features (dev_basename, +1ULL <<VIRTIO_NET_F_MRG_RXBUF ); +rte_vhost_driver_callback_register (&virtio_net_device_ops);rte_vhost_driver_session_start ();
examples/vhost/main.c +27 -16
72 lines not on this page · raw message
lib/librte_vhost/rte_vhost_version.map +0 -3
@@ -7,9 +7,6 @@ DPDK_2.0 { rte_vhost_driver_session_start; rte_vhost_enable_guest_notification; rte_vhost_enqueue_burst; - rte_vhost_feature_disable; - rte_vhost_feature_enable; - rte_vhost_feature_get; local: *; };
lib/librte_vhost/rte_virtio_net.h +0 -13
@@ -70,19 +70,6 @@ struct virtio_net_device_ops {void *reserved[5 ];/**< Reserved for future extension */ }; -/** -* Disable features in feature_mask. Returns 0 on success. -*/ -int rte_vhost_feature_disable (uint64_t feature_mask); - -/** -* Enable features in feature_mask. Returns 0 on success. -*/ -int rte_vhost_feature_enable (uint64_t feature_mask); - -/* Returns currently supported vhost features */ -uint64_t rte_vhost_feature_get (void ); -int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/**
lib/librte_vhost/socket.c +22 -1
@@ -500,6 +500,21 @@ struct vhost_user_reconnect_list {return NULL ; } +/* +* Applications know nothing about features the builtin virtio net +* driver (virtio_net.c) supports, thus it's not possible for them +* to invoke rte_vhost_driver_set_features(). To workaround it, here +* we set it when no such call is invoked. +*/ +static void +workaround_builtin_virtio_net_features (struct vhost_user_socket *vsocket) +{ +if (vsocket->supported_features ==UINT64_MAX ) { + vsocket->supported_features =VIRTIO_NET_SUPPORTED_FEATURES ; + vsocket->features =VIRTIO_NET_SUPPORTED_FEATURES ; + } +} +int rte_vhost_driver_disable_features (const char *path,uint64_t features) {
@@ -507,8 +522,10 @@ struct vhost_user_reconnect_list {pthread_mutex_lock (&vhost_user.mutex); vsocket =find_vhost_user_socket (path); -if (vsocket) +if (vsocket) { +workaround_builtin_virtio_net_features (vsocket); vsocket->features &= ~features; + }pthread_mutex_unlock (&vhost_user.mutex);return vsocket ?0 :-1 ;
@@ -522,6 +539,7 @@ struct vhost_user_reconnect_list {pthread_mutex_lock (&vhost_user.mutex); vsocket =find_vhost_user_socket (path);if (vsocket) { +workaround_builtin_virtio_net_features (vsocket);if ((vsocket->supported_features & features) != features) {/* * trying to enable features the driver doesn't
@@ -560,6 +578,8 @@ struct vhost_user_reconnect_list {pthread_mutex_lock (&vhost_user.mutex); vsocket =find_vhost_user_socket (path); +if (vsocket) +workaround_builtin_virtio_net_features (vsocket);pthread_mutex_unlock (&vhost_user.mutex);return vsocket ? vsocket->features : (uint64_t )-1 ;
@@ -594,6 +614,7 @@ struct vhost_user_reconnect_list { vsocket->path =strdup (path); vsocket->connfd =-1 ; vsocket->dequeue_zero_copy = flags &RTE_VHOST_USER_DEQUEUE_ZERO_COPY ; + vsocket->supported_features =UINT64_MAX ;if ((flags &RTE_VHOST_USER_CLIENT ) !=0 ) { vsocket->reconnect = !(flags &RTE_VHOST_USER_NO_RECONNECT );
lib/librte_vhost/vhost.c +0 -41
53 lines not on this page · raw message
lib/librte_vhost/vhost.h +20 -0
@@ -44,6 +44,26 @@#include "rte_virtio_net.h" +#define VHOST_USER_F_PROTOCOL_FEATURES 30 + +/* Features supported by this lib. */ +#define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \ + (1ULL << VIRTIO_NET_F_CTRL_VQ) | \ + (1ULL << VIRTIO_NET_F_CTRL_RX) | \ + (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \ + (1ULL << VIRTIO_NET_F_MQ) | \ + (1ULL << VIRTIO_F_VERSION_1) | \ + (1ULL << VHOST_F_LOG_ALL) | \ + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \ + (1ULL << VIRTIO_NET_F_HOST_TSO4) | \ + (1ULL << VIRTIO_NET_F_HOST_TSO6) | \ + (1ULL << VIRTIO_NET_F_CSUM) | \ + (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \ + (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \ + (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \ + (1ULL << VIRTIO_RING_F_INDIRECT_DESC)) + +/* Used to indicate that the device is running on a data core */ #define VIRTIO_DEV_RUNNING 1
lib/librte_vhost/vhost_user.c +4 -4
@@ -143,9 +143,9 @@* The features that we support are requested. */ static uint64_t -vhost_user_get_features (void ) +vhost_user_get_features (struct virtio_net *dev) { -return VHOST_FEATURES ; +return rte_vhost_driver_get_features (dev->ifname); }/*
@@ -154,7 +154,7 @@static int vhost_user_set_features (struct virtio_net *dev,uint64_t features) { -if (features & ~VHOST_FEATURES ) +if (features & ~rte_vhost_driver_get_features (dev->ifname))return -1 ; dev->features = features;
@@ -980,7 +980,7 @@switch (msg.request) {case VHOST_USER_GET_FEATURES : - msg.payload.u64 =vhost_user_get_features (); + msg.payload.u64 =vhost_user_get_features (dev); msg.size =sizeof (msg.payload.u64);send_vhost_message (fd, &msg);break ;
Signature · 1 line
1.9.0
Re: [PATCH 03/17] vhost: use new APIs to handle features
Quoted 12 lines · Yuanhan Liu
Signed-off-by Yuanhan Liu <[email protected]>--- examples/tep_termination/main.c | 4 +++- examples/vhost/main.c | 43 +++++++++++++++++++++------------- lib/librte_vhost/rte_vhost_version.map | 3 --- lib/librte_vhost/rte_virtio_net.h | 13 ---------- lib/librte_vhost/socket.c | 23 +++++++++++++++++- lib/librte_vhost/vhost.c | 41 -------------------------------- lib/librte_vhost/vhost.h | 20 ++++++++++++++++ lib/librte_vhost/vhost_user.c | 8 +++---- 8 files changed, 76 insertions(+), 79 deletions(-)
</snip>
Quoted 18 lines
lib/librte_vhost/vhost_user.c +2
-2@@ -143,9 +143,9 @@* The features that we support are requested. */ static uint64_t -vhost_user_get_features (void ) +vhost_user_get_features (struct virtio_net *dev) { -return VHOST_FEATURES ; +return rte_vhost_driver_get_features (dev->ifname); }/*
lib/librte_vhost/vhost_user.c line 157
Quoted 5 lines
lib/librte_vhost/vhost_user.c +1
-1@@ -154,7 +154,7 @@static int vhost_user_set_features (struct virtio_net *dev,uint64_t features) { -if (features & ~VHOST_FEATURES ) +if (features & ~rte_vhost_driver_get_features (dev->ifname))
rte_vhost_driver_get_features() returns -1 if the socket is not found. It would result in accepting any feature trying to be set.
Maxime
Re: [PATCH 03/17] vhost: use new APIs to handle features
Quoted 15 lines · Maxime Coquelin
Quoted 15 lines
lib/librte_vhost/vhost_user.c +0
-0@@ -143,9 +143,9 @@* The features that we support are requested. */ static
uint64_tlib/librte_vhost/vhost_user.c +1
-1-vhost_user_get_features (void) +vhost_user_get_features(struct virtio_net *dev){
lib/librte_vhost/vhost_user.c +1
-1-return VHOST_FEATURES ; +return rte_vhost_driver_get_features (dev->ifname);}
Quoted 10 lines
lib/librte_vhost/vhost_user.c line 157
Quoted 7 lines
/*
lib/librte_vhost/vhost_user.c +0
-0@@ -154,7 +154,7 @@static int
vhost_user_set_features(struct virtio_net *dev, uint64_t features){lib/librte_vhost/vhost_user.c +1
-1-if (features & ~VHOST_FEATURES ) +if (features & ~rte_vhost_driver_get_features (dev->ifname))
rte_vhost_driver_get_features()returns -1 if the socket is not found. It would result in accepting any feature trying to be set.
If we have gone here, I think rte_vhost_driver_get_features() should not return -1. The only exception is user unregistered such socket during the negotiation?
--yliu
Re: [PATCH 03/17] vhost: use new APIs to handle features
Quoted 27 lines · Yuanhan Liu
Quoted 15 lines · Maxime Coquelin
Quoted 15 lines
lib/librte_vhost/vhost_user.c +0
-0@@ -143,9 +143,9 @@* The features that we support are requested. */ static
uint64_tlib/librte_vhost/vhost_user.c +1
-1-vhost_user_get_features (void) +vhost_user_get_features(struct virtio_net *dev){
lib/librte_vhost/vhost_user.c +1
-1-return VHOST_FEATURES ; +return rte_vhost_driver_get_features (dev->ifname);}
Quoted 10 lines
lib/librte_vhost/vhost_user.c line 157
Quoted 7 lines
/*
lib/librte_vhost/vhost_user.c +0
-0@@ -154,7 +154,7 @@static int
vhost_user_set_features(struct virtio_net *dev, uint64_t features){lib/librte_vhost/vhost_user.c +1
-1-if (features & ~VHOST_FEATURES ) +if (features & ~rte_vhost_driver_get_features (dev->ifname))
rte_vhost_driver_get_features()returns -1 if the socket is not found. It would result in accepting any feature trying to be set.
Quoted 3 lines
If we have gone here, I think
rte_vhost_driver_get_features()should not return -1. The only exception is user unregistered such socket during the negotiation?
Maybe this could never happen.
I just noticed that rte_vhost_driver_get_features() can fail, and in that case, we wouldn't see it and the behavior could make hard the cause to be hard to spot.
As this is not in the hot code path, my view is that checking its return and print an error message does not hurt.
Or maybe we could directly do the error prints into rte_vhost_driver_*_features() functions if the socket name is not found?
Cheers,
Maxime
Re: [PATCH 03/17] vhost: use new APIs to handle features
Quoted 39 lines · Maxime Coquelin
Quoted 27 lines · Yuanhan Liu
Quoted 15 lines · Maxime Coquelin
Quoted 15 lines
lib/librte_vhost/vhost_user.c +0
-0@@ -143,9 +143,9 @@* The features that we support are requested. */ static
uint64_tlib/librte_vhost/vhost_user.c +1
-1-vhost_user_get_features (void) +vhost_user_get_features(struct virtio_net *dev){
lib/librte_vhost/vhost_user.c +1
-1-return VHOST_FEATURES ; +return rte_vhost_driver_get_features (dev->ifname);}
Quoted 10 lines
lib/librte_vhost/vhost_user.c line 157
Quoted 7 lines
/*
lib/librte_vhost/vhost_user.c +0
-0@@ -154,7 +154,7 @@static int
vhost_user_set_features(struct virtio_net *dev, uint64_t features){lib/librte_vhost/vhost_user.c +1
-1-if (features & ~VHOST_FEATURES ) +if (features & ~rte_vhost_driver_get_features (dev->ifname))
rte_vhost_driver_get_features()returns -1 if the socket is not found. It would result in accepting any feature trying to be set.Quoted 3 lines
If we have gone here, I think
rte_vhost_driver_get_features()should not return -1. The only exception is user unregistered such socket during the negotiation?Maybe this could never happen.
I just noticed thatrte_vhost_driver_get_features()can fail, and in that case, we wouldn't see it and the behavior could make hard the cause to be hard to spot.
Quoted 5 lines
As this is not in the hot code path, my view is that checking its return and print an error message does not hurt.
Or maybe we could directly do the error prints into rte_vhost_driver_*_features() functions if the socket name is not found?
Yes, I think we could do that. Thanks!
--yliu
PATCH 4/17 vhost: make notify ops per vhost driver
In reply to Yuanhan LiuAssume there is an application both support vhost-user net and vhost-user scsi, the callback should be different. Making notify ops per vhost driver allow application define different set of callbacks for different driver.
--- drivers/net/vhost/rte_eth_vhost.c | 20 +++++++++++--------- examples/tep_termination/main.c | 3 ++- examples/vhost/main.c | 5 +++-- lib/librte_vhost/rte_virtio_net.h | 3 ++- lib/librte_vhost/socket.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 16 +--------------- lib/librte_vhost/vhost.h | 5 ++++- lib/librte_vhost/vhost_user.c | 15 +++++++++------ 8 files changed, 64 insertions(+), 35 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +11 -9
@@ -667,6 +667,12 @@ struct vhost_xstats_name_off {return 0 ; } +static struct virtio_net_device_ops vhost_ops = { + .new_device = new_device, + .destroy_device = destroy_device, + .vring_state_changed = vring_state_changed, +}; +int rte_eth_vhost_get_queue_event (uint8_t port_id,struct rte_eth_vhost_queue_event *event)
@@ -736,15 +742,6 @@ struct vhost_xstats_name_off {static void * vhost_driver_session(void *param __rte_unused) { -static struct virtio_net_device_ops vhost_ops; - -/* set vhost arguments */ - vhost_ops.new_device = new_device; - vhost_ops.destroy_device = destroy_device; - vhost_ops.vring_state_changed = vring_state_changed; -if (rte_vhost_driver_callback_register (&vhost_ops) <0 ) -RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); -/* start event handling */ rte_vhost_driver_session_start ();
@@ -1077,6 +1074,11 @@ struct vhost_xstats_name_off {if (rte_vhost_driver_register (iface_name, flags)) goto error; +if (rte_vhost_driver_callback_register (iface_name, &vhost_ops) <0 ) { +RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); + goto error; + } +/* We need only one message handling thread */ if (rte_atomic16_add_return (&nb_started_ports,1 ) ==1 ) {if (vhost_driver_session_start ())
examples/tep_termination/main.c +2 -1
@@ -1258,7 +1258,8 @@ static inline void __attribute__((always_inline))rte_vhost_driver_disable_features (dev_basename,1ULL <<VIRTIO_NET_F_MRG_RXBUF ); -rte_vhost_driver_callback_register (&virtio_net_device_ops); +rte_vhost_driver_callback_register (dev_basename, + &virtio_net_device_ops);rte_vhost_driver_session_start ();
examples/vhost/main.c +3 -2
@@ -1538,9 +1538,10 @@ static inline void __attribute__((always_inline))rte_vhost_driver_enable_features (file,1ULL <<VIRTIO_NET_F_CTRL_RX ); } - } -rte_vhost_driver_callback_register (&virtio_net_device_ops); +rte_vhost_driver_callback_register (file, + &virtio_net_device_ops); + }rte_vhost_driver_session_start ();return 0 ;
lib/librte_vhost/rte_virtio_net.h +2 -1
@@ -91,7 +91,8 @@ struct virtio_net_device_ops {int rte_vhost_driver_disable_features (const char *path,uint64_t features);/* Register callbacks. */ -int rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ); +int rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const );/* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start (void );
lib/librte_vhost/socket.c +32 -0
@@ -73,6 +73,8 @@ struct vhost_user_socket {*/ uint64_t supported_features;uint64_t features; + +struct virtio_net_device_ops const *notify_ops; };struct vhost_user_connection {
@@ -718,6 +720,36 @@ struct vhost_user_reconnect_list {return -1 ; } +/* +* Register ops so that we can add/remove device to data core. +*/ +int +rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const ops) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +if (vsocket) + vsocket->notify_ops = ops; +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket ?0 :-1 ; +} + +struct virtio_net_device_ops const * +vhost_driver_callback_get (const char *path) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket->notify_ops; +} +int rte_vhost_driver_session_start (void ) {
lib/librte_vhost/vhost.c +1 -15
@@ -51,9 +51,6 @@struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ]; -/* device ops to add/remove device to/from data core. */ -struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device (int vid) {
@@ -253,7 +250,7 @@ struct virtio_net *if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (vid); + dev->notify_ops->destroy_device (vid); }cleanup_device (dev,1 );
@@ -377,14 +374,3 @@ struct virtio_net * dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ;return 0 ; } - -/* -* Register ops so that we can add/remove device to data core. -*/ -int -rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ops) -{ - notify_ops = ops; - -return 0 ; -}
lib/librte_vhost/vhost.h +4 -1
@@ -177,6 +177,8 @@ struct virtio_net {uint64_t log_addr;struct ether_addr mac; +struct virtio_net_device_ops const *notify_ops; +uint32_t nr_guest_pages;uint32_t max_guest_pages;struct guest_page *guest_pages;
@@ -280,7 +282,6 @@ static inline phys_addr_t __attribute__((always_inline))return 0 ; } -struct virtio_net_device_ops const *notify_ops;struct virtio_net *get_device (int vid);int vhost_new_device (void );
@@ -293,6 +294,8 @@ static inline phys_addr_t __attribute__((always_inline))void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid); +struct virtio_net_device_ops const *vhost_driver_callback_get (const char *path); +/* * Backend-specific cleanup. *
lib/librte_vhost/vhost_user.c +9 -6
@@ -131,7 +131,7 @@ {if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }cleanup_device (dev,0 );
@@ -499,7 +499,7 @@/* Remove from the data plane. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }if (dev->mem) {
@@ -680,7 +680,7 @@ "dequeue zero copy is enabled\n"); } -if (notify_ops->new_device (dev->vid) ==0 ) +if (dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; } }
@@ -713,7 +713,7 @@/* We have to stop the queue (virtio) if it is running. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }/* Here we are safe to get the last used index */
@@ -753,8 +753,8 @@"set queue enable: %d to qp idx: %d\n" , enable, state->index); -if (notify_ops->vring_state_changed) - notify_ops->vring_state_changed (dev->vid, state->index, enable); +if (dev->notify_ops->vring_state_changed) + dev->notify_ops->vring_state_changed (dev->vid, state->index, enable); dev->virtqueue[state->index]->enabled = enable;
@@ -952,6 +952,9 @@if (dev ==NULL )return -1 ; +if (!dev->notify_ops) + dev->notify_ops =vhost_driver_callback_get (dev->ifname); + ret =read_vhost_message (fd, &msg);if (ret <=0 || msg.request >=VHOST_USER_MAX ) {if (ret <0 )
Signature · 1 line
1.9.0
Re: [PATCH 04/17] vhost: make notify ops per vhost driver
Quoted 67 lines · Yuanhan Liu
Assume there is an application both support vhost-user net and vhost-user scsi, the callback should be different. Making notify ops per vhost driver allow application define different set of callbacks for different driver.
Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 20 +++++++++++--------- examples/tep_termination/main.c | 3 ++- examples/vhost/main.c | 5 +++-- lib/librte_vhost/rte_virtio_net.h | 3 ++- lib/librte_vhost/socket.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 16 +--------------- lib/librte_vhost/vhost.h | 5 ++++- lib/librte_vhost/vhost_user.c | 15 +++++++++------ 8 files changed, 64 insertions(+), 35 deletions(-)drivers/net/vhost/rte_eth_vhost.c +11
-9@@ -667,6 +667,12 @@ struct vhost_xstats_name_off {return 0 ; } +static struct virtio_net_device_ops vhost_ops = { + .new_device = new_device, + .destroy_device = destroy_device, + .vring_state_changed = vring_state_changed, +}; +int rte_eth_vhost_get_queue_event (uint8_t port_id,struct rte_eth_vhost_queue_event *event)@@ -736,15 +742,6 @@ struct vhost_xstats_name_off {static void * vhost_driver_session(void *param __rte_unused) { -static struct virtio_net_device_ops vhost_ops; - -/* set vhost arguments */ - vhost_ops.new_device = new_device; - vhost_ops.destroy_device = destroy_device; - vhost_ops.vring_state_changed = vring_state_changed; -if (rte_vhost_driver_callback_register (&vhost_ops) <0 ) -RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); -/* start event handling */ rte_vhost_driver_session_start ();@@ -1077,6 +1074,11 @@ struct vhost_xstats_name_off {if (rte_vhost_driver_register (iface_name, flags)) goto error; +if (rte_vhost_driver_callback_register (iface_name, &vhost_ops) <0 ) { +RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); + goto error; + } +/* We need only one message handling thread */ if (rte_atomic16_add_return (&nb_started_ports,1 ) ==1 ) {if (vhost_driver_session_start ())examples/tep_termination/main.c +0
-0
examples/tep_termination/main.c static inline void __attribute__((always_inline)) · line 1262
Quoted 6 lines
examples/tep_termination/main.c +2
-1@@ -1258,7 +1258,8 @@ static inline void __attribute__((always_inline))rte_vhost_driver_disable_features (dev_basename,1ULL <<VIRTIO_NET_F_MRG_RXBUF ); -rte_vhost_driver_callback_register (&virtio_net_device_ops); +rte_vhost_driver_callback_register (dev_basename, + &virtio_net_device_ops);
Return should be checked here, as this function can now return -1.
Quoted 8 lines
examples/tep_termination/main.c +0
-0rte_vhost_driver_session_start ();examples/vhost/main.c +0
-0
examples/vhost/main.c static inline void __attribute__((always_inline)) · line 1544
Quoted 9 lines
examples/vhost/main.c +3
-2@@ -1538,9 +1538,10 @@ static inline void __attribute__((always_inline))rte_vhost_driver_enable_features (file,1ULL <<VIRTIO_NET_F_CTRL_RX ); } - } -rte_vhost_driver_callback_register (&virtio_net_device_ops); +rte_vhost_driver_callback_register (file, + &virtio_net_device_ops); + }
Ditto.
Quoted 52 lines
examples/vhost/main.c +0
-0rte_vhost_driver_session_start ();return 0 ;lib/librte_vhost/rte_virtio_net.h +2
-1@@ -91,7 +91,8 @@ struct virtio_net_device_ops {int rte_vhost_driver_disable_features (const char *path,uint64_t features);/* Register callbacks. */ -int rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ); +int rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const );/* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start (void );lib/librte_vhost/socket.c +20
-0@@ -73,6 +73,8 @@ struct vhost_user_socket {*/ uint64_t supported_features;uint64_t features; + +struct virtio_net_device_ops const *notify_ops; };struct vhost_user_connection {@@ -718,6 +720,36 @@ struct vhost_user_reconnect_list {return -1 ; } +/* +* Register ops so that we can add/remove device to data core. +*/ +int +rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const ops) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +if (vsocket) + vsocket->notify_ops = ops; +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket ?0 :-1 ; +} +
lib/librte_vhost/socket.c struct vhost_user_reconnect_list { · line 750
Quoted 10 lines
lib/librte_vhost/socket.c +10
-0+struct virtio_net_device_ops const * +vhost_driver_callback_get (const char *path) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket->notify_ops;
There should be a check against vsocket to avoid NULL pointer dereferencing.
Quoted 125 lines
lib/librte_vhost/socket.c +2
-0+} +int rte_vhost_driver_session_start (void ) {lib/librte_vhost/vhost.c +1
-15@@ -51,9 +51,6 @@struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ]; -/* device ops to add/remove device to/from data core. */ -struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device (int vid) {@@ -253,7 +250,7 @@ struct virtio_net *if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (vid); + dev->notify_ops->destroy_device (vid); }cleanup_device (dev,1 );@@ -377,14 +374,3 @@ struct virtio_net * dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ;return 0 ; } - -/* -* Register ops so that we can add/remove device to data core. -*/ -int -rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ops) -{ - notify_ops = ops; - -return 0 ; -}lib/librte_vhost/vhost.h +4
-1@@ -177,6 +177,8 @@ struct virtio_net {uint64_t log_addr;struct ether_addr mac; +struct virtio_net_device_ops const *notify_ops; +uint32_t nr_guest_pages;uint32_t max_guest_pages;struct guest_page *guest_pages;@@ -280,7 +282,6 @@ static inline phys_addr_t __attribute__((always_inline))return 0 ; } -struct virtio_net_device_ops const *notify_ops;struct virtio_net *get_device (int vid);int vhost_new_device (void );@@ -293,6 +294,8 @@ static inline phys_addr_t __attribute__((always_inline))void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid); +struct virtio_net_device_ops const *vhost_driver_callback_get (const char *path); +/* * Backend-specific cleanup. * lib/librte_vhost/vhost_user.c +6
-6@@ -131,7 +131,7 @@ {if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }cleanup_device (dev,0 );@@ -499,7 +499,7 @@/* Remove from the data plane. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }if (dev->mem) {@@ -680,7 +680,7 @@ "dequeue zero copy is enabled\n"); } -if (notify_ops->new_device (dev->vid) ==0 ) +if (dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; } }@@ -713,7 +713,7 @@/* We have to stop the queue (virtio) if it is running. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }/* Here we are safe to get the last used index */ @@ -753,8 +753,8 @@"set queue enable: %d to qp idx: %d\n" , enable, state->index); -if (notify_ops->vring_state_changed) - notify_ops->vring_state_changed (dev->vid, state->index, enable); +if (dev->notify_ops->vring_state_changed) + dev->notify_ops->vring_state_changed (dev->vid, state->index, enable); dev->virtqueue[state->index]->enabled = enable;
lib/librte_vhost/vhost_user.c line 956
Quoted 5 lines
lib/librte_vhost/vhost_user.c +2
-0@@ -952,6 +952,9 @@if (dev ==NULL )return -1 ; +if (!dev->notify_ops) + dev->notify_ops =vhost_driver_callback_get (dev->ifname);
Once vhost_driver_callback_get() fixed, notify_ops can be NULL, and it seems to be dereferenced without being checked later on.
Quoted 5 lines
lib/librte_vhost/vhost_user.c +1
-0+ ret =read_vhost_message (fd, &msg);if (ret <=0 || msg.request >=VHOST_USER_MAX ) {if (ret <0 )
Re: [PATCH 04/17] vhost: make notify ops per vhost driver
Quoted 8 lines · Maxime Coquelin
Quoted 8 lines
examples/tep_termination/main.c +0
-0@@ -1258,7 +1258,8 @@ static inline void __attribute__((always_inline))rte_vhost_driver_disable_features (dev_basename,1ULL <<VIRTIO_NET_F_MRG_RXBUF );
Quoted 5 lines
examples/tep_termination/main.c static inline void __attribute__((always_inline)) · line 1262
Quoted 3 lines
examples/tep_termination/main.c +2
-1-rte_vhost_driver_callback_register (&virtio_net_device_ops); +rte_vhost_driver_callback_register (dev_basename, + &virtio_net_device_ops);Return should be checked here, as this function can now return -1.
Right.
Quoted 5 lines
Quoted 5 lines
examples/tep_termination/main.c +5
-0+struct virtio_net_device_ops const * +vhost_driver_callback_get (const char *path) +{ +struct vhost_user_socket *vsocket; +
Quoted 8 lines
examples/tep_termination/main.c
Quoted 5 lines
examples/tep_termination/main.c +5
-0+pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket->notify_ops;There should be a check against vsocket to avoid NULL pointer dereferencing.
Yes.
Quoted 9 lines
examples/tep_termination/main.c line 956
Quoted 6 lines
examples/tep_termination/main.c +2
-0@@ -952,6 +952,9 @@if (dev ==NULL )return -1 ; +if (!dev->notify_ops) + dev->notify_ops =vhost_driver_callback_get (dev->ifname);Once
vhost_driver_callback_get()fixed,notify_opscan be NULL, and it seems to be dereferenced without being checked later on.
Yes.
--yliu
PATCH 5/17 vhost: export guest memory regions
In reply to Yuanhan LiuSome vhost-user driver may need this info to setup its own page tables for GPA (guest physical addr) to HPA (host physical addr) translation. SPDK (Storage Performance Development Kit) is one example.
Besides, by exporting this memory info, we could also export the gpa_to_vva() as an inline function, which helps for performance. Otherwise, it has to be referenced indirectly by a "vid".
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 24 ++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 23 +++++++++++++++++++++++ lib/librte_vhost/vhost.h | 28 ++-------------------------- lib/librte_vhost/vhost_user.c | 12 ++++++------ 5 files changed, 56 insertions(+), 32 deletions(-)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -35,5 +35,6 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_get_vhost_memory; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +24 -0
@@ -59,6 +59,28 @@enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM };/** +* Information relating to memory regions including offsets to +* addresses in QEMUs memory file. +*/ +struct rte_vhost_mem_region { +uint64_t guest_phys_addr; +uint64_t guest_user_addr; +uint64_t host_user_addr; +uint64_t size; +void *mmap_addr; +uint64_t mmap_size; +int fd; +}; + +/** +* Memory structure includes region and mapping information. +*/ +struct rte_vhost_memory { +uint32_t nregions; +struct rte_vhost_mem_region regions[0 ]; +}; + +/** * Device and vring operations. */ struct virtio_net_device_ops {
@@ -187,4 +209,6 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count); +int rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem); +#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +23 -0
@@ -340,6 +340,29 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem) +{ +struct virtio_net *dev; +struct rte_vhost_memory *m; +size_t size; + + dev =get_device (vid); +if (!dev) +return -1 ; + + size = dev->mem->nregions *sizeof (struct rte_vhost_mem_region ); + m =malloc (size); +if (!m) +return -1 ; + + m->nregions = dev->mem->nregions; +memcpy (m->regions, dev->mem->regions, size); + *mem = m; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {
lib/librte_vhost/vhost.h +2 -26
@@ -159,7 +159,7 @@ struct guest_page {*/ struct virtio_net {/* Frontend (QEMU) memory and memory region information */ -struct virtio_memory *mem; +struct rte_vhost_memory *mem;uint64_t features;uint64_t protocol_features;int vid;
@@ -184,30 +184,6 @@ struct virtio_net {struct guest_page *guest_pages; } __rte_cache_aligned; -/** -* Information relating to memory regions including offsets to -* addresses in QEMUs memory file. -*/ -struct virtio_memory_region { -uint64_t guest_phys_addr; -uint64_t guest_user_addr; -uint64_t host_user_addr; -uint64_t size; -void *mmap_addr; -uint64_t mmap_size; -int fd; -}; - - -/** -* Memory structure includes region and mapping information. -*/ -struct virtio_memory { -uint32_t nregions; -struct virtio_memory_region regions[0 ]; -}; - -/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
@@ -247,7 +223,7 @@ struct virtio_memory {static inline uint64_t __attribute__((always_inline))gpa_to_vva (struct virtio_net *dev,uint64_t gpa) { -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;uint32_t i;for (i =0 ; i < dev->mem->nregions; i++) {
lib/librte_vhost/vhost_user.c +6 -6
@@ -88,7 +88,7 @@ free_mem_region(struct virtio_net *dev) {uint32_t i; -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;if (!dev || !dev->mem)return ;
@@ -300,7 +300,7 @@static uint64_t qva_to_vva (struct virtio_net *dev,uint64_t qva) { -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;uint32_t i;/* Find the region where the address lives. */
@@ -428,7 +428,7 @@ }static void -add_guest_pages (struct virtio_net *dev,struct virtio_memory_region *reg, +add_guest_pages (struct virtio_net *dev,struct rte_vhost_mem_region *reg,uint64_t page_size) {uint64_t reg_size = reg->size;
@@ -488,7 +488,7 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) { struct VhostUserMemory memory = pmsg->payload.memory; -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;void *mmap_addr;uint64_t mmap_size;uint64_t mmap_offset;
@@ -515,8 +515,8 @@ sizeof(struct guest_page)); } - dev->mem =rte_zmalloc ("vhost-mem-table" ,sizeof (struct virtio_memory ) + -sizeof (struct virtio_memory_region ) * memory.nregions,0 ); + dev->mem =rte_zmalloc ("vhost-mem-table" ,sizeof (struct rte_vhost_memory ) + +sizeof (struct rte_vhost_mem_region ) * memory.nregions,0 );if (dev->mem ==NULL ) { RTE_LOG(ERR, VHOST_CONFIG, "(%d) failed to allocate memory for dev->mem\n",
Signature · 1 line
1.9.0
Re: [PATCH 05/17] vhost: export guest memory regions
Quoted 89 lines · Yuanhan Liu
Some vhost-user driver may need this info to setup its own page tables for GPA (guest physical addr) to HPA (host physical addr) translation. SPDK (Storage Performance Development Kit) is one example.
Besides, by exporting this memory info, we could also export the
gpa_to_vva()as an inline function, which helps for performance. Otherwise, it has to be referenced indirectly by a "vid".Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 24 ++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 23 +++++++++++++++++++++++ lib/librte_vhost/vhost.h | 28 ++-------------------------- lib/librte_vhost/vhost_user.c | 12 ++++++------ 5 files changed, 56 insertions(+), 32 deletions(-)lib/librte_vhost/rte_vhost_version.map +1
-0@@ -35,5 +35,6 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_get_vhost_memory; } DPDK_16.07;lib/librte_vhost/rte_virtio_net.h +24
-0@@ -59,6 +59,28 @@enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM };/** +* Information relating to memory regions including offsets to +* addresses in QEMUs memory file. +*/ +struct rte_vhost_mem_region { +uint64_t guest_phys_addr; +uint64_t guest_user_addr; +uint64_t host_user_addr; +uint64_t size; +void *mmap_addr; +uint64_t mmap_size; +int fd; +}; + +/** +* Memory structure includes region and mapping information. +*/ +struct rte_vhost_memory { +uint32_t nregions; +struct rte_vhost_mem_region regions[0 ]; +}; + +/** * Device and vring operations. */ struct virtio_net_device_ops {@@ -187,4 +209,6 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count); +int rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem); +#endif /* _VIRTIO_NET_H_ */ lib/librte_vhost/vhost.c +13
-0@@ -340,6 +340,29 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem) +{ +struct virtio_net *dev; +struct rte_vhost_memory *m; +size_t size; + + dev =get_device (vid); +if (!dev) +return -1 ; + + size = dev->mem->nregions *sizeof (struct rte_vhost_mem_region ); + m =malloc (size);
lib/librte_vhost/vhost.c struct virtio_net * · line 365
Quoted 10 lines
lib/librte_vhost/vhost.c +10
-0+if (!m) +return -1 ; + + m->nregions = dev->mem->nregions; +memcpy (m->regions, dev->mem->regions, size); + *mem = m; + +return 0 ; +} +
Might worth to be documented, as API.
Other than that:
Thanks,
Maxime
PATCH 6/17 vhost: introduce API to fetch negotiated features
In reply to Yuanhan Liu--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 1 + lib/librte_vhost/vhost.c | 12 ++++++++++++ 3 files changed, 14 insertions(+)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -35,6 +35,7 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +1 -0
@@ -210,5 +210,6 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id, struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);int rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem); +uint64_t rte_vhost_get_negotiated_features (int vid);#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +12 -0
@@ -340,6 +340,18 @@ struct virtio_net *return 0 ; } +uint64_t +rte_vhost_get_negotiated_features (int vid) +{ +struct virtio_net *dev; + + dev =get_device (vid); +if (!dev) +return -1 ; + +return dev->features; +} +int rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem) {
Signature · 1 line
1.9.0
Re: [PATCH 06/17] vhost: introduce API to fetch negotiated features
Quoted 39 lines · Yuanhan Liu
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 1 + lib/librte_vhost/vhost.c | 12 ++++++++++++ 3 files changed, 14 insertions(+)lib/librte_vhost/rte_vhost_version.map +1
-0@@ -35,6 +35,7 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; } DPDK_16.07;lib/librte_vhost/rte_virtio_net.h +1
-0@@ -210,5 +210,6 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id, struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);int rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem); +uint64_t rte_vhost_get_negotiated_features (int vid);#endif /* _VIRTIO_NET_H_ */ lib/librte_vhost/vhost.c +1
-0@@ -340,6 +340,18 @@ struct virtio_net *return 0 ; } +uint64_t
lib/librte_vhost/vhost.c struct virtio_net * · line 353
Quoted 10 lines
lib/librte_vhost/vhost.c +10
-0+rte_vhost_get_negotiated_features(int vid) +{ +struct virtio_net *dev; + + dev =get_device (vid); +if (!dev) +return -1 ; + +return dev->features; +}
Are we sure the negotiation is done when we can get the device?
Maxime
Re: [PATCH 06/17] vhost: introduce API to fetch negotiated features
Quoted 4 lines · Maxime Coquelin
Quoted 4 lines
lib/librte_vhost/vhost.c +4
-0+uint64_t +rte_vhost_get_negotiated_features (int vid) +{ +struct virtio_net *dev;
Quoted 8 lines
lib/librte_vhost/vhost.c struct virtio_net * · line 353
Quoted 7 lines
lib/librte_vhost/vhost.c +7
-0+ + dev =get_device (vid); +if (!dev) +return -1 ; + +return dev->features; +}Are we sure the negotiation is done when we can get the device?
Yes. However, one thing worth noting is that the features may change after the new_device() callback. Notablely, when live migration starts /ends, the VHOST_F_LOG_ALL will be set/cleared, respectively.
Quoted 1 line
From that point of view, we need a new callback, something like
features_changed(), or live_migration_starts()? Or a better name?
--yliu
Re: [PATCH 06/17] vhost: introduce API to fetch negotiated features
Quoted 14 lines · Yuanhan Liu
Quoted 4 lines · Maxime Coquelin
Quoted 4 lines
lib/librte_vhost/vhost.c +4
-0+uint64_t +rte_vhost_get_negotiated_features (int vid) +{ +struct virtio_net *dev;Quoted 8 lines
lib/librte_vhost/vhost.c struct virtio_net * · line 353
Quoted 7 lines
lib/librte_vhost/vhost.c +7
-0+ + dev =get_device (vid); +if (!dev) +return -1 ; + +return dev->features; +}Are we sure the negotiation is done when we can get the device?
Quoted 3 lines
Yes. However, one thing worth noting is that the features may change after the
new_device()callback. Notablely, when live migration starts /ends, theVHOST_F_LOG_ALLwill be set/cleared, respectively.
Good point.
Quoted 2 lines
From that point of view, we need a new callback, something like
features_changed(), orlive_migration_starts()? Or a better name?
I would name it features_changed() to be future-proof (even if I don't foresee other cases than live migration right now).
Thanks,
Maxime
Re: [PATCH 06/17] vhost: introduce API to fetch negotiated features
Quoted 21 lines · Maxime Coquelin
Quoted 14 lines · Yuanhan Liu
Quoted 4 lines · Maxime Coquelin
Quoted 4 lines
lib/librte_vhost/vhost.c +4
-0+uint64_t +rte_vhost_get_negotiated_features (int vid) +{ +struct virtio_net *dev;Quoted 8 lines
lib/librte_vhost/vhost.c struct virtio_net * · line 353
Quoted 7 lines
lib/librte_vhost/vhost.c +7
-0+ + dev =get_device (vid); +if (!dev) +return -1 ; + +return dev->features; +}Are we sure the negotiation is done when we can get the device?
Quoted 3 lines
Yes. However, one thing worth noting is that the features may change after the
new_device()callback. Notablely, when live migration starts /ends, theVHOST_F_LOG_ALLwill be set/cleared, respectively.
Quoted 7 lines
Good point.
Quoted 2 lines
From that point of view, we need a new callback, something like
features_changed(), orlive_migration_starts()? Or a better name?I would name it
features_changed()to be future-proof (even if I don't foresee other cases than live migration right now).
Right, it will be "features_changed()" then.
--yliu
PATCH 7/17 vhost: export vhost vring info
In reply to Yuanhan Liu--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 13 +++++++++++++ lib/librte_vhost/vhost.c | 30 ++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 2 ++ 4 files changed, 46 insertions(+)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -37,5 +37,6 @@ DPDK_17.05 { rte_vhost_driver_set_features; rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; + rte_vhost_get_vhost_vring; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +13 -0
@@ -80,6 +80,17 @@ struct rte_vhost_memory {struct rte_vhost_mem_region regions[0 ]; }; +struct rte_vhost_vring { +struct vring_desc *desc; +struct vring_avail *avail; +struct vring_used *used; +uint64_t log_guest_addr; + +int callfd; +int kickfd; +uint16_t size; +}; +/** * Device and vring operations. */
@@ -211,5 +222,7 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,int rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem);uint64_t rte_vhost_get_negotiated_features (int vid); +int rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring);#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +30 -0
@@ -375,6 +375,36 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring) +{ +struct virtio_net *dev; +struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (!dev) +return -1 ; + +if (vring_idx >VHOST_MAX_VRING ) +return -1 ; + + vq = dev->virtqueue[vring_idx]; +if (!vq) +return -1 ; + + vring->desc = vq->desc; + vring->avail = vq->avail; + vring->used = vq->used; + vring->log_guest_addr = vq->log_guest_addr; + + vring->callfd = vq->callfd; + vring->kickfd = vq->kickfd; + vring->size = vq->size; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {
lib/librte_vhost/vhost.h +2 -0
@@ -138,6 +138,8 @@ struct vhost_virtqueue {#ifndef VIRTIO_NET_F_MQ #define VIRTIO_NET_F_MQ 22#endif + +#define VHOST_MAX_VRING 0x100#define VHOST_MAX_QUEUE_PAIRS 0x80/*
Signature · 1 line
1.9.0
Re: [PATCH 07/17] vhost: export vhost vring info
Quoted 59 lines · Yuanhan Liu
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 13 +++++++++++++ lib/librte_vhost/vhost.c | 30 ++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 2 ++ 4 files changed, 46 insertions(+)lib/librte_vhost/rte_vhost_version.map +1
-0@@ -37,5 +37,6 @@ DPDK_17.05 { rte_vhost_driver_set_features; rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; + rte_vhost_get_vhost_vring; } DPDK_16.07;lib/librte_vhost/rte_virtio_net.h +13
-0@@ -80,6 +80,17 @@ struct rte_vhost_memory {struct rte_vhost_mem_region regions[0 ]; }; +struct rte_vhost_vring { +struct vring_desc *desc; +struct vring_avail *avail; +struct vring_used *used; +uint64_t log_guest_addr; + +int callfd; +int kickfd; +uint16_t size; +}; +/** * Device and vring operations. */ @@ -211,5 +222,7 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,int rte_vhost_get_vhost_memory (int vid,struct rte_vhost_memory **mem);uint64_t rte_vhost_get_negotiated_features (int vid); +int rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring);#endif /* _VIRTIO_NET_H_ */ lib/librte_vhost/vhost.c +2
-0@@ -375,6 +375,36 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
lib/librte_vhost/vhost.c struct virtio_net * · line 389
Quoted 10 lines
lib/librte_vhost/vhost.c +10
-0+ struct rte_vhost_vring *vring) +{ +struct virtio_net *dev; +struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (!dev) +return -1 ; + +if (vring_idx >VHOST_MAX_VRING )
Shouldn't be ">=" ?
Quoted 26 lines
lib/librte_vhost/vhost.c +18
-0+return -1 ; + + vq = dev->virtqueue[vring_idx]; +if (!vq) +return -1 ; + + vring->desc = vq->desc; + vring->avail = vq->avail; + vring->used = vq->used; + vring->log_guest_addr = vq->log_guest_addr; + + vring->callfd = vq->callfd; + vring->kickfd = vq->kickfd; + vring->size = vq->size; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {lib/librte_vhost/vhost.h +0
-0
lib/librte_vhost/vhost.h struct vhost_virtqueue { · line 142
Quoted 5 lines
lib/librte_vhost/vhost.h +2
-0@@ -138,6 +138,8 @@ struct vhost_virtqueue {#ifndef VIRTIO_NET_F_MQ #define VIRTIO_NET_F_MQ 22#endif + +#define VHOST_MAX_VRING 0x100
Looking at the code, I'm not clear where this limitation comes from. It seems that it can be up to 0x10000, no?
struct virtio_net {
...
struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
with:
#ifdef VIRTIO_NET_F_MQ
#define VHOST_MAX_QUEUE_PAIRS VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
#define VHOST_SUPPORTS_MQ (1ULL << VIRTIO_NET_F_MQ)
#else
#define VHOST_MAX_QUEUE_PAIRS 1
#define VHOST_SUPPORTS_MQ 0
#endif
and:
#define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000
Regards,
Maxime
Re: [PATCH 07/17] vhost: export vhost vring info
Quoted 5 lines · Maxime Coquelin
Quoted 5 lines
lib/librte_vhost/vhost.c +5
-0+int +rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring) +{ +struct virtio_net *dev;
Quoted 8 lines
lib/librte_vhost/vhost.c struct virtio_net * · line 389
Quoted 7 lines
lib/librte_vhost/vhost.c +7
-0+struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (!dev) +return -1 ; + +if (vring_idx >VHOST_MAX_VRING )Shouldn't be ">=" ?
Nice catch!
Quoted 3 lines
Quoted 1 line
+#define
VHOST_MAX_VRING0x100Looking at the code, I'm not clear where this limitation comes from. It seems that it can be up to
0x10000, no?
It comes from the vhost-user spec:
--yliu
---
* VHOST_USER_SET_VRING_KICK
Id: 12
Equivalent ioctl: VHOST_SET_VRING_KICK
Master payload: u64
Set the event file descriptor for adding buffers to the vring. It is passed in the ancillary data.
Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. This signals that polling should be used instead of waiting for a kick.
Quoted 20 lines
struct
virtio_net{
...struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];with:
#ifdefVIRTIO_NET_F_MQ
#defineVHOST_MAX_QUEUE_PAIRSVIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
#defineVHOST_SUPPORTS_MQ(1ULL <<VIRTIO_NET_F_MQ)
#else
#defineVHOST_MAX_QUEUE_PAIRS1
#defineVHOST_SUPPORTS_MQ0
#endifand:
#defineVIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX0x8000Regards,
Maxime
Maxime Coquelin
Reviewed-byRe: [PATCH 07/17] vhost: export vhost vring info
Quoted 32 lines · Yuanhan Liu
Quoted 5 lines · Maxime Coquelin
Quoted 5 lines
lib/librte_vhost/vhost.c +5
-0+int +rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring) +{ +struct virtio_net *dev;Quoted 8 lines
lib/librte_vhost/vhost.c struct virtio_net * · line 389
Quoted 7 lines
lib/librte_vhost/vhost.c +7
-0+struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (!dev) +return -1 ; + +if (vring_idx >VHOST_MAX_VRING )Shouldn't be ">=" ?
Nice catch!
Quoted 3 lines
Quoted 1 line
+#define
VHOST_MAX_VRING0x100Looking at the code, I'm not clear where this limitation comes from. It seems that it can be up to
0x10000, no?It comes from the vhost-user spec:
--yliu---
*VHOST_USER_SET_VRING_KICKId: 12
Equivalent ioctl:VHOST_SET_VRING_KICK
Master payload: u64
Quoted 6 lines
Set the event file descriptor for adding buffers to the vring. It is passed in the ancillary data.
Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. This signals that polling should be used instead of waiting for a kick.
Thanks for the pointer.
With the vring_idx check fixed you can add my:
Cheers,
Maxime
PATCH 8/17 vhost: export API to translate gpa to vva
In reply to Yuanhan Liu--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 21 +++++++++++++++++++++ lib/librte_vhost/vhost.h | 19 ------------------- lib/librte_vhost/virtio_net.c | 23 +++++++++++++---------- 4 files changed, 35 insertions(+), 29 deletions(-)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -38,5 +38,6 @@ DPDK_17.05 { rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; rte_vhost_get_vhost_vring; + rte_vhost_gpa_to_vva; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +21 -0
@@ -103,6 +103,27 @@ struct virtio_net_device_ops {void *reserved[5 ];/**< Reserved for future extension */ }; +/** +* Convert guest physical Address to host virtual address +*/ +static inline uint64_t __attribute__((always_inline)) +rte_vhost_gpa_to_vva (struct rte_vhost_memory *mem,uint64_t gpa) +{ +struct rte_vhost_mem_region *reg; +uint32_t i; + +for (i =0 ; i < mem->nregions; i++) { + reg = &mem->regions[i]; +if (gpa >= reg->guest_phys_addr && + gpa < reg->guest_phys_addr + reg->size) { +return gpa - reg->guest_phys_addr + + reg->host_user_addr; + } + } + +return 0 ; +} +int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/**
lib/librte_vhost/vhost.h +0 -19
@@ -221,25 +221,6 @@ struct virtio_net {#define MAX_VHOST_DEVICE 1024extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ]; -/* Convert guest physical Address to host virtual address */ -static inline uint64_t __attribute__((always_inline)) -gpa_to_vva (struct virtio_net *dev,uint64_t gpa) -{ -struct rte_vhost_mem_region *reg; -uint32_t i; - -for (i =0 ; i < dev->mem->nregions; i++) { - reg = &dev->mem->regions[i]; -if (gpa >= reg->guest_phys_addr && - gpa < reg->guest_phys_addr + reg->size) { -return gpa - reg->guest_phys_addr + - reg->host_user_addr; - } - } - -return 0 ; -} -/* Convert guest physical address to host physical address */ static inline phys_addr_t __attribute__((always_inline))gpa_to_hpa (struct virtio_net *dev,uint64_t gpa,uint64_t size)
lib/librte_vhost/virtio_net.c +13 -10
@@ -199,7 +199,7 @@ static inline int __attribute__((always_inline))uint16_t nr_desc =1 ; desc = &descs[desc_idx]; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);/* * Checking of 'desc_addr' placed outside of 'unlikely' macro to avoid * performance issue with some versions of gcc (4.8.4 and 5.3.0) which
@@ -239,7 +239,7 @@ static inline int __attribute__((always_inline))return -1 ; desc = &descs[desc->next]; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -323,7 +323,8 @@ static inline uint32_t __attribute__((always_inline))int err;if (vq->desc[desc_idx].flags &VRING_DESC_F_INDIRECT ) { - descs = (struct vring_desc *)(uintptr_t )gpa_to_vva (dev, + descs = (struct vring_desc *)(uintptr_t ) +rte_vhost_gpa_to_vva (dev->mem, vq->desc[desc_idx].addr);if (unlikely (!descs)) { count = i;
@@ -383,7 +384,7 @@ static inline int __attribute__((always_inline))if (vq->desc[idx].flags &VRING_DESC_F_INDIRECT ) { descs = (struct vring_desc *)(uintptr_t ) -gpa_to_vva (dev, vq->desc[idx].addr); +rte_vhost_gpa_to_vva (dev->mem, vq->desc[idx].addr);if (unlikely (!descs))return -1 ;
@@ -473,7 +474,7 @@ static inline int __attribute__((always_inline))if (unlikely (m ==NULL ))return -1 ; - desc_addr =gpa_to_vva (dev, buf_vec[vec_idx].buf_addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, buf_vec[vec_idx].buf_addr);if (buf_vec[vec_idx].buf_len < dev->vhost_hlen || !desc_addr)return -1 ;
@@ -495,7 +496,8 @@ static inline int __attribute__((always_inline))/* done with current desc buf, get the next one */ if (desc_avail ==0 ) { vec_idx++; - desc_addr =gpa_to_vva (dev, buf_vec[vec_idx].buf_addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, + buf_vec[vec_idx].buf_addr);if (unlikely (!desc_addr))return -1 ;
@@ -798,7 +800,7 @@ static inline int __attribute__((always_inline)) (desc->flags & VRING_DESC_F_INDIRECT))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -818,7 +820,7 @@ static inline int __attribute__((always_inline))if (unlikely (desc->flags &VRING_DESC_F_INDIRECT ))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -882,7 +884,7 @@ static inline int __attribute__((always_inline))if (unlikely (desc->flags &VRING_DESC_F_INDIRECT ))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -1113,7 +1115,8 @@ static inline bool __attribute__((always_inline))rte_prefetch0 (&vq->desc[desc_indexes[i +1 ]]);if (vq->desc[desc_indexes[i]].flags &VRING_DESC_F_INDIRECT ) { - desc = (struct vring_desc *)(uintptr_t )gpa_to_vva (dev, + desc = (struct vring_desc *)(uintptr_t ) +rte_vhost_gpa_to_vva (dev->mem, vq->desc[desc_indexes[i]].addr);if (unlikely (!desc))break ;
Signature · 1 line
1.9.0
Re: [PATCH 08/17] vhost: export API to translate gpa to vva
Quoted 8 lines · Yuanhan Liu
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 21 +++++++++++++++++++++ lib/librte_vhost/vhost.h | 19 ------------------- lib/librte_vhost/virtio_net.c | 23 +++++++++++++---------- 4 files changed, 35 insertions(+), 29 deletions(-)
Same remark as previous patches, the API should be documented. Other than that:
Thanks,
Maxime
PATCH 9/17 vhost: turn queue pair to vring
In reply to Yuanhan LiuThe queue pair is very virtio-net specific, other devices don't have such concept. To make it generic, we should log the number of vrings instead of the number of queue pairs.
This patch just does a simple convert, a later patch would export the number of vrings to applications.
--- lib/librte_vhost/vhost.c | 74 ++++++++++++++----------------------------- lib/librte_vhost/vhost.h | 4 +-- lib/librte_vhost/vhost_user.c | 28 +++++----------- lib/librte_vhost/virtio_net.c | 10 +++--- 4 files changed, 38 insertions(+), 78 deletions(-)
lib/librte_vhost/vhost.c +23 -51
@@ -84,10 +84,8 @@ struct virtio_net *vhost_backend_cleanup (dev); -for (i =0 ; i < dev->virt_qp_nb; i++) { -cleanup_vq (dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ], destroy); -cleanup_vq (dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ], destroy); - } +for (i =0 ; i < dev->nr_vring; i++) +cleanup_vq (dev->virtqueue[i], destroy); }/*
@@ -97,24 +95,21 @@ struct virtio_net * free_device(struct virtio_net *dev) {uint32_t i; -struct vhost_virtqueue *rxq, *txq; +struct vhost_virtqueue *vq; -for (i =0 ; i < dev->virt_qp_nb; i++) { - rxq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ]; - txq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ]; +for (i =0 ; i < dev->nr_vring; i++) { + vq = dev->virtqueue[i]; -rte_free (rxq->shadow_used_ring); -rte_free (txq->shadow_used_ring); +rte_free (vq->shadow_used_ring); -/* rxq and txq are allocated together as queue-pair */ -rte_free (rxq); +rte_free (vq); }rte_free (dev); }static void -init_vring_queue (struct vhost_virtqueue *vq,int qp_idx) +init_vring_queue (struct vhost_virtqueue *vq,int vring_idx) {memset (vq,0 ,sizeof (struct vhost_virtqueue ));
@@ -125,68 +120,45 @@ struct virtio_net * vq->backend =-1 ;/* always set the default vq pair to enabled */ -if (qp_idx ==0 ) +if (vring_idx /2 ==0 ) vq->enabled =1 ;TAILQ_INIT (&vq->zmbuf_list); }static void -init_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) -{ -uint32_t base_idx = qp_idx *VIRTIO_QNUM ; - -init_vring_queue (dev->virtqueue[base_idx +VIRTIO_RXQ ], qp_idx); -init_vring_queue (dev->virtqueue[base_idx +VIRTIO_TXQ ], qp_idx); -} - -static void -reset_vring_queue (struct vhost_virtqueue *vq,int qp_idx) +reset_vring_queue (struct vhost_virtqueue *vq,int vring_idx) {int callfd; callfd = vq->callfd; -init_vring_queue (vq, qp_idx); +init_vring_queue (vq, vring_idx); vq->callfd = callfd; } -static void -reset_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) -{ -uint32_t base_idx = qp_idx *VIRTIO_QNUM ; - -reset_vring_queue (dev->virtqueue[base_idx +VIRTIO_RXQ ], qp_idx); -reset_vring_queue (dev->virtqueue[base_idx +VIRTIO_TXQ ], qp_idx); -} -int -alloc_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) +alloc_vring_queue (struct virtio_net *dev,uint32_t vring_idx) { -struct vhost_virtqueue *virtqueue =NULL ; -uint32_t virt_rx_q_idx = qp_idx *VIRTIO_QNUM +VIRTIO_RXQ ; -uint32_t virt_tx_q_idx = qp_idx *VIRTIO_QNUM +VIRTIO_TXQ ; +struct vhost_virtqueue *vq; - virtqueue =rte_malloc (NULL , -sizeof (struct vhost_virtqueue ) *VIRTIO_QNUM ,0 ); -if (virtqueue ==NULL ) { + vq =rte_malloc (NULL ,sizeof (struct vhost_virtqueue ),0 ); +if (vq ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"Failed to allocate memory for virt qp:%d.\n" , qp_idx); +"Failed to allocate memory for vring:%u.\n" , vring_idx);return -1 ; } - dev->virtqueue[virt_rx_q_idx] = virtqueue; - dev->virtqueue[virt_tx_q_idx] = virtqueue +VIRTIO_TXQ ; - -init_vring_queue_pair (dev, qp_idx); + dev->virtqueue[vring_idx] = vq; +init_vring_queue (vq, vring_idx); - dev->virt_qp_nb +=1 ; + dev->nr_vring +=1 ;return 0 ; }/* * Reset some variables in device structure, while keeping few -* others untouched, such as vid, ifname, virt_qp_nb: they +* others untouched, such as vid, ifname, nr_vring: they * should be same unless the device is removed. */ void
@@ -198,8 +170,8 @@ struct virtio_net * dev->protocol_features =0 ; dev->flags =0 ; -for (i =0 ; i < dev->virt_qp_nb; i++) -reset_vring_queue_pair (dev, i); +for (i =0 ; i < dev->nr_vring; i++) +reset_vring_queue (dev->virtqueue[i], i); }/*
@@ -321,7 +293,7 @@ struct virtio_net *if (dev ==NULL )return 0 ; -return dev->virt_qp_nb; +return dev->nr_vring /2 ; }int
lib/librte_vhost/vhost.h +2 -2
@@ -169,7 +169,7 @@ struct virtio_net {uint16_t vhost_hlen;/* to tell if we need broadcast rarp packet */ rte_atomic16_t broadcast_rarp; -uint32_t virt_qp_nb; +uint32_t nr_vring;int dequeue_zero_copy;struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ];#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
@@ -248,7 +248,7 @@ static inline phys_addr_t __attribute__((always_inline))void reset_device (struct virtio_net *dev);void vhost_destroy_device (int ); -int alloc_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx); +int alloc_vring_queue (struct virtio_net *dev,uint32_t vring_idx);void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid);
lib/librte_vhost/vhost_user.c +8 -20
@@ -223,13 +223,6 @@struct vhost_virtqueue *old_vq, *vq;int ret; -/* -* vq is allocated on pairs, we should try to do realloc -* on first queue of one queue pair only. -*/ -if (index %VIRTIO_QNUM !=0 ) -return dev; - old_dev = dev; vq = old_vq = dev->virtqueue[index];
@@ -247,8 +240,7 @@if (oldnode != newnode) {RTE_LOG (INFO ,VHOST_CONFIG ,"reallocate vq from %d to %d node\n" , oldnode, newnode); - vq =rte_malloc_socket (NULL ,sizeof (*vq) *VIRTIO_QNUM ,0 , - newnode); + vq =rte_malloc_socket (NULL ,sizeof (*vq),0 , newnode);if (!vq)return dev;
@@ -280,7 +272,6 @@ out: dev->virtqueue[index] = vq; - dev->virtqueue[index +1 ] = vq +1 ; vhost_devices[dev->vid] = dev;return dev;
@@ -611,14 +602,13 @@static int virtio_is_ready (struct virtio_net *dev) { -struct vhost_virtqueue *rvq, *tvq; +struct vhost_virtqueue *vq;uint32_t i; -for (i =0 ; i < dev->virt_qp_nb; i++) { - rvq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ]; - tvq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ]; +for (i =0 ; i < dev->nr_vring; i++) { + vq = dev->virtqueue[i]; -if (!vq_is_ready (rvq) || !vq_is_ready (tvq)) { +if (!vq_is_ready (vq)) {RTE_LOG (INFO ,VHOST_CONFIG ,"virtio is not ready for processing.\n" );return 0 ;
@@ -908,7 +898,6 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg) { uint16_t vring_idx; -uint16_t qp_idx;switch (msg->request) {case VHOST_USER_SET_VRING_KICK :
@@ -928,17 +917,16 @@return 0 ; } - qp_idx = vring_idx /VIRTIO_QNUM ; -if (qp_idx >=VHOST_MAX_QUEUE_PAIRS ) { +if (vring_idx >=VHOST_MAX_VRING ) {RTE_LOG (ERR ,VHOST_CONFIG ,"invalid vring index: %u\n" , vring_idx);return -1 ; } -if (dev->virtqueue[qp_idx]) +if (dev->virtqueue[vring_idx])return 0 ; -return alloc_vring_queue_pair (dev, qp_idx); +return alloc_vring_queue (dev, vring_idx); }int
lib/librte_vhost/virtio_net.c +5 -5
@@ -86,9 +86,9 @@ static inline void __attribute__((always_inline)) }static bool -is_valid_virt_queue_idx (uint32_t idx,int is_tx,uint32_t qp_nb) +is_valid_virt_queue_idx (uint32_t idx,int is_tx,uint32_t nr_vring) { -return (is_tx ^ (idx &1 )) ==0 && idx < qp_nb *VIRTIO_QNUM ; +return (is_tx ^ (idx &1 )) ==0 && idx < nr_vring; } static inline void __attribute__((always_inline))
@@ -283,7 +283,7 @@ static inline uint32_t __attribute__((always_inline))uint32_t i, sz;LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__); -if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
@@ -554,7 +554,7 @@ static inline uint32_t __attribute__((always_inline))uint16_t avail_head;LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__); -if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
@@ -1019,7 +1019,7 @@ static inline bool __attribute__((always_inline))if (!dev)return 0 ; -if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
Signature · 1 line
1.9.0
Re: [PATCH 09/17] vhost: turn queue pair to vring
Quoted 7 lines · Yuanhan Liu
The queue pair is very virtio-net specific, other devices don't have such concept. To make it generic, we should log the number of vrings instead of the number of queue pairs.
This patch just does a simple convert, a later patch would export the number of vrings to applications.
Quoted 8 lines
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/vhost.c | 74 ++++++++++++++----------------------------- lib/librte_vhost/vhost.h | 4 +-- lib/librte_vhost/vhost_user.c | 28 +++++----------- lib/librte_vhost/virtio_net.c | 10 +++--- 4 files changed, 38 insertions(+), 78 deletions(-)
Nice. Making it generic simplifies the net specific code.
Thanks,
Maxime
PATCH 10/17 vhost: export the number of vrings
In reply to Yuanhan LiuWe used to use rte_vhost_get_queue_num() for telling how many vrings. However, the return value is the number of "queue pairs", which is very virtio-net specific. To make it generic, we should return the number of vrings instead, and let the driver do the proper translation. Say, virtio-net driver could turn it to the number of queue pairs by dividing 2.
Meanwhile, mark rte_vhost_get_queue_num as deprecated.
--- drivers/net/vhost/rte_eth_vhost.c | 2 +- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 17 +++++++++++++++++ lib/librte_vhost/vhost.c | 11 +++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-)
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -569,7 +569,7 @@ struct vhost_xstats_name_off { vq->port = eth_dev->data->port_id; } -for (i =0 ; i <rte_vhost_get_queue_num (vid) *VIRTIO_QNUM ; i++) +for (i =0 ; i <rte_vhost_get_vring_num (vid); i++)rte_vhost_enable_guest_notification (vid, i,0 ); eth_dev->data->dev_link.link_status =ETH_LINK_UP ;
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -38,6 +38,7 @@ DPDK_17.05 { rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; rte_vhost_get_vhost_vring; + rte_vhost_get_vring_num; rte_vhost_gpa_to_vva; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +17 -0
@@ -163,17 +163,34 @@ int rte_vhost_driver_callback_register(const char *path,int rte_vhost_get_numa_node (int vid);/** +* @deprecated * Get the number of queues the device supports. * +* Note this function is deprecated, as it returns a queue pair number, +* which is virtio-net specific. Instead, rte_vhost_get_vring_num should +* be used. +* * @param vid * virtio-net device ID * * @return * The number of queues, 0 on failure */ +__rte_deprecated uint32_t rte_vhost_get_queue_num(int vid);/** +* Get the number of vrings the device supports. +* +* @param vid +* vhost device ID +* +* @return +* The number of vrings, 0 on failure +*/ +uint16_t rte_vhost_get_vring_num (int vid); + +/** * Get the virtio net device's ifname, which is the vhost-user socket * file path. *
lib/librte_vhost/vhost.c +11 -0
@@ -296,6 +296,17 @@ struct virtio_net *return dev->nr_vring /2 ; } +uint16_t +rte_vhost_get_vring_num (int vid) +{ +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return 0 ; + +return dev->nr_vring; +} +int rte_vhost_get_ifname (int vid,char *buf,size_t len) {
Signature · 1 line
1.9.0
Re: [PATCH 10/17] vhost: export the number of vrings
Quoted 9 lines · Yuanhan Liu
We used to use
rte_vhost_get_queue_num()for telling how many vrings. However, the return value is the number of "queue pairs", which is very virtio-net specific. To make it generic, we should return the number of vrings instead, and let the driver do the proper translation. Say, virtio-net driver could turn it to the number of queue pairs by dividing 2.Meanwhile, mark
rte_vhost_get_queue_numas deprecated.
Quoted 7 lines
Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 2 +- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 17 +++++++++++++++++ lib/librte_vhost/vhost.c | 11 +++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-)
Thanks,
Maxime
PATCH 11/17 vhost: move the device ready check at proper place
In reply to Yuanhan LiuCurrently, we check vq->desc, vq->kickfd and vq->callfd to know whether a virtio device is ready or not. However, we only do it when handling SET_VRING_KICK message, which could be wrong if a vhost-user frontend send SET_VRING_KICK first and SET_VRING_CALL later.
To work for all possible vhost-user frontend implementations, we could move the ready check at the end of vhost-user message handler.
Meanwhile, since we do the check more often than before, the "virtio not ready" message is dropped, to not flood the screen.
--- lib/librte_vhost/vhost_user.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
lib/librte_vhost/vhost_user.c +14 -18
@@ -605,14 +605,14 @@struct vhost_virtqueue *vq;uint32_t i; +if (dev->nr_vring ==0 ) +return 0 ; +for (i =0 ; i < dev->nr_vring; i++) { vq = dev->virtqueue[i]; -if (!vq_is_ready (vq)) { -RTE_LOG (INFO ,VHOST_CONFIG , -"virtio is not ready for processing.\n" ); +if (!vq_is_ready (vq))return 0 ; - } } RTE_LOG(INFO, VHOST_CONFIG,
@@ -641,10 +641,6 @@ vq->callfd = file.fd; } -/* -* In vhost-user, when we receive kick message, will test whether virtio -* device is ready for packet processing. -*/ static void vhost_user_set_vring_kick (struct virtio_net *dev,struct VhostUserMsg *pmsg) {
@@ -663,16 +659,6 @@if (vq->kickfd >=0 )close (vq->kickfd); vq->kickfd = file.fd; - -if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) { -if (dev->dequeue_zero_copy) { -RTE_LOG (INFO ,VHOST_CONFIG , -"dequeue zero copy is enabled\n" ); - } - -if (dev->notify_ops->new_device (dev->vid) ==0 ) - dev->flags |=VIRTIO_DEV_RUNNING ; - } } static void
@@ -1065,5 +1051,15 @@send_vhost_message (fd, &msg); } +if (!(dev->flags &VIRTIO_DEV_RUNNING ) &&virtio_is_ready (dev)) { +if (dev->dequeue_zero_copy) { +RTE_LOG (INFO ,VHOST_CONFIG , +"dequeue zero copy is enabled\n" ); + } + +if (dev->notify_ops->new_device (dev->vid) ==0 ) + dev->flags |=VIRTIO_DEV_RUNNING ; + } +return 0 ; }
Signature · 1 line
1.9.0
Re: [PATCH 11/17] vhost: move the device ready check at proper place
Quoted 8 lines · Yuanhan Liu
Currently, we check
vq->desc,vq->kickfdandvq->callfdto know whether a virtio device is ready or not. However, we only do it when handlingSET_VRING_KICKmessage, which could be wrong if a vhost-user frontend sendSET_VRING_KICKfirst andSET_VRING_CALLlater.To work for all possible vhost-user frontend implementations, we could move the ready check at the end of vhost-user message handler.
Quoted 7 lines
Meanwhile, since we do the check more often than before, the "virtio not ready" message is dropped, to not flood the screen.
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/vhost_user.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
Makes sense:
Thanks,
Maxime
PATCH 12/17 vhost: drop the Rx and Tx queue macro
In reply to Yuanhan LiuThey are virti-net specific and should be defined inside the virtio-net driver.
--- drivers/net/vhost/rte_eth_vhost.c | 2 ++ examples/tep_termination/main.h | 2 ++ examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 3 --- 4 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +2 -0
@@ -45,6 +45,8 @@#include "rte_eth_vhost.h" +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +#define ETH_VHOST_IFACE_ARG "iface"#define ETH_VHOST_QUEUES_ARG "queues"#define ETH_VHOST_CLIENT_ARG "client"
examples/tep_termination/main.h +2 -0
@@ -54,6 +54,8 @@/* Max number of devices. Limited by the application. */ #define MAX_DEVICES 64 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +/* Per-device statistics struct */ struct device_statistics {uint64_t tx_total;
examples/vhost/main.h +2 -0
@@ -41,6 +41,8 @@#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2#define RTE_LOGTYPE_VHOST_PORT RTE_LOGTYPE_USER3 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +struct device_statistics {uint64_t tx;uint64_t tx_total;
lib/librte_vhost/rte_virtio_net.h +0 -3
@@ -55,9 +55,6 @@#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)#define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2) -/* Enum for virtqueue management. */ -enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; -/** * Information relating to memory regions including offsets to * addresses in QEMUs memory file.
Signature · 1 line
1.9.0
Re: [PATCH 12/17] vhost: drop the Rx and Tx queue macro
Quoted 1 line · Yuanhan Liu
They are virti-net specific and should be defined inside the virtio-net
s/virti-net/virtio-net/
Quoted 9 lines
driver.
Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 2 ++ examples/tep_termination/main.h | 2 ++ examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 3 --- 4 files changed, 6 insertions(+), 3 deletions(-)
With the commit msg fixed:
Thanks,
Maxime
PATCH 13/17 vhost: do not include net specific headers
In reply to Yuanhan LiuInclude it internally, at vhost.h.
--- examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 4 ---- lib/librte_vhost/vhost.h | 4 ++++ 3 files changed, 6 insertions(+), 4 deletions(-)
examples/vhost/main.h +2 -0
@@ -36,6 +36,8 @@#include <sys/queue.h> +#include <rte_ether.h> +/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2
lib/librte_vhost/rte_virtio_net.h +0 -4
@@ -42,14 +42,10 @@#include <stdint.h> #include <linux/vhost.h> #include <linux/virtio_ring.h> -#include <linux/virtio_net.h> #include <sys/eventfd.h> -#include <sys/socket.h> -#include <linux/if.h> #include <rte_memory.h> #include <rte_mempool.h> -#include <rte_ether.h> #define RTE_VHOST_USER_CLIENT (1ULL << 0)#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)
lib/librte_vhost/vhost.h +4 -0
@@ -39,8 +39,12 @@#include <sys/queue.h> #include <unistd.h> #include <linux/vhost.h> +#include <linux/virtio_net.h> +#include <sys/socket.h> +#include <linux/if.h> #include <rte_log.h> +#include <rte_ether.h> #include "rte_virtio_net.h"
Signature · 1 line
1.9.0
Re: [PATCH 13/17] vhost: do not include net specific headers
Quoted 8 lines · Yuanhan Liu
Include it internally, at
vhost.h.Signed-off-by Yuanhan Liu <[email protected]>--- examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 4 ---- lib/librte_vhost/vhost.h | 4 ++++ 3 files changed, 6 insertions(+), 4 deletions(-)
Re: [PATCH 13/17] vhost: do not include net specific headers
In reply to Yuanhan LiuQuoted 39 lines
-----Original Message-----
From: Yuanhan Liu [mailto:[email protected]]
Sent: Friday, March 3, 2017 5:51 PM
To: [email protected]
Cc: Maxime Coquelin <[email protected]>; Harris, James R <[email protected]>; Liu, Changpeng <[email protected]>; Yuanhan Liu <[email protected]>
Subject: [PATCH 13/17] vhost: do not include net specific headersInclude it internally, at
vhost.h.Signed-off-by Yuanhan Liu <[email protected]>--- examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 4 ---- lib/librte_vhost/vhost.h | 4 ++++ 3 files changed, 6 insertions(+), 4 deletions(-)examples/vhost/main.h +2
-0@@ -36,6 +36,8 @@#include <sys/queue.h> +#include <rte_ether.h> +/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2lib/librte_vhost/rte_virtio_net.h +0
-0@@ -42,14 +42,10 @@#include <stdint.h>
lib/librte_vhost/rte_virtio_net.h line 52
Quoted 10 lines
lib/librte_vhost/rte_virtio_net.h +0
-4#include <linux/vhost.h> #include <linux/virtio_ring.h> -#include <linux/virtio_net.h> #include <sys/eventfd.h> -#include <sys/socket.h> -#include <linux/if.h> #include <rte_memory.h> #include <rte_mempool.h> -#include <rte_ether.h>
One small nits here, remove net specific headers is good idea, since API rte_vhost_dequeue_burst/rte_vhost_enqueue_burst has "struct rte_mbuf" declared parameter, user must include <rte_mbuf.h> in their own applications. Can we add extra line "struct rte_mbuf;" before the rte_vhost_dequeue_burst/rte_vhost_enqueue_burst APIs to avoid such extra includes?
Quoted 22 lines
lib/librte_vhost/rte_virtio_net.h +0
-0#define RTE_VHOST_USER_CLIENT (1ULL << 0)#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)lib/librte_vhost/vhost.h +4
-1@@ -39,8 +39,12 @@#include <sys/queue.h> #include <unistd.h> #include <linux/vhost.h> +#include <linux/virtio_net.h> +#include <sys/socket.h> +#include <linux/if.h> #include <rte_log.h> +#include <rte_ether.h> #include "rte_virtio_net.h" --1.9.0
Re: [PATCH 13/17] vhost: do not include net specific headers
Quoted 13 lines · Changpeng
Quoted 13 lines
lib/librte_vhost/rte_virtio_net.h +0
-3@@ -42,14 +42,10 @@#include <stdint.h> #include <linux/vhost.h> #include <linux/virtio_ring.h> -#include <linux/virtio_net.h> #include <sys/eventfd.h> -#include <sys/socket.h> -#include <linux/if.h>
Quoted 8 lines
lib/librte_vhost/rte_virtio_net.h line 52
Quoted 3 lines
lib/librte_vhost/rte_virtio_net.h +0
-1#include <rte_memory.h> #include <rte_mempool.h> -#include <rte_ether.h> One small nits here, remove net specific headers is good idea, since API rte_vhost_dequeue_burst/rte_vhost_enqueue_burst has "struct
rte_mbuf" declared parameter, user must include <rte_mbuf.h> in their own applications. Can we add extra line "structrte_mbuf;" before the rte_vhost_dequeue_burst/rte_vhost_enqueue_burst APIs to avoid such extra includes?
Good suggestion, and sure, we can do that.
And I had a plan to add a config option to not build the net driver when it's given. Thus, it could give us a vhost with minimum dependences, say no dependence on mbuf, on rte_malloc and etc.
I was thinking to name it to "CONFIG_RTE_VHOST_MINIMUM", or something like that. It's likely something I will do in the next release.
--yliu
PATCH 14/17 vhost: rename device ops struct
In reply to Yuanhan Liurename "virtio_net_device_ops" to "vhost_device_ops", to not let it be virtio-net specific.
--- drivers/net/vhost/rte_eth_vhost.c | 2 +- examples/tep_termination/main.c | 4 ++-- examples/vhost/main.c | 4 ++-- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_virtio_net.h | 4 ++-- lib/librte_vhost/socket.c | 6 +++--- lib/librte_vhost/vhost.h | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -669,7 +669,7 @@ struct vhost_xstats_name_off {return 0 ; } -static struct virtio_net_device_ops vhost_ops = { +static struct vhost_device_ops vhost_ops = { .new_device = new_device, .destroy_device = destroy_device, .vring_state_changed = vring_state_changed,
examples/tep_termination/main.c +2 -2
@@ -1081,7 +1081,7 @@ static inline void __attribute__((always_inline))* These callback allow devices to be added to the data core when configuration * has been fully complete. */ -static const struct virtio_net_device_ops virtio_net_device_ops = { +static const struct vhost_device_ops vhost_device_ops = { .new_device = new_device, .destroy_device = destroy_device, };
@@ -1259,7 +1259,7 @@ static inline void __attribute__((always_inline)) 1ULL << VIRTIO_NET_F_MRG_RXBUF);rte_vhost_driver_callback_register (dev_basename, - &virtio_net_device_ops); + &vhost_device_ops);rte_vhost_driver_session_start ();
examples/vhost/main.c +2 -2
@@ -1270,7 +1270,7 @@ static inline void __attribute__((always_inline))* These callback allow devices to be added to the data core when configuration * has been fully complete. */ -static const struct virtio_net_device_ops virtio_net_device_ops = +static const struct vhost_device_ops vhost_device_ops = { .new_device = new_device, .destroy_device = destroy_device,
@@ -1540,7 +1540,7 @@ static inline void __attribute__((always_inline)) }rte_vhost_driver_callback_register (file, - &virtio_net_device_ops); + &vhost_device_ops); }rte_vhost_driver_session_start ();
lib/librte_vhost/Makefile +1 -1
@@ -36,7 +36,7 @@ LIB = librte_vhost.a EXPORT_MAP := rte_vhost_version.map -LIBABIVER := 3 +LIBABIVER := 4 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -D_FILE_OFFSET_BITS=64 CFLAGS += -I vhost_user
lib/librte_vhost/rte_virtio_net.h +2 -2
@@ -87,7 +87,7 @@ struct rte_vhost_vring {/** * Device and vring operations. */ -struct virtio_net_device_ops { +struct vhost_device_ops {int (*new_device)(int vid);/**< Add device. */ void (*destroy_device)(int vid);/**< Remove device. */
@@ -139,7 +139,7 @@ static inline uint64_t __attribute__((always_inline))/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path, -struct virtio_net_device_ops const *const ); +struct vhost_device_ops const *const );/* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start (void );
lib/librte_vhost/socket.c +3 -3
@@ -74,7 +74,7 @@ struct vhost_user_socket {uint64_t supported_features;uint64_t features; -struct virtio_net_device_ops const *notify_ops; +struct vhost_device_ops const *notify_ops; };struct vhost_user_connection {
@@ -725,7 +725,7 @@ struct vhost_user_reconnect_list {*/ int rte_vhost_driver_callback_register (const char *path, -struct virtio_net_device_ops const *const ops) +struct vhost_device_ops const *const ops) {struct vhost_user_socket *vsocket;
@@ -738,7 +738,7 @@ struct vhost_user_reconnect_list {return vsocket ?0 :-1 ; } -struct virtio_net_device_ops const * +struct vhost_device_ops const *vhost_driver_callback_get (const char *path) {struct vhost_user_socket *vsocket;
lib/librte_vhost/vhost.h +2 -2
@@ -183,7 +183,7 @@ struct virtio_net {uint64_t log_addr;struct ether_addr mac; -struct virtio_net_device_ops const *notify_ops; +struct vhost_device_ops const *notify_ops;uint32_t nr_guest_pages;uint32_t max_guest_pages;
@@ -257,7 +257,7 @@ static inline phys_addr_t __attribute__((always_inline))void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid); -struct virtio_net_device_ops const *vhost_driver_callback_get (const char *path); +struct vhost_device_ops const *vhost_driver_callback_get (const char *path);/* * Backend-specific cleanup.
Signature · 1 line
1.9.0
Re: [PATCH 14/17] vhost: rename device ops struct
Quoted 4 lines · Yuanhan Liu
rename "
virtio_net_device_ops" to "vhost_device_ops", to not let it be virtio-net specific.Signed-off-by Yuanhan Liu <[email protected]>
Quoted 10 lines
--- drivers/net/vhost/rte_eth_vhost.c | 2 +- examples/tep_termination/main.c | 4 ++-- examples/vhost/main.c | 4 ++-- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_virtio_net.h | 4 ++-- lib/librte_vhost/socket.c | 6 +++--- lib/librte_vhost/vhost.h | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-)
Thanks,
Maxime
PATCH 15/17 vhost: rename virtio-net to vhost
In reply to Yuanhan LiuRename "virtio-net" to "vhost" in the API comments.
--- lib/librte_vhost/rte_virtio_net.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
lib/librte_vhost/rte_virtio_net.h +7 -7
@@ -148,7 +148,7 @@ int rte_vhost_driver_callback_register(const char *path,* is allocated. * * @param vid -* virtio-net device ID +* vhost device ID * * @return * The numa node, -1 on failure
@@ -160,11 +160,11 @@ int rte_vhost_driver_callback_register(const char *path,* Get the number of queues the device supports. * * Note this function is deprecated, as it returns a queue pair number, -* which is virtio-net specific. Instead, rte_vhost_get_vring_num should +* which is vhost specific. Instead, rte_vhost_get_vring_num should * be used. * * @param vid -* virtio-net device ID +* vhost device ID * * @return * The number of queues, 0 on failure
@@ -188,7 +188,7 @@ int rte_vhost_driver_callback_register(const char *path,* file path. * * @param vid -* virtio-net device ID +* vhost device ID * @param buf * The buffer to stored the queried ifname * @param len
@@ -203,7 +203,7 @@ int rte_vhost_driver_callback_register(const char *path,* Get how many avail entries are left in the queue * * @param vid -* virtio-net device ID +* vhost device ID * @param queue_id * virtio queue index *
@@ -218,7 +218,7 @@ int rte_vhost_driver_callback_register(const char *path,* count is returned to indicate the number of packets that were succesfully * added to the RX queue. * @param vid -* virtio-net device ID +* vhost device ID * @param queue_id * virtio queue index in mq case * @param pkts
@@ -236,7 +236,7 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,* construct host mbufs, copies guest buffer content to host mbufs and * store them in pkts to be processed. * @param vid -* virtio-net device +* vhost device ID * @param queue_id * virtio queue index in mq case * @param mbuf_pool
Signature · 1 line
1.9.0
Re: [PATCH 15/17] vhost: rename virtio-net to vhost
Quoted 7 lines · Yuanhan Liu
Rename "virtio-net" to "vhost" in the API comments.
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_virtio_net.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
Thanks,
Maxime
PATCH 16/17 vhost: rename header file
In reply to Yuanhan LiuRename "rte_virtio_net.h" to "rte_vhost.h", to not let it be virtio net specific.
--- doc/guides/rel_notes/deprecation.rst | 9 -- drivers/net/vhost/rte_eth_vhost.c | 2 +- drivers/net/vhost/rte_eth_vhost.h | 2 +- examples/tep_termination/main.c | 2 +- examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/main.c | 2 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_vhost.h | 259 +++++++++++++++++++++++++++++++++ lib/librte_vhost/rte_virtio_net.h | 259 --------------------------------- lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 2 +- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 2 +- 13 files changed, 269 insertions(+), 278 deletions(-) create mode 100644 lib/librte_vhost/rte_vhost.h delete mode 100644 lib/librte_vhost/rte_virtio_net.h
doc/guides/rel_notes/deprecation.rst +0 -9
@@ -104,15 +104,6 @@ Deprecation Notices Target release for removal of the legacy API will be defined once most PMDs have switched to rte_flow. -* vhost: API/ABI changes are planned for 17.05, for making DPDK vhost library - generic enough so that applications can build different vhost-user drivers - (instead of vhost-user net only) on top of that. - Specifically, ``virtio_net_device_ops`` will be renamed to ``vhost_device_ops``. - Correspondingly, some API's parameter need be changed. Few more functions also - need be reworked to let it be device aware. For example, different virtio device - has different feature set, meaning functions like ``rte_vhost_feature_disable`` - need be changed. Last, file rte_virtio_net.h will be renamed to rte_vhost.h. - * kni: Remove :ref:`kni_vhost_backend-label` feature (KNI_VHOST) in 17.05 release. :doc:`Vhost Library </prog_guide/vhost_lib>` is currently preferred method for guest - host communication. Just for clarification, this is not to remove KNI
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -40,7 +40,7 @@#include <rte_memcpy.h> #include <rte_vdev.h> #include <rte_kvargs.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_spinlock.h> #include "rte_eth_vhost.h"
drivers/net/vhost/rte_eth_vhost.h +1 -1
@@ -41,7 +41,7 @@#include <stdint.h> #include <stdbool.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> /* * Event description.
examples/tep_termination/main.c +1 -1
@@ -49,7 +49,7 @@#include <rte_log.h> #include <rte_string_fns.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include "main.h" #include "vxlan.h"
examples/tep_termination/vxlan_setup.c +1 -1
@@ -49,7 +49,7 @@#include <rte_tcp.h> #include "main.h" -#include "rte_virtio_net.h" +#include "rte_vhost.h" #include "vxlan.h" #include "vxlan_setup.h"
examples/vhost/main.c +1 -1
@@ -49,7 +49,7 @@#include <rte_log.h> #include <rte_string_fns.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_ip.h> #include <rte_tcp.h>
lib/librte_vhost/Makefile +1 -1
@@ -51,7 +51,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c socket.c vhost.c vhost_user.c \ virtio_net.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h +SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h # dependencies DEPDIRS-$(CONFIG_RTE_LIBRTE_VHOST) += lib/librte_eal
lib/librte_vhost/rte_vhost.h new file +259 -0
259 lines not on this page · raw message
lib/librte_vhost/rte_virtio_net.h deleted +0 -259
259 lines not on this page · raw message
lib/librte_vhost/vhost.c +1 -1
@@ -45,7 +45,7 @@#include <rte_string_fns.h> #include <rte_memory.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include "vhost.h"
lib/librte_vhost/vhost.h +1 -1
@@ -46,7 +46,7 @@#include <rte_log.h> #include <rte_ether.h> -#include "rte_virtio_net.h" +#include "rte_vhost.h" #define VHOST_USER_F_PROTOCOL_FEATURES 30
lib/librte_vhost/vhost_user.h +1 -1
@@ -37,7 +37,7 @@#include <stdint.h> #include <linux/vhost.h> -#include "rte_virtio_net.h" +#include "rte_vhost.h" /* refer to hw/virtio/vhost-user.c */
lib/librte_vhost/virtio_net.c +1 -1
@@ -39,7 +39,7 @@#include <rte_memcpy.h> #include <rte_ether.h> #include <rte_ip.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_tcp.h> #include <rte_udp.h> #include <rte_sctp.h>
Signature · 1 line
1.9.0
Re: [PATCH 16/17] vhost: rename header file
Quoted 4 lines · Yuanhan Liu
Rename "
rte_virtio_net.h" to "rte_vhost.h", to not let it be virtio net specific.Signed-off-by Yuanhan Liu <[email protected]>
Quoted 10 lines
--- doc/guides/rel_notes/deprecation.rst | 9 -- drivers/net/vhost/rte_eth_vhost.c | 2 +- drivers/net/vhost/rte_eth_vhost.h | 2 +- examples/tep_termination/main.c | 2 +- examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/main.c | 2 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_vhost.h | 259 +++++++++++++++++++++++++++++++++ lib/librte_vhost/rte_virtio_net.h | 259 ---------------------------------
Did you perform the rename using git mv?
Quoted 7 lines
lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 2 +- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 2 +- 13 files changed, 269 insertions(+), 278 deletions(-) create mode 100644 lib/librte_vhost/rte_vhost.h delete mode 100644 lib/librte_vhost/rte_virtio_net.h
Other than that, the change looks good to me:
Thanks,
Maxime
Re: [PATCH 16/17] vhost: rename header file
Quoted 17 lines · Maxime Coquelin
Quoted 5 lines · Yuanhan Liu
Rename "
rte_virtio_net.h" to "rte_vhost.h", to not let it be virtio net specific.Signed-off-by Yuanhan Liu <[email protected]>---
Quoted 9 lines
doc/guides/rel_notes/deprecation.rst | 9 -- drivers/net/vhost/rte_eth_vhost.c | 2 +- drivers/net/vhost/rte_eth_vhost.h | 2 +- examples/tep_termination/main.c | 2 +- examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/main.c | 2 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_vhost.h | 259 +++++++++++++++++++++++++++++++++ lib/librte_vhost/rte_virtio_net.h | 259 ---------------------------------
Quoted 1 line
Did you perform the rename using git mv?
Yes, and I forgot to add '-M' option while run "git format-patch".
--yliu
Quoted 14 lines
Quoted 8 lines
lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 2 +- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 2 +- 13 files changed, 269 insertions(+), 278 deletions(-)create mode 100644
lib/librte_vhost/rte_vhost.hdelete mode 100644lib/librte_vhost/rte_virtio_net.hOther than that, the change looks good to me:
Reviewed-by Maxime Coquelin <[email protected]>Thanks,
Maxime
PATCH 17/17 examples/vhost: demonstrate the new generic vhost APIs
In reply to Yuanhan LiuNow DPDK vhost lib has been generic enough, that it can be used to implement any vhost-user drivers.
For example, this patch implements a very simple vhost-user net driver, mainly for demonstrating how to use those generic vhost APIs.
And when the --builtin-net-driver option is used, the example virtio-net driver code will be invoked, instead of the one provided from the vhost library.
--- examples/vhost/Makefile | 2 +- examples/vhost/main.c | 36 +++- examples/vhost/main.h | 29 +++- examples/vhost/virtio_net.c | 405 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 465 insertions(+), 7 deletions(-) create mode 100644 examples/vhost/virtio_net.c
examples/vhost/Makefile +1 -1
@@ -48,7 +48,7 @@ else APP = vhost-switch # all source are stored in SRCS-y -SRCS-y := main.c +SRCS-y := main.c virtio_net.c CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 CFLAGS += $(WERROR_FLAGS)
examples/vhost/main.c +31 -5
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2016 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2017 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -65,7 +65,6 @@#define MBUF_CACHE_SIZE 128#define MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE -#define MAX_PKT_BURST 32/* Max burst size for RX/TX */ #define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ #define BURST_RX_WAIT_US 15/* Defines how long we wait between retries on RX */
@@ -129,6 +128,8 @@static int client_mode;static int dequeue_zero_copy; +static int builtin_net_driver; +/* Specify timeout (in useconds) between retries on RX. */ static uint32_t burst_rx_delay_time =BURST_RX_WAIT_US ;/* Specify the number of retries on RX. */
@@ -499,6 +500,7 @@ struct mbuf_table { {"tso", required_argument, NULL, 0}, {"client", no_argument, &client_mode, 1}, {"dequeue-zero-copy", no_argument, &dequeue_zero_copy, 1}, + {"builtin-net-driver", no_argument, &builtin_net_driver, 1}, {NULL, 0, 0, 0}, };
@@ -795,7 +797,12 @@ static inline void __attribute__((always_inline)) {uint16_t ret; - ret =rte_vhost_enqueue_burst (dst_vdev->vid,VIRTIO_RXQ , &m,1 ); +if (builtin_net_driver) { + ret =vs_enqueue_pkts (dst_vdev,VIRTIO_RXQ , &m,1 ); + }else { + ret =rte_vhost_enqueue_burst (dst_vdev->vid,VIRTIO_RXQ , &m,1 ); + } +if (enable_stats) {rte_atomic64_inc (&dst_vdev->stats.rx_total_atomic);rte_atomic64_add (&dst_vdev->stats.rx_atomic, ret);
@@ -1066,8 +1073,13 @@ static inline void __attribute__((always_inline)) } } - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , +if (builtin_net_driver) { + enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , pkts, rx_count); + }else { + enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , + pkts, rx_count); + }if (enable_stats) {rte_atomic64_add (&vdev->stats.rx_total_atomic, rx_count);rte_atomic64_add (&vdev->stats.rx_atomic, enqueue_count);
@@ -1083,8 +1095,13 @@ static inline void __attribute__((always_inline))uint16_t count;uint16_t i; - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , mbuf_pool, +if (builtin_net_driver) { + count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST ); + }else { + count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , + mbuf_pool, pkts,MAX_PKT_BURST ); + }/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1187,6 +1204,9 @@ static inline void __attribute__((always_inline))rte_pause (); } +if (builtin_net_driver) +vs_vhost_net_remove (vdev); +TAILQ_REMOVE (&lcore_info[vdev->coreid].vdev_list, vdev, lcore_vdev_entry);TAILQ_REMOVE (&vhost_dev_list, vdev, global_vdev_entry);
@@ -1235,6 +1255,9 @@ static inline void __attribute__((always_inline)) } vdev->vid = vid; +if (builtin_net_driver) +vs_vhost_net_setup (vdev); +TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, global_vdev_entry); vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;
@@ -1513,6 +1536,9 @@ static inline void __attribute__((always_inline))rte_exit (EXIT_FAILURE ,"vhost driver register failure.\n" ); } + + ret =rte_vhost_driver_set_features (file,VIRTIO_NET_FEATURES ); +if (mergeable ==0 ) {rte_vhost_driver_disable_features (file,1ULL <<VIRTIO_NET_F_MRG_RXBUF );
examples/vhost/main.h +28 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2016 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2017 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -43,8 +43,11 @@#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2#define RTE_LOGTYPE_VHOST_PORT RTE_LOGTYPE_USER3 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +#define MAX_PKT_BURST 32/* Max burst size for RX/TX */ +struct device_statistics {uint64_t tx;uint64_t tx_total;
@@ -52,6 +55,12 @@ struct device_statistics {rte_atomic64_t rx_total_atomic; }; +struct vhost_queue { +struct rte_vhost_vring vr; +uint16_t last_avail_idx; +uint16_t last_used_idx; +}; +struct vhost_dev {/**< Number of memory regions for gpa to hpa translation. */ uint32_t nregions_hpa;
@@ -69,9 +78,16 @@ struct vhost_dev {volatile uint8_t remove;int vid; +uint64_t features; +size_t hdr_len; +uint16_t nr_vrings; +struct rte_vhost_memory *mem;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) global_vdev_entry;TAILQ_ENTRY (vhost_dev) lcore_vdev_entry; + +#define MAX_QUEUE_PAIRS 4 +struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned;TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -92,4 +108,15 @@ struct lcore_info { struct vhost_dev_tailq_list vdev_list; }; +/* we implement non-extra virtio net features */ +#define VIRTIO_NET_FEATURES 0 + +void vs_vhost_net_setup (struct vhost_dev *dev); +void vs_vhost_net_remove (struct vhost_dev *dev); +uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c new file +405 -0
405 lines not on this page · raw message
Signature · 1 line
1.9.0
v2 cover vhost: generic vhost API
In reply to Yuanhan LiuThis patchset makes DPDK vhost library be generic enough, so that we could build other vhost-user drivers on top of it. For example, SPDK (Storage Performance Development Kit) is trying to enable vhost-user SCSI.
The basic idea is, let DPDK vhost be a vhost-user agent. It stores all the info about the virtio device (i.e. vring address, negotiated features, etc) and let the specific vhost-user driver to fetch them (by the API provided by DPDK vhost lib). With those info being provided, the vhost-user driver then could get/put vring entries, thus, it could exchange data between the guest and host.
The last patch demonstrates how to use these new APIs to implement a very simple vhost-user net driver, without any fancy features enabled.
Major API/ABI Changes summary
=============================
- some renames
* "struct virtio_net_device_ops" ==> "struct vhost_device_ops"
* "rte_virtio_net.h" ==> "rte_vhost.h"
- driver related APIs are bond with the socket file
* rte_vhost_driver_set_features(socket_file, features);
* rte_vhost_driver_get_features(socket_file, features);
* rte_vhost_driver_enable_features(socket_file, features)
* rte_vhost_driver_disable_features(socket_file, features)
* rte_vhost_driver_callback_register(socket_file, notify_ops);
* rte_vhost_driver_start(socket_file);
This function replaces rte_vhost_driver_session_start(). Check patch 18 for more information.
- new APIs to fetch guest and vring info
* rte_vhost_get_mem_table(vid, mem);
* rte_vhost_get_negotiated_features(vid);
* rte_vhost_get_vhost_vring(vid, vring_idx, vring);
- new exported structures
* struct rte_vhost_vring
* struct rte_vhost_mem_region
* struct rte_vhost_memory
- a new device ops callback: features_changed().
Change log
==========
v2: - rebase
- updated release note
- updated API comments
- renamed rte_vhost_get_vhost_memory to rte_vhost_get_mem_table
- added a new device callback: features_changed(), bascially for live migration support
- introduced rte_vhost_driver_start() to start a specific driver
- misc fixes
Some design choices
===================
While making this patchset, I met quite few design choices and here are two of them, with the issue and the reason I made such choices provided. Please let me know if you have any comments (or better ideas).
Export public structures or not
-------------------------------
I made an ABI refactor last time (v16.07): move all the structures internally and let applications use a "vid" to reference the internal struct. With that, I hope we could never worry about the annoying ABI issues.
It works great (and as expected) since then, as far as we only support virito-net, as far as we can handle all the descs inside vhost lib. It becomes problematic when a user wants to implement a vhost-user driver somewhere. For example, it needs do the GPA to VVA translation. Without any structs exported, some functions like gpa_to_vva() can't be inlined. Calling it would be costly, especially it's a function we have to invoke for processing each vring desc.
For that reason, the guest memory regions are exported. With that, the gpa_to_vva could be inlined.
Add helper functions to fetch/update descs or not
-------------------------------------------------
I intended to do it like this way: introduce one function to get @count of descs from a specific vring and another one to update the used descs. It's something like
rte_vhost_vring_get_descs(vid, vring_idx, count, offset, iov, descs);
rte_vhost_vring_update_used_descs(vid, vring_idx, count, offset, descs);With that, vhost-user driver programmer's task would be easier, as he/she doesn't have to parse the descs any more (such as to handle indirect desc).
But judging that virtio 1.1 is just emerged and it proposes a completely ring layout, and most importantly, the vring desc structure is also changed, I'd like to hold the introducation of such two functions. Otherwise, it's very likely the two will be invalid when virtio 1.1 is out. Though I think it may could be addressed with a care design, something like making the IOV generic enough:
struct rte_vhost_iov {
uint64_t gpa;
uint64_t vva;
uint64_t len;
};Instead, I go with the other way: introduce few APIs to export all the vring infos (vring size, vring addr, callfd, etc), and let the vhost-user driver read and update the descs. Those info could be passed to vhost-user driver by introducing one API for each, but for saving few APIs and reducing few calls for the programmer, I packed few key fields into a new structure, so that it can be fetched with one call:
struct rte_vhost_vring {
struct vring_desc *desc;
struct vring_avail *avail;
struct vring_used *used;
uint64_t log_guest_addr;
int callfd;
int kickfd;
uint16_t size;
};When virtio 1.1 comes out, likely a simple change like following would just work:
struct rte_vhost_vring {
union {
struct {
struct vring_desc *desc;
struct vring_avail *avail;
struct vring_used *used;
uint64_t log_guest_addr;
};
struct desc *desc_1_1; /* vring addr for virtio 1.1 */
};
int callfd;
int kickfd;
uint16_t size;
};AFAIK, it's not an ABI breakage. Even if it does, we could introduce a new API to get the virtio 1.1 ring address.
Those fields are the minimum set I got for a specific vring, with the mind it would bring the minimum chance to break ABI for future extension. If we need more info, we could introduce a new API.
OTOH, for getting the best performance, the two functions also have to be inlined ("vid + vring_idx" combo is replaced with "vring"):
rte_vhost_vring_get_descs(vring, count, offset, iov, descs);
rte_vhost_vring_update_used_descs(vring, count, offset, descs);That said, one way or another, we have to export rte_vhost_vring struct. For this reason, I didn't rush into introducing the two APIs.
--yliu
---
Yuanhan Liu (22):
vhost: introduce driver features related APIs net/vhost: remove feature related APIs
vhost: use new APIs to handle features
vhost: make notify ops per vhost driver
vhost: export guest memory regions
vhost: introduce API to fetch negotiated features
vhost: export vhost vring info
vhost: export API to translate gpa to vva
vhost: turn queue pair to vring
vhost: export the number of vrings
vhost: move the device ready check at proper place
vhost: drop the Rx and Tx queue macro
vhost: do not include net specific headers
vhost: rename device ops struct
vhost: rename virtio-net to vhost
vhost: add features changed callback
vhost: export APIs for live migration support
vhost: introduce API to start a specific driver
vhost: rename header file
vhost: workaround the build dependency on mbuf header
vhost: do not destroy device on repeat mem table message examples/vhost: demonstrate the new generic vhost APIs
doc/guides/prog_guide/vhost_lib.rst | 42 +-- doc/guides/rel_notes/deprecation.rst | 9 - doc/guides/rel_notes/release_17_05.rst | 40 +++ drivers/net/vhost/rte_eth_vhost.c | 101 ++----- drivers/net/vhost/rte_eth_vhost.h | 32 +-- drivers/net/vhost/rte_pmd_vhost_version.map | 3 - examples/tep_termination/main.c | 23 +- examples/tep_termination/main.h | 2 + examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/Makefile | 2 +- examples/vhost/main.c | 100 +++++-- examples/vhost/main.h | 33 ++- examples/vhost/virtio_net.c | 405 ++++++++++++++++++++++++++ lib/librte_vhost/Makefile | 4 +- lib/librte_vhost/fd_man.c | 9 +- lib/librte_vhost/fd_man.h | 2 +- lib/librte_vhost/rte_vhost.h | 423 ++++++++++++++++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 17 +- lib/librte_vhost/rte_virtio_net.h | 208 -------------- lib/librte_vhost/socket.c | 222 ++++++++++++--- lib/librte_vhost/vhost.c | 229 ++++++++------- lib/librte_vhost/vhost.h | 113 +++++--- lib/librte_vhost/vhost_user.c | 115 ++++---- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 71 ++--- 25 files changed, 1523 insertions(+), 686 deletions(-) create mode 100644 examples/vhost/virtio_net.c create mode 100644 lib/librte_vhost/rte_vhost.h delete mode 100644 lib/librte_vhost/rte_virtio_net.h
Signature · 1 line
1.9.0
PATCH v2 1/22 vhost: introduce driver features related APIs
Introduce few APIs to set/get/enable/disable driver features.
--- doc/guides/prog_guide/vhost_lib.rst | 10 +++- lib/librte_vhost/rte_vhost_version.map | 4 ++ lib/librte_vhost/rte_virtio_net.h | 51 +++++++++++++++++++ lib/librte_vhost/socket.c | 90 ++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 2 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +8 -2
@@ -53,7 +53,7 @@ vhost library should be able to: Vhost API Overview ------------------ -The following is an overview of the Vhost API functions: +The following is an overview of some key Vhost API functions: * ``rte_vhost_driver_register(path, flags)``
@@ -110,6 +110,12 @@ The following is an overview of the Vhost API functions: of those segments, thus the fewer the segments, the quicker we will get the mapping. NOTE: we may speed it by using tree searching in future. +* ``rte_vhost_driver_set_features(path, features)`` + + This function sets the feature bits the vhost-user driver supports. The + vhost-user driver could be vhost-user net, yet it could be something else, + say, vhost-user SCSI. + * ``rte_vhost_driver_session_start()`` This function starts the vhost session loop to handle vhost messages. It
@@ -145,7 +151,7 @@ The following is an overview of the Vhost API functions: Receives (dequeues) ``count`` packets from guest, and stored them at ``pkts``. -* ``rte_vhost_feature_disable/rte_vhost_feature_enable(feature_mask)`` +* ``rte_vhost_driver_disable/enable_features(path, features))`` This function disables/enables some features. For example, it can be used to disable mergeable buffers and TSO features, which both are enabled by
lib/librte_vhost/rte_vhost_version.map +4 -0
@@ -34,6 +34,10 @@ DPDK_16.07 { DPDK_17.05 { global: + rte_vhost_driver_disable_features; + rte_vhost_driver_enable_features; + rte_vhost_driver_get_features; + rte_vhost_driver_set_features; rte_vhost_get_mtu; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +51 -0
57 lines not on this page · raw message
lib/librte_vhost/socket.c +90 -0
102 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v2 2/22 net/vhost: remove feature related APIs
In reply to Yuanhan LiuThe rte_eth_vhost_feature_disable/enable/get APIs are just a wrapper of rte_vhost_feature_disable/enable/get. However, the later are going to be refactored; it's going to take an extra parameter (socket_file path), to let it be per-device.
Instead of changing those vhost-pmd APIs to adapt to the new vhost APIs, we could simply remove them, and let vdev to serve this purpose. After all, vdev options is better for disabling/enabling some features.
---
v2: - write more informative commit log on why they are removed.
- update release note
--- doc/guides/rel_notes/release_17_05.rst | 7 +++++++ drivers/net/vhost/rte_eth_vhost.c | 25 ------------------------ drivers/net/vhost/rte_eth_vhost.h | 30 ----------------------------- drivers/net/vhost/rte_pmd_vhost_version.map | 3 --- 4 files changed, 7 insertions(+), 58 deletions(-)
doc/guides/rel_notes/release_17_05.rst +7 -0
@@ -129,6 +129,13 @@ API Changes * The LPM ``next_hop`` field is extended from 8 bits to 21 bits for IPv6 while keeping ABI compatibility. + * The following vhost-pmd APIs are removed + + * ``rte_eth_vhost_feature_disable`` + * ``rte_eth_vhost_feature_enable`` + * ``rte_eth_vhost_feature_get`` + + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +0 -25
@@ -965,31 +965,6 @@ struct vhost_xstats_name_off {return 0 ; } -/** -* Disable features in feature_mask. Returns 0 on success. -*/ -int -rte_eth_vhost_feature_disable (uint64_t feature_mask) -{ -return rte_vhost_feature_disable (feature_mask); -} - -/** -* Enable features in feature_mask. Returns 0 on success. -*/ -int -rte_eth_vhost_feature_enable (uint64_t feature_mask) -{ -return rte_vhost_feature_enable (feature_mask); -} - -/* Returns currently supported vhost features */ -uint64_t -rte_eth_vhost_feature_get (void ) -{ -return rte_vhost_feature_get (); -} -static const struct eth_dev_ops ops = { .dev_start = eth_dev_start, .dev_stop = eth_dev_stop,
drivers/net/vhost/rte_eth_vhost.h +0 -30
@@ -43,36 +43,6 @@#include <rte_virtio_net.h> -/** -* Disable features in feature_mask. -* -* @param feature_mask -* Vhost features defined in "linux/virtio_net.h". -* @return -* - On success, zero. -* - On failure, a negative value. -*/ -int rte_eth_vhost_feature_disable (uint64_t feature_mask); - -/** -* Enable features in feature_mask. -* -* @param feature_mask -* Vhost features defined in "linux/virtio_net.h". -* @return -* - On success, zero. -* - On failure, a negative value. -*/ -int rte_eth_vhost_feature_enable (uint64_t feature_mask); - -/** -* Returns currently supported vhost features. -* -* @return -* Vhost features defined in "linux/virtio_net.h". -*/ -uint64_t rte_eth_vhost_feature_get (void ); -/* * Event description. */
drivers/net/vhost/rte_pmd_vhost_version.map +0 -3
@@ -1,9 +1,6 @@ DPDK_16.04 { global: - rte_eth_vhost_feature_disable; - rte_eth_vhost_feature_enable; - rte_eth_vhost_feature_get; rte_eth_vhost_get_queue_event; local: *;
Signature · 1 line
1.9.0
PATCH v2 3/22 vhost: use new APIs to handle features
In reply to Yuanhan Liu--- examples/tep_termination/main.c | 4 +++- examples/vhost/main.c | 43 +++++++++++++++++++++------------- lib/librte_vhost/rte_vhost_version.map | 3 --- lib/librte_vhost/rte_virtio_net.h | 13 ---------- lib/librte_vhost/socket.c | 23 +++++++++++++++++- lib/librte_vhost/vhost.c | 42 --------------------------------- lib/librte_vhost/vhost.h | 21 +++++++++++++++++ lib/librte_vhost/vhost_user.c | 8 +++---- 8 files changed, 77 insertions(+), 80 deletions(-)
examples/tep_termination/main.c +3 -1
@@ -1248,12 +1248,14 @@ static inline void __attribute__((always_inline))rte_eal_remote_launch (switch_worker, mbuf_pool, lcore_id); } -rte_vhost_feature_disable (1ULL <<VIRTIO_NET_F_MRG_RXBUF ); ret =rte_vhost_driver_register ((char *)&dev_basename,0 );if (ret !=0 )rte_exit (EXIT_FAILURE ,"failed to register vhost driver.\n" ); +rte_vhost_driver_disable_features (dev_basename, +1ULL <<VIRTIO_NET_F_MRG_RXBUF ); +rte_vhost_driver_callback_register (&virtio_net_device_ops);rte_vhost_driver_session_start ();
examples/vhost/main.c +27 -16
72 lines not on this page · raw message
lib/librte_vhost/rte_vhost_version.map +0 -3
@@ -7,9 +7,6 @@ DPDK_2.0 { rte_vhost_driver_session_start; rte_vhost_enable_guest_notification; rte_vhost_enqueue_burst; - rte_vhost_feature_disable; - rte_vhost_feature_enable; - rte_vhost_feature_get; local: *; };
lib/librte_vhost/rte_virtio_net.h +0 -13
@@ -70,19 +70,6 @@ struct virtio_net_device_ops {void *reserved[5 ];/**< Reserved for future extension */ }; -/** -* Disable features in feature_mask. Returns 0 on success. -*/ -int rte_vhost_feature_disable (uint64_t feature_mask); - -/** -* Enable features in feature_mask. Returns 0 on success. -*/ -int rte_vhost_feature_enable (uint64_t feature_mask); - -/* Returns currently supported vhost features */ -uint64_t rte_vhost_feature_get (void ); -int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/**
lib/librte_vhost/socket.c +22 -1
@@ -562,7 +562,13 @@ struct vhost_user_reconnect_list { vsocket =find_vhost_user_socket (path);pthread_mutex_unlock (&vhost_user.mutex); -return vsocket ? vsocket->features : (uint64_t )-1 ; +if (!vsocket) { +RTE_LOG (ERR ,VHOST_CONFIG , +"socket file %s is not registered yet.\n" , path); +return 0 ; + }else { +return vsocket->features; + } }/*
@@ -595,6 +601,21 @@ struct vhost_user_reconnect_list { vsocket->connfd =-1 ; vsocket->dequeue_zero_copy = flags &RTE_VHOST_USER_DEQUEUE_ZERO_COPY ; +/* +* Set the supported features correctly for the builtin vhost-user +* net driver. +* +* Applications know nothing about features the builtin virtio net +* driver (virtio_net.c) supports, thus it's not possible for them +* to invoke rte_vhost_driver_set_features(). To workaround it, here +* we set it unconditionaly. If the application want to implement +* another vhost-user driver (say SCSI), it should call the +* rte_vhost_driver_set_features(), which will overwrite following +* two values. +*/ + vsocket->supported_features =VIRTIO_NET_SUPPORTED_FEATURES ; + vsocket->features =VIRTIO_NET_SUPPORTED_FEATURES ; +if ((flags &RTE_VHOST_USER_CLIENT ) !=0 ) { vsocket->reconnect = !(flags &RTE_VHOST_USER_NO_RECONNECT );if (vsocket->reconnect && reconn_tid ==0 ) {
lib/librte_vhost/vhost.c +0 -42
54 lines not on this page · raw message
lib/librte_vhost/vhost.h +21 -0
@@ -133,6 +133,27 @@ struct vhost_virtqueue {#define VIRTIO_F_VERSION_1 32#endif +#define VHOST_USER_F_PROTOCOL_FEATURES 30 + +/* Features supported by this builtin vhost-user net driver. */ +#define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \ + (1ULL << VIRTIO_NET_F_CTRL_VQ) | \ + (1ULL << VIRTIO_NET_F_CTRL_RX) | \ + (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \ + (1ULL << VIRTIO_NET_F_MQ) | \ + (1ULL << VIRTIO_F_VERSION_1) | \ + (1ULL << VHOST_F_LOG_ALL) | \ + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \ + (1ULL << VIRTIO_NET_F_HOST_TSO4) | \ + (1ULL << VIRTIO_NET_F_HOST_TSO6) | \ + (1ULL << VIRTIO_NET_F_CSUM) | \ + (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \ + (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \ + (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \ + (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \ + (1ULL << VIRTIO_NET_F_MTU)) + +struct guest_page {uint64_t guest_phys_addr;uint64_t host_phys_addr;
lib/librte_vhost/vhost_user.c +4 -4
@@ -147,9 +147,9 @@* The features that we support are requested. */ static uint64_t -vhost_user_get_features (void ) +vhost_user_get_features (struct virtio_net *dev) { -return VHOST_FEATURES ; +return rte_vhost_driver_get_features (dev->ifname); }/*
@@ -158,7 +158,7 @@static int vhost_user_set_features (struct virtio_net *dev,uint64_t features) { -if (features & ~VHOST_FEATURES ) +if (features & ~rte_vhost_driver_get_features (dev->ifname))return -1 ; dev->features = features;
@@ -1006,7 +1006,7 @@switch (msg.request) {case VHOST_USER_GET_FEATURES : - msg.payload.u64 =vhost_user_get_features (); + msg.payload.u64 =vhost_user_get_features (dev); msg.size =sizeof (msg.payload.u64);send_vhost_message (fd, &msg);break ;
Signature · 1 line
1.9.0
PATCH v2 4/22 vhost: make notify ops per vhost driver
In reply to Yuanhan LiuAssume there is an application both support vhost-user net and vhost-user scsi, the callback should be different. Making notify ops per vhost driver allow application define different set of callbacks for different driver.
---
v2: - check the return value of callback_register and callback_get
- update release note
--- doc/guides/prog_guide/vhost_lib.rst | 2 +- doc/guides/rel_notes/release_17_05.rst | 3 +++ drivers/net/vhost/rte_eth_vhost.c | 20 +++++++++++--------- examples/tep_termination/main.c | 7 ++++++- examples/vhost/main.c | 9 +++++++-- lib/librte_vhost/rte_virtio_net.h | 3 ++- lib/librte_vhost/socket.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 16 +--------------- lib/librte_vhost/vhost.h | 5 ++++- lib/librte_vhost/vhost_user.c | 22 ++++++++++++++++------ 10 files changed, 83 insertions(+), 36 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +1 -1
@@ -122,7 +122,7 @@ The following is an overview of some key Vhost API functions: starts an infinite loop, therefore it should be called in a dedicated thread. -* ``rte_vhost_driver_callback_register(virtio_net_device_ops)`` +* ``rte_vhost_driver_callback_register(path, virtio_net_device_ops)`` This function registers a set of callbacks, to let DPDK applications take the appropriate action when some events happen. The following events are
doc/guides/rel_notes/release_17_05.rst +3 -0
@@ -135,6 +135,9 @@ API Changes * ``rte_eth_vhost_feature_enable`` * ``rte_eth_vhost_feature_get`` + * The vhost API ``rte_vhost_driver_callback_register(ops)`` takes one + more argument: ``rte_vhost_driver_callback_register(path, ops)``. + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +11 -9
@@ -669,6 +669,12 @@ struct vhost_xstats_name_off {return 0 ; } +static struct virtio_net_device_ops vhost_ops = { + .new_device = new_device, + .destroy_device = destroy_device, + .vring_state_changed = vring_state_changed, +}; +int rte_eth_vhost_get_queue_event (uint8_t port_id,struct rte_eth_vhost_queue_event *event)
@@ -738,15 +744,6 @@ struct vhost_xstats_name_off {static void * vhost_driver_session(void *param __rte_unused) { -static struct virtio_net_device_ops vhost_ops; - -/* set vhost arguments */ - vhost_ops.new_device = new_device; - vhost_ops.destroy_device = destroy_device; - vhost_ops.vring_state_changed = vring_state_changed; -if (rte_vhost_driver_callback_register (&vhost_ops) <0 ) -RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); -/* start event handling */ rte_vhost_driver_session_start ();
@@ -1079,6 +1076,11 @@ struct vhost_xstats_name_off {if (rte_vhost_driver_register (iface_name, flags)) goto error; +if (rte_vhost_driver_callback_register (iface_name, &vhost_ops) <0 ) { +RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); + goto error; + } +/* We need only one message handling thread */ if (rte_atomic16_add_return (&nb_started_ports,1 ) ==1 ) {if (vhost_driver_session_start ())
examples/tep_termination/main.c +6 -1
@@ -1256,7 +1256,12 @@ static inline void __attribute__((always_inline))rte_vhost_driver_disable_features (dev_basename,1ULL <<VIRTIO_NET_F_MRG_RXBUF ); -rte_vhost_driver_callback_register (&virtio_net_device_ops); + ret =rte_vhost_driver_callback_register (dev_basename, + &virtio_net_device_ops); +if (ret !=0 ) { +rte_exit (EXIT_FAILURE , +"failed to register vhost driver callbacks.\n" ); + }rte_vhost_driver_session_start ();
examples/vhost/main.c +7 -2
@@ -1538,9 +1538,14 @@ static inline void __attribute__((always_inline))rte_vhost_driver_enable_features (file,1ULL <<VIRTIO_NET_F_CTRL_RX ); } - } -rte_vhost_driver_callback_register (&virtio_net_device_ops); + ret =rte_vhost_driver_callback_register (file, + &virtio_net_device_ops); +if (ret !=0 ) { +rte_exit (EXIT_FAILURE , +"failed to register vhost driver callbacks.\n" ); + } + }rte_vhost_driver_session_start ();return 0 ;
lib/librte_vhost/rte_virtio_net.h +2 -1
@@ -133,7 +133,8 @@ struct virtio_net_device_ops {uint64_t rte_vhost_driver_get_features (const char *path);/* Register callbacks. */ -int rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ); +int rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const ops);/* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start (void );
lib/librte_vhost/socket.c +32 -0
@@ -73,6 +73,8 @@ struct vhost_user_socket {*/ uint64_t supported_features;uint64_t features; + +struct virtio_net_device_ops const *notify_ops; };struct vhost_user_connection {
@@ -718,6 +720,36 @@ struct vhost_user_reconnect_list {return -1 ; } +/* +* Register ops so that we can add/remove device to data core. +*/ +int +rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const ops) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +if (vsocket) + vsocket->notify_ops = ops; +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket ?0 :-1 ; +} + +struct virtio_net_device_ops const * +vhost_driver_callback_get (const char *path) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket ? vsocket->notify_ops :NULL ; +} +int rte_vhost_driver_session_start (void ) {
lib/librte_vhost/vhost.c +1 -15
@@ -51,9 +51,6 @@struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ]; -/* device ops to add/remove device to/from data core. */ -struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device (int vid) {
@@ -253,7 +250,7 @@ struct virtio_net *if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (vid); + dev->notify_ops->destroy_device (vid); }cleanup_device (dev,1 );
@@ -396,14 +393,3 @@ struct virtio_net * dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ;return 0 ; } - -/* -* Register ops so that we can add/remove device to data core. -*/ -int -rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ops) -{ - notify_ops = ops; - -return 0 ; -}
lib/librte_vhost/vhost.h +4 -1
@@ -185,6 +185,8 @@ struct virtio_net {struct ether_addr mac;uint16_t mtu; +struct virtio_net_device_ops const *notify_ops; +uint32_t nr_guest_pages;uint32_t max_guest_pages;struct guest_page *guest_pages;
@@ -288,7 +290,6 @@ static inline phys_addr_t __attribute__((always_inline))return 0 ; } -struct virtio_net_device_ops const *notify_ops;struct virtio_net *get_device (int vid);int vhost_new_device (void );
@@ -301,6 +302,8 @@ static inline phys_addr_t __attribute__((always_inline))void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid); +struct virtio_net_device_ops const *vhost_driver_callback_get (const char *path); +/* * Backend-specific cleanup. *
lib/librte_vhost/vhost_user.c +16 -6
@@ -135,7 +135,7 @@ {if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }cleanup_device (dev,0 );
@@ -503,7 +503,7 @@/* Remove from the data plane. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }if (dev->mem) {
@@ -687,7 +687,7 @@ "dequeue zero copy is enabled\n"); } -if (notify_ops->new_device (dev->vid) ==0 ) +if (dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; } }
@@ -721,7 +721,7 @@/* We have to stop the queue (virtio) if it is running. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); } dev->flags &= ~VIRTIO_DEV_READY ;
@@ -763,8 +763,8 @@"set queue enable: %d to qp idx: %d\n" , enable, state->index); -if (notify_ops->vring_state_changed) - notify_ops->vring_state_changed (dev->vid, state->index, enable); +if (dev->notify_ops->vring_state_changed) + dev->notify_ops->vring_state_changed (dev->vid, state->index, enable); dev->virtqueue[state->index]->enabled = enable;
@@ -978,6 +978,16 @@if (dev ==NULL )return -1 ; +if (!dev->notify_ops) { + dev->notify_ops =vhost_driver_callback_get (dev->ifname); +if (!dev->notify_ops) { +RTE_LOG (ERR ,VHOST_CONFIG , +"failed to get callback ops for driver %s\n" , + dev->ifname); +return -1 ; + } + } + ret =read_vhost_message (fd, &msg);if (ret <=0 || msg.request >=VHOST_USER_MAX ) {if (ret <0 )
Signature · 1 line
1.9.0
PATCH v2 5/22 vhost: export guest memory regions
In reply to Yuanhan LiuSome vhost-user driver may need this info to setup its own page tables for GPA (guest physical addr) to HPA (host physical addr) translation. SPDK (Storage Performance Development Kit) is one example.
Besides, by exporting this memory info, we could also export the gpa_to_vva() as an inline function, which helps for performance. Otherwise, it has to be referenced indirectly by a "vid".
---
v2: add API comments
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 38 ++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 23 ++++++++++++++++++++ lib/librte_vhost/vhost.h | 28 ++----------------------- lib/librte_vhost/vhost_user.c | 12 +++++------ 5 files changed, 70 insertions(+), 32 deletions(-)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -35,6 +35,7 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_get_mem_table; rte_vhost_get_mtu; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +38 -0
@@ -59,6 +59,28 @@enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM };/** +* Information relating to memory regions including offsets to +* addresses in QEMUs memory file. +*/ +struct rte_vhost_mem_region { +uint64_t guest_phys_addr; +uint64_t guest_user_addr; +uint64_t host_user_addr; +uint64_t size; +void *mmap_addr; +uint64_t mmap_size; +int fd; +}; + +/** +* Memory structure includes region and mapping information. +*/ +struct rte_vhost_memory { +uint32_t nregions; +struct rte_vhost_mem_region regions[0 ]; +}; + +/** * Device and vring operations. */ struct virtio_net_device_ops {
@@ -244,4 +266,20 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count); +/** +* Get guest mem table: a list of memory regions. +* +* An rte_vhost_vhost_memory object will be allocated internaly, to hold the +* guest memory regions. Application should free it at destroy_device() +* callback. +* +* @param vid +* vhost device ID +* @param mem +* To store the returned mem regions +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem); +#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +23 -0
@@ -359,6 +359,29 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem) +{ +struct virtio_net *dev; +struct rte_vhost_memory *m; +size_t size; + + dev =get_device (vid); +if (!dev) +return -1 ; + + size = dev->mem->nregions *sizeof (struct rte_vhost_mem_region ); + m =malloc (size); +if (!m) +return -1 ; + + m->nregions = dev->mem->nregions; +memcpy (m->regions, dev->mem->regions, size); + *mem = m; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {
lib/librte_vhost/vhost.h +2 -26
@@ -166,7 +166,7 @@ struct guest_page {*/ struct virtio_net {/* Frontend (QEMU) memory and memory region information */ -struct virtio_memory *mem; +struct rte_vhost_memory *mem;uint64_t features;uint64_t protocol_features;int vid;
@@ -192,30 +192,6 @@ struct virtio_net {struct guest_page *guest_pages; } __rte_cache_aligned; -/** -* Information relating to memory regions including offsets to -* addresses in QEMUs memory file. -*/ -struct virtio_memory_region { -uint64_t guest_phys_addr; -uint64_t guest_user_addr; -uint64_t host_user_addr; -uint64_t size; -void *mmap_addr; -uint64_t mmap_size; -int fd; -}; - - -/** -* Memory structure includes region and mapping information. -*/ -struct virtio_memory { -uint32_t nregions; -struct virtio_memory_region regions[0 ]; -}; - -/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
@@ -255,7 +231,7 @@ struct virtio_memory {static inline uint64_t __attribute__((always_inline))gpa_to_vva (struct virtio_net *dev,uint64_t gpa) { -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;uint32_t i;for (i =0 ; i < dev->mem->nregions; i++) {
lib/librte_vhost/vhost_user.c +6 -6
@@ -92,7 +92,7 @@ free_mem_region(struct virtio_net *dev) {uint32_t i; -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;if (!dev || !dev->mem)return ;
@@ -304,7 +304,7 @@static uint64_t qva_to_vva (struct virtio_net *dev,uint64_t qva) { -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;uint32_t i;/* Find the region where the address lives. */
@@ -432,7 +432,7 @@ }static void -add_guest_pages (struct virtio_net *dev,struct virtio_memory_region *reg, +add_guest_pages (struct virtio_net *dev,struct rte_vhost_mem_region *reg,uint64_t page_size) {uint64_t reg_size = reg->size;
@@ -492,7 +492,7 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) { struct VhostUserMemory memory = pmsg->payload.memory; -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;void *mmap_addr;uint64_t mmap_size;uint64_t mmap_offset;
@@ -519,8 +519,8 @@ sizeof(struct guest_page)); } - dev->mem =rte_zmalloc ("vhost-mem-table" ,sizeof (struct virtio_memory ) + -sizeof (struct virtio_memory_region ) * memory.nregions,0 ); + dev->mem =rte_zmalloc ("vhost-mem-table" ,sizeof (struct rte_vhost_memory ) + +sizeof (struct rte_vhost_mem_region ) * memory.nregions,0 );if (dev->mem ==NULL ) { RTE_LOG(ERR, VHOST_CONFIG, "(%d) failed to allocate memory for dev->mem\n",
Signature · 1 line
1.9.0
PATCH v2 6/22 vhost: introduce API to fetch negotiated features
In reply to Yuanhan Liu--- lib/librte_vhost/rte_vhost_version.map | 2 ++ lib/librte_vhost/rte_virtio_net.h | 10 ++++++++++ lib/librte_vhost/vhost.c | 12 ++++++++++++ 3 files changed, 24 insertions(+)
lib/librte_vhost/rte_vhost_version.map +2 -0
@@ -37,5 +37,7 @@ DPDK_17.05 { rte_vhost_driver_set_features; rte_vhost_get_mem_table; rte_vhost_get_mtu; + rte_vhost_get_negotiated_features + rte_vhost_get_vhost_memory; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +10 -0
@@ -154,6 +154,16 @@ struct virtio_net_device_ops {*/ uint64_t rte_vhost_driver_get_features (const char *path); +/** +* Get the feature bits after negotiation +* +* @param vid +* Vhost device ID +* @return +* Negotiated feature bits on success, 0 on failure +*/ +uint64_t rte_vhost_get_negotiated_features (int vid); +/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path,struct virtio_net_device_ops const *const ops);
lib/librte_vhost/vhost.c +12 -0
@@ -359,6 +359,18 @@ struct virtio_net *return 0 ; } +uint64_t +rte_vhost_get_negotiated_features (int vid) +{ +struct virtio_net *dev; + + dev =get_device (vid); +if (!dev) +return 0 ; + +return dev->features; +} +int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem) {
Signature · 1 line
1.9.0
PATCH v2 7/22 vhost: export vhost vring info
In reply to Yuanhan Liu---
v2: - fix off-by-one check
- add API comments
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 26 ++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 30 ++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 2 ++ 4 files changed, 59 insertions(+)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -39,5 +39,6 @@ DPDK_17.05 { rte_vhost_get_mtu; rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; + rte_vhost_get_vhost_vring; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +26 -0
@@ -80,6 +80,17 @@ struct rte_vhost_memory {struct rte_vhost_mem_region regions[0 ]; }; +struct rte_vhost_vring { +struct vring_desc *desc; +struct vring_avail *avail; +struct vring_used *used; +uint64_t log_guest_addr; + +int callfd; +int kickfd; +uint16_t size; +}; +/** * Device and vring operations. */
@@ -292,4 +303,19 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,*/ int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem); +/** +* Get guest vring info, including the vring address, vring size, etc. +* +* @param vid +* vhost device ID +* @param vring_idx +* vring index +* @param vring +* the structure to hold the requested vring info +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring); +#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +30 -0
@@ -394,6 +394,36 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring) +{ +struct virtio_net *dev; +struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (!dev) +return -1 ; + +if (vring_idx >=VHOST_MAX_VRING ) +return -1 ; + + vq = dev->virtqueue[vring_idx]; +if (!vq) +return -1 ; + + vring->desc = vq->desc; + vring->avail = vq->avail; + vring->used = vq->used; + vring->log_guest_addr = vq->log_guest_addr; + + vring->callfd = vq->callfd; + vring->kickfd = vq->kickfd; + vring->size = vq->size; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {
lib/librte_vhost/vhost.h +2 -0
@@ -120,6 +120,8 @@ struct vhost_virtqueue {#ifndef VIRTIO_NET_F_MQ #define VIRTIO_NET_F_MQ 22#endif + +#define VHOST_MAX_VRING 0x100#define VHOST_MAX_QUEUE_PAIRS 0x80#ifndef VIRTIO_NET_F_MTU
Signature · 1 line
1.9.0
PATCH v2 8/22 vhost: export API to translate gpa to vva
In reply to Yuanhan Liu--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 28 ++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 19 ------------------- lib/librte_vhost/virtio_net.c | 23 +++++++++++++---------- 4 files changed, 42 insertions(+), 29 deletions(-)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -40,5 +40,6 @@ DPDK_17.05 { rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; rte_vhost_get_vhost_vring; + rte_vhost_gpa_to_vva; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +28 -0
@@ -103,6 +103,34 @@ struct virtio_net_device_ops {void *reserved[5 ];/**< Reserved for future extension */ }; +/** +* Convert guest physical address to host virtual address +* +* @param mem +* the guest memory regions +* @param gpa +* the guest physical address for querying +* @return +* the host virtual address on success, 0 on failure +*/ +static inline uint64_t __attribute__((always_inline)) +rte_vhost_gpa_to_vva (struct rte_vhost_memory *mem,uint64_t gpa) +{ +struct rte_vhost_mem_region *reg; +uint32_t i; + +for (i =0 ; i < mem->nregions; i++) { + reg = &mem->regions[i]; +if (gpa >= reg->guest_phys_addr && + gpa < reg->guest_phys_addr + reg->size) { +return gpa - reg->guest_phys_addr + + reg->host_user_addr; + } + } + +return 0 ; +} +int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/**
lib/librte_vhost/vhost.h +0 -19
@@ -229,25 +229,6 @@ struct virtio_net {#define MAX_VHOST_DEVICE 1024extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ]; -/* Convert guest physical Address to host virtual address */ -static inline uint64_t __attribute__((always_inline)) -gpa_to_vva (struct virtio_net *dev,uint64_t gpa) -{ -struct rte_vhost_mem_region *reg; -uint32_t i; - -for (i =0 ; i < dev->mem->nregions; i++) { - reg = &dev->mem->regions[i]; -if (gpa >= reg->guest_phys_addr && - gpa < reg->guest_phys_addr + reg->size) { -return gpa - reg->guest_phys_addr + - reg->host_user_addr; - } - } - -return 0 ; -} -/* Convert guest physical address to host physical address */ static inline phys_addr_t __attribute__((always_inline))gpa_to_hpa (struct virtio_net *dev,uint64_t gpa,uint64_t size)
lib/librte_vhost/virtio_net.c +13 -10
@@ -199,7 +199,7 @@ static inline int __attribute__((always_inline))uint16_t nr_desc =1 ; desc = &descs[desc_idx]; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);/* * Checking of 'desc_addr' placed outside of 'unlikely' macro to avoid * performance issue with some versions of gcc (4.8.4 and 5.3.0) which
@@ -239,7 +239,7 @@ static inline int __attribute__((always_inline))return -1 ; desc = &descs[desc->next]; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -323,7 +323,8 @@ static inline uint32_t __attribute__((always_inline))int err;if (vq->desc[desc_idx].flags &VRING_DESC_F_INDIRECT ) { - descs = (struct vring_desc *)(uintptr_t )gpa_to_vva (dev, + descs = (struct vring_desc *)(uintptr_t ) +rte_vhost_gpa_to_vva (dev->mem, vq->desc[desc_idx].addr);if (unlikely (!descs)) { count = i;
@@ -383,7 +384,7 @@ static inline int __attribute__((always_inline))if (vq->desc[idx].flags &VRING_DESC_F_INDIRECT ) { descs = (struct vring_desc *)(uintptr_t ) -gpa_to_vva (dev, vq->desc[idx].addr); +rte_vhost_gpa_to_vva (dev->mem, vq->desc[idx].addr);if (unlikely (!descs))return -1 ;
@@ -473,7 +474,7 @@ static inline int __attribute__((always_inline))if (unlikely (m ==NULL ))return -1 ; - desc_addr =gpa_to_vva (dev, buf_vec[vec_idx].buf_addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, buf_vec[vec_idx].buf_addr);if (buf_vec[vec_idx].buf_len < dev->vhost_hlen || !desc_addr)return -1 ;
@@ -495,7 +496,8 @@ static inline int __attribute__((always_inline))/* done with current desc buf, get the next one */ if (desc_avail ==0 ) { vec_idx++; - desc_addr =gpa_to_vva (dev, buf_vec[vec_idx].buf_addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, + buf_vec[vec_idx].buf_addr);if (unlikely (!desc_addr))return -1 ;
@@ -798,7 +800,7 @@ static inline int __attribute__((always_inline)) (desc->flags & VRING_DESC_F_INDIRECT))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -818,7 +820,7 @@ static inline int __attribute__((always_inline))if (unlikely (desc->flags &VRING_DESC_F_INDIRECT ))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -882,7 +884,7 @@ static inline int __attribute__((always_inline))if (unlikely (desc->flags &VRING_DESC_F_INDIRECT ))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -1113,7 +1115,8 @@ static inline bool __attribute__((always_inline))rte_prefetch0 (&vq->desc[desc_indexes[i +1 ]]);if (vq->desc[desc_indexes[i]].flags &VRING_DESC_F_INDIRECT ) { - desc = (struct vring_desc *)(uintptr_t )gpa_to_vva (dev, + desc = (struct vring_desc *)(uintptr_t ) +rte_vhost_gpa_to_vva (dev->mem, vq->desc[desc_indexes[i]].addr);if (unlikely (!desc))break ;
Signature · 1 line
1.9.0
PATCH v2 9/22 vhost: turn queue pair to vring
In reply to Yuanhan LiuThe queue pair is very virtio-net specific, other devices don't have such concept. To make it generic, we should log the number of vrings instead of the number of queue pairs.
This patch just does a simple convert, a later patch would export the number of vrings to applications.
---
v2: enable all vrings by unconditionally
--- lib/librte_vhost/vhost.c | 80 +++++++++++++++---------------------------- lib/librte_vhost/vhost.h | 4 +-- lib/librte_vhost/vhost_user.c | 28 +++++---------- lib/librte_vhost/virtio_net.c | 10 +++--- 4 files changed, 42 insertions(+), 80 deletions(-)
lib/librte_vhost/vhost.c +27 -53
@@ -84,10 +84,8 @@ struct virtio_net *vhost_backend_cleanup (dev); -for (i =0 ; i < dev->virt_qp_nb; i++) { -cleanup_vq (dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ], destroy); -cleanup_vq (dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ], destroy); - } +for (i =0 ; i < dev->nr_vring; i++) +cleanup_vq (dev->virtqueue[i], destroy); }/*
@@ -97,24 +95,21 @@ struct virtio_net * free_device(struct virtio_net *dev) {uint32_t i; -struct vhost_virtqueue *rxq, *txq; +struct vhost_virtqueue *vq; -for (i =0 ; i < dev->virt_qp_nb; i++) { - rxq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ]; - txq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ]; +for (i =0 ; i < dev->nr_vring; i++) { + vq = dev->virtqueue[i]; -rte_free (rxq->shadow_used_ring); -rte_free (txq->shadow_used_ring); +rte_free (vq->shadow_used_ring); -/* rxq and txq are allocated together as queue-pair */ -rte_free (rxq); +rte_free (vq); }rte_free (dev); }static void -init_vring_queue (struct vhost_virtqueue *vq,int qp_idx) +init_vring_queue (struct vhost_virtqueue *vq) {memset (vq,0 ,sizeof (struct vhost_virtqueue ));
@@ -124,69 +119,48 @@ struct virtio_net */* Backends are set to -1 indicating an inactive device. */ vq->backend =-1 ; -/* always set the default vq pair to enabled */ -if (qp_idx ==0 ) - vq->enabled =1 ; +/* +* always set the vq to enabled; this is to keep compatibility +* with the old QEMU, whereas there is no SET_VRING_ENABLE message. +*/ + vq->enabled =1 ;TAILQ_INIT (&vq->zmbuf_list); }static void -init_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) -{ -uint32_t base_idx = qp_idx *VIRTIO_QNUM ; - -init_vring_queue (dev->virtqueue[base_idx +VIRTIO_RXQ ], qp_idx); -init_vring_queue (dev->virtqueue[base_idx +VIRTIO_TXQ ], qp_idx); -} - -static void -reset_vring_queue (struct vhost_virtqueue *vq,int qp_idx) +reset_vring_queue (struct vhost_virtqueue *vq) {int callfd; callfd = vq->callfd; -init_vring_queue (vq, qp_idx); +init_vring_queue (vq); vq->callfd = callfd; } -static void -reset_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) -{ -uint32_t base_idx = qp_idx *VIRTIO_QNUM ; - -reset_vring_queue (dev->virtqueue[base_idx +VIRTIO_RXQ ], qp_idx); -reset_vring_queue (dev->virtqueue[base_idx +VIRTIO_TXQ ], qp_idx); -} -int -alloc_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) +alloc_vring_queue (struct virtio_net *dev,uint32_t vring_idx) { -struct vhost_virtqueue *virtqueue =NULL ; -uint32_t virt_rx_q_idx = qp_idx *VIRTIO_QNUM +VIRTIO_RXQ ; -uint32_t virt_tx_q_idx = qp_idx *VIRTIO_QNUM +VIRTIO_TXQ ; +struct vhost_virtqueue *vq; - virtqueue =rte_malloc (NULL , -sizeof (struct vhost_virtqueue ) *VIRTIO_QNUM ,0 ); -if (virtqueue ==NULL ) { + vq =rte_malloc (NULL ,sizeof (struct vhost_virtqueue ),0 ); +if (vq ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"Failed to allocate memory for virt qp:%d.\n" , qp_idx); +"Failed to allocate memory for vring:%u.\n" , vring_idx);return -1 ; } - dev->virtqueue[virt_rx_q_idx] = virtqueue; - dev->virtqueue[virt_tx_q_idx] = virtqueue +VIRTIO_TXQ ; - -init_vring_queue_pair (dev, qp_idx); + dev->virtqueue[vring_idx] = vq; +init_vring_queue (vq); - dev->virt_qp_nb +=1 ; + dev->nr_vring +=1 ;return 0 ; }/* * Reset some variables in device structure, while keeping few -* others untouched, such as vid, ifname, virt_qp_nb: they +* others untouched, such as vid, ifname, nr_vring: they * should be same unless the device is removed. */ void
@@ -198,8 +172,8 @@ struct virtio_net * dev->protocol_features =0 ; dev->flags =0 ; -for (i =0 ; i < dev->virt_qp_nb; i++) -reset_vring_queue_pair (dev, i); +for (i =0 ; i < dev->nr_vring; i++) +reset_vring_queue (dev->virtqueue[i]); }/*
@@ -340,7 +314,7 @@ struct virtio_net *if (dev ==NULL )return 0 ; -return dev->virt_qp_nb; +return dev->nr_vring /2 ; }int
lib/librte_vhost/vhost.h +2 -2
@@ -176,7 +176,7 @@ struct virtio_net {uint16_t vhost_hlen;/* to tell if we need broadcast rarp packet */ rte_atomic16_t broadcast_rarp; -uint32_t virt_qp_nb; +uint32_t nr_vring;int dequeue_zero_copy;struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ];#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
@@ -256,7 +256,7 @@ static inline phys_addr_t __attribute__((always_inline))void reset_device (struct virtio_net *dev);void vhost_destroy_device (int ); -int alloc_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx); +int alloc_vring_queue (struct virtio_net *dev,uint32_t vring_idx);void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid);
lib/librte_vhost/vhost_user.c +8 -20
@@ -227,13 +227,6 @@struct vhost_virtqueue *old_vq, *vq;int ret; -/* -* vq is allocated on pairs, we should try to do realloc -* on first queue of one queue pair only. -*/ -if (index %VIRTIO_QNUM !=0 ) -return dev; - old_dev = dev; vq = old_vq = dev->virtqueue[index];
@@ -251,8 +244,7 @@if (oldnode != newnode) {RTE_LOG (INFO ,VHOST_CONFIG ,"reallocate vq from %d to %d node\n" , oldnode, newnode); - vq =rte_malloc_socket (NULL ,sizeof (*vq) *VIRTIO_QNUM ,0 , - newnode); + vq =rte_malloc_socket (NULL ,sizeof (*vq),0 , newnode);if (!vq)return dev;
@@ -284,7 +276,6 @@ out: dev->virtqueue[index] = vq; - dev->virtqueue[index +1 ] = vq +1 ; vhost_devices[dev->vid] = dev;return dev;
@@ -615,14 +606,13 @@static int virtio_is_ready (struct virtio_net *dev) { -struct vhost_virtqueue *rvq, *tvq; +struct vhost_virtqueue *vq;uint32_t i; -for (i =0 ; i < dev->virt_qp_nb; i++) { - rvq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ]; - tvq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ]; +for (i =0 ; i < dev->nr_vring; i++) { + vq = dev->virtqueue[i]; -if (!vq_is_ready (rvq) || !vq_is_ready (tvq)) { +if (!vq_is_ready (vq)) {RTE_LOG (INFO ,VHOST_CONFIG ,"virtio is not ready for processing.\n" );return 0 ;
@@ -934,7 +924,6 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg) { uint16_t vring_idx; -uint16_t qp_idx;switch (msg->request) {case VHOST_USER_SET_VRING_KICK :
@@ -954,17 +943,16 @@return 0 ; } - qp_idx = vring_idx /VIRTIO_QNUM ; -if (qp_idx >=VHOST_MAX_QUEUE_PAIRS ) { +if (vring_idx >=VHOST_MAX_VRING ) {RTE_LOG (ERR ,VHOST_CONFIG ,"invalid vring index: %u\n" , vring_idx);return -1 ; } -if (dev->virtqueue[qp_idx]) +if (dev->virtqueue[vring_idx])return 0 ; -return alloc_vring_queue_pair (dev, qp_idx); +return alloc_vring_queue (dev, vring_idx); }int
lib/librte_vhost/virtio_net.c +5 -5
@@ -86,9 +86,9 @@ static inline void __attribute__((always_inline)) }static bool -is_valid_virt_queue_idx (uint32_t idx,int is_tx,uint32_t qp_nb) +is_valid_virt_queue_idx (uint32_t idx,int is_tx,uint32_t nr_vring) { -return (is_tx ^ (idx &1 )) ==0 && idx < qp_nb *VIRTIO_QNUM ; +return (is_tx ^ (idx &1 )) ==0 && idx < nr_vring; } static inline void __attribute__((always_inline))
@@ -283,7 +283,7 @@ static inline uint32_t __attribute__((always_inline))uint32_t i, sz;LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__); -if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
@@ -554,7 +554,7 @@ static inline uint32_t __attribute__((always_inline))uint16_t avail_head;LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__); -if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
@@ -1019,7 +1019,7 @@ static inline bool __attribute__((always_inline))if (!dev)return 0 ; -if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
Signature · 1 line
1.9.0
PATCH v2 10/22 vhost: export the number of vrings
In reply to Yuanhan LiuWe used to use rte_vhost_get_queue_num() for telling how many vrings. However, the return value is the number of "queue pairs", which is very virtio-net specific. To make it generic, we should return the number of vrings instead, and let the driver do the proper translation. Say, virtio-net driver could turn it to the number of queue pairs by dividing 2.
Meanwhile, mark rte_vhost_get_queue_num as deprecated.
---
v2: - update release note
--- doc/guides/rel_notes/release_17_05.rst | 3 +++ drivers/net/vhost/rte_eth_vhost.c | 2 +- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 17 +++++++++++++++++ lib/librte_vhost/vhost.c | 11 +++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_17_05.rst +3 -0
@@ -138,6 +138,9 @@ API Changes * The vhost API ``rte_vhost_driver_callback_register(ops)`` takes one more argument: ``rte_vhost_driver_callback_register(path, ops)``. + * The vhost API ``rte_vhost_get_queue_num`` is deprecated, instead, + ``rte_vhost_get_vring_num`` should be used. + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -569,7 +569,7 @@ struct vhost_xstats_name_off { vq->port = eth_dev->data->port_id; } -for (i =0 ; i <rte_vhost_get_queue_num (vid) *VIRTIO_QNUM ; i++) +for (i =0 ; i <rte_vhost_get_vring_num (vid); i++)rte_vhost_enable_guest_notification (vid, i,0 );rte_vhost_get_mtu (vid, ð_dev->data->mtu);
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -40,6 +40,7 @@ DPDK_17.05 { rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; rte_vhost_get_vhost_vring; + rte_vhost_get_vring_num; rte_vhost_gpa_to_vva; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +17 -0
@@ -237,17 +237,34 @@ int rte_vhost_driver_callback_register(const char *path,int rte_vhost_get_numa_node (int vid);/** +* @deprecated * Get the number of queues the device supports. * +* Note this function is deprecated, as it returns a queue pair number, +* which is virtio-net specific. Instead, rte_vhost_get_vring_num should +* be used. +* * @param vid * virtio-net device ID * * @return * The number of queues, 0 on failure */ +__rte_deprecated uint32_t rte_vhost_get_queue_num(int vid);/** +* Get the number of vrings the device supports. +* +* @param vid +* vhost device ID +* +* @return +* The number of vrings, 0 on failure +*/ +uint16_t rte_vhost_get_vring_num (int vid); + +/** * Get the virtio net device's ifname, which is the vhost-user socket * file path. *
lib/librte_vhost/vhost.c +11 -0
@@ -317,6 +317,17 @@ struct virtio_net *return dev->nr_vring /2 ; } +uint16_t +rte_vhost_get_vring_num (int vid) +{ +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return 0 ; + +return dev->nr_vring; +} +int rte_vhost_get_ifname (int vid,char *buf,size_t len) {
Signature · 1 line
1.9.0
PATCH v2 11/22 vhost: move the device ready check at proper place
In reply to Yuanhan LiuCurrently, we check vq->desc, vq->kickfd and vq->callfd to know whether a virtio device is ready or not. However, we only do it when handling SET_VRING_KICK message, which could be wrong if a vhost-user frontend send SET_VRING_KICK first and SET_VRING_CALL later.
To work for all possible vhost-user frontend implementations, we could move the ready check at the end of vhost-user message handler.
Meanwhile, since we do the check more often than before, the "virtio not ready" message is dropped, to not flood the screen.
--- lib/librte_vhost/vhost_user.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-)
lib/librte_vhost/vhost_user.c +18 -22
@@ -609,14 +609,14 @@struct vhost_virtqueue *vq;uint32_t i; +if (dev->nr_vring ==0 ) +return 0 ; +for (i =0 ; i < dev->nr_vring; i++) { vq = dev->virtqueue[i]; -if (!vq_is_ready (vq)) { -RTE_LOG (INFO ,VHOST_CONFIG , -"virtio is not ready for processing.\n" ); +if (!vq_is_ready (vq))return 0 ; - } } RTE_LOG(INFO, VHOST_CONFIG,
@@ -645,10 +645,6 @@ vq->callfd = file.fd; } -/* -* In vhost-user, when we receive kick message, will test whether virtio -* device is ready for packet processing. -*/ static void vhost_user_set_vring_kick (struct virtio_net *dev,struct VhostUserMsg *pmsg) {
@@ -667,20 +663,6 @@if (vq->kickfd >=0 )close (vq->kickfd); vq->kickfd = file.fd; - -if (virtio_is_ready (dev)) { - dev->flags |=VIRTIO_DEV_READY ; - -if (!(dev->flags &VIRTIO_DEV_RUNNING )) { -if (dev->dequeue_zero_copy) { -RTE_LOG (INFO ,VHOST_CONFIG , -"dequeue zero copy is enabled\n" ); - } - -if (dev->notify_ops->new_device (dev->vid) ==0 ) - dev->flags |=VIRTIO_DEV_RUNNING ; - } - } } static void
@@ -1102,5 +1084,19 @@send_vhost_message (fd, &msg); } +if (!(dev->flags &VIRTIO_DEV_RUNNING ) &&virtio_is_ready (dev)) { + dev->flags |=VIRTIO_DEV_READY ; + +if (!(dev->flags &VIRTIO_DEV_RUNNING )) { +if (dev->dequeue_zero_copy) { +RTE_LOG (INFO ,VHOST_CONFIG , +"dequeue zero copy is enabled\n" ); + } + +if (dev->notify_ops->new_device (dev->vid) ==0 ) + dev->flags |=VIRTIO_DEV_RUNNING ; + } + } +return 0 ; }
Signature · 1 line
1.9.0
PATCH v2 12/22 vhost: drop the Rx and Tx queue macro
In reply to Yuanhan LiuThey are virtio-net specific and should be defined inside the virtio-net driver.
---
v2: - update release note
--- doc/guides/rel_notes/release_17_05.rst | 6 ++++++ drivers/net/vhost/rte_eth_vhost.c | 2 ++ examples/tep_termination/main.h | 2 ++ examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 3 --- 5 files changed, 12 insertions(+), 3 deletions(-)
doc/guides/rel_notes/release_17_05.rst +6 -0
@@ -141,6 +141,12 @@ API Changes * The vhost API ``rte_vhost_get_queue_num`` is deprecated, instead, ``rte_vhost_get_vring_num`` should be used. + * Few macros are removed in ``rte_virtio_net.h`` + + * ``VIRTIO_RXQ`` + * ``VIRTIO_TXQ`` + * ``VIRTIO_QNUM`` + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +2 -0
@@ -45,6 +45,8 @@#include "rte_eth_vhost.h" +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +#define ETH_VHOST_IFACE_ARG "iface"#define ETH_VHOST_QUEUES_ARG "queues"#define ETH_VHOST_CLIENT_ARG "client"
examples/tep_termination/main.h +2 -0
@@ -54,6 +54,8 @@/* Max number of devices. Limited by the application. */ #define MAX_DEVICES 64 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +/* Per-device statistics struct */ struct device_statistics {uint64_t tx_total;
examples/vhost/main.h +2 -0
@@ -41,6 +41,8 @@#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2#define RTE_LOGTYPE_VHOST_PORT RTE_LOGTYPE_USER3 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +struct device_statistics {uint64_t tx;uint64_t tx_total;
lib/librte_vhost/rte_virtio_net.h +0 -3
@@ -55,9 +55,6 @@#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)#define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2) -/* Enum for virtqueue management. */ -enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; -/** * Information relating to memory regions including offsets to * addresses in QEMUs memory file.
Signature · 1 line
1.9.0
PATCH v2 13/22 vhost: do not include net specific headers
In reply to Yuanhan LiuInclude it internally, at vhost.h.
---
v2: - update release note
--- doc/guides/rel_notes/release_17_05.rst | 7 +++++++ examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 4 ---- lib/librte_vhost/vhost.h | 4 ++++ 4 files changed, 13 insertions(+), 4 deletions(-)
doc/guides/rel_notes/release_17_05.rst +7 -0
@@ -147,6 +147,13 @@ API Changes * ``VIRTIO_TXQ`` * ``VIRTIO_QNUM`` + * Few net specific header files are removed in ``rte_virtio_net.h`` + + * ``linux/virtio_net.h`` + * ``sys/socket.h`` + * ``linux/if.h`` + * ``rte_ether.h`` + ABI Changes -----------
examples/vhost/main.h +2 -0
@@ -36,6 +36,8 @@#include <sys/queue.h> +#include <rte_ether.h> +/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2
lib/librte_vhost/rte_virtio_net.h +0 -4
@@ -42,14 +42,10 @@#include <stdint.h> #include <linux/vhost.h> #include <linux/virtio_ring.h> -#include <linux/virtio_net.h> #include <sys/eventfd.h> -#include <sys/socket.h> -#include <linux/if.h> #include <rte_memory.h> #include <rte_mempool.h> -#include <rte_ether.h> #define RTE_VHOST_USER_CLIENT (1ULL << 0)#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)
lib/librte_vhost/vhost.h +4 -0
@@ -39,8 +39,12 @@#include <sys/queue.h> #include <unistd.h> #include <linux/vhost.h> +#include <linux/virtio_net.h> +#include <sys/socket.h> +#include <linux/if.h> #include <rte_log.h> +#include <rte_ether.h> #include "rte_virtio_net.h"
Signature · 1 line
1.9.0
PATCH v2 14/22 vhost: rename device ops struct
In reply to Yuanhan Liurename "virtio_net_device_ops" to "vhost_device_ops", to not let it be virtio-net specific.
--- doc/guides/prog_guide/vhost_lib.rst | 2 +- doc/guides/rel_notes/release_17_05.rst | 3 +++ drivers/net/vhost/rte_eth_vhost.c | 2 +- examples/tep_termination/main.c | 2 +- examples/vhost/main.c | 2 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_virtio_net.h | 4 ++-- lib/librte_vhost/socket.c | 6 +++--- lib/librte_vhost/vhost.h | 4 ++-- 9 files changed, 15 insertions(+), 12 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +1 -1
@@ -122,7 +122,7 @@ The following is an overview of some key Vhost API functions: starts an infinite loop, therefore it should be called in a dedicated thread. -* ``rte_vhost_driver_callback_register(path, virtio_net_device_ops)`` +* ``rte_vhost_driver_callback_register(path, vhost_device_ops)`` This function registers a set of callbacks, to let DPDK applications take the appropriate action when some events happen. The following events are
doc/guides/rel_notes/release_17_05.rst +3 -0
@@ -154,6 +154,9 @@ API Changes * ``linux/if.h`` * ``rte_ether.h`` + * The vhost struct ``virtio_net_device_ops`` is renamed to + ``vhost_device_ops`` + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -671,7 +671,7 @@ struct vhost_xstats_name_off {return 0 ; } -static struct virtio_net_device_ops vhost_ops = { +static struct vhost_device_ops vhost_ops = { .new_device = new_device, .destroy_device = destroy_device, .vring_state_changed = vring_state_changed,
examples/tep_termination/main.c +1 -1
@@ -1081,7 +1081,7 @@ static inline void __attribute__((always_inline))* These callback allow devices to be added to the data core when configuration * has been fully complete. */ -static const struct virtio_net_device_ops virtio_net_device_ops = { +static const struct vhost_device_ops virtio_net_device_ops = { .new_device = new_device, .destroy_device = destroy_device, };
examples/vhost/main.c +1 -1
@@ -1270,7 +1270,7 @@ static inline void __attribute__((always_inline))* These callback allow devices to be added to the data core when configuration * has been fully complete. */ -static const struct virtio_net_device_ops virtio_net_device_ops = +static const struct vhost_device_ops virtio_net_device_ops = { .new_device = new_device, .destroy_device = destroy_device,
lib/librte_vhost/Makefile +1 -1
@@ -36,7 +36,7 @@ LIB = librte_vhost.a EXPORT_MAP := rte_vhost_version.map -LIBABIVER := 3 +LIBABIVER := 4 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -D_FILE_OFFSET_BITS=64 CFLAGS += -I vhost_user
lib/librte_vhost/rte_virtio_net.h +2 -2
@@ -87,7 +87,7 @@ struct rte_vhost_vring {/** * Device and vring operations. */ -struct virtio_net_device_ops { +struct vhost_device_ops {int (*new_device)(int vid);/**< Add device. */ void (*destroy_device)(int vid);/**< Remove device. */
@@ -198,7 +198,7 @@ static inline uint64_t __attribute__((always_inline))/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path, -struct virtio_net_device_ops const *const ops); +struct vhost_device_ops const *const ops);/* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start (void );
lib/librte_vhost/socket.c +3 -3
@@ -74,7 +74,7 @@ struct vhost_user_socket {uint64_t supported_features;uint64_t features; -struct virtio_net_device_ops const *notify_ops; +struct vhost_device_ops const *notify_ops; };struct vhost_user_connection {
@@ -725,7 +725,7 @@ struct vhost_user_reconnect_list {*/ int rte_vhost_driver_callback_register (const char *path, -struct virtio_net_device_ops const *const ops) +struct vhost_device_ops const *const ops) {struct vhost_user_socket *vsocket;
@@ -738,7 +738,7 @@ struct vhost_user_reconnect_list {return vsocket ?0 :-1 ; } -struct virtio_net_device_ops const * +struct vhost_device_ops const *vhost_driver_callback_get (const char *path) {struct vhost_user_socket *vsocket;
lib/librte_vhost/vhost.h +2 -2
@@ -191,7 +191,7 @@ struct virtio_net {struct ether_addr mac;uint16_t mtu; -struct virtio_net_device_ops const *notify_ops; +struct vhost_device_ops const *notify_ops;uint32_t nr_guest_pages;uint32_t max_guest_pages;
@@ -265,7 +265,7 @@ static inline phys_addr_t __attribute__((always_inline))void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid); -struct virtio_net_device_ops const *vhost_driver_callback_get (const char *path); +struct vhost_device_ops const *vhost_driver_callback_get (const char *path);/* * Backend-specific cleanup.
Signature · 1 line
1.9.0
PATCH v2 15/22 vhost: rename virtio-net to vhost
In reply to Yuanhan LiuRename "virtio-net" to "vhost" in the API comments and vhost prog guide.
--- doc/guides/prog_guide/vhost_lib.rst | 6 +++--- lib/librte_vhost/rte_virtio_net.h | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +3 -3
@@ -130,12 +130,12 @@ The following is an overview of some key Vhost API functions: * ``new_device(int vid)`` - This callback is invoked when a virtio net device becomes ready. ``vid`` - is the virtio net device ID. + This callback is invoked when a virtio device becomes ready. ``vid`` + is the vhost device ID. * ``destroy_device(int vid)`` - This callback is invoked when a virtio net device shuts down (or when the + This callback is invoked when a virtio device shuts down (or when the vhost connection is broken). * ``vring_state_changed(int vid, uint16_t queue_id, int enable)``
lib/librte_vhost/rte_virtio_net.h +7 -7
@@ -222,7 +222,7 @@ int rte_vhost_driver_callback_register(const char *path,* is allocated. * * @param vid -* virtio-net device ID +* vhost device ID * * @return * The numa node, -1 on failure
@@ -234,11 +234,11 @@ int rte_vhost_driver_callback_register(const char *path,* Get the number of queues the device supports. * * Note this function is deprecated, as it returns a queue pair number, -* which is virtio-net specific. Instead, rte_vhost_get_vring_num should +* which is vhost specific. Instead, rte_vhost_get_vring_num should * be used. * * @param vid -* virtio-net device ID +* vhost device ID * * @return * The number of queues, 0 on failure
@@ -262,7 +262,7 @@ int rte_vhost_driver_callback_register(const char *path,* file path. * * @param vid -* virtio-net device ID +* vhost device ID * @param buf * The buffer to stored the queried ifname * @param len
@@ -277,7 +277,7 @@ int rte_vhost_driver_callback_register(const char *path,* Get how many avail entries are left in the queue * * @param vid -* virtio-net device ID +* vhost device ID * @param queue_id * virtio queue index *
@@ -292,7 +292,7 @@ int rte_vhost_driver_callback_register(const char *path,* count is returned to indicate the number of packets that were succesfully * added to the RX queue. * @param vid -* virtio-net device ID +* vhost device ID * @param queue_id * virtio queue index in mq case * @param pkts
@@ -310,7 +310,7 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,* construct host mbufs, copies guest buffer content to host mbufs and * store them in pkts to be processed. * @param vid -* virtio-net device +* vhost device ID * @param queue_id * virtio queue index in mq case * @param mbuf_pool
Signature · 1 line
1.9.0
PATCH v2 16/22 vhost: add features changed callback
In reply to Yuanhan LiuFeatures could be changed after the feature negotiation. For example, VHOST_F_LOG_ALL will be set/cleared at the start/end of live migration, respecitively. Thus, we need a new callback to inform the application on such change.
--- doc/guides/prog_guide/vhost_lib.rst | 6 ++++++ lib/librte_vhost/rte_virtio_net.h | 10 +++++++++- lib/librte_vhost/vhost_user.c | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-)
doc/guides/prog_guide/vhost_lib.rst +6 -0
@@ -143,6 +143,12 @@ The following is an overview of some key Vhost API functions: This callback is invoked when a specific queue's state is changed, for example to enabled or disabled. + * ``features_changed(int vid, uint64_t features)`` + + This callback is invoked when the features is changed. For example, + ``VHOST_F_LOG_ALL`` will be set/cleared at the start/end of live + migration, respectively. + * ``rte_vhost_enqueue_burst(vid, queue_id, pkts, count)`` Transmits (enqueues) ``count`` packets from host to guest.
lib/librte_vhost/rte_virtio_net.h +9 -1
@@ -93,7 +93,15 @@ struct vhost_device_ops {int (*vring_state_changed)(int vid,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ -void *reserved[5 ];/**< Reserved for future extension */ +/** +* Features could be changed after the feature negotiation. +* For example, VHOST_F_LOG_ALL will be set/cleared at the +* start/end of live migration, respectively. This callback +* is used to inform the application on such change. +*/ +int (*features_changed)(int vid,uint64_t features); + +void *reserved[4 ];/**< Reserved for future extension */ };/**
lib/librte_vhost/vhost_user.c +5 -0
@@ -161,6 +161,11 @@if (features & ~rte_vhost_driver_get_features (dev->ifname))return -1 ; +if ((dev->flags &VIRTIO_DEV_RUNNING ) && dev->features != features) { +if (dev->notify_ops->features_changed) + dev->notify_ops->features_changed (dev->vid, features); + } + dev->features = features;if (dev->features & ((1 <<VIRTIO_NET_F_MRG_RXBUF ) | (1ULL <<VIRTIO_F_VERSION_1 ))) {
Signature · 1 line
1.9.0
PATCH v2 17/22 vhost: export APIs for live migration support
In reply to Yuanhan LiuExport few APIs for the vhost-user driver to log the guest memory writes, which is a must for live migration support.
This patch basically moves vhost_log_write() and vhost_log_used_vring() into vhost.h and then add an wrapper (the public API) to them.
--- lib/librte_vhost/rte_vhost_version.map | 2 ++ lib/librte_vhost/rte_virtio_net.h | 43 ++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 31 ++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 38 ++++++++++++++++++++++++++++++ lib/librte_vhost/virtio_net.c | 36 ---------------------------- 5 files changed, 114 insertions(+), 36 deletions(-)
lib/librte_vhost/rte_vhost_version.map +2 -0
@@ -42,5 +42,7 @@ DPDK_17.05 { rte_vhost_get_vhost_vring; rte_vhost_get_vring_num; rte_vhost_gpa_to_vva; + rte_vhost_log_used_vring; + rte_vhost_log_write; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +43 -0
49 lines not on this page · raw message
lib/librte_vhost/vhost.c +31 -0
@@ -443,3 +443,34 @@ struct virtio_net * dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ;return 0 ; } + +void +rte_vhost_log_write (int vid,uint64_t addr,uint64_t len) +{ +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return ; + +vhost_log_write (dev, addr, len); +} + +void +rte_vhost_log_used_vring (int vid,uint16_t vring_idx, +uint64_t offset,uint64_t len) +{ +struct virtio_net *dev; +struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (dev ==NULL ) +return ; + +if (vring_idx >=VHOST_MAX_VRING ) +return ; + vq = dev->virtqueue[vring_idx]; +if (!vq) +return ; + +vhost_log_used_vring (dev, vq, offset, len); +}
lib/librte_vhost/vhost.h +38 -0
@@ -198,6 +198,44 @@ struct virtio_net {struct guest_page *guest_pages; } __rte_cache_aligned; + +#define VHOST_LOG_PAGE 4096 + +static inline void __attribute__((always_inline)) +vhost_log_page (uint8_t *log_base,uint64_t page) +{ + log_base[page /8 ] |=1 << (page %8 ); +} + +static inline void __attribute__((always_inline)) +vhost_log_write (struct virtio_net *dev,uint64_t addr,uint64_t len) +{ +uint64_t page; + +if (likely (((dev->features & (1ULL <<VHOST_F_LOG_ALL )) ==0 ) || + !dev->log_base || !len)) +return ; + +if (unlikely (dev->log_size <= ((addr + len -1 ) /VHOST_LOG_PAGE /8 ))) +return ; + +/* To make sure guest memory updates are committed before logging */ +rte_smp_wmb (); + + page = addr /VHOST_LOG_PAGE ; +while (page *VHOST_LOG_PAGE < addr + len) { +vhost_log_page ((uint8_t *)(uintptr_t )dev->log_base, page); + page +=1 ; + } +} + +static inline void __attribute__((always_inline)) +vhost_log_used_vring (struct virtio_net *dev,struct vhost_virtqueue *vq, +uint64_t offset,uint64_t len) +{ +vhost_log_write (dev, vq->log_guest_addr + offset, len); +} +/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
lib/librte_vhost/virtio_net.c +0 -36
@@ -48,42 +48,6 @@#include "vhost.h" #define MAX_PKT_BURST 32 -#define VHOST_LOG_PAGE 4096 - -static inline void __attribute__((always_inline)) -vhost_log_page (uint8_t *log_base,uint64_t page) -{ - log_base[page /8 ] |=1 << (page %8 ); -} - -static inline void __attribute__((always_inline)) -vhost_log_write (struct virtio_net *dev,uint64_t addr,uint64_t len) -{ -uint64_t page; - -if (likely (((dev->features & (1ULL <<VHOST_F_LOG_ALL )) ==0 ) || - !dev->log_base || !len)) -return ; - -if (unlikely (dev->log_size <= ((addr + len -1 ) /VHOST_LOG_PAGE /8 ))) -return ; - -/* To make sure guest memory updates are committed before logging */ -rte_smp_wmb (); - - page = addr /VHOST_LOG_PAGE ; -while (page *VHOST_LOG_PAGE < addr + len) { -vhost_log_page ((uint8_t *)(uintptr_t )dev->log_base, page); - page +=1 ; - } -} - -static inline void __attribute__((always_inline)) -vhost_log_used_vring (struct virtio_net *dev,struct vhost_virtqueue *vq, -uint64_t offset,uint64_t len) -{ -vhost_log_write (dev, vq->log_guest_addr + offset, len); -}static bool is_valid_virt_queue_idx (uint32_t idx,int is_tx,uint32_t nr_vring)
Signature · 1 line
1.9.0
PATCH v2 18/22 vhost: introduce API to start a specific driver
In reply to Yuanhan LiuWe used to use rte_vhost_driver_session_start() to trigger the vhost-user session. It takes no argument, thus it's a global trigger. And it could be problematic.
The issue is, currently, rte_vhost_driver_register(path, flags) actually tries to put it into the session loop (by fdset_add). However, it needs a set of APIs to set a vhost-user driver properly:
* rte_vhost_driver_register(path, flags);
* rte_vhost_driver_set_features(path, features);
* rte_vhost_driver_callback_register(path, vhost_device_ops);
If a new vhost-user driver is registered after the trigger (think OVS-DPDK that could add a port dynamically from cmdline), the current code will effectively starts the session for the new driver just after the first API rte_vhost_driver_register() is invoked, leaving later calls taking no effect at all.
To handle the case properly, this patch introduce a new API, rte_vhost_driver_start(path), to trigger a specific vhost-user driver. To do that, the rte_vhost_driver_register(path, flags) is simplified to create the socket only and let rte_vhost_driver_start(path) to actually put it into the session loop.
Meanwhile, the rte_vhost_driver_session_start is removed: we could hide the session thread internally (create the thread if it has not been created). This would also simplify the application.
NOTE: the API order in prog guide is slightly adjusted for showing the correct invoke order.
--- doc/guides/prog_guide/vhost_lib.rst | 24 +++++------ doc/guides/rel_notes/release_17_05.rst | 8 ++++ drivers/net/vhost/rte_eth_vhost.c | 50 ++------------------- examples/tep_termination/main.c | 8 +++- examples/vhost/main.c | 9 +++- lib/librte_vhost/fd_man.c | 9 ++-- lib/librte_vhost/fd_man.h | 2 +- lib/librte_vhost/rte_vhost_version.map | 2 +- lib/librte_vhost/rte_virtio_net.h | 15 ++++++- lib/librte_vhost/socket.c | 79 +++++++++++++++++++--------------- 10 files changed, 104 insertions(+), 102 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +11 -13
@@ -116,12 +116,6 @@ The following is an overview of some key Vhost API functions: vhost-user driver could be vhost-user net, yet it could be something else, say, vhost-user SCSI. -* ``rte_vhost_driver_session_start()`` - - This function starts the vhost session loop to handle vhost messages. It - starts an infinite loop, therefore it should be called in a dedicated - thread. - * ``rte_vhost_driver_callback_register(path, vhost_device_ops)`` This function registers a set of callbacks, to let DPDK applications take
@@ -149,6 +143,17 @@ The following is an overview of some key Vhost API functions: ``VHOST_F_LOG_ALL`` will be set/cleared at the start/end of live migration, respectively. +* ``rte_vhost_driver_disable/enable_features(path, features))`` + + This function disables/enables some features. For example, it can be used to + disable mergeable buffers and TSO features, which both are enabled by + default. + +* ``rte_vhost_driver_start(path)`` + + This function triggers the vhost-user negotiation. It should be invoked at + the end of initializing a vhost-user driver. + * ``rte_vhost_enqueue_burst(vid, queue_id, pkts, count)`` Transmits (enqueues) ``count`` packets from host to guest.
@@ -157,13 +162,6 @@ The following is an overview of some key Vhost API functions: Receives (dequeues) ``count`` packets from guest, and stored them at ``pkts``. -* ``rte_vhost_driver_disable/enable_features(path, features))`` - - This function disables/enables some features. For example, it can be used to - disable mergeable buffers and TSO features, which both are enabled by - default. - - Vhost-user Implementations --------------------------
doc/guides/rel_notes/release_17_05.rst +8 -0
@@ -57,6 +57,11 @@ New Features * Enable Vhost PMD's MTU get feature. * Get max MTU value from host in Virtio PMD +* **Made the vhost lib be a generic vhost-user lib.** + + Now it could be used to implement any other vhost-user drivers, such + as, vhost-user SCSI. + Resolved Issues ---------------
@@ -157,6 +162,9 @@ API Changes * The vhost struct ``virtio_net_device_ops`` is renamed to ``vhost_device_ops`` + * The vhost API ``rte_vhost_driver_session_start`` is removed. Instead, + ``rte_vhost_driver_start`` should be used. + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +4 -46
74 lines not on this page · raw message
examples/tep_termination/main.c +7 -1
@@ -1263,7 +1263,13 @@ static inline void __attribute__((always_inline)) "failed to register vhost driver callbacks.\n"); } -rte_vhost_driver_session_start (); +if (rte_vhost_driver_start (dev_basename) <0 ) { +rte_exit (EXIT_FAILURE , +"failed to start vhost driver.\n" ); + } + +RTE_LCORE_FOREACH_SLAVE (lcore_id) +rte_eal_wait_lcore (lcore_id);return 0 ; }
examples/vhost/main.c +8 -1
@@ -1545,9 +1545,16 @@ static inline void __attribute__((always_inline))rte_exit (EXIT_FAILURE ,"failed to register vhost driver callbacks.\n" ); } + +if (rte_vhost_driver_start (file) <0 ) { +rte_exit (EXIT_FAILURE , +"failed to start vhost driver.\n" ); + } } -rte_vhost_driver_session_start (); +RTE_LCORE_FOREACH_SLAVE (lcore_id) +rte_eal_wait_lcore (lcore_id); +return 0 ; }
lib/librte_vhost/fd_man.c +6 -3
@@ -210,8 +210,8 @@* will wait until the flag is reset to zero(which indicates the callback is * finished), then it could free the context after fdset_del. */ -void -fdset_event_dispatch (struct fdset *pfdset) +void * +fdset_event_dispatch (void *arg) {int i;struct pollfd *pfd;
@@ -221,9 +221,10 @@int fd, numfds;int remove1, remove2;int need_shrink; +struct fdset *pfdset = arg;if (pfdset ==NULL ) -return ; +return NULL ;while (1 ) {
@@ -294,4 +295,6 @@if (need_shrink)fdset_shrink (pfdset); } + +return NULL ; }
lib/librte_vhost/fd_man.h +1 -1
@@ -64,6 +64,6 @@ int fdset_add(struct fdset *pfdset, int fd,void *fdset_del (struct fdset *pfdset,int fd); -void fdset_event_dispatch (struct fdset *pfdset); +void *fdset_event_dispatch (void *arg);#endif
lib/librte_vhost/rte_vhost_version.map +1 -1
@@ -4,7 +4,6 @@ DPDK_2.0 { rte_vhost_dequeue_burst; rte_vhost_driver_callback_register; rte_vhost_driver_register; - rte_vhost_driver_session_start; rte_vhost_enable_guest_notification; rte_vhost_enqueue_burst;
@@ -35,6 +34,7 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_driver_start; rte_vhost_get_mem_table; rte_vhost_get_mtu; rte_vhost_get_negotiated_features
lib/librte_vhost/rte_virtio_net.h +13 -2
@@ -250,8 +250,19 @@ void rte_vhost_log_used_vring(int vid, uint16_t vring_idx,/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path,struct vhost_device_ops const *const ops); -/* Start vhost driver session blocking loop. */ -int rte_vhost_driver_session_start (void ); + +/** +* +* Start the vhost-user driver. +* +* This function triggers the vhost-user negotiation. +* +* @param path +* The vhost-user socket file path +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_driver_start (const char *path);/** * Get the MTU value of the device if set in QEMU.
lib/librte_vhost/socket.c +45 -34
168 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v2 19/22 vhost: rename header file
In reply to Yuanhan LiuRename "rte_virtio_net.h" to "rte_vhost.h", to not let it be virtio net specific.
--- doc/guides/rel_notes/deprecation.rst | 9 - doc/guides/rel_notes/release_17_05.rst | 3 + drivers/net/vhost/rte_eth_vhost.c | 2 +- drivers/net/vhost/rte_eth_vhost.h | 2 +- examples/tep_termination/main.c | 2 +- examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/main.c | 2 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_vhost.h | 421 +++++++++++++++++++++++++++++++++ lib/librte_vhost/rte_virtio_net.h | 421 --------------------------------- lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 2 +- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 2 +- 14 files changed, 434 insertions(+), 440 deletions(-) create mode 100644 lib/librte_vhost/rte_vhost.h delete mode 100644 lib/librte_vhost/rte_virtio_net.h
doc/guides/rel_notes/deprecation.rst +0 -9
@@ -95,15 +95,6 @@ Deprecation Notices Target release for removal of the legacy API will be defined once most PMDs have switched to rte_flow. -* vhost: API/ABI changes are planned for 17.05, for making DPDK vhost library - generic enough so that applications can build different vhost-user drivers - (instead of vhost-user net only) on top of that. - Specifically, ``virtio_net_device_ops`` will be renamed to ``vhost_device_ops``. - Correspondingly, some API's parameter need be changed. Few more functions also - need be reworked to let it be device aware. For example, different virtio device - has different feature set, meaning functions like ``rte_vhost_feature_disable`` - need be changed. Last, file rte_virtio_net.h will be renamed to rte_vhost.h. - * ABI changes are planned for 17.05 in the ``rte_cryptodev_ops`` structure. A pointer to a rte_cryptodev_config structure will be added to the function prototype ``cryptodev_configure_t``, as a new parameter.
doc/guides/rel_notes/release_17_05.rst +3 -0
@@ -165,6 +165,9 @@ API Changes * The vhost API ``rte_vhost_driver_session_start`` is removed. Instead, ``rte_vhost_driver_start`` should be used. + * The vhost public header file ``rte_virtio_net.h`` is renamed to + ``rte_vhost.h`` + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -40,7 +40,7 @@#include <rte_memcpy.h> #include <rte_vdev.h> #include <rte_kvargs.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_spinlock.h> #include "rte_eth_vhost.h"
drivers/net/vhost/rte_eth_vhost.h +1 -1
@@ -41,7 +41,7 @@#include <stdint.h> #include <stdbool.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> /* * Event description.
examples/tep_termination/main.c +1 -1
@@ -49,7 +49,7 @@#include <rte_log.h> #include <rte_string_fns.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include "main.h" #include "vxlan.h"
examples/tep_termination/vxlan_setup.c +1 -1
@@ -49,7 +49,7 @@#include <rte_tcp.h> #include "main.h" -#include "rte_virtio_net.h" +#include "rte_vhost.h" #include "vxlan.h" #include "vxlan_setup.h"
examples/vhost/main.c +1 -1
@@ -49,7 +49,7 @@#include <rte_log.h> #include <rte_string_fns.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_ip.h> #include <rte_tcp.h>
lib/librte_vhost/Makefile +1 -1
@@ -51,7 +51,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c socket.c vhost.c vhost_user.c \ virtio_net.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h +SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h # dependencies DEPDIRS-$(CONFIG_RTE_LIBRTE_VHOST) += lib/librte_eal
lib/librte_vhost/rte_vhost.h new file +421 -0
421 lines not on this page · raw message
lib/librte_vhost/rte_virtio_net.h deleted +0 -421
421 lines not on this page · raw message
lib/librte_vhost/vhost.c +1 -1
@@ -45,7 +45,7 @@#include <rte_string_fns.h> #include <rte_memory.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include "vhost.h"
lib/librte_vhost/vhost.h +1 -1
@@ -46,7 +46,7 @@#include <rte_log.h> #include <rte_ether.h> -#include "rte_virtio_net.h" +#include "rte_vhost.h" /* Used to indicate that the device is running on a data core */ #define VIRTIO_DEV_RUNNING 1
lib/librte_vhost/vhost_user.h +1 -1
@@ -37,7 +37,7 @@#include <stdint.h> #include <linux/vhost.h> -#include "rte_virtio_net.h" +#include "rte_vhost.h" /* refer to hw/virtio/vhost-user.c */
lib/librte_vhost/virtio_net.c +1 -1
@@ -39,7 +39,7 @@#include <rte_memcpy.h> #include <rte_ether.h> #include <rte_ip.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_tcp.h> #include <rte_udp.h> #include <rte_sctp.h>
Signature · 1 line
1.9.0
PATCH v2 20/22 vhost: workaround the build dependency on mbuf header
In reply to Yuanhan Liurte_mbuf struct is something more likely will be used only in vhost-user net driver, while we have made vhost-user generic enough that it can be used for implementing other drivers (such as vhost-user SCSI), they have also include <rte_mbuf.h>. Otherwise, the build will be broken.
We could workaround it by using forward declaration, so that other non-net drivers won't need include <rte_mbuf.h>.
--- lib/librte_vhost/rte_vhost.h | 2 ++ 1 file changed, 2 insertions(+)
lib/librte_vhost/rte_vhost.h +2 -0
@@ -348,6 +348,8 @@ int rte_vhost_driver_callback_register(const char *path,*/ uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id); +struct rte_mbuf ; +struct rte_mempool ;/** * This function adds buffers to the virtio devices RX virtqueue. Buffers can * be received from the physical port or from another virtual device. A packet
Signature · 1 line
1.9.0
PATCH v2 21/22 vhost: do not destroy device on repeat mem table message
In reply to Yuanhan LiuIt doesn't make any sense to invoke destroy_device() callback at while handling SET_MEM_TABLE message.
Quoted 1 line
From the vhost-user spec, it's the
GET_VRING_BASEmessage indicates
the end of a vhost device: the destroy_device() should be invoked from there (luckily, we already did that).
--- lib/librte_vhost/vhost_user.c | 6 ------ 1 file changed, 6 deletions(-)
lib/librte_vhost/vhost_user.c +0 -6
@@ -496,12 +496,6 @@uint32_t i;int fd; -/* Remove from the data plane. */ -if (dev->flags &VIRTIO_DEV_RUNNING ) { - dev->flags &= ~VIRTIO_DEV_RUNNING ; - dev->notify_ops->destroy_device (dev->vid); - } -if (dev->mem) {free_mem_region (dev);rte_free (dev->mem);
Signature · 1 line
1.9.0
PATCH v2 22/22 examples/vhost: demonstrate the new generic vhost APIs
In reply to Yuanhan LiuNow DPDK vhost lib has been generic enough, that it can be used to implement any vhost-user drivers.
For example, this patch implements a very simple vhost-user net driver, mainly for demonstrating how to use those generic vhost APIs.
And when the --builtin-net-driver option is used, the example virtio-net driver code will be invoked, instead of the one provided from the vhost library.
--- examples/vhost/Makefile | 2 +- examples/vhost/main.c | 37 +++- examples/vhost/main.h | 29 +++- examples/vhost/virtio_net.c | 405 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 466 insertions(+), 7 deletions(-) create mode 100644 examples/vhost/virtio_net.c
examples/vhost/Makefile +1 -1
@@ -48,7 +48,7 @@ else APP = vhost-switch # all source are stored in SRCS-y -SRCS-y := main.c +SRCS-y := main.c virtio_net.c CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 CFLAGS += $(WERROR_FLAGS)
examples/vhost/main.c +32 -5
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2016 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2017 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -65,7 +65,6 @@#define MBUF_CACHE_SIZE 128#define MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE -#define MAX_PKT_BURST 32/* Max burst size for RX/TX */ #define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ #define BURST_RX_WAIT_US 15/* Defines how long we wait between retries on RX */
@@ -129,6 +128,8 @@static int client_mode;static int dequeue_zero_copy; +static int builtin_net_driver; +/* Specify timeout (in useconds) between retries on RX. */ static uint32_t burst_rx_delay_time =BURST_RX_WAIT_US ;/* Specify the number of retries on RX. */
@@ -499,6 +500,7 @@ struct mbuf_table { {"tso", required_argument, NULL, 0}, {"client", no_argument, &client_mode, 1}, {"dequeue-zero-copy", no_argument, &dequeue_zero_copy, 1}, + {"builtin-net-driver", no_argument, &builtin_net_driver, 1}, {NULL, 0, 0, 0}, };
@@ -795,7 +797,12 @@ static inline void __attribute__((always_inline)) {uint16_t ret; - ret =rte_vhost_enqueue_burst (dst_vdev->vid,VIRTIO_RXQ , &m,1 ); +if (builtin_net_driver) { + ret =vs_enqueue_pkts (dst_vdev,VIRTIO_RXQ , &m,1 ); + }else { + ret =rte_vhost_enqueue_burst (dst_vdev->vid,VIRTIO_RXQ , &m,1 ); + } +if (enable_stats) {rte_atomic64_inc (&dst_vdev->stats.rx_total_atomic);rte_atomic64_add (&dst_vdev->stats.rx_atomic, ret);
@@ -1066,8 +1073,13 @@ static inline void __attribute__((always_inline)) } } - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , +if (builtin_net_driver) { + enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , pkts, rx_count); + }else { + enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , + pkts, rx_count); + }if (enable_stats) {rte_atomic64_add (&vdev->stats.rx_total_atomic, rx_count);rte_atomic64_add (&vdev->stats.rx_atomic, enqueue_count);
@@ -1083,8 +1095,13 @@ static inline void __attribute__((always_inline))uint16_t count;uint16_t i; - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , mbuf_pool, +if (builtin_net_driver) { + count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST ); + }else { + count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , + mbuf_pool, pkts,MAX_PKT_BURST ); + }/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1187,6 +1204,9 @@ static inline void __attribute__((always_inline))rte_pause (); } +if (builtin_net_driver) +vs_vhost_net_remove (vdev); +TAILQ_REMOVE (&lcore_info[vdev->coreid].vdev_list, vdev, lcore_vdev_entry);TAILQ_REMOVE (&vhost_dev_list, vdev, global_vdev_entry);
@@ -1235,6 +1255,9 @@ static inline void __attribute__((always_inline)) } vdev->vid = vid; +if (builtin_net_driver) +vs_vhost_net_setup (vdev); +TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, global_vdev_entry); vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;
@@ -1513,6 +1536,10 @@ static inline void __attribute__((always_inline))rte_exit (EXIT_FAILURE ,"vhost driver register failure.\n" ); } + +if (builtin_net_driver) +rte_vhost_driver_set_features (file,VIRTIO_NET_FEATURES ); +if (mergeable ==0 ) {rte_vhost_driver_disable_features (file,1ULL <<VIRTIO_NET_F_MRG_RXBUF );
examples/vhost/main.h +28 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2016 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2017 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -43,8 +43,11 @@#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2#define RTE_LOGTYPE_VHOST_PORT RTE_LOGTYPE_USER3 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +#define MAX_PKT_BURST 32/* Max burst size for RX/TX */ +struct device_statistics {uint64_t tx;uint64_t tx_total;
@@ -52,6 +55,12 @@ struct device_statistics {rte_atomic64_t rx_total_atomic; }; +struct vhost_queue { +struct rte_vhost_vring vr; +uint16_t last_avail_idx; +uint16_t last_used_idx; +}; +struct vhost_dev {/**< Number of memory regions for gpa to hpa translation. */ uint32_t nregions_hpa;
@@ -69,9 +78,16 @@ struct vhost_dev {volatile uint8_t remove;int vid; +uint64_t features; +size_t hdr_len; +uint16_t nr_vrings; +struct rte_vhost_memory *mem;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) global_vdev_entry;TAILQ_ENTRY (vhost_dev) lcore_vdev_entry; + +#define MAX_QUEUE_PAIRS 4 +struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned;TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -92,4 +108,15 @@ struct lcore_info { struct vhost_dev_tailq_list vdev_list; }; +/* we implement non-extra virtio net features */ +#define VIRTIO_NET_FEATURES 0 + +void vs_vhost_net_setup (struct vhost_dev *dev); +void vs_vhost_net_remove (struct vhost_dev *dev); +uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c new file +405 -0
405 lines not on this page · raw message
Signature · 1 line
1.9.0
v3 cover vhost: generic vhost API
In reply to Yuanhan LiuThis patchset makes DPDK vhost library generic enough, so that we could build other vhost-user drivers on top of it. For example, SPDK (Storage Performance Development Kit) is trying to enable vhost-user SCSI.
The basic idea is, let DPDK vhost be a vhost-user agent. It stores all the info about the virtio device (i.e. vring address, negotiated features, etc) and let the specific vhost-user driver to fetch them (by the API provided by DPDK vhost lib). With those info being provided, the vhost-user driver then could get/put vring entries, thus, it could exchange data between the guest and host.
The last patch demonstrates how to use these new APIs to implement a very simple vhost-user net driver, without any fancy features enabled.
Change log
==========
v2: - rebase
- updated release note
- updated API comments
- renamed rte_vhost_get_vhost_memory to rte_vhost_get_mem_table
- added a new device callback: features_changed(), bascially for live migration support
- introduced rte_vhost_driver_start() to start a specific driver
- misc fixes
v3: - rebaseon top of vhost-user socket fix
- fix reconnect
- fix shared build
- fix typos
Major API/ABI Changes summary
=============================
- some renames
* "struct virtio_net_device_ops" ==> "struct vhost_device_ops"
* "rte_virtio_net.h" ==> "rte_vhost.h"
- driver related APIs are bond with the socket file
* rte_vhost_driver_set_features(socket_file, features);
* rte_vhost_driver_get_features(socket_file, features);
* rte_vhost_driver_enable_features(socket_file, features)
* rte_vhost_driver_disable_features(socket_file, features)
* rte_vhost_driver_callback_register(socket_file, notify_ops);
* rte_vhost_driver_start(socket_file);
This function replaces rte_vhost_driver_session_start(). Check patch 18 for more information.
- new APIs to fetch guest and vring info
* rte_vhost_get_mem_table(vid, mem);
* rte_vhost_get_negotiated_features(vid);
* rte_vhost_get_vhost_vring(vid, vring_idx, vring);
- new exported structures
* struct rte_vhost_vring
* struct rte_vhost_mem_region
* struct rte_vhost_memory
- a new device ops callback: features_changed().
Some design choices
===================
While making this patchset, I met quite few design choices and here are two of them, with the issue and the reason I made such choices provided. Please let me know if you have any comments (or better ideas).
Export public structures or not
-------------------------------
I made an ABI refactor last time (v16.07): move all the structures internally and let applications use a "vid" to reference the internal struct. With that, I hope we could never worry about the annoying ABI issues.
It works great (and as expected) since then, as far as we only support virito-net, as far as we can handle all the descs inside vhost lib. It becomes problematic when a user wants to implement a vhost-user driver somewhere. For example, it needs do the GPA to VVA translation. Without any structs exported, some functions like gpa_to_vva() can't be inlined. Calling it would be costly, especially it's a function we have to invoke for processing each vring desc.
For that reason, the guest memory regions are exported. With that, the gpa_to_vva could be inlined.
Add helper functions to fetch/update descs or not
-------------------------------------------------
I intended to do it like this way: introduce one function to get @count of descs from a specific vring and another one to update the used descs. It's something like
rte_vhost_vring_get_descs(vid, vring_idx, count, offset, iov, descs);
rte_vhost_vring_update_used_descs(vid, vring_idx, count, offset, descs);With that, vhost-user driver programmer's task would be easier, as he/she doesn't have to parse the descs any more (such as to handle indirect desc).
But judging that virtio 1.1 is just emerged and it proposes a completely ring layout, and most importantly, the vring desc structure is also changed, I'd like to hold the introducation of such two functions. Otherwise, it's very likely the two will be invalid when virtio 1.1 is out. Though I think it may could be addressed with a care design, something like making the IOV generic enough:
struct rte_vhost_iov {
uint64_t gpa;
uint64_t vva;
uint64_t len;
};Instead, I go with the other way: introduce few APIs to export all the vring infos (vring size, vring addr, callfd, etc), and let the vhost-user driver read and update the descs. Those info could be passed to vhost-user driver by introducing one API for each, but for saving few APIs and reducing few calls for the programmer, I packed few key fields into a new structure, so that it can be fetched with one call:
struct rte_vhost_vring {
struct vring_desc *desc;
struct vring_avail *avail;
struct vring_used *used;
uint64_t log_guest_addr;
int callfd;
int kickfd;
uint16_t size;
};When virtio 1.1 comes out, likely a simple change like following would just work:
struct rte_vhost_vring {
union {
struct {
struct vring_desc *desc;
struct vring_avail *avail;
struct vring_used *used;
uint64_t log_guest_addr;
};
struct desc *desc_1_1; /* vring addr for virtio 1.1 */
};
int callfd;
int kickfd;
uint16_t size;
};AFAIK, it's not an ABI breakage. Even if it does, we could introduce a new API to get the virtio 1.1 ring address.
Those fields are the minimum set I got for a specific vring, with the mind it would bring the minimum chance to break ABI for future extension. If we need more info, we could introduce a new API.
OTOH, for getting the best performance, the two functions also have to be inlined ("vid + vring_idx" combo is replaced with "vring"):
rte_vhost_vring_get_descs(vring, count, offset, iov, descs);
rte_vhost_vring_update_used_descs(vring, count, offset, descs);That said, one way or another, we have to export rte_vhost_vring struct. For this reason, I didn't rush into introducing the two APIs.
--yliu
---
Yuanhan Liu (22):
vhost: introduce driver features related APIs net/vhost: remove feature related APIs
vhost: use new APIs to handle features
vhost: make notify ops per vhost driver
vhost: export guest memory regions
vhost: introduce API to fetch negotiated features
vhost: export vhost vring info
vhost: export API to translate gpa to vva
vhost: turn queue pair to vring
vhost: export the number of vrings
vhost: move the device ready check at proper place
vhost: drop the Rx and Tx queue macro
vhost: do not include net specific headers
vhost: rename device ops struct
vhost: rename virtio-net to vhost
vhost: add features changed callback
vhost: export APIs for live migration support
vhost: introduce API to start a specific driver
vhost: rename header file
vhost: workaround the build dependency on mbuf header
vhost: do not destroy device on repeat mem table message examples/vhost: demonstrate the new generic vhost APIs
doc/guides/prog_guide/vhost_lib.rst | 42 +-- doc/guides/rel_notes/deprecation.rst | 9 - doc/guides/rel_notes/release_17_05.rst | 40 +++ drivers/net/vhost/rte_eth_vhost.c | 101 ++----- drivers/net/vhost/rte_eth_vhost.h | 32 +-- drivers/net/vhost/rte_pmd_vhost_version.map | 3 - examples/tep_termination/main.c | 23 +- examples/tep_termination/main.h | 2 + examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/Makefile | 2 +- examples/vhost/main.c | 100 +++++-- examples/vhost/main.h | 33 ++- examples/vhost/virtio_net.c | 405 ++++++++++++++++++++++++++ lib/librte_vhost/Makefile | 4 +- lib/librte_vhost/fd_man.c | 9 +- lib/librte_vhost/fd_man.h | 2 +- lib/librte_vhost/rte_vhost.h | 423 ++++++++++++++++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 16 +- lib/librte_vhost/rte_virtio_net.h | 208 -------------- lib/librte_vhost/socket.c | 227 ++++++++++++--- lib/librte_vhost/vhost.c | 229 ++++++++------- lib/librte_vhost/vhost.h | 113 +++++--- lib/librte_vhost/vhost_user.c | 115 ++++---- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 71 ++--- 25 files changed, 1526 insertions(+), 687 deletions(-) create mode 100644 examples/vhost/virtio_net.c create mode 100644 lib/librte_vhost/rte_vhost.h delete mode 100644 lib/librte_vhost/rte_virtio_net.h
Signature · 1 line
1.9.0
PATCH v3 1/22 vhost: introduce driver features related APIs
Introduce few APIs to set/get/enable/disable driver features.
--- doc/guides/prog_guide/vhost_lib.rst | 10 +++- lib/librte_vhost/rte_vhost_version.map | 4 ++ lib/librte_vhost/rte_virtio_net.h | 51 +++++++++++++++++++ lib/librte_vhost/socket.c | 90 ++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 2 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +8 -2
@@ -53,7 +53,7 @@ vhost library should be able to: Vhost API Overview ------------------ -The following is an overview of the Vhost API functions: +The following is an overview of some key Vhost API functions: * ``rte_vhost_driver_register(path, flags)``
@@ -110,6 +110,12 @@ The following is an overview of the Vhost API functions: of those segments, thus the fewer the segments, the quicker we will get the mapping. NOTE: we may speed it by using tree searching in future. +* ``rte_vhost_driver_set_features(path, features)`` + + This function sets the feature bits the vhost-user driver supports. The + vhost-user driver could be vhost-user net, yet it could be something else, + say, vhost-user SCSI. + * ``rte_vhost_driver_session_start()`` This function starts the vhost session loop to handle vhost messages. It
@@ -145,7 +151,7 @@ The following is an overview of the Vhost API functions: Receives (dequeues) ``count`` packets from guest, and stored them at ``pkts``. -* ``rte_vhost_feature_disable/rte_vhost_feature_enable(feature_mask)`` +* ``rte_vhost_driver_disable/enable_features(path, features))`` This function disables/enables some features. For example, it can be used to disable mergeable buffers and TSO features, which both are enabled by
lib/librte_vhost/rte_vhost_version.map +4 -0
@@ -34,6 +34,10 @@ DPDK_16.07 { DPDK_17.05 { global: + rte_vhost_driver_disable_features; + rte_vhost_driver_enable_features; + rte_vhost_driver_get_features; + rte_vhost_driver_set_features; rte_vhost_get_mtu; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +51 -0
57 lines not on this page · raw message
lib/librte_vhost/socket.c +90 -0
102 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v3 2/22 net/vhost: remove feature related APIs
In reply to Yuanhan LiuThe rte_eth_vhost_feature_disable/enable/get APIs are just a wrapper of rte_vhost_feature_disable/enable/get. However, the later are going to be refactored; it's going to take an extra parameter (socket_file path), to let it be per-device.
Instead of changing those vhost-pmd APIs to adapt to the new vhost APIs, we could simply remove them, and let vdev to serve this purpose. After all, vdev options is better for disabling/enabling some features.
---
v2: - write more informative commit log on why they are removed.
- update release note
--- doc/guides/rel_notes/release_17_05.rst | 7 +++++++ drivers/net/vhost/rte_eth_vhost.c | 25 ------------------------ drivers/net/vhost/rte_eth_vhost.h | 30 ----------------------------- drivers/net/vhost/rte_pmd_vhost_version.map | 3 --- 4 files changed, 7 insertions(+), 58 deletions(-)
doc/guides/rel_notes/release_17_05.rst +7 -0
@@ -129,6 +129,13 @@ API Changes * The LPM ``next_hop`` field is extended from 8 bits to 21 bits for IPv6 while keeping ABI compatibility. + * The following vhost-pmd APIs are removed + + * ``rte_eth_vhost_feature_disable`` + * ``rte_eth_vhost_feature_enable`` + * ``rte_eth_vhost_feature_get`` + + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +0 -25
@@ -965,31 +965,6 @@ struct vhost_xstats_name_off {return 0 ; } -/** -* Disable features in feature_mask. Returns 0 on success. -*/ -int -rte_eth_vhost_feature_disable (uint64_t feature_mask) -{ -return rte_vhost_feature_disable (feature_mask); -} - -/** -* Enable features in feature_mask. Returns 0 on success. -*/ -int -rte_eth_vhost_feature_enable (uint64_t feature_mask) -{ -return rte_vhost_feature_enable (feature_mask); -} - -/* Returns currently supported vhost features */ -uint64_t -rte_eth_vhost_feature_get (void ) -{ -return rte_vhost_feature_get (); -} -static const struct eth_dev_ops ops = { .dev_start = eth_dev_start, .dev_stop = eth_dev_stop,
drivers/net/vhost/rte_eth_vhost.h +0 -30
@@ -43,36 +43,6 @@#include <rte_virtio_net.h> -/** -* Disable features in feature_mask. -* -* @param feature_mask -* Vhost features defined in "linux/virtio_net.h". -* @return -* - On success, zero. -* - On failure, a negative value. -*/ -int rte_eth_vhost_feature_disable (uint64_t feature_mask); - -/** -* Enable features in feature_mask. -* -* @param feature_mask -* Vhost features defined in "linux/virtio_net.h". -* @return -* - On success, zero. -* - On failure, a negative value. -*/ -int rte_eth_vhost_feature_enable (uint64_t feature_mask); - -/** -* Returns currently supported vhost features. -* -* @return -* Vhost features defined in "linux/virtio_net.h". -*/ -uint64_t rte_eth_vhost_feature_get (void ); -/* * Event description. */
drivers/net/vhost/rte_pmd_vhost_version.map +0 -3
@@ -1,9 +1,6 @@ DPDK_16.04 { global: - rte_eth_vhost_feature_disable; - rte_eth_vhost_feature_enable; - rte_eth_vhost_feature_get; rte_eth_vhost_get_queue_event; local: *;
Signature · 1 line
1.9.0
PATCH v3 3/22 vhost: use new APIs to handle features
In reply to Yuanhan Liu---
v3: fix comment typo
--- examples/tep_termination/main.c | 4 +++- examples/vhost/main.c | 43 +++++++++++++++++++++------------- lib/librte_vhost/rte_vhost_version.map | 3 --- lib/librte_vhost/rte_virtio_net.h | 13 ---------- lib/librte_vhost/socket.c | 23 +++++++++++++++++- lib/librte_vhost/vhost.c | 42 --------------------------------- lib/librte_vhost/vhost.h | 21 +++++++++++++++++ lib/librte_vhost/vhost_user.c | 8 +++---- 8 files changed, 77 insertions(+), 80 deletions(-)
examples/tep_termination/main.c +3 -1
@@ -1248,12 +1248,14 @@ static inline void __attribute__((always_inline))rte_eal_remote_launch (switch_worker, mbuf_pool, lcore_id); } -rte_vhost_feature_disable (1ULL <<VIRTIO_NET_F_MRG_RXBUF ); ret =rte_vhost_driver_register ((char *)&dev_basename,0 );if (ret !=0 )rte_exit (EXIT_FAILURE ,"failed to register vhost driver.\n" ); +rte_vhost_driver_disable_features (dev_basename, +1ULL <<VIRTIO_NET_F_MRG_RXBUF ); +rte_vhost_driver_callback_register (&virtio_net_device_ops);rte_vhost_driver_session_start ();
examples/vhost/main.c +27 -16
72 lines not on this page · raw message
lib/librte_vhost/rte_vhost_version.map +0 -3
@@ -7,9 +7,6 @@ DPDK_2.0 { rte_vhost_driver_session_start; rte_vhost_enable_guest_notification; rte_vhost_enqueue_burst; - rte_vhost_feature_disable; - rte_vhost_feature_enable; - rte_vhost_feature_get; local: *; };
lib/librte_vhost/rte_virtio_net.h +0 -13
@@ -70,19 +70,6 @@ struct virtio_net_device_ops {void *reserved[5 ];/**< Reserved for future extension */ }; -/** -* Disable features in feature_mask. Returns 0 on success. -*/ -int rte_vhost_feature_disable (uint64_t feature_mask); - -/** -* Enable features in feature_mask. Returns 0 on success. -*/ -int rte_vhost_feature_enable (uint64_t feature_mask); - -/* Returns currently supported vhost features */ -uint64_t rte_vhost_feature_get (void ); -int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/**
lib/librte_vhost/socket.c +22 -1
@@ -577,7 +577,13 @@ struct vhost_user_reconnect_list { vsocket =find_vhost_user_socket (path);pthread_mutex_unlock (&vhost_user.mutex); -return vsocket ? vsocket->features : (uint64_t )-1 ; +if (!vsocket) { +RTE_LOG (ERR ,VHOST_CONFIG , +"socket file %s is not registered yet.\n" , path); +return 0 ; + }else { +return vsocket->features; + } }/*
@@ -611,6 +617,21 @@ struct vhost_user_reconnect_list {pthread_mutex_init (&vsocket->conn_mutex,NULL ); vsocket->dequeue_zero_copy = flags &RTE_VHOST_USER_DEQUEUE_ZERO_COPY ; +/* +* Set the supported features correctly for the builtin vhost-user +* net driver. +* +* Applications know nothing about features the builtin virtio net +* driver (virtio_net.c) supports, thus it's not possible for them +* to invoke rte_vhost_driver_set_features(). To workaround it, here +* we set it unconditionally. If the application want to implement +* another vhost-user driver (say SCSI), it should call the +* rte_vhost_driver_set_features(), which will overwrite following +* two values. +*/ + vsocket->supported_features =VIRTIO_NET_SUPPORTED_FEATURES ; + vsocket->features =VIRTIO_NET_SUPPORTED_FEATURES ; +if ((flags &RTE_VHOST_USER_CLIENT ) !=0 ) { vsocket->reconnect = !(flags &RTE_VHOST_USER_NO_RECONNECT );if (vsocket->reconnect && reconn_tid ==0 ) {
lib/librte_vhost/vhost.c +0 -42
54 lines not on this page · raw message
lib/librte_vhost/vhost.h +21 -0
@@ -133,6 +133,27 @@ struct vhost_virtqueue {#define VIRTIO_F_VERSION_1 32#endif +#define VHOST_USER_F_PROTOCOL_FEATURES 30 + +/* Features supported by this builtin vhost-user net driver. */ +#define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \ + (1ULL << VIRTIO_NET_F_CTRL_VQ) | \ + (1ULL << VIRTIO_NET_F_CTRL_RX) | \ + (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \ + (1ULL << VIRTIO_NET_F_MQ) | \ + (1ULL << VIRTIO_F_VERSION_1) | \ + (1ULL << VHOST_F_LOG_ALL) | \ + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \ + (1ULL << VIRTIO_NET_F_HOST_TSO4) | \ + (1ULL << VIRTIO_NET_F_HOST_TSO6) | \ + (1ULL << VIRTIO_NET_F_CSUM) | \ + (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \ + (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \ + (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \ + (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \ + (1ULL << VIRTIO_NET_F_MTU)) + +struct guest_page {uint64_t guest_phys_addr;uint64_t host_phys_addr;
lib/librte_vhost/vhost_user.c +4 -4
@@ -147,9 +147,9 @@* The features that we support are requested. */ static uint64_t -vhost_user_get_features (void ) +vhost_user_get_features (struct virtio_net *dev) { -return VHOST_FEATURES ; +return rte_vhost_driver_get_features (dev->ifname); }/*
@@ -158,7 +158,7 @@static int vhost_user_set_features (struct virtio_net *dev,uint64_t features) { -if (features & ~VHOST_FEATURES ) +if (features & ~rte_vhost_driver_get_features (dev->ifname))return -1 ; dev->features = features;
@@ -1006,7 +1006,7 @@switch (msg.request) {case VHOST_USER_GET_FEATURES : - msg.payload.u64 =vhost_user_get_features (); + msg.payload.u64 =vhost_user_get_features (dev); msg.size =sizeof (msg.payload.u64);send_vhost_message (fd, &msg);break ;
Signature · 1 line
1.9.0
Re: [PATCH v3 03/22] vhost: use new APIs to handle features
Quoted 4 lines · Yuanhan Liu
Signed-off-by Yuanhan Liu <[email protected]>---
v3: fix comment typo
Quoted 10 lines
--- examples/tep_termination/main.c | 4 +++- examples/vhost/main.c | 43 +++++++++++++++++++++------------- lib/librte_vhost/rte_vhost_version.map | 3 --- lib/librte_vhost/rte_virtio_net.h | 13 ---------- lib/librte_vhost/socket.c | 23 +++++++++++++++++- lib/librte_vhost/vhost.c | 42 --------------------------------- lib/librte_vhost/vhost.h | 21 +++++++++++++++++ lib/librte_vhost/vhost_user.c | 8 +++---- 8 files changed, 77 insertions(+), 80 deletions(-)
Thanks,
Maxime
PATCH v3 4/22 vhost: make notify ops per vhost driver
In reply to Yuanhan LiuAssume there is an application both support vhost-user net and vhost-user scsi, the callback should be different. Making notify ops per vhost driver allow application define different set of callbacks for different driver.
---
v2: - check the return value of callback_register and callback_get
- update release note
--- doc/guides/prog_guide/vhost_lib.rst | 2 +- doc/guides/rel_notes/release_17_05.rst | 3 +++ drivers/net/vhost/rte_eth_vhost.c | 20 +++++++++++--------- examples/tep_termination/main.c | 7 ++++++- examples/vhost/main.c | 9 +++++++-- lib/librte_vhost/rte_virtio_net.h | 3 ++- lib/librte_vhost/socket.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 16 +--------------- lib/librte_vhost/vhost.h | 5 ++++- lib/librte_vhost/vhost_user.c | 22 ++++++++++++++++------ 10 files changed, 83 insertions(+), 36 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +1 -1
@@ -122,7 +122,7 @@ The following is an overview of some key Vhost API functions: starts an infinite loop, therefore it should be called in a dedicated thread. -* ``rte_vhost_driver_callback_register(virtio_net_device_ops)`` +* ``rte_vhost_driver_callback_register(path, virtio_net_device_ops)`` This function registers a set of callbacks, to let DPDK applications take the appropriate action when some events happen. The following events are
doc/guides/rel_notes/release_17_05.rst +3 -0
@@ -135,6 +135,9 @@ API Changes * ``rte_eth_vhost_feature_enable`` * ``rte_eth_vhost_feature_get`` + * The vhost API ``rte_vhost_driver_callback_register(ops)`` takes one + more argument: ``rte_vhost_driver_callback_register(path, ops)``. + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +11 -9
@@ -669,6 +669,12 @@ struct vhost_xstats_name_off {return 0 ; } +static struct virtio_net_device_ops vhost_ops = { + .new_device = new_device, + .destroy_device = destroy_device, + .vring_state_changed = vring_state_changed, +}; +int rte_eth_vhost_get_queue_event (uint8_t port_id,struct rte_eth_vhost_queue_event *event)
@@ -738,15 +744,6 @@ struct vhost_xstats_name_off {static void * vhost_driver_session(void *param __rte_unused) { -static struct virtio_net_device_ops vhost_ops; - -/* set vhost arguments */ - vhost_ops.new_device = new_device; - vhost_ops.destroy_device = destroy_device; - vhost_ops.vring_state_changed = vring_state_changed; -if (rte_vhost_driver_callback_register (&vhost_ops) <0 ) -RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); -/* start event handling */ rte_vhost_driver_session_start ();
@@ -1079,6 +1076,11 @@ struct vhost_xstats_name_off {if (rte_vhost_driver_register (iface_name, flags)) goto error; +if (rte_vhost_driver_callback_register (iface_name, &vhost_ops) <0 ) { +RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); + goto error; + } +/* We need only one message handling thread */ if (rte_atomic16_add_return (&nb_started_ports,1 ) ==1 ) {if (vhost_driver_session_start ())
examples/tep_termination/main.c +6 -1
@@ -1256,7 +1256,12 @@ static inline void __attribute__((always_inline))rte_vhost_driver_disable_features (dev_basename,1ULL <<VIRTIO_NET_F_MRG_RXBUF ); -rte_vhost_driver_callback_register (&virtio_net_device_ops); + ret =rte_vhost_driver_callback_register (dev_basename, + &virtio_net_device_ops); +if (ret !=0 ) { +rte_exit (EXIT_FAILURE , +"failed to register vhost driver callbacks.\n" ); + }rte_vhost_driver_session_start ();
examples/vhost/main.c +7 -2
@@ -1538,9 +1538,14 @@ static inline void __attribute__((always_inline))rte_vhost_driver_enable_features (file,1ULL <<VIRTIO_NET_F_CTRL_RX ); } - } -rte_vhost_driver_callback_register (&virtio_net_device_ops); + ret =rte_vhost_driver_callback_register (file, + &virtio_net_device_ops); +if (ret !=0 ) { +rte_exit (EXIT_FAILURE , +"failed to register vhost driver callbacks.\n" ); + } + }rte_vhost_driver_session_start ();return 0 ;
lib/librte_vhost/rte_virtio_net.h +2 -1
@@ -133,7 +133,8 @@ struct virtio_net_device_ops {uint64_t rte_vhost_driver_get_features (const char *path);/* Register callbacks. */ -int rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ); +int rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const ops);/* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start (void );
lib/librte_vhost/socket.c +32 -0
@@ -77,6 +77,8 @@ struct vhost_user_socket {*/ uint64_t supported_features;uint64_t features; + +struct virtio_net_device_ops const *notify_ops; };struct vhost_user_connection {
@@ -741,6 +743,36 @@ struct vhost_user_reconnect_list {return -1 ; } +/* +* Register ops so that we can add/remove device to data core. +*/ +int +rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const ops) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +if (vsocket) + vsocket->notify_ops = ops; +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket ?0 :-1 ; +} + +struct virtio_net_device_ops const * +vhost_driver_callback_get (const char *path) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket ? vsocket->notify_ops :NULL ; +} +int rte_vhost_driver_session_start (void ) {
lib/librte_vhost/vhost.c +1 -15
@@ -51,9 +51,6 @@struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ]; -/* device ops to add/remove device to/from data core. */ -struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device (int vid) {
@@ -253,7 +250,7 @@ struct virtio_net *if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (vid); + dev->notify_ops->destroy_device (vid); }cleanup_device (dev,1 );
@@ -396,14 +393,3 @@ struct virtio_net * dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ;return 0 ; } - -/* -* Register ops so that we can add/remove device to data core. -*/ -int -rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ops) -{ - notify_ops = ops; - -return 0 ; -}
lib/librte_vhost/vhost.h +4 -1
@@ -185,6 +185,8 @@ struct virtio_net {struct ether_addr mac;uint16_t mtu; +struct virtio_net_device_ops const *notify_ops; +uint32_t nr_guest_pages;uint32_t max_guest_pages;struct guest_page *guest_pages;
@@ -288,7 +290,6 @@ static inline phys_addr_t __attribute__((always_inline))return 0 ; } -struct virtio_net_device_ops const *notify_ops;struct virtio_net *get_device (int vid);int vhost_new_device (void );
@@ -301,6 +302,8 @@ static inline phys_addr_t __attribute__((always_inline))void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid); +struct virtio_net_device_ops const *vhost_driver_callback_get (const char *path); +/* * Backend-specific cleanup. *
lib/librte_vhost/vhost_user.c +16 -6
@@ -135,7 +135,7 @@ {if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }cleanup_device (dev,0 );
@@ -503,7 +503,7 @@/* Remove from the data plane. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }if (dev->mem) {
@@ -687,7 +687,7 @@ "dequeue zero copy is enabled\n"); } -if (notify_ops->new_device (dev->vid) ==0 ) +if (dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; } }
@@ -721,7 +721,7 @@/* We have to stop the queue (virtio) if it is running. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); } dev->flags &= ~VIRTIO_DEV_READY ;
@@ -763,8 +763,8 @@"set queue enable: %d to qp idx: %d\n" , enable, state->index); -if (notify_ops->vring_state_changed) - notify_ops->vring_state_changed (dev->vid, state->index, enable); +if (dev->notify_ops->vring_state_changed) + dev->notify_ops->vring_state_changed (dev->vid, state->index, enable); dev->virtqueue[state->index]->enabled = enable;
@@ -978,6 +978,16 @@if (dev ==NULL )return -1 ; +if (!dev->notify_ops) { + dev->notify_ops =vhost_driver_callback_get (dev->ifname); +if (!dev->notify_ops) { +RTE_LOG (ERR ,VHOST_CONFIG , +"failed to get callback ops for driver %s\n" , + dev->ifname); +return -1 ; + } + } + ret =read_vhost_message (fd, &msg);if (ret <=0 || msg.request >=VHOST_USER_MAX ) {if (ret <0 )
Signature · 1 line
1.9.0
Re: [PATCH v3 04/22] vhost: make notify ops per vhost driver
Quoted 10 lines · Yuanhan Liu
Assume there is an application both support vhost-user net and vhost-user scsi, the callback should be different. Making notify ops per vhost driver allow application define different set of callbacks for different driver.
Signed-off-by Yuanhan Liu <[email protected]>---
v2: - check the return value of
callback_registerandcallback_get
- update release note
Quoted 12 lines
--- doc/guides/prog_guide/vhost_lib.rst | 2 +- doc/guides/rel_notes/release_17_05.rst | 3 +++ drivers/net/vhost/rte_eth_vhost.c | 20 +++++++++++--------- examples/tep_termination/main.c | 7 ++++++- examples/vhost/main.c | 9 +++++++-- lib/librte_vhost/rte_virtio_net.h | 3 ++- lib/librte_vhost/socket.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 16 +--------------- lib/librte_vhost/vhost.h | 5 ++++- lib/librte_vhost/vhost_user.c | 22 ++++++++++++++++------ 10 files changed, 83 insertions(+), 36 deletions(-)
Thanks,
Maxime
PATCH v3 5/22 vhost: export guest memory regions
In reply to Yuanhan LiuSome vhost-user driver may need this info to setup its own page tables for GPA (guest physical addr) to HPA (host physical addr) translation. SPDK (Storage Performance Development Kit) is one example.
Besides, by exporting this memory info, we could also export the gpa_to_vva() as an inline function, which helps for performance. Otherwise, it has to be referenced indirectly by a "vid".
---
v2: add API comments
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 38 ++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 23 ++++++++++++++++++++ lib/librte_vhost/vhost.h | 28 ++----------------------- lib/librte_vhost/vhost_user.c | 12 +++++------ 5 files changed, 70 insertions(+), 32 deletions(-)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -35,6 +35,7 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_get_mem_table; rte_vhost_get_mtu; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +38 -0
@@ -59,6 +59,28 @@enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM };/** +* Information relating to memory regions including offsets to +* addresses in QEMUs memory file. +*/ +struct rte_vhost_mem_region { +uint64_t guest_phys_addr; +uint64_t guest_user_addr; +uint64_t host_user_addr; +uint64_t size; +void *mmap_addr; +uint64_t mmap_size; +int fd; +}; + +/** +* Memory structure includes region and mapping information. +*/ +struct rte_vhost_memory { +uint32_t nregions; +struct rte_vhost_mem_region regions[0 ]; +}; + +/** * Device and vring operations. */ struct virtio_net_device_ops {
@@ -244,4 +266,20 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count); +/** +* Get guest mem table: a list of memory regions. +* +* An rte_vhost_vhost_memory object will be allocated internaly, to hold the +* guest memory regions. Application should free it at destroy_device() +* callback. +* +* @param vid +* vhost device ID +* @param mem +* To store the returned mem regions +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem); +#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +23 -0
@@ -359,6 +359,29 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem) +{ +struct virtio_net *dev; +struct rte_vhost_memory *m; +size_t size; + + dev =get_device (vid); +if (!dev) +return -1 ; + + size = dev->mem->nregions *sizeof (struct rte_vhost_mem_region ); + m =malloc (size); +if (!m) +return -1 ; + + m->nregions = dev->mem->nregions; +memcpy (m->regions, dev->mem->regions, size); + *mem = m; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {
lib/librte_vhost/vhost.h +2 -26
@@ -166,7 +166,7 @@ struct guest_page {*/ struct virtio_net {/* Frontend (QEMU) memory and memory region information */ -struct virtio_memory *mem; +struct rte_vhost_memory *mem;uint64_t features;uint64_t protocol_features;int vid;
@@ -192,30 +192,6 @@ struct virtio_net {struct guest_page *guest_pages; } __rte_cache_aligned; -/** -* Information relating to memory regions including offsets to -* addresses in QEMUs memory file. -*/ -struct virtio_memory_region { -uint64_t guest_phys_addr; -uint64_t guest_user_addr; -uint64_t host_user_addr; -uint64_t size; -void *mmap_addr; -uint64_t mmap_size; -int fd; -}; - - -/** -* Memory structure includes region and mapping information. -*/ -struct virtio_memory { -uint32_t nregions; -struct virtio_memory_region regions[0 ]; -}; - -/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
@@ -255,7 +231,7 @@ struct virtio_memory {static inline uint64_t __attribute__((always_inline))gpa_to_vva (struct virtio_net *dev,uint64_t gpa) { -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;uint32_t i;for (i =0 ; i < dev->mem->nregions; i++) {
lib/librte_vhost/vhost_user.c +6 -6
@@ -92,7 +92,7 @@ free_mem_region(struct virtio_net *dev) {uint32_t i; -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;if (!dev || !dev->mem)return ;
@@ -304,7 +304,7 @@static uint64_t qva_to_vva (struct virtio_net *dev,uint64_t qva) { -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;uint32_t i;/* Find the region where the address lives. */
@@ -432,7 +432,7 @@ }static void -add_guest_pages (struct virtio_net *dev,struct virtio_memory_region *reg, +add_guest_pages (struct virtio_net *dev,struct rte_vhost_mem_region *reg,uint64_t page_size) {uint64_t reg_size = reg->size;
@@ -492,7 +492,7 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) { struct VhostUserMemory memory = pmsg->payload.memory; -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;void *mmap_addr;uint64_t mmap_size;uint64_t mmap_offset;
@@ -519,8 +519,8 @@ sizeof(struct guest_page)); } - dev->mem =rte_zmalloc ("vhost-mem-table" ,sizeof (struct virtio_memory ) + -sizeof (struct virtio_memory_region ) * memory.nregions,0 ); + dev->mem =rte_zmalloc ("vhost-mem-table" ,sizeof (struct rte_vhost_memory ) + +sizeof (struct rte_vhost_mem_region ) * memory.nregions,0 );if (dev->mem ==NULL ) { RTE_LOG(ERR, VHOST_CONFIG, "(%d) failed to allocate memory for dev->mem\n",
Signature · 1 line
1.9.0
PATCH v3 6/22 vhost: introduce API to fetch negotiated features
In reply to Yuanhan Liu--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 10 ++++++++++ lib/librte_vhost/vhost.c | 12 ++++++++++++ 3 files changed, 23 insertions(+)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -37,5 +37,6 @@ DPDK_17.05 { rte_vhost_driver_set_features; rte_vhost_get_mem_table; rte_vhost_get_mtu; + rte_vhost_get_negotiated_features; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +10 -0
@@ -154,6 +154,16 @@ struct virtio_net_device_ops {*/ uint64_t rte_vhost_driver_get_features (const char *path); +/** +* Get the feature bits after negotiation +* +* @param vid +* Vhost device ID +* @return +* Negotiated feature bits on success, 0 on failure +*/ +uint64_t rte_vhost_get_negotiated_features (int vid); +/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path,struct virtio_net_device_ops const *const ops);
lib/librte_vhost/vhost.c +12 -0
@@ -359,6 +359,18 @@ struct virtio_net *return 0 ; } +uint64_t +rte_vhost_get_negotiated_features (int vid) +{ +struct virtio_net *dev; + + dev =get_device (vid); +if (!dev) +return 0 ; + +return dev->features; +} +int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem) {
Signature · 1 line
1.9.0
Re: [PATCH v3 06/22] vhost: introduce API to fetch negotiated features
Quoted 45 lines · Yuanhan Liu
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 10 ++++++++++ lib/librte_vhost/vhost.c | 12 ++++++++++++ 3 files changed, 23 insertions(+)lib/librte_vhost/rte_vhost_version.map +1
-0@@ -37,5 +37,6 @@ DPDK_17.05 { rte_vhost_driver_set_features; rte_vhost_get_mem_table; rte_vhost_get_mtu; + rte_vhost_get_negotiated_features; } DPDK_16.07;lib/librte_vhost/rte_virtio_net.h +10
-0@@ -154,6 +154,16 @@ struct virtio_net_device_ops {*/ uint64_t rte_vhost_driver_get_features (const char *path); +/** +* Get the feature bits after negotiation +* +* @param vid +* Vhost device ID +* @return +* Negotiated feature bits on success, 0 on failure +*/ +uint64_t rte_vhost_get_negotiated_features (int vid); +/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path,struct virtio_net_device_ops const *const ops);lib/librte_vhost/vhost.c +0
-0@@ -359,6 +359,18 @@ struct virtio_net *return 0 ;
lib/librte_vhost/vhost.c struct virtio_net * · line 369
Quoted 10 lines
lib/librte_vhost/vhost.c +8
-0} +uint64_t +rte_vhost_get_negotiated_features (int vid) +{ +struct virtio_net *dev; + + dev =get_device (vid); +if (!dev) +return 0 ;
It's unlikely to happen with net devices, but as this series is about generalizing the use of this lib, couldn't we have cases where the negotiated features is 0?
If so, shouldn't be preferable the caller passes features pointer as argument?
lib/librte_vhost/vhost.c struct virtio_net * · line 376
Quoted 8 lines
lib/librte_vhost/vhost.c +4
-0+ +return dev->features; +} +int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem) {
Thanks,
Maxime
Re: [PATCH v3 06/22] vhost: introduce API to fetch negotiated features
Quoted 11 lines · Maxime Coquelin
lib/librte_vhost/vhost.c struct virtio_net * · line 369
Quoted 8 lines
lib/librte_vhost/vhost.c +8
-0+uint64_t +rte_vhost_get_negotiated_features (int vid) +{ +struct virtio_net *dev; + + dev =get_device (vid); +if (!dev) +return 0 ;It's unlikely to happen with net devices, but as this series is about generalizing the use of this lib, couldn't we have cases where the negotiated features is 0?
Yes, I think so.
Quoted 2 lines
If so, shouldn't be preferable the caller passes features pointer as argument?
I thought of that. The reason I did that is to keep the semantics with rte_vhost_driver_get_feature(path). But you are right, we don't have to follow that. More importantly, we may also need change the return value of rte_vhost_driver_get_features(path): which could also fail if 'path' is not found.
--yliu
PATCH v3 7/22 vhost: export vhost vring info
In reply to Yuanhan Liu---
v2: - fix off-by-one check
- add API comments
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 26 ++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 30 ++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 2 ++ 4 files changed, 59 insertions(+)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -38,5 +38,6 @@ DPDK_17.05 { rte_vhost_get_mem_table; rte_vhost_get_mtu; rte_vhost_get_negotiated_features; + rte_vhost_get_vhost_vring; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +26 -0
@@ -80,6 +80,17 @@ struct rte_vhost_memory {struct rte_vhost_mem_region regions[0 ]; }; +struct rte_vhost_vring { +struct vring_desc *desc; +struct vring_avail *avail; +struct vring_used *used; +uint64_t log_guest_addr; + +int callfd; +int kickfd; +uint16_t size; +}; +/** * Device and vring operations. */
@@ -292,4 +303,19 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,*/ int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem); +/** +* Get guest vring info, including the vring address, vring size, etc. +* +* @param vid +* vhost device ID +* @param vring_idx +* vring index +* @param vring +* the structure to hold the requested vring info +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring); +#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +30 -0
@@ -394,6 +394,36 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring) +{ +struct virtio_net *dev; +struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (!dev) +return -1 ; + +if (vring_idx >=VHOST_MAX_VRING ) +return -1 ; + + vq = dev->virtqueue[vring_idx]; +if (!vq) +return -1 ; + + vring->desc = vq->desc; + vring->avail = vq->avail; + vring->used = vq->used; + vring->log_guest_addr = vq->log_guest_addr; + + vring->callfd = vq->callfd; + vring->kickfd = vq->kickfd; + vring->size = vq->size; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {
lib/librte_vhost/vhost.h +2 -0
@@ -120,6 +120,8 @@ struct vhost_virtqueue {#ifndef VIRTIO_NET_F_MQ #define VIRTIO_NET_F_MQ 22#endif + +#define VHOST_MAX_VRING 0x100#define VHOST_MAX_QUEUE_PAIRS 0x80#ifndef VIRTIO_NET_F_MTU
Signature · 1 line
1.9.0
Re: [PATCH v3 07/22] vhost: export vhost vring info
Quoted 11 lines · Yuanhan Liu
Signed-off-by Yuanhan Liu <[email protected]>---
v2: - fix off-by-one check
- add API comments--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 26 ++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 30 ++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 2 ++ 4 files changed, 59 insertions(+)
Thanks,
Maxime
PATCH v3 8/22 vhost: export API to translate gpa to vva
In reply to Yuanhan Liu--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 28 ++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 19 ------------------- lib/librte_vhost/virtio_net.c | 23 +++++++++++++---------- 4 files changed, 42 insertions(+), 29 deletions(-)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -39,5 +39,6 @@ DPDK_17.05 { rte_vhost_get_mtu; rte_vhost_get_negotiated_features; rte_vhost_get_vhost_vring; + rte_vhost_gpa_to_vva; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +28 -0
@@ -103,6 +103,34 @@ struct virtio_net_device_ops {void *reserved[5 ];/**< Reserved for future extension */ }; +/** +* Convert guest physical address to host virtual address +* +* @param mem +* the guest memory regions +* @param gpa +* the guest physical address for querying +* @return +* the host virtual address on success, 0 on failure +*/ +static inline uint64_t __attribute__((always_inline)) +rte_vhost_gpa_to_vva (struct rte_vhost_memory *mem,uint64_t gpa) +{ +struct rte_vhost_mem_region *reg; +uint32_t i; + +for (i =0 ; i < mem->nregions; i++) { + reg = &mem->regions[i]; +if (gpa >= reg->guest_phys_addr && + gpa < reg->guest_phys_addr + reg->size) { +return gpa - reg->guest_phys_addr + + reg->host_user_addr; + } + } + +return 0 ; +} +int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/**
lib/librte_vhost/vhost.h +0 -19
@@ -229,25 +229,6 @@ struct virtio_net {#define MAX_VHOST_DEVICE 1024extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ]; -/* Convert guest physical Address to host virtual address */ -static inline uint64_t __attribute__((always_inline)) -gpa_to_vva (struct virtio_net *dev,uint64_t gpa) -{ -struct rte_vhost_mem_region *reg; -uint32_t i; - -for (i =0 ; i < dev->mem->nregions; i++) { - reg = &dev->mem->regions[i]; -if (gpa >= reg->guest_phys_addr && - gpa < reg->guest_phys_addr + reg->size) { -return gpa - reg->guest_phys_addr + - reg->host_user_addr; - } - } - -return 0 ; -} -/* Convert guest physical address to host physical address */ static inline phys_addr_t __attribute__((always_inline))gpa_to_hpa (struct virtio_net *dev,uint64_t gpa,uint64_t size)
lib/librte_vhost/virtio_net.c +13 -10
@@ -199,7 +199,7 @@ static inline int __attribute__((always_inline))uint16_t nr_desc =1 ; desc = &descs[desc_idx]; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);/* * Checking of 'desc_addr' placed outside of 'unlikely' macro to avoid * performance issue with some versions of gcc (4.8.4 and 5.3.0) which
@@ -239,7 +239,7 @@ static inline int __attribute__((always_inline))return -1 ; desc = &descs[desc->next]; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -323,7 +323,8 @@ static inline uint32_t __attribute__((always_inline))int err;if (vq->desc[desc_idx].flags &VRING_DESC_F_INDIRECT ) { - descs = (struct vring_desc *)(uintptr_t )gpa_to_vva (dev, + descs = (struct vring_desc *)(uintptr_t ) +rte_vhost_gpa_to_vva (dev->mem, vq->desc[desc_idx].addr);if (unlikely (!descs)) { count = i;
@@ -383,7 +384,7 @@ static inline int __attribute__((always_inline))if (vq->desc[idx].flags &VRING_DESC_F_INDIRECT ) { descs = (struct vring_desc *)(uintptr_t ) -gpa_to_vva (dev, vq->desc[idx].addr); +rte_vhost_gpa_to_vva (dev->mem, vq->desc[idx].addr);if (unlikely (!descs))return -1 ;
@@ -473,7 +474,7 @@ static inline int __attribute__((always_inline))if (unlikely (m ==NULL ))return -1 ; - desc_addr =gpa_to_vva (dev, buf_vec[vec_idx].buf_addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, buf_vec[vec_idx].buf_addr);if (buf_vec[vec_idx].buf_len < dev->vhost_hlen || !desc_addr)return -1 ;
@@ -495,7 +496,8 @@ static inline int __attribute__((always_inline))/* done with current desc buf, get the next one */ if (desc_avail ==0 ) { vec_idx++; - desc_addr =gpa_to_vva (dev, buf_vec[vec_idx].buf_addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, + buf_vec[vec_idx].buf_addr);if (unlikely (!desc_addr))return -1 ;
@@ -798,7 +800,7 @@ static inline int __attribute__((always_inline)) (desc->flags & VRING_DESC_F_INDIRECT))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -818,7 +820,7 @@ static inline int __attribute__((always_inline))if (unlikely (desc->flags &VRING_DESC_F_INDIRECT ))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -882,7 +884,7 @@ static inline int __attribute__((always_inline))if (unlikely (desc->flags &VRING_DESC_F_INDIRECT ))return -1 ; - desc_addr =gpa_to_vva (dev, desc->addr); + desc_addr =rte_vhost_gpa_to_vva (dev->mem, desc->addr);if (unlikely (!desc_addr))return -1 ;
@@ -1113,7 +1115,8 @@ static inline bool __attribute__((always_inline))rte_prefetch0 (&vq->desc[desc_indexes[i +1 ]]);if (vq->desc[desc_indexes[i]].flags &VRING_DESC_F_INDIRECT ) { - desc = (struct vring_desc *)(uintptr_t )gpa_to_vva (dev, + desc = (struct vring_desc *)(uintptr_t ) +rte_vhost_gpa_to_vva (dev->mem, vq->desc[desc_indexes[i]].addr);if (unlikely (!desc))break ;
Signature · 1 line
1.9.0
PATCH v3 9/22 vhost: turn queue pair to vring
In reply to Yuanhan LiuThe queue pair is very virtio-net specific, other devices don't have such concept. To make it generic, we should log the number of vrings instead of the number of queue pairs.
This patch just does a simple convert, a later patch would export the number of vrings to applications.
---
v2: enable all vrings by unconditionally
--- lib/librte_vhost/vhost.c | 80 +++++++++++++++---------------------------- lib/librte_vhost/vhost.h | 4 +-- lib/librte_vhost/vhost_user.c | 28 +++++---------- lib/librte_vhost/virtio_net.c | 10 +++--- 4 files changed, 42 insertions(+), 80 deletions(-)
lib/librte_vhost/vhost.c +27 -53
@@ -84,10 +84,8 @@ struct virtio_net *vhost_backend_cleanup (dev); -for (i =0 ; i < dev->virt_qp_nb; i++) { -cleanup_vq (dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ], destroy); -cleanup_vq (dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ], destroy); - } +for (i =0 ; i < dev->nr_vring; i++) +cleanup_vq (dev->virtqueue[i], destroy); }/*
@@ -97,24 +95,21 @@ struct virtio_net * free_device(struct virtio_net *dev) {uint32_t i; -struct vhost_virtqueue *rxq, *txq; +struct vhost_virtqueue *vq; -for (i =0 ; i < dev->virt_qp_nb; i++) { - rxq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ]; - txq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ]; +for (i =0 ; i < dev->nr_vring; i++) { + vq = dev->virtqueue[i]; -rte_free (rxq->shadow_used_ring); -rte_free (txq->shadow_used_ring); +rte_free (vq->shadow_used_ring); -/* rxq and txq are allocated together as queue-pair */ -rte_free (rxq); +rte_free (vq); }rte_free (dev); }static void -init_vring_queue (struct vhost_virtqueue *vq,int qp_idx) +init_vring_queue (struct vhost_virtqueue *vq) {memset (vq,0 ,sizeof (struct vhost_virtqueue ));
@@ -124,69 +119,48 @@ struct virtio_net */* Backends are set to -1 indicating an inactive device. */ vq->backend =-1 ; -/* always set the default vq pair to enabled */ -if (qp_idx ==0 ) - vq->enabled =1 ; +/* +* always set the vq to enabled; this is to keep compatibility +* with the old QEMU, whereas there is no SET_VRING_ENABLE message. +*/ + vq->enabled =1 ;TAILQ_INIT (&vq->zmbuf_list); }static void -init_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) -{ -uint32_t base_idx = qp_idx *VIRTIO_QNUM ; - -init_vring_queue (dev->virtqueue[base_idx +VIRTIO_RXQ ], qp_idx); -init_vring_queue (dev->virtqueue[base_idx +VIRTIO_TXQ ], qp_idx); -} - -static void -reset_vring_queue (struct vhost_virtqueue *vq,int qp_idx) +reset_vring_queue (struct vhost_virtqueue *vq) {int callfd; callfd = vq->callfd; -init_vring_queue (vq, qp_idx); +init_vring_queue (vq); vq->callfd = callfd; } -static void -reset_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) -{ -uint32_t base_idx = qp_idx *VIRTIO_QNUM ; - -reset_vring_queue (dev->virtqueue[base_idx +VIRTIO_RXQ ], qp_idx); -reset_vring_queue (dev->virtqueue[base_idx +VIRTIO_TXQ ], qp_idx); -} -int -alloc_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx) +alloc_vring_queue (struct virtio_net *dev,uint32_t vring_idx) { -struct vhost_virtqueue *virtqueue =NULL ; -uint32_t virt_rx_q_idx = qp_idx *VIRTIO_QNUM +VIRTIO_RXQ ; -uint32_t virt_tx_q_idx = qp_idx *VIRTIO_QNUM +VIRTIO_TXQ ; +struct vhost_virtqueue *vq; - virtqueue =rte_malloc (NULL , -sizeof (struct vhost_virtqueue ) *VIRTIO_QNUM ,0 ); -if (virtqueue ==NULL ) { + vq =rte_malloc (NULL ,sizeof (struct vhost_virtqueue ),0 ); +if (vq ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"Failed to allocate memory for virt qp:%d.\n" , qp_idx); +"Failed to allocate memory for vring:%u.\n" , vring_idx);return -1 ; } - dev->virtqueue[virt_rx_q_idx] = virtqueue; - dev->virtqueue[virt_tx_q_idx] = virtqueue +VIRTIO_TXQ ; - -init_vring_queue_pair (dev, qp_idx); + dev->virtqueue[vring_idx] = vq; +init_vring_queue (vq); - dev->virt_qp_nb +=1 ; + dev->nr_vring +=1 ;return 0 ; }/* * Reset some variables in device structure, while keeping few -* others untouched, such as vid, ifname, virt_qp_nb: they +* others untouched, such as vid, ifname, nr_vring: they * should be same unless the device is removed. */ void
@@ -198,8 +172,8 @@ struct virtio_net * dev->protocol_features =0 ; dev->flags =0 ; -for (i =0 ; i < dev->virt_qp_nb; i++) -reset_vring_queue_pair (dev, i); +for (i =0 ; i < dev->nr_vring; i++) +reset_vring_queue (dev->virtqueue[i]); }/*
@@ -340,7 +314,7 @@ struct virtio_net *if (dev ==NULL )return 0 ; -return dev->virt_qp_nb; +return dev->nr_vring /2 ; }int
lib/librte_vhost/vhost.h +2 -2
@@ -176,7 +176,7 @@ struct virtio_net {uint16_t vhost_hlen;/* to tell if we need broadcast rarp packet */ rte_atomic16_t broadcast_rarp; -uint32_t virt_qp_nb; +uint32_t nr_vring;int dequeue_zero_copy;struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ];#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
@@ -256,7 +256,7 @@ static inline phys_addr_t __attribute__((always_inline))void reset_device (struct virtio_net *dev);void vhost_destroy_device (int ); -int alloc_vring_queue_pair (struct virtio_net *dev,uint32_t qp_idx); +int alloc_vring_queue (struct virtio_net *dev,uint32_t vring_idx);void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid);
lib/librte_vhost/vhost_user.c +8 -20
@@ -227,13 +227,6 @@struct vhost_virtqueue *old_vq, *vq;int ret; -/* -* vq is allocated on pairs, we should try to do realloc -* on first queue of one queue pair only. -*/ -if (index %VIRTIO_QNUM !=0 ) -return dev; - old_dev = dev; vq = old_vq = dev->virtqueue[index];
@@ -251,8 +244,7 @@if (oldnode != newnode) {RTE_LOG (INFO ,VHOST_CONFIG ,"reallocate vq from %d to %d node\n" , oldnode, newnode); - vq =rte_malloc_socket (NULL ,sizeof (*vq) *VIRTIO_QNUM ,0 , - newnode); + vq =rte_malloc_socket (NULL ,sizeof (*vq),0 , newnode);if (!vq)return dev;
@@ -284,7 +276,6 @@ out: dev->virtqueue[index] = vq; - dev->virtqueue[index +1 ] = vq +1 ; vhost_devices[dev->vid] = dev;return dev;
@@ -615,14 +606,13 @@static int virtio_is_ready (struct virtio_net *dev) { -struct vhost_virtqueue *rvq, *tvq; +struct vhost_virtqueue *vq;uint32_t i; -for (i =0 ; i < dev->virt_qp_nb; i++) { - rvq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_RXQ ]; - tvq = dev->virtqueue[i *VIRTIO_QNUM +VIRTIO_TXQ ]; +for (i =0 ; i < dev->nr_vring; i++) { + vq = dev->virtqueue[i]; -if (!vq_is_ready (rvq) || !vq_is_ready (tvq)) { +if (!vq_is_ready (vq)) {RTE_LOG (INFO ,VHOST_CONFIG ,"virtio is not ready for processing.\n" );return 0 ;
@@ -934,7 +924,6 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg) { uint16_t vring_idx; -uint16_t qp_idx;switch (msg->request) {case VHOST_USER_SET_VRING_KICK :
@@ -954,17 +943,16 @@return 0 ; } - qp_idx = vring_idx /VIRTIO_QNUM ; -if (qp_idx >=VHOST_MAX_QUEUE_PAIRS ) { +if (vring_idx >=VHOST_MAX_VRING ) {RTE_LOG (ERR ,VHOST_CONFIG ,"invalid vring index: %u\n" , vring_idx);return -1 ; } -if (dev->virtqueue[qp_idx]) +if (dev->virtqueue[vring_idx])return 0 ; -return alloc_vring_queue_pair (dev, qp_idx); +return alloc_vring_queue (dev, vring_idx); }int
lib/librte_vhost/virtio_net.c +5 -5
@@ -86,9 +86,9 @@ static inline void __attribute__((always_inline)) }static bool -is_valid_virt_queue_idx (uint32_t idx,int is_tx,uint32_t qp_nb) +is_valid_virt_queue_idx (uint32_t idx,int is_tx,uint32_t nr_vring) { -return (is_tx ^ (idx &1 )) ==0 && idx < qp_nb *VIRTIO_QNUM ; +return (is_tx ^ (idx &1 )) ==0 && idx < nr_vring; } static inline void __attribute__((always_inline))
@@ -283,7 +283,7 @@ static inline uint32_t __attribute__((always_inline))uint32_t i, sz;LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__); -if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
@@ -554,7 +554,7 @@ static inline uint32_t __attribute__((always_inline))uint16_t avail_head;LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__); -if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
@@ -1019,7 +1019,7 @@ static inline bool __attribute__((always_inline))if (!dev)return 0 ; -if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) { +if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->nr_vring))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);return 0 ;
Signature · 1 line
1.9.0
PATCH v3 10/22 vhost: export the number of vrings
In reply to Yuanhan LiuWe used to use rte_vhost_get_queue_num() for telling how many vrings. However, the return value is the number of "queue pairs", which is very virtio-net specific. To make it generic, we should return the number of vrings instead, and let the driver do the proper translation. Say, virtio-net driver could turn it to the number of queue pairs by dividing 2.
Meanwhile, mark rte_vhost_get_queue_num as deprecated.
---
v2: - update release note
--- doc/guides/rel_notes/release_17_05.rst | 3 +++ drivers/net/vhost/rte_eth_vhost.c | 2 +- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 17 +++++++++++++++++ lib/librte_vhost/vhost.c | 11 +++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_17_05.rst +3 -0
@@ -138,6 +138,9 @@ API Changes * The vhost API ``rte_vhost_driver_callback_register(ops)`` takes one more argument: ``rte_vhost_driver_callback_register(path, ops)``. + * The vhost API ``rte_vhost_get_queue_num`` is deprecated, instead, + ``rte_vhost_get_vring_num`` should be used. + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -569,7 +569,7 @@ struct vhost_xstats_name_off { vq->port = eth_dev->data->port_id; } -for (i =0 ; i <rte_vhost_get_queue_num (vid) *VIRTIO_QNUM ; i++) +for (i =0 ; i <rte_vhost_get_vring_num (vid); i++)rte_vhost_enable_guest_notification (vid, i,0 );rte_vhost_get_mtu (vid, ð_dev->data->mtu);
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -39,6 +39,7 @@ DPDK_17.05 { rte_vhost_get_mtu; rte_vhost_get_negotiated_features; rte_vhost_get_vhost_vring; + rte_vhost_get_vring_num; rte_vhost_gpa_to_vva; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +17 -0
@@ -237,17 +237,34 @@ int rte_vhost_driver_callback_register(const char *path,int rte_vhost_get_numa_node (int vid);/** +* @deprecated * Get the number of queues the device supports. * +* Note this function is deprecated, as it returns a queue pair number, +* which is virtio-net specific. Instead, rte_vhost_get_vring_num should +* be used. +* * @param vid * virtio-net device ID * * @return * The number of queues, 0 on failure */ +__rte_deprecated uint32_t rte_vhost_get_queue_num(int vid);/** +* Get the number of vrings the device supports. +* +* @param vid +* vhost device ID +* +* @return +* The number of vrings, 0 on failure +*/ +uint16_t rte_vhost_get_vring_num (int vid); + +/** * Get the virtio net device's ifname, which is the vhost-user socket * file path. *
lib/librte_vhost/vhost.c +11 -0
@@ -317,6 +317,17 @@ struct virtio_net *return dev->nr_vring /2 ; } +uint16_t +rte_vhost_get_vring_num (int vid) +{ +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return 0 ; + +return dev->nr_vring; +} +int rte_vhost_get_ifname (int vid,char *buf,size_t len) {
Signature · 1 line
1.9.0
PATCH v3 11/22 vhost: move the device ready check at proper place
In reply to Yuanhan LiuCurrently, we check vq->desc, vq->kickfd and vq->callfd to know whether a virtio device is ready or not. However, we only do it when handling SET_VRING_KICK message, which could be wrong if a vhost-user frontend send SET_VRING_KICK first and SET_VRING_CALL later.
To work for all possible vhost-user frontend implementations, we could move the ready check at the end of vhost-user message handler.
Meanwhile, since we do the check more often than before, the "virtio not ready" message is dropped, to not flood the screen.
--- lib/librte_vhost/vhost_user.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-)
lib/librte_vhost/vhost_user.c +18 -22
@@ -609,14 +609,14 @@struct vhost_virtqueue *vq;uint32_t i; +if (dev->nr_vring ==0 ) +return 0 ; +for (i =0 ; i < dev->nr_vring; i++) { vq = dev->virtqueue[i]; -if (!vq_is_ready (vq)) { -RTE_LOG (INFO ,VHOST_CONFIG , -"virtio is not ready for processing.\n" ); +if (!vq_is_ready (vq))return 0 ; - } } RTE_LOG(INFO, VHOST_CONFIG,
@@ -645,10 +645,6 @@ vq->callfd = file.fd; } -/* -* In vhost-user, when we receive kick message, will test whether virtio -* device is ready for packet processing. -*/ static void vhost_user_set_vring_kick (struct virtio_net *dev,struct VhostUserMsg *pmsg) {
@@ -667,20 +663,6 @@if (vq->kickfd >=0 )close (vq->kickfd); vq->kickfd = file.fd; - -if (virtio_is_ready (dev)) { - dev->flags |=VIRTIO_DEV_READY ; - -if (!(dev->flags &VIRTIO_DEV_RUNNING )) { -if (dev->dequeue_zero_copy) { -RTE_LOG (INFO ,VHOST_CONFIG , -"dequeue zero copy is enabled\n" ); - } - -if (dev->notify_ops->new_device (dev->vid) ==0 ) - dev->flags |=VIRTIO_DEV_RUNNING ; - } - } } static void
@@ -1102,5 +1084,19 @@send_vhost_message (fd, &msg); } +if (!(dev->flags &VIRTIO_DEV_RUNNING ) &&virtio_is_ready (dev)) { + dev->flags |=VIRTIO_DEV_READY ; + +if (!(dev->flags &VIRTIO_DEV_RUNNING )) { +if (dev->dequeue_zero_copy) { +RTE_LOG (INFO ,VHOST_CONFIG , +"dequeue zero copy is enabled\n" ); + } + +if (dev->notify_ops->new_device (dev->vid) ==0 ) + dev->flags |=VIRTIO_DEV_RUNNING ; + } + } +return 0 ; }
Signature · 1 line
1.9.0
PATCH v3 12/22 vhost: drop the Rx and Tx queue macro
In reply to Yuanhan LiuThey are virtio-net specific and should be defined inside the virtio-net driver.
---
v2: - update release note
--- doc/guides/rel_notes/release_17_05.rst | 6 ++++++ drivers/net/vhost/rte_eth_vhost.c | 2 ++ examples/tep_termination/main.h | 2 ++ examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 3 --- 5 files changed, 12 insertions(+), 3 deletions(-)
doc/guides/rel_notes/release_17_05.rst +6 -0
@@ -141,6 +141,12 @@ API Changes * The vhost API ``rte_vhost_get_queue_num`` is deprecated, instead, ``rte_vhost_get_vring_num`` should be used. + * Few macros are removed in ``rte_virtio_net.h`` + + * ``VIRTIO_RXQ`` + * ``VIRTIO_TXQ`` + * ``VIRTIO_QNUM`` + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +2 -0
@@ -45,6 +45,8 @@#include "rte_eth_vhost.h" +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +#define ETH_VHOST_IFACE_ARG "iface"#define ETH_VHOST_QUEUES_ARG "queues"#define ETH_VHOST_CLIENT_ARG "client"
examples/tep_termination/main.h +2 -0
@@ -54,6 +54,8 @@/* Max number of devices. Limited by the application. */ #define MAX_DEVICES 64 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +/* Per-device statistics struct */ struct device_statistics {uint64_t tx_total;
examples/vhost/main.h +2 -0
@@ -41,6 +41,8 @@#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2#define RTE_LOGTYPE_VHOST_PORT RTE_LOGTYPE_USER3 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +struct device_statistics {uint64_t tx;uint64_t tx_total;
lib/librte_vhost/rte_virtio_net.h +0 -3
@@ -55,9 +55,6 @@#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)#define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2) -/* Enum for virtqueue management. */ -enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; -/** * Information relating to memory regions including offsets to * addresses in QEMUs memory file.
Signature · 1 line
1.9.0
PATCH v3 13/22 vhost: do not include net specific headers
In reply to Yuanhan LiuInclude it internally, at vhost.h.
---
v2: - update release note
--- doc/guides/rel_notes/release_17_05.rst | 7 +++++++ examples/vhost/main.h | 2 ++ lib/librte_vhost/rte_virtio_net.h | 4 ---- lib/librte_vhost/vhost.h | 4 ++++ 4 files changed, 13 insertions(+), 4 deletions(-)
doc/guides/rel_notes/release_17_05.rst +7 -0
@@ -147,6 +147,13 @@ API Changes * ``VIRTIO_TXQ`` * ``VIRTIO_QNUM`` + * Few net specific header files are removed in ``rte_virtio_net.h`` + + * ``linux/virtio_net.h`` + * ``sys/socket.h`` + * ``linux/if.h`` + * ``rte_ether.h`` + ABI Changes -----------
examples/vhost/main.h +2 -0
@@ -36,6 +36,8 @@#include <sys/queue.h> +#include <rte_ether.h> +/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2
lib/librte_vhost/rte_virtio_net.h +0 -4
@@ -42,14 +42,10 @@#include <stdint.h> #include <linux/vhost.h> #include <linux/virtio_ring.h> -#include <linux/virtio_net.h> #include <sys/eventfd.h> -#include <sys/socket.h> -#include <linux/if.h> #include <rte_memory.h> #include <rte_mempool.h> -#include <rte_ether.h> #define RTE_VHOST_USER_CLIENT (1ULL << 0)#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)
lib/librte_vhost/vhost.h +4 -0
@@ -39,8 +39,12 @@#include <sys/queue.h> #include <unistd.h> #include <linux/vhost.h> +#include <linux/virtio_net.h> +#include <sys/socket.h> +#include <linux/if.h> #include <rte_log.h> +#include <rte_ether.h> #include "rte_virtio_net.h"
Signature · 1 line
1.9.0
PATCH v3 14/22 vhost: rename device ops struct
In reply to Yuanhan Liurename "virtio_net_device_ops" to "vhost_device_ops", to not let it be virtio-net specific.
--- doc/guides/prog_guide/vhost_lib.rst | 2 +- doc/guides/rel_notes/release_17_05.rst | 3 +++ drivers/net/vhost/rte_eth_vhost.c | 2 +- examples/tep_termination/main.c | 2 +- examples/vhost/main.c | 2 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_virtio_net.h | 4 ++-- lib/librte_vhost/socket.c | 6 +++--- lib/librte_vhost/vhost.h | 4 ++-- 9 files changed, 15 insertions(+), 12 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +1 -1
@@ -122,7 +122,7 @@ The following is an overview of some key Vhost API functions: starts an infinite loop, therefore it should be called in a dedicated thread. -* ``rte_vhost_driver_callback_register(path, virtio_net_device_ops)`` +* ``rte_vhost_driver_callback_register(path, vhost_device_ops)`` This function registers a set of callbacks, to let DPDK applications take the appropriate action when some events happen. The following events are
doc/guides/rel_notes/release_17_05.rst +3 -0
@@ -154,6 +154,9 @@ API Changes * ``linux/if.h`` * ``rte_ether.h`` + * The vhost struct ``virtio_net_device_ops`` is renamed to + ``vhost_device_ops`` + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -671,7 +671,7 @@ struct vhost_xstats_name_off {return 0 ; } -static struct virtio_net_device_ops vhost_ops = { +static struct vhost_device_ops vhost_ops = { .new_device = new_device, .destroy_device = destroy_device, .vring_state_changed = vring_state_changed,
examples/tep_termination/main.c +1 -1
@@ -1081,7 +1081,7 @@ static inline void __attribute__((always_inline))* These callback allow devices to be added to the data core when configuration * has been fully complete. */ -static const struct virtio_net_device_ops virtio_net_device_ops = { +static const struct vhost_device_ops virtio_net_device_ops = { .new_device = new_device, .destroy_device = destroy_device, };
examples/vhost/main.c +1 -1
@@ -1270,7 +1270,7 @@ static inline void __attribute__((always_inline))* These callback allow devices to be added to the data core when configuration * has been fully complete. */ -static const struct virtio_net_device_ops virtio_net_device_ops = +static const struct vhost_device_ops virtio_net_device_ops = { .new_device = new_device, .destroy_device = destroy_device,
lib/librte_vhost/Makefile +1 -1
@@ -36,7 +36,7 @@ LIB = librte_vhost.a EXPORT_MAP := rte_vhost_version.map -LIBABIVER := 3 +LIBABIVER := 4 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -D_FILE_OFFSET_BITS=64 CFLAGS += -I vhost_user
lib/librte_vhost/rte_virtio_net.h +2 -2
@@ -87,7 +87,7 @@ struct rte_vhost_vring {/** * Device and vring operations. */ -struct virtio_net_device_ops { +struct vhost_device_ops {int (*new_device)(int vid);/**< Add device. */ void (*destroy_device)(int vid);/**< Remove device. */
@@ -198,7 +198,7 @@ static inline uint64_t __attribute__((always_inline))/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path, -struct virtio_net_device_ops const *const ops); +struct vhost_device_ops const *const ops);/* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start (void );
lib/librte_vhost/socket.c +3 -3
@@ -78,7 +78,7 @@ struct vhost_user_socket {uint64_t supported_features;uint64_t features; -struct virtio_net_device_ops const *notify_ops; +struct vhost_device_ops const *notify_ops; };struct vhost_user_connection {
@@ -748,7 +748,7 @@ struct vhost_user_reconnect_list {*/ int rte_vhost_driver_callback_register (const char *path, -struct virtio_net_device_ops const *const ops) +struct vhost_device_ops const *const ops) {struct vhost_user_socket *vsocket;
@@ -761,7 +761,7 @@ struct vhost_user_reconnect_list {return vsocket ?0 :-1 ; } -struct virtio_net_device_ops const * +struct vhost_device_ops const *vhost_driver_callback_get (const char *path) {struct vhost_user_socket *vsocket;
lib/librte_vhost/vhost.h +2 -2
@@ -191,7 +191,7 @@ struct virtio_net {struct ether_addr mac;uint16_t mtu; -struct virtio_net_device_ops const *notify_ops; +struct vhost_device_ops const *notify_ops;uint32_t nr_guest_pages;uint32_t max_guest_pages;
@@ -265,7 +265,7 @@ static inline phys_addr_t __attribute__((always_inline))void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid); -struct virtio_net_device_ops const *vhost_driver_callback_get (const char *path); +struct vhost_device_ops const *vhost_driver_callback_get (const char *path);/* * Backend-specific cleanup.
Signature · 1 line
1.9.0
PATCH v3 15/22 vhost: rename virtio-net to vhost
In reply to Yuanhan LiuRename "virtio-net" to "vhost" in the API comments and vhost prog guide.
--- doc/guides/prog_guide/vhost_lib.rst | 6 +++--- lib/librte_vhost/rte_virtio_net.h | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +3 -3
@@ -130,12 +130,12 @@ The following is an overview of some key Vhost API functions: * ``new_device(int vid)`` - This callback is invoked when a virtio net device becomes ready. ``vid`` - is the virtio net device ID. + This callback is invoked when a virtio device becomes ready. ``vid`` + is the vhost device ID. * ``destroy_device(int vid)`` - This callback is invoked when a virtio net device shuts down (or when the + This callback is invoked when a virtio device shuts down (or when the vhost connection is broken). * ``vring_state_changed(int vid, uint16_t queue_id, int enable)``
lib/librte_vhost/rte_virtio_net.h +7 -7
@@ -222,7 +222,7 @@ int rte_vhost_driver_callback_register(const char *path,* is allocated. * * @param vid -* virtio-net device ID +* vhost device ID * * @return * The numa node, -1 on failure
@@ -234,11 +234,11 @@ int rte_vhost_driver_callback_register(const char *path,* Get the number of queues the device supports. * * Note this function is deprecated, as it returns a queue pair number, -* which is virtio-net specific. Instead, rte_vhost_get_vring_num should +* which is vhost specific. Instead, rte_vhost_get_vring_num should * be used. * * @param vid -* virtio-net device ID +* vhost device ID * * @return * The number of queues, 0 on failure
@@ -262,7 +262,7 @@ int rte_vhost_driver_callback_register(const char *path,* file path. * * @param vid -* virtio-net device ID +* vhost device ID * @param buf * The buffer to stored the queried ifname * @param len
@@ -277,7 +277,7 @@ int rte_vhost_driver_callback_register(const char *path,* Get how many avail entries are left in the queue * * @param vid -* virtio-net device ID +* vhost device ID * @param queue_id * virtio queue index *
@@ -292,7 +292,7 @@ int rte_vhost_driver_callback_register(const char *path,* count is returned to indicate the number of packets that were succesfully * added to the RX queue. * @param vid -* virtio-net device ID +* vhost device ID * @param queue_id * virtio queue index in mq case * @param pkts
@@ -310,7 +310,7 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,* construct host mbufs, copies guest buffer content to host mbufs and * store them in pkts to be processed. * @param vid -* virtio-net device +* vhost device ID * @param queue_id * virtio queue index in mq case * @param mbuf_pool
Signature · 1 line
1.9.0
PATCH v3 16/22 vhost: add features changed callback
In reply to Yuanhan LiuFeatures could be changed after the feature negotiation. For example, VHOST_F_LOG_ALL will be set/cleared at the start/end of live migration, respecitively. Thus, we need a new callback to inform the application on such change.
--- doc/guides/prog_guide/vhost_lib.rst | 6 ++++++ lib/librte_vhost/rte_virtio_net.h | 10 +++++++++- lib/librte_vhost/vhost_user.c | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-)
doc/guides/prog_guide/vhost_lib.rst +6 -0
@@ -143,6 +143,12 @@ The following is an overview of some key Vhost API functions: This callback is invoked when a specific queue's state is changed, for example to enabled or disabled. + * ``features_changed(int vid, uint64_t features)`` + + This callback is invoked when the features is changed. For example, + ``VHOST_F_LOG_ALL`` will be set/cleared at the start/end of live + migration, respectively. + * ``rte_vhost_enqueue_burst(vid, queue_id, pkts, count)`` Transmits (enqueues) ``count`` packets from host to guest.
lib/librte_vhost/rte_virtio_net.h +9 -1
@@ -93,7 +93,15 @@ struct vhost_device_ops {int (*vring_state_changed)(int vid,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ -void *reserved[5 ];/**< Reserved for future extension */ +/** +* Features could be changed after the feature negotiation. +* For example, VHOST_F_LOG_ALL will be set/cleared at the +* start/end of live migration, respectively. This callback +* is used to inform the application on such change. +*/ +int (*features_changed)(int vid,uint64_t features); + +void *reserved[4 ];/**< Reserved for future extension */ };/**
lib/librte_vhost/vhost_user.c +5 -0
@@ -161,6 +161,11 @@if (features & ~rte_vhost_driver_get_features (dev->ifname))return -1 ; +if ((dev->flags &VIRTIO_DEV_RUNNING ) && dev->features != features) { +if (dev->notify_ops->features_changed) + dev->notify_ops->features_changed (dev->vid, features); + } + dev->features = features;if (dev->features & ((1 <<VIRTIO_NET_F_MRG_RXBUF ) | (1ULL <<VIRTIO_F_VERSION_1 ))) {
Signature · 1 line
1.9.0
Re: [PATCH v3 16/22] vhost: add features changed callback
Quoted 11 lines · Yuanhan Liu
Features could be changed after the feature negotiation. For example,
VHOST_F_LOG_ALLwill be set/cleared at the start/end of live migration, respecitively. Thus, we need a new callback to inform the application on such change.Signed-off-by Yuanhan Liu <[email protected]>--- doc/guides/prog_guide/vhost_lib.rst | 6 ++++++ lib/librte_vhost/rte_virtio_net.h | 10 +++++++++- lib/librte_vhost/vhost_user.c | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-)
Thanks,
Maxime
PATCH v3 17/22 vhost: export APIs for live migration support
In reply to Yuanhan LiuExport few APIs for the vhost-user driver to log the guest memory writes, which is a must for live migration support.
This patch basically moves vhost_log_write() and vhost_log_used_vring() into vhost.h and then add an wrapper (the public API) to them.
--- lib/librte_vhost/rte_vhost_version.map | 2 ++ lib/librte_vhost/rte_virtio_net.h | 43 ++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 31 ++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 38 ++++++++++++++++++++++++++++++ lib/librte_vhost/virtio_net.c | 36 ---------------------------- 5 files changed, 114 insertions(+), 36 deletions(-)
lib/librte_vhost/rte_vhost_version.map +2 -0
@@ -41,5 +41,7 @@ DPDK_17.05 { rte_vhost_get_vhost_vring; rte_vhost_get_vring_num; rte_vhost_gpa_to_vva; + rte_vhost_log_used_vring; + rte_vhost_log_write; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +43 -0
49 lines not on this page · raw message
lib/librte_vhost/vhost.c +31 -0
@@ -443,3 +443,34 @@ struct virtio_net * dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ;return 0 ; } + +void +rte_vhost_log_write (int vid,uint64_t addr,uint64_t len) +{ +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return ; + +vhost_log_write (dev, addr, len); +} + +void +rte_vhost_log_used_vring (int vid,uint16_t vring_idx, +uint64_t offset,uint64_t len) +{ +struct virtio_net *dev; +struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (dev ==NULL ) +return ; + +if (vring_idx >=VHOST_MAX_VRING ) +return ; + vq = dev->virtqueue[vring_idx]; +if (!vq) +return ; + +vhost_log_used_vring (dev, vq, offset, len); +}
lib/librte_vhost/vhost.h +38 -0
@@ -198,6 +198,44 @@ struct virtio_net {struct guest_page *guest_pages; } __rte_cache_aligned; + +#define VHOST_LOG_PAGE 4096 + +static inline void __attribute__((always_inline)) +vhost_log_page (uint8_t *log_base,uint64_t page) +{ + log_base[page /8 ] |=1 << (page %8 ); +} + +static inline void __attribute__((always_inline)) +vhost_log_write (struct virtio_net *dev,uint64_t addr,uint64_t len) +{ +uint64_t page; + +if (likely (((dev->features & (1ULL <<VHOST_F_LOG_ALL )) ==0 ) || + !dev->log_base || !len)) +return ; + +if (unlikely (dev->log_size <= ((addr + len -1 ) /VHOST_LOG_PAGE /8 ))) +return ; + +/* To make sure guest memory updates are committed before logging */ +rte_smp_wmb (); + + page = addr /VHOST_LOG_PAGE ; +while (page *VHOST_LOG_PAGE < addr + len) { +vhost_log_page ((uint8_t *)(uintptr_t )dev->log_base, page); + page +=1 ; + } +} + +static inline void __attribute__((always_inline)) +vhost_log_used_vring (struct virtio_net *dev,struct vhost_virtqueue *vq, +uint64_t offset,uint64_t len) +{ +vhost_log_write (dev, vq->log_guest_addr + offset, len); +} +/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
lib/librte_vhost/virtio_net.c +0 -36
@@ -48,42 +48,6 @@#include "vhost.h" #define MAX_PKT_BURST 32 -#define VHOST_LOG_PAGE 4096 - -static inline void __attribute__((always_inline)) -vhost_log_page (uint8_t *log_base,uint64_t page) -{ - log_base[page /8 ] |=1 << (page %8 ); -} - -static inline void __attribute__((always_inline)) -vhost_log_write (struct virtio_net *dev,uint64_t addr,uint64_t len) -{ -uint64_t page; - -if (likely (((dev->features & (1ULL <<VHOST_F_LOG_ALL )) ==0 ) || - !dev->log_base || !len)) -return ; - -if (unlikely (dev->log_size <= ((addr + len -1 ) /VHOST_LOG_PAGE /8 ))) -return ; - -/* To make sure guest memory updates are committed before logging */ -rte_smp_wmb (); - - page = addr /VHOST_LOG_PAGE ; -while (page *VHOST_LOG_PAGE < addr + len) { -vhost_log_page ((uint8_t *)(uintptr_t )dev->log_base, page); - page +=1 ; - } -} - -static inline void __attribute__((always_inline)) -vhost_log_used_vring (struct virtio_net *dev,struct vhost_virtqueue *vq, -uint64_t offset,uint64_t len) -{ -vhost_log_write (dev, vq->log_guest_addr + offset, len); -}static bool is_valid_virt_queue_idx (uint32_t idx,int is_tx,uint32_t nr_vring)
Signature · 1 line
1.9.0
Re: [PATCH v3 17/22] vhost: export APIs for live migration support
Quoted 6 lines · Yuanhan Liu
Export few APIs for the vhost-user driver to log the guest memory writes, which is a must for live migration support.
This patch basically moves
vhost_log_write()andvhost_log_used_vring()intovhost.hand then add an wrapper (the public API) to them.
Quoted 8 lines
Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost_version.map | 2 ++ lib/librte_vhost/rte_virtio_net.h | 43 ++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 31 ++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 38 ++++++++++++++++++++++++++++++ lib/librte_vhost/virtio_net.c | 36 ---------------------------- 5 files changed, 114 insertions(+), 36 deletions(-)
Thanks,
Maxime
PATCH v3 18/22 vhost: introduce API to start a specific driver
In reply to Yuanhan LiuWe used to use rte_vhost_driver_session_start() to trigger the vhost-user session. It takes no argument, thus it's a global trigger. And it could be problematic.
The issue is, currently, rte_vhost_driver_register(path, flags) actually tries to put it into the session loop (by fdset_add). However, it needs a set of APIs to set a vhost-user driver properly:
* rte_vhost_driver_register(path, flags);
* rte_vhost_driver_set_features(path, features);
* rte_vhost_driver_callback_register(path, vhost_device_ops);
If a new vhost-user driver is registered after the trigger (think OVS-DPDK that could add a port dynamically from cmdline), the current code will effectively starts the session for the new driver just after the first API rte_vhost_driver_register() is invoked, leaving later calls taking no effect at all.
To handle the case properly, this patch introduce a new API, rte_vhost_driver_start(path), to trigger a specific vhost-user driver. To do that, the rte_vhost_driver_register(path, flags) is simplified to create the socket only and let rte_vhost_driver_start(path) to actually put it into the session loop.
Meanwhile, the rte_vhost_driver_session_start is removed: we could hide the session thread internally (create the thread if it has not been created). This would also simplify the application.
NOTE: the API order in prog guide is slightly adjusted for showing the correct invoke order.
---
v3: - fix broken reconnect
--- doc/guides/prog_guide/vhost_lib.rst | 24 +++++----- doc/guides/rel_notes/release_17_05.rst | 8 ++++ drivers/net/vhost/rte_eth_vhost.c | 50 ++------------------ examples/tep_termination/main.c | 8 +++- examples/vhost/main.c | 9 +++- lib/librte_vhost/fd_man.c | 9 ++-- lib/librte_vhost/fd_man.h | 2 +- lib/librte_vhost/rte_vhost_version.map | 2 +- lib/librte_vhost/rte_virtio_net.h | 15 +++++- lib/librte_vhost/socket.c | 84 ++++++++++++++++++++-------------- 10 files changed, 108 insertions(+), 103 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +11 -13
@@ -116,12 +116,6 @@ The following is an overview of some key Vhost API functions: vhost-user driver could be vhost-user net, yet it could be something else, say, vhost-user SCSI. -* ``rte_vhost_driver_session_start()`` - - This function starts the vhost session loop to handle vhost messages. It - starts an infinite loop, therefore it should be called in a dedicated - thread. - * ``rte_vhost_driver_callback_register(path, vhost_device_ops)`` This function registers a set of callbacks, to let DPDK applications take
@@ -149,6 +143,17 @@ The following is an overview of some key Vhost API functions: ``VHOST_F_LOG_ALL`` will be set/cleared at the start/end of live migration, respectively. +* ``rte_vhost_driver_disable/enable_features(path, features))`` + + This function disables/enables some features. For example, it can be used to + disable mergeable buffers and TSO features, which both are enabled by + default. + +* ``rte_vhost_driver_start(path)`` + + This function triggers the vhost-user negotiation. It should be invoked at + the end of initializing a vhost-user driver. + * ``rte_vhost_enqueue_burst(vid, queue_id, pkts, count)`` Transmits (enqueues) ``count`` packets from host to guest.
@@ -157,13 +162,6 @@ The following is an overview of some key Vhost API functions: Receives (dequeues) ``count`` packets from guest, and stored them at ``pkts``. -* ``rte_vhost_driver_disable/enable_features(path, features))`` - - This function disables/enables some features. For example, it can be used to - disable mergeable buffers and TSO features, which both are enabled by - default. - - Vhost-user Implementations --------------------------
doc/guides/rel_notes/release_17_05.rst +8 -0
@@ -57,6 +57,11 @@ New Features * Enable Vhost PMD's MTU get feature. * Get max MTU value from host in Virtio PMD +* **Made the vhost lib be a generic vhost-user lib.** + + Now it could be used to implement any other vhost-user drivers, such + as, vhost-user SCSI. + Resolved Issues ---------------
@@ -157,6 +162,9 @@ API Changes * The vhost struct ``virtio_net_device_ops`` is renamed to ``vhost_device_ops`` + * The vhost API ``rte_vhost_driver_session_start`` is removed. Instead, + ``rte_vhost_driver_start`` should be used. + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +4 -46
74 lines not on this page · raw message
examples/tep_termination/main.c +7 -1
@@ -1263,7 +1263,13 @@ static inline void __attribute__((always_inline)) "failed to register vhost driver callbacks.\n"); } -rte_vhost_driver_session_start (); +if (rte_vhost_driver_start (dev_basename) <0 ) { +rte_exit (EXIT_FAILURE , +"failed to start vhost driver.\n" ); + } + +RTE_LCORE_FOREACH_SLAVE (lcore_id) +rte_eal_wait_lcore (lcore_id);return 0 ; }
examples/vhost/main.c +8 -1
@@ -1545,9 +1545,16 @@ static inline void __attribute__((always_inline))rte_exit (EXIT_FAILURE ,"failed to register vhost driver callbacks.\n" ); } + +if (rte_vhost_driver_start (file) <0 ) { +rte_exit (EXIT_FAILURE , +"failed to start vhost driver.\n" ); + } } -rte_vhost_driver_session_start (); +RTE_LCORE_FOREACH_SLAVE (lcore_id) +rte_eal_wait_lcore (lcore_id); +return 0 ; }
lib/librte_vhost/fd_man.c +6 -3
@@ -210,8 +210,8 @@* will wait until the flag is reset to zero(which indicates the callback is * finished), then it could free the context after fdset_del. */ -void -fdset_event_dispatch (struct fdset *pfdset) +void * +fdset_event_dispatch (void *arg) {int i;struct pollfd *pfd;
@@ -221,9 +221,10 @@int fd, numfds;int remove1, remove2;int need_shrink; +struct fdset *pfdset = arg;if (pfdset ==NULL ) -return ; +return NULL ;while (1 ) {
@@ -294,4 +295,6 @@if (need_shrink)fdset_shrink (pfdset); } + +return NULL ; }
lib/librte_vhost/fd_man.h +1 -1
@@ -64,6 +64,6 @@ int fdset_add(struct fdset *pfdset, int fd,void *fdset_del (struct fdset *pfdset,int fd); -void fdset_event_dispatch (struct fdset *pfdset); +void *fdset_event_dispatch (void *arg);#endif
lib/librte_vhost/rte_vhost_version.map +1 -1
@@ -4,7 +4,6 @@ DPDK_2.0 { rte_vhost_dequeue_burst; rte_vhost_driver_callback_register; rte_vhost_driver_register; - rte_vhost_driver_session_start; rte_vhost_enable_guest_notification; rte_vhost_enqueue_burst;
@@ -35,6 +34,7 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_driver_start; rte_vhost_get_mem_table; rte_vhost_get_mtu; rte_vhost_get_negotiated_features;
lib/librte_vhost/rte_virtio_net.h +13 -2
@@ -250,8 +250,19 @@ void rte_vhost_log_used_vring(int vid, uint16_t vring_idx,/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path,struct vhost_device_ops const *const ops); -/* Start vhost driver session blocking loop. */ -int rte_vhost_driver_session_start (void ); + +/** +* +* Start the vhost-user driver. +* +* This function triggers the vhost-user negotiation. +* +* @param path +* The vhost-user socket file path +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_driver_start (const char *path);/** * Get the MTU value of the device if set in QEMU.
lib/librte_vhost/socket.c +49 -35
172 lines not on this page · raw message
Signature · 1 line
1.9.0
Re: [PATCH v3 18/22] vhost: introduce API to start a specific driver
Quoted 34 lines · Yuanhan Liu
We used to use
rte_vhost_driver_session_start()to trigger the vhost-user session. It takes no argument, thus it's a global trigger. And it could be problematic.The issue is, currently,
rte_vhost_driver_register(path, flags)actually tries to put it into the session loop (byfdset_add). However, it needs a set of APIs to set a vhost-user driver properly:
*rte_vhost_driver_register(path, flags);
*rte_vhost_driver_set_features(path, features);
*rte_vhost_driver_callback_register(path, vhost_device_ops);If a new vhost-user driver is registered after the trigger (think OVS-DPDK that could add a port dynamically from cmdline), the current code will effectively starts the session for the new driver just after the first API
rte_vhost_driver_register()is invoked, leaving later calls taking no effect at all.To handle the case properly, this patch introduce a new API,
rte_vhost_driver_start(path), to trigger a specific vhost-user driver. To do that, therte_vhost_driver_register(path, flags)is simplified to create the socket only and letrte_vhost_driver_start(path)to actually put it into the session loop.Meanwhile, the
rte_vhost_driver_session_startis removed: we could hide the session thread internally (create the thread if it has not been created). This would also simplify the application.NOTE: the API order in prog guide is slightly adjusted for showing the correct invoke order.
Signed-off-by Yuanhan Liu <[email protected]>---
v3: - fix broken reconnect
Quoted 13 lines
--- doc/guides/prog_guide/vhost_lib.rst | 24 +++++----- doc/guides/rel_notes/release_17_05.rst | 8 ++++ drivers/net/vhost/rte_eth_vhost.c | 50 ++------------------ examples/tep_termination/main.c | 8 +++- examples/vhost/main.c | 9 +++- lib/librte_vhost/fd_man.c | 9 ++-- lib/librte_vhost/fd_man.h | 2 +- lib/librte_vhost/rte_vhost_version.map | 2 +- lib/librte_vhost/rte_virtio_net.h | 15 +++++- lib/librte_vhost/socket.c | 84 ++++++++++++++++++++-------------- 10 files changed, 108 insertions(+), 103 deletions(-)
Thanks,
Maxime
PATCH v3 19/22 vhost: rename header file
In reply to Yuanhan LiuRename "rte_virtio_net.h" to "rte_vhost.h", to not let it be virtio net specific.
---
doc/guides/rel_notes/deprecation.rst | 9 ---------
doc/guides/rel_notes/release_17_05.rst | 3 +++
drivers/net/vhost/rte_eth_vhost.c | 2 +-
drivers/net/vhost/rte_eth_vhost.h | 2 +-
examples/tep_termination/main.c | 2 +-
examples/tep_termination/vxlan_setup.c | 2 +-
examples/vhost/main.c | 2 +-
lib/librte_vhost/Makefile | 2 +-
lib/librte_vhost/{rte_virtio_net.h => rte_vhost.h} | 10 +++++-----
lib/librte_vhost/vhost.c | 2 +-
lib/librte_vhost/vhost.h | 2 +-
lib/librte_vhost/vhost_user.h | 2 +-
lib/librte_vhost/virtio_net.c | 2 +-
13 files changed, 18 insertions(+), 24 deletions(-)
rename lib/librte_vhost/{rte_virtio_net.h => rte_vhost.h} (98%)doc/guides/rel_notes/deprecation.rst +0 -9
@@ -95,15 +95,6 @@ Deprecation Notices Target release for removal of the legacy API will be defined once most PMDs have switched to rte_flow. -* vhost: API/ABI changes are planned for 17.05, for making DPDK vhost library - generic enough so that applications can build different vhost-user drivers - (instead of vhost-user net only) on top of that. - Specifically, ``virtio_net_device_ops`` will be renamed to ``vhost_device_ops``. - Correspondingly, some API's parameter need be changed. Few more functions also - need be reworked to let it be device aware. For example, different virtio device - has different feature set, meaning functions like ``rte_vhost_feature_disable`` - need be changed. Last, file rte_virtio_net.h will be renamed to rte_vhost.h. - * ABI changes are planned for 17.05 in the ``rte_cryptodev_ops`` structure. A pointer to a rte_cryptodev_config structure will be added to the function prototype ``cryptodev_configure_t``, as a new parameter.
doc/guides/rel_notes/release_17_05.rst +3 -0
@@ -165,6 +165,9 @@ API Changes * The vhost API ``rte_vhost_driver_session_start`` is removed. Instead, ``rte_vhost_driver_start`` should be used. + * The vhost public header file ``rte_virtio_net.h`` is renamed to + ``rte_vhost.h`` + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -40,7 +40,7 @@#include <rte_memcpy.h> #include <rte_vdev.h> #include <rte_kvargs.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_spinlock.h> #include "rte_eth_vhost.h"
drivers/net/vhost/rte_eth_vhost.h +1 -1
@@ -41,7 +41,7 @@#include <stdint.h> #include <stdbool.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> /* * Event description.
examples/tep_termination/main.c +1 -1
@@ -49,7 +49,7 @@#include <rte_log.h> #include <rte_string_fns.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include "main.h" #include "vxlan.h"
examples/tep_termination/vxlan_setup.c +1 -1
@@ -49,7 +49,7 @@#include <rte_tcp.h> #include "main.h" -#include "rte_virtio_net.h" +#include "rte_vhost.h" #include "vxlan.h" #include "vxlan_setup.h"
examples/vhost/main.c +1 -1
@@ -49,7 +49,7 @@#include <rte_log.h> #include <rte_string_fns.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_ip.h> #include <rte_tcp.h>
lib/librte_vhost/Makefile +1 -1
@@ -51,7 +51,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c socket.c vhost.c vhost_user.c \ virtio_net.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h +SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h # dependencies DEPDIRS-$(CONFIG_RTE_LIBRTE_VHOST) += lib/librte_eal
lib/librte_vhost/rte_vhost.h renamed from lib/librte_vhost/rte_virtio_net.h +5 -5
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2017 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -31,12 +31,12 @@* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _VIRTIO_NET_H_ -#define _VIRTIO_NET_H_ +#ifndef _RTE_VHOST_H_ +#define _RTE_VHOST_H_/** * @file -* Interface to vhost net +* Interface to vhost-user */ #include <stdint.h>
@@ -418,4 +418,4 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,int rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx,struct rte_vhost_vring *vring); -#endif /* _VIRTIO_NET_H_ */ +#endif /* _RTE_VHOST_H_ */
lib/librte_vhost/vhost.c +1 -1
@@ -45,7 +45,7 @@#include <rte_string_fns.h> #include <rte_memory.h> #include <rte_malloc.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include "vhost.h"
lib/librte_vhost/vhost.h +1 -1
@@ -46,7 +46,7 @@#include <rte_log.h> #include <rte_ether.h> -#include "rte_virtio_net.h" +#include "rte_vhost.h" /* Used to indicate that the device is running on a data core */ #define VIRTIO_DEV_RUNNING 1
lib/librte_vhost/vhost_user.h +1 -1
@@ -37,7 +37,7 @@#include <stdint.h> #include <linux/vhost.h> -#include "rte_virtio_net.h" +#include "rte_vhost.h" /* refer to hw/virtio/vhost-user.c */
lib/librte_vhost/virtio_net.c +1 -1
@@ -39,7 +39,7 @@#include <rte_memcpy.h> #include <rte_ether.h> #include <rte_ip.h> -#include <rte_virtio_net.h> +#include <rte_vhost.h> #include <rte_tcp.h> #include <rte_udp.h> #include <rte_sctp.h>
Signature · 1 line
1.9.0
PATCH v3 20/22 vhost: workaround the build dependency on mbuf header
In reply to Yuanhan Liurte_mbuf struct is something more likely will be used only in vhost-user net driver, while we have made vhost-user generic enough that it can be used for implementing other drivers (such as vhost-user SCSI), they have also include <rte_mbuf.h>. Otherwise, the build will be broken.
We could workaround it by using forward declaration, so that other non-net drivers won't need include <rte_mbuf.h>.
--- lib/librte_vhost/rte_vhost.h | 2 ++ 1 file changed, 2 insertions(+)
lib/librte_vhost/rte_vhost.h +2 -0
@@ -348,6 +348,8 @@ int rte_vhost_driver_callback_register(const char *path,*/ uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id); +struct rte_mbuf ; +struct rte_mempool ;/** * This function adds buffers to the virtio devices RX virtqueue. Buffers can * be received from the physical port or from another virtual device. A packet
Signature · 1 line
1.9.0
Re: [PATCH v3 20/22] vhost: workaround the build dependency on mbuf header
Quoted 5 lines · Yuanhan Liu
rte_mbufstruct is something more likely will be used only in vhost-user net driver, while we have made vhost-user generic enough that it can be used for implementing other drivers (such as vhost-user SCSI), they have also include <rte_mbuf.h>. Otherwise, the build will be broken.
Quoted 7 lines
We could workaround it by using forward declaration, so that other non-net drivers won't need include <
rte_mbuf.h>.Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/rte_vhost.h | 2 ++ 1 file changed, 2 insertions(+)
Thanks,
Maxime
PATCH v3 21/22 vhost: do not destroy device on repeat mem table message
In reply to Yuanhan LiuIt doesn't make any sense to invoke destroy_device() callback at while handling SET_MEM_TABLE message.
Quoted 1 line
From the vhost-user spec, it's the
GET_VRING_BASEmessage indicates
the end of a vhost device: the destroy_device() should be invoked from there (luckily, we already did that).
--- lib/librte_vhost/vhost_user.c | 6 ------ 1 file changed, 6 deletions(-)
lib/librte_vhost/vhost_user.c +0 -6
@@ -496,12 +496,6 @@uint32_t i;int fd; -/* Remove from the data plane. */ -if (dev->flags &VIRTIO_DEV_RUNNING ) { - dev->flags &= ~VIRTIO_DEV_RUNNING ; - dev->notify_ops->destroy_device (dev->vid); - } -if (dev->mem) {free_mem_region (dev);rte_free (dev->mem);
Signature · 1 line
1.9.0
Re: [PATCH v3 21/22] vhost: do not destroy device on repeat mem table message
Quoted 11 lines · Yuanhan Liu
It doesn't make any sense to invoke
destroy_device()callback at while handlingSET_MEM_TABLEmessage.From the vhost-user spec, it's the
GET_VRING_BASEmessage indicates the end of a vhost device: thedestroy_device()should be invoked from there (luckily, we already did that).Signed-off-by Yuanhan Liu <[email protected]>--- lib/librte_vhost/vhost_user.c | 6 ------ 1 file changed, 6 deletions(-)
Thanks,
Maxime
PATCH v3 22/22 examples/vhost: demonstrate the new generic vhost APIs
In reply to Yuanhan LiuNow DPDK vhost lib has been generic enough, that it can be used to implement any vhost-user drivers.
For example, this patch implements a very simple vhost-user net driver, mainly for demonstrating how to use those generic vhost APIs.
And when the --builtin-net-driver option is used, the example virtio-net driver code will be invoked, instead of the one provided from the vhost library.
--- examples/vhost/Makefile | 2 +- examples/vhost/main.c | 37 +++- examples/vhost/main.h | 29 +++- examples/vhost/virtio_net.c | 405 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 466 insertions(+), 7 deletions(-) create mode 100644 examples/vhost/virtio_net.c
examples/vhost/Makefile +1 -1
@@ -48,7 +48,7 @@ else APP = vhost-switch # all source are stored in SRCS-y -SRCS-y := main.c +SRCS-y := main.c virtio_net.c CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 CFLAGS += $(WERROR_FLAGS)
examples/vhost/main.c +32 -5
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2016 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2017 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -65,7 +65,6 @@#define MBUF_CACHE_SIZE 128#define MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE -#define MAX_PKT_BURST 32/* Max burst size for RX/TX */ #define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ #define BURST_RX_WAIT_US 15/* Defines how long we wait between retries on RX */
@@ -129,6 +128,8 @@static int client_mode;static int dequeue_zero_copy; +static int builtin_net_driver; +/* Specify timeout (in useconds) between retries on RX. */ static uint32_t burst_rx_delay_time =BURST_RX_WAIT_US ;/* Specify the number of retries on RX. */
@@ -499,6 +500,7 @@ struct mbuf_table { {"tso", required_argument, NULL, 0}, {"client", no_argument, &client_mode, 1}, {"dequeue-zero-copy", no_argument, &dequeue_zero_copy, 1}, + {"builtin-net-driver", no_argument, &builtin_net_driver, 1}, {NULL, 0, 0, 0}, };
@@ -795,7 +797,12 @@ static inline void __attribute__((always_inline)) {uint16_t ret; - ret =rte_vhost_enqueue_burst (dst_vdev->vid,VIRTIO_RXQ , &m,1 ); +if (builtin_net_driver) { + ret =vs_enqueue_pkts (dst_vdev,VIRTIO_RXQ , &m,1 ); + }else { + ret =rte_vhost_enqueue_burst (dst_vdev->vid,VIRTIO_RXQ , &m,1 ); + } +if (enable_stats) {rte_atomic64_inc (&dst_vdev->stats.rx_total_atomic);rte_atomic64_add (&dst_vdev->stats.rx_atomic, ret);
@@ -1066,8 +1073,13 @@ static inline void __attribute__((always_inline)) } } - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , +if (builtin_net_driver) { + enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , pkts, rx_count); + }else { + enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , + pkts, rx_count); + }if (enable_stats) {rte_atomic64_add (&vdev->stats.rx_total_atomic, rx_count);rte_atomic64_add (&vdev->stats.rx_atomic, enqueue_count);
@@ -1083,8 +1095,13 @@ static inline void __attribute__((always_inline))uint16_t count;uint16_t i; - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , mbuf_pool, +if (builtin_net_driver) { + count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST ); + }else { + count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , + mbuf_pool, pkts,MAX_PKT_BURST ); + }/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1187,6 +1204,9 @@ static inline void __attribute__((always_inline))rte_pause (); } +if (builtin_net_driver) +vs_vhost_net_remove (vdev); +TAILQ_REMOVE (&lcore_info[vdev->coreid].vdev_list, vdev, lcore_vdev_entry);TAILQ_REMOVE (&vhost_dev_list, vdev, global_vdev_entry);
@@ -1235,6 +1255,9 @@ static inline void __attribute__((always_inline)) } vdev->vid = vid; +if (builtin_net_driver) +vs_vhost_net_setup (vdev); +TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, global_vdev_entry); vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;
@@ -1513,6 +1536,10 @@ static inline void __attribute__((always_inline))rte_exit (EXIT_FAILURE ,"vhost driver register failure.\n" ); } + +if (builtin_net_driver) +rte_vhost_driver_set_features (file,VIRTIO_NET_FEATURES ); +if (mergeable ==0 ) {rte_vhost_driver_disable_features (file,1ULL <<VIRTIO_NET_F_MRG_RXBUF );
examples/vhost/main.h +28 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2016 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2017 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -43,8 +43,11 @@#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2#define RTE_LOGTYPE_VHOST_PORT RTE_LOGTYPE_USER3 +enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; +#define MAX_PKT_BURST 32/* Max burst size for RX/TX */ +struct device_statistics {uint64_t tx;uint64_t tx_total;
@@ -52,6 +55,12 @@ struct device_statistics {rte_atomic64_t rx_total_atomic; }; +struct vhost_queue { +struct rte_vhost_vring vr; +uint16_t last_avail_idx; +uint16_t last_used_idx; +}; +struct vhost_dev {/**< Number of memory regions for gpa to hpa translation. */ uint32_t nregions_hpa;
@@ -69,9 +78,16 @@ struct vhost_dev {volatile uint8_t remove;int vid; +uint64_t features; +size_t hdr_len; +uint16_t nr_vrings; +struct rte_vhost_memory *mem;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) global_vdev_entry;TAILQ_ENTRY (vhost_dev) lcore_vdev_entry; + +#define MAX_QUEUE_PAIRS 4 +struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned;TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -92,4 +108,15 @@ struct lcore_info { struct vhost_dev_tailq_list vdev_list; }; +/* we implement non-extra virtio net features */ +#define VIRTIO_NET_FEATURES 0 + +void vs_vhost_net_setup (struct vhost_dev *dev); +void vs_vhost_net_remove (struct vhost_dev *dev); +uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c new file +405 -0
405 lines not on this page · raw message
Signature · 1 line
1.9.0
v4 cover vhost: generic vhost API
In reply to Yuanhan LiuThis patchset makes DPDK vhost library generic enough, so that we could build other vhost-user drivers on top of it. For example, SPDK (Storage Performance Development Kit) is trying to enable vhost-user SCSI.
The basic idea is, let DPDK vhost be a vhost-user agent. It stores all the info about the virtio device (i.e. vring address, negotiated features, etc) and let the specific vhost-user driver to fetch them (by the API provided by DPDK vhost lib). With those info being provided, the vhost-user driver then could get/put vring entries, thus, it could exchange data between the guest and host.
The last patch demonstrates how to use these new APIs to implement a very simple vhost-user net driver, without any fancy features enabled.
Change log
==========
v2: - rebase
- updated release note
- updated API comments
- renamed rte_vhost_get_vhost_memory to rte_vhost_get_mem_table
- added a new device callback: features_changed(), bascially for live migration support
- introduced rte_vhost_driver_start() to start a specific driver
- misc fixes
v3: - rebaseon top of vhost-user socket fix
- fix reconnect
- fix shared build
- fix typos
v4: - rebase
- let rte_vhost_get.*_features() to return features by parameter and return -1 on failure
- Follow the style of ring rework to update the release note: use one entry for all vhost changes and add sub items for each change.
Major API/ABI Changes summary
=============================
- some renames
* "struct virtio_net_device_ops" ==> "struct vhost_device_ops"
* "rte_virtio_net.h" ==> "rte_vhost.h"
- driver related APIs are bond with the socket file
* rte_vhost_driver_set_features(socket_file, features);
* rte_vhost_driver_get_features(socket_file, features);
* rte_vhost_driver_enable_features(socket_file, features)
* rte_vhost_driver_disable_features(socket_file, features)
* rte_vhost_driver_callback_register(socket_file, notify_ops);
* rte_vhost_driver_start(socket_file);
This function replaces rte_vhost_driver_session_start(). Check patch 18 for more information.
- new APIs to fetch guest and vring info
* rte_vhost_get_mem_table(vid, mem);
* rte_vhost_get_negotiated_features(vid);
* rte_vhost_get_vhost_vring(vid, vring_idx, vring);
- new exported structures
* struct rte_vhost_vring
* struct rte_vhost_mem_region
* struct rte_vhost_memory
- a new device ops callback: features_changed().
--yliu
---
Yuanhan Liu (22):
vhost: introduce driver features related APIs net/vhost: remove feature related APIs
vhost: use new APIs to handle features
vhost: make notify ops per vhost driver
vhost: export guest memory regions
vhost: introduce API to fetch negotiated features
vhost: export vhost vring info
vhost: export API to translate gpa to vva
vhost: turn queue pair to vring
vhost: export the number of vrings
vhost: move the device ready check at proper place
vhost: drop the Rx and Tx queue macro
vhost: do not include net specific headers
vhost: rename device ops struct
vhost: rename virtio-net to vhost
vhost: add features changed callback
vhost: export APIs for live migration support
vhost: introduce API to start a specific driver
vhost: rename header file
vhost: workaround the build dependency on mbuf header
vhost: do not destroy device on repeat mem table message examples/vhost: demonstrate the new generic vhost APIs
doc/guides/prog_guide/vhost_lib.rst | 42 +-- doc/guides/rel_notes/deprecation.rst | 9 - doc/guides/rel_notes/release_17_05.rst | 43 +++ drivers/net/vhost/rte_eth_vhost.c | 101 ++----- drivers/net/vhost/rte_eth_vhost.h | 32 +-- drivers/net/vhost/rte_pmd_vhost_version.map | 3 - examples/tep_termination/main.c | 23 +- examples/tep_termination/main.h | 2 + examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/Makefile | 2 +- examples/vhost/main.c | 100 +++++-- examples/vhost/main.h | 32 ++- examples/vhost/virtio_net.c | 405 ++++++++++++++++++++++++++ lib/librte_vhost/Makefile | 4 +- lib/librte_vhost/fd_man.c | 9 +- lib/librte_vhost/fd_man.h | 2 +- lib/librte_vhost/rte_vhost.h | 427 ++++++++++++++++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 16 +- lib/librte_vhost/rte_virtio_net.h | 208 -------------- lib/librte_vhost/socket.c | 229 ++++++++++++--- lib/librte_vhost/vhost.c | 230 ++++++++------- lib/librte_vhost/vhost.h | 113 +++++--- lib/librte_vhost/vhost_user.c | 121 ++++---- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 71 ++--- 25 files changed, 1541 insertions(+), 687 deletions(-) create mode 100644 examples/vhost/virtio_net.c create mode 100644 lib/librte_vhost/rte_vhost.h delete mode 100644 lib/librte_vhost/rte_virtio_net.h
Signature · 1 line
1.9.0
PATCH v4 1/22 vhost: introduce driver features related APIs
Introduce few APIs to set/get/enable/disable driver features.
--- doc/guides/prog_guide/vhost_lib.rst | 10 +++- lib/librte_vhost/rte_vhost_version.map | 4 ++ lib/librte_vhost/rte_virtio_net.h | 53 ++++++++++++++++++++ lib/librte_vhost/socket.c | 92 ++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 2 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +8 -2
@@ -53,7 +53,7 @@ vhost library should be able to: Vhost API Overview ------------------ -The following is an overview of the Vhost API functions: +The following is an overview of some key Vhost API functions: * ``rte_vhost_driver_register(path, flags)``
@@ -110,6 +110,12 @@ The following is an overview of the Vhost API functions: of those segments, thus the fewer the segments, the quicker we will get the mapping. NOTE: we may speed it by using tree searching in future. +* ``rte_vhost_driver_set_features(path, features)`` + + This function sets the feature bits the vhost-user driver supports. The + vhost-user driver could be vhost-user net, yet it could be something else, + say, vhost-user SCSI. + * ``rte_vhost_driver_session_start()`` This function starts the vhost session loop to handle vhost messages. It
@@ -145,7 +151,7 @@ The following is an overview of the Vhost API functions: Receives (dequeues) ``count`` packets from guest, and stored them at ``pkts``. -* ``rte_vhost_feature_disable/rte_vhost_feature_enable(feature_mask)`` +* ``rte_vhost_driver_disable/enable_features(path, features))`` This function disables/enables some features. For example, it can be used to disable mergeable buffers and TSO features, which both are enabled by
lib/librte_vhost/rte_vhost_version.map +4 -0
@@ -34,6 +34,10 @@ DPDK_16.07 { DPDK_17.05 { global: + rte_vhost_driver_disable_features; + rte_vhost_driver_enable_features; + rte_vhost_driver_get_features; + rte_vhost_driver_set_features; rte_vhost_get_mtu; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +53 -0
59 lines not on this page · raw message
lib/librte_vhost/socket.c +92 -0
104 lines not on this page · raw message
Signature · 1 line
1.9.0
Re: [PATCH v4 01/22] vhost: introduce driver features related APIs
2017-04-01 15:22, Yuanhan Liu:
lib/librte_vhost/rte_virtio_net.h struct virtio_net_device_ops { · line 105
Quoted 9 lines
lib/librte_vhost/rte_virtio_net.h +9
-0+/** +* Set the feature bits the vhost-user driver supports. +* +* @param path +* The vhost-user socket file path +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_driver_set_features (const char *path,uint64_t features);
The parameter @features is not documented.
I suggest
+ * @param features
+ * Supported features
PATCH v4 2/22 net/vhost: remove feature related APIs
In reply to Yuanhan LiuThe rte_eth_vhost_feature_disable/enable/get APIs are just a wrapper of rte_vhost_feature_disable/enable/get. However, the later are going to be refactored; it's going to take an extra parameter (socket_file path), to let it be per-device.
Instead of changing those vhost-pmd APIs to adapt to the new vhost APIs, we could simply remove them, and let vdev to serve this purpose. After all, vdev options is better for disabling/enabling some features.
---
v2: - write more informative commit log on why they are removed.
- update release note
--- doc/guides/rel_notes/release_17_05.rst | 13 +++++++++++++ drivers/net/vhost/rte_eth_vhost.c | 25 ------------------------ drivers/net/vhost/rte_eth_vhost.h | 30 ----------------------------- drivers/net/vhost/rte_pmd_vhost_version.map | 3 --- 4 files changed, 13 insertions(+), 58 deletions(-)
doc/guides/rel_notes/release_17_05.rst +13 -0
@@ -192,6 +192,19 @@ API Changes flagged by the compiler. The return value usage should be checked while fixing the compiler error due to the extra parameter. +* **Reworked rte_vhost library** + + The rte_vhost library has been reworked to make it generic enough so that + user could build other vhost-user drivers on top of it. To achieve that, + following changes have been made: + + * The following vhost-pmd APIs are removed: + + * ``rte_eth_vhost_feature_disable`` + * ``rte_eth_vhost_feature_enable`` + * ``rte_eth_vhost_feature_get`` + + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +0 -25
@@ -975,31 +975,6 @@ struct vhost_xstats_name_off {return 0 ; } -/** -* Disable features in feature_mask. Returns 0 on success. -*/ -int -rte_eth_vhost_feature_disable (uint64_t feature_mask) -{ -return rte_vhost_feature_disable (feature_mask); -} - -/** -* Enable features in feature_mask. Returns 0 on success. -*/ -int -rte_eth_vhost_feature_enable (uint64_t feature_mask) -{ -return rte_vhost_feature_enable (feature_mask); -} - -/* Returns currently supported vhost features */ -uint64_t -rte_eth_vhost_feature_get (void ) -{ -return rte_vhost_feature_get (); -} -static const struct eth_dev_ops ops = { .dev_start = eth_dev_start, .dev_stop = eth_dev_stop,
drivers/net/vhost/rte_eth_vhost.h +0 -30
@@ -43,36 +43,6 @@#include <rte_virtio_net.h> -/** -* Disable features in feature_mask. -* -* @param feature_mask -* Vhost features defined in "linux/virtio_net.h". -* @return -* - On success, zero. -* - On failure, a negative value. -*/ -int rte_eth_vhost_feature_disable (uint64_t feature_mask); - -/** -* Enable features in feature_mask. -* -* @param feature_mask -* Vhost features defined in "linux/virtio_net.h". -* @return -* - On success, zero. -* - On failure, a negative value. -*/ -int rte_eth_vhost_feature_enable (uint64_t feature_mask); - -/** -* Returns currently supported vhost features. -* -* @return -* Vhost features defined in "linux/virtio_net.h". -*/ -uint64_t rte_eth_vhost_feature_get (void ); -/* * Event description. */
drivers/net/vhost/rte_pmd_vhost_version.map +0 -3
@@ -1,9 +1,6 @@ DPDK_16.04 { global: - rte_eth_vhost_feature_disable; - rte_eth_vhost_feature_enable; - rte_eth_vhost_feature_get; rte_eth_vhost_get_queue_event; local: *;
Signature · 1 line
1.9.0
PATCH v4 3/22 vhost: use new APIs to handle features
In reply to Yuanhan Liu---
v3: fix comment typo
--- examples/tep_termination/main.c | 4 +++- examples/vhost/main.c | 43 +++++++++++++++++++++------------- lib/librte_vhost/rte_vhost_version.map | 3 --- lib/librte_vhost/rte_virtio_net.h | 13 ---------- lib/librte_vhost/socket.c | 23 +++++++++++++++++- lib/librte_vhost/vhost.c | 42 --------------------------------- lib/librte_vhost/vhost.h | 21 +++++++++++++++++ lib/librte_vhost/vhost_user.c | 14 +++++++---- 8 files changed, 83 insertions(+), 80 deletions(-)
examples/tep_termination/main.c +3 -1
@@ -1248,12 +1248,14 @@ static inline void __attribute__((always_inline))rte_eal_remote_launch (switch_worker, mbuf_pool, lcore_id); } -rte_vhost_feature_disable (1ULL <<VIRTIO_NET_F_MRG_RXBUF ); ret =rte_vhost_driver_register ((char *)&dev_basename,0 );if (ret !=0 )rte_exit (EXIT_FAILURE ,"failed to register vhost driver.\n" ); +rte_vhost_driver_disable_features (dev_basename, +1ULL <<VIRTIO_NET_F_MRG_RXBUF ); +rte_vhost_driver_callback_register (&virtio_net_device_ops);rte_vhost_driver_session_start ();
examples/vhost/main.c +27 -16
72 lines not on this page · raw message
lib/librte_vhost/rte_vhost_version.map +0 -3
@@ -7,9 +7,6 @@ DPDK_2.0 { rte_vhost_driver_session_start; rte_vhost_enable_guest_notification; rte_vhost_enqueue_burst; - rte_vhost_feature_disable; - rte_vhost_feature_enable; - rte_vhost_feature_get; local: *; };
lib/librte_vhost/rte_virtio_net.h +0 -13
@@ -70,19 +70,6 @@ struct virtio_net_device_ops {void *reserved[5 ];/**< Reserved for future extension */ }; -/** -* Disable features in feature_mask. Returns 0 on success. -*/ -int rte_vhost_feature_disable (uint64_t feature_mask); - -/** -* Enable features in feature_mask. Returns 0 on success. -*/ -int rte_vhost_feature_enable (uint64_t feature_mask); - -/* Returns currently supported vhost features */ -uint64_t rte_vhost_feature_get (void ); -int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/**
lib/librte_vhost/socket.c +22 -1
@@ -579,7 +579,13 @@ struct vhost_user_reconnect_list { *features = vsocket->features;pthread_mutex_unlock (&vhost_user.mutex); -return vsocket ?0 :-1 ; +if (!vsocket) { +RTE_LOG (ERR ,VHOST_CONFIG , +"socket file %s is not registered yet.\n" , path); +return -1 ; + }else { +return 0 ; + } }/*
@@ -613,6 +619,21 @@ struct vhost_user_reconnect_list {pthread_mutex_init (&vsocket->conn_mutex,NULL ); vsocket->dequeue_zero_copy = flags &RTE_VHOST_USER_DEQUEUE_ZERO_COPY ; +/* +* Set the supported features correctly for the builtin vhost-user +* net driver. +* +* Applications know nothing about features the builtin virtio net +* driver (virtio_net.c) supports, thus it's not possible for them +* to invoke rte_vhost_driver_set_features(). To workaround it, here +* we set it unconditionally. If the application want to implement +* another vhost-user driver (say SCSI), it should call the +* rte_vhost_driver_set_features(), which will overwrite following +* two values. +*/ + vsocket->supported_features =VIRTIO_NET_SUPPORTED_FEATURES ; + vsocket->features =VIRTIO_NET_SUPPORTED_FEATURES ; +if ((flags &RTE_VHOST_USER_CLIENT ) !=0 ) { vsocket->reconnect = !(flags &RTE_VHOST_USER_NO_RECONNECT );if (vsocket->reconnect && reconn_tid ==0 ) {
lib/librte_vhost/vhost.c +0 -42
54 lines not on this page · raw message
lib/librte_vhost/vhost.h +21 -0
@@ -133,6 +133,27 @@ struct vhost_virtqueue {#define VIRTIO_F_VERSION_1 32#endif +#define VHOST_USER_F_PROTOCOL_FEATURES 30 + +/* Features supported by this builtin vhost-user net driver. */ +#define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \ + (1ULL << VIRTIO_NET_F_CTRL_VQ) | \ + (1ULL << VIRTIO_NET_F_CTRL_RX) | \ + (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \ + (1ULL << VIRTIO_NET_F_MQ) | \ + (1ULL << VIRTIO_F_VERSION_1) | \ + (1ULL << VHOST_F_LOG_ALL) | \ + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \ + (1ULL << VIRTIO_NET_F_HOST_TSO4) | \ + (1ULL << VIRTIO_NET_F_HOST_TSO6) | \ + (1ULL << VIRTIO_NET_F_CSUM) | \ + (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \ + (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \ + (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \ + (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \ + (1ULL << VIRTIO_NET_F_MTU)) + +struct guest_page {uint64_t guest_phys_addr;uint64_t host_phys_addr;
lib/librte_vhost/vhost_user.c +10 -4
@@ -147,9 +147,12 @@* The features that we support are requested. */ static uint64_t -vhost_user_get_features (void ) +vhost_user_get_features (struct virtio_net *dev) { -return VHOST_FEATURES ; +uint64_t features =0 ; + +rte_vhost_driver_get_features (dev->ifname, &features); +return features; }/*
@@ -158,7 +161,10 @@static int vhost_user_set_features (struct virtio_net *dev,uint64_t features) { -if (features & ~VHOST_FEATURES ) +uint64_t vhost_features =0 ; + +rte_vhost_driver_get_features (dev->ifname, &vhost_features); +if (features & ~vhost_features)return -1 ; dev->features = features;
@@ -1006,7 +1012,7 @@switch (msg.request) {case VHOST_USER_GET_FEATURES : - msg.payload.u64 =vhost_user_get_features (); + msg.payload.u64 =vhost_user_get_features (dev); msg.size =sizeof (msg.payload.u64);send_vhost_message (fd, &msg);break ;
Signature · 1 line
1.9.0
PATCH v4 4/22 vhost: make notify ops per vhost driver
In reply to Yuanhan LiuAssume there is an application both support vhost-user net and vhost-user scsi, the callback should be different. Making notify ops per vhost driver allow application define different set of callbacks for different driver.
---
v2: - check the return value of callback_register and callback_get
- update release note
--- doc/guides/prog_guide/vhost_lib.rst | 2 +- doc/guides/rel_notes/release_17_05.rst | 4 ++++ drivers/net/vhost/rte_eth_vhost.c | 20 +++++++++++--------- examples/tep_termination/main.c | 7 ++++++- examples/vhost/main.c | 9 +++++++-- lib/librte_vhost/rte_virtio_net.h | 3 ++- lib/librte_vhost/socket.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 16 +--------------- lib/librte_vhost/vhost.h | 5 ++++- lib/librte_vhost/vhost_user.c | 22 ++++++++++++++++------ 10 files changed, 84 insertions(+), 36 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +1 -1
@@ -122,7 +122,7 @@ The following is an overview of some key Vhost API functions: starts an infinite loop, therefore it should be called in a dedicated thread. -* ``rte_vhost_driver_callback_register(virtio_net_device_ops)`` +* ``rte_vhost_driver_callback_register(path, virtio_net_device_ops)`` This function registers a set of callbacks, to let DPDK applications take the appropriate action when some events happen. The following events are
doc/guides/rel_notes/release_17_05.rst +4 -0
@@ -204,6 +204,10 @@ API Changes * ``rte_eth_vhost_feature_enable`` * ``rte_eth_vhost_feature_get`` + * The vhost API ``rte_vhost_driver_callback_register(ops)`` is reworked to + be per vhost-user socket file. Thus, it takes one more argument: + ``rte_vhost_driver_callback_register(path, ops)``. + ABI Changes -----------
drivers/net/vhost/rte_eth_vhost.c +11 -9
@@ -669,6 +669,12 @@ struct vhost_xstats_name_off {return 0 ; } +static struct virtio_net_device_ops vhost_ops = { + .new_device = new_device, + .destroy_device = destroy_device, + .vring_state_changed = vring_state_changed, +}; +int rte_eth_vhost_get_queue_event (uint8_t port_id,struct rte_eth_vhost_queue_event *event)
@@ -738,15 +744,6 @@ struct vhost_xstats_name_off {static void * vhost_driver_session(void *param __rte_unused) { -static struct virtio_net_device_ops vhost_ops; - -/* set vhost arguments */ - vhost_ops.new_device = new_device; - vhost_ops.destroy_device = destroy_device; - vhost_ops.vring_state_changed = vring_state_changed; -if (rte_vhost_driver_callback_register (&vhost_ops) <0 ) -RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); -/* start event handling */ rte_vhost_driver_session_start ();
@@ -1090,6 +1087,11 @@ struct vhost_xstats_name_off {if (rte_vhost_driver_register (iface_name, flags)) goto error; +if (rte_vhost_driver_callback_register (iface_name, &vhost_ops) <0 ) { +RTE_LOG (ERR ,PMD ,"Can't register callbacks\n" ); + goto error; + } +/* We need only one message handling thread */ if (rte_atomic16_add_return (&nb_started_ports,1 ) ==1 ) {if (vhost_driver_session_start ())
examples/tep_termination/main.c +6 -1
@@ -1256,7 +1256,12 @@ static inline void __attribute__((always_inline))rte_vhost_driver_disable_features (dev_basename,1ULL <<VIRTIO_NET_F_MRG_RXBUF ); -rte_vhost_driver_callback_register (&virtio_net_device_ops); + ret =rte_vhost_driver_callback_register (dev_basename, + &virtio_net_device_ops); +if (ret !=0 ) { +rte_exit (EXIT_FAILURE , +"failed to register vhost driver callbacks.\n" ); + }rte_vhost_driver_session_start ();
examples/vhost/main.c +7 -2
@@ -1538,9 +1538,14 @@ static inline void __attribute__((always_inline))rte_vhost_driver_enable_features (file,1ULL <<VIRTIO_NET_F_CTRL_RX ); } - } -rte_vhost_driver_callback_register (&virtio_net_device_ops); + ret =rte_vhost_driver_callback_register (file, + &virtio_net_device_ops); +if (ret !=0 ) { +rte_exit (EXIT_FAILURE , +"failed to register vhost driver callbacks.\n" ); + } + }rte_vhost_driver_session_start ();return 0 ;
lib/librte_vhost/rte_virtio_net.h +2 -1
@@ -135,7 +135,8 @@ struct virtio_net_device_ops {int rte_vhost_driver_get_features (const char *path,uint64_t *features);/* Register callbacks. */ -int rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ); +int rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const ops);/* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start (void );
lib/librte_vhost/socket.c +32 -0
@@ -77,6 +77,8 @@ struct vhost_user_socket {*/ uint64_t supported_features;uint64_t features; + +struct virtio_net_device_ops const *notify_ops; };struct vhost_user_connection {
@@ -743,6 +745,36 @@ struct vhost_user_reconnect_list {return -1 ; } +/* +* Register ops so that we can add/remove device to data core. +*/ +int +rte_vhost_driver_callback_register (const char *path, +struct virtio_net_device_ops const *const ops) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +if (vsocket) + vsocket->notify_ops = ops; +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket ?0 :-1 ; +} + +struct virtio_net_device_ops const * +vhost_driver_callback_get (const char *path) +{ +struct vhost_user_socket *vsocket; + +pthread_mutex_lock (&vhost_user.mutex); + vsocket =find_vhost_user_socket (path); +pthread_mutex_unlock (&vhost_user.mutex); + +return vsocket ? vsocket->notify_ops :NULL ; +} +int rte_vhost_driver_session_start (void ) {
lib/librte_vhost/vhost.c +1 -15
@@ -51,9 +51,6 @@struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ]; -/* device ops to add/remove device to/from data core. */ -struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device (int vid) {
@@ -253,7 +250,7 @@ struct virtio_net *if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (vid); + dev->notify_ops->destroy_device (vid); }cleanup_device (dev,1 );
@@ -396,14 +393,3 @@ struct virtio_net * dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ;return 0 ; } - -/* -* Register ops so that we can add/remove device to data core. -*/ -int -rte_vhost_driver_callback_register (struct virtio_net_device_ops const *const ops) -{ - notify_ops = ops; - -return 0 ; -}
lib/librte_vhost/vhost.h +4 -1
@@ -185,6 +185,8 @@ struct virtio_net {struct ether_addr mac;uint16_t mtu; +struct virtio_net_device_ops const *notify_ops; +uint32_t nr_guest_pages;uint32_t max_guest_pages;struct guest_page *guest_pages;
@@ -288,7 +290,6 @@ static inline phys_addr_t __attribute__((always_inline))return 0 ; } -struct virtio_net_device_ops const *notify_ops;struct virtio_net *get_device (int vid);int vhost_new_device (void );
@@ -301,6 +302,8 @@ static inline phys_addr_t __attribute__((always_inline))void vhost_set_ifname (int ,const char *if_name,unsigned int if_len);void vhost_enable_dequeue_zero_copy (int vid); +struct virtio_net_device_ops const *vhost_driver_callback_get (const char *path); +/* * Backend-specific cleanup. *
lib/librte_vhost/vhost_user.c +16 -6
@@ -135,7 +135,7 @@ {if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }cleanup_device (dev,0 );
@@ -509,7 +509,7 @@/* Remove from the data plane. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); }if (dev->mem) {
@@ -693,7 +693,7 @@ "dequeue zero copy is enabled\n"); } -if (notify_ops->new_device (dev->vid) ==0 ) +if (dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; } }
@@ -727,7 +727,7 @@/* We have to stop the queue (virtio) if it is running. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev->vid); + dev->notify_ops->destroy_device (dev->vid); } dev->flags &= ~VIRTIO_DEV_READY ;
@@ -769,8 +769,8 @@"set queue enable: %d to qp idx: %d\n" , enable, state->index); -if (notify_ops->vring_state_changed) - notify_ops->vring_state_changed (dev->vid, state->index, enable); +if (dev->notify_ops->vring_state_changed) + dev->notify_ops->vring_state_changed (dev->vid, state->index, enable); dev->virtqueue[state->index]->enabled = enable;
@@ -984,6 +984,16 @@if (dev ==NULL )return -1 ; +if (!dev->notify_ops) { + dev->notify_ops =vhost_driver_callback_get (dev->ifname); +if (!dev->notify_ops) { +RTE_LOG (ERR ,VHOST_CONFIG , +"failed to get callback ops for driver %s\n" , + dev->ifname); +return -1 ; + } + } + ret =read_vhost_message (fd, &msg);if (ret <=0 || msg.request >=VHOST_USER_MAX ) {if (ret <0 )
Signature · 1 line
1.9.0
PATCH v4 5/22 vhost: export guest memory regions
In reply to Yuanhan LiuSome vhost-user driver may need this info to setup its own page tables for GPA (guest physical addr) to HPA (host physical addr) translation. SPDK (Storage Performance Development Kit) is one example.
Besides, by exporting this memory info, we could also export the gpa_to_vva() as an inline function, which helps for performance. Otherwise, it has to be referenced indirectly by a "vid".
---
v2: add API comments
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 38 ++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 23 ++++++++++++++++++++ lib/librte_vhost/vhost.h | 28 ++----------------------- lib/librte_vhost/vhost_user.c | 12 +++++------ 5 files changed, 70 insertions(+), 32 deletions(-)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -35,6 +35,7 @@ DPDK_17.05 { rte_vhost_driver_enable_features; rte_vhost_driver_get_features; rte_vhost_driver_set_features; + rte_vhost_get_mem_table; rte_vhost_get_mtu; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +38 -0
@@ -59,6 +59,28 @@enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM };/** +* Information relating to memory regions including offsets to +* addresses in QEMUs memory file. +*/ +struct rte_vhost_mem_region { +uint64_t guest_phys_addr; +uint64_t guest_user_addr; +uint64_t host_user_addr; +uint64_t size; +void *mmap_addr; +uint64_t mmap_size; +int fd; +}; + +/** +* Memory structure includes region and mapping information. +*/ +struct rte_vhost_memory { +uint32_t nregions; +struct rte_vhost_mem_region regions[0 ]; +}; + +/** * Device and vring operations. */ struct virtio_net_device_ops {
@@ -246,4 +268,20 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count); +/** +* Get guest mem table: a list of memory regions. +* +* An rte_vhost_vhost_memory object will be allocated internaly, to hold the +* guest memory regions. Application should free it at destroy_device() +* callback. +* +* @param vid +* vhost device ID +* @param mem +* To store the returned mem regions +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem); +#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +23 -0
@@ -359,6 +359,29 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem) +{ +struct virtio_net *dev; +struct rte_vhost_memory *m; +size_t size; + + dev =get_device (vid); +if (!dev) +return -1 ; + + size = dev->mem->nregions *sizeof (struct rte_vhost_mem_region ); + m =malloc (size); +if (!m) +return -1 ; + + m->nregions = dev->mem->nregions; +memcpy (m->regions, dev->mem->regions, size); + *mem = m; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {
lib/librte_vhost/vhost.h +2 -26
@@ -166,7 +166,7 @@ struct guest_page {*/ struct virtio_net {/* Frontend (QEMU) memory and memory region information */ -struct virtio_memory *mem; +struct rte_vhost_memory *mem;uint64_t features;uint64_t protocol_features;int vid;
@@ -192,30 +192,6 @@ struct virtio_net {struct guest_page *guest_pages; } __rte_cache_aligned; -/** -* Information relating to memory regions including offsets to -* addresses in QEMUs memory file. -*/ -struct virtio_memory_region { -uint64_t guest_phys_addr; -uint64_t guest_user_addr; -uint64_t host_user_addr; -uint64_t size; -void *mmap_addr; -uint64_t mmap_size; -int fd; -}; - - -/** -* Memory structure includes region and mapping information. -*/ -struct virtio_memory { -uint32_t nregions; -struct virtio_memory_region regions[0 ]; -}; - -/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
@@ -255,7 +231,7 @@ struct virtio_memory {static inline uint64_t __attribute__((always_inline))gpa_to_vva (struct virtio_net *dev,uint64_t gpa) { -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;uint32_t i;for (i =0 ; i < dev->mem->nregions; i++) {
lib/librte_vhost/vhost_user.c +6 -6
@@ -92,7 +92,7 @@ free_mem_region(struct virtio_net *dev) {uint32_t i; -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;if (!dev || !dev->mem)return ;
@@ -310,7 +310,7 @@static uint64_t qva_to_vva (struct virtio_net *dev,uint64_t qva) { -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;uint32_t i;/* Find the region where the address lives. */
@@ -438,7 +438,7 @@ }static void -add_guest_pages (struct virtio_net *dev,struct virtio_memory_region *reg, +add_guest_pages (struct virtio_net *dev,struct rte_vhost_mem_region *reg,uint64_t page_size) {uint64_t reg_size = reg->size;
@@ -498,7 +498,7 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) { struct VhostUserMemory memory = pmsg->payload.memory; -struct virtio_memory_region *reg; +struct rte_vhost_mem_region *reg;void *mmap_addr;uint64_t mmap_size;uint64_t mmap_offset;
@@ -525,8 +525,8 @@ sizeof(struct guest_page)); } - dev->mem =rte_zmalloc ("vhost-mem-table" ,sizeof (struct virtio_memory ) + -sizeof (struct virtio_memory_region ) * memory.nregions,0 ); + dev->mem =rte_zmalloc ("vhost-mem-table" ,sizeof (struct rte_vhost_memory ) + +sizeof (struct rte_vhost_mem_region ) * memory.nregions,0 );if (dev->mem ==NULL ) { RTE_LOG(ERR, VHOST_CONFIG, "(%d) failed to allocate memory for dev->mem\n",
Signature · 1 line
1.9.0
PATCH v4 6/22 vhost: introduce API to fetch negotiated features
In reply to Yuanhan Liu---
v4: use parameter to store the returned features and return -1 on error
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 12 ++++++++++++ lib/librte_vhost/vhost.c | 13 +++++++++++++ 3 files changed, 26 insertions(+)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -37,5 +37,6 @@ DPDK_17.05 { rte_vhost_driver_set_features; rte_vhost_get_mem_table; rte_vhost_get_mtu; + rte_vhost_get_negotiated_features; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +12 -0
@@ -156,6 +156,18 @@ struct virtio_net_device_ops {*/ int rte_vhost_driver_get_features (const char *path,uint64_t *features); +/** +* Get the feature bits after negotiation +* +* @param vid +* Vhost device ID +* @param features +* A pointer to store the queried feature bits +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_negotiated_features (int vid,uint64_t *features); +/* Register callbacks. */ int rte_vhost_driver_callback_register (const char *path,struct virtio_net_device_ops const *const ops);
lib/librte_vhost/vhost.c +13 -0
@@ -360,6 +360,19 @@ struct virtio_net * }int +rte_vhost_get_negotiated_features (int vid,uint64_t *features) +{ +struct virtio_net *dev; + + dev =get_device (vid); +if (!dev) +return -1 ; + + *features = dev->features; +return 0 ; +} + +int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem) {struct virtio_net *dev;
Signature · 1 line
1.9.0
Re: [PATCH v4 06/22] vhost: introduce API to fetch negotiated features
Quoted 9 lines · Yuanhan Liu
Signed-off-by Yuanhan Liu <[email protected]>---
v4: use parameter to store the returned features and return -1 on error
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 12 ++++++++++++ lib/librte_vhost/vhost.c | 13 +++++++++++++ 3 files changed, 26 insertions(+)
Thanks!
Maxime
PATCH v4 7/22 vhost: export vhost vring info
In reply to Yuanhan Liu---
v2: - fix off-by-one check
- add API comments
--- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 26 ++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 30 ++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 2 ++ 4 files changed, 59 insertions(+)
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -38,5 +38,6 @@ DPDK_17.05 { rte_vhost_get_mem_table; rte_vhost_get_mtu; rte_vhost_get_negotiated_features; + rte_vhost_get_vhost_vring; } DPDK_16.07;
lib/librte_vhost/rte_virtio_net.h +26 -0
@@ -80,6 +80,17 @@ struct rte_vhost_memory {struct rte_vhost_mem_region regions[0 ]; }; +struct rte_vhost_vring { +struct vring_desc *desc; +struct vring_avail *avail; +struct vring_used *used; +uint64_t log_guest_addr; + +int callfd; +int kickfd; +uint16_t size; +}; +/** * Device and vring operations. */
@@ -296,4 +307,19 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,*/ int rte_vhost_get_mem_table (int vid,struct rte_vhost_memory **mem); +/** +* Get guest vring info, including the vring address, vring size, etc. +* +* @param vid +* vhost device ID +* @param vring_idx +* vring index +* @param vring +* the structure to hold the requested vring info +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring); +#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost.c +30 -0
@@ -395,6 +395,36 @@ struct virtio_net *return 0 ; } +int +rte_vhost_get_vhost_vring (int vid,uint16_t vring_idx, +struct rte_vhost_vring *vring) +{ +struct virtio_net *dev; +struct vhost_virtqueue *vq; + + dev =get_device (vid); +if (!dev) +return -1 ; + +if (vring_idx >=VHOST_MAX_VRING ) +return -1 ; + + vq = dev->virtqueue[vring_idx]; +if (!vq) +return -1 ; + + vring->desc = vq->desc; + vring->avail = vq->avail; + vring->used = vq->used; + vring->log_guest_addr = vq->log_guest_addr; + + vring->callfd = vq->callfd; + vring->kickfd = vq->kickfd; + vring->size = vq->size; + +return 0 ; +} +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id) {
lib/librte_vhost/vhost.h +2 -0
@@ -120,6 +120,8 @@ struct vhost_virtqueue {#ifndef VIRTIO_NET_F_MQ #define VIRTIO_NET_F_MQ 22#endif + +#define VHOST_MAX_VRING 0x100#define VHOST_MAX_QUEUE_PAIRS 0x80#ifndef VIRTIO_NET_F_MTU
Signature · 1 line
1.9.0