From nobody Wed Jan 15 01:13:30 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 C251B1E9B35 for ; Wed, 11 Dec 2024 21:20:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952038; cv=none; b=ObOHR0PJqSvDE0EH8n+9uUpR+xP3UJ+P3L1lqhR8CZ88JHUVLZZl+eHdRBvnfLlykyXnkkhEdn46/MA9GCrbLY5XlZ/FYpQkfT3GbcmYGNh6nef/RMpgjCS+bxuVEUo0bfrbhq8dyjnmmxAYA4jnMQgz1pNhlKt9Caduhq4cRYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952038; c=relaxed/simple; bh=inYtJTadn/ilQufeg2hRjROOpb6WnuRJ/R3Eo2kT9Ak=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IAwZ9odfhGHPzN9zZ7Hx4f0V9j63pBTX4IoW06Rbaa3n1IbYVJoeIYQL1+lo7Sy3vT8itTOqve5EGwrQLloDnPnwDSR8r/DXBz4n+0ISM5vCQ7m0uRhNF2oFIvifCEC6ezh7RsynaIN/vC3ye/shlSJGVMCp8NOlTgB59OPdnI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lUavxQ9e; arc=none smtp.client-ip=209.85.216.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lUavxQ9e" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef91d5c863so4398424a91.2 for ; Wed, 11 Dec 2024 13:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733952036; x=1734556836; 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=rD4fHb5o8v+27TSL8zHXq3Z19Qh3ytPkt3LCpxEoKxE=; b=lUavxQ9eRMEmBsI3lEvBBfmHbFKLjv9u0oR1LJycr9qZR/4l+FLLOTEzK5nkeeDPoX WmuXZRRrBR84rXRgeqde4QdYXcvSLGAtKNqpBQJ7dAM/JMeaY2Cl8aRtavgFpKc84nK2 mEeEGWCX60SkfJLqBnENNJSq1R0wnTp/QbZe3Y5o8QGrRxu8JcUE4I90lnRp6I+kLz/B nNfGfNYLHYuPiaZmFl/FCi/aghtfdHb/EseZT2ZZGQF4IcfVhww6/6ZqPjd7LYZJGLQ5 YeoUHSPdLYB7gSMCBVxOa8lveYRLaHTV9hoGiGuml6XcQc0udU6g6VwYN6tJ5PtwQEOm 1JOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733952036; x=1734556836; 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=rD4fHb5o8v+27TSL8zHXq3Z19Qh3ytPkt3LCpxEoKxE=; b=PU7GMkdMZZao6Y97h9opThpI5nrUj/SV7Cua+uFSgdTAylWsiXXmYngq5O3S/c8NIM V2MFarQwS6F4fA99GCclM2q8Tz704wfpB7ylz6pkztsc1dhcgGU8hs9Zk0R6fMc5gGdU ULp8t/TCf8Z6K1cjZj1mou2NT+ifBvyhvPuGv3n2GK+7wMWbU6s2lWpBFGxUUIm1iRFB EMdY3dfyImOL7iR/o/ojf+S94Syv4rSf8GHprMSQ5Ld9fxbzTjoNJP6XVg9TflbjgKhJ wodgQbNI2LXeSh4bIGUg7OgQwcTsloqXcdjBOz9QPz37bBXJpgTQZNNWwo68TijRxS2Y mD3w== X-Forwarded-Encrypted: i=1; AJvYcCWnWZy1UWP6iBsJLvv9+859CPV9744Cx26eELwVNFdkq/GesY2wHBH4toImcg+1XxPY8fY69f1L9ierbh8=@vger.kernel.org X-Gm-Message-State: AOJu0YxxCVo/41KB/bS+EKsSsRfwk3SETprSK1EYJlr8X0QIXj6KGCaQ rvFUumzBmm9oyXygV6l8BAZ6S3FCy0Ex9g+ECpfn7cuQgOxfe8nerIapzHlXKYTTastbDOZ/eZB P9W6vAm9baD2mQj105n5HiA== X-Google-Smtp-Source: AGHT+IHYrU+SD7vPYOEQ3idsKub4yW3CEQ29DrUylYyi6L34qN5kVr/+aOtP9HfJhrQ9YokFfMxe3gTS5yVuZy+J1w== X-Received: from pjg16.prod.google.com ([2002:a17:90b:3f50:b0:2ea:4a74:ac2]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:510c:b0:2ee:e158:125b with SMTP id 98e67ed59e1d1-2f128032774mr5992885a91.26.1733952036117; Wed, 11 Dec 2024 13:20:36 -0800 (PST) Date: Wed, 11 Dec 2024 21:20:28 +0000 In-Reply-To: <20241211212033.1684197-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: <20241211212033.1684197-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211212033.1684197-2-almasrymina@google.com> Subject: [PATCH net-next v4 1/5] net: page_pool: rename page_pool_alloc_netmem to *_netmems From: Mina Almasry To: netdev@vger.kernel.org, Jakub Kicinski , Mina Almasry , Pavel Begunkov , Willem de Bruijn , Kaiyuan Zhang , Samiullah Khawaja , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jonathan Corbet , Jesper Dangaard Brouer , Ilias Apalodimas , Stanislav Fomichev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" page_pool_alloc_netmem (without an s) was the mirror of page_pool_alloc_pages (with an s), which was confusing. Rename to page_pool_alloc_netmems so it's the mirror of page_pool_alloc_pages. Signed-off-by: Mina Almasry Acked-by: Stanislav Fomichev --- include/net/page_pool/types.h | 2 +- net/core/page_pool.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index 1ea16b0e9c79..bd1170e16cff 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -242,7 +242,7 @@ struct page_pool { }; =20 struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp); -netmem_ref page_pool_alloc_netmem(struct page_pool *pool, gfp_t gfp); +netmem_ref page_pool_alloc_netmems(struct page_pool *pool, gfp_t gfp); struct page *page_pool_alloc_frag(struct page_pool *pool, unsigned int *of= fset, unsigned int size, gfp_t gfp); netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool, diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 4c85b77cfdac..3c0e19e13e64 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -574,7 +574,7 @@ static noinline netmem_ref __page_pool_alloc_pages_slow= (struct page_pool *pool, /* For using page_pool replace: alloc_pages() API calls, but provide * synchronization guarantee for allocation side. */ -netmem_ref page_pool_alloc_netmem(struct page_pool *pool, gfp_t gfp) +netmem_ref page_pool_alloc_netmems(struct page_pool *pool, gfp_t gfp) { netmem_ref netmem; =20 @@ -590,11 +590,11 @@ netmem_ref page_pool_alloc_netmem(struct page_pool *p= ool, gfp_t gfp) netmem =3D __page_pool_alloc_pages_slow(pool, gfp); return netmem; } -EXPORT_SYMBOL(page_pool_alloc_netmem); +EXPORT_SYMBOL(page_pool_alloc_netmems); =20 struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp) { - return netmem_to_page(page_pool_alloc_netmem(pool, gfp)); + return netmem_to_page(page_pool_alloc_netmems(pool, gfp)); } EXPORT_SYMBOL(page_pool_alloc_pages); ALLOW_ERROR_INJECTION(page_pool_alloc_pages, NULL); @@ -957,7 +957,7 @@ netmem_ref page_pool_alloc_frag_netmem(struct page_pool= *pool, } =20 if (!netmem) { - netmem =3D page_pool_alloc_netmem(pool, gfp); + netmem =3D page_pool_alloc_netmems(pool, gfp); if (unlikely(!netmem)) { pool->frag_page =3D 0; return 0; --=20 2.47.0.338.g60cca15819-goog From nobody Wed Jan 15 01:13:30 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 533F31EC4CD for ; Wed, 11 Dec 2024 21:20:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952039; cv=none; b=e8HgFdJ/2F8Lp+GSYJVI/2MjBpZ1lXVXu3oETeeU8OAoRuR2WcRKTQ6aQkrSTvMdV8/hQw7bXWaunuhd7392hHTZHn7AxkJK9XAgp5cVl704AVobPG6viMxYxtJAMYszQD2TUJkl8iYsA5+77Ez1Tbgj5AO1Bt4F2z/Mut4OymU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952039; c=relaxed/simple; bh=3m4AIfXRnx+qjxTq4vCGjNR0f9YLSWQ6fISqEIE0hIQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TK2ZTWN4XR8ZTm5XVY04FKaIUUyTmFyz+EelshG93dc7b64OHI8h/RlV/zcfdo3CmU6Qn7DVPiyqt5DKIzV3bJZXiicNB93FUDYR22ALX1NP+9G+Br1nOLK5NEMxRisBrb8GqvSsYZJr1gyY/hDB8JiXLgLVhb/ZpCOoojrjMtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zWqXVral; arc=none smtp.client-ip=209.85.216.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zWqXVral" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2eedd15c29eso6995800a91.3 for ; Wed, 11 Dec 2024 13:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733952038; x=1734556838; 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=mA8UqtPkSm6GQfXzmIjEK9H6u29hiGHFb3M2KsrojFY=; b=zWqXVralWRnHS3P3g7jzVp5qP+IUiFeFJlYBpRDXiwybvAV8q73zgWe1vVLbDgel9u P4R/a9dYsIkhiZlFvObIuTis2ZKcNXgzRwaL0m/P+jlsocxyAV87Q/ZV5m+1ZSaJIR4s yGGux1DgYQ2n9q6+F9JQY3q8SZVb1gyOvTqLnKS5NPXK3bE6LGsjb0d0+WVFKR+mPTNk DaKdFD1x88XTeIjR4JUP/Uc09r5rySZI1ErBNjLPWU72GYgO/8YwnZGVE43m/cOKYkrS ISJtPmeZOLqJQq2unVgrXC9cuFj9Rht4UTtEoof2CHTAhFRS/aAC/p3Whh6B/P+1K+ji r+JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733952038; x=1734556838; 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=mA8UqtPkSm6GQfXzmIjEK9H6u29hiGHFb3M2KsrojFY=; b=KbMh+p6b85ZXSzj0+FoV9d3YyxvQF0xJITLWTrgcfkifqXovtA46SwKJpxLFs4h05P ZxEm6zOxggnud8tFcIS6Zm55qSpdvAec8JziDj8o9EevA9j+xOhXgU+FlCqNhP0X7ZJB mZNBpKi16CC+ygG151pDORieImlylQ5qZv2zK0d3PocSerXHF1bZiBa9yZi2/EaBudYP TLiMrtTAXFlnfwsmZukCXpPv6VpgeYrY6lxCTJB3Bp8LPyVQsHd6VQBo8HIvkiJmYem+ EQXfHCB3Ow7z6ycC5LBGd37bJ8h2Gv17PGXe/9T9GEFkTmwtxP3CfOCCI7U6qY16oj0C FADA== X-Forwarded-Encrypted: i=1; AJvYcCVC0Nm88HhvVmeOg2gjwjDkcT9AnO5NF/KFufpglPuBUUKM6pUZmVxejrnfr33ARXoe4LHjHeZ2Eh8yb48=@vger.kernel.org X-Gm-Message-State: AOJu0YyUCJ9tvnErwr6rW5XgkUiyJv/gRFfLfrnBNxEpF4OODqQ1YVtn RLSLLaNxgaWWMTJFkypr1dzxiJxsM/aYkiM5tQxTCRt/fSEP3gnFULQOJYRzhv0oOL42t0EBIhL AOQNqOtuEvKbJwCSb5yY9SQ== X-Google-Smtp-Source: AGHT+IHN1brNhEqwbjgxRfUmN4rKMrV4z/3BVdYGbVJagf+4pWYCGKpL+e4/y4yE3uGb17nnzh1gc+fCR05mYSThTA== X-Received: from pjbli8.prod.google.com ([2002:a17:90b:48c8:b0:2ee:2761:b67a]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3802:b0:2ee:bc7b:9237 with SMTP id 98e67ed59e1d1-2f12803559bmr6406562a91.27.1733952037733; Wed, 11 Dec 2024 13:20:37 -0800 (PST) Date: Wed, 11 Dec 2024 21:20:29 +0000 In-Reply-To: <20241211212033.1684197-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: <20241211212033.1684197-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211212033.1684197-3-almasrymina@google.com> Subject: [PATCH net-next v4 2/5] net: page_pool: create page_pool_alloc_netmem From: Mina Almasry To: netdev@vger.kernel.org, Jakub Kicinski , Mina Almasry , Pavel Begunkov , Willem de Bruijn , Kaiyuan Zhang , Samiullah Khawaja , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jonathan Corbet , Jesper Dangaard Brouer , Ilias Apalodimas , Stanislav Fomichev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create page_pool_alloc_netmem to be the mirror of page_pool_alloc. This enables drivers that want currently use page_pool_alloc to transition to netmem by converting the call sites to page_pool_alloc_netmem. Signed-off-by: Mina Almasry Acked-by: Stanislav Fomichev --- include/net/page_pool/helpers.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helper= s.h index 26caa2c20912..95af7f0b029e 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -115,22 +115,22 @@ static inline struct page *page_pool_dev_alloc_frag(s= truct page_pool *pool, return page_pool_alloc_frag(pool, offset, size, gfp); } =20 -static inline struct page *page_pool_alloc(struct page_pool *pool, - unsigned int *offset, - unsigned int *size, gfp_t gfp) +static inline netmem_ref page_pool_alloc_netmem(struct page_pool *pool, + unsigned int *offset, + unsigned int *size, gfp_t gfp) { unsigned int max_size =3D PAGE_SIZE << pool->p.order; - struct page *page; + netmem_ref netmem; =20 if ((*size << 1) > max_size) { *size =3D max_size; *offset =3D 0; - return page_pool_alloc_pages(pool, gfp); + return page_pool_alloc_netmems(pool, gfp); } =20 - page =3D page_pool_alloc_frag(pool, offset, *size, gfp); - if (unlikely(!page)) - return NULL; + netmem =3D page_pool_alloc_frag_netmem(pool, offset, *size, gfp); + if (unlikely(!netmem)) + return 0; =20 /* There is very likely not enough space for another fragment, so append * the remaining size to the current fragment to avoid truesize @@ -141,7 +141,14 @@ static inline struct page *page_pool_alloc(struct page= _pool *pool, pool->frag_offset =3D max_size; } =20 - return page; + return netmem; +} + +static inline struct page *page_pool_alloc(struct page_pool *pool, + unsigned int *offset, + unsigned int *size, gfp_t gfp) +{ + return netmem_to_page(page_pool_alloc_netmem(pool, offset, size, gfp)); } =20 /** --=20 2.47.0.338.g60cca15819-goog From nobody Wed Jan 15 01:13:30 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 C4CEC1EC4D3 for ; Wed, 11 Dec 2024 21:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952042; cv=none; b=mibps5WCJIfHUkrCQMfs64tDyHq7UXYHvadxCKSWxROjmSmp90d4xfwan73YJqUcvXa3lzBxz+t2yLECSIAGxsVxl0YrHcGqHM0Nlona3vVX5jp1ZdSuGQEQbZJtoXlzG05NWKPJq/ey0Jvc6e7yXQ0wctNzVv0LyoIWODS591E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952042; c=relaxed/simple; bh=b90XShILltXC+LvOAJbN7AuVnXlBIVN+oi/xu7qF+1k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ml4+MQzj89UsSKnoey1gXMFfOY1bHVBi6+hY2vupYmy+bZN0QZ9Kb2pEYHXQG14Cgn7LUUA27pdIJmHRtD8ooidtZp2X8eX+6nAKZ8gxYSMlllPH01K7Wm9JGbzvjnchnutOmA1AMTGB+vPJjl3mwG8zpK9fF/YClMNI8fcrg9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=s/EpJ0W2; arc=none smtp.client-ip=209.85.215.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s/EpJ0W2" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-6c8f99fef10so7664682a12.3 for ; Wed, 11 Dec 2024 13:20:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733952039; x=1734556839; 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=VkkaSKdaGNTNNhg4FUb498GHLs5FUYHJ5RvbafI+ZxI=; b=s/EpJ0W2mNFEeUnNn1xZ1TFGvqlWTt/ynOuqMsa/43tYpPRomrTsZI31x+4idNcsGJ p0bfQKfAU4Jks7ctcnEorFsbfjD7ENbp6GkW/tYV7qaoD/KVLgdn4BMLw7WSQC9odt9G rzGnsb064jnAS+0u9wflHiiulXj+KkItTUSbc2qzehLmp2SWEndYdm5XnzhgwpdyyIHL vQxVKtflHywz7LBt4G7BaiwtlbSP8ZVJTBVeXRdykSt1YkS3X7cdmFvRzBu2dhCR4hm5 dVTIpL7Hx8V0qa/C77W+3YC+6iXKY90xUbkRqyXLqZnbffceXTyGZ8CC/QRonkIcZaRw IomA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733952039; x=1734556839; 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=VkkaSKdaGNTNNhg4FUb498GHLs5FUYHJ5RvbafI+ZxI=; b=smxsGSSBhGX0/8DOabo/3VOb2dYPfUk574dRPNdfNlv/zmXqgUS3bnNOQ34F5skvng 4/AJlXmHf9yFqmBmzyJFCWUYV4hGDUdTwda1OmMYn0UTdwUrOqs0hh/rXIysaOz/wxgX KW5cXWkCwlv3zsGYZnnDGURzXQ3PFmrWbrY3Ruy2pw1wwnv9OJfzSE1J6RFxVYiVJjOR ECaCop2znJyXZAfanVdtKKBICfPxUCa53iTNBvSnmrzsBvXL1BboKMqYYkII1jRGR8N2 4BG6QjcmKnPku424QMm6ork1hlkxJU4KNmGnnTi0/8VPjAOxieaRMStvqyfG5krYl1lR V+Vg== X-Forwarded-Encrypted: i=1; AJvYcCXBYI0+iTkLDasJ9UoelprlGp2/QaRPHZPyVk1rRNZxh/JDgywTyfU9rQvB6SuEvZgguno41QzCloRFOYI=@vger.kernel.org X-Gm-Message-State: AOJu0Yxop9Twk136k9bYJ2p71JgnH6yEvy1JTG976bjtY2XMq6dOWIlv PpapvEjxE1tEFoGnZD4tijF/0GDinwEPjkhJpPJmJGds+5qkN9VJD0f7fbvpa2IDGemA2NlzvI8 EkHcxiuKCO7Qa3g3qAZn9jQ== X-Google-Smtp-Source: AGHT+IEWhVqk1hESVIlHN9fpnPz7ovhaAwHnlpf82RR0HAKH6Gbqs6fHleZO+74e3iAsiD+P7NcS8Md3jf3KevFa3Q== X-Received: from pfbc2.prod.google.com ([2002:a05:6a00:ad02:b0:725:e76f:1445]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:258a:b0:1db:ec3e:c959 with SMTP id adf61e73a8af0-1e1cea99eadmr1328009637.10.1733952039349; Wed, 11 Dec 2024 13:20:39 -0800 (PST) Date: Wed, 11 Dec 2024 21:20:30 +0000 In-Reply-To: <20241211212033.1684197-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: <20241211212033.1684197-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211212033.1684197-4-almasrymina@google.com> Subject: [PATCH net-next v4 3/5] page_pool: Set `dma_sync` to false for devmem memory provider From: Mina Almasry To: netdev@vger.kernel.org, Jakub Kicinski , Mina Almasry , Pavel Begunkov , Willem de Bruijn , Kaiyuan Zhang , Samiullah Khawaja , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jonathan Corbet , Jesper Dangaard Brouer , Ilias Apalodimas , Jason Gunthorpe Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Samiullah Khawaja Move the `dma_map` and `dma_sync` checks to `page_pool_init` to make them generic. Set dma_sync to false for devmem memory provider because the dma_sync APIs should not be used for dma_buf backed devmem memory provider. Cc: Jason Gunthorpe Signed-off-by: Samiullah Khawaja Signed-off-by: Mina Almasry --- v4: - Improve comment (Jakub) --- net/core/devmem.c | 9 ++++----- net/core/page_pool.c | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 11b91c12ee11..3ebdeed2bf18 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -331,11 +331,10 @@ int mp_dmabuf_devmem_init(struct page_pool *pool) if (!binding) return -EINVAL; =20 - if (!pool->dma_map) - return -EOPNOTSUPP; - - if (pool->dma_sync) - return -EOPNOTSUPP; + /* dma-buf dma addresses do not need and should not be used with + * dma_sync_for_cpu/device. Force disable dma_sync. + */ + pool->dma_sync =3D false; =20 if (pool->p.order !=3D 0) return -E2BIG; diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 3c0e19e13e64..060450082342 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -287,6 +287,9 @@ static int page_pool_init(struct page_pool *pool, } =20 if (pool->mp_priv) { + if (!pool->dma_map || !pool->dma_sync) + return -EOPNOTSUPP; + err =3D mp_dmabuf_devmem_init(pool); if (err) { pr_warn("%s() mem-provider init failed %d\n", __func__, --=20 2.47.0.338.g60cca15819-goog From nobody Wed Jan 15 01:13:30 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 DE5C71F0E51 for ; Wed, 11 Dec 2024 21:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952043; cv=none; b=CO3Y9ywuqUjdOyYcFje7mLvKiUcHhX1Y5fPJYs23pRTv0xAG9+VIX1TSbgEZa8A+rELlVGrAnJ+ZAKnUSpjMQpWWU3rlqq/TzNl9ccHO52yR+SiHmOJRhQgYGG7vZIOE4SxAFvzozyln7IvTa+0immPWzKcDn21fhA8MKE7FOS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952043; c=relaxed/simple; bh=2jfORmA3BpQKqPymRv0Q7ztYndICOlLeutvP3frs5fM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Z0Pq/bMTa0TWijBTo9u7HFQTKO94cv13hHcJ7enIPf0BBlSy/5FMiiA5PtP8n1FHsanyuLXeIHj5bDnYEBO7T/KjOASZMDiJVGJOltRFBMt33H68TRE7Kr22ZREyxo9vBnFbFpccuTD90JCnHB8b4tpHIG4K/Aw+xe9FKNe1XW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QpUrHs82; arc=none smtp.client-ip=209.85.216.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QpUrHs82" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef6ef9ba3fso5584548a91.2 for ; Wed, 11 Dec 2024 13:20:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733952041; x=1734556841; 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=FM/slA5nw2rdy331TOQTDkUyJFKnKJSONZ98aa2Mh9o=; b=QpUrHs82Lfzkpb4bh88YPonXIc2OHBMG7p1aAmHjJxaC8xraR+Uu6zD9S74AW32u0u xq5RfJnyXaY7RJRGiuvddTtGfkm57hGOvXrxaCXl7HTHN3IDVUB8ldPyA56t9Y8xCpSp 2sT6xAfGWseL7D7FCfZxo0UJI6ymhSIly1+y3DeG+8RotVdydKj4fic4efHv5K8y3ZmU lQmC2uAwxpGGbWMoi+7K5lPdffYFAzvevUpoy949QgccEHhthS2+F2QC/988h+4Zqrsy Kq/K22bE1Yd7bgaNo0wwJW9u6svSrZf0wcXcB9htD9vlByVbUG4GLs6EdscKgkKW0kGO 8/xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733952041; x=1734556841; 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=FM/slA5nw2rdy331TOQTDkUyJFKnKJSONZ98aa2Mh9o=; b=lwXo+LmCjsZX/SRzLQo5Eyg/foT/OONww0ziwWQ3c3kEf3SvyKpR0LHWp9tilHfKft 3GKEWW8hdca4KdC599rmvvv8qHlQ0I6J4vBjb6iJT7DNd/n63oAoZ+QFI+p0B0r4EIdr 9qvFE9OPXGRkititOIeiANy7CBXqA2we5EdvtPS+FtdV0MCBwtTaaEWRb0nlo3rKdlNf URkX9dzQ8DLc5tDZ4V+XCWqaV3HzeFMeRisplK95gtRZHkEkLhkdwZgWBazU8weZr29i frPqRLgXE0S5Qq9UMEofA55KNh3GKEBqxxck/O1fJmCtpJpbd0gfgZ5kPInRtNKb6h+7 Ckvw== X-Forwarded-Encrypted: i=1; AJvYcCXPIhcQYQUWPYa1J5SNLfCsB2vmLkDAmD4uDZ1cI2RVJR4k7WJbcPbygELFsORxtWDcevupTboFrXtygfE=@vger.kernel.org X-Gm-Message-State: AOJu0YwTGgAsek/XfA4919SX3wc6oLZU033ro7+VSQ4R0UeqAF/MDX8Y AOQBuDPOyAQ24BAqSEZ3+ag/5YL7TRUqX2fqUSlHPXfZSMtPaDJR6bXEFISy9uNHeM87N754DR1 fOkeSP4J0613/MWYfOEzFrA== X-Google-Smtp-Source: AGHT+IFKGSYNgoQ2YviqqfiKTGp9vrd+/ZJrCWTHUKyr11+B2AR5/fODajQoxs0yxpOTuQOugTCOlKnFKeu/B0rvlA== X-Received: from pjbtb5.prod.google.com ([2002:a17:90b:53c5:b0:2ea:7d73:294e]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2b50:b0:2ee:9a82:5a93 with SMTP id 98e67ed59e1d1-2f127fbd84dmr7212398a91.14.1733952041202; Wed, 11 Dec 2024 13:20:41 -0800 (PST) Date: Wed, 11 Dec 2024 21:20:31 +0000 In-Reply-To: <20241211212033.1684197-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: <20241211212033.1684197-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211212033.1684197-5-almasrymina@google.com> Subject: [PATCH net-next v4 4/5] page_pool: disable sync for cpu for dmabuf memory provider From: Mina Almasry To: netdev@vger.kernel.org, Jakub Kicinski , Mina Almasry , Pavel Begunkov , Willem de Bruijn , Kaiyuan Zhang , Samiullah Khawaja , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jonathan Corbet , Jesper Dangaard Brouer , Ilias Apalodimas , Alexander Lobakin , Jason Gunthorpe Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" dmabuf dma-addresses should not be dma_sync'd for CPU/device. Typically its the driver responsibility to dma_sync for CPU, but the driver should not dma_sync for CPU if the netmem is actually coming from a dmabuf memory provider. The page_pool already exposes a helper for dma_sync_for_cpu: page_pool_dma_sync_for_cpu. Upgrade this existing helper to handle netmem, and have it skip dma_sync if the memory is from a dmabuf memory provider. Drivers should migrate to using this helper when adding support for netmem. Also minimize the impact on the dma syncing performance for pages. Special case the dma-sync path for pages to not go through the overhead checks for dma-syncing and conversion to netmem. Cc: Alexander Lobakin Cc: Jason Gunthorpe Signed-off-by: Mina Almasry --- v4: - Special case pages to reduce perf overhead (Jakub) - Add page_pool flag to set dma syncing for cpu (Jakub) --- include/net/page_pool/helpers.h | 35 ++++++++++++++++++++++++++++----- include/net/page_pool/types.h | 3 ++- net/core/devmem.c | 1 + net/core/page_pool.c | 1 + 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helper= s.h index 95af7f0b029e..e555921e5233 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -422,7 +422,21 @@ static inline dma_addr_t page_pool_get_dma_addr_netmem= (netmem_ref netmem) */ static inline dma_addr_t page_pool_get_dma_addr(const struct page *page) { - return page_pool_get_dma_addr_netmem(page_to_netmem((struct page *)page)); + dma_addr_t ret =3D page->dma_addr; + + if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) + ret <<=3D PAGE_SHIFT; + + return ret; +} + +static inline void __page_pool_dma_sync_for_cpu(const struct page_pool *po= ol, + const dma_addr_t dma_addr, + u32 offset, u32 dma_sync_size) +{ + dma_sync_single_range_for_cpu(pool->p.dev, dma_addr, + offset + pool->p.offset, dma_sync_size, + page_pool_get_dma_dir(pool)); } =20 /** @@ -441,10 +455,21 @@ static inline void page_pool_dma_sync_for_cpu(const s= truct page_pool *pool, const struct page *page, u32 offset, u32 dma_sync_size) { - dma_sync_single_range_for_cpu(pool->p.dev, - page_pool_get_dma_addr(page), - offset + pool->p.offset, dma_sync_size, - page_pool_get_dma_dir(pool)); + __page_pool_dma_sync_for_cpu(pool, page_pool_get_dma_addr(page), offset, + dma_sync_size); +} + +static inline void +page_pool_dma_sync_netmem_for_cpu(const struct page_pool *pool, + const netmem_ref netmem, u32 offset, + u32 dma_sync_size) +{ + if (!pool->dma_sync_for_cpu) + return; + + __page_pool_dma_sync_for_cpu(pool, + page_pool_get_dma_addr_netmem(netmem), + offset, dma_sync_size); } =20 static inline bool page_pool_put(struct page_pool *pool) diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index bd1170e16cff..6ae003d3647c 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -164,7 +164,8 @@ struct page_pool { =20 bool has_init_callback:1; /* slow::init_callback is set */ bool dma_map:1; /* Perform DMA mapping */ - bool dma_sync:1; /* Perform DMA sync */ + bool dma_sync:1; /* Perform DMA sync for device */ + bool dma_sync_for_cpu:1; /* Perform DMA sync for cpu */ #ifdef CONFIG_PAGE_POOL_STATS bool system:1; /* This is a global percpu pool */ #endif diff --git a/net/core/devmem.c b/net/core/devmem.c index 3ebdeed2bf18..0b6ed7525b22 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -335,6 +335,7 @@ int mp_dmabuf_devmem_init(struct page_pool *pool) * dma_sync_for_cpu/device. Force disable dma_sync. */ pool->dma_sync =3D false; + pool->dma_sync_for_cpu =3D false; =20 if (pool->p.order !=3D 0) return -E2BIG; diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 060450082342..51b8264de74a 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -201,6 +201,7 @@ static int page_pool_init(struct page_pool *pool, memcpy(&pool->slow, ¶ms->slow, sizeof(pool->slow)); =20 pool->cpuid =3D cpuid; + pool->dma_sync_for_cpu =3D true; =20 /* Validate only known flags were used */ if (pool->slow.flags & ~PP_FLAG_ALL) --=20 2.47.0.338.g60cca15819-goog From nobody Wed Jan 15 01:13:30 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 726F41F2396 for ; Wed, 11 Dec 2024 21:20:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952045; cv=none; b=dLDonbvsRlsuOYL7iz4/UqEjCC8bS6Ny7U7rdlY0jLAG+GwKPdIGApwfPsAHjggPqsZ1vRgdzPZnN+TDgjj0JbiORDHmbNqnccghZoADEf5DiRvPIMnM4r0eWxpDuCHPjKcx/UT3db81exzuMp6WRpFwqdlQML5dm8wambpoZkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952045; c=relaxed/simple; bh=9BNoKvvCDKbyXYRvGcmAgiOTx+VjuHH2W8Or3dRTMpc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mVg7M4zQl0kIbmSBapaHyYwrd9bJvXiUBXaOZIhaZ8O5EeqLdt1wVz4WCh4LZH2pxEMPr9jV1umazzMmDNJ8dUxbO+8g+E/JJPVoR8xaLfxq+k+zU+ypqDjf7OVCTH7CBuuiKlRYyD2aBPUP6njOHtpV7mjVWahl3Dz8Hdm3uU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CmqoNzRw; arc=none smtp.client-ip=209.85.216.73 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CmqoNzRw" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ee36569f4cso7321411a91.2 for ; Wed, 11 Dec 2024 13:20:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733952043; x=1734556843; 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=745mn/S2xe1Z43WeSOTvQvgzJ70pexQD0FqzrefhnYc=; b=CmqoNzRwnz58z4wKlWaK9VJkxia4k9usxdlLwfnj89aTSmvyfW6pbOXhjN6AgsT8dZ UDeNxuHPP5ykljoCbTmFcRC+aCWsVJYaQH/RHJZuqVPKgw7J0GmbJ1sZc37COOMZf5r2 Q0ZrmcBDCgmXdjd7SU+N2yG1DFtowAH6IkwD20Gs+Wuiuky+8kKBXB7awyhDVqGSfwJo BjcOUoR2zVqCXEgJaDDw8a+cfTLgraLyMTqsSJfBtSEFcq2Rwb2JqlFCBSJZbjsw9Ejr jZ8bSQu0rYTqgKQVM7S0t0DjhmGJrsycFOTHpHOq4/DUKJnhjaInb28ywKZO8nTPpo+x VHyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733952043; x=1734556843; 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=745mn/S2xe1Z43WeSOTvQvgzJ70pexQD0FqzrefhnYc=; b=SH2PICgSynK80PqwKKn0l7N7T/JISfn8CPnH0HfG63EgpI/oZQv8+84z2gIbsjLwUn TIzhp2ItX0AWP8QYviLkIViNI4PTDJXr/JgbQ/dSUtOUVv5nnfFMUEiUASqMctCWcoee oi5uduf+hrLgrf+o3hivTDFIciTzCtE9KXqxbkM0VlwiU/HVUGWmVN0jm4H3KxBrMBeX 7UmTTTy77J6vCYkIPS4hIZ7DdHbTo+OpxSFtwaz7ljDUXO5c8+uKroi4mixpK7aMsEVw JvIwWx2mf3jXzF+o4nacuoOAVC7qPrOvnh6B1B30psFnm18AW2Sn919Cn2wSQ5ZeeD8t oNGg== X-Forwarded-Encrypted: i=1; AJvYcCXjslLvMpXVkbjlrNEcjVVpva0AXtDDTgJwEC2yLTsopBajCStBYdyUGzPmFIjlcEo0VOrWd9/z4O4H84I=@vger.kernel.org X-Gm-Message-State: AOJu0YxlalaAZb47n68xcHJGDe+WH71GzqnMLgARK01rWBC4iTwvGU/T Gz/GLOWlcqaj2aAYJx6bQm2MoUKBdeYitR91IukwIR+sGvfziwQBh0jNZvZhVCOPPpWGhCQ/v5r L48fNWimF8YEtkN6FuxTTRw== X-Google-Smtp-Source: AGHT+IF2uRXFUQriUo4tvi6x2FYHwsywKL7Zw3vDn+zO9RvFZ2JyJoMpQxG3APMIfW/ed/zYgqVVYVaPi7Sv7tAlhg== X-Received: from pjbsp5.prod.google.com ([2002:a17:90b:52c5:b0:2ea:6b84:3849]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:17ce:b0:2ee:b26c:10a3 with SMTP id 98e67ed59e1d1-2f139329035mr1977597a91.36.1733952042875; Wed, 11 Dec 2024 13:20:42 -0800 (PST) Date: Wed, 11 Dec 2024 21:20:32 +0000 In-Reply-To: <20241211212033.1684197-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: <20241211212033.1684197-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211212033.1684197-6-almasrymina@google.com> Subject: [PATCH net-next v4 5/5] net: Document netmem driver support From: Mina Almasry To: netdev@vger.kernel.org, Jakub Kicinski , Mina Almasry , Pavel Begunkov , Willem de Bruijn , Kaiyuan Zhang , Samiullah Khawaja , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jonathan Corbet , Jesper Dangaard Brouer , Ilias Apalodimas Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Document expectations from drivers looking to add support for device memory tcp or other netmem based features. Signed-off-by: Mina Almasry --- v4: - Address comments from Randy. - Change docs to netmem focus (Jakub). - Address comments from Jakub. --- Documentation/networking/index.rst | 1 + Documentation/networking/netmem.rst | 62 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Documentation/networking/netmem.rst diff --git a/Documentation/networking/index.rst b/Documentation/networking/= index.rst index 46c178e564b3..058193ed2eeb 100644 --- a/Documentation/networking/index.rst +++ b/Documentation/networking/index.rst @@ -86,6 +86,7 @@ Contents: netdevices netfilter-sysctl netif-msg + netmem nexthop-group-resilient nf_conntrack-sysctl nf_flowtable diff --git a/Documentation/networking/netmem.rst b/Documentation/networking= /netmem.rst new file mode 100644 index 000000000000..f9f03189c53c --- /dev/null +++ b/Documentation/networking/netmem.rst @@ -0,0 +1,62 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Netmem +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + + +Introduction +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Device memory TCP, and likely more upcoming features, are reliant on netmem +support in the driver. This outlines what drivers need to do to support ne= tmem. + + +Driver support +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +1. The driver must support page_pool. The driver must not do its own recyc= ling + on top of page_pool. + +2. The driver must support the tcp-data-split ethtool option. + +3. The driver must use the page_pool netmem APIs. The netmem APIs are + currently 1-to-1 correspond with page APIs. Conversion to netmem should= be + achievable by switching the page APIs to netmem APIs and tracking memor= y via + netmem_refs in the driver rather than struct page * : + + - page_pool_alloc -> page_pool_alloc_netmem + - page_pool_get_dma_addr -> page_pool_get_dma_addr_netmem + - page_pool_put_page -> page_pool_put_netmem + + Not all page APIs have netmem equivalents at the moment. If your driver + relies on a missing netmem API, feel free to add and propose to netdev@= or + reach out to almasrymina@google.com for help adding the netmem API. + +4. The driver must use the following PP_FLAGS: + + - PP_FLAG_DMA_MAP: netmem is not dma-mappable by the driver. The driver + must delegate the dma mapping to the page_pool. + - PP_FLAG_DMA_SYNC_DEV: netmem dma addr is not necessarily dma-syncable + by the driver. The driver must delegate the dma syncing to the page_p= ool. + - PP_FLAG_ALLOW_UNREADABLE_NETMEM. The driver must specify this flag iff + tcp-data-split is enabled. + +5. The driver must not assume the netmem is readable and/or backed by page= s. + The netmem returned by the page_pool may be unreadable, in which case + netmem_address() will return NULL. The driver must correctly handle + unreadable netmem, i.e. don't attempt to handle its contents when + netmem_address() is NULL. + + Ideally, drivers should not have to check the underlying netmem type via + helpers like netmem_is_net_iov() or convert the netmem to any of its + underlying types via netmem_to_page() or netmem_to_net_iov(). In most c= ases, + netmem or page_pool helpers that abstract this complexity are provided + (and more can be added). + +6. The driver must use page_pool_dma_sync_netmem_for_cpu() in lieu of + dma_sync_single_range_for_cpu(). For some memory providers, dma_syncing= for + CPU will be done by the page_pool, for others (particularly dmabuf memo= ry + provider), dma syncing for CPU is the responsibility of the userspace u= sing + dmabuf APIs. The driver must delegate the entire dma-syncing operation = to + the page_pool which will do it correctly. --=20 2.47.0.338.g60cca15819-goog