Lines Matching +full:ref +full:- +full:clock +full:- +full:period +full:- +full:ns
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
13 * Corey Minyard <wf-rch!minyard@relay.EU.net>
14 * Florian La Roche <flla@stud.uni-sb.de>
57 #include <linux/cgroup-defs.h>
92 /* This is the per-socket lock. The spinlock provides a synchronization
94 * mini-semaphore synchronizes multiple users amongst themselves.
101 * We express the mutex-alike socket_lock semantics
119 * struct sock_common - minimal network layer representation of sockets
122 * @skc_addrpair: 8-byte-aligned __u64 union of @skc_daddr & @skc_rcv_saddr
133 * @skc_net_refcnt: socket is using net ref counting
136 * @skc_portaddr_node: second hash linkage for UDP/UDP-Lite protocol
143 * @skc_nulls_node: main hash linkage for TCP/UDP/UDP-Lite protocol
251 * struct sock - network layer representation of sockets
272 * @sk_reserved_mem: space reserved and non-reclaimable for the socket
291 * @sk_backlog: always used with the per-socket spinlock held
321 * @sk_bind_phc: SO_TIMESTAMPING bind PHC index of PTP virtual clock
326 * @sk_user_data: RPC layer private data. Write-protected by @sk_callback_lock.
330 * @tcp_rtx_queue: TCP re-transmit queue [union with @sk_send_head]
345 * @sk_rcu: used during RCU grace period
346 * @sk_clockid: clockid used by time-based scheduling (SO_TXTIME)
356 * don't add nothing before this first member (__sk_common) --acme
405 * the per-socket spinlock held and requires low latency
552 * - SK_USER_DATA_NOCOPY: Pointer stored in sk_user_data might
557 * - SK_USER_DATA_BPF: Mark whether sk_user_data field is
561 * - SK_USER_DATA_PSOCK: Mark whether pointer stored in
572 * sk_user_data_is_nocopy - Test if sk_user_data pointer must not be copied
577 return ((uintptr_t)sk->sk_user_data & SK_USER_DATA_NOCOPY); in sk_user_data_is_nocopy()
580 #define __sk_user_data(sk) ((*((void __rcu **)&(sk)->sk_user_data)))
583 * __locked_read_sk_user_data_with_flags - return the pointer
590 * The caller must be holding sk->sk_callback_lock.
598 lockdep_is_held(&sk->sk_callback_lock)); in __locked_read_sk_user_data_with_flags()
608 * __rcu_dereference_sk_user_data_with_flags - return the pointer
645 return read_pnet(&sk->sk_net); in sock_net()
651 write_pnet(&sk->sk_net, net); in sock_net_set()
670 return READ_ONCE(sk->sk_peek_off); in sk_peek_offset()
678 s32 off = READ_ONCE(sk->sk_peek_off); in sk_peek_offset_bwd()
681 off = max_t(s32, off - val, 0); in sk_peek_offset_bwd()
682 WRITE_ONCE(sk->sk_peek_off, off); in sk_peek_offset_bwd()
688 sk_peek_offset_bwd(sk, -val); in sk_peek_offset_fwd()
701 return hlist_entry(head->first, struct sock, sk_node); in __sk_head()
711 return hlist_nulls_entry(head->first, struct sock, sk_nulls_node); in __sk_nulls_head()
721 return hlist_entry_safe(sk->sk_node.next, struct sock, sk_node); in sk_next()
726 return (!is_a_nulls(sk->sk_nulls_node.next)) ? in sk_nulls_next()
727 hlist_nulls_entry(sk->sk_nulls_node.next, in sk_nulls_next()
734 return hlist_unhashed(&sk->sk_node); in sk_unhashed()
744 node->pprev = NULL; in sk_node_init()
749 __hlist_del(&sk->sk_node); in __sk_del_node()
757 sk_node_init(&sk->sk_node); in __sk_del_node_init()
771 refcount_inc(&sk->sk_refcnt); in sock_hold()
779 refcount_dec(&sk->sk_refcnt); in __sock_put()
787 /* paranoid for a while -acme */ in sk_del_node_init()
788 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_del_node_init()
798 hlist_nulls_del_init_rcu(&sk->sk_nulls_node); in __sk_nulls_del_node_init_rcu()
809 /* paranoid for a while -acme */ in sk_nulls_del_node_init_rcu()
810 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_nulls_del_node_init_rcu()
818 hlist_add_head(&sk->sk_node, list); in __sk_add_node()
830 if (IS_ENABLED(CONFIG_IPV6) && sk->sk_reuseport && in sk_add_node_rcu()
831 sk->sk_family == AF_INET6) in sk_add_node_rcu()
832 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_rcu()
834 hlist_add_head_rcu(&sk->sk_node, list); in sk_add_node_rcu()
840 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_tail_rcu()
845 hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_rcu()
850 hlist_nulls_add_tail_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_tail_rcu()
861 __hlist_del(&sk->sk_bind_node); in __sk_del_bind_node()
867 hlist_add_head(&sk->sk_bind_node, list); in sk_add_bind_node()
872 __hlist_del(&sk->sk_bind2_node); in __sk_del_bind2_node()
877 hlist_add_head(&sk->sk_bind2_node, list); in sk_add_bind2_node()
891 if (__sk && ({ node = &(__sk)->sk_nulls_node; 1; })) \
901 * sk_for_each_entry_offset_rcu - iterate over a list at a given struct offset
911 ({ tpos = (typeof(*tpos) *)((void *)pos - offset); 1;}); \
920 return sk->sk_socket->file->f_cred->user_ns; in sk_user_ns()
934 SOCK_USE_WRITE_QUEUE, /* whether to call sk->sk_write_space in sock_wfree */
947 * user-space instead.
951 SOCK_RCU_FREE, /* wait rcu grace period in sk_destruct() */
962 nsk->sk_flags = osk->sk_flags; in sock_copy_flags()
967 __set_bit(flag, &sk->sk_flags); in sock_set_flag()
972 __clear_bit(flag, &sk->sk_flags); in sock_reset_flag()
986 return test_bit(flag, &sk->sk_flags); in sock_flag()
1010 return gfp_mask | (sk->sk_allocation & __GFP_MEMALLOC); in sk_gfp_mask()
1015 WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog - 1); in sk_acceptq_removed()
1020 WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog + 1); in sk_acceptq_added()
1024 * return READ_ONCE(sk->sk_ack_backlog) >= READ_ONCE(sk->sk_max_ack_backlog);
1029 return READ_ONCE(sk->sk_ack_backlog) > READ_ONCE(sk->sk_max_ack_backlog); in sk_acceptq_is_full()
1037 return READ_ONCE(sk->sk_wmem_queued) >> 1; in sk_stream_min_wspace()
1042 return READ_ONCE(sk->sk_sndbuf) - READ_ONCE(sk->sk_wmem_queued); in sk_stream_wspace()
1047 WRITE_ONCE(sk->sk_wmem_queued, sk->sk_wmem_queued + val); in sk_wmem_queued_add()
1058 if (!sk->sk_backlog.tail) in __sk_add_backlog()
1059 WRITE_ONCE(sk->sk_backlog.head, skb); in __sk_add_backlog()
1061 sk->sk_backlog.tail->next = skb; in __sk_add_backlog()
1063 WRITE_ONCE(sk->sk_backlog.tail, skb); in __sk_add_backlog()
1064 skb->next = NULL; in __sk_add_backlog()
1074 unsigned int qsize = sk->sk_backlog.len + atomic_read(&sk->sk_rmem_alloc); in sk_rcvqueues_full()
1079 /* The per-socket spinlock must be held here. */
1084 return -ENOBUFS; in sk_add_backlog()
1092 return -ENOMEM; in sk_add_backlog()
1095 sk->sk_backlog.len += skb->truesize; in sk_add_backlog()
1109 return INDIRECT_CALL_INET(sk->sk_backlog_rcv, in sk_backlog_rcv()
1119 if (unlikely(READ_ONCE(sk->sk_incoming_cpu) != cpu)) in sk_incoming_cpu_update()
1120 WRITE_ONCE(sk->sk_incoming_cpu, cpu); in sk_incoming_cpu_update()
1139 /* Reading sk->sk_rxhash might incur an expensive cache line in sock_rps_record_flow()
1144 * IPv4: inet_sk(sk)->inet_daddr in sock_rps_record_flow()
1145 * IPv6: ipv6_addr_any(&sk->sk_v6_daddr) in sock_rps_record_flow()
1149 if (sk->sk_state == TCP_ESTABLISHED) in sock_rps_record_flow()
1150 sock_rps_record_flow_hash(sk->sk_rxhash); in sock_rps_record_flow()
1159 if (unlikely(sk->sk_rxhash != skb->hash)) in sock_rps_save_rxhash()
1160 sk->sk_rxhash = skb->hash; in sock_rps_save_rxhash()
1167 sk->sk_rxhash = 0; in sock_rps_reset_rxhash()
1198 if (unlikely(READ_ONCE(sk->sk_backlog.tail))) { in sk_flush_backlog()
1217 * un-modified. Special care is taken when initializing object to zero.
1223 memset(&sk->sk_node.pprev, 0, in sk_prot_clear_nulls()
1224 size - offsetof(struct sock, sk_node.pprev)); in sk_prot_clear_nulls()
1228 * socket layer -> transport layer interface
1361 atomic_inc(&sk->sk_prot->socks); in sk_refcnt_debug_inc()
1366 atomic_dec(&sk->sk_prot->socks); in sk_refcnt_debug_dec()
1368 sk->sk_prot->name, sk, atomic_read(&sk->sk_prot->socks)); in sk_refcnt_debug_dec()
1373 if (refcount_read(&sk->sk_refcnt) != 1) in sk_refcnt_debug_release()
1375 sk->sk_prot->name, sk, refcount_read(&sk->sk_refcnt)); in sk_refcnt_debug_release()
1388 if (sk->sk_prot->forward_alloc_get) in sk_forward_alloc_get()
1389 return sk->sk_prot->forward_alloc_get(sk); in sk_forward_alloc_get()
1391 return sk->sk_forward_alloc; in sk_forward_alloc_get()
1396 if (READ_ONCE(sk->sk_wmem_queued) >= READ_ONCE(sk->sk_sndbuf)) in __sk_stream_memory_free()
1399 return sk->sk_prot->stream_memory_free ? in __sk_stream_memory_free()
1400 INDIRECT_CALL_INET_1(sk->sk_prot->stream_memory_free, in __sk_stream_memory_free()
1424 return cgroup_is_descendant(sock_cgroup_ptr(&sk->sk_cgrp_data), in sk_under_cgroup_hierarchy()
1427 return -ENOTSUPP; in sk_under_cgroup_hierarchy()
1433 return sk->sk_prot->memory_pressure != NULL; in sk_has_memory_pressure()
1438 if (!sk->sk_prot->memory_pressure) in sk_under_memory_pressure()
1441 if (mem_cgroup_sockets_enabled && sk->sk_memcg && in sk_under_memory_pressure()
1442 mem_cgroup_under_socket_pressure(sk->sk_memcg)) in sk_under_memory_pressure()
1445 return !!*sk->sk_prot->memory_pressure; in sk_under_memory_pressure()
1451 return max(0L, atomic_long_read(prot->memory_allocated)); in proto_memory_allocated()
1457 return proto_memory_allocated(sk->sk_prot); in sk_memory_allocated()
1461 #define SK_MEMORY_PCPU_RESERVE (1 << (20 - PAGE_SHIFT))
1469 local_reserve = __this_cpu_add_return(*sk->sk_prot->per_cpu_fw_alloc, amt); in sk_memory_allocated_add()
1471 __this_cpu_sub(*sk->sk_prot->per_cpu_fw_alloc, local_reserve); in sk_memory_allocated_add()
1472 atomic_long_add(local_reserve, sk->sk_prot->memory_allocated); in sk_memory_allocated_add()
1483 local_reserve = __this_cpu_sub_return(*sk->sk_prot->per_cpu_fw_alloc, amt); in sk_memory_allocated_sub()
1484 if (local_reserve <= -SK_MEMORY_PCPU_RESERVE) { in sk_memory_allocated_sub()
1485 __this_cpu_sub(*sk->sk_prot->per_cpu_fw_alloc, local_reserve); in sk_memory_allocated_sub()
1486 atomic_long_add(local_reserve, sk->sk_prot->memory_allocated); in sk_memory_allocated_sub()
1495 percpu_counter_add_batch(sk->sk_prot->sockets_allocated, -1, in sk_sockets_allocated_dec()
1501 percpu_counter_add_batch(sk->sk_prot->sockets_allocated, 1, in sk_sockets_allocated_inc()
1508 return percpu_counter_read_positive(sk->sk_prot->sockets_allocated); in sk_sockets_allocated_read_positive()
1514 return percpu_counter_sum_positive(prot->sockets_allocated); in proto_sockets_allocated_sum_positive()
1520 if (!prot->memory_pressure) in proto_memory_pressure()
1522 return !!*prot->memory_pressure; in proto_memory_pressure()
1536 this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); in sock_prot_inuse_add()
1541 this_cpu_add(net->core.prot_inuse->all, val); in sock_inuse_add()
1558 /* With per-bucket locks this operation is not-atomic, so that
1563 sk->sk_prot->unhash(sk); in __sk_prot_rehash()
1564 return sk->sk_prot->hash(sk); in __sk_prot_rehash()
1570 /* Sockets 0-1023 can't be bound to unless you are superuser */
1587 return &container_of(inode, struct socket_alloc, vfs_inode)->socket; in SOCKET_I()
1592 return &container_of(socket, struct socket_alloc, socket)->vfs_inode; in SOCK_INODE()
1609 return READ_ONCE(sk->sk_prot->sysctl_mem[index]); in sk_prot_mem_limits()
1614 return (amt + PAGE_SIZE - 1) >> PAGE_SHIFT; in sk_mem_pages()
1620 return !!sk->sk_prot->memory_allocated; in sk_has_account()
1629 delta = size - sk->sk_forward_alloc; in sk_wmem_schedule()
1640 delta = size - sk->sk_forward_alloc; in sk_rmem_schedule()
1649 if (likely(!sk->sk_reserved_mem)) in sk_unused_reserved_mem()
1652 unused_mem = sk->sk_reserved_mem - sk->sk_wmem_queued - in sk_unused_reserved_mem()
1653 atomic_read(&sk->sk_rmem_alloc); in sk_unused_reserved_mem()
1665 reclaimable = sk->sk_forward_alloc - sk_unused_reserved_mem(sk); in sk_mem_reclaim()
1673 sk->sk_reserved_mem = 0; in sk_mem_reclaim_final()
1681 sk->sk_forward_alloc -= size; in sk_mem_charge()
1688 sk->sk_forward_alloc += size; in sk_mem_uncharge()
1697 * per-address-family lock class.
1701 sk->sk_lock.owned = 0; \
1702 init_waitqueue_head(&sk->sk_lock.wq); \
1703 spin_lock_init(&(sk)->sk_lock.slock); \
1704 debug_check_no_locks_freed((void *)&(sk)->sk_lock, \
1705 sizeof((sk)->sk_lock)); \
1706 lockdep_set_class_and_name(&(sk)->sk_lock.slock, \
1708 lockdep_init_map(&(sk)->sk_lock.dep_map, (name), (key), 0); \
1713 return lockdep_is_held(&sk->sk_lock) || in lockdep_sock_is_held()
1714 lockdep_is_held(&sk->sk_lock.slock); in lockdep_sock_is_held()
1729 #define bh_lock_sock(__sk) spin_lock(&((__sk)->sk_lock.slock))
1731 spin_lock_nested(&((__sk)->sk_lock.slock), \
1733 #define bh_unlock_sock(__sk) spin_unlock(&((__sk)->sk_lock.slock))
1735 bool __lock_sock_fast(struct sock *sk) __acquires(&sk->sk_lock.slock);
1738 * lock_sock_fast - fast version of lock_sock
1753 mutex_acquire(&sk->sk_lock.dep_map, 0, 0, _RET_IP_); in lock_sock_fast()
1761 mutex_acquire(&sk->sk_lock.dep_map, SINGLE_DEPTH_NESTING, 0, _RET_IP_); in lock_sock_fast_nested()
1767 * unlock_sock_fast - complement of lock_sock_fast
1775 __releases(&sk->sk_lock.slock) in unlock_sock_fast()
1779 __release(&sk->sk_lock.slock); in unlock_sock_fast()
1781 mutex_release(&sk->sk_lock.dep_map, _RET_IP_); in unlock_sock_fast()
1782 spin_unlock_bh(&sk->sk_lock.slock); in unlock_sock_fast()
1788 bool sockopt_ns_capable(struct user_namespace *ns, int cap);
1815 return sk->sk_lock.owned; in sock_owned_by_user()
1820 return sk->sk_lock.owned; in sock_owned_by_user_nocheck()
1826 sk->sk_lock.owned = 0; in sock_release_ownership()
1829 mutex_release(&sk->sk_lock.dep_map, _RET_IP_); in sock_release_ownership()
1839 !spin_is_locked(&sk->sk_lock.slock); in sock_allow_reclassification()
1894 if (sk->sk_socket) in sock_replace_proto()
1895 clear_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); in sock_replace_proto()
1896 WRITE_ONCE(sk->sk_prot, proto); in sock_replace_proto()
1908 *sockc = (struct sockcm_cookie) { .tsflags = sk->sk_tsflags }; in sockcm_init()
1969 * it is called, socket has no references from outside -> sk_free
1986 if (refcount_dec_and_test(&sk->sk_refcnt)) in sock_put()
2004 /* sk_tx_queue_mapping accept only upto a 16-bit value */ in sk_tx_queue_set()
2007 sk->sk_tx_queue_mapping = tx_queue; in sk_tx_queue_set()
2014 sk->sk_tx_queue_mapping = NO_QUEUE_MAPPING; in sk_tx_queue_clear()
2019 if (sk && sk->sk_tx_queue_mapping != NO_QUEUE_MAPPING) in sk_tx_queue_get()
2020 return sk->sk_tx_queue_mapping; in sk_tx_queue_get()
2022 return -1; in sk_tx_queue_get()
2034 unlikely(READ_ONCE(sk->sk_rx_queue_mapping) != rx_queue)) in __sk_rx_queue_set()
2035 WRITE_ONCE(sk->sk_rx_queue_mapping, rx_queue); in __sk_rx_queue_set()
2053 WRITE_ONCE(sk->sk_rx_queue_mapping, NO_QUEUE_MAPPING); in sk_rx_queue_clear()
2061 int res = READ_ONCE(sk->sk_rx_queue_mapping); in sk_rx_queue_get()
2068 return -1; in sk_rx_queue_get()
2073 sk->sk_socket = sock; in sk_set_socket()
2079 return &rcu_dereference_raw(sk->sk_wq)->wait; in sk_sleep()
2090 write_lock_bh(&sk->sk_callback_lock); in sock_orphan()
2093 sk->sk_wq = NULL; in sock_orphan()
2094 write_unlock_bh(&sk->sk_callback_lock); in sock_orphan()
2099 WARN_ON(parent->sk); in sock_graft()
2100 write_lock_bh(&sk->sk_callback_lock); in sock_graft()
2101 rcu_assign_pointer(sk->sk_wq, &parent->wq); in sock_graft()
2102 parent->sk = sk; in sock_graft()
2104 sk->sk_uid = SOCK_INODE(parent)->i_uid; in sock_graft()
2106 write_unlock_bh(&sk->sk_callback_lock); in sock_graft()
2114 return sk ? sk->sk_uid : make_kuid(net->user_ns, 0); in sock_net_uid()
2127 WRITE_ONCE(sk->sk_txhash, net_tx_rndhash()); in sk_set_txhash()
2132 if (sk->sk_txhash && sk->sk_txrehash == SOCK_TXREHASH_ENABLED) { in sk_rethink_txhash()
2142 return rcu_dereference_check(sk->sk_dst_cache, in __sk_dst_get()
2152 dst = rcu_dereference(sk->sk_dst_cache); in sk_dst_get()
2153 if (dst && !atomic_inc_not_zero(&dst->__refcnt)) in sk_dst_get()
2163 if (dst && dst->ops->negative_advice) { in __dst_negative_advice()
2164 ndst = dst->ops->negative_advice(dst); in __dst_negative_advice()
2167 rcu_assign_pointer(sk->sk_dst_cache, ndst); in __dst_negative_advice()
2169 sk->sk_dst_pending_confirm = 0; in __dst_negative_advice()
2186 sk->sk_dst_pending_confirm = 0; in __sk_dst_set()
2187 old_dst = rcu_dereference_protected(sk->sk_dst_cache, in __sk_dst_set()
2189 rcu_assign_pointer(sk->sk_dst_cache, dst); in __sk_dst_set()
2199 sk->sk_dst_pending_confirm = 0; in sk_dst_set()
2200 old_dst = xchg((__force struct dst_entry **)&sk->sk_dst_cache, dst); in sk_dst_set()
2222 if (!READ_ONCE(sk->sk_dst_pending_confirm)) in sk_dst_confirm()
2223 WRITE_ONCE(sk->sk_dst_pending_confirm, 1); in sk_dst_confirm()
2229 struct sock *sk = skb->sk; in sock_confirm_neigh()
2231 if (sk && READ_ONCE(sk->sk_dst_pending_confirm)) in sock_confirm_neigh()
2232 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in sock_confirm_neigh()
2241 return net_gso_ok(sk->sk_route_caps, sk->sk_gso_type); in sk_can_gso()
2248 sk->sk_gso_disabled = 1; in sk_gso_disable()
2249 sk->sk_route_caps &= ~NETIF_F_GSO_MASK; in sk_gso_disable()
2256 if (skb->ip_summed == CHECKSUM_NONE) { in skb_do_copy_data_nocache()
2259 return -EFAULT; in skb_do_copy_data_nocache()
2260 skb->csum = csum_block_add(skb->csum, csum, offset); in skb_do_copy_data_nocache()
2261 } else if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) { in skb_do_copy_data_nocache()
2263 return -EFAULT; in skb_do_copy_data_nocache()
2265 return -EFAULT; in skb_do_copy_data_nocache()
2273 int err, offset = skb->len; in skb_add_data_nocache()
2291 copy, skb->len); in skb_copy_to_page_nocache()
2302 * sk_wmem_alloc_get - returns write allocations
2309 return refcount_read(&sk->sk_wmem_alloc) - 1; in sk_wmem_alloc_get()
2313 * sk_rmem_alloc_get - returns read allocations
2320 return atomic_read(&sk->sk_rmem_alloc); in sk_rmem_alloc_get()
2324 * sk_has_allocations - check if allocations are outstanding
2335 * skwq_has_sleeper - check if there are any waiting processes
2348 * __add_wait_queue update tp->rcv_nxt
2350 * tp->rcv_nxt check sock_def_readable
2353 * wq = rcu_dereference(sk->sk_wq);
2354 * if (wq && waitqueue_active(&wq->wait))
2355 * wake_up_interruptible(&wq->wait)
2360 * in its cache, and so does the tp->rcv_nxt update on CPU2 side. The CPU1
2367 return wq && wq_has_sleeper(&wq->wait); in skwq_has_sleeper()
2371 * sock_poll_wait - place memory barrier behind the poll_wait call.
2382 poll_wait(filp, &sock->wq.wait, p); in sock_poll_wait()
2395 u32 txhash = READ_ONCE(sk->sk_txhash); in skb_set_hash_from_sk()
2398 skb->l4_hash = 1; in skb_set_hash_from_sk()
2399 skb->hash = txhash; in skb_set_hash_from_sk()
2416 skb->sk = sk; in skb_set_owner_r()
2417 skb->destructor = sock_rfree; in skb_set_owner_r()
2418 atomic_add(skb->truesize, &sk->sk_rmem_alloc); in skb_set_owner_r()
2419 sk_mem_charge(sk, skb->truesize); in skb_set_owner_r()
2424 if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) { in skb_set_owner_sk_safe()
2426 skb->destructor = sock_efree; in skb_set_owner_sk_safe()
2427 skb->sk = sk; in skb_set_owner_sk_safe()
2435 if (skb->destructor != sock_wfree) { in skb_prepare_for_gro()
2439 skb->slow_gro = 1; in skb_prepare_for_gro()
2477 if (likely(data_race(!sk->sk_err))) in sock_error()
2480 err = xchg(&sk->sk_err, 0); in sock_error()
2481 return -err; in sock_error()
2490 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) { in sock_wspace()
2491 amt = sk->sk_sndbuf - refcount_read(&sk->sk_wmem_alloc); in sock_wspace()
2499 * We use sk->sk_wq_raw, from contexts knowing this
2508 set_bit(nr, &sk->sk_wq_raw->flags); in sk_set_bit()
2517 clear_bit(nr, &sk->sk_wq_raw->flags); in sk_clear_bit()
2524 sock_wake_async(rcu_dereference(sk->sk_wq), how, band); in sk_wake_async()
2529 /* Since sk_{r,w}mem_alloc sums skb->truesize, even a small frame might
2543 if (sk->sk_userlocks & SOCK_SNDBUF_LOCK) in sk_stream_moderate_sndbuf()
2546 val = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1); in sk_stream_moderate_sndbuf()
2549 WRITE_ONCE(sk->sk_sndbuf, max_t(u32, val, SOCK_MIN_SNDBUF)); in sk_stream_moderate_sndbuf()
2553 * sk_page_frag - return an appropriate page_frag
2571 if ((sk->sk_allocation & (__GFP_DIRECT_RECLAIM | __GFP_MEMALLOC | __GFP_FS)) == in sk_page_frag()
2573 return ¤t->task_frag; in sk_page_frag()
2575 return &sk->sk_frag; in sk_page_frag()
2585 return refcount_read(&sk->sk_wmem_alloc) < (READ_ONCE(sk->sk_sndbuf) >> 1); in sock_writeable()
2600 return noblock ? 0 : sk->sk_rcvtimeo; in sock_rcvtimeo()
2605 return noblock ? 0 : sk->sk_sndtimeo; in sock_sndtimeo()
2610 int v = waitall ? len : min_t(int, READ_ONCE(sk->sk_rcvlowat), len); in sock_rcvlowat()
2620 return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR; in sock_intr_errno()
2627 /* Store sock_skb_cb at the end of skb->cb[] so protocol families
2628 * using skb->cb[] would keep using it directly and utilize its
2631 #define SOCK_SKB_CB_OFFSET ((sizeof_field(struct sk_buff, cb) - \
2634 #define SOCK_SKB_CB(__skb) ((struct sock_skb_cb *)((__skb)->cb + \
2643 SOCK_SKB_CB(skb)->dropcount = sock_flag(sk, SOCK_RXQ_OVFL) ? in sock_skb_set_dropcount()
2644 atomic_read(&sk->sk_drops) : 0; in sock_skb_set_dropcount()
2649 int segs = max_t(u16, 1, skb_shinfo(skb)->gso_segs); in sk_drops_add()
2651 atomic_add(segs, &sk->sk_drops); in sk_drops_add()
2661 seq = read_seqbegin(&sk->sk_stamp_seq); in sock_read_timestamp()
2662 kt = sk->sk_stamp; in sock_read_timestamp()
2663 } while (read_seqretry(&sk->sk_stamp_seq, seq)); in sock_read_timestamp()
2667 return READ_ONCE(sk->sk_stamp); in sock_read_timestamp()
2674 write_seqlock(&sk->sk_stamp_seq); in sock_write_timestamp()
2675 sk->sk_stamp = kt; in sock_write_timestamp()
2676 write_sequnlock(&sk->sk_stamp_seq); in sock_write_timestamp()
2678 WRITE_ONCE(sk->sk_stamp, kt); in sock_write_timestamp()
2690 ktime_t kt = skb->tstamp; in sock_recv_timestamp()
2695 * - receive time stamping in software requested in sock_recv_timestamp()
2696 * - software time stamp available and wanted in sock_recv_timestamp()
2697 * - hardware time stamps available and wanted in sock_recv_timestamp()
2700 (sk->sk_tsflags & SOF_TIMESTAMPING_RX_SOFTWARE) || in sock_recv_timestamp()
2701 (kt && sk->sk_tsflags & SOF_TIMESTAMPING_SOFTWARE) || in sock_recv_timestamp()
2702 (hwtstamps->hwtstamp && in sock_recv_timestamp()
2703 (sk->sk_tsflags & SOF_TIMESTAMPING_RAW_HARDWARE))) in sock_recv_timestamp()
2708 if (sock_flag(sk, SOCK_WIFI_STATUS) && skb->wifi_acked_valid) in sock_recv_timestamp()
2715 #define SK_DEFAULT_STAMP (-1L * NSEC_PER_SEC)
2725 if (sk->sk_flags & FLAGS_RECV_CMSGS || sk->sk_tsflags & TSFLAGS_ANY) in sock_recv_cmsgs()
2728 sock_write_timestamp(sk, skb->tstamp); in sock_recv_cmsgs()
2729 else if (unlikely(sk->sk_stamp == SK_DEFAULT_STAMP)) in sock_recv_cmsgs()
2736 * _sock_tx_timestamp - checks whether the outgoing packet is to be time stamped
2751 *tskey = atomic_inc_return(&sk->sk_tskey) - 1; in _sock_tx_timestamp()
2765 _sock_tx_timestamp(skb->sk, tsflags, &skb_shinfo(skb)->tx_flags, in skb_setup_tx_timestamp()
2766 &skb_shinfo(skb)->tskey); in skb_setup_tx_timestamp()
2771 return sk->sk_type == SOCK_STREAM && sk->sk_protocol == IPPROTO_TCP; in sk_is_tcp()
2775 * sk_eat_skb - Release a skb if it is no longer needed
2784 __skb_unlink(skb, &sk->sk_receive_queue); in sk_eat_skb()
2792 return skb->destructor == sock_pfree; in skb_sk_is_prefetched()
2803 return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV); in sk_fullsock()
2809 /* Only full sockets have sk->sk_flags. */ in sk_is_refcounted()
2814 * skb_steal_sock - steal a socket from an sk_buff
2816 * @refcounted: is set to true if the socket is reference-counted
2821 if (skb->sk) { in skb_steal_sock()
2822 struct sock *sk = skb->sk; in skb_steal_sock()
2827 skb->destructor = NULL; in skb_steal_sock()
2828 skb->sk = NULL; in skb_steal_sock()
2843 struct sock *sk = skb->sk; in sk_validate_xmit_skb()
2845 if (sk && sk_fullsock(sk) && sk->sk_validate_xmit_skb) { in sk_validate_xmit_skb()
2846 skb = sk->sk_validate_xmit_skb(sk, dev, skb); in sk_validate_xmit_skb()
2848 } else if (unlikely(skb->decrypted)) { in sk_validate_xmit_skb()
2849 pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n"); in sk_validate_xmit_skb()
2864 return (1 << sk->sk_state) & (TCPF_LISTEN | TCPF_NEW_SYN_RECV); in sk_listener()
2879 * determination of these values, since that is non-constant across
2903 if (proto->sysctl_wmem_offset) in sk_get_wmem0()
2904 return READ_ONCE(*(int *)((void *)sock_net(sk) + proto->sysctl_wmem_offset)); in sk_get_wmem0()
2906 return READ_ONCE(*proto->sysctl_wmem); in sk_get_wmem0()
2912 if (proto->sysctl_rmem_offset) in sk_get_rmem0()
2913 return READ_ONCE(*(int *)((void *)sock_net(sk) + proto->sysctl_rmem_offset)); in sk_get_rmem0()
2915 return READ_ONCE(*proto->sysctl_rmem); in sk_get_rmem0()
2924 if (!sk || !sk_fullsock(sk) || READ_ONCE(sk->sk_pacing_shift) == val) in sk_pacing_shift_update()
2926 WRITE_ONCE(sk->sk_pacing_shift, val); in sk_pacing_shift_update()
2936 int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if); in sk_dev_equal_l3scope()
2974 if (sk->sk_prot->sock_is_readable) in sk_is_readable()
2975 return sk->sk_prot->sock_is_readable(sk); in sk_is_readable()