901-debloat_sock_diag.patch 4.4 KB

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