From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BC95C83F27 for ; Wed, 16 Jul 2025 04:51:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 922D96B008C; Wed, 16 Jul 2025 00:51:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D3EC6B0092; Wed, 16 Jul 2025 00:51:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C2646B0093; Wed, 16 Jul 2025 00:51:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6D1B06B008C for ; Wed, 16 Jul 2025 00:51:34 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0CDC08025D for ; Wed, 16 Jul 2025 04:51:34 +0000 (UTC) X-FDA: 83668904508.22.CD527AC Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf24.hostedemail.com (Postfix) with ESMTP id 5A109180007 for ; Wed, 16 Jul 2025 04:51:30 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; spf=pass (imf24.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752641492; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X+6Ly/sDXtC3oNgNUyxtjOrgZWVkW0j5gMJjYT3LY4U=; b=DS0DiQg5/ODvpsCgmHqph+CVEH6+wktzcPTzALR6isgasbzahiKKHsK1q1+twucDjDxuJv w+au39lyYK6uILdH/IzdRFM64iMYagncZ48LE3GePqcN6soFaKm6+vG53Yyx/jihweUdKj c72/LVmC6FRvt4vwEkdPsp8RubRwb9Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752641492; a=rsa-sha256; cv=none; b=UFr4Ra2f6Js7uMfgh7idh3AuKXyMln7DUo7tTxnejuvXYdizH3JCMWHRIjO5jhsO5cV+L0 42AycBJUg7iHhmnKpjUbZv+gFri76IOullogF8FFl+gPHTjbTOKtpw0FR/sJXZXt2qw2ra uXtC7tK/IehO1LKt2H/OQgEPVXjHCWI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com X-AuditID: a67dfc5b-669ff7000002311f-e0-68772fd17b46 Date: Wed, 16 Jul 2025 13:51:24 +0900 From: Byungchul Park To: Mina Almasry Cc: willy@infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel_team@skhynix.com, ilias.apalodimas@linaro.org, harry.yoo@oracle.com, akpm@linux-foundation.org, andrew+netdev@lunn.ch, asml.silence@gmail.com, toke@redhat.com, david@redhat.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, linux-rdma@vger.kernel.org, bpf@vger.kernel.org, vishal.moola@gmail.com, hannes@cmpxchg.org, ziy@nvidia.com, jackmanb@google.com, wei.fang@nxp.com, shenwei.wang@nxp.com, xiaoning.wang@nxp.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com, sgoutham@marvell.com, gakula@marvell.com, sbhatta@marvell.com, hkelam@marvell.com, bbhushan2@marvell.com, tariqt@nvidia.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, saeedm@nvidia.com, leon@kernel.org, mbloch@nvidia.com, danishanwar@ti.com, rogerq@kernel.org, nbd@nbd.name, lorenzo@kernel.org, ryder.lee@mediatek.com, shayne.chen@mediatek.com, sean.wang@mediatek.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, aleksander.lobakin@intel.com, horms@kernel.org, m-malladi@ti.com, krzysztof.kozlowski@linaro.org, matthias.schiffer@ew.tq-group.com, robh@kernel.org, imx@lists.linux.dev, intel-wired-lan@lists.osuosl.org, linux-arm-kernel@lists.infradead.org, linux-wireless@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: Re: [PATCH net-next v10 02/12] netmem: use netmem_desc instead of page to access ->pp in __netmem_get_pp() Message-ID: <20250716045124.GB12760@system.software.com> References: <20250714120047.35901-1-byungchul@sk.com> <20250714120047.35901-3-byungchul@sk.com> <20250715013626.GA49874@system.software.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Brightmail-Tracker: H4sIAAAAAAAAA02SfUyTZxDA87zfdHZ517HtGWwhlpExkonbMLkpMWTJklcTFhf/MJsxrpNu 7VYQi5SPaAZY58BR3KpGSjFVqxRqVlIEOlfY1hJAMXxUYB3yIaBEszInSqFS2rV1Zvz3u7vc /e6S40hJN5PAKfMOytV5MpWUEVGi+XXn3x5KL1JsPHksFYy2ywwMPTpHg3W5GBpuO2jwNGL4 ZXCZAGNTG4LHgVss2CvHSXjU1cPAhXN+EgLN1RQYB7QULNqekHC3e4aFXtcqBVZ7NkxdmqPA eaydBPdiCszU9DJQrV0hoXbyKAPhsRUaOgJ/s1DhsBDQ8VcrC4NtOhpOPrlIQnvZ7YhrdpSG m1eNDNw8MoRg8nKYhjlXROizjLOgsx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luWgmASKNbkXf8jNG+wNoygxmulk5waV5WFicp+n3x1l05LuL+DInmH8bPGEZ2UcksYc0ZpHUH0x+KahSJw1YaTMkrmGOyJF4MG2RSzH4pcQeBhyoseXbVueLCXphDAjdbA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jul 15, 2025 at 12:09:34PM -0700, Mina Almasry wrote: > On Mon, Jul 14, 2025 at 6:36 PM Byungchul Park wrote: > > > > On Mon, Jul 14, 2025 at 12:58:15PM -0700, Mina Almasry wrote: > > > On Mon, Jul 14, 2025 at 12:37 PM Mina Almasry wrote: > > > > > > > > On Mon, Jul 14, 2025 at 5:01 AM Byungchul Park wrote: > > > > > > > > > > To eliminate the use of the page pool fields in struct page, the page > > > > > pool code should use netmem descriptor and APIs instead. > > > > > > > > > > However, __netmem_get_pp() still accesses ->pp via struct page. So > > > > > change it to use struct netmem_desc instead, since ->pp no longer will > > > > > be available in struct page. > > > > > > > > > > While at it, add a helper, pp_page_to_nmdesc(), that can be used to > > > > > extract netmem_desc from page only if it's pp page. For now that > > > > > netmem_desc overlays on page, it can be achieved by just casting. > > > > > > > > > > Signed-off-by: Byungchul Park > > > > > --- > > > > > include/net/netmem.h | 13 ++++++++++++- > > > > > 1 file changed, 12 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/include/net/netmem.h b/include/net/netmem.h > > > > > index 535cf17b9134..2b8a7b51ac99 100644 > > > > > --- a/include/net/netmem.h > > > > > +++ b/include/net/netmem.h > > > > > @@ -267,6 +267,17 @@ static inline struct net_iov *__netmem_clear_lsb(netmem_ref netmem) > > > > > return (struct net_iov *)((__force unsigned long)netmem & ~NET_IOV); > > > > > } > > > > > > > > > > +static inline struct netmem_desc *pp_page_to_nmdesc(struct page *page) > > > > > +{ > > > > > + DEBUG_NET_WARN_ON_ONCE(!page_pool_page_is_pp(page)); > > > > > + > > > > > + /* XXX: How to extract netmem_desc from page must be changed, > > > > > + * once netmem_desc no longer overlays on page and will be > > > > > + * allocated through slab. > > > > > + */ > > > > > + return (struct netmem_desc *)page; > > > > > +} > > > > > + > > > > > > > > Same thing. Do not create a generic looking pp_page_to_nmdesc helper > > > > which does not check that the page is the correct type. The > > > > DEBUG_NET... is not good enough. > > > > > > > > You don't need to add a generic helper here. There is only one call > > > > site. Open code this in the callsite. The one callsite is marked as > > > > unsafe, only called by code that knows that the netmem is specifically > > > > a pp page. Open code this in the unsafe callsite, instead of creating > > > > a generic looking unsafe helper and not even documenting it's unsafe. > > > > > > > > > > On second read through the series, I actually now think this is a > > > great idea :-) Adding this helper has simplified the series greatly. I > > > did not realize you were converting entire drivers to netmem just to > > > get rid of page->pp accesses. Adding a pp_page_to_nmdesc helper makes > > > the entire series simpler. > > > > > > You're also calling it only from code paths like drivers that already > > > assumed that the page is a pp page and did page->pp deference without > > > a check, so this should be safe. > > > > > > Only thing I would change is add a comment explaining that the calling > > > code needs to check the page is pp page or know it's a pp page (like a > > > driver that supports pp). > > > > > > > > > > > /** > > > > > * __netmem_get_pp - unsafely get pointer to the &page_pool backing @netmem > > > > > * @netmem: netmem reference to get the pointer from > > > > > @@ -280,7 +291,7 @@ static inline struct net_iov *__netmem_clear_lsb(netmem_ref netmem) > > > > > */ > > > > > static inline struct page_pool *__netmem_get_pp(netmem_ref netmem) > > > > > { > > > > > - return __netmem_to_page(netmem)->pp; > > > > > + return pp_page_to_nmdesc(__netmem_to_page(netmem))->pp; > > > > > } > > > > > > > > This makes me very sad. Casting from netmem -> page -> nmdesc... > > > > > > > > Instead, we should be able to go from netmem directly to nmdesc. I > > > > would suggest rename __netmem_clear_lsb to netmem_to_nmdesc and have > > > > it return netmem_desc instead of net_iov. Then use it here. > > > > > > > > We could have an unsafe version of netmem_to_nmdesc which converts the > > > > netmem to netmem_desc without clearing the lsb and mark it unsafe. > > > > > > > > > > This, I think, we should address to keep some sanity in the code and > > > reduce the casts and make it a bit more maintainable. > > > > I will reflect your suggestions. To summarize: > > > > 1) The current implementation of pp_page_to_nmdesc() is good enough > > to keep, but add a comment on it like "Check if the page is a pp > > page before calling this function or know it's a pp page.". > > > > Yes please. > > > 2) Introduce the unsafe version, __netmem_to_nmdesc(), and use it in > > __netmem_get_pp(). > > > > No need following Pavel's feedback. We can just delete > __netmem_get_pp. If we do find a need in the future to extract the > netmem_desc from a netmem_ref, I would rather we do a straight cast > from netmem_ref to netmem_desc rather than netmem_ref -> pages/net_iov > -> netmem_desc. > > But that seems unnecessary for this series. No. The series should remove accessing ->pp through page. I will kill __netmem_get_pp() as you and I prefer. However, __netmem_get_pp() users e.i. libeth_xdp_return_va() and libeth_xdp_tx_fill_buf() should be altered. I will modify the code like: as is: __netmem_get_pp(netmem) to be: __netmem_nmdesc(netmem)->pp Is it okay with you? > > 3) Rename __netmem_clear_lsb() to netmem_to_nmdesc(), and return > > netmem_desc, and use it in all users of __netmem_clear_lsb(). > > > > Following Pavel's comment, this I think also is not necessary for this > series. Cleaning up the return value of __netmem_clear_lsb is good > work I think, but we're already on v10 of this and I think it would > unnecessary to ask for added cleanups. We can do the cleanup on top. However, I still need to include 'introduce __netmem_nmdesc() helper' in this series since it should be used to remove __netmem_get_pp() as I described above. I think I'd better add netmem_nmdesc() too while at it. I assume __netmem_nmdesc() is an unsafe version not clearing lsb. The safe version, netmem_nmdesc() needs an additional operation clearing lsb. If you are fine with it, I will add these two helpers in the next spin. Or I could add __netmem_nmdesc() only. Thoughts? > > Anything else? > > Thank you very much :-) I rather apprecisate your feedbacks. Byungchul > -- > Thanks, > Mina