🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11041

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

#11041
From: Sebastian Andrzej Siewior
Date: Wed, 04 Nov 2026 15:10
93 lines
13230 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.

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: <20261104-hsr_ptp-v10-2-2c4a38ad973c@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-356535-linux-kernel-netdev=dewy.ru
References: <20261104-hsr_ptp-v10-0-2c4a38ad973c@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-356535-linux-kernel-netdev=dewy.ru
From: bigeasy@linutronix.de (Sebastian Andrzej Siewior)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v10 2/8] hsr: Use skb_clone() while adding the HSR header
Date: Wed,  4 Nov 2026 16:10:38 +0100
Organization: Usenet Network
Message-ID: <20261104-hsr_ptp-v10-2-2c4a38ad973c@linutronix.de>
References: <20261104-hsr_ptp-v10-0-2c4a38ad973c@linutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3418932"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:BccR/RmbG0IHEFsTA1IEfHgjIxc= sha256:PvJWtpwPq6eMSXnDLiMdGJ2VP7XXgmtk7UmHqNfpPFg=
	sha1:p3oT6vn4eNPudZZag+67TrM/c0w= sha256:6TER40CZOF+L7XCyqZt6YrINZVEqXQrxePpTSeXd+Ns=
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 636FA112C20; Wed,  4 Nov 2026 18:23:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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, URIBL_BLOCKED=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=bmpUn3VX; dkim=neutral
	reason="invalid (unsupported algorithm ed25519-sha256)"
	header.d=linutronix.de header.b=5SqNw9ed
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 ftPR0WfR1kii;
	Wed,  4 Nov 2026 18:23:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-356535-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 207BF112C12; Wed,  4 Nov 2026 18:23:23 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 96BA1306E3; Wed,  4 Nov 2026 15:11:43 +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=1793805071;
	b=dg7GbIkj1M1UwpIWqRO6B+qILDC4nJ8NX1ZOGm9VUbdW3igOZVQTWnhGKdBx1qPhZye0
	 AtcNTCP0TlRhHSJWsyk4m1nAOBfRf7HMqbTqR9ZRMsM1iSZAIVWINp2zUw1z5TJlUXgFo
	 vsDth6UpzCOijh8AcaU+HNZG2STu2siUjJNZUPIFA37BeuJD5Fdsr2E/obZrjcUnMPuUr
	 pH+OovrcrCApFZPrA2MJ6zl+Rqkk5YKKP5zsoZ+PeVxN9y8zaeuUQp5XjC6XE86IjSr4G
	 DAQoF/zduSMFSTKTMmjjBMCeURTI7mfVfa4T3zrFaBUcuT/iNVDKGdvK0oQ7uNKM0mw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793805071;
	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=Pk7eIp3MYrwXSarqTn5cvtxQfD6X7+eKRfE/ltgZX2g=;
	b=ryZR4TB++LDTHjTF6JkEJRGzltusIDWNje7/5qY8Fb5peOd504OHzxNwYH1DOeZjGJKP
	 Mwx1POaRqdmeyxDcoHPBhotZFwbpaa1zS0u1d0gaQZMVzt+9V7HoiJMNSnLj2022cnYHt
	 /fO+OBzn281cz0N0YCrNu7oGk51TUyz7u8vrBlxt3t8f+6TQJWJ5GVGh8YOjbzmUdkHh2
	 83cHL03vYE/2szllEl6/MNQWzAbKU4ZUND3ZOA5OuwGOznRTpPVb9Qh2rb5Q7sdnFR0cY
	 xn6obpI3Nhj6evO3J+bZrQ1wIAtPla08tythrs6nKcx7mxbqvDv92MpIZpxL7yGO/Nw==
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=bmpUn3VX;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=5SqNw9ed;
	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 0DADD606EE92;
	Wed,  4 Nov 2026 15:11:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=bmpUn3VX;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=5SqNw9ed
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=1793805053;
	b=PCTrAllZ6V+ZIzfIdH3HJ0st2NyBLRMy4jhzQ7BzkbaDChBcZH6x8GAsdCfBqXTSeUrb
	 mCEU3yUoHPQc3ymA7AasEXf7TTfiJJUt1LARhuPZrhtkQRLhoZ8/x+B5m/G8ps/EbgPtx
	 rjxcxm6hPcYtrAjlHjL1RItUJObMcuFFqi2pyOINhR3QqDiw1Veu+iJOF/ZB+rNb+mLm9
	 R99oVtPEopfnY2HZ/VsJAXPwfSLdzqLQW58EIybGoUOhqe+317F3CZKPEaKNaIM+Ky5dX
	 i2G75/QQO+yv4uQ0tQHULoQDsZxcqppvcHdXo9TqgupdlfvgyonDmd5IiJBM9OUGy/Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793805053;
	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=Pk7eIp3MYrwXSarqTn5cvtxQfD6X7+eKRfE/ltgZX2g=;
	b=KlTEQei3RNOwUvhhWC6Qm7ZaxBOwtFvsVfqKO5WTcPbsTP3Hiw4OE5H/PhcoRMCOTdL0
	 oRY0pHTy8elPjbPMtQWcaCJ8S3/ne8oU2kD6wRDmSOBEBaoEGfczmOo1c9CqqidcjHAHL
	 n8eZCxkYpP5hk/OPy7YABkVRGwFP7PyZbIzOqpjTSV3PhLeD+KYcNVAfbR4i2cH1wsXH5
	 08E7fgzS2exktUDlGEP9vxs7O9Dt9uwmYcrRzHrgCFjYojwGFQ89aOsk+0+3tBZwdzZdq
	 909/haZYkM6iIFuDowg4iccoJWmpc8PyjXGVXQzJXKLlPuC0mcRRcK5H/3M2fYd3v7g==
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=bmpUn3VX;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=5SqNw9ed;
	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 43E3C606A334
	for <netdev@vger.kernel.org>; Wed,  4 Nov 2026 15:10:53 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 43E3C606A334
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=1793805051;
	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=Pk7eIp3MYrwXSarqTn5cvtxQfD6X7+eKRfE/ltgZX2g=;
	b=bmpUn3VXKgaFqNDEQeN+r4ttmSh6ZAFc4+hSBTABOAEXdFr55z8UtID0AFlqzwQCGnkHwV
	3aE1X+E45arjDQxiV7vM3oJnQrRFL+iPjcNpQpwc19VrklfVdjHOAlmaNw5+1guwnkUi/l
	gVqFWTfc95iMZBpXJOJbPG4iu7JJqp5AU+veYDu/FWtj59njmC2/z8KdnMD6FVg8nIC1SN
	Lmy6hM0W8wo/e+CZwxlfZlKNpXJVM6pL6nXVWdjqV826yHHqiY3qgGzb4FhTWJR/72yxKG
	e45VLoDde7OtjOCpZ2MOWVAwUzQ5cn8e4gNxhHQpvXx5HHFoo5GY5badpGfGRw==
X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020e; t=1793805051;
	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=Pk7eIp3MYrwXSarqTn5cvtxQfD6X7+eKRfE/ltgZX2g=;
	b=5SqNw9ed4ZdRWpjk/lqUJiuGLo0SzM/VEg1c3hDZ94ZjJPzzBviY5FpaU83KX/qDpzSNwh
	tLehfQ1vQ/yeHGCA==
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: <20261104-hsr_ptp-v10-0-2c4a38ad973c@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