Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

can: use skb hash instead of private variable in headroom

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 <mkl@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260201-can_skb_ext-v8-1-3635d790fe8b@hartkopp.net
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Oliver Hartkopp and committed by
Paolo Abeni
d4fb6514 0cbcc0fd

+15 -19
-2
drivers/net/can/dev/skb.c
··· 202 202 skb_reset_transport_header(skb); 203 203 204 204 can_skb_reserve(skb); 205 - can_skb_prv(skb)->skbcnt = 0; 206 205 } 207 206 208 207 struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf) ··· 311 312 if (skb->ip_summed == CHECKSUM_NONE) { 312 313 /* init headroom */ 313 314 can_skb_prv(skb)->ifindex = dev->ifindex; 314 - can_skb_prv(skb)->skbcnt = 0; 315 315 316 316 skb->ip_summed = CHECKSUM_UNNECESSARY; 317 317
+1
include/linux/can/core.h
··· 58 58 void *data); 59 59 60 60 extern int can_send(struct sk_buff *skb, int loop); 61 + void can_set_skb_uid(struct sk_buff *skb); 61 62 void can_sock_destruct(struct sock *sk); 62 63 63 64 #endif /* !_CAN_CORE_H */
-2
include/linux/can/skb.h
··· 49 49 /** 50 50 * struct can_skb_priv - private additional data inside CAN sk_buffs 51 51 * @ifindex: ifindex of the first interface the CAN frame appeared on 52 - * @skbcnt: atomic counter to have an unique id together with skb pointer 53 52 * @frame_len: length of CAN frame in data link layer 54 53 * @cf: align to the following CAN frame at skb->data 55 54 */ 56 55 struct can_skb_priv { 57 56 int ifindex; 58 - int skbcnt; 59 57 unsigned int frame_len; 60 58 struct can_frame cf[]; 61 59 };
+11 -3
net/can/af_can.c
··· 641 641 return matches; 642 642 } 643 643 644 + void can_set_skb_uid(struct sk_buff *skb) 645 + { 646 + /* create non-zero unique skb identifier together with *skb */ 647 + while (!(skb->hash)) 648 + skb->hash = atomic_inc_return(&skbcounter); 649 + 650 + skb->sw_hash = 1; 651 + } 652 + EXPORT_SYMBOL(can_set_skb_uid); 653 + 644 654 static void can_receive(struct sk_buff *skb, struct net_device *dev) 645 655 { 646 656 struct can_dev_rcv_lists *dev_rcv_lists; ··· 662 652 atomic_long_inc(&pkg_stats->rx_frames); 663 653 atomic_long_inc(&pkg_stats->rx_frames_delta); 664 654 665 - /* create non-zero unique skb identifier together with *skb */ 666 - while (!(can_skb_prv(skb)->skbcnt)) 667 - can_skb_prv(skb)->skbcnt = atomic_inc_return(&skbcounter); 655 + can_set_skb_uid(skb); 668 656 669 657 rcu_read_lock(); 670 658
-2
net/can/bcm.c
··· 316 316 317 317 can_skb_reserve(skb); 318 318 can_skb_prv(skb)->ifindex = dev->ifindex; 319 - can_skb_prv(skb)->skbcnt = 0; 320 319 321 320 skb_put_data(skb, cf, op->cfsiz); 322 321 ··· 1343 1344 } 1344 1345 1345 1346 can_skb_prv(skb)->ifindex = dev->ifindex; 1346 - can_skb_prv(skb)->skbcnt = 0; 1347 1347 skb->dev = dev; 1348 1348 can_skb_set_owner(skb, sk); 1349 1349 err = can_send(skb, 1); /* send with loopback */
-3
net/can/isotp.c
··· 230 230 231 231 can_skb_reserve(nskb); 232 232 can_skb_prv(nskb)->ifindex = dev->ifindex; 233 - can_skb_prv(nskb)->skbcnt = 0; 234 233 235 234 nskb->dev = dev; 236 235 can_skb_set_owner(nskb, sk); ··· 779 780 780 781 can_skb_reserve(skb); 781 782 can_skb_prv(skb)->ifindex = dev->ifindex; 782 - can_skb_prv(skb)->skbcnt = 0; 783 783 784 784 cf = (struct canfd_frame *)skb->data; 785 785 skb_put_zero(skb, so->ll.mtu); ··· 1007 1009 1008 1010 can_skb_reserve(skb); 1009 1011 can_skb_prv(skb)->ifindex = dev->ifindex; 1010 - can_skb_prv(skb)->skbcnt = 0; 1011 1012 1012 1013 so->tx.len = size; 1013 1014 so->tx.idx = 0;
-1
net/can/j1939/socket.c
··· 897 897 898 898 can_skb_reserve(skb); 899 899 can_skb_prv(skb)->ifindex = ndev->ifindex; 900 - can_skb_prv(skb)->skbcnt = 0; 901 900 skb_reserve(skb, offsetof(struct can_frame, data)); 902 901 903 902 ret = memcpy_from_msg(skb_put(skb, size), msg, size);
-2
net/can/j1939/transport.c
··· 601 601 skb->dev = priv->ndev; 602 602 can_skb_reserve(skb); 603 603 can_skb_prv(skb)->ifindex = priv->ndev->ifindex; 604 - can_skb_prv(skb)->skbcnt = 0; 605 604 /* reserve CAN header */ 606 605 skb_reserve(skb, offsetof(struct can_frame, data)); 607 606 ··· 1535 1536 skb->dev = priv->ndev; 1536 1537 can_skb_reserve(skb); 1537 1538 can_skb_prv(skb)->ifindex = priv->ndev->ifindex; 1538 - can_skb_prv(skb)->skbcnt = 0; 1539 1539 skcb = j1939_skb_to_cb(skb); 1540 1540 memcpy(skcb, rel_skcb, sizeof(*skcb)); 1541 1541
+3 -4
net/can/raw.c
··· 76 76 77 77 struct uniqframe { 78 78 const struct sk_buff *skb; 79 - int skbcnt; 79 + u32 hash; 80 80 unsigned int join_rx_count; 81 81 }; 82 82 ··· 164 164 165 165 /* eliminate multiple filter matches for the same skb */ 166 166 if (this_cpu_ptr(ro->uniq)->skb == oskb && 167 - this_cpu_ptr(ro->uniq)->skbcnt == can_skb_prv(oskb)->skbcnt) { 167 + this_cpu_ptr(ro->uniq)->hash == oskb->hash) { 168 168 if (!ro->join_filters) 169 169 return; 170 170 ··· 174 174 return; 175 175 } else { 176 176 this_cpu_ptr(ro->uniq)->skb = oskb; 177 - this_cpu_ptr(ro->uniq)->skbcnt = can_skb_prv(oskb)->skbcnt; 177 + this_cpu_ptr(ro->uniq)->hash = oskb->hash; 178 178 this_cpu_ptr(ro->uniq)->join_rx_count = 1; 179 179 /* drop first frame to check all enabled filters? */ 180 180 if (ro->join_filters && ro->count > 1) ··· 958 958 959 959 can_skb_reserve(skb); 960 960 can_skb_prv(skb)->ifindex = dev->ifindex; 961 - can_skb_prv(skb)->skbcnt = 0; 962 961 963 962 /* fill the skb before testing for valid CAN frames */ 964 963 err = memcpy_from_msg(skb_put(skb, size), msg, size);