From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id DCC351C659 for ; Wed, 4 Apr 2018 16:08:06 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E0D48424D; Wed, 4 Apr 2018 14:08:06 +0000 (UTC) Received: from [10.36.112.30] (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E183063538; Wed, 4 Apr 2018 14:08:04 +0000 (UTC) To: Fan Zhang , dev@dpdk.org Cc: jianjay.zhou@huawei.com, jianfeng.tan@intel.com, pawelx.wodkowski@intel.com References: <1522327975-28769-1-git-send-email-roy.fan.zhang@intel.com> <20180404100902.27637-1-roy.fan.zhang@intel.com> <20180404100902.27637-2-roy.fan.zhang@intel.com> From: Maxime Coquelin Message-ID: <2c94fc1f-6068-9136-d27f-1c6ec4dc13a9@redhat.com> Date: Wed, 4 Apr 2018 16:08:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180404100902.27637-2-roy.fan.zhang@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 04 Apr 2018 14:08:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 04 Apr 2018 14:08:06 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'maxime.coquelin@redhat.com' RCPT:'' Subject: Re: [dpdk-dev] [PATCH v5 1/8] lib/librte_vhost: add external backend support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Apr 2018 14:08:07 -0000 Hi, I think the title should change, as it makes to think it could be used by external backends that doesn't live in the librte_vhost directory. One more comment below, otherwise that looks good to me. Thanks, Maxime On 04/04/2018 12:08 PM, Fan Zhang wrote: > This patch adds external backend support to vhost library. The patch provides > new function prototypes for the external backend to register pre and post > vhost-user message handlers. > > Signed-off-by: Fan Zhang > --- > lib/librte_vhost/vhost.c | 2 +- > lib/librte_vhost/vhost.h | 53 +++++++++++++++++++++++++++++++++++++++++-- > lib/librte_vhost/vhost_user.c | 31 ++++++++++++++++++++++++- > 3 files changed, 82 insertions(+), 4 deletions(-) > > diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c > index f6f12a03b..99f8b01fb 100644 > --- a/lib/librte_vhost/vhost.c > +++ b/lib/librte_vhost/vhost.c > @@ -1,5 +1,5 @@ > /* SPDX-License-Identifier: BSD-3-Clause > - * Copyright(c) 2010-2016 Intel Corporation > + * Copyright(c) 2010-2017 Intel Corporation > */ > > #include > diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h > index 4981e6d0c..f28164849 100644 > --- a/lib/librte_vhost/vhost.h > +++ b/lib/librte_vhost/vhost.h > @@ -1,5 +1,5 @@ > /* SPDX-License-Identifier: BSD-3-Clause > - * Copyright(c) 2010-2014 Intel Corporation > + * Copyright(c) 2010-2018 Intel Corporation > */ > > #ifndef _VHOST_NET_CDEV_H_ > @@ -211,6 +211,51 @@ struct guest_page { > }; > > /** > + * 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 require_reply > + * If the handler requires sending a reply, this varaible shall be written 1, > + * otherwise 0. > + * @param skip_master > + * If the handler requires skipping the master message handling, this variable > + * shall be written 1, otherwise 0. > + * @return > + * 0 on success, -1 on failure > + */ > +typedef int (*rte_vhost_msg_pre_handle)(int vid, void *msg, > + uint32_t *require_reply, uint32_t *skip_master); Also, please remove the rte_ prefix here and evrywhere else as it is purely vhost lib internal for now. > + > +/** > + * 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. > + * @param require_reply > + * If the handler requires sending a reply, this varaible shall be written 1, > + * otherwise 0. > + * @return > + * 0 on success, -1 on failure > + */ > +typedef int (*rte_vhost_msg_post_handle)(int vid, void *msg, > + uint32_t *require_reply); > + > +/** > + * pre and post vhost user message handlers > + */ > +struct vhost_user_extern_ops { > + rte_vhost_msg_pre_handle pre_msg_handle; > + rte_vhost_msg_post_handle post_msg_handle; > +}; > + > +/** > * Device structure contains all configuration information relating > * to the device. > */ > @@ -242,8 +287,12 @@ struct virtio_net { > struct guest_page *guest_pages; > > int slave_req_fd; > -} __rte_cache_aligned; > > + /* private data for external virtio device */ > + void *extern_data; > + /* pre and post vhost user message handlers for externel backend */ > + struct vhost_user_extern_ops extern_ops; > +} __rte_cache_aligned; > > #define VHOST_LOG_PAGE 4096 > > diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c > index 66e1b82a5..a435cce17 100644 > --- a/lib/librte_vhost/vhost_user.c > +++ b/lib/librte_vhost/vhost_user.c > @@ -1,5 +1,5 @@ > /* SPDX-License-Identifier: BSD-3-Clause > - * Copyright(c) 2010-2016 Intel Corporation > + * Copyright(c) 2010-2018 Intel Corporation > */ > > /* Security model > @@ -1379,6 +1379,7 @@ vhost_user_msg_handler(int vid, int fd) > struct VhostUserMsg msg; > int ret; > int unlock_required = 0; > + uint32_t skip_master = 0; > > dev = get_device(vid); > if (dev == NULL) > @@ -1456,6 +1457,21 @@ vhost_user_msg_handler(int vid, int fd) > > } > > + if (dev->extern_ops.pre_msg_handle) { > + uint32_t need_reply; > + > + ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, > + (void *)&msg, &need_reply, &skip_master); > + if (ret < 0) > + goto skip_to_reply; > + > + if (need_reply) > + send_vhost_reply(fd, &msg); > + > + if (skip_master) > + goto skip_to_post_handle; > + } > + > switch (msg.request.master) { > case VHOST_USER_GET_FEATURES: > msg.payload.u64 = vhost_user_get_features(dev); > @@ -1556,9 +1572,22 @@ vhost_user_msg_handler(int vid, int fd) > default: > ret = -1; > break; > + } > + > +skip_to_post_handle: > + if (dev->extern_ops.post_msg_handle) { > + uint32_t need_reply; > + > + ret = (*dev->extern_ops.post_msg_handle)( > + dev->vid, (void *)&msg, &need_reply); > + if (ret < 0) > + goto skip_to_reply; > > + if (need_reply) > + send_vhost_reply(fd, &msg); > } > > +skip_to_reply: > if (unlock_required) > vhost_user_unlock_all_queue_pairs(dev); > >