901-debloat_sock_diag.patch 4.6 KB

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