[PATCH 1/4] net: add sock 'sk_no_lock' member

Jens Axboe
2022-04-12T23:26:21Z

In preparation for allowing lockless access to the socket for specialized
use cases, add a member denoting that the socket supports this.

No functional changes in this patch.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
include/net/sock.h | 3 +++
net/core/sock.c | 1 +
2 files changed, 4 insertions(+)

diff --git a/include/net/sock.h b/include/net/sock.h
index c4b91fc19b9c..e8283a65b757 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -131,6 +131,7 @@ typedef __u64 __bitwise __addrpair;
* @skc_reuseport: %SO_REUSEPORT setting
* @skc_ipv6only: socket is IPV6 only
* @skc_net_refcnt: socket is using net ref counting
+ * @skc_no_lock: socket is private, no locking needed
* @skc_bound_dev_if: bound device index if != 0
* @skc_bind_node: bind hash linkage for various protocol lookup tables
* @skc_portaddr_node: second hash linkage for UDP/UDP-Lite protocol
@@ -190,6 +191,7 @@ struct sock_common {
unsigned char skc_reuseport:1;
unsigned char skc_ipv6only:1;
unsigned char skc_net_refcnt:1;
+ unsigned char skc_no_lock:1;
int skc_bound_dev_if;
union {
struct hlist_node skc_bind_node;
@@ -382,6 +384,7 @@ struct sock {
#define sk_reuseport __sk_common.skc_reuseport
#define sk_ipv6only __sk_common.skc_ipv6only
#define sk_net_refcnt __sk_common.skc_net_refcnt
+#define sk_no_lock __sk_common.skc_no_lock
#define sk_bound_dev_if __sk_common.skc_bound_dev_if
#define sk_bind_node __sk_common.skc_bind_node
#define sk_prot __sk_common.skc_prot
diff --git a/net/core/sock.c b/net/core/sock.c
index 1180a0cb0110..fec892b384a4 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2101,6 +2101,7 @@ EXPORT_SYMBOL(sk_free);

static void sk_init_common(struct sock *sk)
{
+ sk->sk_no_lock = false;
skb_queue_head_init(&sk->sk_receive_queue);
skb_queue_head_init(&sk->sk_write_queue);
skb_queue_head_init(&sk->sk_error_queue);
--
2.35.1