From nobody Tue Feb 10 02:00:33 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D7D462C08A2; Sat, 31 Jan 2026 13:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769865914; cv=none; b=q5KH2zw+iBvQVPMMPJTGAyScS88UJZK2AN1/5Swnwlp3NHDV2AUHt4rmVLPZJuSIn7Y1CG2AXa7TgLY9bt+8HZAWjCJBKtRAJzA55vVVoXyZLAVsd9sWqz+UyzV+PsehMl87eqOvpa072lbsYxDPu8Dg4/P2boA2LR1fYsuIboQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769865914; c=relaxed/simple; bh=JBFIByEVATCHIEF3t0UYW6l3zge4t/kRXZbMpYmFA+c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GHvTY5+cGQs27UuquLK5ilfxYfZ1F/bw/dSXriTocJCGYPeNq+uFw15TFCTGNkL94hz3CLGhsoV9xhYRec79MmDNOwCKxi12TEbpAqgsyJol2FNmQYCf1yMphiiaM1U75JoTnV3DvfX7z3CFhep46Sp4CUHplBAQmrD/qsTyq4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Aa5GApEO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Aa5GApEO" Received: by smtp.kernel.org (Postfix) with ESMTPS id A7253C19422; Sat, 31 Jan 2026 13:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769865914; bh=JBFIByEVATCHIEF3t0UYW6l3zge4t/kRXZbMpYmFA+c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Aa5GApEONe4TwYearyLmtBDnXFUAIRbYkmTxA4Dm6cvXE00r8YA3r35i4ja7CpQPm nkhOe8U1dMbDRzHcCCAbTOGDc4NR6rYD2ju0ydYjXYniE/GUsJWtJdYIfj2b3ftXTQ sOMn2rgdTtN1LC1KM3Y5WcdmuVO7XuoCigLmz/ALTMyFs1kBpDGzwbhRhx1YoxMDMy WfThRGsVDz8S8Lt2wWB/C0R5xbQfQb9+03jrK5GAidQtPGAKxISugGP1D3Rl2IkHPR vhciGkB0hUdCwDRr1Ul8rcetAPaHfxcTZufwVEbghY/SmmR1VSVlj6vwS009sviMyx Qjgsd7qO7wcYQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 966EED79768; Sat, 31 Jan 2026 13:25:14 +0000 (UTC) From: Oliver Hartkopp via B4 Relay Date: Sat, 31 Jan 2026 14:25:06 +0100 Subject: [PATCH net-next v7 1/6] can: use skb hash instead of private variable in headroom Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260131-can_skb_ext-v7-1-dd0f8f84a83d@hartkopp.net> References: <20260131-can_skb_ext-v7-0-dd0f8f84a83d@hartkopp.net> In-Reply-To: <20260131-can_skb_ext-v7-0-dd0f8f84a83d@hartkopp.net> To: Marc Kleine-Budde , Vincent Mailhol , Oliver Hartkopp , Robin van der Gracht , Oleksij Rempel , kernel@pengutronix.de, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org X-Mailer: b4 0.15-dev-47773 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769865912; l=9579; i=socketcan@hartkopp.net; s=20260128; h=from:subject:message-id; bh=zxcFoiKJF2100rOz6zKnSRW+KicEl2DYfMk7Y/gmvbI=; b=tK4aoNPj/tHvEntrs9XW92XjPUlxd5ahjpKrlBEXuP4ddg2MD2oqZWIObXI/BbfcAdsWjK/9/ Jig6snYi6xJA0gDqYHIRSr08JDNNl3A34e1wSjl+bZ1Mh0Yfmgps0t3 X-Developer-Key: i=socketcan@hartkopp.net; a=ed25519; pk=/gU/7/wBqak3kTsTeFbCCqUi9dnh+1i6ITEkfPj/BvU= X-Endpoint-Received: by B4 Relay for socketcan@hartkopp.net/20260128 with auth_id=620 X-Original-From: Oliver Hartkopp Reply-To: socketcan@hartkopp.net From: Oliver Hartkopp The can_skb_priv::skbcnt variable is used to identify CAN skbs in the RX path analogue to the skb->hash. As the skb hash is not filled in CAN skbs move the private skbcnt value to skb->hash and set skb->sw_hash accordingly. The skb->hash is a value used for RPS to identify skbs. Use it as intended. Signed-off-by: Marc Kleine-Budde Signed-off-by: Oliver Hartkopp --- drivers/net/can/dev/skb.c | 2 -- include/linux/can/core.h | 1 + include/linux/can/skb.h | 2 -- net/can/af_can.c | 14 +++++++++++--- net/can/bcm.c | 2 -- net/can/isotp.c | 3 --- net/can/j1939/socket.c | 1 - net/can/j1939/transport.c | 2 -- net/can/raw.c | 7 +++---- 9 files changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c index 3ebd4f779b9b..0da615afa04d 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -200,11 +200,10 @@ static void init_can_skb_reserve(struct sk_buff *skb) skb_reset_mac_header(skb); skb_reset_network_header(skb); skb_reset_transport_header(skb); =20 can_skb_reserve(skb); - can_skb_prv(skb)->skbcnt =3D 0; } =20 struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **c= f) { struct sk_buff *skb; @@ -310,11 +309,10 @@ static bool can_skb_headroom_valid(struct net_device = *dev, struct sk_buff *skb) =20 /* af_packet does not apply CAN skb specific settings */ if (skb->ip_summed =3D=3D CHECKSUM_NONE) { /* init headroom */ can_skb_prv(skb)->ifindex =3D dev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; =20 skb->ip_summed =3D CHECKSUM_UNNECESSARY; =20 /* perform proper loopback on capable devices */ if (dev->flags & IFF_ECHO) diff --git a/include/linux/can/core.h b/include/linux/can/core.h index 5fb8d0e3f9c1..3287232e3cad 100644 --- a/include/linux/can/core.h +++ b/include/linux/can/core.h @@ -56,8 +56,9 @@ extern void can_rx_unregister(struct net *net, struct net= _device *dev, canid_t can_id, canid_t mask, void (*func)(struct sk_buff *, void *), void *data); =20 extern int can_send(struct sk_buff *skb, int loop); +void can_set_skb_uid(struct sk_buff *skb); void can_sock_destruct(struct sock *sk); =20 #endif /* !_CAN_CORE_H */ diff --git a/include/linux/can/skb.h b/include/linux/can/skb.h index 1abc25a8d144..869ea574a40a 100644 --- a/include/linux/can/skb.h +++ b/include/linux/can/skb.h @@ -47,17 +47,15 @@ bool can_dropped_invalid_skb(struct net_device *dev, st= ruct sk_buff *skb); */ =20 /** * struct can_skb_priv - private additional data inside CAN sk_buffs * @ifindex: ifindex of the first interface the CAN frame appeared on - * @skbcnt: atomic counter to have an unique id together with skb pointer * @frame_len: length of CAN frame in data link layer * @cf: align to the following CAN frame at skb->data */ struct can_skb_priv { int ifindex; - int skbcnt; unsigned int frame_len; struct can_frame cf[]; }; =20 static inline struct can_skb_priv *can_skb_prv(struct sk_buff *skb) diff --git a/net/can/af_can.c b/net/can/af_can.c index 770173d8db42..70659987ef4d 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -639,10 +639,20 @@ static int can_rcv_filter(struct can_dev_rcv_lists *d= ev_rcv_lists, struct sk_buf } =20 return matches; } =20 +void can_set_skb_uid(struct sk_buff *skb) +{ + /* create non-zero unique skb identifier together with *skb */ + while (!(skb->hash)) + skb->hash =3D atomic_inc_return(&skbcounter); + + skb->sw_hash =3D 1; +} +EXPORT_SYMBOL(can_set_skb_uid); + static void can_receive(struct sk_buff *skb, struct net_device *dev) { struct can_dev_rcv_lists *dev_rcv_lists; struct net *net =3D dev_net(dev); struct can_pkg_stats *pkg_stats =3D net->can.pkg_stats; @@ -650,13 +660,11 @@ static void can_receive(struct sk_buff *skb, struct n= et_device *dev) =20 /* update statistics */ atomic_long_inc(&pkg_stats->rx_frames); atomic_long_inc(&pkg_stats->rx_frames_delta); =20 - /* create non-zero unique skb identifier together with *skb */ - while (!(can_skb_prv(skb)->skbcnt)) - can_skb_prv(skb)->skbcnt =3D atomic_inc_return(&skbcounter); + can_set_skb_uid(skb); =20 rcu_read_lock(); =20 /* deliver the packet to sockets listening on all devices */ matches =3D can_rcv_filter(net->can.rx_alldev_list, skb); diff --git a/net/can/bcm.c b/net/can/bcm.c index 7eba8ae01a5b..8ed60f18c2ea 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -314,11 +314,10 @@ static void bcm_can_tx(struct bcm_op *op) if (!skb) goto out; =20 can_skb_reserve(skb); can_skb_prv(skb)->ifindex =3D dev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; =20 skb_put_data(skb, cf, op->cfsiz); =20 /* send with loopback */ skb->dev =3D dev; @@ -1342,11 +1341,10 @@ static int bcm_tx_send(struct msghdr *msg, int ifin= dex, struct sock *sk, kfree_skb(skb); return -ENODEV; } =20 can_skb_prv(skb)->ifindex =3D dev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; skb->dev =3D dev; can_skb_set_owner(skb, sk); err =3D can_send(skb, 1); /* send with loopback */ dev_put(dev); =20 diff --git a/net/can/isotp.c b/net/can/isotp.c index ce588b85665a..4bb60b8f9b96 100644 --- a/net/can/isotp.c +++ b/net/can/isotp.c @@ -228,11 +228,10 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 = flowstatus) return 1; } =20 can_skb_reserve(nskb); can_skb_prv(nskb)->ifindex =3D dev->ifindex; - can_skb_prv(nskb)->skbcnt =3D 0; =20 nskb->dev =3D dev; can_skb_set_owner(nskb, sk); ncf =3D (struct canfd_frame *)nskb->data; skb_put_zero(nskb, so->ll.mtu); @@ -778,11 +777,10 @@ static void isotp_send_cframe(struct isotp_sock *so) return; } =20 can_skb_reserve(skb); can_skb_prv(skb)->ifindex =3D dev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; =20 cf =3D (struct canfd_frame *)skb->data; skb_put_zero(skb, so->ll.mtu); =20 /* create consecutive frame */ @@ -1007,11 +1005,10 @@ static int isotp_sendmsg(struct socket *sock, struc= t msghdr *msg, size_t size) goto err_out_drop; } =20 can_skb_reserve(skb); can_skb_prv(skb)->ifindex =3D dev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; =20 so->tx.len =3D size; so->tx.idx =3D 0; =20 cf =3D (struct canfd_frame *)skb->data; diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c index ff9c4fd7b433..1589e8ca634e 100644 --- a/net/can/j1939/socket.c +++ b/net/can/j1939/socket.c @@ -895,11 +895,10 @@ static struct sk_buff *j1939_sk_alloc_skb(struct net_= device *ndev, if (!skb) goto failure; =20 can_skb_reserve(skb); can_skb_prv(skb)->ifindex =3D ndev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; skb_reserve(skb, offsetof(struct can_frame, data)); =20 ret =3D memcpy_from_msg(skb_put(skb, size), msg, size); if (ret < 0) goto free_skb; diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index 8656ab388c83..d5d3e5320f7a 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -599,11 +599,10 @@ sk_buff *j1939_tp_tx_dat_new(struct j1939_priv *priv, return ERR_PTR(-ENOMEM); =20 skb->dev =3D priv->ndev; can_skb_reserve(skb); can_skb_prv(skb)->ifindex =3D priv->ndev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; /* reserve CAN header */ skb_reserve(skb, offsetof(struct can_frame, data)); =20 /* skb->cb must be large enough to hold a j1939_sk_buff_cb structure */ BUILD_BUG_ON(sizeof(skb->cb) < sizeof(*re_skcb)); @@ -1534,11 +1533,10 @@ j1939_session *j1939_session_fresh_new(struct j1939= _priv *priv, return NULL; =20 skb->dev =3D priv->ndev; can_skb_reserve(skb); can_skb_prv(skb)->ifindex =3D priv->ndev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; skcb =3D j1939_skb_to_cb(skb); memcpy(skcb, rel_skcb, sizeof(*skcb)); =20 session =3D j1939_session_new(priv, skb, size); if (!session) { diff --git a/net/can/raw.c b/net/can/raw.c index 12293363413c..fb4f9c854df0 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -74,11 +74,11 @@ MODULE_ALIAS("can-proto-1"); * storing the single filter in dfilter, to avoid using dynamic memory. */ =20 struct uniqframe { const struct sk_buff *skb; - int skbcnt; + u32 hash; unsigned int join_rx_count; }; =20 struct raw_sock { struct sock sk; @@ -162,21 +162,21 @@ static void raw_rcv(struct sk_buff *oskb, void *data) } } =20 /* eliminate multiple filter matches for the same skb */ if (this_cpu_ptr(ro->uniq)->skb =3D=3D oskb && - this_cpu_ptr(ro->uniq)->skbcnt =3D=3D can_skb_prv(oskb)->skbcnt) { + this_cpu_ptr(ro->uniq)->hash =3D=3D oskb->hash) { if (!ro->join_filters) return; =20 this_cpu_inc(ro->uniq->join_rx_count); /* drop frame until all enabled filters matched */ if (this_cpu_ptr(ro->uniq)->join_rx_count < ro->count) return; } else { this_cpu_ptr(ro->uniq)->skb =3D oskb; - this_cpu_ptr(ro->uniq)->skbcnt =3D can_skb_prv(oskb)->skbcnt; + this_cpu_ptr(ro->uniq)->hash =3D oskb->hash; this_cpu_ptr(ro->uniq)->join_rx_count =3D 1; /* drop first frame to check all enabled filters? */ if (ro->join_filters && ro->count > 1) return; } @@ -956,11 +956,10 @@ static int raw_sendmsg(struct socket *sock, struct ms= ghdr *msg, size_t size) if (!skb) goto put_dev; =20 can_skb_reserve(skb); can_skb_prv(skb)->ifindex =3D dev->ifindex; - can_skb_prv(skb)->skbcnt =3D 0; =20 /* fill the skb before testing for valid CAN frames */ err =3D memcpy_from_msg(skb_put(skb, size), msg, size); if (err < 0) goto free_skb; --=20 2.51.0