From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DACD2A04FF; Tue, 14 Jan 2020 16:27:18 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CFEF61C11D; Tue, 14 Jan 2020 16:27:17 +0100 (CET) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id 9A8582C6E for ; Tue, 14 Jan 2020 16:27:16 +0100 (CET) Received: by mail-wm1-f67.google.com with SMTP id a5so14285580wmb.0 for ; Tue, 14 Jan 2020 07:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=reUhMFocW2mJHtn115yVIX4Cl6pFehNIA9viD3Wk5vo=; b=FZ1tvPdANFDJCyZE7ScZoxhdHRp4NodXkqcYK1aavVBqyHmtq1bIjrDMS05smTjOq2 uLxQb+qz1tp4JpNpHQPQaT3HFQXWAlTlazhxFBKdBNPfWVAUNi+5N8n32Z2rdUV2RBk/ Em7dVXmocBCqqDUyY9dxMrYe99egK59F3/nyoIo5yg9PYZmMRD7iAZ7hS1xhEGh3l4XJ q2fWphThWm+AGlmj7zcPZ/Af5C88utbkIDxRy1hOCevAz2zOkBK4SBv6IUGlu5hWUgQM qArtW+C9o5b+3kCETOvWLVeWyBDP/s64ANf3vWT8FrRw+qEmKBY/W0VfoKVPr139Qmh7 6+FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=reUhMFocW2mJHtn115yVIX4Cl6pFehNIA9viD3Wk5vo=; b=IxTEKa7FcpUOq1MNmX5ZFTuFXTYlPsCyTauDPoVpc1S9rDbkwcFVpg85C7GCQm7o+r fA1vIf9SVUeHMa/GVcBfNLI0+isQfbgxgQ+d+xoR8fXhj8ys5YPWXzQJj+ae97k42GsO O+G1QgxU4/X+BDL5jeumM5sMn2NOBJJW2f3b4d1DFVuS33a/YRf7GmAwLDWBGAXSi3RW o34y+uJd6CLtZLC0wTQSDYeYl66ZXZRaHETWaw+ESThjFoz+EGgfwj+J4ZM2FJgfxpOe Bx+WyoSuBGPswLzoqSb9vR/QTB+GLOasfWu1XuElnLIyrRH/8IRPKFeGFJiU4PiUb2Pj Hwzw== X-Gm-Message-State: APjAAAWh7gWsWWyVQvkmbk6FOlPFy7PAY2HG6jftA31xcGzADcaWRXuG nTk6Ij88dyTdaUl3w+lKc2S41g== X-Google-Smtp-Source: APXvYqzLcl9SjDEtl8LsiyA6M0p4hF8l4ta0io3tcVV6OBWkc/ymMqW7sHposyq6/cYFf3AtWA0wzw== X-Received: by 2002:a05:600c:2383:: with SMTP id m3mr29173289wma.32.1579015636067; Tue, 14 Jan 2020 07:27:16 -0800 (PST) Received: from 6wind.com (2a01cb0c0005a600345636f7e65ed1a0.ipv6.abo.wanadoo.fr. [2a01:cb0c:5:a600:3456:36f7:e65e:d1a0]) by smtp.gmail.com with ESMTPSA id p18sm18601506wmg.4.2020.01.14.07.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:27:14 -0800 (PST) Date: Tue, 14 Jan 2020 16:27:13 +0100 From: Olivier Matz To: Viacheslav Ovsiienko Cc: dev@dpdk.org, matan@mellanox.com, rasland@mellanox.com, orika@mellanox.com, shahafs@mellanox.com, stephen@networkplumber.org Message-ID: <20200114152713.GS22738@platinum> References: <20191118094938.192850-1-shahafs@mellanox.com> <1578993305-15165-1-git-send-email-viacheslavo@mellanox.com> <1578993305-15165-2-git-send-email-viacheslavo@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1578993305-15165-2-git-send-email-viacheslavo@mellanox.com> User-Agent: Mutt/1.10.1 (2018-07-13) Subject: Re: [dpdk-dev] [PATCH v3 1/4] mbuf: detach mbuf with pinned external buffer 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Viacheslav, Please see some comments below. On Tue, Jan 14, 2020 at 09:15:02AM +0000, Viacheslav Ovsiienko wrote: > Update detach routine to check the mbuf pool type. > > Signed-off-by: Shahaf Shuler > Signed-off-by: Viacheslav Ovsiienko > --- > lib/librte_mbuf/rte_mbuf.h | 64 +++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 60 insertions(+), 4 deletions(-) > > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h > index 219b110..8f486af 100644 > --- a/lib/librte_mbuf/rte_mbuf.h > +++ b/lib/librte_mbuf/rte_mbuf.h > @@ -306,6 +306,46 @@ struct rte_pktmbuf_pool_private { > uint32_t flags; /**< reserved for future use. */ > }; > > +/** > + * When set pktmbuf mempool will hold only mbufs with pinned external > + * buffer. The external buffer will be attached on the mbuf at the > + * memory pool creation and will never be detached by the mbuf free calls. > + * mbuf should not contain any room for data after the mbuf structure. > + */ > +#define RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF (1 << 0) Out of curiosity, why using a pool flag instead of flagging the mbufs? The reason I see is that adding a new m->flag would impact places where we copy or reset the flags (it should be excluded). Is there another reason? > +/** > + * Returns TRUE if given mbuf has an pinned external buffer, or FALSE > + * otherwise. The pinned external buffer is allocated at pool creation > + * time and should not be freed. > + * > + * External buffer is a user-provided anonymous buffer. > + */ > +#ifdef ALLOW_EXPERIMENTAL_API > +#define RTE_MBUF_HAS_PINNED_EXTBUF(mb) rte_mbuf_has_pinned_extbuf(mb) > +#else > +#define RTE_MBUF_HAS_PINNED_EXTBUF(mb) false > +#endif I suppose you added these lines because the compilation was broken after introducing the new __rte_experimental API, which is called from detach(). I find a bit strange that we require to do this. I don't see what would be broken without the ifdef: an application compiled for 19.11 cannot use the pinned-ext-buf feature (because it did not exist), so the modification looks safe to me. > + > +__rte_experimental > +static inline uint32_t I don't think uint32_t is really better than uint64_t. I agree with Stephen that bool is the preferred choice, however if it breaks compilation in some cases, I think int is better. > +rte_mbuf_has_pinned_extbuf(const struct rte_mbuf *m) > +{ > + if (RTE_MBUF_HAS_EXTBUF(m)) { > + /* > + * The mbuf has the external attached buffer, > + * we should check the type of the memory pool where > + * the mbuf was allocated from. > + */ > + struct rte_pktmbuf_pool_private *priv = > + (struct rte_pktmbuf_pool_private *) > + rte_mempool_get_priv(m->pool); > + > + return priv->flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF; What about introducing a rte_pktmbuf_priv_flags() function, on the same model than rte_pktmbuf_priv_size() or rte_pktmbuf_data_room_size()? > + } > + return 0; > +} > + > #ifdef RTE_LIBRTE_MBUF_DEBUG > > /** check mbuf type in debug mode */ > @@ -571,7 +611,8 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp) > static __rte_always_inline void > rte_mbuf_raw_free(struct rte_mbuf *m) > { > - RTE_ASSERT(RTE_MBUF_DIRECT(m)); > + RTE_ASSERT(!RTE_MBUF_CLONED(m) && > + (!RTE_MBUF_HAS_EXTBUF(m) || RTE_MBUF_HAS_PINNED_EXTBUF(m))); > RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1); > RTE_ASSERT(m->next == NULL); > RTE_ASSERT(m->nb_segs == 1); > @@ -1141,11 +1182,26 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m) > uint32_t mbuf_size, buf_len; > uint16_t priv_size; > > - if (RTE_MBUF_HAS_EXTBUF(m)) > + if (RTE_MBUF_HAS_EXTBUF(m)) { > + /* > + * The mbuf has the external attached buffed, > + * we should check the type of the memory pool where > + * the mbuf was allocated from to detect the pinned > + * external buffer. > + */ > + struct rte_pktmbuf_pool_private *priv = > + (struct rte_pktmbuf_pool_private *) > + rte_mempool_get_priv(mp); > + It could be rte_pktmbuf_priv_flags() as said above. > + if (priv->flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF) { > + RTE_ASSERT(m->shinfo == NULL); > + m->ol_flags = EXT_ATTACHED_MBUF; > + return; > + } I think it is not possible to have m->shinfo == NULL (this comment is also related to next patch, because shinfo init is done there). If you try to clone a mbuf that comes from an ext-pinned pool, it will crash. Here is the code from attach(): static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m) { RTE_ASSERT(RTE_MBUF_DIRECT(mi) && rte_mbuf_refcnt_read(mi) == 1); if (RTE_MBUF_HAS_EXTBUF(m)) { rte_mbuf_ext_refcnt_update(m->shinfo, 1); << HERE mi->ol_flags = m->ol_flags; mi->shinfo = m->shinfo; ... The 2 alternatives I see are: - do not allow to clone these mbufs, but today there is no return value to attach() functions, so there is no way to know if it failed or not - manage shinfo to support clones I think just ignoring the rte_mbuf_ext_refcnt_update() if shinfo == NULL is not an option, because if could result in recycling the extbuf while a clone still references it. > __rte_pktmbuf_free_extbuf(m); > - else > + } else { > __rte_pktmbuf_free_direct(m); > - > + } > priv_size = rte_pktmbuf_priv_size(mp); > mbuf_size = (uint32_t)(sizeof(struct rte_mbuf) + priv_size); > buf_len = rte_pktmbuf_data_room_size(mp); > -- > 1.8.3.1 >