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 5F49BC83F17 for ; Fri, 11 Jul 2025 01:03:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABB4B6B009D; Thu, 10 Jul 2025 21:03:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6BBE6B009E; Thu, 10 Jul 2025 21:03:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 982276B00A0; Thu, 10 Jul 2025 21:03:03 -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 88AFF6B009D for ; Thu, 10 Jul 2025 21:03:03 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2CA2912DA7C for ; Fri, 11 Jul 2025 01:03:03 +0000 (UTC) X-FDA: 83650184646.22.E1ECA5D Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf04.hostedemail.com (Postfix) with ESMTP id 6FDA040010 for ; Fri, 11 Jul 2025 01:03:00 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; spf=pass (imf04.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752195781; a=rsa-sha256; cv=none; b=YRDF+neZwaDmeJ0/ZBU6U94igA2R8PYScvDjXPzPgPMJUPG1yhZI6mrJaQxojuqkeVVYTN TO/5smGOuUlWvvILvouC9VW53/jxxxg72put8Ut1IS8pNnWpJrq4WMIvqb1mixiZ68fwDX mGad9pbdROLiQzli8/hx2l9PSsSsXf8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752195781; 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=Hmi7cvmAdheg++j0Z6i+cgA/FcZT8ZyFlZPvjPdr31k=; b=z0NIjk4sZDJyO342ujp73EHKFv5Y7cCfoLGs/XAmxSVwB2XUjYwqSAvyi+Bb4sl6dNGo+R S5snrHEfibl96CxSQZyk/BPHB3zZhSPG5CFphRNksFEOc/7rnPW7FZGeMQzCgCBePIzyYJ ljkbBLUaJzN3qjOXomRb3yzKztyrV4A= X-AuditID: a67dfc5b-669ff7000002311f-f4-687062c211be Date: Fri, 11 Jul 2025 10:02:53 +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, kuba@kernel.org, ilias.apalodimas@linaro.org, harry.yoo@oracle.com, hawk@kernel.org, akpm@linux-foundation.org, davem@davemloft.net, john.fastabend@gmail.com, andrew+netdev@lunn.ch, asml.silence@gmail.com, toke@redhat.com, tariqt@nvidia.com, edumazet@google.com, pabeni@redhat.com, saeedm@nvidia.com, leon@kernel.org, ast@kernel.org, daniel@iogearbox.net, david@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, horms@kernel.org, linux-rdma@vger.kernel.org, bpf@vger.kernel.org, vishal.moola@gmail.com, hannes@cmpxchg.org, ziy@nvidia.com, jackmanb@google.com Subject: Re: [PATCH net-next v9 2/8] netmem: introduce utility APIs to use struct netmem_desc Message-ID: <20250711010253.GB40145@system.software.com> References: <20250710082807.27402-1-byungchul@sk.com> <20250710082807.27402-3-byungchul@sk.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: H4sIAAAAAAAAA02Sa2yLYRTHPX2va/byroaHLUhnwZLNCHIkwiIiDyFxSSTDMmUvbbZ1TTez CkkxEWXD3LuijK27UMq6rZmx7ioIyqjrpowPrOa27MJYLWLffvmfk//vfDg8pbjKjOM12gxJ r1WlKFk5Le8IPh/t3qBTx3YUzAGLvYyF0u4sKGqrZMBS4kTwvecFB9/qm1goONdFgeV+Ng0/ 7L0UtDf6OCh1LIPWwvc0VO+toMB3sJmFnOw+Cm70+DnYVWmTwQNnLgNHey9SUGFs4+CRy8LC 67LfDLx359Bw21xMQ2tuHDRaR0PXnU8I6u0VMug6cJqFIx4rC2+zWxF46nw05O/MRWCv8TLQ 1z3Qkd/wmoubROo+fabI9eJnMlJlfsURq2MLuWaLIiavhyKOkn0scXzN48jLJ9UsaT7ZR5Oq ym8ykrPbz5Iv7c9p8rmmhSX26y00uWut55aHrJHPTZJSNJmSftq89XL1h/J+RueLznru7+eM qCHChIJ4LM7Eriu13D++c+wxbUI8T4uRuMUYGYhZcTL2enuoAIeKU/GFmsOMCcl5SjSzuMXl owODkWIi7jzhlAVYEAFX1LrYACtEG8L+82gwD8G3T737u08NlP4846ECLkoMw0X9/GA8Ae8u z//rChJXYG+5iwnwKDEC33I2yQJeLN7lcXfnR3bw5rG41ualD6EQ8xCFeYjC/F9hHqKwIroE KTTazFSVJmVmjNqg1WTFbExLdaCBRyrc8XNtJfr6YJUbiTxSBgtxpWlqBaPKTDekuhHmKWWo cHmZTq0QklSGbZI+LVG/JUVKd6MwnlaOEWZ0bU1SiJtVGVKyJOkk/b+pjA8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kQ2eRimnJVJEH5XX0gCG2k0VqRhhTpFQhv65ZPQmqhD1jOtOypvMpcolnHyyVejVbpjwHK5npBgjoiptwC+dQ3FEQkTyVtATFPU9ZGbIC8cIwy+MGWB1lyEVs/oVUVSUgaCYVSKV3UstcbaeIEW+tv//DZdPYs3nmOYd8b5rdRMpaeN96xfV65cGDmiRB9IfCoMWZsBvSknuo8yIJWFCdq0hGnHQ1FxHk4dM+P1rvbbHXIY cRzE16w+ y7mk3mGYKl/jZs/TMCNZpEIV6+zlpvHqPdXC4SAaB9E2iX/kiNdtdJ9aUoKVZTdcN86G4yBUO2zp8OHcF/WRPJizts72XUKRVoUojB8os8Z9YXT5PQOImHpwexV9wNu2cOafF0gYVJ5ul9Wnl6g+jV6nvaWyzfSd86Gzy3HsbOwqDnlAFQd4ggmNzWCo5eI1xpwtk3u74JIP8Qaw= 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 Thu, Jul 10, 2025 at 11:11:51AM -0700, Mina Almasry wrote: > > On Thu, Jul 10, 2025 at 1:28 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, some code e.g. __netmem_to_page() is still used to access the > > page pool fields e.g. ->pp via struct page, which should be changed so > > as to access them via netmem descriptor, struct netmem_desc instead, > > since the fields no longer will be available in struct page. > > > > Introduce utility APIs to make them easy to use struct netmem_desc as > > descriptor. The APIs are: > > > > 1. __netmem_to_nmdesc(), to convert netmem_ref to struct netmem_desc, > > but unsafely without checking if it's net_iov or system memory. > > > > 2. netmem_to_nmdesc(), to convert netmem_ref to struct netmem_desc, > > safely with checking if it's net_iov or system memory. > > > > 3. nmdesc_to_page(), to convert struct netmem_desc to struct page, > > assuming struct netmem_desc overlays on struct page. > > > > 4. page_to_nmdesc(), to convert struct page to struct netmem_desc, > > assuming struct netmem_desc overlays on struct page, allowing only > > head page to be converted. > > > > 5. nmdesc_adress(), to get its virtual address corresponding to the > > struct netmem_desc. > > > > Signed-off-by: Byungchul Park > > --- > > include/net/netmem.h | 41 +++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 41 insertions(+) > > > > diff --git a/include/net/netmem.h b/include/net/netmem.h > > index 535cf17b9134..ad9444be229a 100644 > > --- a/include/net/netmem.h > > +++ b/include/net/netmem.h > > @@ -198,6 +198,32 @@ static inline struct page *netmem_to_page(netmem_ref netmem) > > return __netmem_to_page(netmem); > > } > > > > +/** > > + * __netmem_to_nmdesc - unsafely get pointer to the &netmem_desc backing > > + * @netmem > > + * @netmem: netmem reference to convert > > + * > > + * Unsafe version of netmem_to_nmdesc(). When @netmem is always backed > > + * by system memory, performs faster and generates smaller object code > > + * (no check for the LSB, no WARN). When @netmem points to IOV, provokes > > + * undefined behaviour. > > + * > > + * Return: pointer to the &netmem_desc (garbage if @netmem is not backed > > + * by system memory). > > + */ > > +static inline struct netmem_desc *__netmem_to_nmdesc(netmem_ref netmem) > > +{ > > + return (__force struct netmem_desc *)netmem; > > +} > > + > > Does a netmem_desc represent the pp fields shared between struct page > and struct net_iov, or does netmem_desc represent paged kernel memory? > If the former, I don't think we need a safe and unsafe version of this > helper, since netmem_ref always has netmem_desc fields underneath. If Ah, right. I missed the point. I will narrow down into a single safe helper for that purpose. > the latter, then this helper should not exist at all. We should not > allow casting netmem_ref to a netmem_desc without first checking if > it's a net_iov. > > To be honest the cover letter should come up with a detailed > explanation of (a) what are the current types (b) what are the new > types (c) what are the relationships between the types, so these > questions stop coming up. I will. Thanks for the feedback. > > +static inline struct netmem_desc *netmem_to_nmdesc(netmem_ref netmem) > > +{ > > + if (WARN_ON_ONCE(netmem_is_net_iov(netmem))) > > + return NULL; > > + > > + return __netmem_to_nmdesc(netmem); > > +} > > + > > static inline struct net_iov *netmem_to_net_iov(netmem_ref netmem) > > { > > if (netmem_is_net_iov(netmem)) > > @@ -314,6 +340,21 @@ static inline netmem_ref netmem_compound_head(netmem_ref netmem) > > return page_to_netmem(compound_head(netmem_to_page(netmem))); > > } > > > > +#define nmdesc_to_page(nmdesc) (_Generic((nmdesc), \ > > + const struct netmem_desc * : (const struct page *)(nmdesc), \ > > + struct netmem_desc * : (struct page *)(nmdesc))) > > + > > +static inline struct netmem_desc *page_to_nmdesc(struct page *page) > > +{ > > + VM_BUG_ON_PAGE(PageTail(page), page); > > + return (struct netmem_desc *)page; > > +} > > + > > It's not safe to cast a page to netmem_desc, without first checking if > it's a pp page or not, otherwise you may be casting random non-pp > pages to netmem_desc... Agree, but page_to_nmdesc() will be used in page_pool_page_is_pp() to check if it's a pp page or not: static inline bool page_pool_page_is_pp(struct page *page) { struct netmem_desc *desc = page_to_nmdesc(page); return (desc->pp_magic & PP_MAGIC_MASK) == PP_SIGNATURE; } Hm.. maybe, it'd be better to resore the original code and remove this page_to_nmdesc() helper. FYI, the original code was: static inline bool page_pool_page_is_pp(struct page *page) { struct netmem_desc *desc = (struct netmem_desc *)page; return (desc->pp_magic & PP_MAGIC_MASK) == PP_SIGNATURE; } > > +static inline void *nmdesc_address(struct netmem_desc *nmdesc) > > +{ > > + return page_address(nmdesc_to_page(nmdesc)); > > +} > > + > > /** > > Introduce helpers in the same patch that uses them please. Having to > cross reference your series to see if there are any callers to this > (and the callers are correct) is an unnecessary burden to the > reviewers. I adopted how Matthew Wilcox worked on this[1], but sure, I will. [1] https://lore.kernel.org/linux-mm/20230111042214.907030-3-willy@infradead.org/ Byungchul > -- > Thanks, > Mina