From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DCF8606A322 for ; Sat, 5 Dec 2026 12:52:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=2QKnajHy; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=YA/q6DxN Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id E4F4F60663; Sat, 5 Dec 2026 12:52:48 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id CpPZXhr8MYlp; Sat, 5 Dec 2026 12:52:47 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org BB2876065C Authentication-Results: smtp3.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796475167; b=H8+3Ip744mfWG6svZQd+Gz2a704yujI8OUfr9El4GT2PXIF/uj80B4dKY6FuARcfl4Sg o5aVi9KXgH8vhM4Ou6u38TENvkzl4gwL7DYL1kWHYSX78vNZ1S4yYcwp34EaHnpinOYVE LgkN1WSOcZB3g0JZnvAvGcbnFjMnb5GC02gBhwbr6u+YLuCZQU+lDlajRCpf0BerlIuRn wlng0M6wOAxZuA0HBWSKhYN8xgVsBZM4h6zXXXvrrSr2f4JaOt6C2Gnu3d77jZh1c4oYm Lvv7AJaMLSzcL+f0qh0bzds8vdWWurk/TF2jlIMSmtq6wFgnFZaZRYT6W43wH0a2J/A== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796475167; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type: X-BeenThere:X-Mailman-Version:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:Errors-To; bh=maTIwvSCn+WwHEIpWN0thii3LzhrIw4sJSK9zqv+0JY=; b=gllAMVfRYaUB9L+nhcT2P5f5oxo5GP1TqwyKhCcjq09PiMKbXRUdm4pQSgjf13sEDqa5 AA4yx5m+gXogIQOgZRYg2Pjy4TKu1WnyxiGJeaM1tsHfH2axeFHldNCDZzcJe5cHhJ96w q/dLuzkCj7leJSg7qHdYeCH3W/4dSse6qh6G7OXIxuZQSVV+ej7Dv2qEpFcRy/eIUZbTN dMyVMLMFFZ28ObtRBuvxLEI9kMPBrzj1ANsTdWw69i1UWrnph1PEUtF4nm1ls67S08o2Y SW37AZhzV0REZ7NvD76f/K4IYmHlCFewBOkxzNOWRXgu50CNyk+ffF5Ngv5RpRCPBmg== ARC-Authentication-Results: i=1; smtp3.osuosl.org; dmarc=pass header.from=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="YA/q6DxN"; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1796475167; bh=maTIwvSCn+WwHEIpWN0thii3LzhrIw4sJSK9zqv+0JY=; h=Date:In-Reply-To:References:Subject:From:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=2QKnajHyWVEsCHRNqVeTEmUzmWEPTIAUHiG4+oUKFvnT+pVpiblOTsejbOJGYnaeA reKIPI483mHhS4PpIcdpQ7WYRXlqOIQhaO3PHazh5nAZWLIrxpifqt1xdof8FW5SLG lHNtyR2x7Kr7pBqDwtt38TxgzG+fWb+F8zSA9bIQ+u8gdSLBrGV6KhAGd2SPXSuKdw Ar16EAKtIiU9czx71JjgT32pibcKamqEgy485qAPDc2jjR4trIxOKKPlsAcpERF098 tViVQL1Hfzd4Ei62Cf4dR3R+oFdb6aoVte97DrzX8451EyHCMJ8JarahE/3kCdzdgO briHZfVpp5l+Q== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp3.osuosl.org (Postfix) with ESMTP id BB2876065C; Sat, 5 Dec 2026 12:52:47 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists1.osuosl.org (Postfix) with ESMTP id 6C0522BD for ; Sat, 5 Dec 2026 12:52:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 5B37A60657 for ; Sat, 5 Dec 2026 12:52:44 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Ibq-4qniEm0w for ; Sat, 5 Dec 2026 12:52:43 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org 1E9E360658 Authentication-Results: smtp3.osuosl.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::1045" Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2607:f8b0:4864:20::1045; helo=mail-pj1-x1045.google.com; envelope-from=3gqkuawykd9ogqjeuqckkcha.8kiejpah-sena9-h6jheopo.koqkoh.knc@flex--kuniyu.bounces.google.com; receiver= Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=YA/q6DxN Received: from mail-pj1-x1045.google.com (mail-pj1-x1045.google.com [IPv6:2607:f8b0:4864:20::1045]) by smtp3.osuosl.org (Postfix) with ESMTPS id 1E9E360658 for ; Sat, 5 Dec 2026 12:52:42 +0000 (UTC) Received: by mail-pj1-x1045.google.com with SMTP id 98e67ed59e1d1-3b3a74ee77fso1061415a91.0 for ; Sat, 05 Dec 2026 04:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796475162; x=1797079962; darn=lists.osuosl.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=maTIwvSCn+WwHEIpWN0thii3LzhrIw4sJSK9zqv+0JY=; b=YA/q6DxNEOJIgwrga3WlfsI6iu9EC36X2CPC8TPiJ1at4biKXGsCUUo1+m9mZYJQui PfXTYQag6I39Ef/xRAQ2Fa+VI3X24RMVWhv3ib8UoAlGZqCKlVTUARm6MFck28a86aZ5 TthGhss45lMdwMzKOpDkQz5+YFIm2WJHDWqGj+YtyVVvSA4m+u7ahh8ZSyyTL02+GBVw 1ORUmkKRgb3Hx4HDPSefYo55ZT/MZpnpHWAwUDmhLUtIYT/j9hWSzlBmEDTr7EwhB71g eyMIZdArstn78+/1hjhKJynBVJrKPhkMU8AQE55x3kLcL0e22NjR9S149oeqZW3M33yj fbgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796475162; x=1797079962; h=content-type: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:content-type; bh=maTIwvSCn+WwHEIpWN0thii3LzhrIw4sJSK9zqv+0JY=; b=OKxu4zH48ov0G+erpEuoUhw9WVahdi7eUrZ9OCbWooqIXAAtEaWuLRsvod0gnsqSMe J9sy629LaEe1c5peLRBWTah/CSVeHKi50z5/PUuWxj5+1uRTsT8Li1Y49nPHUTs3cFtg JAZhCuVrCJuflF7HHjjtSC2v74GeJp02+UOjd+BjQxwUe6oh35FpayVhn9+Sj6+gVdNe FPWazPqSbd/a2ZegS+pe7qmYeFgIUdrf809ysZAKrBnxpH4rZFGuyWc+pAMLzzRwHLYi bW58+IU19CFohnHKFp3vRDIkQ3I48vJYIi1yICjs35I0C2GdBpO/petd6wuW3hpl2RSb mbEA== X-Forwarded-Encrypted: i=1; AL+hErEe07sl8do0ap5wYH9YFbFt19hDtYvxXxMeJRoXf71OKrfwzH39uDALy+7Z92qehRkFKFR3Reop9nh/U5VJ1kE=@lists.osuosl.org X-Gm-Message-State: AB4q+uEQ+gKLmzqYjbeMuiFdJCKc53Crq11dW2+HZlErb9TPRMl3JX+w 1zIXRXD04BT+bLLeEa6Sg6F/I5j/Ai6qT3j/p7mGQxsP8K+c/LEO9mxEEs3AEOtJgpfj8MjUvew MdbnMgA== X-Received: from pjub7.prod.google.com ([2002:a17:90a:cc07:b0:3b4:e149:2f8]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4c44:b0:3b5:8d10:28b2 with SMTP id 98e67ed59e1d1-3b5e0680e67mr4426941a91.44.1796475161883; Sat, 05 Dec 2026 04:52:41 -0800 (PST) Date: Sat, 5 Dec 2026 21:52:22 +0900 In-Reply-To: <20261205125237.2290932-1-kuniyu@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261205125237.2290932-1-kuniyu@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261205125237.2290932-5-kuniyu@google.com> Subject: [PATCH v2 iwl-next 4/5] page_pool: Allow drivers to unmap DMA before returning pages. From: Kuniyuki Iwashima To: Alexander Lobakin , Tony Nguyen , Przemek Kitszel , Jesper Dangaard Brouer , Ilias Apalodimas Cc: Brian Vazquez , David Decotigny , Li Li , Kuniyuki Iwashima , Kuniyuki Iwashima , intel-wired-lan@lists.osuosl.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-26.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Drivers using PP_FLAG_DMA_MAP under an IOMMU DMA-FQ domain keep every Rx page DMA-mapped until all skbs release their references back to the page_pool. When many flows pin pages in socket queues, these mappings can exhaust the 32-bit IOVA window. Unmapping every page unconditionally once HW Rx finishes avoids IOVA exhaustion, but incurs per-page IOMMU map/unmap overhead even for healthy low-flow workloads whose in-flight pages fit easily in the 32-bit IOVA space. Let's allow drivers to unmap DMA before returning pages. Drivers must opt in via page_pool_enable_dma_unmap() on a DMA-coherent pool before allocating pages or starting NAPI, which enables page_pool_dma_early_unmap so the map, recycle, and release checks incur no overhead when unused. Drivers can track active DMA mappings via page_pool_dma_mapped_pages() and unmap pages early via page_pool_dma_unmap_netmem() once pressure rises. page_pool_dma_unmap_netmem() calls __page_pool_release_netmem_dma() to unmap DMA with DMA_ATTR_SKIP_CPU_SYNC, clear dma_addr, and zero the non-zero DMA index in pp_magic. If the netmem is still attached as pool->frag_page, it also detaches it via page_pool_free_frag() so remaining space is not handed out unmapped. page_pool_netmem_is_dma_mapped() and __page_pool_release_netmem_dma() check netmem_get_dma_index() after smp_acquire__after_ctrl_dep(). It guarantees that pp_magic is loaded after page_ref_count() or pp_ref_count on weakly ordered architectures (just a compiler barrier on x86) so early-unmapped pages are returned rather than recycled without repeating unmap. Signed-off-by: Kuniyuki Iwashima --- include/net/page_pool/helpers.h | 26 ++++++++ include/net/page_pool/types.h | 16 +++++ net/core/page_pool.c | 107 ++++++++++++++++++++++++++++---- 3 files changed, 138 insertions(+), 11 deletions(-) diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 28635ce9454e..cabb0eb7442f 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -505,6 +505,32 @@ static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid) page_pool_update_nid(pool, new_nid); } +/* Calculate distance between two u32 values, valid if distance is below 2^(31) + * https://en.wikipedia.org/wiki/Serial_number_arithmetic#General_Solution + */ +static inline s32 page_pool_distance(u32 hold, u32 release) +{ + return (s32)(hold - release); +} + +/** + * page_pool_dma_mapped_pages() - get approximate number of DMA-mapped pages + * @pool: queried page pool + * + * Counts pages that remain DMA-mapped by @pool, excluding pages already + * unmapped early via page_pool_dma_unmap_netmem(). Requires + * page_pool_enable_dma_unmap() to be enabled on @pool. + * + * Return: approximate number of DMA-mapped pages held by @pool. + */ +static inline u32 page_pool_dma_mapped_pages(const struct page_pool *pool) +{ + u32 unmap_cnt = atomic_read(&pool->dma_unmap_cnt); + u32 map_cnt = READ_ONCE(pool->dma_map_cnt); + + return max_t(s32, 0, page_pool_distance(map_cnt, unmap_cnt)); +} + /** * page_pool_is_unreadable() - will allocated buffers be unreadable for the CPU * @pool: queried page pool diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index 5306e34105eb..89bde9df0872 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -188,6 +188,7 @@ struct page_pool { #ifdef CONFIG_PAGE_POOL_STATS bool system:1; /* This is a global percpu pool */ #endif + bool dma_unmap:1; /* Early DMA unmapping enabled */ __cacheline_group_begin_aligned(frag, PAGE_POOL_FRAG_GROUP_ALIGN); long frag_users; @@ -220,6 +221,7 @@ struct page_pool { * on a single CPU (see napi_schedule). */ struct pp_alloc_cache alloc ____cacheline_aligned_in_smp; + u32 dma_map_cnt; /* Data structure for storing recycled pages. * @@ -261,6 +263,9 @@ struct page_pool { ktime_t detach_time; u32 id; } user; + + /* Separated from pages_state_release_cnt by slow/user fields */ + atomic_t dma_unmap_cnt; }; struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp); @@ -284,6 +289,8 @@ void page_pool_destroy(struct page_pool *pool); void page_pool_use_xdp_mem(struct page_pool *pool, void (*disconnect)(void *), const struct xdp_mem_info *mem); void page_pool_put_netmem_bulk(netmem_ref *data, u32 count); +void page_pool_enable_dma_unmap(struct page_pool *pool); +void page_pool_dma_unmap_netmem(struct page_pool *pool, netmem_ref netmem); #else static inline void page_pool_destroy(struct page_pool *pool) { @@ -298,6 +305,15 @@ static inline void page_pool_use_xdp_mem(struct page_pool *pool, static inline void page_pool_put_netmem_bulk(netmem_ref *data, u32 count) { } + +static inline void page_pool_enable_dma_unmap(struct page_pool *pool) +{ +} + +static inline void page_pool_dma_unmap_netmem(struct page_pool *pool, + netmem_ref netmem) +{ +} #endif void page_pool_put_unrefed_netmem(struct page_pool *pool, netmem_ref netmem, diff --git a/net/core/page_pool.c b/net/core/page_pool.c index d7c88c0b67e5..cf2afa295282 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -33,6 +33,7 @@ #include "page_pool_priv.h" DEFINE_STATIC_KEY_FALSE(page_pool_mem_providers); +static DEFINE_STATIC_KEY_FALSE(page_pool_dma_early_unmap); #define DEFER_TIME (msecs_to_jiffies(1000)) #define DEFER_WARN_INTERVAL (60 * HZ) @@ -330,6 +331,9 @@ static void page_pool_uninit(struct page_pool *pool) pool->mp_ops->destroy(pool); static_branch_dec(&page_pool_mem_providers); } + + if (pool->dma_unmap) + static_branch_dec(&page_pool_dma_early_unmap); } /** @@ -571,6 +575,10 @@ static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem, gfp_t g page_pool_dma_sync_for_device(pool, netmem, pool->p.max_len); + if (static_branch_unlikely(&page_pool_dma_early_unmap) && + pool->dma_unmap) + WRITE_ONCE(pool->dma_map_cnt, pool->dma_map_cnt + 1); + return true; unset_failed: @@ -697,18 +705,13 @@ struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp) } EXPORT_SYMBOL(page_pool_alloc_pages); -/* Calculate distance between two u32 values, valid if distance is below 2^(31) - * https://en.wikipedia.org/wiki/Serial_number_arithmetic#General_Solution - */ -#define _distance(a, b) (s32)((a) - (b)) - s32 page_pool_inflight(const struct page_pool *pool, bool strict) { u32 release_cnt = atomic_read(&pool->pages_state_release_cnt); u32 hold_cnt = READ_ONCE(pool->pages_state_hold_cnt); s32 inflight; - inflight = _distance(hold_cnt, release_cnt); + inflight = page_pool_distance(hold_cnt, release_cnt); if (strict) { trace_page_pool_release(pool, inflight, hold_cnt, release_cnt); @@ -752,7 +755,23 @@ static __always_inline void __page_pool_release_netmem_dma(struct page_pool *poo if (!pool->dma_map) return; - __page_pool_unmap_netmem_dma(pool, netmem); + if (static_branch_unlikely(&page_pool_dma_early_unmap) && + pool->dma_unmap) { + /* Pair with page_pool_dma_unmap_netmem() / releasing CPU + * before reading pp_magic in netmem_get_dma_index(). + */ + smp_acquire__after_ctrl_dep(); + + if (PP_DMA_INDEX_BITS && !netmem_get_dma_index(netmem)) + return; + + __page_pool_unmap_netmem_dma(pool, netmem); + + atomic_inc(&pool->dma_unmap_cnt); + } else { + __page_pool_unmap_netmem_dma(pool, netmem); + } + page_pool_set_dma_addr_netmem(netmem, 0); if (likely(PP_DMA_INDEX_BITS)) netmem_set_dma_index(netmem, 0); @@ -823,11 +842,28 @@ static bool page_pool_recycle_in_cache(netmem_ref netmem, return true; } -static bool __page_pool_page_can_be_recycled(netmem_ref netmem) +static bool page_pool_netmem_is_dma_mapped(struct page_pool *pool, + netmem_ref netmem) +{ + if (!static_branch_unlikely(&page_pool_dma_early_unmap) || + !pool->dma_unmap) + return true; + + /* Pair with page_pool_dma_unmap_netmem() / releasing CPU + * before reading pp_magic in netmem_get_dma_index(). + */ + smp_acquire__after_ctrl_dep(); + + return netmem_get_dma_index(netmem) != 0; +} + +static bool __page_pool_page_can_be_recycled(struct page_pool *pool, + netmem_ref netmem) { return netmem_is_net_iov(netmem) || (page_ref_count(netmem_to_page(netmem)) == 1 && - !page_is_pfmemalloc(netmem_to_page(netmem))); + !page_is_pfmemalloc(netmem_to_page(netmem)) && + page_pool_netmem_is_dma_mapped(pool, netmem)); } /* If the page refcnt == 1, this will try to recycle the page. @@ -851,7 +887,7 @@ __page_pool_put_page(struct page_pool *pool, netmem_ref netmem, * page is NOT reusable when allocated when system is under * some pressure. (page_is_pfmemalloc) */ - if (likely(__page_pool_page_can_be_recycled(netmem))) { + if (likely(__page_pool_page_can_be_recycled(pool, netmem))) { /* Read barrier done in page_ref_count / READ_ONCE */ page_pool_dma_sync_for_device(pool, netmem, dma_sync_size); @@ -1041,7 +1077,7 @@ static netmem_ref page_pool_drain_frag(struct page_pool *pool, if (likely(page_pool_unref_netmem(netmem, drain_count))) return 0; - if (__page_pool_page_can_be_recycled(netmem)) { + if (__page_pool_page_can_be_recycled(pool, netmem)) { page_pool_dma_sync_for_device(pool, netmem, -1); return netmem; } @@ -1063,6 +1099,55 @@ static void page_pool_free_frag(struct page_pool *pool) page_pool_return_netmem(pool, netmem); } +/** + * page_pool_enable_dma_unmap() - enable early DMA unmapping for a pool + * @pool: page pool that may call page_pool_dma_unmap_netmem() + * + * Must be called on a DMA-coherent pool before allocating pages or starting + * NAPI polling. + */ +void page_pool_enable_dma_unmap(struct page_pool *pool) +{ + if (unlikely(!PP_DMA_INDEX_BITS || !pool->dma_map || pool->mp_ops || + dma_dev_need_sync(pool->p.dev) || + READ_ONCE(pool->pages_state_hold_cnt))) + return; + + if (pool->dma_unmap) + return; + + pool->dma_unmap = true; + static_branch_inc(&page_pool_dma_early_unmap); +} +EXPORT_SYMBOL(page_pool_enable_dma_unmap); + +/** + * page_pool_dma_unmap_netmem() - unmap a DMA-mapped netmem early + * @pool: page pool owning @netmem + * @netmem: network memory reference to unmap + * + * Unmaps @netmem with %DMA_ATTR_SKIP_CPU_SYNC and clears the stored DMA + * address to 0 before it is returned to @pool so long-lived skb queues do + * not pin IOMMU IOVAs. If @netmem is still attached as @pool->frag_page, + * clears @pool->frag_page so remaining space is not handed out unmapped. + * No-op if dma_dev_need_sync() is true. Caller must have enabled early + * unmapping via page_pool_enable_dma_unmap(), ensure no hardware DMA remains + * pending on @netmem (including other fragments of the same page), hold a + * reference on @netmem, and run in NAPI/control context. + */ +void page_pool_dma_unmap_netmem(struct page_pool *pool, netmem_ref netmem) +{ + if (unlikely(!pool->dma_unmap || dma_dev_need_sync(pool->p.dev) || + netmem_is_net_iov(netmem))) + return; + + __page_pool_release_netmem_dma(pool, netmem); + + if (unlikely(pool->frag_page == netmem)) + page_pool_free_frag(pool); +} +EXPORT_SYMBOL(page_pool_dma_unmap_netmem); + netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool, unsigned int *offset, unsigned int size, gfp_t gfp) -- 2.56.1.915.g69d5ec7298-goog