From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp10.goneo.de (smtp10.goneo.de [85.220.189.106]) (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 9A0AD2AE8D; Sun, 7 Jun 2026 13:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.220.189.106 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780840274; cv=none; b=HZCl1sH2ViSXduGx2ZQTdRlKZZVuvcoPbhB1PcHNOA7caMGJLShfEM0akjnYXceaQI1LVzrTT7dS+r9ZyVJZyOuea8wmxnhn6SeEm1t69YbDr+S/Mg3q8Jq3PRSdgdQEKFQrkRoHRxckusL0QbHVqCyqn1WNYiUtlqmFlG31edI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780840274; c=relaxed/simple; bh=+4txlRb61jWfcSdAwcGsJ21jPzWWq48W/vnO+eSxS/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LgEN/iAOhwCEoTOvrKx3XGibn6lnZx95K5iyOVmHKQR9AEN/UX3TJt9ULROAEfbvzAkF+UUKRvPtbmDxTUw0OfAXK5acZDASbFkKJZx+D/tbouaw7EPkFLVqx2aViUmcVJMX6uqmuLguC3FXSZ7gxfudmxjD1LdN38cADzZxvWM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tk154.de; spf=pass smtp.mailfrom=tk154.de; dkim=pass (2048-bit key) header.d=tk154.de header.i=@tk154.de header.b=n1uQpKeA; arc=none smtp.client-ip=85.220.189.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tk154.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tk154.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tk154.de header.i=@tk154.de header.b="n1uQpKeA" Received: from hub1.goneo.de (hub1.goneo.de [85.220.129.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by smtp10.goneo.de (Postfix) with ESMTPS id 0FE5E240937; Sun, 07 Jun 2026 15:50:59 +0200 (CEST) Received: from hub1.goneo.de (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by hub1.goneo.de (Postfix) with ESMTPS id 6BAE2240023; Sun, 7 Jun 2026 15:50:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tk154.de; s=DKIM001; t=1780840257; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5THlrM0am5qqbwBY1A1KQHMu7kcoO5c1HP7D/7vY/wg=; b=n1uQpKeA/ffNHOSlH9IZ1XT1To3bBGqK9V6Tl4OoJFDbJGwWMiMCbcHRsqZaGId2FxZMoG n3lX+w1esYoPS3hCxnMygNlUVBaErPjdS4/AY0pEopcFMlfrmKwnq8inT+fu76WP5LbZdI T/iwlyZu3715vWLAcb6+tpjgB2l0OjBB5VXY6fjiIACLggB3YTUVX7PkZ+zIpub4sY/7hl qpYxR51Oj5vt1vd7jkXWKZS1jm9V1rzZW904IkzlAoF02UCjcPugUI5xruw0TYP+JYgHZr JSch64Fb3167GfL5xpKjiH3LsWwqQ/sEI8/00G4IbfvC0n584zJdhCllnFhorw== Received: from Til-Notebook.lan (unknown [IPv6:2a00:1f:5743:3300:7fdc:421c:b21a:ba71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by hub1.goneo.de (Postfix) with ESMTPSA id 642512402A5; Sun, 7 Jun 2026 15:50:54 +0200 (CEST) From: Til Kaiser To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: marcin.s.wojtas@gmail.com, linux@armlinux.org.uk, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, mcroce@redhat.com, sven.auhagen@voleatech.de, lorenzo@kernel.org, Til Kaiser Subject: [PATCH net v5 4/4] net: mvpp2: build skb from XDP-adjusted data on XDP_PASS Date: Sun, 7 Jun 2026 15:49:43 +0200 Message-ID: <20260607134943.21996-5-mail@tk154.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607134943.21996-1-mail@tk154.de> References: <20260607134943.21996-1-mail@tk154.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-UID: a84e83 X-Rspamd-UID: 07283a When an XDP program uses bpf_xdp_adjust_head() or bpf_xdp_adjust_tail() and then returns XDP_PASS, mvpp2 still builds the skb from fixed offsets derived from the original RX descriptor. Packet geometry changes made by the XDP program are therefore discarded before the skb reaches the stack. Update rx_offset and rx_bytes from xdp.data and xdp.data_end for XDP_PASS. This makes skb_reserve() and skb_put() reflect the packet seen by XDP, and makes RX byte accounting for XDP_PASS follow the length of the skb passed to the network stack. Keep a separate rx_sync_size for page-pool recycling on skb allocation failure, which must stay tied to the received buffer range. Non-PASS verdicts continue to account the descriptor length because no skb is passed up in those cases. Fixes: 07dd0a7aae7f ("mvpp2: add basic XDP support") Signed-off-by: Til Kaiser --- .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index 481daafdc1cb..ccc24a1301f2 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -3917,10 +3917,10 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, struct mvpp2_bm_pool *bm_pool; struct page_pool *pp = NULL; struct sk_buff *skb; - unsigned int frag_size; + unsigned int frag_size, rx_sync_size; dma_addr_t dma_addr; phys_addr_t phys_addr; - int pool, rx_bytes, err, ret; + int pool, rx_bytes, rx_offset, err, ret; struct page *page; void *data; @@ -3933,6 +3933,8 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, rx_status = mvpp2_rxdesc_status_get(port, rx_desc); rx_bytes = mvpp2_rxdesc_size_get(port, rx_desc); rx_bytes -= MVPP2_MH_SIZE; + rx_sync_size = rx_bytes + MVPP2_MH_SIZE; + rx_offset = MVPP2_MH_SIZE + MVPP2_SKB_HEADROOM; dma_addr = mvpp2_rxdesc_dma_addr_get(port, rx_desc); pool = (rx_status & MVPP2_RXD_BM_POOL_ID_MASK) >> @@ -3948,7 +3950,7 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, dma_sync_single_range_for_cpu(dev->dev.parent, dma_addr, MVPP2_SKB_HEADROOM, - rx_bytes + MVPP2_MH_SIZE, + rx_sync_size, dma_dir); /* Buffer header not supported */ @@ -3999,6 +4001,14 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, continue; } + rx_sync_size = max_t(unsigned int, rx_sync_size, + xdp.data_end - xdp.data_hard_start - + MVPP2_SKB_HEADROOM); + + /* Update offset and length to reflect any XDP adjustments. */ + rx_offset = xdp.data - data; + rx_bytes = xdp.data_end - xdp.data; + metasize = xdp.data - xdp.data_meta; } @@ -4010,8 +4020,7 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, netdev_warn(port->dev, "skb build failed\n"); if (pp) { page_pool_put_page(pp, virt_to_head_page(data), - rx_bytes + MVPP2_MH_SIZE, - true); + rx_sync_size, true); } else { dma_unmap_single_attrs(dev->dev.parent, dma_addr, bm_pool->buf_size, @@ -4041,7 +4050,7 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, ps.rx_packets++; ps.rx_bytes += rx_bytes; - skb_reserve(skb, MVPP2_MH_SIZE + MVPP2_SKB_HEADROOM); + skb_reserve(skb, rx_offset); skb_put(skb, rx_bytes); if (metasize) skb_metadata_set(skb, metasize); -- 2.54.0