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
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
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(-)
19 @@ -129,6 +129,9 @@ source "net/mptcp/Kconfig"
26 config NETWORK_SECMARK
27 bool "Security Marking"
29 --- a/net/core/Makefile
30 +++ b/net/core/Makefile
31 @@ -11,12 +11,13 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.
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
40 obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
42 +obj-$(CONFIG_SOCK_DIAG) += sock_diag.o
44 obj-$(CONFIG_PAGE_POOL) += page_pool.o
45 obj-$(CONFIG_PROC_FS) += net-procfs.o
49 #include <linux/mroute.h>
50 #include <linux/mroute6.h>
51 #include <linux/icmpv6.h>
52 +#include <linux/cookie.h>
54 #include <linux/uaccess.h>
58 static DEFINE_MUTEX(proto_list_mutex);
59 static LIST_HEAD(proto_list);
60 +DEFINE_COOKIE(sock_cookie);
62 static void sock_def_write_space_wfree(struct sock *sk);
63 static void sock_def_write_space(struct sock *sk);
64 @@ -589,6 +591,21 @@ discard_and_relse:
66 EXPORT_SYMBOL(__sk_receive_skb);
68 +u64 __sock_gen_cookie(struct sock *sk)
70 + u64 res = atomic64_read(&sk->sk_cookie);
73 + u64 new = gen_cookie_next(&sock_cookie);
75 + atomic64_cmpxchg(&sk->sk_cookie, res, new);
77 + /* Another thread might have changed sk_cookie before us. */
78 + res = atomic64_read(&sk->sk_cookie);
83 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ip6_dst_check(struct dst_entry *,
85 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *,
86 @@ -2246,9 +2263,11 @@ static void __sk_free(struct sock *sk)
87 if (likely(sk->sk_net_refcnt))
88 sock_inuse_add(sock_net(sk), -1);
90 +#ifdef CONFIG_SOCK_DIAG
91 if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
92 sock_diag_broadcast_destroy(sk);
98 --- a/net/core/sock_diag.c
99 +++ b/net/core/sock_diag.c
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>
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;
112 -DEFINE_COOKIE(sock_cookie);
114 -u64 __sock_gen_cookie(struct sock *sk)
116 - u64 res = atomic64_read(&sk->sk_cookie);
119 - u64 new = gen_cookie_next(&sock_cookie);
121 - atomic64_cmpxchg(&sk->sk_cookie, res, new);
123 - /* Another thread might have changed sk_cookie before us. */
124 - res = atomic64_read(&sk->sk_cookie);
129 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
132 --- a/net/ipv4/Kconfig
133 +++ b/net/ipv4/Kconfig
134 @@ -423,6 +423,7 @@ config INET_TUNNEL
137 tristate "INET: socket monitoring interface"
141 Support for INET (TCP, DCCP, etc) socket monitoring interface used by
142 --- a/net/netlink/Kconfig
143 +++ b/net/netlink/Kconfig
147 tristate "NETLINK: socket monitoring interface"
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
156 tristate "Packet: sockets monitoring interface"
161 Support for PF_PACKET sockets monitoring interface used by the ss tool.
162 --- a/net/unix/Kconfig
163 +++ b/net/unix/Kconfig
164 @@ -29,6 +29,7 @@ config AF_UNIX_OOB
166 tristate "UNIX: socket monitoring interface"
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
181 Support for PF_XDP sockets monitoring interface used by the ss tool.