🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #3266

[PATCH net-next v9 2/8] hsr: Use skb_clone() while adding the HSR header

#3266
From: Sebastian Andrzej Siewior
Date: Wed, 14 Oct 2026 14:43
87 lines
10107 bytes
hsr_create_tagged_frame() creates a new skb where the HSR header can be
prepended via __pskb_copy(). This does not copy the skb_shared_info part
of the original skb so any timestamp request is lost.

An alternative is to use skb_clone() where the skb_shared_info part is
shared and then skb_cow_head() to make the header part writeable. This
avoids touching manually the tx_flags and tskey members.
Using skb_clone() allows also return early (after the clone) in the
offloaded case so this can be unified a bit. The clone also preserves
metadata so skb_postpush_data_move() is used instead of memmove().

This is a prepartion for PTP handling where timestatmps are requested.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 net/hsr/hsr_forward.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
index 7734a521a96c2..5862c05f52110 100644
--- a/net/hsr/hsr_forward.c
+++ b/net/hsr/hsr_forward.c
@@ -331,7 +331,6 @@ static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,
 struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
 					struct hsr_port *port)
 {
-	unsigned char *dst, *src;
 	struct sk_buff *skb;
 	int movelen;
 
@@ -342,33 +341,40 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
 		/* set the lane id properly */
 		hsr_set_path_id(frame, hsr_ethhdr, port);
 		return skb_clone(frame->skb_hsr, GFP_ATOMIC);
-	} else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
-		return skb_clone(frame->skb_std, GFP_ATOMIC);
 	}
 
-	/* Create the new skb with enough headroom to fit the HSR tag */
-	skb = __pskb_copy(frame->skb_std,
-			  skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC);
+	skb = skb_clone(frame->skb_std, GFP_ATOMIC);
 	if (!skb)
 		return NULL;
-	skb_reset_mac_header(skb);
 
-	if (skb->ip_summed == CHECKSUM_PARTIAL)
-		skb->csum_start += HSR_HLEN;
+	if (port->dev->features & NETIF_F_HW_HSR_TAG_INS)
+		return skb;
+
+	/* Ensure the cloned skb has enough headroom to fit the HSR tag */
+	if (skb_cow_head(skb, HSR_HLEN))
+		goto err;
 
 	movelen = ETH_HLEN;
 	if (frame->is_vlan)
 		movelen += VLAN_HLEN;
 
-	src = skb_mac_header(skb);
-	dst = skb_push(skb, HSR_HLEN);
-	memmove(dst, src, movelen);
+	/* The entire header area needs to be linear */
+	if (!pskb_may_pull(skb, movelen))
+		goto err;
+
+	skb_push(skb, HSR_HLEN);
+	skb_postpush_data_move(skb, HSR_HLEN, movelen);
+	skb_set_network_header(skb, HSR_HLEN + movelen);
 	skb_reset_mac_header(skb);
+	skb_reset_mac_len(skb);
 
 	/* skb_put_padto free skb on error and hsr_fill_tag returns NULL in
 	 * that case
 	 */
 	return hsr_fill_tag(skb, frame, port, port->hsr->prot_version);
+err:
+	kfree_skb(skb);
+	return NULL;
 }
 
 struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,

-- 
2.55.0
Technical Details
Message-ID: <20261014-hsr_ptp-v9-2-2d20a2a0f816@linutronix.de>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346318-linux-kernel-netdev=dewy.ru
References: <20261014-hsr_ptp-v9-0-2d20a2a0f816@linutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346318-linux-kernel-netdev=dewy.ru
From: bigeasy@linutronix.de (Sebastian Andrzej Siewior)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v9 2/8] hsr: Use skb_clone() while adding the HSR header
Date: Wed, 14 Oct 2026 16:43:56 +0200
Organization: Usenet Network
Message-ID: <20261014-hsr_ptp-v9-2-2d20a2a0f816@linutronix.de>
References: <20261014-hsr_ptp-v9-0-2d20a2a0f816@linutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2315916"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:o4VE7i5geleiPeAljueu2VCgEtg= sha256:aZGkUBz3uKPmLtEqDIJg+oROrEnWq9fxR26gVCsKkC4=
	sha1:u9WQbQD7n0gLP3BSf9R2WNtfOAs= sha256:Rvux0Ng/nIeIFKneKxBtbtngF4GOZEDzScmwZ6unIpQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id CDD7B110135; Wed, 14 Oct 2026 17:45:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=linutronix.de header.b=qHJyQv9X; dkim=neutral
	reason="invalid (unsupported algorithm ed25519-sha256)"
	header.d=linutronix.de header.b=hLJiZBph
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id V5llGrCSZ38x;
	Wed, 14 Oct 2026 17:45:15 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-346318-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linutronix.de
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id B4578110105; Wed, 14 Oct 2026 17:45:01 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sto.lore.kernel.org (Postfix) with ESMTP id 4D29C612F5D; Wed, 14 Oct 2026 14:44:18 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C88C54B1C0;
	Wed, 14 Oct 2026 14:44:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qHJyQv9X";
	dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hLJiZBph"
