[v2] vhost: add external message handling callbacks to the public API

Message ID 20190114042829.24499-1-dariusz.stojaczyk@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series [v2] vhost: add external message handling callbacks to the public API |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Stojaczyk, Dariusz Jan. 14, 2019, 4:28 a.m. UTC
  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 <dariusz.stojaczyk@intel.com>
---
 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(-)
  

Comments

Tiwei Bie Jan. 15, 2019, 11:22 a.m. UTC | #1
On Mon, Jan 14, 2019 at 05:28:29AM +0100, Darek Stojaczyk wrote:
> 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 <dariusz.stojaczyk@intel.com>
> ---
>  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(-)
> 
> diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
> index d280ac420..a11f9ca04 100644
> --- a/lib/librte_vhost/rte_vhost.h
> +++ b/lib/librte_vhost/rte_vhost.h
> @@ -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.

> +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_*?

> +
[...]
>  
> +/**
> + * 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);

This symbol also needs to be added to the .map file
for shared library.

For the rest,
Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
  
Stojaczyk, Dariusz Jan. 16, 2019, 12:22 p.m. UTC | #2
> -----Original Message-----
> From: Bie, Tiwei
> Sent: Tuesday, January 15, 2019 12:22 PM
> To: Stojaczyk, Dariusz <dariusz.stojaczyk@intel.com>
> Cc: dev@dpdk.org; Wang, Zhihong <zhihong.wang@intel.com>; Liang,
> Cunming <cunming.liang@intel.com>; Maxime Coquelin
> <maxime.coquelin@redhat.com>; Harris, James R
> <james.r.harris@intel.com>; Liu, Changpeng <changpeng.liu@intel.com>
> Subject: Re: [PATCH v2] vhost: add external message handling callbacks to
> the public API
> 
> On Mon, Jan 14, 2019 at 05:28:29AM +0100, Darek Stojaczyk wrote:
> > 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 <dariusz.stojaczyk@intel.com>
> > ---
> >  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(-)
> >
> > diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
> > index d280ac420..a11f9ca04 100644
> > --- a/lib/librte_vhost/rte_vhost.h
> > +++ b/lib/librte_vhost/rte_vhost.h
> > @@ -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.

Ack

> 
> > +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_*?

Ack

> 
> > +
> [...]
> >
> > +/**
> > + * 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);
> 
> This symbol also needs to be added to the .map file
> for shared library.

Ack

> 
> For the rest,
> Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>

Thanks,
D.
  

Patch

diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index d280ac420..a11f9ca04 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -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.
  *
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index b32babee4..00ec58e01 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -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;
+}
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index f267f898c..fc31796bf 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -286,56 +286,6 @@  struct guest_page {
 	uint64_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 (*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 (*vhost_msg_post_handle)(int vid, void *msg);
-
-/**
- * pre and post vhost user message handlers
- */
-struct vhost_user_extern_ops {
-	vhost_msg_pre_handle pre_msg_handle;
-	vhost_msg_post_handle post_msg_handle;
-};
-
 /**
  * Device structure contains all configuration information relating
  * to the device.
@@ -379,10 +329,10 @@  struct virtio_net {
 	 */
 	int			vdpa_dev_id;
 
-	/* private data for virtio device */
+	/* context data for the external message handlers */
 	void			*extern_data;
 	/* pre and post vhost user message handlers for the device */
-	struct vhost_user_extern_ops extern_ops;
+	struct rte_vhost_user_extern_ops extern_ops;
 } __rte_cache_aligned;
 
 static __rte_always_inline bool