Lines Matching +full:timer +full:- +full:cannot +full:- +full:wake +full:- +full:cpu
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>
42 #include <linux/timer.h>
57 #include <linux/cgroup-defs.h>
79 /* This is the per-socket lock. The spinlock provides a synchronization
81 * mini-semaphore synchronizes multiple users amongst themselves.
88 * We express the mutex-alike socket_lock semantics
106 * struct sock_common - minimal network layer representation of sockets
109 * @skc_addrpair: 8-byte-aligned __u64 union of @skc_daddr & @skc_rcv_saddr
123 * @skc_portaddr_node: second hash linkage for UDP/UDP-Lite protocol
130 * @skc_nulls_node: main hash linkage for TCP/UDP/UDP-Lite protocol
140 * @skc_incoming_cpu: record/match cpu processing incoming packets
238 * struct sock - network layer representation of sockets
259 * @sk_reserved_mem: space reserved and non-reclaimable for the socket
276 * @sk_backlog: always used with the per-socket spinlock held
302 * @sk_timer: sock cleanup timer
307 * @sk_use_task_frag: allow sk_page_frag() to use current->task_frag.
315 * @sk_user_data: RPC layer private data. Write-protected by @sk_callback_lock.
319 * @tcp_rtx_queue: TCP re-transmit queue [union with @sk_send_head]
336 * @sk_clockid: clockid used by time-based scheduling (SO_TXTIME)
354 * don't add nothing before this first member (__sk_common) --acme
399 * the per-socket spinlock held and requires low latency
547 #define SK_BPF_CB_FLAG_TEST(SK, FLAG) ((SK)->sk_bpf_cb_flags & (FLAG))
587 * - SK_USER_DATA_NOCOPY: Pointer stored in sk_user_data might
592 * - SK_USER_DATA_BPF: Mark whether sk_user_data field is
596 * - SK_USER_DATA_PSOCK: Mark whether pointer stored in
607 * sk_user_data_is_nocopy - Test if sk_user_data pointer must not be copied
612 return ((uintptr_t)sk->sk_user_data & SK_USER_DATA_NOCOPY); in sk_user_data_is_nocopy()
615 #define __sk_user_data(sk) ((*((void __rcu **)&(sk)->sk_user_data)))
618 * __locked_read_sk_user_data_with_flags - return the pointer
625 * The caller must be holding sk->sk_callback_lock.
633 lockdep_is_held(&sk->sk_callback_lock)); in __locked_read_sk_user_data_with_flags()
643 * __rcu_dereference_sk_user_data_with_flags - return the pointer
680 return read_pnet(&sk->sk_net); in sock_net()
686 write_pnet(&sk->sk_net, net); in sock_net_set()
705 return READ_ONCE(sk->sk_peek_off); in sk_peek_offset()
713 s32 off = READ_ONCE(sk->sk_peek_off); in sk_peek_offset_bwd()
716 off = max_t(s32, off - val, 0); in sk_peek_offset_bwd()
717 WRITE_ONCE(sk->sk_peek_off, off); in sk_peek_offset_bwd()
723 sk_peek_offset_bwd(sk, -val); in sk_peek_offset_fwd()
736 return hlist_entry(head->first, struct sock, sk_node); in __sk_head()
746 return hlist_nulls_entry(head->first, struct sock, sk_nulls_node); in __sk_nulls_head()
756 return hlist_entry_safe(sk->sk_node.next, struct sock, sk_node); in sk_next()
761 return (!is_a_nulls(sk->sk_nulls_node.next)) ? in sk_nulls_next()
762 hlist_nulls_entry(sk->sk_nulls_node.next, in sk_nulls_next()
769 return hlist_unhashed(&sk->sk_node); in sk_unhashed()
779 node->pprev = NULL; in sk_node_init()
784 __hlist_del(&sk->sk_node); in __sk_del_node()
792 sk_node_init(&sk->sk_node); in __sk_del_node_init()
806 refcount_inc(&sk->sk_refcnt); in sock_hold()
810 cannot hit zero, f.e. it is true in context of any socketcall.
814 refcount_dec(&sk->sk_refcnt); in __sock_put()
822 /* paranoid for a while -acme */ in sk_del_node_init()
823 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_del_node_init()
833 hlist_nulls_del_init_rcu(&sk->sk_nulls_node); in __sk_nulls_del_node_init_rcu()
844 /* paranoid for a while -acme */ in sk_nulls_del_node_init_rcu()
845 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_nulls_del_node_init_rcu()
853 hlist_add_head(&sk->sk_node, list); in __sk_add_node()
865 if (IS_ENABLED(CONFIG_IPV6) && sk->sk_reuseport && in sk_add_node_rcu()
866 sk->sk_family == AF_INET6) in sk_add_node_rcu()
867 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_rcu()
869 hlist_add_head_rcu(&sk->sk_node, list); in sk_add_node_rcu()
875 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_tail_rcu()
880 hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_rcu()
885 hlist_nulls_add_tail_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_tail_rcu()
896 __hlist_del(&sk->sk_bind_node); in __sk_del_bind_node()
902 hlist_add_head(&sk->sk_bind_node, list); in sk_add_bind_node()
916 if (__sk && ({ node = &(__sk)->sk_nulls_node; 1; })) \
926 * sk_for_each_entry_offset_rcu - iterate over a list at a given struct offset
936 ({ tpos = (typeof(*tpos) *)((void *)pos - offset); 1;}); \
945 return sk->sk_socket->file->f_cred->user_ns; in sk_user_ns()
959 SOCK_USE_WRITE_QUEUE, /* whether to call sk->sk_write_space in sock_wfree */
972 * user-space instead.
974 SOCK_FILTER_LOCKED, /* Filter cannot be changed anymore */
975 SOCK_SELECT_ERR_QUEUE, /* Wake select on error queue */
987 * The highest bit of sk_tsflags is reserved for kernel-internal
995 nsk->sk_flags = osk->sk_flags; in sock_copy_flags()
1000 __set_bit(flag, &sk->sk_flags); in sock_set_flag()
1005 __clear_bit(flag, &sk->sk_flags); in sock_reset_flag()
1019 return test_bit(flag, &sk->sk_flags); in sock_flag()
1043 return gfp_mask | (sk->sk_allocation & __GFP_MEMALLOC); in sk_gfp_mask()
1048 WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog - 1); in sk_acceptq_removed()
1053 WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog + 1); in sk_acceptq_added()
1057 * return READ_ONCE(sk->sk_ack_backlog) >= READ_ONCE(sk->sk_max_ack_backlog);
1062 return READ_ONCE(sk->sk_ack_backlog) > READ_ONCE(sk->sk_max_ack_backlog); in sk_acceptq_is_full()
1070 return READ_ONCE(sk->sk_wmem_queued) >> 1; in sk_stream_min_wspace()
1075 return READ_ONCE(sk->sk_sndbuf) - READ_ONCE(sk->sk_wmem_queued); in sk_stream_wspace()
1080 WRITE_ONCE(sk->sk_wmem_queued, sk->sk_wmem_queued + val); in sk_wmem_queued_add()
1085 /* Paired with lockless reads of sk->sk_forward_alloc */ in sk_forward_alloc_add()
1086 WRITE_ONCE(sk->sk_forward_alloc, sk->sk_forward_alloc + val); in sk_forward_alloc_add()
1097 if (!sk->sk_backlog.tail) in __sk_add_backlog()
1098 WRITE_ONCE(sk->sk_backlog.head, skb); in __sk_add_backlog()
1100 sk->sk_backlog.tail->next = skb; in __sk_add_backlog()
1102 WRITE_ONCE(sk->sk_backlog.tail, skb); in __sk_add_backlog()
1103 skb->next = NULL; in __sk_add_backlog()
1113 unsigned int qsize = sk->sk_backlog.len + atomic_read(&sk->sk_rmem_alloc); in sk_rcvqueues_full()
1118 /* The per-socket spinlock must be held here. */
1123 return -ENOBUFS; in sk_add_backlog()
1131 return -ENOMEM; in sk_add_backlog()
1134 sk->sk_backlog.len += skb->truesize; in sk_add_backlog()
1148 return INDIRECT_CALL_INET(sk->sk_backlog_rcv, in sk_backlog_rcv()
1156 int cpu = raw_smp_processor_id(); in sk_incoming_cpu_update() local
1158 if (unlikely(READ_ONCE(sk->sk_incoming_cpu) != cpu)) in sk_incoming_cpu_update()
1159 WRITE_ONCE(sk->sk_incoming_cpu, cpu); in sk_incoming_cpu_update()
1170 if (unlikely(READ_ONCE(sk->sk_rxhash) != skb->hash)) in sock_rps_save_rxhash()
1171 WRITE_ONCE(sk->sk_rxhash, skb->hash); in sock_rps_save_rxhash()
1179 WRITE_ONCE(sk->sk_rxhash, 0); in sock_rps_reset_rxhash()
1184 ({ int __rc, __dis = __sk->sk_disconnects; \
1194 __rc = __dis == __sk->sk_disconnects ? __condition : -EPIPE; \
1210 if (unlikely(READ_ONCE(sk->sk_backlog.tail))) { in sk_flush_backlog()
1229 * un-modified. Special care is taken when initializing object to zero.
1235 memset(&sk->sk_node.pprev, 0, in sk_prot_clear_nulls()
1236 size - offsetof(struct sock, sk_node.pprev)); in sk_prot_clear_nulls()
1247 * socket layer -> transport layer interface
1313 bool (*stream_memory_free)(const struct sock *sk, int wake);
1371 INDIRECT_CALLABLE_DECLARE(bool tcp_stream_memory_free(const struct sock *sk, int wake));
1373 static inline bool __sk_stream_memory_free(const struct sock *sk, int wake) in __sk_stream_memory_free() argument
1375 if (READ_ONCE(sk->sk_wmem_queued) >= READ_ONCE(sk->sk_sndbuf)) in __sk_stream_memory_free()
1378 return sk->sk_prot->stream_memory_free ? in __sk_stream_memory_free()
1379 INDIRECT_CALL_INET_1(sk->sk_prot->stream_memory_free, in __sk_stream_memory_free()
1380 tcp_stream_memory_free, sk, wake) : true; in __sk_stream_memory_free()
1388 static inline bool __sk_stream_is_writeable(const struct sock *sk, int wake) in __sk_stream_is_writeable() argument
1391 __sk_stream_memory_free(sk, wake); in __sk_stream_is_writeable()
1403 return cgroup_is_descendant(sock_cgroup_ptr(&sk->sk_cgrp_data), in sk_under_cgroup_hierarchy()
1406 return -ENOTSUPP; in sk_under_cgroup_hierarchy()
1414 percpu_counter_add_batch(sk->sk_prot->sockets_allocated, -1, in sk_sockets_allocated_dec()
1420 percpu_counter_add_batch(sk->sk_prot->sockets_allocated, 1, in sk_sockets_allocated_inc()
1427 return percpu_counter_read_positive(sk->sk_prot->sockets_allocated); in sk_sockets_allocated_read_positive()
1433 return percpu_counter_sum_positive(prot->sockets_allocated); in proto_sockets_allocated_sum_positive()
1446 this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); in sock_prot_inuse_add()
1451 this_cpu_add(net->core.prot_inuse->all, val); in sock_inuse_add()
1468 /* With per-bucket locks this operation is not-atomic, so that
1473 sk->sk_prot->unhash(sk); in __sk_prot_rehash()
1474 return sk->sk_prot->hash(sk); in __sk_prot_rehash()
1480 /* Sockets 0-1023 can't be bound to unless you are superuser */
1497 return &container_of(inode, struct socket_alloc, vfs_inode)->socket; in SOCKET_I()
1502 return &container_of(socket, struct socket_alloc, socket)->vfs_inode; in SOCK_INODE()
1519 return READ_ONCE(sk->sk_prot->sysctl_mem[index]); in sk_prot_mem_limits()
1524 return (amt + PAGE_SIZE - 1) >> PAGE_SHIFT; in sk_mem_pages()
1530 return !!sk->sk_prot->memory_allocated; in sk_has_account()
1539 delta = size - sk->sk_forward_alloc; in sk_wmem_schedule()
1550 delta = size - sk->sk_forward_alloc; in __sk_rmem_schedule()
1565 if (likely(!sk->sk_reserved_mem)) in sk_unused_reserved_mem()
1568 unused_mem = sk->sk_reserved_mem - sk->sk_wmem_queued - in sk_unused_reserved_mem()
1569 atomic_read(&sk->sk_rmem_alloc); in sk_unused_reserved_mem()
1581 reclaimable = sk->sk_forward_alloc - sk_unused_reserved_mem(sk); in sk_mem_reclaim()
1589 sk->sk_reserved_mem = 0; in sk_mem_reclaim_final()
1597 sk_forward_alloc_add(sk, -size); in sk_mem_charge()
1612 sk->sk_owner = owner; in sk_owner_set()
1617 sk->sk_owner = NULL; in sk_owner_clear()
1622 module_put(sk->sk_owner); in sk_owner_put()
1642 * per-address-family lock class.
1647 sk->sk_lock.owned = 0; \
1648 init_waitqueue_head(&sk->sk_lock.wq); \
1649 spin_lock_init(&(sk)->sk_lock.slock); \
1650 debug_check_no_locks_freed((void *)&(sk)->sk_lock, \
1651 sizeof((sk)->sk_lock)); \
1652 lockdep_set_class_and_name(&(sk)->sk_lock.slock, \
1654 lockdep_init_map(&(sk)->sk_lock.dep_map, (name), (key), 0); \
1659 return lockdep_is_held(&sk->sk_lock) || in lockdep_sock_is_held()
1660 lockdep_is_held(&sk->sk_lock.slock); in lockdep_sock_is_held()
1675 #define bh_lock_sock(__sk) spin_lock(&((__sk)->sk_lock.slock))
1677 spin_lock_nested(&((__sk)->sk_lock.slock), \
1679 #define bh_unlock_sock(__sk) spin_unlock(&((__sk)->sk_lock.slock))
1681 bool __lock_sock_fast(struct sock *sk) __acquires(&sk->sk_lock.slock);
1684 * lock_sock_fast - fast version of lock_sock
1699 mutex_acquire(&sk->sk_lock.dep_map, 0, 0, _RET_IP_); in lock_sock_fast()
1707 mutex_acquire(&sk->sk_lock.dep_map, SINGLE_DEPTH_NESTING, 0, _RET_IP_); in lock_sock_fast_nested()
1713 * unlock_sock_fast - complement of lock_sock_fast
1721 __releases(&sk->sk_lock.slock) in unlock_sock_fast()
1725 __release(&sk->sk_lock.slock); in unlock_sock_fast()
1727 mutex_release(&sk->sk_lock.dep_map, _RET_IP_); in unlock_sock_fast()
1728 spin_unlock_bh(&sk->sk_lock.slock); in unlock_sock_fast()
1768 return sk->sk_lock.owned; in sock_owned_by_user()
1773 return sk->sk_lock.owned; in sock_owned_by_user_nocheck()
1779 sk->sk_lock.owned = 0; in sock_release_ownership()
1782 mutex_release(&sk->sk_lock.dep_map, _RET_IP_); in sock_release_ownership()
1791 !spin_is_locked(&sk->sk_lock.slock); in sock_allow_reclassification()
1817 if (refcount_inc_not_zero(&sk->sk_refcnt)) { in skb_set_owner_edemux()
1818 skb->sk = sk; in skb_set_owner_edemux()
1819 skb->destructor = sock_edemux; in skb_set_owner_edemux()
1859 if (sk->sk_socket) in sock_replace_proto()
1860 clear_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); in sock_replace_proto()
1861 WRITE_ONCE(sk->sk_prot, proto); in sock_replace_proto()
1877 .mark = READ_ONCE(sk->sk_mark), in sockcm_init()
1878 .tsflags = READ_ONCE(sk->sk_tsflags), in sockcm_init()
1879 .priority = READ_ONCE(sk->sk_priority), in sockcm_init()
1936 * running timer, skb in flight MUST hold a reference count.
1939 * outside exist to this socket and current process on current CPU
1942 * it is called, socket has no references from outside -> sk_free
1949 * socket is looked up by one cpu and unhasing is made by another CPU.
1959 if (refcount_dec_and_test(&sk->sk_refcnt)) in sock_put()
1977 /* sk_tx_queue_mapping accept only upto a 16-bit value */ in sk_tx_queue_set()
1983 WRITE_ONCE(sk->sk_tx_queue_mapping, tx_queue); in sk_tx_queue_set()
1993 WRITE_ONCE(sk->sk_tx_queue_mapping, NO_QUEUE_MAPPING); in sk_tx_queue_clear()
2002 int val = READ_ONCE(sk->sk_tx_queue_mapping); in sk_tx_queue_get()
2007 return -1; in sk_tx_queue_get()
2019 unlikely(READ_ONCE(sk->sk_rx_queue_mapping) != rx_queue)) in __sk_rx_queue_set()
2020 WRITE_ONCE(sk->sk_rx_queue_mapping, rx_queue); in __sk_rx_queue_set()
2038 WRITE_ONCE(sk->sk_rx_queue_mapping, NO_QUEUE_MAPPING); in sk_rx_queue_clear()
2046 int res = READ_ONCE(sk->sk_rx_queue_mapping); in sk_rx_queue_get()
2053 return -1; in sk_rx_queue_get()
2058 sk->sk_socket = sock; in sk_set_socket()
2064 return &rcu_dereference_raw(sk->sk_wq)->wait; in sk_sleep()
2075 write_lock_bh(&sk->sk_callback_lock); in sock_orphan()
2078 sk->sk_wq = NULL; in sock_orphan()
2079 write_unlock_bh(&sk->sk_callback_lock); in sock_orphan()
2084 WARN_ON(parent->sk); in sock_graft()
2085 write_lock_bh(&sk->sk_callback_lock); in sock_graft()
2086 rcu_assign_pointer(sk->sk_wq, &parent->wq); in sock_graft()
2087 parent->sk = sk; in sock_graft()
2089 sk->sk_uid = SOCK_INODE(parent)->i_uid; in sock_graft()
2091 write_unlock_bh(&sk->sk_callback_lock); in sock_graft()
2100 return sk ? sk->sk_uid : make_kuid(net->user_ns, 0); in sock_net_uid()
2113 WRITE_ONCE(sk->sk_txhash, net_tx_rndhash()); in sk_set_txhash()
2118 if (sk->sk_txhash && sk->sk_txrehash == SOCK_TXREHASH_ENABLED) { in sk_rethink_txhash()
2128 return rcu_dereference_check(sk->sk_dst_cache, in __sk_dst_get()
2138 dst = rcu_dereference(sk->sk_dst_cache); in sk_dst_get()
2139 if (dst && !rcuref_get(&dst->__rcuref)) in sk_dst_get()
2149 if (dst && dst->ops->negative_advice) in __dst_negative_advice()
2150 dst->ops->negative_advice(sk, dst); in __dst_negative_advice()
2165 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in __sk_dst_set()
2166 old_dst = rcu_dereference_protected(sk->sk_dst_cache, in __sk_dst_set()
2168 rcu_assign_pointer(sk->sk_dst_cache, dst); in __sk_dst_set()
2178 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in sk_dst_set()
2179 old_dst = unrcu_pointer(xchg(&sk->sk_dst_cache, RCU_INITIALIZER(dst))); in sk_dst_set()
2201 if (!READ_ONCE(sk->sk_dst_pending_confirm)) in sk_dst_confirm()
2202 WRITE_ONCE(sk->sk_dst_pending_confirm, 1); in sk_dst_confirm()
2208 struct sock *sk = skb->sk; in sock_confirm_neigh()
2210 if (sk && READ_ONCE(sk->sk_dst_pending_confirm)) in sock_confirm_neigh()
2211 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in sock_confirm_neigh()
2220 return net_gso_ok(sk->sk_route_caps, sk->sk_gso_type); in sk_can_gso()
2227 sk->sk_gso_disabled = 1; in sk_gso_disable()
2228 sk->sk_route_caps &= ~NETIF_F_GSO_MASK; in sk_gso_disable()
2235 if (skb->ip_summed == CHECKSUM_NONE) { in skb_do_copy_data_nocache()
2238 return -EFAULT; in skb_do_copy_data_nocache()
2239 skb->csum = csum_block_add(skb->csum, csum, offset); in skb_do_copy_data_nocache()
2240 } else if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) { in skb_do_copy_data_nocache()
2242 return -EFAULT; in skb_do_copy_data_nocache()
2244 return -EFAULT; in skb_do_copy_data_nocache()
2252 int err, offset = skb->len; in skb_add_data_nocache()
2270 copy, skb->len); in skb_copy_to_page_nocache()
2281 * sk_wmem_alloc_get - returns write allocations
2288 return refcount_read(&sk->sk_wmem_alloc) - 1; in sk_wmem_alloc_get()
2292 * sk_rmem_alloc_get - returns read allocations
2299 return atomic_read(&sk->sk_rmem_alloc); in sk_rmem_alloc_get()
2303 * sk_has_allocations - check if allocations are outstanding
2314 * skwq_has_sleeper - check if there are any waiting processes
2327 * __add_wait_queue update tp->rcv_nxt
2329 * tp->rcv_nxt check sock_def_readable
2332 * wq = rcu_dereference(sk->sk_wq);
2333 * if (wq && waitqueue_active(&wq->wait))
2334 * wake_up_interruptible(&wq->wait)
2339 * in its cache, and so does the tp->rcv_nxt update on CPU2 side. The CPU1
2346 return wq && wq_has_sleeper(&wq->wait); in skwq_has_sleeper()
2350 * sock_poll_wait - wrapper for the poll_wait call.
2365 poll_wait(filp, &sock->wq.wait, p); in sock_poll_wait()
2371 u32 txhash = READ_ONCE(sk->sk_txhash); in skb_set_hash_from_sk()
2374 skb->l4_hash = 1; in skb_set_hash_from_sk()
2375 skb->hash = txhash; in skb_set_hash_from_sk()
2392 skb->sk = sk; in skb_set_owner_r()
2393 skb->destructor = sock_rfree; in skb_set_owner_r()
2394 atomic_add(skb->truesize, &sk->sk_rmem_alloc); in skb_set_owner_r()
2395 sk_mem_charge(sk, skb->truesize); in skb_set_owner_r()
2400 if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) { in skb_set_owner_sk_safe()
2402 skb->destructor = sock_efree; in skb_set_owner_sk_safe()
2403 skb->sk = sk; in skb_set_owner_sk_safe()
2413 if (sk_rmem_schedule(sk, skb, skb->truesize)) { in skb_clone_and_charge_r()
2424 if (skb->destructor != sock_wfree) { in skb_prepare_for_gro()
2428 skb->slow_gro = 1; in skb_prepare_for_gro()
2431 void sk_reset_timer(struct sock *sk, struct timer_list *timer,
2434 void sk_stop_timer(struct sock *sk, struct timer_list *timer);
2436 void sk_stop_timer_sync(struct sock *sk, struct timer_list *timer);
2464 * This is racy since another cpu/thread can change sk_err under us. in sock_error()
2466 if (likely(data_race(!sk->sk_err))) in sock_error()
2469 err = xchg(&sk->sk_err, 0); in sock_error()
2470 return -err; in sock_error()
2479 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) { in sock_wspace()
2480 amt = sk->sk_sndbuf - refcount_read(&sk->sk_wmem_alloc); in sock_wspace()
2488 * We use sk->sk_wq_raw, from contexts knowing this
2489 * pointer is not NULL and cannot disappear/change.
2497 set_bit(nr, &sk->sk_wq_raw->flags); in sk_set_bit()
2506 clear_bit(nr, &sk->sk_wq_raw->flags); in sk_clear_bit()
2513 sock_wake_async(rcu_dereference(sk->sk_wq), how, band); in sk_wake_async()
2521 sock_wake_async(rcu_dereference(sk->sk_wq), how, band); in sk_wake_async_rcu()
2524 /* Since sk_{r,w}mem_alloc sums skb->truesize, even a small frame might
2538 if (sk->sk_userlocks & SOCK_SNDBUF_LOCK) in sk_stream_moderate_sndbuf()
2541 val = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1); in sk_stream_moderate_sndbuf()
2544 WRITE_ONCE(sk->sk_sndbuf, max_t(u32, val, SOCK_MIN_SNDBUF)); in sk_stream_moderate_sndbuf()
2548 * sk_page_frag - return an appropriate page_frag
2565 if (sk->sk_use_task_frag) in sk_page_frag()
2566 return ¤t->task_frag; in sk_page_frag()
2568 return &sk->sk_frag; in sk_page_frag()
2578 return refcount_read(&sk->sk_wmem_alloc) < (READ_ONCE(sk->sk_sndbuf) >> 1); in sock_writeable()
2593 return noblock ? 0 : sk->sk_rcvtimeo; in sock_rcvtimeo()
2598 return noblock ? 0 : sk->sk_sndtimeo; in sock_sndtimeo()
2603 int v = waitall ? len : min_t(int, READ_ONCE(sk->sk_rcvlowat), len); in sock_rcvlowat()
2613 return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR; in sock_intr_errno()
2620 /* Store sock_skb_cb at the end of skb->cb[] so protocol families
2621 * using skb->cb[] would keep using it directly and utilize its
2624 #define SOCK_SKB_CB_OFFSET (sizeof_field(struct sk_buff, cb) - \
2627 #define SOCK_SKB_CB(__skb) ((struct sock_skb_cb *)((__skb)->cb + \
2636 SOCK_SKB_CB(skb)->dropcount = sock_flag(sk, SOCK_RXQ_OVFL) ? in sock_skb_set_dropcount()
2637 atomic_read(&sk->sk_drops) : 0; in sock_skb_set_dropcount()
2642 int segs = max_t(u16, 1, skb_shinfo(skb)->gso_segs); in sk_drops_add()
2644 atomic_add(segs, &sk->sk_drops); in sk_drops_add()
2654 seq = read_seqbegin(&sk->sk_stamp_seq); in sock_read_timestamp()
2655 kt = sk->sk_stamp; in sock_read_timestamp()
2656 } while (read_seqretry(&sk->sk_stamp_seq, seq)); in sock_read_timestamp()
2660 return READ_ONCE(sk->sk_stamp); in sock_read_timestamp()
2667 write_seqlock(&sk->sk_stamp_seq); in sock_write_timestamp()
2668 sk->sk_stamp = kt; in sock_write_timestamp()
2669 write_sequnlock(&sk->sk_stamp_seq); in sock_write_timestamp()
2671 WRITE_ONCE(sk->sk_stamp, kt); in sock_write_timestamp()
2684 u32 tsflags = READ_ONCE(sk->sk_tsflags); in sock_recv_timestamp()
2685 ktime_t kt = skb->tstamp; in sock_recv_timestamp()
2688 * - receive time stamping in software requested in sock_recv_timestamp()
2689 * - software time stamp available and wanted in sock_recv_timestamp()
2690 * - hardware time stamps available and wanted in sock_recv_timestamp()
2695 (hwtstamps->hwtstamp && in sock_recv_timestamp()
2708 #define SK_DEFAULT_STAMP (-1L * NSEC_PER_SEC)
2720 if (READ_ONCE(sk->sk_flags) & FLAGS_RECV_CMSGS) in sock_recv_cmsgs()
2723 sock_write_timestamp(sk, skb->tstamp); in sock_recv_cmsgs()
2731 * _sock_tx_timestamp - checks whether the outgoing packet is to be time stamped
2743 __u32 tsflags = sockc->tsflags; in _sock_tx_timestamp()
2750 *tskey = sockc->ts_opt_id; in _sock_tx_timestamp()
2752 *tskey = atomic_inc_return(&sk->sk_tskey) - 1; in _sock_tx_timestamp()
2767 _sock_tx_timestamp(skb->sk, sockc, &skb_shinfo(skb)->tx_flags, in skb_setup_tx_timestamp()
2768 &skb_shinfo(skb)->tskey); in skb_setup_tx_timestamp()
2773 int family = READ_ONCE(sk->sk_family); in sk_is_inet()
2781 sk->sk_type == SOCK_STREAM && in sk_is_tcp()
2782 sk->sk_protocol == IPPROTO_TCP; in sk_is_tcp()
2788 sk->sk_type == SOCK_DGRAM && in sk_is_udp()
2789 sk->sk_protocol == IPPROTO_UDP; in sk_is_udp()
2794 return sk->sk_family == AF_UNIX; in sk_is_unix()
2799 return sk_is_unix(sk) && sk->sk_type == SOCK_STREAM; in sk_is_stream_unix()
2804 return sk->sk_family == AF_VSOCK; in sk_is_vsock()
2809 return (IS_ENABLED(CONFIG_UNIX) && sk->sk_family == AF_UNIX) || in sk_may_scm_recv()
2810 sk->sk_family == AF_NETLINK || in sk_may_scm_recv()
2811 (IS_ENABLED(CONFIG_BT) && sk->sk_family == AF_BLUETOOTH); in sk_may_scm_recv()
2815 * sk_eat_skb - Release a skb if it is no longer needed
2824 __skb_unlink(skb, &sk->sk_receive_queue); in sk_eat_skb()
2832 return skb->destructor == sock_pfree; in skb_sk_is_prefetched()
2843 return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV); in sk_fullsock()
2849 /* Only full sockets have sk->sk_flags. */ in sk_is_refcounted()
2867 struct sock *sk = skb->sk; in sk_validate_xmit_skb()
2869 if (sk && sk_fullsock(sk) && sk->sk_validate_xmit_skb) { in sk_validate_xmit_skb()
2870 skb = sk->sk_validate_xmit_skb(sk, dev, skb); in sk_validate_xmit_skb()
2872 pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n"); in sk_validate_xmit_skb()
2886 return (1 << sk->sk_state) & (TCPF_LISTEN | TCPF_NEW_SYN_RECV); in sk_listener()
2895 return (1 << READ_ONCE(sk->sk_state)) & in sk_listener_or_tw()
2911 * determination of these values, since that is non-constant across
2932 if (proto->sysctl_wmem_offset) in sk_get_wmem0()
2933 return READ_ONCE(*(int *)((void *)sock_net(sk) + proto->sysctl_wmem_offset)); in sk_get_wmem0()
2935 return READ_ONCE(*proto->sysctl_wmem); in sk_get_wmem0()
2941 if (proto->sysctl_rmem_offset) in sk_get_rmem0()
2942 return READ_ONCE(*(int *)((void *)sock_net(sk) + proto->sysctl_rmem_offset)); in sk_get_rmem0()
2944 return READ_ONCE(*proto->sysctl_rmem); in sk_get_rmem0()
2953 if (!sk || !sk_fullsock(sk) || READ_ONCE(sk->sk_pacing_shift) == val) in sk_pacing_shift_update()
2955 WRITE_ONCE(sk->sk_pacing_shift, val); in sk_pacing_shift_update()
2965 int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if); in sk_dev_equal_l3scope()
3013 const struct proto *prot = READ_ONCE(sk->sk_prot); in sk_is_readable()
3015 if (prot->sock_is_readable) in sk_is_readable()
3016 return prot->sock_is_readable(sk); in sk_is_readable()