X-Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55])
	(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 3CAAF548562
	for <netdev@vger.kernel.org>; Wed, 14 Oct 2026 14:44:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791989054; cv=none; b=MevmuAM+Ym97wcrgS6yNIdJLJf/VUWR3WHxqKww3Z7Ysz8mYfKBCnzlh4NXyJVB8KAIUg/dh0HHnxc2QH10zdu1MBeAYECaH6Gc5BQeuHGjm6aIQw6X4DgFOs5zGcHAwrkkQyv/WoUF6I5wJ3ZClx+PYbWn+w+GQAOQ2I1T+xs0=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791989054; c=relaxed/simple;
	bh=NWDD9/HBcZlan+7iDsY7WLsNVY180qvXfGnmZd28KJE=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version:Content-Type; b=Vlrs0JQ7JjHS8Eki69yrigMsc39dTtRghDVKk5FpV2UHRMBQB5E+NzKnx3BK7YkDATO01KYSn//HtMGxVXghVK3ihKZlgbUS9QzUpaL7PBNnCg3ZPDpA2hae/5zhh9ru+POiGEGth3raux1flUfziYMUEMdZGuodTybtu563STY=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qHJyQv9X; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hLJiZBph; arc=none smtp.client-ip=193.142.43.55
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020; t=1791989047;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=Wz09Vw74WWRM4lngFu8aaLmkLNIthV4SzeyqQ1FGPk4=;
	b=qHJyQv9Xb/tkxzbWIcX97ip/hItMQjzbq0uOrxrJMsrCLLdft/RQFhXSCmRlPX86dsC4Vs
	IFIt8NsdnQ7GVOGNYz9L0FPC4eJaaCR2fKlHi+4rH89CohA3KSDITgVzNkHayv5kiZZlsT
	+Xi33WrsQFuQ2kfMg1N5AiPRJQluGFZge/KtFgOC6ke+BjdzWJ7WVbFXcuhKFI5qCGSq62
	Qdz58Q20NVRCq/sHGLJMIdBQK3eRxwEScGOKm5RVCtfreauI6UrSBGKFMAMckXU8iV8kqw
	Xt+XcW/QEeNo/esX4MqmgVQH77ZQEEBOLis21TzATUlMKpbYMuSQHhIByKqzbQ==
X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020e; t=1791989047;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=Wz09Vw74WWRM4lngFu8aaLmkLNIthV4SzeyqQ1FGPk4=;
	b=hLJiZBphCgNMmtA944dZtwn4ECNmxnyST5sfHFgvScr0M4FOXYWlnkyER+7ZEhV+ljuNQV
	ZI6Bo+oD5vE0GZBQ==
X-Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	"(JC), Jayachandran" <j-rameshbabu@ti.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Chintan Vankar <c-vankar@ti.com>,
	Danish Anwar <danishanwar@ti.com>,
	Daolin Qiu <d-qiu@ti.com>,
	"David S. Miller" <davem@davemloft.net>,
	Felix Maurer <fmaurer@redhat.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Neelima Muralidharan <neelima@ti.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Praneeth Bajjuri <praneeth@ti.com>,
	Pratheesh Gangadhar TK <pratheesh@ti.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Simon Horman <horms@kernel.org>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Daniel Machon <daniel.machon@microchip.com>,
	Eric Dumazet <edumazet@kernel.org>
X-In-Reply-To: <20261014-hsr_ptp-v9-0-2d20a2a0f816@linutronix.de>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>