kernel: Make the patches apply on top of 4.19
[openwrt/staging/chunkeey.git] / target / linux / generic / hack-4.19 / 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 @@ -98,6 +98,9 @@ source "net/netlabel/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 @@ -10,9 +10,10 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.
32
33 obj-y += dev.o ethtool.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
38
39 +obj-$(CONFIG_SOCK_DIAG) += sock_diag.o
40 obj-y += net-sysfs.o
41 obj-$(CONFIG_PAGE_POOL) += page_pool.o
42 obj-$(CONFIG_PROC_FS) += net-procfs.o
43 --- a/net/core/sock.c
44 +++ b/net/core/sock.c
45 @@ -490,6 +490,18 @@ discard_and_relse:
46 }
47 EXPORT_SYMBOL(__sk_receive_skb);
48
49 +u64 sock_gen_cookie(struct sock *sk)
50 +{
51 + while (1) {
52 + u64 res = atomic64_read(&sk->sk_cookie);
53 +
54 + if (res)
55 + return res;
56 + res = atomic64_inc_return(&sock_net(sk)->cookie_gen);
57 + atomic64_cmpxchg(&sk->sk_cookie, 0, res);
58 + }
59 +}
60 +
61 struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie)
62 {
63 struct dst_entry *dst = __sk_dst_get(sk);
64 @@ -1600,9 +1612,11 @@ static void __sk_free(struct sock *sk)
65 if (likely(sk->sk_net_refcnt))
66 sock_inuse_add(sock_net(sk), -1);
67
68 +#ifdef CONFIG_SOCK_DIAG
69 if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
70 sock_diag_broadcast_destroy(sk);
71 else
72 +#endif
73 sk_destruct(sk);
74 }
75
76 --- a/net/core/sock_diag.c
77 +++ b/net/core/sock_diag.c
78 @@ -20,18 +20,6 @@ static int (*inet_rcv_compat)(struct sk_
79 static DEFINE_MUTEX(sock_diag_table_mutex);
80 static struct workqueue_struct *broadcast_wq;
81
82 -u64 sock_gen_cookie(struct sock *sk)
83 -{
84 - while (1) {
85 - u64 res = atomic64_read(&sk->sk_cookie);
86 -
87 - if (res)
88 - return res;
89 - res = atomic64_inc_return(&sock_net(sk)->cookie_gen);
90 - atomic64_cmpxchg(&sk->sk_cookie, 0, res);
91 - }
92 -}
93 -
94 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
95 {
96 u64 res;
97 --- a/net/ipv4/Kconfig
98 +++ b/net/ipv4/Kconfig
99 @@ -425,6 +425,7 @@ config INET_XFRM_MODE_BEET
100
101 config INET_DIAG
102 tristate "INET: socket monitoring interface"
103 + select SOCK_DIAG
104 default y
105 ---help---
106 Support for INET (TCP, DCCP, etc) socket monitoring interface used by
107 --- a/net/netlink/Kconfig
108 +++ b/net/netlink/Kconfig
109 @@ -4,6 +4,7 @@
110
111 config NETLINK_DIAG
112 tristate "NETLINK: socket monitoring interface"
113 + select SOCK_DIAG
114 default n
115 ---help---
116 Support for NETLINK socket monitoring interface used by the ss tool.
117 --- a/net/packet/Kconfig
118 +++ b/net/packet/Kconfig
119 @@ -18,6 +18,7 @@ config PACKET
120 config PACKET_DIAG
121 tristate "Packet: sockets monitoring interface"
122 depends on PACKET
123 + select SOCK_DIAG
124 default n
125 ---help---
126 Support for PF_PACKET sockets monitoring interface used by the ss tool.
127 --- a/net/unix/Kconfig
128 +++ b/net/unix/Kconfig
129 @@ -22,6 +22,7 @@ config UNIX
130 config UNIX_DIAG
131 tristate "UNIX: socket monitoring interface"
132 depends on UNIX
133 + select SOCK_DIAG
134 default n
135 ---help---
136 Support for UNIX socket monitoring interface used by the ss tool.