generic: 6.6: manually refresh hack patches
[openwrt/staging/981213.git] / target / linux / generic / hack-6.6 / 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,12 +11,13 @@ 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 netdev-genl.o netdev-genl-gen.o gso.o
39
40 obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
41
42 +obj-$(CONFIG_SOCK_DIAG) += sock_diag.o
43 obj-y += net-sysfs.o
44 obj-$(CONFIG_PAGE_POOL) += page_pool.o
45 obj-$(CONFIG_PROC_FS) += net-procfs.o
46 --- a/net/core/sock.c
47 +++ b/net/core/sock.c
48 @@ -117,6 +117,7 @@
49 #include <linux/mroute.h>
50 #include <linux/mroute6.h>
51 #include <linux/icmpv6.h>
52 +#include <linux/cookie.h>
53
54 #include <linux/uaccess.h>
55
56 @@ -149,6 +150,7 @@
57
58 static DEFINE_MUTEX(proto_list_mutex);
59 static LIST_HEAD(proto_list);
60 +DEFINE_COOKIE(sock_cookie);
61
62 static void sock_def_write_space_wfree(struct sock *sk);
63 static void sock_def_write_space(struct sock *sk);
64 @@ -588,6 +590,21 @@ int __sk_receive_skb(struct sock *sk, str
65 }
66 EXPORT_SYMBOL(__sk_receive_skb);
67
68 +u64 __sock_gen_cookie(struct sock *sk)
69 +{
70 + u64 res = atomic64_read(&sk->sk_cookie);
71 +
72 + if (!res) {
73 + u64 new = gen_cookie_next(&sock_cookie);
74 +
75 + atomic64_cmpxchg(&sk->sk_cookie, res, new);
76 +
77 + /* Another thread might have changed sk_cookie before us. */
78 + res = atomic64_read(&sk->sk_cookie);
79 + }
80 + return res;
81 +}
82 +
83 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ip6_dst_check(struct dst_entry *,
84 u32));
85 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *,
86 @@ -2238,9 +2255,11 @@ static void __sk_free(struct sock *sk)
87 if (likely(sk->sk_net_refcnt))
88 sock_inuse_add(sock_net(sk), -1);
89
90 +#ifdef CONFIG_SOCK_DIAG
91 if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
92 sock_diag_broadcast_destroy(sk);
93 else
94 +#endif
95 sk_destruct(sk);
96 }
97
98 --- a/net/core/sock_diag.c
99 +++ b/net/core/sock_diag.c
100 @@ -12,7 +12,6 @@
101 #include <linux/tcp.h>
102 #include <linux/workqueue.h>
103 #include <linux/nospec.h>
104 -#include <linux/cookie.h>
105 #include <linux/inet_diag.h>
106 #include <linux/sock_diag.h>
107
108 @@ -21,23 +20,6 @@ static int (*inet_rcv_compat)(struct sk_
109 static DEFINE_MUTEX(sock_diag_table_mutex);
110 static struct workqueue_struct *broadcast_wq;
111
112 -DEFINE_COOKIE(sock_cookie);
113 -
114 -u64 __sock_gen_cookie(struct sock *sk)
115 -{
116 - u64 res = atomic64_read(&sk->sk_cookie);
117 -
118 - if (!res) {
119 - u64 new = gen_cookie_next(&sock_cookie);
120 -
121 - atomic64_cmpxchg(&sk->sk_cookie, res, new);
122 -
123 - /* Another thread might have changed sk_cookie before us. */
124 - res = atomic64_read(&sk->sk_cookie);
125 - }
126 - return res;
127 -}
128 -
129 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
130 {
131 u64 res;
132 --- a/net/ipv4/Kconfig
133 +++ b/net/ipv4/Kconfig
134 @@ -423,6 +423,7 @@ config INET_TUNNEL
135
136 config INET_DIAG
137 tristate "INET: socket monitoring interface"
138 + select SOCK_DIAG
139 default y
140 help
141 Support for INET (TCP, DCCP, etc) socket monitoring interface used by
142 --- a/net/netlink/Kconfig
143 +++ b/net/netlink/Kconfig
144 @@ -5,6 +5,7 @@
145
146 config NETLINK_DIAG
147 tristate "NETLINK: socket monitoring interface"
148 + select SOCK_DIAG
149 default n
150 help
151 Support for NETLINK socket monitoring interface used by the ss tool.
152 --- a/net/packet/Kconfig
153 +++ b/net/packet/Kconfig
154 @@ -19,6 +19,7 @@ config PACKET
155 config PACKET_DIAG
156 tristate "Packet: sockets monitoring interface"
157 depends on PACKET
158 + select SOCK_DIAG
159 default n
160 help
161 Support for PF_PACKET sockets monitoring interface used by the ss tool.
162 --- a/net/unix/Kconfig
163 +++ b/net/unix/Kconfig
164 @@ -33,6 +33,7 @@ config AF_UNIX_OOB
165 config UNIX_DIAG
166 tristate "UNIX: socket monitoring interface"
167 depends on UNIX
168 + select SOCK_DIAG
169 default n
170 help
171 Support for UNIX socket monitoring interface used by the ss tool.
172 --- a/net/xdp/Kconfig
173 +++ b/net/xdp/Kconfig
174 @@ -10,6 +10,7 @@ config XDP_SOCKETS
175 config XDP_SOCKETS_DIAG
176 tristate "XDP sockets: monitoring interface"
177 depends on XDP_SOCKETS
178 + select SOCK_DIAG
179 default n
180 help
181 Support for PF_XDP sockets monitoring interface used by the ss tool.