901-debloat_sock_diag.patch 4.8 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. @@ -129,6 +129,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-$(CONFIG_PAGE_POOL) += page_pool.o
  38. obj-$(CONFIG_PROC_FS) += net-procfs.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. @@ -150,6 +151,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. @@ -589,6 +591,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. @@ -2246,9 +2263,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. @@ -21,23 +20,6 @@ static int (*inet_rcv_compat)(struct sk_
  94. static DEFINE_MUTEX(sock_diag_table_mutex);
  95. static struct workqueue_struct *broadcast_wq;
  96. -DEFINE_COOKIE(sock_cookie);
  97. -
  98. -u64 __sock_gen_cookie(struct sock *sk)
  99. -{
  100. - u64 res = atomic64_read(&sk->sk_cookie);
  101. -
  102. - if (!res) {
  103. - u64 new = gen_cookie_next(&sock_cookie);
  104. -
  105. - atomic64_cmpxchg(&sk->sk_cookie, res, new);
  106. -
  107. - /* Another thread might have changed sk_cookie before us. */
  108. - res = atomic64_read(&sk->sk_cookie);
  109. - }
  110. - return res;
  111. -}
  112. -
  113. int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
  114. {
  115. u64 res;
  116. --- a/net/ipv4/Kconfig
  117. +++ b/net/ipv4/Kconfig
  118. @@ -423,6 +423,7 @@ config INET_TUNNEL
  119. config INET_DIAG
  120. tristate "INET: socket monitoring interface"
  121. + select SOCK_DIAG
  122. default y
  123. help
  124. Support for INET (TCP, DCCP, etc) socket monitoring interface used by
  125. --- a/net/netlink/Kconfig
  126. +++ b/net/netlink/Kconfig
  127. @@ -5,6 +5,7 @@
  128. config NETLINK_DIAG
  129. tristate "NETLINK: socket monitoring interface"
  130. + select SOCK_DIAG
  131. default n
  132. help
  133. Support for NETLINK socket monitoring interface used by the ss tool.
  134. --- a/net/packet/Kconfig
  135. +++ b/net/packet/Kconfig
  136. @@ -19,6 +19,7 @@ config PACKET
  137. config PACKET_DIAG
  138. tristate "Packet: sockets monitoring interface"
  139. depends on PACKET
  140. + select SOCK_DIAG
  141. default n
  142. help
  143. Support for PF_PACKET sockets monitoring interface used by the ss tool.
  144. --- a/net/unix/Kconfig
  145. +++ b/net/unix/Kconfig
  146. @@ -29,6 +29,7 @@ config AF_UNIX_OOB
  147. config UNIX_DIAG
  148. tristate "UNIX: socket monitoring interface"
  149. depends on UNIX
  150. + select SOCK_DIAG
  151. default n
  152. help
  153. Support for UNIX socket monitoring interface used by the ss tool.
  154. --- a/net/xdp/Kconfig
  155. +++ b/net/xdp/Kconfig
  156. @@ -10,6 +10,7 @@ config XDP_SOCKETS
  157. config XDP_SOCKETS_DIAG
  158. tristate "XDP sockets: monitoring interface"
  159. depends on XDP_SOCKETS
  160. + select SOCK_DIAG
  161. default n
  162. help
  163. Support for PF_XDP sockets monitoring interface used by the ss tool.