Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0048221ABC9 for ; Thu, 5 Mar 2026 11:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772711096; cv=none; b=QGr5DTgnMxY71rz3LxVU7IBEgX5JIO0PxONJJqLkIXwSsF59/371LXDp6NgIRR57gv76KOv676LGDlorlmXIsLFv1e6HlqzoGz+sKgptveDuYYwofl6cFVV6QXaOst9vRrIujlmylXJ5Z9GWIXPGJLfsd0fXm3fJyfA66KCHXH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772711096; c=relaxed/simple; bh=I8LeZNgeuqgDpbXs60sxkQ/Vovn1rVcrBzDtzH6nvI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MllsQDEVE/WbrJ1dPbLH4cDTfgZV+wuRMBnHj7YPV/2PtlNvX11RdT7IwAJ5ol8kx1zt4XAv0FWwCQYjkQENBdx5rFMP5Ryxrk2Uad/sdS6Rnqe79iyZz8B4Qt2ydfLja6DGkNfnVKJpbGyYx2EJGO0U50+Bw0cXxje8sDfbTY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OkMASRzh; arc=none smtp.client-ip=192.198.163.11 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) header.d=intel.com header.i=@intel.com header.b="OkMASRzh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772711094; x=1804247094; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I8LeZNgeuqgDpbXs60sxkQ/Vovn1rVcrBzDtzH6nvI0=; b=OkMASRzh6XUhoMwGLDmyQx/v+OW7dvaumCPhg80uBx7JSZzpDn7y4GSp xigNj4md4Q4oYUTIxieDA/oWwgq7pOroJPYzbSq7eUMLoQiiEAr8cIZUW yUB5ef78xInBxfy41iDifzsUuPRs6pXw3Ijquf7doid2973FRnI7urDBf 14Tj+ff2inPBq0DYVsswFYlYFMj8KCqC4zj+RE64xsSnAKn1qP513fGWk yBz6V71d8m60ZBxWgwKllE/KEdzfTOFCdgSMCUlSW+E71GS20v/Ix4jVZ sUXkbyqy5zUI4H3yTJzuIT4OA/rO6miI24w4lQpV7vQNfUTbauoXWmkk2 g==; X-CSE-ConnectionGUID: PB7NqnRsSdyjjUvXck05rg== X-CSE-MsgGUID: E2KM3r3YTxKRRgeGjj5kUw== X-IronPort-AV: E=McAfee;i="6800,10657,11719"; a="84428615" X-IronPort-AV: E=Sophos;i="6.23,102,1770624000"; d="scan'208";a="84428615" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Mar 2026 03:44:54 -0800 X-CSE-ConnectionGUID: 4xiX/YobTn69jNy5+yChAw== X-CSE-MsgGUID: ulYTWkQGTY+j2drROyl4+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,102,1770624000"; d="scan'208";a="223345245" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa005.fm.intel.com with ESMTP; 05 Mar 2026 03:44:46 -0800 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id D9E512876D; Thu, 5 Mar 2026 11:44:42 +0000 (GMT) From: Larysa Zaremba To: netdev@vger.kernel.org, bpf@vger.kernel.org, Jakub Kicinski Cc: Larysa Zaremba , Claudiu Manoil , Vladimir Oltean , Wei Fang , Clark Wang , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Tony Nguyen , Przemek Kitszel , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Hao Luo , Jiri Olsa , Simon Horman , Shuah Khan , Alexander Lobakin , Maciej Fijalkowski , "Bastien Curutchet (eBPF Foundation)" , Tushar Vyavahare , Jason Xing , =?UTF-8?q?Ricardo=20B=2E=20Marli=C3=A8re?= , Eelco Chaudron , Lorenzo Bianconi , Toke Hoiland-Jorgensen , imx@lists.linux.dev, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-kselftest@vger.kernel.org, Aleksandr Loktionov , Dragos Tatulea , Magnus Karlsson Subject: [PATCH net v5 1/9] xdp: use modulo operation to calculate XDP frag tailroom Date: Thu, 5 Mar 2026 12:12:42 +0100 Message-ID: <20260305111253.2317394-2-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260305111253.2317394-1-larysa.zaremba@intel.com> References: <20260305111253.2317394-1-larysa.zaremba@intel.com> Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The current formula for calculating XDP tailroom in mbuf packets works only if each frag has its own page (if rxq->frag_size is PAGE_SIZE), this defeats the purpose of the parameter overall and without any indication leads to negative calculated tailroom on at least half of frags, if shared pages are used. There are not many drivers that set rxq->frag_size. Among them: * i40e and enetc always split page uniformly between frags, use shared pages * ice uses page_pool frags via libeth, those are power-of-2 and uniformly distributed across page * idpf has variable frag_size with XDP on, so current API is not applicable * mlx5, mtk and mvneta use PAGE_SIZE or 0 as frag_size for page_pool As for AF_XDP ZC, only ice, i40e and idpf declare frag_size for it. Modulo operation yields good results for aligned chunks, they are all power-of-2, between 2K and PAGE_SIZE. Formula without modulo fails when chunk_size is 2K. Buffers in unaligned mode are not distributed uniformly, so modulo operation would not work. To accommodate unaligned buffers, we could define frag_size as data + tailroom, and hence do not subtract offset when calculating tailroom, but this would necessitate more changes in the drivers. Define rxq->frag_size as an even portion of a page that fully belongs to a single frag. When calculating tailroom, locate the data start within such portion by performing a modulo operation on page offset. Fixes: bf25146a5595 ("bpf: add frags support to the bpf_xdp_adjust_tail() API") Acked-by: Jakub Kicinski Reviewed-by: Aleksandr Loktionov Signed-off-by: Larysa Zaremba --- net/core/filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index 0d5d5a17acb2..d6fafb3633b0 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4155,7 +4155,8 @@ static int bpf_xdp_frags_increase_tail(struct xdp_buff *xdp, int offset) if (!rxq->frag_size || rxq->frag_size > xdp->frame_sz) return -EOPNOTSUPP; - tailroom = rxq->frag_size - skb_frag_size(frag) - skb_frag_off(frag); + tailroom = rxq->frag_size - skb_frag_size(frag) - + skb_frag_off(frag) % rxq->frag_size; if (unlikely(offset > tailroom)) return -EINVAL; -- 2.52.0