From patchwork Wed Dec 11 21:20:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13904218 X-Patchwork-Delegate: kuba@kernel.org 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 C48FA1E9B36 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-2ee8ced572eso7473609a91.0 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=XN1QRbOULsRqieMk8FnCpayFTPG4n8BNJyZ8Ntoz6yvbyByesZKnYrQNIcbIyZf4pj ZUiwjJKUjbQGBBsfRobko8KTw1+ICYBKpDzaoO+ei48t1Oup4BeZGfGS4duufHcZS+qG UIkkXqicPwfPIl7S8GCILvww1pDoftFp6H0soO4M148hN+EdEO4ppabGcdAsM8v0XJTc PQTofaHtj6Uo19KTmbC7syzI6031e8EGcp0O1jYPNVB6RVKZ1dUa9+Uvwga+BjVTvHOV 5qh1jmw1P9KD/OsfwABQrBQALD6OJ8pjGCXJONcpTiT/2vBCzi9YhX5riDUDFhrjVobJ KbFw== X-Gm-Message-State: AOJu0Yxej+m0t3UmvcHOQOIQPmZsXSjZq6ss32MJO0QxDxIipA1v0pWB B6Fo3ybSX7kGo6WOWPnUSTWNX1tAZDdckiR3MSyX4cbnjMUG5v1WiOuWwPLtwbHrVw4X6975zqK aoH8PaL+pJrezs2lQk7bPKDagSnmq3vgc1ypKu9Ly3rE9CTH6ybFchdNoY249NDKv+I5acnpguc /7ijh5/y6JPo/Uftk7nECEq7Q5h+UU89Xnz0PIaX5DrmTMCjUhIEC5vYbZS6M= 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: netdev@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 X-Patchwork-Delegate: kuba@kernel.org 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 { }; 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 *offset, 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; @@ -590,11 +590,11 @@ netmem_ref page_pool_alloc_netmem(struct page_pool *pool, gfp_t gfp) netmem = __page_pool_alloc_pages_slow(pool, gfp); return netmem; } -EXPORT_SYMBOL(page_pool_alloc_netmem); +EXPORT_SYMBOL(page_pool_alloc_netmems); 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, } if (!netmem) { - netmem = page_pool_alloc_netmem(pool, gfp); + netmem = page_pool_alloc_netmems(pool, gfp); if (unlikely(!netmem)) { pool->frag_page = 0; return 0; From patchwork Wed Dec 11 21:20:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13904219 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 932F31EC4FB for ; Wed, 11 Dec 2024 21:20:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952040; cv=none; b=eUWhouA4BVNVxyqowpW50tBUfOU6nYSbgzHBhSvN21oI/ULUMKhnvxumoBrskNM8AsuwMz4GCM/Y2nbE1dszsogTc16fJ4n2z75SaiTKEcumP/kpoah9nj12O66W2GRCi9uHsMqmm7Fylja5tprlsds7bawQFU5S9Rjce1/83zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952040; c=relaxed/simple; bh=3m4AIfXRnx+qjxTq4vCGjNR0f9YLSWQ6fISqEIE0hIQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TIybR4F1gyGFns93fwY41A2h+9NxOotJSSTZTmxXtkzY3D3WokuVCUetTl4fxq5SZ32NAiPvtqxs7sT4S8KB8DiYkaXh+YrMzRwMXk3Xo3bxtOftVg/AQ0EeSZ4Wc3XZZQUT6CwvkvG/1e11Pkg9zlFZkMeHhl6QKANBh3sBB8k= 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.215.202 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-pg1-f202.google.com with SMTP id 41be03b00d2f7-7fbbb61a67cso4077263a12.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=izyO//BV9/oRjlOzWa8Fi0Fulm8T5LQNedQ8PSMyciWLn7pr2+OS8ZnXvDieRPh0vl MF28gwUWKQujeUqN122yw5Fzjs4Td1MU9P066Ihivf3wkF5PnfaO48w0oU4Zud4UKl4m DqkelCBQWHTePoc5sOd0rcl7EpIx1p3ZWvdm5PEuh3jdnNYrixck86MqKHa4APxI34i9 GJWFYzCowHhVfy9+4SoldTNYTnD63kYLSHLtc6Uxytlf3S3+7YhdYvy+tzD7z1sYQlNF fdHkQ8Syq46RO1Cg5CDT1ah+c9OqEa1zES5wupDLfHf1wVzje9cSirVAY01/PVeyxb+q gRvg== X-Gm-Message-State: AOJu0YwDI1LA2nLd04FOY/hYSS9HMZcQ1okJr2CCG/26IBLePB3MhmNK Df+mNsuBP/w0B1jUaQmSZYnauCqoAl0EtFe6wV2YDQZ7sSWUSM70QDIvZ/zus5c6ZM/Nm7xRm1u nccJmOBUv9NfsrU7il3/kuvXrSsaBARCEviVNe+3JJV7RL5SI/yGqsfSeQ1r16dfG1VWbBbRmFA sjNUwtO3BbI7P/y0Ul7HeewGRh2ILXjw+okd+2QlUrruNugRpoOJ9wFqes9J4= 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: netdev@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 X-Patchwork-Delegate: kuba@kernel.org 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/helpers.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(struct page_pool *pool, return page_pool_alloc_frag(pool, offset, size, gfp); } -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 = PAGE_SIZE << pool->p.order; - struct page *page; + netmem_ref netmem; if ((*size << 1) > max_size) { *size = max_size; *offset = 0; - return page_pool_alloc_pages(pool, gfp); + return page_pool_alloc_netmems(pool, gfp); } - page = page_pool_alloc_frag(pool, offset, *size, gfp); - if (unlikely(!page)) - return NULL; + netmem = page_pool_alloc_frag_netmem(pool, offset, *size, gfp); + if (unlikely(!netmem)) + return 0; /* 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 = max_size; } - 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)); } /** From patchwork Wed Dec 11 21:20:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13904220 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 3F0FC1F0E54 for ; Wed, 11 Dec 2024 21:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952041; cv=none; b=tRkwci0G2RkgXAIFSC7qONz6NZCSydBNY0OX/c2XSyPTr3PCG6V4M6p/4ZDfVNZora66vyi9bSNclR44mOSJamYWRxf+tfWcM4cCw06Lg3ey7W2b19xzoKUDpg0TTGtk6nRPnad0emfL3pNa5u4ldM/0IroYfrvXndSOe0Ng5UE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733952041; 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=azddL0WiEuQdDTO9GTgGkNe7VWK7jHPZeu7HmtOG8PrBpssjHsai4A4iKASfK8qgZlksAFWU9pR22vrokWszslaiisgVTC+yc+4ilWcUoPUHm+H2R+90YFhbHxrDXVqdX986XqHQYH+iGsOB4wWfo+i1+qBzFmE4W+QZ0hR14ss= 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.202 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-f202.google.com with SMTP id 41be03b00d2f7-7fdde44f4f2so1858129a12.1 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=SNlCbOrgwd5YierZQZbvl6uLruX9EdFrxwXWbMz4K18F3lP7OjBb7Cfm50jbERGZUf BmwrDjAKVkbdcHVtaEvLVR4FgUv4qZ+RkXOE5JpD4c7gqWnxOf7RXiAEinY3sv3v5Ido uYKJTpQIE8CZ20EcCTqC+5Ct82sD/t+/55yuIdukPbVzXfgseKlOEtugE7+gtPGMb3bd T70OfzshEYS/aSvy5nYLV8Qh8dB2VinFXezfgK6mAEJpCjirSfTkws0gb7QakFOtgIn9 w8D8Q8+CQ1vL+GE7lZwO504l6Y/1Ac3QcbX3sHJ0QZDB+ePoM4s8YCMmATC6kHQ85Lah OrbQ== X-Gm-Message-State: AOJu0YxklsZ9hBaBGJEsCOs1pxN/YEYNeRj3fs0c+LOtZ8HuUfRnBxLH ZDIaooQ6Efe/CRHKbcd5wDY/DCC5AvPA1cO/Wz0O0dCneMBGre4zGvy3L8oBaUIInNzQgVGv8Du ajEFWY7B1BE5PCbdBfxB5/nqTmTUnJOx9wcHPxXQWkCnYjDMRFHCnBUFDB9kt7A8ClJ3HqD9y9v wQzvKz2vUWMs3w26qWdruNxMnUsVodtWVYd57EmlUspN0ujJg/ySwcBRiAEdw= 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: netdev@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 X-Patchwork-Delegate: kuba@kernel.org 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; - 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 = false; if (pool->p.order != 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, } if (pool->mp_priv) { + if (!pool->dma_map || !pool->dma_sync) + return -EOPNOTSUPP; + err = mp_dmabuf_devmem_init(pool); if (err) { pr_warn("%s() mem-provider init failed %d\n", __func__, From patchwork Wed Dec 11 21:20:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13904221 X-Patchwork-Delegate: kuba@kernel.org 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 BA9471F0E45 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-2ef6ef9ba3fso5584551a91.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=sngXDB+zcZOWEpJ9kbMxglUHEwbHArkrichfXmkJoF4f07UT2lFq24Q2iZhLhAb8vC LHAMuFTGXf3ePjlb7ZfmXJE0mi07F9/X8rsknKtWcA+3JYwphaalQgItUD/IDwJJS/BC vdmjIJcimFk4m92A1CVy8rbAo96HFcI4XK4U5ubYdFhjfb5wT1hjMQ52n+rjzUa887d+ lqy5C8s3vsahG56S5asJlN7xtGLS3eg50SVMh0VtD8zrBcpw4RD+H8HL85Uyu3saz+Sh /R6NN5AhaG5XbIMGJWQPUNQqi0wCESB6JGbUMJPHNfShRknnjDuws0gsxlYJJN8y8lzM ci8w== X-Gm-Message-State: AOJu0YwYUwKUgclt7nUZYUzl3JF+RLLQnJ9B1lzO+69TOGy5osDAVxue vxgikhu63eiy4GmgzZ9iBbEB+KB4XQJ34iJTJXsRMCMMSU28U/9luQ7X13oEg6BbggKXlVuYnfC /xY6vbmD2VNj31taeXFJLvt3QLX22vofmFe0vcO9rhdDgloyKO8xycbsSKa7AzO9tjMCbLwxbNs jBxiMJLF8mISaQB2kaX7wSQDVw4xUC9VnZ4ZhzG3N3U4pPQeKw3LTq6mDLK9c= 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: netdev@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 X-Patchwork-Delegate: kuba@kernel.org 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/helpers.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 = page->dma_addr; + + if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) + ret <<= PAGE_SHIFT; + + return ret; +} + +static inline void __page_pool_dma_sync_for_cpu(const struct page_pool *pool, + 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)); } /** @@ -441,10 +455,21 @@ static inline void page_pool_dma_sync_for_cpu(const struct 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); } 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 { 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 = false; + pool->dma_sync_for_cpu = false; if (pool->p.order != 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)); pool->cpuid = cpuid; + pool->dma_sync_for_cpu = true; /* Validate only known flags were used */ if (pool->slow.flags & ~PP_FLAG_ALL) From patchwork Wed Dec 11 21:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13904222 X-Patchwork-Delegate: kuba@kernel.org 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 99E2F1EC4C0 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-2efa0eb9dacso3853015a91.1 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=cR1HXS9B8PZJrfPmJ5vWpdv2XvCKRNn5SIngbLy4tM63/L+LIcplyytXq2i7GLlIgu TF/W/CVb5+AkIDuHh96RS3t2YvzHILQr3hoC7qeKrez03MnLFOK5RGC0EWA/qbR9686H 5HBRLtM+aVpY32hwo4MiOzKHdJHPPFdt5mTqgE5ziphciNo1UnuVIDXC9SSxQXR8Itfj +olzdtSmxYuf4LG6O0UU+FcQChkUTyYcoZtetDigFfyzOAXvL2OFVbHE9F0ToMoolKsd aQYaRRwxXEoBBR69kywzH+eD3FEeDHGMKiumk/HmsR/fdXVRGcRg/pzVHZrJML1Mfh07 /+6g== X-Gm-Message-State: AOJu0YxvD20KzfrEuNSMGBXOtvjXEby1vLjbQCKu70+uhsOQ6ewfVs6F 6zZJy2BaVtUGdA31pPd+KGfbYSKQRMMTUM+p8NSiG16mXX+Bn9H54Vm/sfrjEnzCetW1+Z01jz4 hKOv/7kOw+ckWYTAiA83McDUinrBecyilTpP6gsZsYNwlwOjyn8JdhBv53zhDg2XeZCMrH9GZXe HjRjhunCcxpPeq/Zfm8J+0VNSWr6BEWWIxejkQAMeKq3oOVAUX4fIGp+QRtFs= 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: netdev@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 X-Patchwork-Delegate: kuba@kernel.org 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 + +================ +Netmem +================ + + +Introduction +============ + +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 netmem. + + +Driver support +============== + +1. The driver must support page_pool. The driver must not do its own recycling + 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 memory 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_pool. + - 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 pages. + 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 cases, + 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 memory + provider), dma syncing for CPU is the responsibility of the userspace using + dmabuf APIs. The driver must delegate the entire dma-syncing operation to + the page_pool which will do it correctly.