Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7979185rdb; Thu, 4 Jan 2024 14:16:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkHFNIKZjboX0uKnVc1WZdjnE7GuLXhGUdcVoAM9RtqGMWZmlkyClUdsgOlqA3AUOjRBBd X-Received: by 2002:a50:d659:0:b0:556:d08d:aef8 with SMTP id c25-20020a50d659000000b00556d08daef8mr1172207edj.12.1704406586220; Thu, 04 Jan 2024 14:16:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704406586; cv=none; d=google.com; s=arc-20160816; b=JNzyC7zfIm3do92mJ7vtjYiytnTTNUF9nqd2HRQhsbJZ12jIWWgiqcYqz4eknT1ODK KfmddJ8oDusoFrMfjBDNa3DsKIJKMh03asbUWBQk4ckMi7E3Kq9CUwskUkwIjy4k4m7m aMmPZ+HAI9SwFeCBikP1lM1WujcsGtWeBQ94yLB+OrhzZ2zpO7WZn/VrUk+R9TMMSqQg OjJt5gxc8kXeyMKvSu5mVZI+ezTEabCaWQ9QQQnxhRr83I6hA2sVaqxMisR8cg/+xQnj HqBlBCVIIyvmUoIslvFutp+RnMhgyRfE6d9eDJKhtCJMwvLez27c6jrsHpiemJMcLsqP tsuA== 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=YmEwJraJ4e4jT15EacqQbPjlb9M9wODOsTgFHucU8Ww=; fh=qzdgpnK0+tZryYrYIjLlwk0esLnl7zlaaPpBC3QdOHk=; b=s1sltvsvtld5bthYZvSnhvV/B724C9Ce9eOoU1YCQy7g+7YxuApBM30LL3Zt5QK/LW ZWQzI/bXPGOlT4riDcotpBDrc132wMHea6aNDkslw4riVo3wcyyKFiNdFZ53FxoNNyNe Tckc71k+xNZ8cch9/mxRL3ZYoRcTG15YpOLYSFk2fR1Dw5B6RYmIJifhTt3+1/5Hxcce 4CwO2OBcxr52cg+8B5f3Z5Oi3u3B2ll+ysi+OX2yicPFxC3KdOnBvPPLkl7yGR87PTfO n/ziPXr/Fggn5ycKzbOY43rGJpclMNEQHIy0H1NPyDICstUBMn+p5hXMadIBRvSuTQj8 myUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OKRFvuxe; spf=pass (google.com: domain of linux-kernel+bounces-17278-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17278-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u10-20020a50d50a000000b005572ae1f87bsi36556edi.243.2024.01.04.14.16.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 14:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17278-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OKRFvuxe; spf=pass (google.com: domain of linux-kernel+bounces-17278-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17278-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F29541F226C9 for ; Thu, 4 Jan 2024 22:16:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E94102CCB3; Thu, 4 Jan 2024 22:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OKRFvuxe" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 A09342C850 for ; Thu, 4 Jan 2024 22:16:08 +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-f54.google.com with SMTP id 4fb4d7f45d1cf-5572a9b3420so39160a12.1 for ; Thu, 04 Jan 2024 14:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704406567; x=1705011367; 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=YmEwJraJ4e4jT15EacqQbPjlb9M9wODOsTgFHucU8Ww=; b=OKRFvuxev/B8KH1SB0zFaMgZfxNpZdN83YqCV2JkSxdjxUbmr8443yl7d7lRNFvjSc j0GrX/9tA7q74I/Ht5Ad/W8r/TXXxFYhdZ9FL0AVMTqs+owieKHrE2eG8YtU3DTzsjnA wnfz+A/TMO5VCICM3HOH+iABixwj7hJxSRhSiodVAjqaqpZbdUOrAx/p6oLasfgTGKnt cj7xb0nSmvrQ5624XeJLWBZ1wkLXXPPKXPMkvjYzxdmQ/l2PB6IBNYsyy0595+Y49h7R iQXGMy5UAlWaztYy3svd4r3TLGGFkORiN6JZBL1X7mwVwWJjil1dJkPoPEjRKAMgMGdV glCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704406567; x=1705011367; 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=YmEwJraJ4e4jT15EacqQbPjlb9M9wODOsTgFHucU8Ww=; b=tZwopXktYZ+TerKAeHsC1h1kQVFcMaNsLpodLODaoSzekGBPxVaZYCuOtxuAEglt4Q NPUNY+avEU2gizvIk9/BiFqw6nv1gdQ5w8s8EjF9z7t7Fzy0LrcavvODPJUo3rbzZ9Tc +W0lRWjXuFb8LldGeJDhrxmVd+jsOCIcDvRqh6XpmJjI10QY6NRqDDBg2EsFZ5Dq51cn 0xiNoj5ZXEZ5bFdt7WZzBXG9KG9qzdh6yXgVUYJwL13Gx6tZF/K9aaSjd4ytt2GuPmJg iiCvA27yFPqsQNEmSZ3m8lMA792tI/zWVyN4BNNDOZcny2odnSaO5R+TSpzR30CXI+Gc 8a8g== X-Gm-Message-State: AOJu0YyNcyuwSkAP2nkthaNvUmngp5oi4lkmeLxNU0YttyEzb3KHL3E6 VsWIirKPAD47Z8l7EeJF1XPnoiZBcoh34XzNJ4GLLBUvYgAh X-Received: by 2002:a17:906:d154:b0:a28:6621:5801 with SMTP id br20-20020a170906d15400b00a2866215801mr1226462ejb.19.1704406566797; Thu, 04 Jan 2024 14:16:06 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231220214505.2303297-1-almasrymina@google.com> <20231220214505.2303297-3-almasrymina@google.com> <20231221232343.qogdsoavt7z45dfc@google.com> <20240104134424.399fee0a@kernel.org> In-Reply-To: <20240104134424.399fee0a@kernel.org> From: Mina Almasry Date: Thu, 4 Jan 2024 14:15:52 -0800 Message-ID: Subject: Re: [PATCH net-next v3 2/3] net: introduce abstraction for network memory To: Jakub Kicinski Cc: Shakeel Butt , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux.dev, "David S. Miller" , Eric Dumazet , Paolo Abeni , Stefan Hajnoczi , Stefano Garzarella , David Howells , Jason Gunthorpe , =?UTF-8?Q?Christian_K=C3=B6nig?= , Yunsheng Lin , Willem de Bruijn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 4, 2024 at 1:44=E2=80=AFPM Jakub Kicinski wro= te: > > On Thu, 21 Dec 2023 15:44:22 -0800 Mina Almasry wrote: > > The warning is like so: > > > > ./include/net/page_pool/helpers.h: In function =E2=80=98page_pool_alloc= =E2=80=99: > > ./include/linux/stddef.h:8:14: warning: returning =E2=80=98void *=E2=80= =99 from a > > function with return type =E2=80=98netmem_ref=E2=80=99 {aka =E2=80=98lo= ng unsigned int=E2=80=99} makes > > integer from pointer without a cast [-Wint-conversion] > > 8 | #define NULL ((void *)0) > > | ^ > > ./include/net/page_pool/helpers.h:132:24: note: in expansion of macro > > =E2=80=98NULL=E2=80=99 > > 132 | return NULL; > > | ^~~~ > > > > And happens in all the code where: > > > > netmem_ref func() > > { > > return NULL; > > } > > > > It's fixable by changing the return to `return (netmem_ref NULL);` or > > `return 0;`, but I feel like netmem_ref should be some type which > > allows a cast from NULL implicitly. > > Why do you think we should be able to cast NULL implicitly? > netmem_ref is a handle, it could possibly be some form of > an ID in the future, rather than a pointer. Or have more low > bits stolen for specific use cases. > > unsigned long, and returning 0 as "no handle" makes perfect sense to me. > > Note that 0 is a special case, bitwise types are allowed to convert > to 0/bool and 0 is implicitly allowed to become a bitwise type. > This will pass without a warning: > > typedef unsigned long __bitwise netmem_ref; > > netmem_ref some_code(netmem_ref ref) > { > // direct test is fine > if (!ref) > // 0 "upgrades" without casts > return 0; > // 1 does not, we need __force > return (__force netmem_ref)1 | ref; > } > > The __bitwise annotation will make catching people trying > to cast to struct page * trivial. > > You seem to be trying hard to make struct netmem a thing. > Perhaps you have a reason I'm not getting? There are a number of functions that return struct page* today that I convert to return struct netmem* later in the child devmem series, one example is something like: struct page *page_pool_alloc(...); // returns NULL on failure. becomes: struct netmem *page_pool_alloc(...); // also returns NULL on failure. rather than, netmem_ref page_pool_alloc(...); // returns 0 on failure. I guess in my mind having NULL be castable to the new type makes it so that I can avoid the additional code churn of converting a bunch of `return NULL;` to `return 0;`, and maybe the transition from page pointers to netmem pointers can be more easily done if they're both compatible pointer types. But that is not any huge blocker or critical point in my mind, I just thought this approach is preferred. If conversion to unsigned long makes more sense to you, I'll respin this like that and do the `NULL -> 0` conversion everywhere as needed. --=20 Thanks, Mina