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 smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1FE0C83F1B for ; Thu, 17 Jul 2025 06:32:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 8880741685; Thu, 17 Jul 2025 06:32:38 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id w-Ou95O35GQr; Thu, 17 Jul 2025 06:32:37 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 8EAFD41688 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1752733957; bh=Pg2azoYqDdE4dNBLBiUQo4d2AuUDCB+rchkE67GZzC4=; h=Date:From:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=5pNgz9oEt+E3i8/eSjFoIC3F7MuNkitLPlzHUyZnNKy0ZiMJem5PxIU0GLttaTGRx 3eORABHY4La7gqRkMbfOrHQRFlH9icnm8ViikR+J7eUAF3ldxLAC3b7ilXrtNgOFsN fBsfeanRQFw4XNQ8LRl2LJTVcgkjSs034j7oRALkcRcQXN96+9OwWVPmbvRGvRruZP lLU/VDTR1NXQAX+92vzzWb2dP/ueSI7TMtbo1iClW8eD67ehZDjv8EtrmaOkCHE99B MRmmbG2p8WRZkmFfw0oQwPoBWc14A5x6G4bfZr6ig2bD2Vfd7nYCNGPstwJ0cjR/bb +FTV7YLWhC+0g== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp4.osuosl.org (Postfix) with ESMTP id 8EAFD41688; Thu, 17 Jul 2025 06:32:37 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists1.osuosl.org (Postfix) with ESMTP id 4674B1A16 for ; Thu, 17 Jul 2025 06:32:36 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 2D2EF607A0 for ; Thu, 17 Jul 2025 06:32:36 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id LbF5IxnqtQ6K for ; Thu, 17 Jul 2025 06:32:35 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=166.125.252.92; helo=invmail4.hynix.com; envelope-from=byungchul@sk.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 2712E6072A DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 2712E6072A Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by smtp3.osuosl.org (Postfix) with ESMTP id 2712E6072A for ; Thu, 17 Jul 2025 06:32:32 +0000 (UTC) X-AuditID: a67dfc5b-681ff7000002311f-f3-687898feb6e6 Date: Thu, 17 Jul 2025 15:32:25 +0900 From: Byungchul Park To: Mina Almasry Cc: "Lobakin, Aleksander" , 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, 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 Message-ID: <20250717063225.GA28772@system.software.com> References: <20250714120047.35901-1-byungchul@sk.com> <20250714120047.35901-3-byungchul@sk.com> <20250715013626.GA49874@system.software.com> <20250716045124.GB12760@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: H4sIAAAAAAAAA02Sa0yTdxTG83/vNNS8VLf9p1tcuonRRNyULSfZJUa/vF9cNC5ZolFo5J1t BkhaqUCyjWmXzWZUho7QUhSlaLmMYhGoWjptkbK5bLRSrHIrOI2biMxLR7mUvS0x49uT5zl5 fuckhyMVLmYlp8k/JGrzVblKRkbJHqW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05d6+4q/mjeNew9+Gt21tbsrP25ssrje3RrZ4/DT9Yj44/d33N7 wWR5y753e16L7bVe72JdUVRJ6tWqjHSs06v+BSardbOoAwAA X-CFilter-Loop: Reflected X-Mailman-Original-Authentication-Results: smtp3.osuosl.org; dmarc=none (p=none dis=none) header.from=sk.com Subject: Re: [Intel-wired-lan] [PATCH net-next v10 02/12] netmem: use netmem_desc instead of page to access ->pp in __netmem_get_pp() X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" On Wed, Jul 16, 2025 at 12:41:04PM -0700, Mina Almasry wrote: > On Tue, Jul 15, 2025 at 9:51 PM Byungchul Park wrote: > > > > 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? > > > > When Pavel and I were saying 'remove __netmem_get_pp', I think we > meant to remove the entire concept of unsafe netmem -> page > conversions. I think we both don't like them. From this perspective, > __netmem_nmdesc(netmem)->pp is just as bad as __netmem_get_pp(netmem). > > I think since the unsafe netmem-to-page casts are already in mainline, > lets assume they should stay there until someone feels strongly enough > to remove them. The logic in Olek's patch is sound: > > https://lore.kernel.org/all/20241203173733.3181246-8-aleksander.lobakin@intel.com/ > > Header buffer page pools do always use pages and will likely remain so > for a long time, so I guess lets continue to support them rather than > try to remove them in this series. A followup series could try to > remove them. > > > > > 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' > > Yes. > > > in this series since it should be used to remove __netmem_get_pp() as I > > lets keep __netmem_get_pp, which does a `return > __netmem_nmdesc(netmem)->pp;` In general we avoid allowing the driver > to do any netmem casts in the driver code, and we do any casting in > core. > > > described above. I think I'd better add netmem_nmdesc() too while at it. > > > > Yes. netmem_nmdesc should replace __netmem_clear_lsb. Even though the unsafe version is required in this series, on second though, the safe version, netmem_nmdesc() doesn't have to be a part of this series. Let's do adding the safe version on top after. Byungchul > > I assume __netmem_nmdesc() is an unsafe version not clearing lsb. The > > Yes. > > > safe version, netmem_nmdesc() needs an additional operation clearing lsb. > > Yes. > > > -- > Thanks, > Mina