🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27059

Re: [PATCH net] xsk: don't call virt_to_netmem() on vmapped UMEM addresses

#27059
From: Björn Töpel
Date: Fri, 04 Dec 2026 18:13
89 lines
11226 bytes
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
Technical Details
Message-ID: <87ld64zzfq.fsf@all.your.base.are.belong.to.us>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377525-linux-kernel-netdev=dewy.ru
References: <20261204160411.1167875-1-maciej.fijalkowski@intel.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377525-linux-kernel-netdev=dewy.ru
From: bjorn@kernel.org (Björn Töpel)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] xsk: don't call virt_to_netmem() on vmapped UMEM
 addresses
Date: Fri, 04 Dec 2026 19:13:45 +0100
Organization: Usenet Network
Message-ID: <87ld64zzfq.fsf@all.your.base.are.belong.to.us>
References: <20261204160411.1167875-1-maciej.fijalkowski@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2827801"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ihrahcBNjfQtAGWM4GOVLdV43DA= sha256:1/hORs8iCITcJleSnCtxV2UCdf+s/crHnLBTM/kCf5s=
	sha1:gNYao8Bv3jlqDyah/ePz1sjWmmc= sha256:GrKnRFza6cISX7UupKbV4ujpMaqCRrcAnhBWQbzyaCo=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 81AE7117C8C; Fri,  4 Dec 2026 21:14:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.542
X-Spam-Status: No, score=-3.542 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id N-9UB-ohY3Hn;
	Fri,  4 Dec 2026 21:14:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377525-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 38EA1117C0E; Fri,  4 Dec 2026 21:13:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id AC55E39138; Fri,  4 Dec 2026 18:13:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796408030;
	b=tJVITfPDbr0jwYYGZeDcaBE6yw+eueGJh1i64an3PI/YCOoU3XaQNm2K09Tq31qqwZWc
	 vmEUqrpxxiZ7NAb8xXlHOzbBHh6ROYDU1YxvkHgdqwchiY7AH7JXdmuC7a7+igoy7C4lg
	 eWaLQ3B9eZ4Xa15uqAhykXJKlz8xbMUq/lI2RvfW9lGLvbFD3n8/1bCTwD8RdMItz8277
	 mBp0i7a0T1PDQ+yUPUDLLULL9eA4JwVVWhZZBGc4+ss2ugwLitc2LGmBaJXZWrYg1VBWF
	 S/Ki01BKtzJEg4wgbZhfIHwemiH5xfkNaYSCyx4FA24L4xxsTM+tMe9YGfZpuTYbI8Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796408030;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 In-Reply-To:References:Date:Message-ID:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=vFm0cq+jdo5aWkMZtk7hv1Gdyg4t1Cea+ccAfvUywk0=;
	b=hILrNFMAfhesIfAxuxS4fYaIm2NhQboglqZGta4EQr3/FRZUC93t4M0LMpACIDEqWR2M
	 TQwQwi9vo8EavwkeD2Y/vYHmriSDVIjyIUc1hkcR7Vg/HSdegI1bxTamL6ob1Xs36S6MJ
	 RvoFtECUIdr8Q4ljj09yqyUUtJrJcvwUdaMOkIQCXvgoeHAO/6GyS+CgJCo00SuDSMLjZ
	 M5k7kwMECoSg31m9IVUe+tKuHMutl/4j8KDPHBPfkOQo5axUnpGqRr+pb4vjMJrKMNucT
	 dan5L2fL2Hzqh99Br+AnsjUAKiavmdYDZiWWeNDJCzrgkNAbTdtq7raLVJ24cihLZwQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GpcK+3LX;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 830ED606A333;
	Fri,  4 Dec 2026 18:13:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GpcK+3LX
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796408029;
	b=ndSzXquX7tVPlKA+bpDmEPlWc4W6/428QjBNfLi/CS1ouIfc0bZSx0GguKwEMMSJ+cd+
	 yo73KNPo8xzJmD+rxnyC3anFp6IW9aXMtpCjG7Ze2OGSxF9rNCRxoEidR/VsFA5Py72c8
	 bIkXYDPP2cC4Dk3dNvqlBptPSfZ1Ffnac1p5ouPOPpiehi7ecrBhaESn1MWX37WqXce2p
	 o9eCpmwggVg6skGDDc882A/dqR1cNplXCCmrQ642C3Nq5M/P4Kko97ZSIgaZuBa1v5WA2
	 l49bnsTBb55ChxrGN2aCT36Wi9f6duVf4N2fVjXl/pyqPU7FahBfsffwJmvfHcz1QMw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796408029;
	h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References:
	 Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=vFm0cq+jdo5aWkMZtk7hv1Gdyg4t1Cea+ccAfvUywk0=;
	b=NJjQoDsYWdTI5qTv9KEAyRdbYDtLdJOOVNom52Gzoi5A0Lat0QHf3zndu30/JneGzeKT
	 czlp79wKbKgsuBFENoQwj9r4DMOCP+iUOIpkB9LxC7CzkW1aIsTwpPmh1IZVvAiHgvPuH
	 pwepRVYNJxWPu/PBxdcxE5MbtipHrvTnOPgWYIgASajZVjxAyBtrfD3kPUpOhrjrKj5A0
	 uqtTKcuYp8yzNJbML+CN195v7W9rmYyGGeqOp0JWemlVflIxpMrYIt0DlfJiytfMjgBiy
	 M94KEiRcub9dy/PTroAQelgPRelktrG0a2tPalKC0xGZ9jvzJGnPbxKyoPdUPff6j2A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GpcK+3LX;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1AF5606A32C
	for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 18:13:49 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D4911F00A11;
	Fri,  4 Dec 2026 18:13:48 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796408028;
	bh=vFm0cq+jdo5aWkMZtk7hv1Gdyg4t1Cea+ccAfvUywk0=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date;
	b=GpcK+3LXM/TzIvp0dCeKTnHphPOlESu6gIv4hHSmM3WOiFLS13VXS17ZCUYoJz1Xa
	 NS8CsgVTAo3tgMNBiswGPysBgQjzFsOj8EmNrj6HlsnzXCeGMhoXZCR9JmQH3xYD9a
	 0TVGmIcXbFzLt+z/t8ZITKP7ycrsiu/XDYojxl435QoxxBoitutGtKw5h5Tb8YzUkQ
	 kwxB3y4ipqw6UxcDSE1ej33Wqpc27QUNlIIvYYbD4VhNriqD0sn/zmF6lhAIAUpbEe
	 On4gpR+UQ0oy+ks/Uhcj1FbuYh0rWY+CedpQDK4bcsC+UIkXFNeoZahafH+tVN4oxn
	 JL7ufEh7agEHQ==
X-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>
X-In-Reply-To: <20261204160411.1167875-1-maciej.fijalkowski@intel.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list