🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26527

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

#26527
From: Sebastian Andrzej Siewior
Date: Thu, 03 Dec 2026 17:44
94 lines
13278 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 case does not need manual adjustment of sk_buff::csum_start
because by using skb_cow_head() the head does not move relative to the
payload. Should the head need expansion then pskb_expand_head() will
move it and update sk_buff::csum_start accordingly. The clone also
preserves metadata (if available) so skb_postpush_data_move() is used
instead of memmove() to move both. Finally skb_reset_mac_len() is added
to set the new length of the header after expansion.

This is a preparation for PTP handling where timestamps are requested.

Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
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 44f6d9c83180a..b183358207506 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, skb_metadata_len(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: <20261203-hsr_ptp-v14-2-1511ffd4c362@linutronix.de>
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376792-linux-kernel-netdev=dewy.ru
References: <20261203-hsr_ptp-v14-0-1511ffd4c362@linutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376792-linux-kernel-netdev=dewy.ru
From: bigeasy@linutronix.de (Sebastian Andrzej Siewior)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v14 2/8] hsr: Use skb_clone() while adding the HSR header
Date: Thu,  3 Dec 2026 18:44:43 +0100
Organization: Usenet Network
Message-ID: <20261203-hsr_ptp-v14-2-1511ffd4c362@linutronix.de>
References: <20261203-hsr_ptp-v14-0-1511ffd4c362@linutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2557050"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:M5+njJNMRJnOipUHXX9E4rO4j2g= sha256:eOqDQJfm80iVppRlESYFvhWOMspBAGqTrvMzXZgzen8=
	sha1:hnMVQh1riM7dKmRPC3OqsSy6HYk= sha256:uxzmYZPqIID12FBdvz22GHhLzZ1etCbFyTekH+2q19Q=
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 9F1B11179F5; Thu,  3 Dec 2026 20:45:16 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.399
X-Spam-Status: No, score=-3.399 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.001, 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=ttlDErXP; dkim=neutral
	reason="invalid (unsupported algorithm ed25519-sha256)"
	header.d=linutronix.de header.b=ZkurbsI3
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 nRCpHTFHVrCG;
	Thu,  3 Dec 2026 20:45:14 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-376792-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 707361179ED; Thu,  3 Dec 2026 20:45:01 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 98D80601D49; Thu,  3 Dec 2026 17:45:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796319897;
	b=uuIMQo7TaMp4ewmjLkqLARJRDMAyS9jv/45AlrzGU3Gv9x1CA5/vZSgrv0OFJlgfPSZ6
	 8VUWFQtM57lm7J+TpMeNEF76l6iJT6+jAZo+daOXmB+6h9uY/b2htW4KEaRbsaB+jauJR
	 4ZbRAF0y6KEggVEto5OkbtQMmm5C2h7jvrwR+WbKyN70d+ho+YiPSPQg4djUVURpnRXnI
	 GJOYXW/6wvXJ1xctKyCN9ddrnlSVbJFB6VSpqIEd1Dp1M0pRoN5oFGnjBKKqtVsItY59m
	 PtmswQtoYpDP34ip3VoayjJ1/x20l/7bk3TQJQ4PHeWHw/Znwbq++MDOikTQsCSzxHw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796319897;
	h=X-Original-To:Received:DMARC-Filter:From:DKIM-Signature:
	 DKIM-Signature:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=bWopGS2bI8XROBBmCVM7t13PvuhBwV4YLrZxWgs14Oc=;
	b=P6zbLRxy95aPtP7kfqDZktya46dfG7fy4QSskj2rVVZtVlto8em/Koamu7NtIZFUJAMb
	 An1MI4AaM2zKTkQ0rzv/tyaWYnTPniFu5Un4JeN+/6cJI61vcnBJo2R57UwLEa4EIhJy3
	 0tgYaY51F/ho3zMkcuZStRrp35AHgGWqcd82445n85scWuaWWeiGmWhYxUujLoqaiN/JZ
	 6v8cdYC0Q5yk+UZwpvLLB5Uy2LRF5+cDZV8BbiNhWLd4xeCfckPb+yV6zBhnKSSgft3GN
	 8jOlMAYclZUMZkCYNf3M53Us2yw9GABmucDtB5+MzS+z/XuvcdsROMVkgP5kHIlIlug==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=ttlDErXP;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=ZkurbsI3;
	dmarc=pass header.from=linutronix.de;
	spf=pass smtp.mailfrom=linutronix.de;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B67BF606A332;
	Thu,  3 Dec 2026 17:44:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=ttlDErXP;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=ZkurbsI3
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796319896;
	b=HWvMj+t9U45U/ndRkzq8TBJJ7tLO5vE5lh5R33qheO7tTgbMphSFbXXM3D+Q3/yNXMuk
	 8dC/UbWgc3NIyy/U6EfFxv5m7YL5NZtvYJQPMWqIcbEjZTHXUX1rLWcj4961fR/7uL6ZZ
	 vNQPRPeLV8LGQxn+OcH75pdpE3/3gBPPmpbkrrglazB0RxA89q/m40vBH0YU6TaX86xL+
	 Y7vc9YidGDbXbY8w8ZvJgph7aqGtTlS3Zdk6TPzI617pj/acfs/vx2jP9fWHVf1YU8pHk
	 x9BKUavBIUM8KORHrjH+ARYCUnokrPB/z5p4ormnYjXD+XO5EYy5cMYsED69qaB3qqA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796319896;
	h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:To:Cc:Subject:Date:
	 Message-ID:In-Reply-To:References:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=bWopGS2bI8XROBBmCVM7t13PvuhBwV4YLrZxWgs14Oc=;
	b=h0Ql04F1rJ4Av/eJ9bFCxc+po786PPGZ7MvYUMtn8bjP+WyU+x+fkx5yGYKXB3FH2Oeg
	 yrmYTGGMHlomZs3nYTJeP/XeMk5tBSnetvodnLTdQ7liiM+RREU/ahCkhqGv4Dy+OedPS
	 Y82q6DiZUoFdrVqHlLcLVEh7XX5NK6ZWZ8UWgkJXSkvfRSvo5E0aqcGQXlGfpqTLpnYPf
	 KzQXZP4E9x5zn0m4WIcyrEYdJmTYYXRirFnipSo1Wty7NNhaC2Yl1rjoWUVXWvifUmHrm
	 Gi6zyzIqq7SSyQjDDoKd20pvXnt6E2g6gSN2SQD+xdfX+6RyznIc4YLoErqht97n4cw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linutronix.de;
	spf=pass smtp.mailfrom=linutronix.de;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=ttlDErXP;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=ZkurbsI3;
	arc=none smtp.remote-ip=193.142.43.55
