From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 5D40D4A32; Thu, 12 Feb 2026 19:03:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770922988; cv=none; b=pic0SybtaC1cfyYmKasqJQv0Li5YTxo0g2uZPxWrW8uBbx9Q/3TKk94erEHIdj0bLHA8d7bKnfo7gH+gRK5jcXYU9yWsg3Rqqv6I/NugYevJ7eXPW/E6hZ36ihpjJbtFFkcUxX3R4HQw9JB8ys+OmbxCyMK8bo2NfGMKpMgkn4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770922988; c=relaxed/simple; bh=DPurnGILpIn2aCt2tqh8TNRLtY5vbDvkWz2AmMpZNKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LkCIUJkhV0r0PH8B2BMxKJE2t1MrLynnSxmFive31UC1DWiygJt1CTT/jj9klsgn0oPc008ndCOD0KCxktc4pEPjd54nmHKqqPBp+zC0YFJIEdnoKCQn0lRT1GjHHZew0+xLGC/c52+N2SIcgvIX8mMbtNNk7dNE/3vgGTN6hFU= 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=iYmAGLaY; arc=none smtp.client-ip=198.175.65.9 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="iYmAGLaY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770922987; x=1802458987; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DPurnGILpIn2aCt2tqh8TNRLtY5vbDvkWz2AmMpZNKY=; b=iYmAGLaYHNPC1lOG7kYWFU5EwtEzM6VeqIL2+O+Mf73wcAFtxHE/fVlZ Tb7qNv7OVs0yxjZbvvN1or1Qb5gBPL7sEj+05LhDWrOonoTQ4R1Q1a/V5 lh/uPpJGKN8F2tLLnE+JmXXcPxD1HNC29uJrJAHXxhnHnvNaALRjVccEg MLZVrkWRA/Sy1Fa0d/x2C96YRij5a6Cc75gHrtHHrsrOhjmokTuff3lPW v6bQfmbL78j7aHPEPkxTetZ5IOKimB6KaO0QecjK7w6WvwqYAoWL7JC6g uHn/7OJ9iCTg9mb5BvzFP14ucaHX8tYB2whOssSy9gY6W2cVt4GYFqaqK w==; X-CSE-ConnectionGUID: kIdkKxu6TySHIRm4LwmkKQ== X-CSE-MsgGUID: FOroEj2SQpaIFd1lFCFeYQ== X-IronPort-AV: E=McAfee;i="6800,10657,11699"; a="94745930" X-IronPort-AV: E=Sophos;i="6.21,287,1763452800"; d="scan'208";a="94745930" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2026 11:03:07 -0800 X-CSE-ConnectionGUID: 3AVABH/sQEa5swfmcJawyA== X-CSE-MsgGUID: vRadz1eqRmGIcRl3uOZZuA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,287,1763452800"; d="scan'208";a="211921960" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa010.fm.intel.com with ESMTP; 12 Feb 2026 11:02:59 -0800 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id 384EB32C91; Thu, 12 Feb 2026 19:02:56 +0000 (GMT) From: Larysa Zaremba To: bpf@vger.kernel.org Cc: Larysa Zaremba , Claudiu Manoil , Vladimir Oltean , Wei Fang , Clark Wang , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , 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, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-kselftest@vger.kernel.org, Aleksandr Loktionov , Dragos Tatulea Subject: [PATCH bpf v2 1/9] xdp: use modulo operation to calculate XDP frag tailroom Date: Thu, 12 Feb 2026 19:33:16 +0100 Message-ID: <20260212183328.1883148-3-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260212183328.1883148-2-larysa.zaremba@intel.com> References: <20260212183328.1883148-2-larysa.zaremba@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org 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") 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 ba019ded773d..5f5489665c58 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4156,7 +4156,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