From mboxrd@z Thu Jan 1 00:00:00 1970 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 8AD29395256; Thu, 5 Mar 2026 11:44:54 +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=jXYnKyNxARnkJ2esSB/VqYzFdkW+Qa7BsMa0V3CjkVzpZZN96AtzG3WdqTZtdxpSCtkeN3rw5qbx0BWY/PPv5q554muDnEb9P6qJZTsJ7uKPCmurLRKkfwH/r28GCXn3R8QiraKkUJrfC9nrnglaXWl6ABnOYeEVkL04pqoY/jI= 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=T00IEHXQ; 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="T00IEHXQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772711095; x=1804247095; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I8LeZNgeuqgDpbXs60sxkQ/Vovn1rVcrBzDtzH6nvI0=; b=T00IEHXQU9DKh4c7I1eo4ISH3cBIeVFWWduyrC2EcbQjqIiTU3Lk9d5o wizR2kYH2yjsQzZaGqS8T0mXSZL+yaQ16MkCh7FhCdWs5VXP0Ar+PiCku YH/GPQyaiYRwIQ3SQj10JO9OdM/a4QEi+MlH5zVkMFXSbf6zikBsCpbiS 1SK4byqxjvMNA40ABdGWwxsrozdPd1/2H4okLYWNupZixhNJBHCaP/4Hb XFc7pUlfojWqTauZSb5W8j7xjup3Jhu4E93G9WqiNX+ay37RNdH1vgdwG 3AAUYxNTY4HqNYCSgtIlKjfQ10OzuRWV1txDMPXFzxBpcRaAHxyjK1heV w==; X-CSE-ConnectionGUID: XsdawMG4Rj6NuCOioymo3g== X-CSE-MsgGUID: TCZk3UeRQoeBmAQr7b5BtA== X-IronPort-AV: E=McAfee;i="6800,10657,11719"; a="84428613" X-IronPort-AV: E=Sophos;i="6.23,102,1770624000"; d="scan'208";a="84428613" 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: 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") 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