From patchwork Thu Nov 7 21:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13867182 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 DF229217F38 for ; Thu, 7 Nov 2024 21:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014598; cv=none; b=GzHh358bPbBiOcPvcYmShnbxcPgu9kSaWKDKVmfP6Oufnb4S8Mn22riBwMtmukSgaNgfv3p+7CeE2EDJrfe6DZ0aMye5RqtXpRjxHzt6p+P4bTSzz1bbOY9GRiAHuCuJkdzJ5zpkzf3JbG0xSJmdobQAom288/FVyZdbGo2w0Bo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014598; c=relaxed/simple; bh=zU771VywMfhHaMQg5hypX6J21hCCKxI+7oDPusRKQbo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NMQWYN0RPjxLuNvFOYYdRuJQV8peh9UfX6RmhL+W7X/dBGVskun+XTWYApY/jiOUeeBXQ7lGvw+YBMf0raW/koqrNRTkK4p34oySAPVV2eOviPtOolTo1jm2hFtQYOrakn5EXyNEE51927Pv2aD+qcPZn+3oVfo2nsQfLAUesac= 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=kEXhEdqJ; arc=none smtp.client-ip=209.85.219.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="kEXhEdqJ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e297a366304so2298398276.2 for ; Thu, 07 Nov 2024 13:23:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731014596; x=1731619396; 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=HAZq9oy6Bl8obMNqEnRNBAotywvY9gCvI9My8ktbfNI=; b=kEXhEdqJaNPGNjReXtFogjSarfC5FImDYl44aTYtzxhYAS3b+GVDfrIceX+XpmHISZ AHFm4DCvPvvizFe2JSttuygckm9bAFZ/Zdb7nxKBm9ElExcFMtI7DIVi68p7nmbl14JG GjvdgS59x5S9A0ny6DOfsqt6c0WwehYQMQdHcAyG458DkeEF/VOgZIBHAXCCcO1wSGYV RnCo5ZGhwRI1cKQb/Tv6AKUKvzghVsUD0+YZ4Bp7ufBLUFdX1GaOFQnnoCen9J0+kjvu h1lSsLCe5jcXTU9xA8x6JWMFJrwRh3FrtMHA3BGLK1a7AgzpHYrDOxWgiFjEwzXGDRI3 NAGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731014596; x=1731619396; 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=HAZq9oy6Bl8obMNqEnRNBAotywvY9gCvI9My8ktbfNI=; b=pPZHJ3YEQricLXR/g3boPv+/fQmE4AU6ruXDECM7WtCDmN0gg/EFEe3uB70ty0R4Ma 06F0L8enFgSVzz63+uukSJ4kXt65/YiNwPRiWO76e37LXpThe92X9t7Y4cPdm+hAsPlC W28S46tRuC8z9StHKCz3RJqQvjVXJ+OImAvhABChtBChl6o9Aeqv4mHdMsBD8sTwwBwp po8Ceii2DaFXXeBKwTY/OoaZbWIVbYxTtlNjVpqSMG58JonjQvBG32VD+eKO+sprvHHc CxIQcldZIJ8Q8wIyZJBZgxqrgcbCeaM8IHc6F0PaJP0S15UDGTk4xksdbBPFPBRZWqpX MMJA== X-Gm-Message-State: AOJu0YwerV/6a+g41+NLuPnvcACxdcFajXCFmVA7k4WS9mKiKjzf6U0m mh7gD64KnmsGiy21bOIKTm5Rlko7BqT+gcNI8AYbBMgJ345QT0wxfKTHQ4AQnK5ENf6SG9aylmE np0GAtio16dlr73tEW/hKmkQv0+rdwzcpRsp1LXpAqwlILfTBZ72afykQwJh9HJvGh+aUiFBJM1 nua+Q8SmiG5uwiAfz//9pAjAKzSrCxRntCMGd1XrXwp+LoyMJdasatzh6BNkM= X-Google-Smtp-Source: AGHT+IFpZz3joBko2XoXlKijEWXBVEsSKlDAhkhOb9gDzyhStaeTOBcZzdF/pwUDd8RiQ/Qt/WPqhvbOJCOQ6hJZQQ== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a25:3302:0:b0:e28:e4a7:3206 with SMTP id 3f1490d57ef6-e337f8e44f5mr795276.8.1731014595774; Thu, 07 Nov 2024 13:23:15 -0800 (PST) Date: Thu, 7 Nov 2024 21:23:05 +0000 In-Reply-To: <20241107212309.3097362-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241107212309.3097362-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107212309.3097362-2-almasrymina@google.com> Subject: [PATCH net-next v2 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-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas 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 Thu Nov 7 21:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13867183 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 A9A81218931 for ; Thu, 7 Nov 2024 21:23:18 +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=1731014600; cv=none; b=u49NxiynUfEO0eGz1OAmG2/xc4oL3bXqNS6acmly/5CuQuyNyNU8kie6CSCXAn4NFmgJ19qVzSnqmxA3EFJIulkpGIPoCaLE9J6CxIecsIlhtqnhXGZfVvMHj10a4vxNMx6T2pfZ41wJ5TbabAbn6GkNJcZq6kXk3uq0LfSdNbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014600; c=relaxed/simple; bh=MvJ6yPQOrI6wahZADxfSEp4jdMsiVlhVUJM/vAV2fS4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tycwDyBUiZz8fj5/YNbnCPOwwU7Weg0i6nV6PFmAq5c6fmwMuS18lPkhdCnbrhBWf+B0fuhAnohq9g6p/2T/EgjFg1tkkElosxGlfZC4c/mr1dGCWKIhqclohuOji7SI0D27UxU7q+t/QBfsK4EbIkzXM69OFAUvZ1XBI6JGPYk= 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=VvvZHTSc; 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="VvvZHTSc" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3705b2883so27310657b3.3 for ; Thu, 07 Nov 2024 13:23:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731014597; x=1731619397; 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=J83wfJiF0JQ+3oVDQ8yXRG5SdUbkoDbY+HbVcbuh1Lg=; b=VvvZHTScGjBhZdgsuFEa93EhYKmmQxRdWkoHnY328/p+Ll5mw+hP1n1OxjoILI82XN o3oaxBgILqZ4HJXJ8xh6E8e+a7Ypg/QqIO5YrhNwUQqZEKRQwF0qY7ZriSSwajZAkgIf KsUyt+Yaw1gRffdhVO+xkhS1PpUz8M/h0uect80zoz+LiiLcUe0UIyibCu0gfegDPw8c ISiTFd2I7rgWQyXVN7v0GIlcInJ4f2ueJL/LFNklTlppHhosoinG5cg0rbjU9sVhdlXA hvGZlbObGURLjMpWSyst+pA1QQBR4lS1+z3lrT7N1f66r/Ey/phKRbCW/uh7nyJnJj6F TEYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731014597; x=1731619397; 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=J83wfJiF0JQ+3oVDQ8yXRG5SdUbkoDbY+HbVcbuh1Lg=; b=Be3JrOs7khm6smkD3DKQZonr0wJcYE4lJjzUMXTOPLMj+6Komo9xc7jpewypoM/NkS w41RL97kOYk59WEhSS/vee4Ym2ztf24BUT1DMmwdBuJv36FqHCyQ1xxt78D08CxSNcqz OEgZdslYJajraVe+hY7SytPjb76tl+7Jfa2D5qIURl2inJHeUIniwCg05HPs8KFOYDAp xnj5hkAbTfI6d3Sq6zzHNEoEeR4fVPDGU9yn8D0HCLDFSgt6c67ODlOoHXAAmwNgq0wQ KLYmog1yOBJ5y1tOM6zLjNnYSPo+4pk9YuqCqz5jQjKnmYUp7hCAAfxRE4FLHUHLFHbR ftTw== X-Gm-Message-State: AOJu0YxM+reRpYZHImCG7TPHEXippzEbpMVQ4Q6hnykzfddGYMGjakay 0uQxftyXNvyR2Rt/avVqDS+AUSoAX/UqKHsB2rp6Z3f6YgfyKN8hGv60yXkN3sKEsAikQ+xioPo 9aiuFUvoG1u61fjHIH+/0uFVUrb0vKs9XIDLhFGd+q8nlfeMzwGGBR9y9SVNkKsufNWILw4lpC7 qJZ+xxcsKAdZXN9uTP6vBWG3dI4bl1bK7OPeX5+LHxxgH5ye4KqOb3506DTyk= X-Google-Smtp-Source: AGHT+IF6z/QPQ1XLZAvWGreuIWIzXwrgafM/eQRgTmOxVD278ef+a/phPaMZMGyLfa6rqPGjMSbh4Q8VmdUVJC+pTw== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a25:a249:0:b0:e28:e510:6ab1 with SMTP id 3f1490d57ef6-e337f8faff5mr344276.8.1731014597352; Thu, 07 Nov 2024 13:23:17 -0800 (PST) Date: Thu, 7 Nov 2024 21:23:06 +0000 In-Reply-To: <20241107212309.3097362-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241107212309.3097362-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107212309.3097362-3-almasrymina@google.com> Subject: [PATCH net-next v2 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-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas 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 Thu Nov 7 21:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13867184 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 6885E218D8A for ; Thu, 7 Nov 2024 21:23:20 +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=1731014601; cv=none; b=WTpOKzZI18/2Spcx1/SLyuULZWBE6exLtsO2XBlw2etVvWUSXK7Hu8yzx35yK1wR2NbTla0Er4jOugU4vsG/hp3Cw2ZBaVZzTMxThSX4tu+ok3HYe5gPiafKFkLERCQUUOEVFuBsaPTOlPnUDvBa6tgzlUy2uQRfJp+7i6jPoGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014601; c=relaxed/simple; bh=ps8g7aS9YWdHiljpOSe0iIE7Rn7tIj0JNhfoyBSlYao=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=j0o9Gwz+OOP1pQY67ROKURbgJaZidW69+L49qzmUI8kuxS5ULALYiYbWghCGVOqzC/EO8Di3lvkXIJkylfOrMk8PTN+eqIYWPrpMIkKOzGFJshGhV/zvR8+1A26a9LosLVgQ27huqw9RmoSlv91N29x3cL8IGkh8kWpJDzsvMuI= 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=w3Iu36X/; 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="w3Iu36X/" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e33152c8225so3078295276.0 for ; Thu, 07 Nov 2024 13:23:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731014599; x=1731619399; 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=x+st140tRnSi1hqWlJmll4Lhmo3xu0I4VHUB3oVubp4=; b=w3Iu36X/yN/uxVBPCA0bVFgUHHngQwmlQbGeDD5IQUWdRRQwbPr9u7EERMWBkTjcrU czdE26k7JQmthwf5YdeYXKccOoYarRNkLO+dvgyzye8aJFEUZu8+xH7/o7ujiY7ZYE6o +sb4WeqZ8xo0Xjcp24l5F6oh4TdYWJi9xNBtbJG3UCw41HQQAggUbsggMULH08IzqB1p /5ISuwFpbzX7lOe2DasET+M8J1FRQIubFA4/rY2I5Cq20LeDJ7OEJreTEng8IOFH9OT9 dZlhEzOXZ2Wb2Y82FPh7tRoeIlTcWHQRPxI5iTkldRF7HCZj86QEccWnMR27mzlQ55Oz Nakg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731014599; x=1731619399; 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=x+st140tRnSi1hqWlJmll4Lhmo3xu0I4VHUB3oVubp4=; b=c2hXIXVhnPgWi+KACWQGysXhXftrFs+luTI5KpbXm+/vZ5oeDc5cFjqcfRb7hMe97I iLvLio3nUIqBKVBdp8jj975KYTv6AoOEUTnfs9nDN2CBhoA1FiFQLgCFo7BzibC7yevs +mx+dyg77kC+iNmChZzM10lpKDKEpyZcuvolrG5I6mdTfYCx46nTLmGkJbqJOCE8zuK9 9WOrcfFZ/AvcKoEDiOA6VXPz0qp+RcDF1aZbXV8MSYQk1PYvCw422iVyQHo6b2LOitUe kZzFHoUmAPCPPvrhonLcHYG0U3I4LJSRyIUou0jeCDmyMKfXEuGpdSdWcDnbsn33Airb JJnQ== X-Gm-Message-State: AOJu0Yy5/1a8ENZMzY64VhGquLikdWKtAwZDnFCweMG+I96+4fs2+fVC GBqfcvSWdIL0zMnwmVzuXiJG0V68wZa5yKsaT/yTe+3iQM1fi8uONsWWH+u+GqZsnCn0cgOvCBw TB6rN0yXHo3SgdeyBHn3pa9PWhFgMyTrkOXtFVJswT8qVxnPA2Z/3cb+OmXGly1HQMzVy1pPBmf CrkoKkoehY1BKxv1NIUj/AxsVoHekzTMaA+wD2x0v8Q8pQ1mSuaKJ6A8j+jYE= X-Google-Smtp-Source: AGHT+IFgLUXTW1oofpX7j+3fjQdPt6Z3JBpPD3P1QknlqjCzkBELvb4f5iD7diwTeje1LMy4ccv21eNPv4d6rFfFOw== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a25:dc4a:0:b0:e25:5cb1:77d8 with SMTP id 3f1490d57ef6-e337f8ed8bbmr319276.6.1731014599186; Thu, 07 Nov 2024 13:23:19 -0800 (PST) Date: Thu, 7 Nov 2024 21:23:07 +0000 In-Reply-To: <20241107212309.3097362-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241107212309.3097362-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107212309.3097362-4-almasrymina@google.com> Subject: [PATCH net-next v2 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-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , 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 --- 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 Thu Nov 7 21:23:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13867185 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 1E3902194AE for ; Thu, 7 Nov 2024 21:23:21 +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=1731014603; cv=none; b=MSEekE854gFdggiKIwFiqCuWOtukQCCV/p1MsShcxGt/nrxiwkpCYRpgVOCi5g4SjikP/NJFE8Cma42RLdF2Uid/W9y+ilYgys/hW52dUfp3eJKGDxRS1A4MBdivZ+9O/LIvMlVc/XseX60a5+k82ioPPpyRZRUaKUUznAkm1mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014603; c=relaxed/simple; bh=m8IdxZqUwMqRC2HMh2bTKic9Iv2zEBl6lcyJNuEk5WE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uLGmPDC209MswOuQQ19LqgCNTfMmREH7fhl6rxDa9Az3jt9ThhnY0xaAs55UCZ88US2v/52gxdXSoq12Mm920az7b9E0/hs2YX07qvBRSDP6+0XB6ITSH56Vi1klNWwgQfRW/juMNTM9cA2o0OrpO5UuYDaqGcGHlTAd2BKFiII= 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=DRtMRll6; 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="DRtMRll6" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8a5e862eso18644897b3.0 for ; Thu, 07 Nov 2024 13:23:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731014601; x=1731619401; 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=Aiw631cVYF88tA3jMsDP51zKCtA5BveE1WXlRhKkO9c=; b=DRtMRll6XcMEv0/zWo3jzBOx4/oJy3DMVJmP3QOnigu9qvYLzwkZihnV8bhc07ow84 2bupM3LBeBYtnus26kQQsCXM1KIvr7gXpuox6P/QkIrsxO6kDyW4SyuHYzctK5OEqe0r W0gH9yV8zPrifwEy1xD9W66CVtoxgTBqy0VtwqzfCFU4YUIWxw9lFR7jv/gAcgqwas9U j2YjCgLJyj1p2ZXIOII8QiaMKhW/xux/G8zn7UGmLF22Fm2iX4FmzFy3z+588iPJGPCc nS+YouO37ru0efKXTL+iAM8BFHnlVUqUMZa7avMV19b5Nmen7FJaqsugGsLvJA8/ioTZ l0+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731014601; x=1731619401; 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=Aiw631cVYF88tA3jMsDP51zKCtA5BveE1WXlRhKkO9c=; b=kxek5P7ILUqiN3ciDyvhmMi0LtlN93ulLj65UoM5VwYa9GXvQ8ZBw7FzM0F8npU1DP mpjs9v7m6FSBOrq2HXhfoqjpdoqlh53EQEEAuikOSNjSeVhzgcwCc1GaFcKRLRwvjXDW /txdcQnO6rBPpggUpuXA1ZW8Fabaeo+P5FqOm23cvHogznWNPPcwKBBSjGR3AnbMs5lj UnFahz16jmqvnuap7/lcFSW3MZnK3kAYX7G3lPDPG6G9kkuFt5oZOTPJMwkmt89pur5+ k+9Ccju2XmJxkNvE06oPcUFARd2cO413lp8f5j4vOLoicvNNNwEX0YOT/eiZoCRiBM/1 G6AA== X-Gm-Message-State: AOJu0YyzwlQpmfEd7YpKaXl21pq7OghSqytb4zzK38LakdEhWA8Amhdu B4iidoUN9TcjH6Kv5Y5k9zJDEPr8H7rxA32UIH6UMEm/rF19JQN6gZeMNqD/dQxZ1qI7ZK4Z9FR bKlwiTvK4wkvHVwL+rzSYu5fzfVfXP63fdwXTno59z2rcTQzE5JHC0MU+X/jemJbnbjj/D1+reg 5hZpIWt4loWnKsmsNtOJPzjqkdMpYFYW09js81MuKFjvXZ2me8caV1/IOWmdc= X-Google-Smtp-Source: AGHT+IFcD/DvotfYM+pVSvbUUM61OCX/CMwJjo9lQAnn7vXUnCYSFqjVZ5LnQgBS3mPiwUW32kp2i4JkBRuWazqvLw== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a0d:e545:0:b0:6dd:bb6e:ec89 with SMTP id 00721157ae682-6eade40bbf7mr39597b3.2.1731014600825; Thu, 07 Nov 2024 13:23:20 -0800 (PST) Date: Thu, 7 Nov 2024 21:23:08 +0000 In-Reply-To: <20241107212309.3097362-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241107212309.3097362-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107212309.3097362-5-almasrymina@google.com> Subject: [PATCH net-next v2 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-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , 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 Thu Nov 7 21:23:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 13867186 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 E102C218585 for ; Thu, 7 Nov 2024 21:23:23 +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=1731014605; cv=none; b=KQDo/ImZnQSGb0yTN/R0eM8rNA7WeiMnk9mK/mfHmZmQIe1I2H8hrbr9wg9KmJgthNrRowEneNQjaNsqEOPmZLXGXySoI20OzGqPkOE7vc4b4h7RUBh08VE1zYXS4MzN6J9J1pS952bD1Z+EFXnebcNB74V2JzteFZudNQCSBak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014605; c=relaxed/simple; bh=hiLF67ZB3WMU8hX4LaHsXxF0Pkp+AKd2y1OkKzs23ts=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gX85dHajwBTWbHi3fw6oMUo68+Gg/3BGnu+6WVgfEwU4ehu6vuzxl8NcBF6u6X6D1GPIZlKft7JcoNHzY+gV3TWt6uuc3Ycfl3gTC/e1VLn9xA8TlcP6tQRNVzdyKrYDjbAL2FO2pPP0/OX1OY6ZU52e77tL7esyZma9rZ9V+kw= 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=vJa0EmOF; 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="vJa0EmOF" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e36cfed818so22348287b3.3 for ; Thu, 07 Nov 2024 13:23:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731014603; x=1731619403; 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=6k+P4diOLJqi5qBWB1cI5BvWrqmmxwXAHcITy5id4XU=; b=vJa0EmOFM2pai2ANMhzEIr9wzti7adtD5VQ1slkq2pc+aMhCGJRn6MHWUcUS01pTPr q5GsCJY6HnbLx8S9dVwJ0IuzFcAAj/G6ud8piEMRW3Mh8LetO/Vh97Ekrs6HYO0ksNMD kEz3AE5wCUf7DKmb2pBnxn9NyAb39UR+c/hxwKbpRtbfxdPyJa/DO9Tr1JmnPlsfmen4 AORPOMEwr8ZxJ8SW/vbBLSMDgAt/pxw+X6NEYIr3O5Orbn4/stTdi3WkLy8klHABaqN/ yHE37XGbMKC7SJLzBUe5/NLNXLrGk9BhJg7ItwHNRpIggCcA/4GSFdOn5lafUgdWM9AQ JIdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731014603; x=1731619403; 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=6k+P4diOLJqi5qBWB1cI5BvWrqmmxwXAHcITy5id4XU=; b=mPUW9c1bCpSgB833p28gW3FtSSowgA7VmCEwDngPdUtmwmuU6TfexQ6AukHcUfSNi8 E7iyGNVnaoTLIc5X71impI5z0fH1S6kAoZTrixIEzRzszLiGE/c8d7RQrxJawa6lMDeu vXDEd0KTv3n/WAt26lRigf5h29HP7JEj8x2rjBrs8uYvTWSQXaKPWzZDsK6j7J12eZ/m rocEGC5Nzok19pxsJaslbf38F9wEabE3pdMGJEzri88Cf2iDbBbHjEU7aTAyrCFLjN0B 5+nDxzL2YxmjsmDmK9xFZrg+wJImEqZzYIlPjwPQm/M/sbYTMIyHKBT1VYiwq57T2Mfz XRYg== X-Gm-Message-State: AOJu0Yy3Re7l4mZwlFTcOQ7TxfhZO2YpN+QgEJniZ21Uqd5vb1jnC0RK Z5xmhCdTy4070ED4rkvWx55+9Zdv6iJ0PhTzH84+10crj1vHxiB4SHaTFdfXDU6KrjC86K9Me1u v0pkxbnOdtuWd5NGKpFagQSciFufGmxurKdh+v8baZDc6o/Kp8FBYkfPr6TCJlbfNBUNNNfLAvn 8lY2wkpaxWHPHCZoWpFgtZ5UcswBkghmrWdqj6v9szVxMe1SH046eF1mXduCY= X-Google-Smtp-Source: AGHT+IF7xrqtzpYezRtSKaHI3uuKF4iJovh+7+L3DoGZk9NlkYM7SwDne1PSukpRNI4o5wYpQPfuw2lzr3HDcb/9AQ== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a0d:f4c5:0:b0:6e3:2693:ca6b with SMTP id 00721157ae682-6eaddd64226mr13067b3.2.1731014602472; Thu, 07 Nov 2024 13:23:22 -0800 (PST) Date: Thu, 7 Nov 2024 21:23:09 +0000 In-Reply-To: <20241107212309.3097362-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241107212309.3097362-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107212309.3097362-6-almasrymina@google.com> Subject: [PATCH net-next v2 5/5] netmem: add netmem_prefetch From: Mina Almasry To: netdev@vger.kernel.org, Jakub Kicinski , Mina Almasry , Pavel Begunkov , Willem de Bruijn , Kaiyuan Zhang , Samiullah Khawaja , linux-kernel@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas 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 */