Skip to contentSkip to conversation

net: skbuff: clean up unnecessary includes

PATCH Applied Jakub Kicinski 3 participants 14 messages Jan 26, 2023 – Jan 27, 2023

Subsystems (16)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover net: skbuff: clean up unnecessary includes

skbuff.h is included in a significant portion of the tree. Clean up unused dependencies to speed up builds.

This set only takes care of the most obvious cases.

Jakub Kicinski (11):
net: add missing includes of linux/net.h
net: skbuff: drop the linux/net.h include
net: checksum: drop the linux/uaccess.h include
net: skbuff: drop the linux/textsearch.h include
net: add missing includes of linux/sched/clock.h
net: skbuff: drop the linux/sched/clock.h include
net: skbuff: drop the linux/sched.h include
net: add missing includes of linux/splice.h
net: skbuff: drop the linux/splice.h include
net: skbuff: drop the linux/hrtimer.h include
net: remove unnecessary includes from net/flow.h

 arch/arm/include/asm/checksum.h                            | 1 +
 arch/x86/include/asm/checksum_64.h                         | 1 -
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 1 +
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c     | 2 ++
 drivers/net/wireless/intersil/orinoco/hermes.c             | 1 +
 drivers/scsi/lpfc/lpfc_init.c                              | 1 +
 include/linux/filter.h                                     | 1 +
 include/linux/igmp.h                                       | 1 +
 include/linux/skbuff.h                                     | 7 +------
 include/net/checksum.h                                     | 4 +++-
 include/net/flow.h                                         | 5 +++--
 net/core/skbuff.c                                          | 1 +
 net/rds/ib_recv.c                                          | 1 +
 net/rds/recv.c                                             | 1 +
 net/smc/af_smc.c                                           | 1 +
 net/smc/smc_rx.c                                           | 1 +
 net/unix/af_unix.c                                         | 1 +
 17 files changed, 21 insertions(+), 10 deletions(-)
Signature · 1 line
2.39.1
author maintainer
#3 lore raw

PATCH 3/11 net: checksum: drop the linux/uaccess.h include

net/checksum.h pulls in linux/uaccess.h which is large.

In the x86 header the include seems to not be needed at all. ARM on the other hand does not include uaccess.h, even tho it calls access_ok().

In the generic implementation guard the include of linux/uaccess.h with the same condition as the code that needs it.

With this change pre-processed net/checksum.h shrinks on x86 from 30616 lines to just 1193.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 arch/arm/include/asm/checksum.h    | 1 +
 arch/x86/include/asm/checksum_64.h | 1 -
 include/net/checksum.h             | 4 +++-
 3 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/include/asm/checksum.h +1 -0
index f0f54aef3724..d8a13959bff0 100644
@@ -11,6 +11,7 @@
 #define __ASM_ARM_CHECKSUM_H
 
 #include <linux/in6.h>
+#include <linux/uaccess.h>
 
 /*
  * computes the checksum of a memory block at buff, length len,
arch/x86/include/asm/checksum_64.h +0 -1
index 407beebadaf4..4d4a47a3a8ab 100644
@@ -9,7 +9,6 @@
  */
 
 #include <linux/compiler.h>
-#include <linux/uaccess.h>
 #include <asm/byteorder.h>
 
 /**
include/net/checksum.h +3 -1
index 6bc783b7a06c..1338cb92c8e7 100644
@@ -18,8 +18,10 @@
 #include <linux/errno.h>
 #include <asm/types.h>
 #include <asm/byteorder.h>
-#include <linux/uaccess.h>
 #include <asm/checksum.h>
+#if !defined(_HAVE_ARCH_COPY_AND_CSUM_FROM_USER) || !defined(HAVE_CSUM_COPY_USER)
+#include <linux/uaccess.h>
+#endif
 
 #ifndef _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
 static __always_inline
Signature · 1 line
2.39.1
author maintainer
#1 lore raw

PATCH 1/11 net: add missing includes of linux/net.h

In reply to Jakub Kicinski

linux/net.h will soon not be included by linux/skbuff.h. Fix the cases where source files were depending on the implicit include.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 drivers/net/wireless/intersil/orinoco/hermes.c | 1 +
 include/linux/igmp.h                           | 1 +
 2 files changed, 2 insertions(+)
drivers/net/wireless/intersil/orinoco/hermes.c +1 -0
index 256946552742..4888286727ff 100644
@@ -38,6 +38,7 @@
  * under either the MPL or the GPL.
  */
 
