🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24505

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

#24505
From: Sebastian Andrzej Siewior
Date: Mon, 30 Nov 2026 08:52
94 lines
13185 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: <20261130-hsr_ptp-v13-2-598326208fc5@linutronix.de>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374036-linux-kernel-netdev=dewy.ru
References: <20261130-hsr_ptp-v13-0-598326208fc5@linutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374036-linux-kernel-netdev=dewy.ru
From: bigeasy@linutronix.de (Sebastian Andrzej Siewior)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v13 2/8] hsr: Use skb_clone() while adding the HSR header
Date: Mon, 30 Nov 2026 09:52:19 +0100
Organization: Usenet Network
Message-ID: <20261130-hsr_ptp-v13-2-598326208fc5@linutronix.de>
References: <20261130-hsr_ptp-v13-0-598326208fc5@linutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1383969"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:NCJOslETYecSpkxRO8VywW5ejuM= sha256:8V/tUl/RKXyYc++jSgBU+kmX69DodgbBCUsTNpDudXM=
	sha1:D2D9QCHVBAerc0D7MwEENhomUpc= sha256:NlIS4b+F2P0w7wnxgomrOWkMuxLN+1v/X+Vm0EN31i8=
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 CA0C0125FD3; Mon, 30 Nov 2026 11:52:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.151
X-Spam-Status: No, score=-3.151 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.249, 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=k41ReKIU; dkim=neutral
	reason="invalid (unsupported algorithm ed25519-sha256)"
	header.d=linutronix.de header.b=h+V1ckGw
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 OAvdVLm7KoMX;
	Mon, 30 Nov 2026 11:52:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-374036-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 29592125FCF; Mon, 30 Nov 2026 11:52:39 +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 582B0601278; Mon, 30 Nov 2026 08:52:39 +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=1796028752;
	b=ksGKCpFQrXQfOpM50ONQdWBXHooPKIov8/lUK0v+U6tLSW62A529lIbYUYmkclF1mEc7
	 R2QXq8wl6+/oqtqb9/+/bpvYCEHZQhL75jr/sfQ/vMiOAsa780mGj8X2xwDH1j+A24C/l
	 xVUz9ryC8nXoWJfxNwZNcuS8Qx4xemJ74Wn1MhSUxCsPdJGg5I5Fl+DzEU2RSYxrA+OCK
	 D5rGacZWKZJ4UKqtmrx5RjrpVvhyKl4810F4vkB/twe5OjWKdzZxEFATWQOkpfIVBJmAn
	 HuocUtTCPZznFCK5p+dzy1DIMAUNsIwoahJpfzrq3uIhzugoem1pqnbmTSpZVBs4nqQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796028752;
	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=VskFyHQYWH3WbvDeTb8zYQ+3fB5ESDKJTclqQ+uCyRuIqgIy8T84A8OdrUJeogez0SgH
	 ACt0ZdbftFn1AKt9l+aYSTNrl50EbULyZ102XWlnvzQFORrhak3lCSBw4hAyjYs2vTrv2
	 DVcg7dwnG3kxDKVMVK5pEWueCJ5SEsg0KgQPzFs7VeXJsKsY0ZWBV8zlCtigXyFpw2Tqw
	 lQDBvHie+1AifBeKAvWvoxpN12eQMkQpVHIpP8ttxInD1X0iuCywQ2PxEB1Fe72tO073b
	 x0ALhE6f1SJodjiQ5nM5ZWuv0O9IBe6HMvkXo6Zj1ynawYyXwm4MqFeUTkKCPRyemZg==
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=k41ReKIU;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=h+V1ckGw;
	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 1F922606A693;
	Mon, 30 Nov 2026 08:52:32 +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=k41ReKIU;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=h+V1ckGw
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=1796028751;
	b=4W5HmTJadD4shU02jPtCndSa1NUnMUepDS9Q7/IBgqcg1YfQmJXqMtW9WkFkYGXJtWPP
	 SbOtOjPrcRI7SDAXwx0fYuwiabSx7KZOw1HezHeIaARBg354acMRUBokYOruN/YKhkDXV
	 QmI/TWaaVSgb5HI384vxa382ue+J28A3ofyDwI3Bqhgi4dnzx4YXJ+PoLvMKRkSvSrBVs
	 GGsn87quH3ri4qzWGfWSJZCnEv3BYAirjICEdFbikQlm4HXwXoD9NE2xdOUTdim3ajU3u
	 WvF21YeB3JLpzNq0u/LF+p+K8mQ9M6hGXr1kE5johfkWwgyGAKY/xTAlTkx2+XHSheQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796028751;
	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=H2H/IHlP70xPA+gcBg7dULi/crRByAtOtmtObE8y5h6hrSYX19l/zm5RE/fJo/tataKm
	 XgynNyoJjdUehPE1mNu4iTHFAfXrCD8Jwa4+G5qkeXWBWNozYhY52VeUhB4xsKC+HQPVq
	 QPWK6SYBG6AwEt8M6MMfkJOGcd/+5M9NNc/fJOWIG6wALrWZKokihUPhuo5mqhFvODxcQ
	 Bh6gSjRJU18PQmRsztFnFqqUW/6WIOkxB2P0cIHavb3+qgrd9qWZY6OLYhMdyesBh3pnH
	 UGMMtDJgGzd/DW9iFmB5di7BF4wZ6ZXedGesmQzmB4MUCcmguNW9+OFe1Ke5RTmj/BQ==
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=k41ReKIU;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=h+V1ckGw;
	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 C5F72606A330
	for <netdev@vger.kernel.org>; Mon, 30 Nov 2026 08:52:30 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C5F72606A330
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=1796028749;
	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=k41ReKIUOWR91Gwdc5Opa1M8wKmFOvfdOsHGGz9Pi3n1X4FBX1PoB9rPMGQiaaSxSySrWQ
	qK78OpLDmpuuoE9XEnJakxu1xO7B34wlUXAcSt4BSpP7VLyyq6L40moWCV8kHrGe5RQxlB
	/s+LYLNcDaUKc5LgkElcZNCUdGXpVPQSEtdPWzN2K8bgIgAveXQSm0J26aVaLaz0c6Vqy6
	BjdNGHfqGBfBJyrfHJM0iVBrK1FcV+M4GGRUu+codtZQZOwGJ2irfdlvme9HEo6rLo+6kk
	/HIMfO8bOFqYib0lVCPJZT5M1370nH5a/0fsZAm8y0Wk3SA0M0IJ7YbVaYSZgQ==
X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020e; t=1796028749;
	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=h+V1ckGw37xEAdn9lhGU2Me7Xe8qTjQg0dnMer4PgSkmB1Ij3HCR9NY0Co5XrPu6tGFisH
	SyxoKEpMJGzGw2DA==
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: <20261130-hsr_ptp-v13-0-598326208fc5@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