Received: by 2002:a05:7412:8d08:b0:f9:2d0a:d759 with SMTP id bj8csp27028rdb; Sun, 17 Dec 2023 00:15:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIa4xgRRxaFb9oGOZv8ei0Bz//ZA/nnyGtzslxdQQu6lIOrXqJdp3RlJNbSr45GHK6PdLz X-Received: by 2002:a05:622a:491:b0:423:ab46:f97b with SMTP id p17-20020a05622a049100b00423ab46f97bmr16597977qtx.27.1702800930053; Sun, 17 Dec 2023 00:15:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702800930; cv=none; d=google.com; s=arc-20160816; b=hVLh84nQr/vkAdGBrgBJaSP4jowI9RjCKpSaY0bCrj8Ju7WX1dBbfKoa/WOdjghXTl TtMcct3E5K4ruwyFd5g4j0LmEsBJRYtwJ61DfZyCh4/uQdS4ptaZVOO638fQBi1bIYzp JU6DAlhJS/4PPIyH6GIJosleBN1zfGZPTyg/XB7S+AsF4HZk3S9vsj0aShqDblvbxRxS ohV8uCqE9A9Wu3xSEOl7vK3SU0bVM14CDgF/Y/cvzGKHAZkzAQUVgvWdjbwpz0Ly54jy lpEsK/+tNfBfZUi0j+DC0PJAShxLhs9tcF/VZ+0tmZoXKSBx1yEAaAgfA5OMo8JYazyX hEWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=60F2ATzAHDKtGPRs2bXfsavW1DI+agjrMkffzWa7PLI=; fh=nNl3TOHGi4Xedfzd0dEsTSOpx0drNbHNsO1WDluQa2w=; b=NneU7s+37FiRsQZaAC5aHNakdSiFKOqvgInOr9rzSlAo0azQ5TEcTKLhSRXi0vfKth +MFBB+9gHv/xiqYBL9NIDQGYwofStOKQg50mYEZzjE4OZaMwGwNo6dZNCMvBh4mUKoQs JNot9shHaQ+RyF2P7Y1VaoALQeja8DPWC+5qwp+L4bmnZV/9OC750ZMFDKXrQG+5ep+i DecTZNsW/bxkZlUkEjo+07F/ucaCG5g1Q7wBiexe1yP4XnrEABR7j1xb9psb6/DiifJH 0nttOOO9L5KsiJhhhrs3EsJpThWM1lAxeIG9aHBGdezrojZZ0W+TSOLDfK+szayAiOe0 kJMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1yKWnsc1; spf=pass (google.com: domain of linux-kernel+bounces-2505-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2505-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gc15-20020a05622a59cf00b00423a6edba0csi22807309qtb.459.2023.12.17.00.15.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 00:15:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2505-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1yKWnsc1; spf=pass (google.com: domain of linux-kernel+bounces-2505-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2505-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BE4FE1C219F7 for ; Sun, 17 Dec 2023 08:15:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE9551FC2; Sun, 17 Dec 2023 08:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1yKWnsc1" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E9E3185E for ; Sun, 17 Dec 2023 08:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-54c77e0835bso2420352a12.2 for ; Sun, 17 Dec 2023 00:15:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702800914; x=1703405714; darn=vger.kernel.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=60F2ATzAHDKtGPRs2bXfsavW1DI+agjrMkffzWa7PLI=; b=1yKWnsc1BiM/fv7trNG8kQ87EY1/JstLrlFwfBUvc8OjDg99cqspvqkcyJmMR0E2Pu IBJIrdcVKB5XxXsUk6i/F0oYY6WcMflL6QCk8LIc/B7TYvyro6ZyCJw/BNkc6yeU9AIr bcgYYadSydATY2Q6C2bquuaACBsQjmCFVakZdM1RdSvC+I5J0KovIKZr85wILy8CTh7o H43/pn7pKNv3RlApzXykOOpd26Qqj8wi9xly5QkzpnLBD1/8akurJMcAb4Q099CSyZB5 2mzQbdyJIukEzllzBRNIucH8pBvhpL9mxTmGlFfZ7zAxQMHv+W46mwV+ibRVxyb3SZtq lx+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702800914; x=1703405714; 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=60F2ATzAHDKtGPRs2bXfsavW1DI+agjrMkffzWa7PLI=; b=EdsF3HQNhjzb+4P8t1Vc1+IqU6M8DbcrZSMnC8cvYHjDzb0HYOar7UmaYQS2Wph7Yq 1joXrQEt4rKIYIKvrf8S0/nml2UlCUEWrS/ds2R/tYNbDrWT7kpGJ/AUPqBcu/OpEika Iokzq9vHgv+asehbgfGgaLSKIDDj6VbtTD7YkrBeZc7AD7+tQySemyCsJd9HBPCgPtzl SP0nEjYpghS9MeGh28kmFxboOnoyorCIxFHPsNUy2uydiJHFCjdnDeI7oD0QrtmBIIa4 ypTN41bAJF7nFC+kg2Mibes1JbZCLscIkkkggsxH8uZpoXBrRY7wtAck1cjuYiA0Ppc+ SXng== X-Gm-Message-State: AOJu0YzopY101YqUzf/Y/JywOt1XKgi5+XNFA2K15aSVoFWMVZaXDfrd bKkq+D5X77UsUPdc6gYYs6nJfi+tEOBUYNFtKkJYNA== X-Received: by 2002:a17:906:8f:b0:a23:26bf:6cd9 with SMTP id 15-20020a170906008f00b00a2326bf6cd9mr925030ejc.34.1702800913483; Sun, 17 Dec 2023 00:15:13 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231214020530.2267499-1-almasrymina@google.com> <20231214020530.2267499-3-almasrymina@google.com> <20231215185159.7bada9a7@kernel.org> <84787af3-aa5e-4202-8578-7a9f14283d87@kernel.org> In-Reply-To: <84787af3-aa5e-4202-8578-7a9f14283d87@kernel.org> From: Mina Almasry Date: Sun, 17 Dec 2023 00:14:59 -0800 Message-ID: Subject: Re: [RFC PATCH net-next v1 2/4] net: introduce abstraction for network memory To: David Ahern Cc: Jakub Kicinski , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Greg Kroah-Hartman , "Rafael J. Wysocki" , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Michael Chan , "David S. Miller" , Eric Dumazet , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Jeroen de Borst , Praveen Kaligineedi , Shailend Chand , Yisen Zhuang , Salil Mehta , Jesse Brandeburg , Tony Nguyen , Thomas Petazzoni , Marcin Wojtas , Russell King , Sunil Goutham , Geetha sowjanya , Subbaraya Sundeep , hariprasad , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Saeed Mahameed , Leon Romanovsky , Horatiu Vultur , UNGLinuxDriver@microchip.com, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Jassi Brar , Ilias Apalodimas , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Siddharth Vadapalli , Ravi Gunasekaran , Roger Quadros , Jiawen Wu , Mengyuan Lou , Ronak Doshi , VMware PV-Drivers Reviewers , Ryder Lee , Shayne Chen , Kalle Valo , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Stefan Hajnoczi , Stefano Garzarella , Shuah Khan , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Jason Gunthorpe , Shakeel Butt , Yunsheng Lin , Willem de Bruijn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Dec 16, 2023 at 5:45=E2=80=AFPM David Ahern wr= ote: > > On 12/16/23 2:10 PM, Mina Almasry wrote: > > On Fri, Dec 15, 2023 at 6:52=E2=80=AFPM Jakub Kicinski wrote: > >> > >> On Wed, 13 Dec 2023 18:05:25 -0800 Mina Almasry wrote: > >>> +struct netmem { > >>> + union { > >>> + struct page page; > >>> + > >>> + /* Stub to prevent compiler implicitly converting from = page* > >>> + * to netmem_t* and vice versa. > >>> + * > >>> + * Other memory type(s) net stack would like to support > >>> + * can be added to this union. > >>> + */ > >>> + void *addr; > >>> + }; > >>> +}; > >> > >> My mind went to something like: > >> > >> typedef unsigned long __bitwise netmem_ref; > >> > >> instead. struct netmem does not exist, it's a handle which has > >> to be converted to a real type using a helper. > > > > Sure thing I can do that. Is it better to do something like: > > > > struct netmem_ref; > > > > like in this patch: > > > > https://lore.kernel.org/linux-mm/20221108194139.57604-1-torvalds@linux-= foundation.org/ > > > > Asking because checkpatch tells me not to add typedefs to the kernel, > > but checkpatch can be ignored if you think it's OK. > > > > Also with this approach I can't use container_of and I need to do a > > cast, I assume that's fine. > > > > Isn't that the whole point of this set - to introduce a new data type > and avoid casts? My understanding here the requirements from Jason are: 1. Never pass a non-page to an mm api. 2. If a mangle a pointer to indicate it's not a page, then I must not call it mm's struct page*, I must add a new type. I think both requirements are met regardless of whether netmem_to_page() is implemented using union/container_of or straight casts. folios implemented something similar being unioned with struct page to avoid casts. I honestly could go either way on this. The union provides some self documenting code and avoids casts. The implementation without the union obfuscates the type and makes it much more opaque. I finished addressing the rest of the comments and I have this series and the next devmem TCP series ready to go, so I fired v2 of this patchset. If one feels strongly about this let me know and I will re-spin. --=20 Thanks, Mina