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

net/packet: Add getsockopt support for PACKET_COPY_THRESH

Currently getsockopt does not support PACKET_COPY_THRESH,
and we are unable to get the value of PACKET_COPY_THRESH
socket option through getsockopt.

This patch adds getsockopt support for PACKET_COPY_THRESH.

In addition, this patch converts access to copy_thresh to
READ_ONCE/WRITE_ONCE.

Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Link: https://lore.kernel.org/r/AM6PR03MB58487A9704FD150CF76F542899272@AM6PR03MB5848.eurprd03.prod.outlook.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Juntong Deng and committed by
Jakub Kicinski
76839e2f 8b6d307f

+6 -3
+5 -2
net/packet/af_packet.c
··· 2318 2318 } 2319 2319 if (po->tp_version <= TPACKET_V2) { 2320 2320 if (macoff + snaplen > po->rx_ring.frame_size) { 2321 - if (po->copy_thresh && 2321 + if (READ_ONCE(po->copy_thresh) && 2322 2322 atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf) { 2323 2323 if (skb_shared(skb)) { 2324 2324 copy_skb = skb_clone(skb, GFP_ATOMIC); ··· 3836 3836 if (copy_from_sockptr(&val, optval, sizeof(val))) 3837 3837 return -EFAULT; 3838 3838 3839 - pkt_sk(sk)->copy_thresh = val; 3839 + WRITE_ONCE(pkt_sk(sk)->copy_thresh, val); 3840 3840 return 0; 3841 3841 } 3842 3842 case PACKET_VERSION: ··· 4089 4089 break; 4090 4090 case PACKET_VNET_HDR_SZ: 4091 4091 val = READ_ONCE(po->vnet_hdr_sz); 4092 + break; 4093 + case PACKET_COPY_THRESH: 4094 + val = READ_ONCE(pkt_sk(sk)->copy_thresh); 4092 4095 break; 4093 4096 case PACKET_VERSION: 4094 4097 val = po->tp_version;
+1 -1
net/packet/diag.c
··· 17 17 pinfo.pdi_index = po->ifindex; 18 18 pinfo.pdi_version = po->tp_version; 19 19 pinfo.pdi_reserve = po->tp_reserve; 20 - pinfo.pdi_copy_thresh = po->copy_thresh; 20 + pinfo.pdi_copy_thresh = READ_ONCE(po->copy_thresh); 21 21 pinfo.pdi_tstamp = READ_ONCE(po->tp_tstamp); 22 22 23 23 pinfo.pdi_flags = 0;