ffa6e8ac60dbe9f6f00664abf362d29fb71d55b9
[openwrt/staging/stintel.git] / target / linux / generic / hack-6.1 / 901-debloat_sock_diag.patch
1 From 3b6115d6b57a263bdc8c9b1df273bd4a7955eead Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Sat, 8 Jul 2017 08:16:31 +0200
4 Subject: debloat: add some debloat patches, strip down procfs and make O_DIRECT support optional, saves ~15K after lzma on MIPS
5
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8 net/Kconfig | 3 +++
9 net/core/Makefile | 3 ++-
10 net/core/sock.c | 2 ++
11 net/ipv4/Kconfig | 1 +
12 net/netlink/Kconfig | 1 +
13 net/packet/Kconfig | 1 +
14 net/unix/Kconfig | 1 +
15 7 files changed, 11 insertions(+), 1 deletion(-)
16
17 --- a/net/Kconfig
18 +++ b/net/Kconfig
19 @@ -104,6 +104,9 @@ source "net/mptcp/Kconfig"
20
21 endif # if INET
22
23 +config SOCK_DIAG
24 + bool
25 +
26 config NETWORK_SECMARK
27 bool "Security Marking"
28 help
29 --- a/net/core/Makefile
30 +++ b/net/core/Makefile
31 @@ -11,11 +11,12 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.
32
33 obj-y += dev.o dev_addr_lists.o dst.o netevent.o \
34 neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
35 - sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \
36 + dev_ioctl.o tso.o sock_reuseport.o \
37 fib_notifier.o xdp.o flow_offload.o gro.o
38
39 obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
40
41 +obj-$(CONFIG_SOCK_DIAG) += sock_diag.o
42 obj-y += net-sysfs.o
43 obj-$(CONFIG_PAGE_POOL) += page_pool.o
44 obj-$(CONFIG_PROC_FS) += net-procfs.o
45 --- a/net/core/sock.c
46 +++ b/net/core/sock.c
47 @@ -114,6 +114,7 @@
48 #include <linux/memcontrol.h>
49 #include <linux/prefetch.h>
50 #include <linux/compat.h>
51 +#include <linux/cookie.h>
52
53 #include <linux/uaccess.h>
54
55 @@ -145,6 +146,7 @@
56
57 static DEFINE_MUTEX(proto_list_mutex);
58 static LIST_HEAD(proto_list);
59 +DEFINE_COOKIE(sock_cookie);
60
61 static void sock_def_write_space_wfree(struct sock *sk);
62 static void sock_def_write_space(struct sock *sk);
63 @@ -584,6 +586,18 @@ discard_and_relse:
64 }
65 EXPORT_SYMBOL(__sk_receive_skb);
66
67 +u64 __sock_gen_cookie(struct sock *sk)
68 +{
69 + while (1) {
70 + u64 res = atomic64_read(&sk->sk_cookie);
71 +
72 + if (res)
73 + return res;
74 + res = gen_cookie_next(&sock_cookie);
75 + atomic64_cmpxchg(&sk->sk_cookie, 0, res);
76 + }
77 +}
78 +
79 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ip6_dst_check(struct dst_entry *,
80 u32));
81 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *,
82 @@ -2187,9 +2201,11 @@ static void __sk_free(struct sock *sk)
83 if (likely(sk->sk_net_refcnt))
84 sock_inuse_add(sock_net(sk), -1);
85
86 +#ifdef CONFIG_SOCK_DIAG
87 if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
88 sock_diag_broadcast_destroy(sk);
89 else
90 +#endif
91 sk_destruct(sk);
92 }
93
94 --- a/net/core/sock_diag.c
95 +++ b/net/core/sock_diag.c
96 @@ -12,7 +12,6 @@
97 #include <linux/tcp.h>
98 #include <linux/workqueue.h>
99 #include <linux/nospec.h>
100 -#include <linux/cookie.h>
101 #include <linux/inet_diag.h>
102 #include <linux/sock_diag.h>
103
104 @@ -21,20 +20,6 @@ static int (*inet_rcv_compat)(struct sk_
105 static DEFINE_MUTEX(sock_diag_table_mutex);
106 static struct workqueue_struct *broadcast_wq;
107
108 -DEFINE_COOKIE(sock_cookie);
109 -
110 -u64 __sock_gen_cookie(struct sock *sk)
111 -{
112 - while (1) {
113 - u64 res = atomic64_read(&sk->sk_cookie);
114 -
115 - if (res)
116 - return res;
117 - res = gen_cookie_next(&sock_cookie);
118 - atomic64_cmpxchg(&sk->sk_cookie, 0, res);
119 - }
120 -}
121 -
122 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
123 {
124 u64 res;
125 --- a/net/ipv4/Kconfig
126 +++ b/net/ipv4/Kconfig
127 @@ -423,6 +423,7 @@ config INET_TUNNEL
128
129 config INET_DIAG
130 tristate "INET: socket monitoring interface"
131 + select SOCK_DIAG
132 default y
133 help
134 Support for INET (TCP, DCCP, etc) socket monitoring interface used by
135 --- a/net/netlink/Kconfig
136 +++ b/net/netlink/Kconfig
137 @@ -5,6 +5,7 @@
138
139 config NETLINK_DIAG
140 tristate "NETLINK: socket monitoring interface"
141 + select SOCK_DIAG
142 default n
143 help
144 Support for NETLINK socket monitoring interface used by the ss tool.
145 --- a/net/packet/Kconfig
146 +++ b/net/packet/Kconfig
147 @@ -19,6 +19,7 @@ config PACKET
148 config PACKET_DIAG
149 tristate "Packet: sockets monitoring interface"
150 depends on PACKET
151 + select SOCK_DIAG
152 default n
153 help
154 Support for PF_PACKET sockets monitoring interface used by the ss tool.
155 --- a/net/unix/Kconfig
156 +++ b/net/unix/Kconfig
157 @@ -33,6 +33,7 @@ config AF_UNIX_OOB
158 config UNIX_DIAG
159 tristate "UNIX: socket monitoring interface"
160 depends on UNIX
161 + select SOCK_DIAG
162 default n
163 help
164 Support for UNIX socket monitoring interface used by the ss tool.
165 --- a/net/xdp/Kconfig
166 +++ b/net/xdp/Kconfig
167 @@ -10,6 +10,7 @@ config XDP_SOCKETS
168 config XDP_SOCKETS_DIAG
169 tristate "XDP sockets: monitoring interface"
170 depends on XDP_SOCKETS
171 + select SOCK_DIAG
172 default n
173 help
174 Support for PF_XDP sockets monitoring interface used by the ss tool.