Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp133883rdh; Mon, 18 Dec 2023 14:07:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWubbwE7s3xcQzZem8jgOcZF7uZcyogo3GYIasc53oz4bh+ASF0nK7UIkOmCjiDTJwvO3A X-Received: by 2002:a05:6a20:160a:b0:194:9872:e351 with SMTP id l10-20020a056a20160a00b001949872e351mr388787pzj.21.1702937224808; Mon, 18 Dec 2023 14:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702937224; cv=none; d=google.com; s=arc-20160816; b=TM6yOSXePR/J47npK4u0JXAkSV+ejpqZne6xrQihGi7PJGq/EhbErgsTGcvKVAgwMb 2DRDOH/SzqNkyei9of0lbBJTLXPtj53qIJo8/xinsEkBuCyBK6k/xtEzqAlv71rWo95B Ny0V46I/hzeLE5C1WdT4wVTNl717rHOMScZDB/6/xGlebd0x6i2k2JRVC3E/xguIZrQa L3shajXRYGCZaMY1JaMlyw3Rya7DupxgXcAgdXVgekOJRLV3f61QEGDA2FmW7s2VnN44 6gE8umYynmP90tp3WuIvECqCGZIaYYDwYbiM2f0Qo/xmzyE4DsAyHH99hV2468kl1PEE u7Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=qiPhbU9yBxhGnBq0xEFiFOWFf3ak8/EBMxUhLP62yZ0=; fh=ZAYnHevk+OujC4QfuOKls9fvnPGHVoT6YCp2eJrqTGM=; b=v+PLJwsvC5EjCLANEMPMYX5N90kBg2W2G4pAuJhKPf1bLG98EgtWXRzEU/5rz4QKHP s0BJW0D+BQH9qkjRtjbQnA4ER5axrOPc3zMYmuDfFAG4zU8v8OHuPNXmHhiCuD8OvdYe btNsxlxhAuMT0OcplKc2llAZrGHQVSS3mWadIViHkxP7PFkFW8T1PokgXzoP6p23duWi A5iLReW9jxKwanX+sGlB+yJXHXlt3bDIVzIW19L3llKbE9PucSGwjjTVtCWxraj30NZW 8FMysp8iXLmuaKTsmXm7GYN6BswobgH/85iPBlBPYWQsWMh8BUVLaxiJrvzzG8Gvc6M+ 5A3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n7H9+Sby; spf=pass (google.com: domain of linux-kernel+bounces-4438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j26-20020a63fc1a000000b005c624eec079si12154180pgi.724.2023.12.18.14.07.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 14:07:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n7H9+Sby; spf=pass (google.com: domain of linux-kernel+bounces-4438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 72E48284344 for ; Mon, 18 Dec 2023 22:07:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1A0174E11; Mon, 18 Dec 2023 22:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n7H9+Sby" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C16A4740A3; Mon, 18 Dec 2023 22:06:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24844C433C8; Mon, 18 Dec 2023 22:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702937210; bh=JRDQObUf/WROaXC2TkDgUYKUAbVrKHE0oead3omIraI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=n7H9+SbylKmNBllkPLk67C+s3qBTkN5kg5IPuij3RSIzvCYvgw7DQlXuvaxgWwfe5 4bWmsjcsK/3oJqHmJyx5Bwf5Z4Wa6uI7UXg/oks+Rs7b8lz8uoXraQdKPGZcptPa0c YKdYevBe3Mlqs0xnIhqUGvL0ttlgOH+VAuzZWuvI/N88D7qli3aAOq1bS57nwyB3dU 40bHJ5lHG2gn1WCXcr8kRC153hBcvSC9WEWaEpGFa1wrS+GtvSmMs6PgULVfu5NcVh fvhX63egnA2LysXBZEoIheB4FzM5Yd1AKC2WYUrIzTGDMmZfmAIhETuKuHDKFeEboT fWR115dNc4f4w== Date: Mon, 18 Dec 2023 14:06:45 -0800 From: Jakub Kicinski To: Mina Almasry 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 , Christian =?UTF-8?B?S8O2bmln?= , 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 Subject: Re: [RFC PATCH net-next v1 2/4] net: introduce abstraction for network memory Message-ID: <20231218140645.461169a7@kernel.org> In-Reply-To: References: <20231214020530.2267499-1-almasrymina@google.com> <20231214020530.2267499-3-almasrymina@google.com> <20231215185159.7bada9a7@kernel.org> <84787af3-aa5e-4202-8578-7a9f14283d87@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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@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? 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 much > 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.