Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp147457rdh; Mon, 18 Dec 2023 14:39:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+53cr3s+txAnu+1UXOdTkn1yvHEug9ouoTSFk7L/78s164lqYFpypQZ4ENR26m5aN6jCY X-Received: by 2002:a05:622a:1a8b:b0:423:839d:9fc5 with SMTP id s11-20020a05622a1a8b00b00423839d9fc5mr24947330qtc.56.1702939170534; Mon, 18 Dec 2023 14:39:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702939170; cv=none; d=google.com; s=arc-20160816; b=P4t7SQOZduCIKT8EC3Shonav/TXxxeNJeDuD+ku727ZBCZiQ/ZKrXtFmtEtMQFl7hP kSLPc3zfYgeOzrczpesBEHhCWhcoLJwFRK7DWXZLD1kGonYwUYsj46HJTzLp2UUK01NO DOTbQpBKtZS5DHGkxotxrngbFQROAWI6GdcEq9jTWW9oTpjup30QhODTv03Ou/x75xm2 4gsc5OT179YsZwBMVZdjMJpibpgc2HKFf9mzyHbkRv6WiPGZPd64gkEJBiyaNSJcrdu5 /fVKhy62ZpoqeO2f2/6LrMDet+36j8KJry9enPjXAnHFdwQdy6vWjPQ4jDgBxN6nhQh0 qAXw== 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=CvjmfRNkX4sQk84Kdm8DrzXfsoFjryBSCdk41+TbjH4=; fh=Y1UvJuagmpoPtxgiqVUZpwbsu5mhkfqF8R1iQBq4fkw=; b=iVAAK9pwJFonwEYV0yu4wTuo/wYIzbcjbs55PuXhworp0XQiUFRKhHNvtjiJky6sJa gET6sdRDqr539gwKxQ9wYjlWj+X76DhxxiiU0jfN8ju5YEJg7EXm4+MsD/ITWVpCAzDM VFWnbhZjBRRIyiQt2BylYlT+nZXrDEtHVYJFWrZOuNEUbWQe4uo8zY6k32oUq9FXyieo ENjxwUza4HSHy/7Neh51wB8MCpmWJk7+lO+R7RILJUvY+7uik9Ctz3qmllsbeM6A5BEX Zxc1Qn/Ze619ByKqXk5y8DZ3B/T2pqQtCIUGPz3rSz5DQVF4Q1x18b7qb4+mUNnQnvqY TPsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=I3uUzqBp; spf=pass (google.com: domain of linux-kernel+bounces-4451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4451-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. [147.75.199.223]) by mx.google.com with ESMTPS id z10-20020ac86b8a000000b004254636976csi23424538qts.604.2023.12.18.14.39.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 14:39:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=I3uUzqBp; spf=pass (google.com: domain of linux-kernel+bounces-4451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4451-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 333A01C22D65 for ; Mon, 18 Dec 2023 22:39:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8756C740B0; Mon, 18 Dec 2023 22:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I3uUzqBp" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 350CF74094 for ; Mon, 18 Dec 2023 22:39: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-f49.google.com with SMTP id 4fb4d7f45d1cf-55322dbac2fso2363202a12.0 for ; Mon, 18 Dec 2023 14:39:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702939154; x=1703543954; 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=CvjmfRNkX4sQk84Kdm8DrzXfsoFjryBSCdk41+TbjH4=; b=I3uUzqBpXN9vkAAFlomaQRNFV8b4LNomjX0Lt1uKTJvLgcxrQzXvY/maQ8XfhRZp9G zP4C9f1oJkUiy+lgm7d/5oy7pQSaEeOjv1Yy7YdRaPhKHvepKwxLUKtu5s56UwGpDkKK /2YpB9lE7U9auU/z5lVcv+Iiq/HC9/MXE2EF2wzGPpItkCSJtCjE2m9emhaqQXzFFlNL iIvq1aE3Ig00EKAvHUsRXVg94lFadXcxJUiDQv9lvmpSU+hpgkgRM5fbL1TENRuuv+bd LefD9JIzhxMWcbi0Z7LY8tx8xJ5HYkeDfPqn+CnRds9y238zzu4rV0ueU1CtlQGJXYUH 3ytg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702939154; x=1703543954; 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=CvjmfRNkX4sQk84Kdm8DrzXfsoFjryBSCdk41+TbjH4=; b=k3QaFbSCg0/I50sOnEGH8imSJTZl8cWrM4A5R+2bz5SEYyml2uF5/znZLwsXgxox3r jDsITPFKojw6Y3kQ8Jzb3GEVlLyy5WyRbQzcEMJzTR1hbGaT8pilDUCHKBxA85Wtt7hx rPXzP/7rDfdnWUZKvLFVSs/1lmnBjcy4yMV5URE9fJiqFh9SE5+jKzEP3E2tsBvfcI3d 3XkL3sA5BlpNBdj4RPUiQm8fjST8G6N4YQtWc1r2Aqz2szNla+gko6NfmZMIKE2TEfqo OGk4oXahMKp2bpw3yefwJeiNs2w4aflCnRupKkq9JiQ+WDhv92tDe1oFL3YRMyzyTs5p cJ4w== X-Gm-Message-State: AOJu0YyAvwbz3ToseHgTDCsjgxNLHQvhGweN3PazqGvYVgDwlT2rnWXy DYBs+LkQJ0rlbGXQ26MkOrgZti6J4SGecSpAqvRYKg== X-Received: by 2002:a17:906:1044:b0:a1f:7f7e:9200 with SMTP id j4-20020a170906104400b00a1f7f7e9200mr8485209ejj.8.1702939154243; Mon, 18 Dec 2023 14:39:14 -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> <20231218140645.461169a7@kernel.org> In-Reply-To: <20231218140645.461169a7@kernel.org> From: Mina Almasry Date: Mon, 18 Dec 2023 14:38:58 -0800 Message-ID: Subject: Re: [RFC PATCH net-next v1 2/4] net: introduce abstraction for network memory To: Jakub Kicinski Cc: David Ahern , 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 Mon, Dec 18, 2023 at 2:06=E2=80=AFPM Jakub Kicinski wr= ote: > > On Sun, 17 Dec 2023 00:14:59 -0800 Mina Almasry wrote: > > > > 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@li= nux-foundation.org/ > > > > > > > > Asking because checkpatch tells me not to add typedefs to the kerne= l, > > > > 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? > > I don't see how we can avoid casts if the type of the referenced object > is encoded on the low bits of the pointer. If we had a separate member > we could so something like: > > struct netmem_ref { > enum netmem_type type; > union { > struct page *p; > struct page_pool_iov *pi; > }; > }; > > barring crazy things with endian-aware bitfields, we need at least one > cast. > > > 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. > > Folios overlay a real struct page. It's completely different. > > > I honestly could go either way on this. The union > > provides some self documenting code and avoids casts. > > Maybe you guys know some trick to mask out the bottom bit :S > > > The implementation without the union obfuscates the type and makes it m= uch > > more opaque. > > Some would say that that's the damn point of the wrapping.. > > You don't want non-core code futzing with the inside of the struct. > > > 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. > > You didn't address my feedback :| > > struct netmem which contains struct page by value is almost as bad > as passing around pretend struct page pointers. Sorry about that. I misread your original request as 'here is something else you can do if you want', not something that you feel is critical. Honestly I missed the subtlety and the approaches seemed roughly equivalent to me. I will respin after the 24hr cooldown. --=20 Thanks, Mina