From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.6 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796400267; b=r1L1FV5Is0DaS5lkB/D9YP2I4TDyQ4tiu3DPbthwsVIJe/xN24aFaF2lm2fDPRjvxfpp GLXA2ZCiDYU+J9/wPg4QuV/34PnclZeSYAyHu3IQlYNTyySWHWWdFZdEAeLlJLY/+49Y1 U6NqNMSEM+yjPpOrEfud/WPnURrs3qrZSboeeE5MRhkDIL1BIBORD+P7E+URYjVzw0URM uquve7+ONilKTjTIq2yexetMQlnCuJbm/Nil0Q4nSqh/ZLzgjBD+2YiABSaxl9ikPYpC0 BbOmazR9+L3fQOXeBvlHUpyUVb5t5xSloy5iWMDDHA6M50Zz2KyBN/NHPz4ohy6aSgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400267; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=x9OqIc+tSjqdCxVY1v8EzUpC8yItTb4jAcC14xfZrzM=; b=1YcozIkw+nB6g/MaHv8Zp9iicKFiyaUhg6e9cYfFVomquG1nmnUh+sf7vjXiSEi1p3aK 9VDSqSKVr0YU90h+ZMtBOPVAIgC4w9QWBWQ+Dvk2a1QfZ3AqHaZrpGRP2asizuR92MgFg BUkBv02szeBxY6C+HKGe+cwPuC6TGDr6bxXI3pmbTFuB+HyT9r8Z1Fl0+0kL3d68S4tYd PqAT8zEqrhDZngfWlBU9Gq9jrtcgKyLfBPFFR4MxLlv+BUJ60thEd/Tt7dsHupsFKLPBT da8Tk3TkA3+xTcpOtJtAC/4xPNCFBvbrgzzrBEJSVUP2Rcwkj4TrAfX+Ap4a5c9FJSw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=E0pTU3Hc; arc=none smtp.remote-ip=192.198.163.6 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.6]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 333C1606A338 for ; Fri, 4 Dec 2026 16:04:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 333C1606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=E0pTU3Hc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796400267; x=1827936267; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=vj0a+WGsIE2te8RIrO+vgFA7cWq4GlU7haMGhJ/8GYE=; b=E0pTU3Hc/La5cvRqfqc+s/FUp9lh7FuAks5KyB0PuFJTJNAi8V9IAQML /o1/hqum2Li+xdssYobhYVs3vStojzKVg65e+aToHSqsooBxHoIGe9A0A AFh9nVakUbkrPjVRbqHBBtW3/jx+x5ytFjw4nR4HeKiZHkOLH/Oo1uZXj fUTKklxniEHuDW2vPkqwXl6SIJH5QORBu7AlgUOOqWa/Qs4Ej0uU5sSbH IvwIKufCpRIQXrxhI/icEYDrhdKRK+deFcgVYQTvLKf8HnYNINORlzH9K 2ZRmgPN/2IUydJC1w0/fYCbhVJSdjj2dZxYulsYUOkAh0T0vbKo/Nt25w A==; X-CSE-ConnectionGUID: wYjVjpQoTWyRUXUIZsZIlw== X-CSE-MsgGUID: 8aO7XqB+Q1yi87i8X5cN4w== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="17542" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="17542" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa116.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 08:04:26 -0800 X-CSE-ConnectionGUID: CmDaD18IR2e1howH3GOOmA== X-CSE-MsgGUID: T9rvUD1ESr6BjnW7qq+49w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="13924968" Received: from boxer.igk.intel.com ([10.102.20.173]) by orviesa004.jf.intel.com with ESMTP; 04 Dec 2026 08:04:24 -0800 From: Maciej Fijalkowski To: netdev@vger.kernel.org Cc: magnus.karlsson@intel.com, stfomichev@gmail.com, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, matttbe@kernel.org, bjorn@kernel.org, Maciej Fijalkowski Subject: [PATCH net] xsk: don't call virt_to_netmem() on vmapped UMEM addresses Date: Fri, 4 Dec 2026 17:04:11 +0100 Message-Id: <20261204160411.1167875-1-maciej.fijalkowski@intel.com> X-Mailer: git-send-email 2.38.1 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 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 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. Take the page from the UMEM page array instead, indexed by the offset of the buffer in the vmap() area. Unlike vmalloc_to_page(), this does not walk the page tables for every frag. I have not benchmarked whether the latter would be cheaper or not when compared to proposed solution. page_address() of the real page points into the linear map, so a frag that runs into the next page is only accessed correctly if the two pages are physically contiguous. Aligned chunks never cross a page. Unaligned ones may cross only where xp_check_dma_contiguity() set XSK_NEXT_PG_CONTIG_MASK, and it does so by comparing DMA addresses alone. With a translating IOMMU those say nothing about physical contiguity, so compare the PFNs as well. Tested on E810 (ice) with CONFIG_DEBUG_VIRTUAL=y: the 9K case no longer hits the BUG and the whole xsk.py run passes. i40e and idpf were only build-tested, and the PFN check was not exercised with a translating IOMMU. Fixes: 51205f841a49 ("xsk: make xsk_buff_add_frag() really add the frag via __xdp_buff_add_frag()") Signed-off-by: Maciej Fijalkowski --- include/net/xdp_sock_drv.h | 8 ++++++-- net/xdp/xsk_buff_pool.c | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h index a40ad3f90f13..0e1b9bb72b8c 100644 --- a/include/net/xdp_sock_drv.h +++ b/include/net/xdp_sock_drv.h @@ -162,18 +162,22 @@ static inline bool xsk_buff_add_frag(struct xdp_buff *head, struct xdp_buff *xdp) { struct xdp_buff_xsk *frag = container_of(xdp, struct xdp_buff_xsk, xdp); + struct xsk_buff_pool *pool = frag->pool; const void *data = xdp->data; + struct page *page; /* Duplicate fill ring entries map to the same xskb in aligned mode */ if (unlikely(xdp == head || !list_empty(&frag->list_node))) return false; - if (!__xdp_buff_add_frag(head, virt_to_netmem(data), + /* data points into the vmap() of the UMEM, not the linear map */ + page = pool->umem->pgs[(data - pool->addrs) >> PAGE_SHIFT]; + if (!__xdp_buff_add_frag(head, page_to_netmem(page), offset_in_page(data), xdp->data_end - data, xdp->frame_sz, false)) return false; - list_add_tail(&frag->list_node, &frag->pool->xskb_list); + list_add_tail(&frag->list_node, &pool->xskb_list); return true; } 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; } } @@ -531,7 +537,7 @@ int xp_dma_map(struct xsk_buff_pool *pool, struct device *dev, } if (pool->unaligned) - xp_check_dma_contiguity(dma_map); + xp_check_dma_contiguity(dma_map, pages); err = xp_init_dma_info(pool, dma_map); if (err) { base-commit: 3c8881ee98069d3c8a1a0ad1fd6efd726e466297 -- 2.43.0