From: "Björn Töpel" <bjorn@kernel.org>
To: Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
netdev@vger.kernel.org
Cc: magnus.karlsson@intel.com, stfomichev@gmail.com, kuba@kernel.org,
pabeni@redhat.com, willemb@google.com, matttbe@kernel.org,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Subject: Re: [PATCH net] xsk: don't call virt_to_netmem() on vmapped UMEM addresses
Date: Fri, 04 Dec 2026 19:13:45 +0100 [thread overview]
Message-ID: <87ld64zzfq.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <20261204160411.1167875-1-maciej.fijalkowski@intel.com>
Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes:
> xsk_buff_add_frag() gets the page of an RX frag via
> virt_to_netmem(xdp->data). The UMEM is vmap()ed, so xdp->data is a
> vmalloc address and virt_to_page() is not valid for it. With
> CONFIG_DEBUG_VIRTUAL, __phys_addr() catches this on the first frame
> that spans more than one buffer, in NAPI context:
>
> kernel BUG at arch/x86/mm/physaddr.c:28!
> Oops: invalid opcode: 0000 [#1] SMP NOPTI
> RIP: 0010:__phys_addr+0x3a/0x50
> Call Trace:
> <IRQ>
> ice_clean_rx_irq_zc+0x16a/0xba0 [ice]
> ice_napi_poll+0x2b3/0xfa0 [ice]
> __napi_poll+0x2c/0x1e0
> net_rx_action+0x122/0x2a0
> handle_softirqs+0x104/0x360
> __irq_exit_rcu+0xb5/0xf0
> common_interrupt+0x81/0xa0
> </IRQ>
> Kernel panic - not syncing: Fatal exception in interrupt
>
> ice, i40e and idpf (through libeth) are affected. This was triggered in
> netdev CI, where the debug hosts hit it on E810 and X710 running
> drivers/net/xsk.py, added to net-next by commit 4c810fcd484d
> ("selftests: drv-net: run the AF_XDP tests over veth or a NIC"). Its
> rx_SEND_RECEIVE_9K_PACKETS case reproduces it on E810 with
> CONFIG_DEBUG_VIRTUAL=y, without kernel changes or error injection.
>
> Without DEBUG_VIRTUAL nothing checks the translation. The frag ends up
> with a struct page that does not back the buffer, but on x86-64
> page_address() of it yields the original address again, so this went
> unnoticed. ice and i40e had the same virt_to_page() open-coded since
> v6.6, before the commit below moved it into the helper, so kernels
> older than v6.14 need a separate fix in those drivers.
Ha! Fun times! You ended up in the direct map on the way back!
[...]
> diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
> index 5ec092f7cb6f..5891ac6b1f01 100644
> --- a/net/xdp/xsk_buff_pool.c
> +++ b/net/xdp/xsk_buff_pool.c
> @@ -459,15 +459,21 @@ void xp_dma_unmap(struct xsk_buff_pool *pool, unsigned long attrs)
> }
> EXPORT_SYMBOL(xp_dma_unmap);
>
> -static void xp_check_dma_contiguity(struct xsk_dma_map *dma_map)
> +static void xp_check_dma_contiguity(struct xsk_dma_map *dma_map,
> + struct page **pages)
> {
> + dma_addr_t *dma = dma_map->dma_pages;
> u32 i;
>
> + /* The CPU reaches RX frags through page_address(), so pages also
> + * need to be physically contiguous when an IOMMU translates.
> + */
> for (i = 0; i < dma_map->dma_pages_cnt - 1; i++) {
> - if (dma_map->dma_pages[i] + PAGE_SIZE == dma_map->dma_pages[i + 1])
> - dma_map->dma_pages[i] |= XSK_NEXT_PG_CONTIG_MASK;
> + if (dma[i] + PAGE_SIZE == dma[i + 1] &&
> + page_to_pfn(pages[i]) + 1 == page_to_pfn(pages[i + 1]))
> + dma[i] |= XSK_NEXT_PG_CONTIG_MASK;
> else
> - dma_map->dma_pages[i] &= ~XSK_NEXT_PG_CONTIG_MASK;
> + dma[i] &= ~XSK_NEXT_PG_CONTIG_MASK;
Hmm, aren't we being overly pessimistic for the Tx side now? Tx needs
DMA contig, but the requirement of contig pfn is only for the odd frag
behavior.
Would it be possible to do the pfn config check in the fill ring
validation, or would this have effect on the performance more than here?
I'm OK with this, but I think we might be regressing on a case that used
to work for Tx. OTOH, we'll get a weird asymmetry.
Then again, who uses unaligned! ;-)
(Let's see what Sashiko says -- I'm leaning towards being happy with
this!)
Happy weekend!
Björn
prev parent reply other threads:[~2026-12-04 18:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 16:04 [PATCH net] xsk: don't call virt_to_netmem() on vmapped UMEM addresses Maciej Fijalkowski
2026-12-04 18:13 ` Björn Töpel [this message]
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=87ld64zzfq.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=matttbe@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stfomichev@gmail.com \
--cc=willemb@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox