From patchwork Tue Oct 29 20:45:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13855483 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 E0AE7207A1B for ; Tue, 29 Oct 2024 20:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234748; cv=none; b=A4yOl/gI/0gKvBuu/r1kAsmLvDrkpVu/EEaHcOxEgFQ0ANJztlyPS6V4ErkhcZXsmS3yVfQXMaHhoYBTYff872UH4d91gVT3kQqQ96TeZZUS3bqheKYAFFJqGrHmDKV7nfQj4f40smzXdtznFBx3/EqkMWj7tSxGxpu/wey/io0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234748; c=relaxed/simple; bh=ANVvHO/Zb6fJtzVUz2e7HjfsostgYB8KbWIfjKVTCSo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OsgXDQTh5zxhRDubjodVxy1yCudY3f1LmA61xNfMvdHZFTw4fVp/jEzQ5V8hTPw/+agSGko9PP50DxpfodsptDFWW3iarbLsrV5acNCaV0P8KYWMRkocqlK2h0J5kQrekHm1FoquHoexM6VD2lp/ijsh1xW87fGo9hW5i1MFDVk= 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=NThEFMzg; arc=none smtp.client-ip=209.85.128.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="NThEFMzg" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea258fe4b6so31705307b3.1 for ; Tue, 29 Oct 2024 13:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730234746; x=1730839546; 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=IKVtq75fITyzSDoz03OSyDAa5pp0EHjXr3igFrBPeF4=; b=NThEFMzgXSI7CP4vWqU3xKJr5zIbt9l8g+AkJLPJ1785X/09WepW0ywegFzdvPmdNE 9sZiGD71hgjuHmMp+jdfQPYgVBQqAlT4Qon0ZSXDht79wo6bic4Hd+AkzudZPew7o7MU aoK6v+emhbvfJvwhIn+ETzMc5Vmws4qSyxu3E85m48Zxk42e9vN739GwVBDvJzC6nfi3 k48V7rqEI6UnmBF/BSlN2PjlcRNGPw/EEfQmR6XYIH3OHjGZrrBzy6JbN36nY+s+bJrM YWQOAANkyy1Ypqudx0RXAn92NYtaf3y9/FJ//PWOF/PR+WnVFYlRXNCwpK3D12i772AI +W0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730234746; x=1730839546; 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=IKVtq75fITyzSDoz03OSyDAa5pp0EHjXr3igFrBPeF4=; b=c0T+FU829Kq/33AqSmhmhd+8lMDh8SlXQzMhtzKc6h3qW8lN/FSNe0qyjAjVvEMb6F pRHXfJzm4QcdwsI+g/WU/Moo2o7bxofBzbnw8+Elk9ddL3mzc7LzG69wrxwtI2JsrMDl XQgJxQSKHXih1EST8Qa2ipnmUIB+uPTSEmU1iXD/c2U1Uu8IQjW5Gcqphm8risexGnte E0Tqx7DD+llGtZQyH1OfJV1SzW4E3a1bxlV8uYYH3ZpE8bjq50cxiAuvjMy27PHRW9p/ nk8/bX/8ITqwpWlYBA/4IzJBphhUSR9pB8wfqhdflaymfaWt4yfJgs9yM/iCtO8LACLc +wIg== X-Gm-Message-State: AOJu0YyWuPOQzU14PxCq5MIMSSCha93/Y1TD51VDis2YzYau/nEjT09a jlyDjq5KBUd1E+tkM7ohNgZMGgVMMJ72vVGKw/DuP3PCliP0cEuyUgMFaZQg/68ls6n84SxkhAo 17TxJ/UoSvzLiXeAtc7LqqoFCANJUazYg8VK84tZum71vx8U6DsJ7SuoTx78h33TAuvNEl4XEJa NtCJKYhZ1baqAPTA/wCpL6B2EUsPBVxs5TYi3lVfWjHYDLAj2koFPcaIwPf00= X-Google-Smtp-Source: AGHT+IHZYCaL3wj1+u0hTpzTRQJ1G7IFk6vtNOjfqwf31bO7KQxkZpsTH7OU8mGhiD8LbP4+F/NssnNl88Gr6RiQGg== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:690c:c14:b0:6ea:34c0:966 with SMTP id 00721157ae682-6ea34c00d19mr990757b3.5.1730234745296; Tue, 29 Oct 2024 13:45:45 -0700 (PDT) Date: Tue, 29 Oct 2024 20:45:35 +0000 In-Reply-To: <20241029204541.1301203-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029204541.1301203-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029204541.1301203-2-almasrymina@google.com> Subject: [PATCH net-next v1 1/7] net: page_pool: rename page_pool_alloc_netmem to *_netmems From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan 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 --- 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 c022c410abe3..8f564fe9eb9a 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 a813d30d2135..77de79c1933b 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); @@ -956,7 +956,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 Tue Oct 29 20:45:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13855484 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 EEEF3208224 for ; Tue, 29 Oct 2024 20:45:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234750; cv=none; b=lyd43v/2EKYHwuE/gwFQdbISnq4lbRbV9nxpKpX+oOyISzxoCGWGFWSKoVu4SlC9AydVlQURQ4bVzWMj5bwXUzkZb5q4RB1lQ1ANX9/jqvoCyecTQJaCEA7KmdlSXVaC/neA9S+4IhcTW4OqQFaGYiRquhB7XqLsu/MO3WbpKEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234750; c=relaxed/simple; bh=MPpJ9MAgQTGKiMca+3TwxgtGAu4G2CP87nP4yq+P6DY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZOb3aZUKIGaJBeXUQvHSt8B0qTn5BESHH42DBe3xkijgq7Gq5pGQFwrTYtdPLUGxZJj7dsRQjpj9EPVUyX8pT5AgZmZiN8feAc/zta9OKu/KaFYZAoua1Fh4lDGBbTG4wwba4DX9pNpYt8cd1IOnAYTJIOLNnQlrjmznfn3OlaA= 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=mmu5TXgE; arc=none smtp.client-ip=209.85.210.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="mmu5TXgE" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-71e4ece7221so164688b3a.0 for ; Tue, 29 Oct 2024 13:45:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730234748; x=1730839548; 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=VTE4xQCVjMyxxqMXxr+7N7iCNqUizi/3PQsJgMgvBFA=; b=mmu5TXgELb128CkFAiGNRv84wtnk9d8nLEg/H4kBpLGN9gwoC4oDNNvP+ygRvgKtOc o+dSPsC7BTjtAtOjWM8QIqX1x6y3rvu7t2MVz3twRkqB065DFQXk16kEuYOPpX6fzE5E Pf0CHlNCQbod2lyim6i85Y+OuboE9FbjZ12CuMy+0ShT8+Vq4v+OoDuRhF1ZhlWrj1P7 LuSLSECVz2ImPf1FJQNXnk2pYj/lfSDc+Sr6MBAXmDRQ1LtrV+YkoyhYLHoO8cbfeqet BBSrCgr4VcTeHAoXrGqM+45qDEQa1/qoLQwBp7od54Z+R5OQUsq2y8BzKTUIBqcZy8mT Mn+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730234748; x=1730839548; 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=VTE4xQCVjMyxxqMXxr+7N7iCNqUizi/3PQsJgMgvBFA=; b=NWJatxvIn8t1OVaYKqOOf0JkEt2vbw1Q2VhM9VK78V1UEh1GQgsnA1vOBMK0rZJJL5 Cg7HFPd47xkeu/zi7StjPFfDEMaTuODg/8E8WaK7F2aXKT8bA1C/vrubQDyRIellMNSB C8rLqoP8zxqi3vTyCSnm9/XV2OeGzN5iIY0VHUV+pBIRDD5OmmgJIuDaI9oTKOIyUwRS bZs1uwYCxwFJCyqGveJ7o53PqI1rNhB98LacfyIRSX5hvQ0WIwbZdBLjgeWtUHq/CqKF NQkIU5K0BRgWLSNbssHM8Q3lATn7CqxG3UWuj6cCjt2pqUrn9YpJVMXWQ3+Hv/1zz/Ky qE2w== X-Gm-Message-State: AOJu0YxUpOSrfotwOA5zuvLPm0i4yZNZOTkMD6sbSK0Ln70ljC8+dJBV aj3e0iRu8aHxCpUxFPY6QnQF6ubDYr4AFhOkl1wJk1yBCUpDDYpawFI1S2W6TPiDTt5WLPJ3Hh9 h94BcXtQjOiRx5L5nz6X1BoCzPibvnuiQzwbPi2+29WBDzmAINDqeWBanU2P/zPFswWnYtj91xv /AyjZUMxnEYH0v16KSQwB1I7FBmv26peAbE21RFcpJ58Vv4z5KY9EHlsC8tQ4= X-Google-Smtp-Source: AGHT+IEKGxoSoddutyhUFaULkcAEtXglgd09/xsyxMRpkID6DUSV4Uo0pLLV1QBH/hysppFRWIE1Nt7vkyQ/XtJbAQ== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:6a00:2e97:b0:71e:6a72:e9d with SMTP id d2e1a72fcca58-72096badedfmr36603b3a.3.1730234747151; Tue, 29 Oct 2024 13:45:47 -0700 (PDT) Date: Tue, 29 Oct 2024 20:45:36 +0000 In-Reply-To: <20241029204541.1301203-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029204541.1301203-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029204541.1301203-3-almasrymina@google.com> Subject: [PATCH net-next v1 2/7] net: page_pool: create page_pool_alloc_netmem From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan 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 --- 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 793e6fd78bc5..8e548ff3044c 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -116,22 +116,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 @@ -142,7 +142,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 Tue Oct 29 20:45:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13855485 X-Patchwork-Delegate: kuba@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 4A0C3208981 for ; Tue, 29 Oct 2024 20:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234752; cv=none; b=I66u/tZYINOfg4/7CPsGSlJdlLQQHaMGcKK4VQDdsaW2gek9o3ALSkzjXTQ2w9SNNMB635Av3f2ua0ASPkMOf/o+98CAfiBxoSkI6A1y59EQnMFJBy/PHP22qMcBv7cmOdd2oeZrSdtrgpPBcsrAd7MaJyv9Jhbi/hm7Nt7Bchc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234752; c=relaxed/simple; bh=wj9CgD+x0GVWC/RysuEBDRx4mXq9fGHiB/kdVGdaca4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Pm2NrP77dBKX6qbAip5OiR1tPCYW9Lizu9sQRXuP9/ykH9AT8DA34/z4Z5spNE+DuZFw1ev3FgnW3YEkRy/UVOcejEZ90rGSNvXs/TrCjVdEjMK1e2waW01ttB8rQxR0qldhRbP3gFyRA2E02m6P0e06tLQRw4/7XNyymOKsndc= 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=nPcxWyh4; arc=none smtp.client-ip=209.85.128.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="nPcxWyh4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e9e897852fso62132137b3.3 for ; Tue, 29 Oct 2024 13:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730234749; x=1730839549; 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=Ia0Z0AQiuotb1aQB7+r4THgYyxvP1pQZETcnEmFDqWc=; b=nPcxWyh4nHDSfNGljewbLP/Ur27KLsWEgOsJWAgGqK3EwwPcSUeOcF9Z6Z7v3vqShx uZEPgwTPherzGDH6Fx4fwowpnrbAM9/mrffJTAa4IrtUiJS4/4MXywBcMzLFNbyS5Qt7 +oIxoclN2QOnB9Arxel024zrWvT8LFsZkuVuFB80g4WRbP9pDlReKAvLAnNX5mjtJuO/ SvNfXga1w5eFkRoWw4F+fnxN+tnQeCriNBaQpDkbtMVRpeiYa8rUJf5l5Z9W3o09kUvT g2jClRPtnG+C4UXCqYD6Mmv7rzVWz3MZRZGCa4X5sftT/grATazTuDFP6iOa2Ox2KzjQ Zp3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730234749; x=1730839549; 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=Ia0Z0AQiuotb1aQB7+r4THgYyxvP1pQZETcnEmFDqWc=; b=ICeuqnAS4BJarIrMO1GGM2B+04X27rXvvwNTcgQb1Q7izNyxzsGIsWXd+XBzr5BXO/ bnshaSYWUF/LXepWzMSqmhfTLd3Vy+F6IWPTyHBNW9VGwAniuy6ARKRViPKLa2RiyzBg ab9awrwphHZ85ikzWkv8QXUKnN7PTIxk5SCIUSzy2LkTnvIKq+9P+xo8sfG+LxpdfKQq 2XcsNwIzNGcYOKGS+QcGCa2ZGuB4lPrEU8HyXa3lgvbPAzxKRbCIwLwVYUkXmWppRKxu QVHSxdjxpd4kAsuK9U2qaxhpFsEwuaPzsjHaMINFCKA5Y/y59Ftds/qAEEFzlyWEq+k5 0j4g== X-Gm-Message-State: AOJu0YxufbackYOQ5qUaH3xxwApwL04gKkQ3JSGUmdMRzfnx+vBnWvvB 6cLL/OnZdHAyDk6uBAO+hGPUa4pifrT6sgiNSx52pLklyUp1e2VYgRdi+BA91YQarO4JW1P+WwJ hHRIvKhAo4kkGI6nJjZlgCUqPPkVCqna1A/bivS7LYe2YNmXCoz0ZoRO6s0gYgv69Y1X2IyuhL1 37Tr3960JhfDluoe54QYLrLpmhrzGJvgT1JKHxUx+iR6YLYuab883R5qWWsmc= X-Google-Smtp-Source: AGHT+IF6iUlUajnIuWSLwO8GHFuWPdZ7TzjtXW+wmOwLsLSi+oJyQ0Mqbj3G/hC6QRpn9nQ26QyYa9SQhh+OMtpcIA== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a25:f301:0:b0:e28:eaba:356a with SMTP id 3f1490d57ef6-e3087c10916mr55330276.9.1730234748927; Tue, 29 Oct 2024 13:45:48 -0700 (PDT) Date: Tue, 29 Oct 2024 20:45:37 +0000 In-Reply-To: <20241029204541.1301203-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029204541.1301203-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029204541.1301203-4-almasrymina@google.com> Subject: [PATCH net-next v1 3/7] page_pool: Set `dma_sync` to false for devmem memory provider From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan , Samiullah Khawaja , 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 --- 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..826d0b00159f 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 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 77de79c1933b..528dd4d18eab 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 Tue Oct 29 20:45:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13855486 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 CCFD520969B for ; Tue, 29 Oct 2024 20:45:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234754; cv=none; b=Z/yRYTrPsEGVlFpemEGSUnNIn995niN1LE7hIpcnW/OGkPODttQJGdkbX7gYLgBjwqeowfeInDLTChosNY+SbEkvUI1/5MnFMZ1X7QBTaxyEcbao423h6hCjBlvVdtoc4Ce5ZlYZ+KfKVbflUICJtya4K/tO7sCakEKaYWFk/dM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234754; c=relaxed/simple; bh=6eTzR/9ZOnj5CYN8SmYXPKii2L+YcvUeqGgZJmywDDk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EK/acgfg8dNZoRL6aD6S26cKItjBIxu6KLxtq7LmJ7RFPRQxgIQZBC37/AZ/1efFHv8nNictzQPAqGz+dKq+ivomCYxdzoyq5JOgTp9vqKfYBHkxxd68IsHJBPNtIY9KIhuZLv7K43cC9KmYk5Ib+a9EL0ygfkUKhnn0Fjuz0K8= 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=JLWDT5TG; arc=none smtp.client-ip=209.85.219.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="JLWDT5TG" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e30c7a7ca60so1242639276.0 for ; Tue, 29 Oct 2024 13:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730234752; x=1730839552; 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=8DWvEuGXnU27PXRSp7zy0hKeJv9z9WHLclRxJOt6bNk=; b=JLWDT5TGrTXJ8jpHQp59sfhfFyiJzlVBaq+Tc30SkEPsRaNfzWw0r+01ild5la3tSs YRhPY6GsCiMOSoJRdwnyWahtl6/LOv+r3V0LLsgHm7z3Y74Ccavius8QEGK6MvjcOAo+ 1C5m2Mj5NfJevwd/4e3BXCDPs7IhnPakgYvHMAjSyPvQj+3X22A0KtzJu31nH5DoQ3mL tMwjp+XIRfAh+P/fbWu+b5dLw+/3cxZXYeZbK1SCgNJXYmRr8NgohLqH5GO6btNNc2DC Id10C7m7O4lOlqpFKQi9tFK6YIXSb+o15QATOqbnPpRaszeQIHeOAaMrgBk9O/WojsuA MDuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730234752; x=1730839552; 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=8DWvEuGXnU27PXRSp7zy0hKeJv9z9WHLclRxJOt6bNk=; b=iljHlAWXnMNIjEtjaBTra2OAOxjMlJvzXWdrn92TBAmXt9YOpoR9nYt438gPsuWQQJ B3ccrj8r2jY7Auyb/oTJBD/vAn70MDzV0p861OOtWQeWLX/iDVQaOgFw5sGLZ96KTJlT BtlhjSzngwFeUxHRyuO3+wpGjv1rgt+3lfjPTNaEJwHphGGv5DNpHrvUQ0oACR7MpWdj Kscspn7EkY9EHkcs5FVTqY68KGvTx90VX+cfPCI7H9x5sGxc7LEd/XUO8QTK31oxQVK6 aEFsv9Dlg/ZXkifK3LFpGgUBWqyzsLuUDOBcBnhVQHFUJ42S+0q1d+zw+KDc1QPZbS8O cexA== X-Gm-Message-State: AOJu0Yx5mZHs46pQYcp3vkmWhzkHKhhwFWjAgqs/h5xACCRzcZ3zFZDo G3HZAfnbJitA36BRuLarQFw9Ylh+rhENYx2Wu8ENnw1YfOjpQGXYt0m5XLWX2QBqbk1PBD9tGQ2 btX+gWgL+qZskMP0rW7oY8Alnhq9upbETMGnKIpdejxSSJ7y64QIrQle5kXni7adsNJp1A48ALa 7hB73YYNxAclzXslyvZHnN4Z7thrSCH7fxPx+w/sNwTl8fat4bO8ub4bzebF4= X-Google-Smtp-Source: AGHT+IH9DOKv8lVSkF/qC/v3j6pptyY01q0mblnOxpf7Wr+4mvSOn1+/x8RXmICWDZSdFxzfx8BIVffTqN0qBKCV1A== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a5b:bcd:0:b0:e29:b6d7:20e2 with SMTP id 3f1490d57ef6-e3087736bf6mr83545276.0.1730234750854; Tue, 29 Oct 2024 13:45:50 -0700 (PDT) Date: Tue, 29 Oct 2024 20:45:38 +0000 In-Reply-To: <20241029204541.1301203-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029204541.1301203-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029204541.1301203-5-almasrymina@google.com> Subject: [PATCH net-next v1 4/7] page_pool: disable sync for cpu for dmabuf memory provider From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan , 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. Cc: Jason Gunthorpe Signed-off-by: Mina Almasry --- include/net/page_pool/helpers.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 8e548ff3044c..ad4fed4a791c 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -429,9 +429,10 @@ static inline dma_addr_t page_pool_get_dma_addr(const struct page *page) } /** - * page_pool_dma_sync_for_cpu - sync Rx page for CPU after it's written by HW + * page_pool_dma_sync_netmem_for_cpu - sync Rx page for CPU after it's written + * by HW * @pool: &page_pool the @page belongs to - * @page: page to sync + * @netmem: netmem to sync * @offset: offset from page start to "hard" start if using PP frags * @dma_sync_size: size of the data written to the page * @@ -440,16 +441,28 @@ static inline dma_addr_t page_pool_get_dma_addr(const struct page *page) * Note that this version performs DMA sync unconditionally, even if the * associated PP doesn't perform sync-for-device. */ -static inline void page_pool_dma_sync_for_cpu(const struct page_pool *pool, - const struct page *page, - u32 offset, u32 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->mp_priv) + return; + dma_sync_single_range_for_cpu(pool->p.dev, - page_pool_get_dma_addr(page), + page_pool_get_dma_addr_netmem(netmem), offset + pool->p.offset, dma_sync_size, page_pool_get_dma_dir(pool)); } +static inline void page_pool_dma_sync_for_cpu(const struct page_pool *pool, + struct page *page, u32 offset, + u32 dma_sync_size) +{ + page_pool_dma_sync_netmem_for_cpu(pool, page_to_netmem(page), offset, + dma_sync_size); +} + static inline bool page_pool_put(struct page_pool *pool) { return refcount_dec_and_test(&pool->user_cnt); From patchwork Tue Oct 29 20:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13855487 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 55A51209F3C for ; Tue, 29 Oct 2024 20:45:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234756; cv=none; b=AVC1gbZ3TLmM/Tp/8PK/jHystVV35pICSFl77c5MFGcoTrDcTbiqL7YC4lh13BdLxEJNJqWXyLw58Mi6rel2MOZ/FUVhECzDrSAldbcGz6najTRBn1p+fGax75zDDcHo4CnsdMxFxUoCIY8BhC6tpdQJchS4MoPMrmsyXofVr38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234756; c=relaxed/simple; bh=oxvcO/ZaB/lL61u8pEJ51NobI8qaVVYlrPTrDOUpHPQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MfMU0EMrNDM2N9oHcSEU+S1AWMFeCle1pNy/pYh0ATeYSWFh1HXQS0DAyQYA1ooVoXD7PTKb/P5t3ByOhDVS0nKxuhix4I6u8u1+5Hbv4Ar+GfGJDnvyzZIsStWfIEz0LvsxadSApoKRv0c4aUYVS96TXX6qOQCycYN/NHLuqzk= 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=pd8bUOpU; arc=none smtp.client-ip=209.85.128.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="pd8bUOpU" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea258fe4b6so31709117b3.1 for ; Tue, 29 Oct 2024 13:45:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730234753; x=1730839553; 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=pKjGAeVoY4GHFtcwq5banhGcJjKwOgTAegNaQaox++w=; b=pd8bUOpUpARD3tcU0bwU12p3PxGCDqoDAszXIIqwYhYs7Bqc7QY1iLPZUnZw2yGNyo liUPo980BUweJNRqeACnmtcMMkhI6WvV9VP+qzzEKJt/gfBBmJ9AaXnXowunn2QLiyXO /d5HBm+pX0YsX7sobJsvzOB8/fl1NsB3RUMeBol5EpE8V+EGt1GhvZors7y/0L2qSAje T3XGtUKjuUwqN2rucag9C0dQDTqWV5tvLCQH8Qu3mrnLUjylW3xO/GWqT1WNtZU9dCQC czSVTbLpIVvC7GOlMHnTgn/y2AXD6Hj1CABV3sjpA/6dnJoa1R9aq+fUSZnR0DAiAEPW EwQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730234753; x=1730839553; 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=pKjGAeVoY4GHFtcwq5banhGcJjKwOgTAegNaQaox++w=; b=JiSdI9dA9KRNBfG2SSwWq+3kTF3Eot2wIE0BhRkYxqPtvHpMFHcXJ8cd3Ned8v1E9B LMULMUlMFn8G1prNeeA4mnTTZJGP8Wf5y/9yRrA5iqjRFRcthe7JOdJfxnjo+vQx46UL v2rG99fKazAays4Auo8M2p5frwSYmeoeBhMn0Ji667jrjuGbUdu5a2dnjJZTTFqBajsv bybBASyz1wEb4T+WRxzrSPU25PphmzVL2glWZuLs7FATVF2+dgZVlmEyZSOuJ2sXniiG EulfyUV6z/ERi+0ZY0SNJDQocwi2T2fEpeHo/IN4uXQrJkfI+WYYJjge6zab5FpgKIzk ERKw== X-Gm-Message-State: AOJu0YyrMARm930com+W8WXcGA6xyNvZM+LvRz5aMKlP92HnMae+OKck Ajb81g455gMb5hxAUXekb99rS6/ryVtFBmQw33Uy0ZGZ4gPRVbov/UqcLZJILnxP0+0unLhAR4r bov1qBvzpz5wH45N987sOYSYsbQnukuT5TjEWAG3h/e522b1JvJQ6RaB9zlBsmKd/pGZX9HPgoM VsMgu7LSgW7nu2tgP9ynTVPJKH6iLUtvHyEBaQ6qR7YJmVH4piRZLoI93bgN4= X-Google-Smtp-Source: AGHT+IFriD3g24XyT1jM0DrGKfcuWZDYLvFnWpLS3cNOCFhL6xGL+ZOplvsxqtm8XLZC9n/DUx7QNPgLv1gz7vx1pw== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:690c:2c85:b0:6e3:14c3:379a with SMTP id 00721157ae682-6e9d87a71camr2100287b3.0.1730234753049; Tue, 29 Oct 2024 13:45:53 -0700 (PDT) Date: Tue, 29 Oct 2024 20:45:39 +0000 In-Reply-To: <20241029204541.1301203-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029204541.1301203-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029204541.1301203-6-almasrymina@google.com> Subject: [PATCH net-next v1 5/7] netmem: add netmem_prefetch From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan X-Patchwork-Delegate: kuba@kernel.org prefect(page) is a common thing to be called from drivers. Add netmem_prefetch that can be called on generic netmem. Skips the prefetch for net_iovs. Signed-off-by: Mina Almasry --- include/net/netmem.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/net/netmem.h b/include/net/netmem.h index 8a6e20be4b9d..923c47147aa8 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -171,4 +171,11 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem) return __netmem_clear_lsb(netmem)->dma_addr; } +static inline void netmem_prefetch(netmem_ref netmem) +{ + if (netmem_is_net_iov(netmem)) + return; + + prefetch(netmem_to_page(netmem)); +} #endif /* _NET_NETMEM_H */