Received: by 2002:a05:7412:8d08:b0:f9:2d0a:d759 with SMTP id bj8csp25467rdb; Sun, 17 Dec 2023 00:10:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcKw+f74QO4me7vrJdkfE2UBQEyS+YvrDkZ4ULBtlFhnvRb6w4y+4m3kINRuUlLiAqSSNd X-Received: by 2002:a50:cdca:0:b0:551:c4ac:6f2 with SMTP id h10-20020a50cdca000000b00551c4ac06f2mr4461386edj.42.1702800636339; Sun, 17 Dec 2023 00:10:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702800636; cv=none; d=google.com; s=arc-20160816; b=hUQeiw3zW9MlLIVC1fNUgX1v11degdiepQs4v3rw7tCMhJCOAzS3GDN5NQuByBci1h LOQ0d53pj4BNGS+QW3H/VpvZLAw1Dqo1aBS3XXxdmlCJ3yNBonq9KFXRJkPBPN+neFaU iv1kxwZ06HpIMTefsIGejVIE0bgB+EQxBSWhUZxTFkrHnoVXIb491OHyam4cYiQ5CRtN CMwdfk4MhDfDAO4nDiTUHtjFIiFk8V0q9Ab3BuM0EV2NxDRZ8Z7JZXDBU+GC2VGssB8e WfJNOvR3egoXiZ2oQpLt7EZOLKYtsqpqjyOsHocNFDlHhRPoixnwCicxtuDuqfhdHpMW /caw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=cjUSNe+bIsKYLrf1i8KK45ElvyWQbESYTUWNmf5dvpE=; fh=5+YZn3qid70ipf23l+1Skq9YU3IOegijAT5j4LrIkeM=; b=jAwUv+0WVv82TcOKLxCbRXYXNg/sqX669NBU/RMRNyDBWGsPQ7cmoToyJinh7hF8m5 y21Oo/9GNzvpe4WaQQTH+4htyFUEbHrr+4Akg8rA0GAcTtWEigvKi8DCRBhyOe48BF+V 5ywezfXBlS6osaeh4bX/LWGa6oHxPSw+/i8MPTGAcszRBIRyD643J/dGVd6TZgwmmyGd nYfC/FkDbT+vYjTfuLINggBLu6nTtqF/B/ZVktsNbNwUSQLGLDk22RuzyIrRhtlrHzGG hT6cHH8QVqrfwVBWrOnrH9kcjY9OH79gzAvpKUr+W4ufOm1xwl/QddeCqYEh/1INNKwU MOUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XROIEh4b; spf=pass (google.com: domain of linux-kernel+bounces-2502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2502-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 f19-20020a0564021e9300b0054c67c19369si9089167edf.164.2023.12.17.00.10.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 00:10:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2502-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=XROIEh4b; spf=pass (google.com: domain of linux-kernel+bounces-2502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2502-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 1ADF21F21FB4 for ; Sun, 17 Dec 2023 08:10:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 998C06FA6; Sun, 17 Dec 2023 08:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XROIEh4b" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 6F63B3FD4 for ; Sun, 17 Dec 2023 08:09:23 +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=flex--almasrymina.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5d42c43d8daso19668647b3.0 for ; Sun, 17 Dec 2023 00:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702800562; x=1703405362; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cjUSNe+bIsKYLrf1i8KK45ElvyWQbESYTUWNmf5dvpE=; b=XROIEh4bGgdrndOSm9jbSvu/lJDWD00B4DbDZByFo/MxPcJ85or4uECojjFSkMK4ZD ibVrYGUmRtje4D7dI528n7428RlpqK066moAEOtiMdn20OC4eFceePYIoiG8BqQMf5cr FJwF3nPtM+Cqur/gtLfMWqC40KodwQvJNLxRMTXwL+XWLJbTBO6BS+x5dxAWztrlbMjZ 8q80Bzgbl9q2SWhT8i8mLL2HFbQhXooEY114ApKFg3KEariBeItyEKxoNS8TCqeE8hER m+a3KO8Xvi6+8xI6fg4KcsnZb0ixBdNFYjhsgtz6lRco5LuHWPOhfRvc+SpihSp5HlSO zQdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702800562; x=1703405362; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cjUSNe+bIsKYLrf1i8KK45ElvyWQbESYTUWNmf5dvpE=; b=A1+vhWgIbSLRZmM1SBIdAKBg6fidSwwdTuUNSys/nFOfSagM2cuaLPCAz7eiOsjM7o RJHMvathAncLFvJJZrOTsjdGFCmmnZgMsINEM4+dUlekOKydSgltw0soOiuugdYyVm1R ZvMqhSRcAQj+73ibJKNOCSYwbNYv9yEr6C1RyasTumHyok/NAPd4DxXvAo04wz2GzxmP BoiwHDebpa9XCWvISSQFsfNenZmPbSyyujygBHpjAk6TV6f1xfs+jW/a1z3Pt5Y4+Dps E3Q82NqUbLkIQqn8LA6VLWotncc0p1wCs1DW+PFYIv79QWbuoSsJwSnopDm5QWjRcvuH oHzQ== X-Gm-Message-State: AOJu0YxbLfHLsLUpF7o7AmSWYmCkucm00RTDnXftAb6guSsim+UsOYBj ALpx0sW+BcxFK7BpuHxlZiUlAp29pBvhH/7LwvWpXuJeGFIn38AEt4VYOhZnAeygD5gPeVl4kT8 zVGMXf+I17nGNHjFd/NPNBrXs5N+W3gGBiYEbt/PQqQj//oWkUOtWDtS60WjhkmP0eGry05moA4 X1q9MHK1g= X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2c4:200:3eb4:e132:f78a:5ba9]) (user=almasrymina job=sendgmr) by 2002:a05:690c:2c83:b0:5e5:d445:d9a9 with SMTP id ep3-20020a05690c2c8300b005e5d445d9a9mr237216ywb.3.1702800562290; Sun, 17 Dec 2023 00:09:22 -0800 (PST) Date: Sun, 17 Dec 2023 00:09:10 -0800 In-Reply-To: <20231217080913.2025973-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231217080913.2025973-1-almasrymina@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231217080913.2025973-3-almasrymina@google.com> Subject: [PATCH net-next v2 2/3] net: introduce abstraction for network memory From: Mina Almasry To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux.dev Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Stefan Hajnoczi , Stefano Garzarella , Jason Gunthorpe , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Shakeel Butt , Yunsheng Lin , Willem de Bruijn Content-Type: text/plain; charset="UTF-8" Add the netmem_t type, an abstraction for network memory. To add support for new memory types to the net stack, we must first abstract the current memory type from the net stack. Currently parts of the net stack use struct page directly: - page_pool - drivers - skb_frag_t Originally the plan was to reuse struct page* for the new memory types, and to set the LSB on the page* to indicate it's not really a page. However, for compiler type checking we need to introduce a new type. netmem_t is introduced to abstract the underlying memory type. Currently it's a no-op abstraction that is always a struct page underneath. In parallel there is an undergoing effort to add support for devmem to the net stack: https://lore.kernel.org/netdev/20231208005250.2910004-1-almasrymina@google.com/ Signed-off-by: Mina Almasry --- v2: - Use container_of instead of a type cast (David). --- include/net/netmem.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 include/net/netmem.h diff --git a/include/net/netmem.h b/include/net/netmem.h new file mode 100644 index 000000000000..b60b00216704 --- /dev/null +++ b/include/net/netmem.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * netmem.h + * Author: Mina Almasry + * Copyright (C) 2023 Google LLC + */ + +#ifndef _NET_NETMEM_H +#define _NET_NETMEM_H + +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; + }; +}; + +static inline struct page *netmem_to_page(struct netmem *netmem) +{ + return &netmem->page; +} + +static inline struct netmem *page_to_netmem(struct page *page) +{ + return container_of(page, struct netmem, page); +} + +#endif /* _NET_NETMEM_H */ -- 2.43.0.472.g3155946c3a-goog