901-debloat_sock_diag.patch 4.7 KB

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