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 @@ -104,6 +104,9 @@ source "net/mptcp/Kconfig"
26 config NETWORK_SECMARK
27 bool "Security Marking"
29 --- a/net/core/Makefile
30 +++ b/net/core/Makefile
31 @@ -10,9 +10,10 @@ 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
39 +obj-$(CONFIG_SOCK_DIAG) += sock_diag.o
41 obj-$(CONFIG_PAGE_POOL) += page_pool.o
42 obj-$(CONFIG_PROC_FS) += net-procfs.o
46 #include <linux/memcontrol.h>
47 #include <linux/prefetch.h>
48 #include <linux/compat.h>
49 +#include <linux/cookie.h>
51 #include <linux/uaccess.h>
55 static DEFINE_MUTEX(proto_list_mutex);
56 static LIST_HEAD(proto_list);
57 +DEFINE_COOKIE(sock_cookie);
59 static void sock_inuse_add(struct net *net, int val);
61 @@ -545,6 +547,18 @@ discard_and_relse:
63 EXPORT_SYMBOL(__sk_receive_skb);
65 +u64 __sock_gen_cookie(struct sock *sk)
68 + u64 res = atomic64_read(&sk->sk_cookie);
72 + res = gen_cookie_next(&sock_cookie);
73 + atomic64_cmpxchg(&sk->sk_cookie, 0, res);
77 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ip6_dst_check(struct dst_entry *,
79 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *,
80 @@ -1987,9 +2001,11 @@ static void __sk_free(struct sock *sk)
81 if (likely(sk->sk_net_refcnt))
82 sock_inuse_add(sock_net(sk), -1);
84 +#ifdef CONFIG_SOCK_DIAG
85 if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
86 sock_diag_broadcast_destroy(sk);
92 --- a/net/core/sock_diag.c
93 +++ b/net/core/sock_diag.c
95 #include <linux/tcp.h>
96 #include <linux/workqueue.h>
97 #include <linux/nospec.h>
98 -#include <linux/cookie.h>
99 #include <linux/inet_diag.h>
100 #include <linux/sock_diag.h>
102 @@ -20,20 +19,6 @@ static int (*inet_rcv_compat)(struct sk_
103 static DEFINE_MUTEX(sock_diag_table_mutex);
104 static struct workqueue_struct *broadcast_wq;
106 -DEFINE_COOKIE(sock_cookie);
108 -u64 __sock_gen_cookie(struct sock *sk)
111 - u64 res = atomic64_read(&sk->sk_cookie);
115 - res = gen_cookie_next(&sock_cookie);
116 - atomic64_cmpxchg(&sk->sk_cookie, 0, res);
120 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
123 --- a/net/ipv4/Kconfig
124 +++ b/net/ipv4/Kconfig
125 @@ -424,6 +424,7 @@ config INET_TUNNEL
128 tristate "INET: socket monitoring interface"
132 Support for INET (TCP, DCCP, etc) socket monitoring interface used by
133 --- a/net/netlink/Kconfig
134 +++ b/net/netlink/Kconfig
138 tristate "NETLINK: socket monitoring interface"
142 Support for NETLINK socket monitoring interface used by the ss tool.
143 --- a/net/packet/Kconfig
144 +++ b/net/packet/Kconfig
145 @@ -19,6 +19,7 @@ config PACKET
147 tristate "Packet: sockets monitoring interface"
152 Support for PF_PACKET sockets monitoring interface used by the ss tool.
153 --- a/net/unix/Kconfig
154 +++ b/net/unix/Kconfig
155 @@ -33,6 +33,7 @@ config AF_UNIX_OOB
157 tristate "UNIX: socket monitoring interface"
162 Support for UNIX socket monitoring interface used by the ss tool.
163 --- a/net/xdp/Kconfig
164 +++ b/net/xdp/Kconfig
165 @@ -10,6 +10,7 @@ config XDP_SOCKETS
166 config XDP_SOCKETS_DIAG
167 tristate "XDP sockets: monitoring interface"
168 depends on XDP_SOCKETS
172 Support for PF_XDP sockets monitoring interface used by the ss tool.