+#include <linux/net.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
include/linux/igmp.h +1 -0
index 78890143f079..b19d3284551f 100644
@@ -15,6 +15,7 @@
 #include <linux/in.h>
 #include <linux/ip.h>
 #include <linux/refcount.h>
+#include <linux/sockptr.h>
 #include <uapi/linux/igmp.h>
 
 static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
Signature · 1 line
2.39.1
author maintainer
#4 lore raw

PATCH 4/11 net: skbuff: drop the linux/textsearch.h include

In reply to Jakub Kicinski

This include was added for skb_find_text() but all we need there is a forward declaration of struct ts_config.

---
CC: [email protected]

---
 include/linux/skbuff.h | 2 +-
 net/core/skbuff.c      | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/skbuff.h +1 -1
index b93818e11da0..7eeb06f9ca1f 100644
@@ -23,7 +23,6 @@
 #include <linux/atomic.h>
 #include <asm/types.h>
 #include <linux/spinlock.h>
-#include <linux/textsearch.h>
 #include <net/checksum.h>
 #include <linux/rcupdate.h>
 #include <linux/hrtimer.h>
@@ -279,6 +278,7 @@ struct napi_struct;
 struct bpf_prog;
 union bpf_attr;
 struct skb_ext;
+struct ts_config;
 
 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
 struct nf_bridge_info {
net/core/skbuff.c +1 -0
index 180df58e85c7..bb79b4cb89db 100644
@@ -79,6 +79,7 @@
 #include <linux/capability.h>
 #include <linux/user_namespace.h>
 #include <linux/indirect_call_wrapper.h>
+#include <linux/textsearch.h>
 
 #include "dev.h"
 #include "sock_destructor.h"
Signature · 1 line
2.39.1
author maintainer
#2 lore raw

PATCH 2/11 net: skbuff: drop the linux/net.h include

In reply to Jakub Kicinski

It appears nothing needs it. The kernel builds fine with this include removed, building an otherwise empty source file with:

#include <linux/skbuff.h>
#ifdef _LINUX_NET_H
#error linux/net.h is back
#endif

works too (meaning net.h is not just pulled in indirectly).

This gives us a slight 0.5% reduction in the pre-processed size of skbuff.h.

---
CC: [email protected]

---
 include/linux/skbuff.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/skbuff.h +0 -1
index 4c8492401a10..b93818e11da0 100644
@@ -23,7 +23,6 @@
 #include <linux/atomic.h>
 #include <asm/types.h>
 #include <linux/spinlock.h>
-#include <linux/net.h>
 #include <linux/textsearch.h>
 #include <net/checksum.h>
 #include <linux/rcupdate.h>
Signature · 1 line
2.39.1
author maintainer
#6 lore raw

PATCH 6/11 net: skbuff: drop the linux/sched/clock.h include

In reply to Jakub Kicinski

It used to be necessary for skb_mstamp_* static inlines, but those are gone since we moved to usec timestamps in TCP, in 2017.

---
CC: [email protected]

---
 include/linux/skbuff.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/skbuff.h +0 -1
index 7eeb06f9ca1f..aa920591ba37 100644
@@ -29,7 +29,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/netdev_features.h>
 #include <linux/sched.h>
-#include <linux/sched/clock.h>
 #include <net/flow_dissector.h>
 #include <linux/splice.h>
 #include <linux/in6.h>
Signature · 1 line
2.39.1
author maintainer
#5 lore raw

PATCH 5/11 net: add missing includes of linux/sched/clock.h

In reply to Jakub Kicinski

Number of files depend on linux/sched/clock.h getting included by linux/skbuff.h which soon will no longer be the case.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 1 +
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c     | 2 ++
 drivers/scsi/lpfc/lpfc_init.c                              | 1 +
 include/linux/filter.h                                     | 1 +
 net/rds/ib_recv.c                                          | 1 +
 net/rds/recv.c                                             | 1 +
 6 files changed, 7 insertions(+)
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c +1 -0
index 142415c84c6b..a0b46e7d863e 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2018-2019 Hisilicon Limited. */
 
 #include <linux/device.h>
+#include <linux/sched/clock.h>
 
 #include "hclge_debugfs.h"
 #include "hclge_err.h"
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c +2 -0
index 6efd768cc07c..3f35227ef1fa 100644
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0+
 /* Copyright (c) 2016-2017 Hisilicon Limited. */
 
+#include <linux/sched/clock.h>
+
 #include "hclge_err.h"
 
 static const struct hclge_hw_error hclge_imp_tcm_ecc_int[] = {
drivers/scsi/lpfc/lpfc_init.c +1 -0
index 25ba20e42825..389a35308be3 100644
@@ -30,6 +30,7 @@
 #include <linux/kthread.h>
 #include <linux/pci.h>
 #include <linux/spinlock.h>
+#include <linux/sched/clock.h>
 #include <linux/ctype.h>
 #include <linux/aer.h>
 #include <linux/slab.h>
include/linux/filter.h +1 -0
index ccc4a4a58c72..1727898f1641 100644
@@ -14,6 +14,7 @@
 #include <linux/printk.h>
 #include <linux/workqueue.h>
 #include <linux/sched.h>
+#include <linux/sched/clock.h>
 #include <linux/capability.h>
 #include <linux/set_memory.h>
 #include <linux/kallsyms.h>
net/rds/ib_recv.c +1 -0
index cfbf0e129cba..e53b7f266bd7 100644
@@ -31,6 +31,7 @@
  *
  */
 #include <linux/kernel.h>
+#include <linux/sched/clock.h>
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/dma-mapping.h>
net/rds/recv.c +1 -0
index 5b426dc3634d..c71b923764fd 100644
@@ -35,6 +35,7 @@
 #include <net/sock.h>
 #include <linux/in.h>
 #include <linux/export.h>
+#include <linux/sched/clock.h>
 #include <linux/time.h>
 #include <linux/rds.h>
 
Signature · 1 line
2.39.1
author maintainer
#7 lore raw

PATCH 7/11 net: skbuff: drop the linux/sched.h include

In reply to Jakub Kicinski

linux/sched.h was added for skb_mstamp_* (all the way back before linux/sched.h got split and linux/sched/clock.h created). We don't need it in skbuff.h any more.

Sadly this change is currently a noop because linux/dma-mapping.h and net/page_pool.h pull in half of the universe.

---
CC: [email protected]

---
 include/linux/skbuff.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/skbuff.h +0 -1
index aa920591ba37..a1978adc5644 100644
@@ -28,7 +28,6 @@
 #include <linux/hrtimer.h>
 #include <linux/dma-mapping.h>
 #include <linux/netdev_features.h>
-#include <linux/sched.h>
 #include <net/flow_dissector.h>
 #include <linux/splice.h>
 #include <linux/in6.h>
Signature · 1 line
2.39.1
author maintainer
#10 lore raw

PATCH 9/11 net: skbuff: drop the linux/splice.h include

In reply to Jakub Kicinski

splice.h is included since commit a60e3cc7c929 ("net: make skb_splice_bits more configureable") but really even then all we needed is some forward declarations. Most of that code is now gone, and remaining has fwd declarations.

---
CC: [email protected]

---
 include/linux/skbuff.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/skbuff.h +0 -1
index a1978adc5644..c6fd5d5b50e0 100644
@@ -29,7 +29,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/netdev_features.h>
 #include <net/flow_dissector.h>
-#include <linux/splice.h>
 #include <linux/in6.h>
 #include <linux/if_packet.h>
 #include <linux/llist.h>
Signature · 1 line
2.39.1
author maintainer
#12 lore raw

PATCH 11/11 net: remove unnecessary includes from net/flow.h

In reply to Jakub Kicinski

This file is included by a lot of other commonly included headers, it doesn't need socket.h or flow_dissector.h.

This reduces the size of this file after pre-processing from 28165 to 4663.

---

---
 include/net/flow.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
include/net/flow.h +3 -2
index 2f0da4f0318b..bb8651a6eaa7 100644
@@ -8,12 +8,13 @@
 #ifndef _NET_FLOW_H
 #define _NET_FLOW_H
 
-#include <linux/socket.h>
 #include <linux/in6.h>
 #include <linux/atomic.h>
-#include <net/flow_dissector.h>
+#include <linux/container_of.h>
 #include <linux/uidgid.h>
 
+struct flow_keys;
+
 /*
  * ifindex generation is per-net namespace, and loopback is
  * always the 1st device in ns (see net_dev_init), thus any
Signature · 1 line
2.39.1
author maintainer
#8 lore raw

PATCH 8/11 net: add missing includes of linux/splice.h

In reply to Jakub Kicinski

Number of files depend on linux/splice.h getting included by linux/skbuff.h which soon will no longer be the case.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 net/smc/af_smc.c   | 1 +
 net/smc/smc_rx.c   | 1 +
 net/unix/af_unix.c | 1 +
 3 files changed, 3 insertions(+)
net/smc/af_smc.c +1 -0
index 036532cf39aa..1c0fe9ba5358 100644
@@ -27,6 +27,7 @@
 #include <linux/if_vlan.h>
 #include <linux/rcupdate_wait.h>
 #include <linux/ctype.h>
+#include <linux/splice.h>
 
 #include <net/sock.h>
 #include <net/tcp.h>
net/smc/smc_rx.c +1 -0
index 0a6e615f000c..4380d32f5a5f 100644
@@ -13,6 +13,7 @@
 #include <linux/net.h>
 #include <linux/rcupdate.h>
 #include <linux/sched/signal.h>
+#include <linux/splice.h>
 
 #include <net/sock.h>
 #include <trace/events/sock.h>
net/unix/af_unix.c +1 -0
index 009616fa0256..0be25e712c28 100644
@@ -112,6 +112,7 @@
 #include <linux/mount.h>
 #include <net/checksum.h>
 #include <linux/security.h>
+#include <linux/splice.h>
 #include <linux/freezer.h>
 #include <linux/file.h>
 #include <linux/btf_ids.h>
Signature · 1 line
2.39.1
author maintainer
#11 lore raw

PATCH 10/11 net: skbuff: drop the linux/hrtimer.h include

In reply to Jakub Kicinski

linux/hrtimer.h include was added because apparently it used to contain ktime related code. This is no longer the case and we include linux/time.h explicitly.

Sadly this change is currently a noop because linux/dma-mapping.h and net/page_pool.h pull in half of the universe.

---
CC: [email protected]

---
 include/linux/skbuff.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/skbuff.h +0 -1
index c6fd5d5b50e0..5ba12185f43e 100644
@@ -25,7 +25,6 @@
 #include <linux/spinlock.h>
 #include <net/checksum.h>
 #include <linux/rcupdate.h>
-#include <linux/hrtimer.h>
 #include <linux/dma-mapping.h>
 #include <linux/netdev_features.h>
 #include <net/flow_dissector.h>
Signature · 1 line
2.39.1
#13 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 18 lines · On Wed, 25 Jan 2023 23:14:13 -0800 you wrote:

skbuff.h is included in a significant portion of the tree. Clean up unused dependencies to speed up builds.

This set only takes care of the most obvious cases.

Jakub Kicinski (11):
net: add missing includes of linux/net.h
net: skbuff: drop the linux/net.h include
net: checksum: drop the linux/uaccess.h include
net: skbuff: drop the linux/textsearch.h include
net: add missing includes of linux/sched/clock.h
net: skbuff: drop the linux/sched/clock.h include
net: skbuff: drop the linux/sched.h include
net: add missing includes of linux/splice.h
net: skbuff: drop the linux/splice.h include
net: skbuff: drop the linux/hrtimer.h include
net: remove unnecessary includes from net/flow.h

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,01/11] net: add missing includes of linux/net.h

    https://git.kernel.org/netdev/net-next/c/ac62f60619fa
  - [net-next,02/11] net: skbuff: drop the linux/net.h include
    https://git.kernel.org/netdev/net-next/c/9a859da28787
  - [net-next,03/11] net: checksum: drop the linux/uaccess.h include
    https://git.kernel.org/netdev/net-next/c/68f4eae781dd
  - [net-next,04/11] net: skbuff: drop the linux/textsearch.h include
    https://git.kernel.org/netdev/net-next/c/2195e2a024ae
  - [net-next,05/11] net: add missing includes of linux/sched/clock.h
    https://git.kernel.org/netdev/net-next/c/2870c4d6a5e4
  - [net-next,06/11] net: skbuff: drop the linux/sched/clock.h include
    https://git.kernel.org/netdev/net-next/c/9ac849f2c492
  - [net-next,07/11] net: skbuff: drop the linux/sched.h include
    https://git.kernel.org/netdev/net-next/c/422164224e32
  - [net-next,08/11] net: add missing includes of linux/splice.h
    https://git.kernel.org/netdev/net-next/c/509f15b9c551
  - [net-next,09/11] net: skbuff: drop the linux/splice.h include
    https://git.kernel.org/netdev/net-next/c/5255c0ca7983
  - [net-next,10/11] net: skbuff: drop the linux/hrtimer.h include
    https://git.kernel.org/netdev/net-next/c/9dd0db2b1303
  - [net-next,11/11] net: remove unnecessary includes from net/flow.h
    https://git.kernel.org/netdev/net-next/c/21bf73158fe7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Acked-by on v1 8/11
#9 lore raw

Re: [PATCH net-next 08/11] net: add missing includes of linux/splice.h

In reply to Jakub Kicinski
Quoted 33 lines · Jakub Kicinski

Number of files depend on linux/splice.h getting included by linux/skbuff.h which soon will no longer be the case.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
  net/smc/af_smc.c   | 1 +
  net/smc/smc_rx.c   | 1 +
  net/unix/af_unix.c | 1 +
  3 files changed, 3 insertions(+)
net/smc/af_smc.c +1 -0
index 036532cf39aa..1c0fe9ba5358 100644
@@ -27,6 +27,7 @@
  #include <linux/if_vlan.h>
  #include <linux/rcupdate_wait.h>
  #include <linux/ctype.h>
+#include <linux/splice.h>
 
  #include <net/sock.h>
  #include <net/tcp.h>
net/smc/smc_rx.c +0 -0
index 0a6e615f000c..4380d32f5a5f 100644

net/smc/smc_rx.c line 17

Quoted 5 lines
net/smc/smc_rx.c +1 -0
@@ -13,6 +13,7 @@
  #include <linux/net.h>
  #include <linux/rcupdate.h>
  #include <linux/sched/signal.h>
+#include <linux/splice.h>
 

Thank you, Jakub!

Quoted 14 lines
net/smc/smc_rx.c +0 -0
  #include <net/sock.h>
  #include <trace/events/sock.h>
net/unix/af_unix.c +1 -0
index 009616fa0256..0be25e712c28 100644
@@ -112,6 +112,7 @@
  #include <linux/mount.h>
  #include <net/checksum.h>
  #include <linux/security.h>
+#include <linux/splice.h>
  #include <linux/freezer.h>
  #include <linux/file.h>
  #include <linux/btf_ids.h>