From: Kuniyuki Iwashima <kuniyu@google.com>
To: Alexander Lobakin <aleksander.lobakin@intel.com>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
Jesper Dangaard Brouer <hawk@kernel.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Brian Vazquez <brianvv@google.com>,
David Decotigny <decot@google.com>, Li Li <boolli@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>,
intel-wired-lan@lists.osuosl.org
Subject: [PATCH v2 iwl-next 3/5] netmem: Annotate data-races around pp_magic.
Date: Sat, 5 Dec 2026 21:52:21 +0900 [thread overview]
Message-ID: <20261205125237.2290932-4-kuniyu@google.com> (raw)
In-Reply-To: <20261205125237.2290932-1-kuniyu@google.com>
page->pp_magic shares storage with page->lru.next, which also holds
the pfmemalloc bit (BIT(1)).
During page_pool_scrub(), a reader can also call
netmem_get_dma_index() concurrently with netmem_clear_pp_magic()
and netmem_set_dma_index().
Furthermore, we will allow unmapping DMA early in page_pool while
earlier fragments of the same page may still be in flight on remote
CPUs, allowing netmem_set_dma_index() to run concurrently with
readers of pp_magic and page_is_pfmemalloc().
Let's annotate accesses to page->pp_magic and page->lru.next with
READ_ONCE() and WRITE_ONCE().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
include/linux/mm.h | 4 ++--
net/core/netmem_priv.h | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 040cff64381b..b4bcd0e389c4 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3354,7 +3354,7 @@ static inline bool page_is_pfmemalloc(const struct page *page)
* pfmemalloc reserves. Callers may simply overwrite it if
* they do not need to preserve that information.
*/
- return (uintptr_t)page->lru.next & BIT(1);
+ return (uintptr_t)READ_ONCE(page->lru.next) & BIT(1);
}
/*
@@ -5764,7 +5764,7 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);
#ifdef CONFIG_PAGE_POOL
static inline bool page_pool_page_is_pp(const struct page *page)
{
- return (page->pp_magic & PP_MAGIC_MASK) == PP_SIGNATURE;
+ return (READ_ONCE(page->pp_magic) & PP_MAGIC_MASK) == PP_SIGNATURE;
}
#else
static inline bool page_pool_page_is_pp(const struct page *page)
diff --git a/net/core/netmem_priv.h b/net/core/netmem_priv.h
index 23175cb2bd86..7bf216b85eec 100644
--- a/net/core/netmem_priv.h
+++ b/net/core/netmem_priv.h
@@ -5,7 +5,7 @@
static inline unsigned long netmem_get_pp_magic(netmem_ref netmem)
{
- return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK;
+ return READ_ONCE(netmem_to_nmdesc(netmem)->pp_magic) & ~PP_DMA_INDEX_MASK;
}
static inline void netmem_or_pp_magic(netmem_ref netmem, unsigned long pp_magic)
@@ -17,7 +17,7 @@ static inline void netmem_clear_pp_magic(netmem_ref netmem)
{
WARN_ON_ONCE(netmem_to_nmdesc(netmem)->pp_magic & PP_DMA_INDEX_MASK);
- netmem_to_nmdesc(netmem)->pp_magic = 0;
+ WRITE_ONCE(netmem_to_nmdesc(netmem)->pp_magic, 0);
}
static inline bool netmem_is_pp(netmem_ref netmem)
@@ -43,7 +43,7 @@ static inline unsigned long netmem_get_dma_index(netmem_ref netmem)
if (WARN_ON_ONCE(netmem_is_net_iov(netmem)))
return 0;
- magic = netmem_to_nmdesc(netmem)->pp_magic;
+ magic = READ_ONCE(netmem_to_nmdesc(netmem)->pp_magic);
return (magic & PP_DMA_INDEX_MASK) >> PP_DMA_INDEX_SHIFT;
}
@@ -57,6 +57,6 @@ static inline void netmem_set_dma_index(netmem_ref netmem,
return;
magic = netmem_get_pp_magic(netmem) | (id << PP_DMA_INDEX_SHIFT);
- netmem_to_nmdesc(netmem)->pp_magic = magic;
+ WRITE_ONCE(netmem_to_nmdesc(netmem)->pp_magic, magic);
}
#endif
--
2.56.1.915.g69d5ec7298-goog
next prev parent reply other threads:[~2026-12-05 12:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 12:52 [PATCH v2 iwl-next 0/5] idpf: Avoid IOVA exhaustion under DMA-FQ IOMMU Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 1/5] idpf: Reuse idpf_rx_update_bufq_desc() in idpf_rx_post_buf_desc() Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 2/5] idpf: Use coherent DMA buffer for Rx header split without XDP Kuniyuki Iwashima
2026-12-05 12:52 ` Kuniyuki Iwashima [this message]
2026-12-05 12:52 ` [PATCH v2 iwl-next 4/5] page_pool: Allow drivers to unmap DMA before returning pages Kuniyuki Iwashima
2026-12-05 13:15 ` sashiko-bot
2026-12-05 12:52 ` [PATCH v2 iwl-next 5/5] idpf: Unmap Rx payload pages above mapped threshold under DMA-FQ IOMMU Kuniyuki Iwashima
2026-12-05 13:16 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205125237.2290932-4-kuniyu@google.com \
--to=kuniyu@google.com \
--cc=aleksander.lobakin@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=boolli@google.com \
--cc=brianvv@google.com \
--cc=decot@google.com \
--cc=hawk@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuni1840@gmail.com \
--cc=przemyslaw.kitszel@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.