X-Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41974606A338
	for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 17:44:56 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 41974606A338
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=1796319894;
	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=bWopGS2bI8XROBBmCVM7t13PvuhBwV4YLrZxWgs14Oc=;
	b=ttlDErXPxlz0uLjUkmXm1f78BfJaEpsRG3GmBXwdwqW2TFcLB63GdaBRCr4peWmi/D4ad9
	8UJHN+XRjzRnPL7XswKbL0q9iRztYY7Ejfw/qJCEbMQIAXes+trs9UMm8hwiAkMq+k6g2T
	V5mlRvxl7PHJlMq2VJHBzl+Kh784M7lceto2DJ0x4KfGG3KA0Dn+bTrcQYdBD+z8TRRRw0
	FNDFmU7kroZ+g8Qy8ZGciG5/aDR9+9dfCrozhucVRlluG5YJmdPZ9DOdRq8pMPZt043GSV
	U/ifTg/2FAmN7GqaRmUCbENm5Zjz3oNF6sn4t5xaGAeBHOVshMgUcY38SGaFlg==
X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020e; t=1796319894;
	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=bWopGS2bI8XROBBmCVM7t13PvuhBwV4YLrZxWgs14Oc=;
	b=ZkurbsI3dmtYnS3jgLcOrueiR3o2dVcqOBTN9TS9omC/KFUlTlRMP5l6rj9OVDuyBK/nMT
	H21Xpjqp3rClc4Dw==
X-Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	"(JC), Jayachandran" <j-rameshbabu@ti.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	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: <20261203-hsr_ptp-v14-0-1511ffd4c362@linutronix.de>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list