Article View: linux.kernel.netdev
Article #19743[PATCH net-next v11 2/8] hsr: Use skb_clone() while adding the HSR header
From: Sebastian Andrzej Siewior
Date: Fri, 20 Nov 2026 10:16
Date: Fri, 20 Nov 2026 10:16
94 lines
13233 bytes
13233 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:
<20261120-hsr_ptp-v11-2-264c88f4f1d0@linutronix.de>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367846-linux-kernel-netdev=dewy.ruReferences:
<20261120-hsr_ptp-v11-0-264c88f4f1d0@linutronix.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367846-linux-kernel-netdev=dewy.ru From: bigeasy@linutronix.de (Sebastian Andrzej Siewior) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v11 2/8] hsr: Use skb_clone() while adding the HSR header Date: Fri, 20 Nov 2026 11:16:58 +0100 Organization: Usenet Network Message-ID: <20261120-hsr_ptp-v11-2-264c88f4f1d0@linutronix.de> References: <20261120-hsr_ptp-v11-0-264c88f4f1d0@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="3131090"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:1On/557n59H4Ohwnzv2NEsw8nEM= sha256:3IqPSbrfYo+Lt+JbdYPvjf4UoOdmiecBVZnzSTw9qTI= sha1:Df4LfNlLVc7Ts+IiBBbJQnedj40= sha256:LV4+MlpItb5s/IiUDToVYgZoWjfSgL/n3g5ASJoHSfo= 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 273F4115943; Fri, 20 Nov 2026 13:17:34 +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=L2ecgBV8; dkim=neutral reason="invalid (unsupported algorithm ed25519-sha256)" header.d=linutronix.de header.b=u6MRp2dg 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 2M77IVcZopZ7; Fri, 20 Nov 2026 13:17:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-367846-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 A9146115945; Fri, 20 Nov 2026 13:17:16 +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 D5BC16249F2; Fri, 20 Nov 2026 10:17:15 +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=1795169832; b=v7B79k27i1OmjVCdN7KQwMWHt3cH/iY6+W4iP+6pkaHP7UNVJxZvHVAJMXXhHDY9I3qe /tGNVhYnB2i8XCueNzV8RZ8Do1yGkMK4dWnE6t06oQ6nyPPPiuBJ+XNXjdOvrKCTDWVZb yy6qjjQ/Jk7W/eRve0baEkU7UhNl7qyx7wtWMboH009jXubD3VzYozze70U67825T9Bkh KL2pPkdPz1C61+Z17HSh6HzR4j/s6aI9rIo8DAoCBpLRuLtHXCjpO8Sz7rsPvKLfAfwpr cUKkGy3i5+pbvGtyzRHliE4CoiDD3yFaWrrhEqQ3cMK4ITUg4TG/HIhdaB4Jq+r+bAA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795169832; 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=QumI+id89tlxSyiZKedxpDxlAm7srg057YYhq2iiC/IcE7WAOboif8Hxf266pt7ZMDBk nnsRd2tBrcD1u4cCBzuL6ne7Y+gdbzO9w13ar91DMMd8mCdFZK6abxaptrWIwnCKCRD0W ASWUjiizixUYFdIY13KKI5SjcriUfkiyKtzgz86crg2CscwcpD+Kr36D80+JFsAYGF2TL nDNw1B4p58rVBSS5uKdtS5yes2mipXVnF5//Cwl6UXQwTjqy/nO01UeNoXbTauGmq383J Yc+F51JGSSknaBVW3sn2pp4vqgKHFrrLbHYvP4d1yYlWbChTUOZI30qKCVD88RauzzA== 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=L2ecgBV8; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=u6MRp2dg; 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 AD33760A2603; Fri, 20 Nov 2026 10:17:12 +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=L2ecgBV8; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=u6MRp2dg 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=1795169831; b=bCk9uCqM+vZlJ+vN5xShCx8L53xyl89UYqKD7DYRO36UawaSS0pLtb5zn75lajQiSCVK L5WHbCrDJBD6XHK1psMcnn/yUp/t2x5wugO29pqpN2O8mRkmc1blcb5yf7T+LlDtN7FcF fXOiPXWNqP5LpMHVuJJD9ggUSmta17oV4Ouil4wrSgz0iacnvBPippIBfDxx1jv7fd3s2 ufd2bd6vW3QVQ2fu1uCtOLUFXmEomhNs6WCxu0uKpJX3QEZkoAUQXE69ikIjol7UffY4J 0/ZaqfPqzRaHkX9E7o3fcS5rxPxR4BRQBAscwDhoDPhxok7gI9Eq7CX6M5WgecTeVig== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795169831; 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=4vXzHd9jg+vNGBnUba2NYwFgE/umXf137Uq6eJ/iOVLNJ18fj7li00Q64vrU+JWDQKGU jIoxhWDhDXSdH7tbYmGT4WA0U4e2bmnHfqxe3/0OCG7CIzF9ncH156TCol1KpTuLwhC3q 9orfRmSJAEKSY3NYDgR8iRMtuhdH2hRAikeM37aKWXpOoKveZaUTWO9Frq96tQc72SQV4 Ef8Okcn/MpwaZNogE1fCwq6/yjs+JEiI0UY3XnxWYSUh0BkoymhbkC0rLYSgN+JJ/kWCh 35GLkVzHYo/VXuxJiH0gsZoH+EAe8x2JoB+OPYKwNDZ6nXj/DlWI5WybUpTeFwabfpQ== 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=L2ecgBV8; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=u6MRp2dg; 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 62613606A326 for <netdev@vger.kernel.org>; Fri, 20 Nov 2026 10:17:11 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 62613606A326 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=1795169830; 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=L2ecgBV8molpFNj/yMEFLH5y+UgTOyKxBBsxm1m/jERkUgDLL5FJOpqdHI3zYVkp5Au6k2 gTo/ayK57UXZgJfdBQmJr3yhlfvIi2gb9QqQCxcc2kAV3GGVsHkQbraFRiD8UQNRlIdLO2 ek8FmFHZZi6QbiuEvNcofoSpNhbXrvtA5Knrew4hpuQp0aE0kvZCMn5aisVtLfdvtA8mNv tLb3bXjoURoYEFAfXQahjxmZLZcvl8l5Y6pLjHim4ZYO9nFBBbFo6KuJndn3mo8ispdZHy MNHJa7Soipj2IvnLKcoglD+Ocjg4zyLFBhd5jSnPnOMazGrf99+tQdNikPSnFA== X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1795169830; 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=u6MRp2dgQpTkNIP3BHQkV0DGU1ASYD07HRI8zfpResiBKHIY93o2WYnsTfOUDVknYdRhTK VJSOU1GGkj3OIbAw== 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: <20261120-hsr_ptp-v11-0-264c88f4f1d0@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