From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2BAFBA0C4B; Thu, 14 Oct 2021 05:24:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D645D40042; Thu, 14 Oct 2021 05:24:42 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id A45FE40041 for ; Thu, 14 Oct 2021 05:24:40 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10136"; a="251020769" X-IronPort-AV: E=Sophos;i="5.85,371,1624345200"; d="scan'208";a="251020769" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 20:24:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,371,1624345200"; d="scan'208";a="481069794" Received: from irsmsx601.ger.corp.intel.com ([163.33.146.7]) by orsmga007.jf.intel.com with ESMTP; 13 Oct 2021 20:24:23 -0700 Received: from shsmsx606.ccr.corp.intel.com (10.109.6.216) by irsmsx601.ger.corp.intel.com (163.33.146.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Thu, 14 Oct 2021 04:24:21 +0100 Received: from shsmsx606.ccr.corp.intel.com ([10.109.6.216]) by SHSMSX606.ccr.corp.intel.com ([10.109.6.216]) with mapi id 15.01.2242.012; Thu, 14 Oct 2021 11:24:18 +0800 From: "Hu, Jiayu" To: Maxime Coquelin , "dev@dpdk.org" , "Xia, Chenbo" , "Wang, YuanX" , "Ma, WenwuX" , "Richardson, Bruce" , "Mcnamara, John" Thread-Topic: [RFC 01/14] vhost: move async data in a dedicated structure Thread-Index: AQHXu8in9ricIncOV02QK4ESLxfD36vR1NTg Date: Thu, 14 Oct 2021 03:24:18 +0000 Message-ID: <8cec24ee308a496eb48734c0cd535639@intel.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> <20211007220013.355530-2-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-2-maxime.coquelin@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-reaction: no-action dlp-version: 11.6.200.16 dlp-product: dlpe-windows x-originating-ip: [10.239.127.36] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [RFC 01/14] vhost: move async data in a dedicated structure X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Maxime, > -----Original Message----- > From: Maxime Coquelin > Sent: Friday, October 8, 2021 6:00 AM > To: dev@dpdk.org; Xia, Chenbo ; Hu, Jiayu > ; Wang, YuanX ; Ma, > WenwuX ; Richardson, Bruce > ; Mcnamara, John > > Cc: Maxime Coquelin > Subject: [RFC 01/14] vhost: move async data in a dedicated structure >=20 > This patch moves async-related metadata from vhost_virtqueue to a > dedicated struct. It makes it clear which fields are async related, and a= lso > saves some memory when async feature is not in use. >=20 > Signed-off-by: Maxime Coquelin > --- > lib/vhost/vhost.c | 129 ++++++++++++++++------------------------- > lib/vhost/vhost.h | 53 ++++++++--------- > lib/vhost/vhost_user.c | 4 +- > lib/vhost/virtio_net.c | 114 +++++++++++++++++++----------------- > 4 files changed, 140 insertions(+), 160 deletions(-) >=20 > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index > 9540522dac..58f72b633c 100644 > --- a/lib/vhost/vhost.c > +++ b/lib/vhost/vhost.c > @@ -340,19 +340,15 @@ cleanup_device(struct virtio_net *dev, int destroy) > static void vhost_free_async_mem(struct vhost_virtqueue *vq) { > - rte_free(vq->async_pkts_info); > + rte_free(vq->async->pkts_info); Apps may unregister async in vring_state_changed() explicitly when vring is disabled. In this case, rte_vhost_async_channel_unregister() will call vhost_free_async_mem() first, so that vq->async becomes NULL. But after then device is destroyed, free_vq() calls vhost_free_async_mem() again. "rte_free(vq->async->pkts_info)" will try to read a NULL pointer, which will cause segment fault. >=20 > - rte_free(vq->async_buffers_packed); > - vq->async_buffers_packed =3D NULL; > - rte_free(vq->async_descs_split); > - vq->async_descs_split =3D NULL; > + rte_free(vq->async->buffers_packed); > + vq->async->buffers_packed =3D NULL; > + rte_free(vq->async->descs_split); > + vq->async->descs_split =3D NULL; >=20 > - rte_free(vq->it_pool); > - rte_free(vq->vec_pool); > - > - vq->async_pkts_info =3D NULL; > - vq->it_pool =3D NULL; > - vq->vec_pool =3D NULL; > + rte_free(vq->async); > + vq->async =3D NULL; > } >=20 > void > @@ -1629,77 +1625,63 @@ async_channel_register(int vid, uint16_t > queue_id, { > struct virtio_net *dev =3D get_device(vid); > struct vhost_virtqueue *vq =3D dev->virtqueue[queue_id]; > + struct vhost_async *async; > + int node =3D vq->numa_node; >=20 > - if (unlikely(vq->async_registered)) { > + if (unlikely(vq->async)) { > VHOST_LOG_CONFIG(ERR, > - "async register failed: channel already registered " > - "(vid %d, qid: %d)\n", vid, queue_id); > + "async register failed: already registered > (vid %d, qid: %d)\n", > + vid, queue_id); > return -1; > } >=20 > - vq->async_pkts_info =3D rte_malloc_socket(NULL, > - vq->size * sizeof(struct async_inflight_info), > - RTE_CACHE_LINE_SIZE, vq->numa_node); > - if (!vq->async_pkts_info) { > - vhost_free_async_mem(vq); > - VHOST_LOG_CONFIG(ERR, > - "async register failed: cannot allocate memory for > async_pkts_info " > - "(vid %d, qid: %d)\n", vid, queue_id); > + async =3D rte_zmalloc_socket(NULL, sizeof(struct vhost_async), 0, > node); > + if (!async) { > + VHOST_LOG_CONFIG(ERR, "failed to allocate async metadata > (vid %d, qid: %d)\n", > + vid, queue_id); > return -1; > } >=20 > - vq->it_pool =3D rte_malloc_socket(NULL, > - VHOST_MAX_ASYNC_IT * sizeof(struct > rte_vhost_iov_iter), > - RTE_CACHE_LINE_SIZE, vq->numa_node); > - if (!vq->it_pool) { > - vhost_free_async_mem(vq); > - VHOST_LOG_CONFIG(ERR, > - "async register failed: cannot allocate memory for > it_pool " > - "(vid %d, qid: %d)\n", vid, queue_id); > - return -1; > - } > - > - vq->vec_pool =3D rte_malloc_socket(NULL, > - VHOST_MAX_ASYNC_VEC * sizeof(struct iovec), > - RTE_CACHE_LINE_SIZE, vq->numa_node); > - if (!vq->vec_pool) { > - vhost_free_async_mem(vq); > - VHOST_LOG_CONFIG(ERR, > - "async register failed: cannot allocate memory for > vec_pool " > - "(vid %d, qid: %d)\n", vid, queue_id); > - return -1; > + async->pkts_info =3D rte_malloc_socket(NULL, vq->size * sizeof(struct > async_inflight_info), > + RTE_CACHE_LINE_SIZE, node); > + if (async->pkts_info) { It should be "if (!async->pkts_info)". Thanks, Jiayu