vhost: add external message handling callbacks to the public API
PATCH v2 1/1 vhost: add external message handling callbacks to the public API
External message callbacks are used e.g. by vhost crypto to parse crypto-specific vhost-user messages.
We are now publishing the API to register those callbacks, so that other backends outside of DPDK can use them as well.
--- lib/librte_vhost/rte_vhost.h | 66 ++++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 13 +++++++ lib/librte_vhost/vhost.h | 54 ++--------------------------- 3 files changed, 81 insertions(+), 52 deletions(-)
lib/librte_vhost/rte_vhost.h +66 -0
@@ -111,6 +111,56 @@ struct rte_vhost_vring {uint16_t size; }; +/* The possible results of a message handling function */ +enum vh_result { +/* Message handling failed */ +VH_RESULT_ERR =-1 , +/* Message handling successful */ +VH_RESULT_OK =0 , +/* Message handling successful and reply prepared */ +VH_RESULT_REPLY =1 , +}; + +/** +* Function prototype for the vhost backend to handler specific vhost user +* messages prior to the master message handling +* +* @param vid +* vhost device id +* @param msg +* Message pointer. +* @param skip_master +* If the handler requires skipping the master message handling, this variable +* shall be written 1, otherwise 0. +* @return +* VH_RESULT_OK on success, VH_RESULT_REPLY on success with reply, +* VH_RESULT_ERR on failure +*/ +typedef enum vh_result (*rte_vhost_msg_pre_handle )(int vid,void *msg, +uint32_t *skip_master); + +/** +* Function prototype for the vhost backend to handler specific vhost user +* messages after the master message handling is done +* +* @param vid +* vhost device id +* @param msg +* Message pointer. +* @return +* VH_RESULT_OK on success, VH_RESULT_REPLY on success with reply, +* VH_RESULT_ERR on failure +*/ +typedef enum vh_result (*rte_vhost_msg_post_handle )(int vid,void *msg); + +/** +* Optional vhost user message handlers. +*/ +struct rte_vhost_user_extern_ops { +rte_vhost_msg_pre_handle pre_msg_handle; +rte_vhost_msg_post_handle post_msg_handle; +}; +/** * Device and vring operations. */
@@ -640,6 +690,22 @@ int __rte_experimental rte_vhost_set_vring_base(int vid, uint16_t queue_id, uint16_t last_avail_idx, uint16_t last_used_idx); +/** +* Register external message handling callbacks +* +* @param vid +* vhost device ID +* @param ops +* virtio external callbacks to register +* @param ctx +* additional context passed to the callbacks +* @return +* 0 on success, -1 on failure +*/ +int __rte_experimental +rte_vhost_extern_callback_register (int vid, +struct rte_vhost_user_extern_ops const *const ops,void *ctx); +/** * Get vdpa device id for vhost device. *
lib/librte_vhost/vhost.c +13 -0
@@ -820,3 +820,16 @@ int rte_vhost_set_vring_base(int vid, uint16_t queue_id,return 0 ; } + +int rte_vhost_extern_callback_register (int vid, +struct rte_vhost_user_extern_ops const *const ops,void *ctx) +{ +struct virtio_net *dev =get_device (vid); + +if (!dev) +return -1 ; + + dev->extern_ops = *ops; + dev->extern_data = ctx; +return 0 ; +}
lib/librte_vhost/vhost.h +2 -52
68 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 18 lines · Darek Stojaczyk
External message callbacks are used e.g. by vhost crypto to parse crypto-specific vhost-user messages.
We are now publishing the API to register those callbacks, so that other backends outside of DPDK can use them as well.
Signed-off-by Darek Stojaczyk <[email protected]>--- lib/librte_vhost/rte_vhost.h | 66 ++++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 13 +++++++ lib/librte_vhost/vhost.h | 54 ++--------------------------- 3 files changed, 81 insertions(+), 52 deletions(-)lib/librte_vhost/rte_vhost.h +0
-0
lib/librte_vhost/rte_vhost.h struct rte_vhost_vring { · line 114
Quoted 4 lines
lib/librte_vhost/rte_vhost.h +1
-0@@ -111,6 +111,56 @@ struct rte_vhost_vring {uint16_t size; }; +/* The possible results of a message handling function */
Better to change /* to /**, so doxygen can generate doc for it.
lib/librte_vhost/rte_vhost.h struct rte_vhost_vring { · line 122
Quoted 8 lines
lib/librte_vhost/rte_vhost.h +8
-0+enum vh_result { +/* Message handling failed */ +VH_RESULT_ERR =-1 , +/* Message handling successful */ +VH_RESULT_OK =0 , +/* Message handling successful and reply prepared */ +VH_RESULT_REPLY =1 , +};
Maybe better to prefix with rte_ and RTE_? How about rte_vhost_result and RTE_VHOST_RESULT_*?
Quoted 1 line
lib/librte_vhost/rte_vhost.h +1
-0+
[...]
Quoted 6 lines
lib/librte_vhost/rte_vhost.h +5
-0+/** +* Register external message handling callbacks +* +* @param vid +* vhost device ID
lib/librte_vhost/rte_vhost.h int __rte_experimental · line 707
Quoted 10 lines
lib/librte_vhost/rte_vhost.h +10
-0+* @param ops +* virtio external callbacks to register +* @param ctx +* additional context passed to the callbacks +* @return +* 0 on success, -1 on failure +*/ +int __rte_experimental +rte_vhost_extern_callback_register (int vid, +struct rte_vhost_user_extern_ops const *const ops,void *ctx);
This symbol also needs to be added to the .map file for shared library.
For the rest,
Quoted 36 lines
-----Original Message-----
From: Bie, Tiwei
Sent: Tuesday, January 15, 2019 12:22 PM
To: Stojaczyk, Dariusz <[email protected]>
Cc: [email protected]; Wang, Zhihong <[email protected]>; Liang, Cunming <[email protected]>; Maxime Coquelin <[email protected]>; Harris, James R <[email protected]>; Liu, Changpeng <[email protected]>
Subject: Re: [PATCH v2] vhost: add external message handling callbacks to the public APIQuoted 9 lines · Darek Stojaczyk
External message callbacks are used e.g. by vhost crypto to parse crypto-specific vhost-user messages.
We are now publishing the API to register those callbacks, so that other backends outside of DPDK can use them as well.
Signed-off-by Darek Stojaczyk <[email protected]>--- lib/librte_vhost/rte_vhost.h | 66++++++++++++++++++++++++++++++++++++
Quoted 12 lines
lib/librte_vhost/vhost.c | 13 +++++++ lib/librte_vhost/vhost.h | 54 ++--------------------------- 3 files changed, 81 insertions(+), 52 deletions(-)lib/librte_vhost/rte_vhost.h +0
-0@@ -111,6 +111,56 @@ struct rte_vhost_vring {uint16_t size; };
Quoted 3 lines
lib/librte_vhost/rte_vhost.h struct rte_vhost_vring { · line 114
Quoted 1 line
lib/librte_vhost/rte_vhost.h +1
-0+/* The possible results of a message handling function */ Better to change /* to /**, so doxygen can generate doc for it.
Ack
Quoted 12 lines
lib/librte_vhost/rte_vhost.h struct rte_vhost_vring { · line 122
Quoted 9 lines
lib/librte_vhost/rte_vhost.h +8
-0+enum vh_result { +/* Message handling failed */ +VH_RESULT_ERR =-1 , +/* Message handling successful */ +VH_RESULT_OK =0 , +/* Message handling successful and reply prepared */ +VH_RESULT_REPLY =1 , +};Maybe better to prefix with
rte_andRTE_? How aboutrte_vhost_resultand RTE_VHOST_RESULT_*?
Ack
Quoted 21 lines
Quoted 2 lines
lib/librte_vhost/rte_vhost.h +1
-0+[...]
Quoted 6 lines
lib/librte_vhost/rte_vhost.h +5
-0+/** +* Register external message handling callbacks +* +* @param vid +* vhost device ID lib/librte_vhost/rte_vhost.h int __rte_experimental
Quoted 10 lines
lib/librte_vhost/rte_vhost.h +10
-0+* @param ops +* virtio external callbacks to register +* @param ctx +* additional context passed to the callbacks +* @return +* 0 on success, -1 on failure +*/ +int __rte_experimental +rte_vhost_extern_callback_register (int vid, + struct rte_vhost_user_extern_ops const * const ops, void*ctx);
Quoted 2 lines
This symbol also needs to be added to the .map file for shared library.
Ack
Quoted 3 lines
For the rest,
Reviewed-by Tiwei Bie <[email protected]>
Thanks,
D.
PATCH v3 1/1 vhost: add external message handling callbacks to the public API
In reply to Darek StojaczykExternal message callbacks are used e.g. by vhost crypto to parse crypto-specific vhost-user messages.
We are now publishing the API to register those callbacks, so that other backends outside of DPDK can use them as well.
--- lib/librte_vhost/rte_vhost.h | 69 ++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/vhost.c | 13 +++ lib/librte_vhost/vhost.h | 54 +---------- lib/librte_vhost/vhost_crypto.c | 12 +-- lib/librte_vhost/vhost_user.c | 123 +++++++++++++------------ 6 files changed, 153 insertions(+), 119 deletions(-)
lib/librte_vhost/rte_vhost.h +69 -0
@@ -111,6 +111,59 @@ struct rte_vhost_vring {uint16_t size; }; +/** +* Possible results of the vhost user message handling callbacks +*/ +enum rte_vhost_msg_result { +/* Message handling failed */ +RTE_VHOST_MSG_RESULT_ERR =-1 , +/* Message handling successful */ +RTE_VHOST_MSG_RESULT_OK =0 , +/* Message handling successful and reply prepared */ +RTE_VHOST_MSG_RESULT_REPLY =1 , +}; + +/** +* Function prototype for the vhost backend to handler specific vhost user +* messages prior to the master message handling +* +* @param vid +* vhost device id +* @param msg +* Message pointer. +* @param skip_master +* If the handler requires skipping the master message handling, this variable +* shall be written 1, otherwise 0. +* @return +* VH_RESULT_OK on success, VH_RESULT_REPLY on success with reply, +* VH_RESULT_ERR on failure +*/ +typedef enum rte_vhost_msg_result (*rte_vhost_msg_pre_handle )(int vid, +void *msg,uint32_t *skip_master); + +/** +* Function prototype for the vhost backend to handler specific vhost user +* messages after the master message handling is done +* +* @param vid +* vhost device id +* @param msg +* Message pointer. +* @return +* VH_RESULT_OK on success, VH_RESULT_REPLY on success with reply, +* VH_RESULT_ERR on failure +*/ +typedef enum rte_vhost_msg_result (*rte_vhost_msg_post_handle )(int vid, +void *msg); + +/** +* Optional vhost user message handlers. +*/ +struct rte_vhost_user_extern_ops { +rte_vhost_msg_pre_handle pre_msg_handle; +rte_vhost_msg_post_handle post_msg_handle; +}; +/** * Device and vring operations. */
@@ -640,6 +693,22 @@ int __rte_experimental rte_vhost_set_vring_base(int vid, uint16_t queue_id, uint16_t last_avail_idx, uint16_t last_used_idx); +/** +* Register external message handling callbacks +* +* @param vid +* vhost device ID +* @param ops +* virtio external callbacks to register +* @param ctx +* additional context passed to the callbacks +* @return +* 0 on success, -1 on failure +*/ +int __rte_experimental +rte_vhost_extern_callback_register (int vid, +struct rte_vhost_user_extern_ops const *const ops,void *ctx); +/** * Get vdpa device id for vhost device. *
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -86,4 +86,5 @@ EXPERIMENTAL { rte_vhost_host_notifier_ctrl; rte_vdpa_relay_vring_avail; rte_vdpa_relay_vring_used; + rte_vhost_extern_callback_register; };
lib/librte_vhost/vhost.c +13 -0
@@ -820,3 +820,16 @@ int rte_vhost_set_vring_base(int vid, uint16_t queue_id,return 0 ; } + +int rte_vhost_extern_callback_register (int vid, +struct rte_vhost_user_extern_ops const *const ops,void *ctx) +{ +struct virtio_net *dev =get_device (vid); + +if (!dev) +return -1 ; + + dev->extern_ops = *ops; + dev->extern_data = ctx; +return 0 ; +}
lib/librte_vhost/vhost.h +2 -52
68 lines not on this page · raw message
lib/librte_vhost/vhost_crypto.c +6 -6
@@ -434,33 +434,33 @@ vhost_crypto_close_sess(struct vhost_crypto *vcrypto, uint64_t session_id)return 0 ; } -static enum vh_result +static enum rte_vhost_msg_result vhost_crypto_msg_post_handler (int vid,void *msg) {struct virtio_net *dev =get_device (vid);struct vhost_crypto *vcrypto;VhostUserMsg *vmsg = msg; -enum vh_result ret =VH_RESULT_OK ; +enum rte_vhost_msg_result ret =RTE_VHOST_MSG_RESULT_OK ;if (dev ==NULL ) {VC_LOG_ERR ("Invalid vid %i" , vid); -return VH_RESULT_ERR ; +return RTE_VHOST_MSG_RESULT_ERR ; } vcrypto = dev->extern_data;if (vcrypto ==NULL ) {VC_LOG_ERR ("Cannot find required data, is it initialized?" ); -return VH_RESULT_ERR ; +return RTE_VHOST_MSG_RESULT_ERR ; }if (vmsg->request.master ==VHOST_USER_CRYPTO_CREATE_SESS ) {vhost_crypto_create_sess (vcrypto, &vmsg->payload.crypto_session); vmsg->fd_num =0 ; - ret =VH_RESULT_REPLY ; + ret =RTE_VHOST_MSG_RESULT_REPLY ; }else if (vmsg->request.master ==VHOST_USER_CRYPTO_CLOSE_SESS ) {if (vhost_crypto_close_sess (vcrypto, vmsg->payload.u64)) - ret =VH_RESULT_ERR ; + ret =RTE_VHOST_MSG_RESULT_ERR ; }return ret;
lib/librte_vhost/vhost_user.c +62 -61
443 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 8 lines · Darek Stojaczyk
External message callbacks are used e.g. by vhost crypto to parse crypto-specific vhost-user messages.
We are now publishing the API to register those callbacks, so that other backends outside of DPDK can use them as well.
Signed-off-by Darek Stojaczyk <[email protected]>Reviewed-by Tiwei Bie <[email protected]>
Quoted 9 lines
--- lib/librte_vhost/rte_vhost.h | 69 ++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/vhost.c | 13 +++ lib/librte_vhost/vhost.h | 54 +---------- lib/librte_vhost/vhost_crypto.c | 12 +-- lib/librte_vhost/vhost_user.c | 123 +++++++++++++------------ 6 files changed, 153 insertions(+), 119 deletions(-)
I'll apply it however only for v19.05 because API changes should be submitted early in the release cycle (before -rc1, -rc2 at he latest).
Thanks!
Maxime
Maxime Coquelin
AppliedQuoted 8 lines · Darek Stojaczyk
External message callbacks are used e.g. by vhost crypto to parse crypto-specific vhost-user messages.
We are now publishing the API to register those callbacks, so that other backends outside of DPDK can use them as well.
Signed-off-by Darek Stojaczyk <[email protected]>Reviewed-by Tiwei Bie <[email protected]>
Quoted 9 lines
--- lib/librte_vhost/rte_vhost.h | 69 ++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/vhost.c | 13 +++ lib/librte_vhost/vhost.h | 54 +---------- lib/librte_vhost/vhost_crypto.c | 12 +-- lib/librte_vhost/vhost_user.c | 123 +++++++++++++------------ 6 files changed, 153 insertions(+), 119 deletions(-)
I fixed build issue with postcopy build flag enabled.
Applied to dpdk-next-virtio/master.
Thanks,
Maxime