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 0ED88C83F17 for ; Thu, 10 Jul 2025 18:12:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A75526B0095; Thu, 10 Jul 2025 14:12:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A00706B0099; Thu, 10 Jul 2025 14:12:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C6446B009A; Thu, 10 Jul 2025 14:12:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 76A426B0095 for ; Thu, 10 Jul 2025 14:12:07 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 264271608BD for ; Thu, 10 Jul 2025 18:12:07 +0000 (UTC) X-FDA: 83649149094.23.1E90397 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf07.hostedemail.com (Postfix) with ESMTP id 3825640005 for ; Thu, 10 Jul 2025 18:12:05 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Cl2ZltKM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of almasrymina@google.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=almasrymina@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752171125; a=rsa-sha256; cv=none; b=dXQqgVOjOJfC76eLrzwGr6ZgD+XRHrOQHmUx6CGbfPJeqLnrZjcsT7/WEmbu3k/V6LGNmD aAGeuPMZb2fIaW70Ik8I9gjcEQnkQ/Td1bNzG3AT4iE/TBiGALMsxuG3nxxpWuO8mevIRr pG1+9GnBBi/n/DmYjylio7xzi+KRsFc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Cl2ZltKM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of almasrymina@google.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=almasrymina@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752171125; 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:dkim-signature; bh=V19aqiboGpdwFSVORlEjus6nArpZ/d5eCyXiiM9x078=; b=A71T9Wnp1K27IAzKMRFAx4Li78AhTz1r6K7zHBPEo/5MxnOqTIt4Hrh+7alK4vFaILLaaI 5pDntTvMSXzPKxfaBPUPvlm61hxm3FFtwC61IpPANxiza3vBFJbc4EegYe+sa53CM+VTXM 430i/PY9BDznYhb6DVmcmhYNrzR52Tk= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2357c61cda7so20845ad.1 for ; Thu, 10 Jul 2025 11:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752171124; x=1752775924; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=V19aqiboGpdwFSVORlEjus6nArpZ/d5eCyXiiM9x078=; b=Cl2ZltKMUntsJunb1ONdY+g9S+b3cFa49QMON1OzAiJF1gFC1ro5HshZozTL9cV1/R 3FV2GyMI1GU8Y7rNioiI8aoR/ApS8GrrlWJ2Qa0gzyqXUicRrSf9a6V2AjyrW2nXgG+A U4klcimmQQB9uaJx2+LHDyEIBWBZnUYAGEK8LdiMPsbyC+3D6wjWF2amaBhweRHBIQhO NPhj6BIjPcOAykika84ItMww7OE0qOSwkBhfjWpYrKrErt76dkeKmkAMsdCv/WCIjiIb S7Pwob3KfgcykzJAao/fOI8QgPsZkNkT3T4el8ZMToaJkQ3FRjHlTf+bcqIraN5S4Xuq 7EEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752171124; x=1752775924; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V19aqiboGpdwFSVORlEjus6nArpZ/d5eCyXiiM9x078=; b=vbzVKvHBAHbRqz+EH9Q7sANtyCWnEYh92SxeQJoCqyQhI9MN+LwdSh0JkEiNfjH27T oTgMvq4YypnK0toWVkDNzPMUIMKP4lPD0LOuJJTTu6YFqQTUiznbiCLR7Q7HawcCKD9e IrIUcn0p4IBc/EgnWdHrj5I1VnWCfQadYSx3VtDHNjejCx7OEnz17bhIJGar22Occ7G+ qu904kByF01UpOLbNvwcCWfAeNzuFfAi/s0NhCLzBtWgjnXHOKpdGPwUPU+ThB3MKf1r EIYwtUXMX8YMcX8NC7XhKEc+OOLnYYFMmau0XLcMs/eC8lC4TOqp7iAJJDBKETy4J1kJ 5AvQ== X-Forwarded-Encrypted: i=1; AJvYcCVnYixvwXzYNhlrbTS1zKpkTKu8T7V2D8dUqF9K3CI+wcP5Crm2UkQlnJV2XAY6ix7r6eGIYB7Fsg==@kvack.org X-Gm-Message-State: AOJu0YxAjj6AHf9WC1kewHOosQDHu0iVmSMsSv/Mbitw24X8sEQo9Pfd uQMh3oOy59VxpY9+gSuEz3EEvKIoOx/mJBRfxN3OpNczyIvwn7NDQUpq+jKLeJzb4/NEx5O5jwM XJGkU8YD59hNFo+xtsiACNpxMbM/59XleYZtQGdDoECvKx16y5fIiNXWuBXw= X-Gm-Gg: ASbGncsLngBjrc0iKWmBGNhgfRy7MAJGhshEnl8CRcN4+pxv2dQVUu2lPcCjHOLBA5s JXwJRewiTMiDNsD/2HHs38VXqMtw8p4sy14Twr0GP0irUgGwupOr+XAGQqN1iP1S4c3hzJ8MMop jmYkv1aIT7eYR6yKRtL3b6eVg60/phYfBlGs4AVTgXbqYu305e6bcjmTJBmvOpoPFL4thXzac= X-Google-Smtp-Source: AGHT+IG5ZbAwY31DrTqPKHnuAy3Jprfz+D7kIoMw6GvkmY8szHlEwG6tCQR4HIE6AdRqx8Df7hZn3pf+KBbD+xSG9cQ= X-Received: by 2002:a17:902:ce84:b0:234:a469:62ef with SMTP id d9443c01a7336-23dee4c2b01mr119975ad.3.1752171123623; Thu, 10 Jul 2025 11:12:03 -0700 (PDT) MIME-Version: 1.0 References: <20250710082807.27402-1-byungchul@sk.com> <20250710082807.27402-3-byungchul@sk.com> In-Reply-To: <20250710082807.27402-3-byungchul@sk.com> From: Mina Almasry Date: Thu, 10 Jul 2025 11:11:51 -0700 X-Gm-Features: Ac12FXwouZPPpjT9QSjhfrgvcsGvhkuRBlZmuIVXl9fEL0h9kvK2OFLOD8o7JwM Message-ID: Subject: Re: [PATCH net-next v9 2/8] netmem: introduce utility APIs to use struct netmem_desc To: Byungchul Park 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 3825640005 X-Stat-Signature: trmq8ecp4hfh35gdqoani5npor3ps7uw X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1752171125-611736 X-HE-Meta: U2FsdGVkX1/Ys5gTDPF+mo7LN/MFmylrt9CtKrGWEeDVFa9IAeRn2FwDkLbXluSm+pN/JWpIYeQDHHhwHqYps3NXPJ2uyGhrL1ZIgeSOhLxJKdRgREM7gVP/84o3kYBZ1madFILTsujUUuGGYJJOKc1KTLfDhxl8SuYjz7PtsKxS/Dp2lqhUEdJHO1uacM70h+58dPbKJ7Ih9I+txsxzbry39oMDFvVx/m7ALaweJlmrmUq9lMQbNQuLVDQp78uvSUUgEN/qZzJG2HRg3oOdq2+/Mq1eCmEFVDnw3b+isF0Iw75AKKPxXOgbrI9u8FQRLUtz0brazRK7gnL0dz8JtQpkmMtqwBVjgZcyN8Lzk5fZtaKWYZgHaqGRCzLmhSeJsT8KkPKOTqOsDK7on229748UChnt2bE10M6HknzqS7X+ZlVSdViU5AejcMfc7Ajcc7X2NfUeRwNRD3PA86uTI5CigAANmk8i4JcHzkxP/VcHwR2fAW9PZgie355DIu0QsCzXA6WfHceYk4qEc78Az8Sjm2v30hiHpcphDpt090JDPqUbPYTiWDC0cDVjvXoTPUbzVoBcQpupX4RZgNGcbhTXHnGgYtaZ7E7yDYVxXrgf4oyCJMEsTvsG4Bm9eaZ4W8Dls23qzWqc4iOTGOPSWw9UP+LFQCye5frxVYjf9t8enkm38gm2wmrE3hIVfFW6dX/ZwGNobtxsQnLUaBdrPpi4gWDKF3CyFppoBe/LnNAkzWDHNIpi7UyiRWnXqDi5VppqYogJ0o1I3ToMBY1L9zMomEPB2d+wP4HQ8InhBEWOIXtD8nrQswO5RpiqDqUhlXgBd4UqBHLBYDet1kMfucgE6XqmVYT6uBwq6bafgnQ67PxLCJ6V8/6sq4Ci4Aq3hGUDnJuaEE0/f8hGx6S389dHxKFjqcJjTWpQ2PlD+4u9vDtFsW310OTAEYZJdJeHc37b0141d2yGPMupPD1 SVYVc4zc T9Xo5mmFQEbn9b1ewUFbZTqYkn1iyKRbGbRA4n3BOwK0b7QF43grGCjg1joXhCymw8RpZgjoKArg9oOWOBYkJF5ehNbGPXOaOB43fP39vZE9qJ/dmspzQHATV9cLLJVTBJGLjoyXOf8HmeMYRVF5WUXuApZ6k6DrMuCIaSHqAKPeUC5WyQouFOyrgEAOF2fra1URGP9eefw3L+WkZw5B7bKt+CEwadZgyz8Gr1W8wYaqX83QztZDySt5MnH6yzHQ/tQI4a0VjJnHgPZdkTsCaCQByuoU9Iejs5kfSYUVOfIMVC1rn76LGaoQ9sOlW3UEIZQEHvOK+UDdZN+fhpYWV/9gYvC816l6PbL5ImmXs6Llj3jHgOVpqXe9yQz6SntoUDPzBMa8d/V6nvsphwrZmEzO9U/Eq/plFqs+Y 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 1:28=E2=80=AFAM Byungchul Park w= rote: > > 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 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. > +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... > +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. --=20 Thanks, Mina