From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (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 B8F5A606A322 for ; Sat, 5 Dec 2026 13:15:54 +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=iDL+IM6E; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kTyv/Z2G Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 9860A409C3; Sat, 5 Dec 2026 13:15:54 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id StNq2DhT2rEl; Sat, 5 Dec 2026 13:15:53 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp4.osuosl.org 9C2F7409CB Authentication-Results: smtp4.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=1796476553; b=fTPulNPqH4CizPu/29KTt5EI/n/KD9BqLW9i1rGsKht2QI/RWLPp3/TFd9YfI/hZBRpJ EyjbVWaJuvV+ix5g0fYKd4TLr+izcEjkUQ+YPXZwlvxGbsk+FuSyaxgxloIkexwfMVmjZ hJhSdu3FVkfWog4hRXRYWYF+65VC8f6/wLDiQlXFns3+MgdsUvrjGPYw9+dR3a7Jtnk/3 sZrcAZm52elixKmUo+vupMZjj+J5ctRCO/Lw+0WIhmc1HEVC29SzgG9SUoJIFoO0kDIGI 58WipuBU0xhxIchN6Ba/Jbvvkn9YDM1j9rJo3pcJH6oaaX6SbqxPtGm9yUpxDJ53dmw== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796476553; 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: Received:DKIM-Signature:Message-ID:From:Subject:To:Cc:In-Reply-To: References:Content-Type:Content-Transfer-Encoding:Date:X-BeenThere: X-Mailman-Version:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:Reply-To:Errors-To; bh=WdnrNOvftbJd3GIxUAhrfCmyHXIC2KZVekN730ZaOEE=; b=Wc7dXR7AOaOApIXY5bNG/80uDiE+2no906We+Y+VURQibiVa376RsIEnsld1gEZENZOM YwekZWRYxpC39qvguvwJNYog5jNjh+dB261zf4Up7Y6sib2nuAQRt82H5YqXuXdxOw+tq YyCa5q/nqRf+Itxk2lMfE6jfQuFK/jA0uJUb6i5OO/CBF+R0Z+XLs/mEvNWwHKzZ5S4o5 9chqhKdDbsBo4L5bkYtmx1s43f2mpEOmWbPXxUTqfzpEq3zVWaWSlEFcW8O0TqMfjP28l NJyzk/M25MhYgBq7ypgVD58JXsruswCX3uO7Wp3RkHdKqhoODwZJ2ne4XsyCM6j4WgA== ARC-Authentication-Results: i=1; smtp4.osuosl.org; dmarc=pass header.from=kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="kTyv/Z2G"; 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=1796476553; bh=WdnrNOvftbJd3GIxUAhrfCmyHXIC2KZVekN730ZaOEE=; h=From:Subject:To:Cc:In-Reply-To:References:Date:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Reply-To:From; b=iDL+IM6EKLavSQETiNdNeCWEi7azHFQ3DAzfSZ+eHH7gttAQ8CjlIqy1YOprlRUxx yexl9JeHjR0K7KOj3I89KigiJphhNk6RaRHfPQB05s7yOZkiGa/ohcAr8KI0/Rew7q mThzNQfHVKN2SZEJqEZnyhIJjgbp8Ae5OD5KDQehK5/i5mNrigG1pBLAioGCC9e9sM +1yMnC61GhToNV3teq/pqErZQP5s1M4WZ4BjNIDXQI9ANhnxqLGdxGH434L6hwKzFG 36ae4xpA0h76b13QmBBWFwKw0M2KJM3Zbj5G8HcqF5LgqReS3opp8kmhwAjCxg+SG0 6zCdsCY7TIgHg== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp4.osuosl.org (Postfix) with ESMTP id 9C2F7409CB; Sat, 5 Dec 2026 13:15:53 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists1.osuosl.org (Postfix) with ESMTP id 854FA158 for ; Sat, 5 Dec 2026 13:15:51 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 767F5409CB for ; Sat, 5 Dec 2026 13:15:51 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id cAbBTEYhqNUu for ; Sat, 5 Dec 2026 13:15:50 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp4.osuosl.org 54A38409C3 Authentication-Results: smtp4.osuosl.org; arc=none smtp.remote-ip="2600:3c04:e001:324:0:1991:8:25" Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2600:3c04:e001:324:0:1991:8:25; helo=tor.source.kernel.org; envelope-from=sashiko-bot@kernel.org; receiver= Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kTyv/Z2G Received: from tor.source.kernel.org (tor.source.kernel.org [IPv6:2600:3c04:e001:324:0:1991:8:25]) by smtp4.osuosl.org (Postfix) with ESMTPS id 54A38409C3 for ; Sat, 5 Dec 2026 13:15:49 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 2D86E61380; Sat, 5 Dec 2026 13:15:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C85311F0092B; Sat, 5 Dec 2026 13:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796476548; bh=WdnrNOvftbJd3GIxUAhrfCmyHXIC2KZVekN730ZaOEE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=kTyv/Z2GvF5rj4UQG2sJ0bZmQeaKQLHyetvYtCPcMw4Q8RrCMoACGYyMwwmK6vWsC cE3KzVsq8+N9F5qLcjel3jAAdmE/l/BJxy+LuCz0+R9kONBAqVH6SXx+IiPdZxHVBL D7M3iB2oo3T5Vw2Ddkb4Hy1hFYxLPA5VdM8ZFJR38Rtjl5s1EmvmjMoJiZ0I+V0GJH kR03RhNVGRItsLp9uw2zKzauJ3673Mr5Ar+1Kv4C5ejX/behKwgEoW4l8zXsGOgmK2 dHoHL4RyL10hzNZWmttJPlkI7TweHmnGPQoj3JylrqwIni8aLJLUTKoRgcWJFEK5Rh U/U7v4YK3PURQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 iwl-next 4/5] page_pool: Allow drivers to unmap DMA before returning pages. To: "Kuniyuki Iwashima" Cc: intel-wired-lan@lists.osuosl.org In-Reply-To: <20261205125237.2290932-5-kuniyu@google.com> References: <20261205125237.2290932-1-kuniyu@google.com> <20261205125237.2290932-5-kuniyu@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 13:15:48 +0000 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: , Reply-To: sashiko-reviews@lists.linux.dev X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_PASS 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] page_pool: unordered dma_unmap_cnt increment risks UAF on pool destroy - [Medium] page_pool: dma_unmap_cnt shares cacheline on 128B/256B SMP architectures -- commit 478e1772cca7ebcaee62ee863cf1ca0ac47a1dc8 Author: Kuniyuki Iwashima page_pool: Allow drivers to unmap DMA before returning pages. This commit adds opt-in early DMA unmapping to page_pool so drivers can track active DMA mappings and unmap in-flight pages before they are returned to the pool. > diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h > index 5306e34105eb6..89bde9df0872c 100644 > --- a/include/net/page_pool/types.h > +++ b/include/net/page_pool/types.h [ ... ] > @@ -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; > }; [Severity: Medium] Can dma_unmap_cnt still share a cacheline with pages_state_release_cnt on architectures with 128-byte or 256-byte cachelines? struct ptr_ring is SMP_CACHE_BYTES-aligned, so mp_priv begins at cacheline offset 0. On 64-bit kernels, pages_state_release_cnt sits at +40 (+32 without CONFIG_PAGE_POOL_STATS) and dma_unmap_cnt sits at +120 (+112), so both share a cacheline on powerpc64 (128B) and s390 (256B). When early DMA unmapping is active, the NAPI CPU updates dma_unmap_cnt in page_pool_dma_unmap_netmem() while remote CPUs freeing skbs update pages_state_release_cnt in page_pool_return_netmem(), causing cross-CPU false sharing. Marking dma_unmap_cnt with ____cacheline_aligned_in_smp would guarantee separation across all SMP_CACHE_BYTES values. [ ... ] > diff --git a/net/core/page_pool.c b/net/core/page_pool.c > index d7c88c0b67e53..cf2afa2952827 100644 > --- a/net/core/page_pool.c > +++ b/net/core/page_pool.c [ ... ] > @@ -752,7 +755,23 @@ static __always_inline void __page_pool_release_netm= em_dma(struct page_pool *poo > if (!pool->dma_map) > return; > =20 > - __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); [Severity: Medium] Can this unordered atomic_inc(&pool->dma_unmap_cnt) write to freed memory when the last page is returned concurrently with pool teardown? In page_pool_return_netmem(), __page_pool_release_netmem_dma() increments dma_unmap_cnt after xa_cmpxchg() unlocks xa_lock, and the caller then updates pages_state_release_cnt with atomic_inc_return_relaxed(). Both atomics are unordered and sit on separate cachelines. CPU0 (last page return) CPU1 (teardown) page_pool_return_netmem() __page_pool_release_netmem_dma() atomic_inc(&pool->dma_unmap_cnt) (delayed / reordered) atomic_inc_return_relaxed( &pool->pages_state_release_cnt) page_pool_release() page_pool_inflight() atomic_read(&pages_state_release_cnt) /* sees inflight =3D=3D 0 */ __page_pool_destroy(pool) kfree(pool) dma_unmap_cnt write commits <-- use-after-free On weakly ordered architectures such as arm64, the pages_state_release_cnt increment can become visible before atomic_inc(&pool->dma_unmap_cnt) completes. Because page_pool_enable_dma_unmap() requires !dma_dev_need_sync(), page_pool_scrub() skips synchronize_net(). When another pool still has dma_unmap enabled, static_branch_dec() takes the lockless fast path, leaving nothing to order the write before kfree(pool). Using release ordering on pages_state_release_cnt (such as atomic_inc_return_release()) paired with acquire ordering when page_pool_release() observes inflight =3D=3D 0 would close this race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205125237.2290= 932-1-kuniyu@google.com?part=3D4