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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 D10B4C83F27 for ; Wed, 16 Jul 2025 04:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=X+6Ly/sDXtC3oNgNUyxtjOrgZWVkW0j5gMJjYT3LY4U=; b=OjPgG55WJ3MV0sYOT44IwM37dd 8YYjPry7R+x6g9w2cg4MVmVqx1bBxJLRtjA5iEuEm0/sfUyZnozYzXk9ePdE7WHmgdjaytJd0U/gC CkHL7dbzcwVNdhdLJpYGVZOQPIbFyB2FI+vW3NGHFt9f4c+4xzclDQVVKGptmPKtP5P9BisA/Z5Ud Zyxgh/O0z7ea4pgjvrI2VemVrexy/vHJ+q5SZONHsFKaQjc328FGzdw9qdnwniPTvdTZqkxdb9yoj /aRA3c/iktgZ5jQBRDsuLSLgHkTutXB28TbU9mUsSaeZA8AFhHEITGaJpmnZUrNx53dlDX4yb1uX0 2xWIZmuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1ubu7F-00000006kCl-1wW4; Wed, 16 Jul 2025 04:51:37 +0000 Received: from exvmail4.hynix.com ([166.125.252.92] helo=invmail4.hynix.com) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1ubu7A-00000006kBy-00ZQ; Wed, 16 Jul 2025 04:51:36 +0000 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 m1eNDNw8MoRg8nKYhjlXROizjLOgsxoQuH5tZKBC+x74Wh+z8M+pLhKmdFkQOqOBbtPL4O/z Ibh1cYSAsNPBQv/kTzR02doJGJ4OkOD/vp6BqvkaBCO1Vwm4Ud9Mg7lvmIjssRNGw0EC9B4T A7PaKQQe9wwFdeU6BLZOLw0PnZGTV5aNTNYHgtv3gBQcE2YkXGn8kxDunQgRgrfzOiH8bJhg BZO9UGixpAkXnPcJocrrIQV7UyUj2Bd+ZIXxUScj9J5ZoYQW8zfCvZZatOP1T0WZOXKVUiNX p2/9TKQo7x9A+S2biiuDVqYMzaVWoTgO8xn4j7kbxDMeHdFTUab4FDygHWOizPBvYq83QEY5 nn8Lmzt/oKuQiCN5M4fvdzhQNHieXyBx32JfrPtFvhCfn/bGWMwD9k0/jHVI+LsEXr1z9r/C C/ha7Z0YkxFF8KwnouAinIgbQt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RlGfvHWPTHOotw8daE41lUQcdBGafNWCElieS+GHBivIGJPcer7PfJuOMc29wgcCYRxjJbeB t7cfpSxIxmLOzvIPL7lRrHiGe4z5nrme+PZzXB5/ajwQZzkHfGj8UXxDwd0n+KV71f8OnuWv We/FGUuKSLVfUrASr+Prouw/7Rf54pYTcXMC9wH/pPcYE+PnuZf5K61XiXK0yrYiybYiyfZ/ km1FUg0iG5FSm2PMVmt1qUmG/ZqCHK0pKTM324Wk1z1TGDnqRrMD73kRxyJVotydZtQoKLXR UJDtRTyLVUp5hV9qybPUBV+J+twMfZ5ONHjROpZUrZG/v1Pco+D2qQ+K+0XxgKj/b0qwCWuL 0Lity5SfWOKJDFdkfPlpelNGSzRzc9umr2dm1rx0vZrbu6Wq/JPXzFm5vsxdhWllCx8v/dye 8hkd7Ew2WhLzrBqf81d7cMdW/GHS9pTv0nftnFr9JNkiV+iappXvTm3xd1pvKUbT3nTsK/uC fbtOmTppMnxe+Pv0qnQfaepsCEbzT6lIg0a9eSPWG9R/Ay6goT22AwAA X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250715_215132_167583_98FF6AAC X-CRM114-Status: GOOD ( 61.64 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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