* [PATCH v1 net-next 1/4] af_unix: Sort headers.
2025-03-18 3:48 [PATCH v1 net-next 0/4] af_unix: Clean up headers Kuniyuki Iwashima
@ 2025-03-18 3:48 ` Kuniyuki Iwashima
2025-03-18 23:07 ` Joe Damato
2025-03-18 3:48 ` [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/ Kuniyuki Iwashima
` (3 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Kuniyuki Iwashima @ 2025-03-18 3:48 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
This is a prep patch to make the following changes cleaner.
No functional change intended.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
include/net/af_unix.h | 4 +--
net/unix/af_unix.c | 62 +++++++++++++++++++-------------------
net/unix/diag.c | 15 ++++-----
net/unix/garbage.c | 17 +++++------
net/unix/sysctl_net_unix.c | 1 -
net/unix/unix_bpf.c | 4 +--
6 files changed, 51 insertions(+), 52 deletions(-)
diff --git a/include/net/af_unix.h b/include/net/af_unix.h
index 63129c79b8cb..c8dfdb41916d 100644
--- a/include/net/af_unix.h
+++ b/include/net/af_unix.h
@@ -2,10 +2,10 @@
#ifndef __LINUX_NET_AFUNIX_H
#define __LINUX_NET_AFUNIX_H
-#include <linux/socket.h>
-#include <linux/un.h>
#include <linux/mutex.h>
#include <linux/refcount.h>
+#include <linux/socket.h>
+#include <linux/un.h>
#include <net/sock.h>
#if IS_ENABLED(CONFIG_UNIX)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 7f8f3859cdb3..1ff0ac99f3f3 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -77,46 +77,46 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/signal.h>
-#include <linux/sched/signal.h>
-#include <linux/errno.h>
-#include <linux/string.h>
-#include <linux/stat.h>
+#include <linux/bpf-cgroup.h>
+#include <linux/btf_ids.h>
#include <linux/dcache.h>
-#include <linux/namei.h>
-#include <linux/socket.h>
-#include <linux/un.h>
+#include <linux/errno.h>
#include <linux/fcntl.h>
+#include <linux/file.h>
#include <linux/filter.h>
-#include <linux/termios.h>
-#include <linux/sockios.h>
-#include <linux/net.h>
-#include <linux/in.h>
+#include <linux/freezer.h>
#include <linux/fs.h>
-#include <linux/slab.h>
-#include <linux/uaccess.h>
-#include <linux/skbuff.h>
-#include <linux/netdevice.h>
-#include <net/net_namespace.h>
-#include <net/sock.h>
-#include <net/tcp_states.h>
-#include <net/af_unix.h>
-#include <linux/proc_fs.h>
-#include <linux/seq_file.h>
-#include <net/scm.h>
+#include <linux/in.h>
#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mount.h>
+#include <linux/namei.h>
+#include <linux/net.h>
+#include <linux/netdevice.h>
#include <linux/poll.h>
+#include <linux/proc_fs.h>
#include <linux/rtnetlink.h>
-#include <linux/mount.h>
-#include <net/checksum.h>
+#include <linux/sched/signal.h>
#include <linux/security.h>
+#include <linux/seq_file.h>
+#include <linux/signal.h>
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+#include <linux/socket.h>
+#include <linux/sockios.h>
#include <linux/splice.h>
-#include <linux/freezer.h>
-#include <linux/file.h>
-#include <linux/btf_ids.h>
-#include <linux/bpf-cgroup.h>
+#include <linux/stat.h>
+#include <linux/string.h>
+#include <linux/termios.h>
+#include <linux/uaccess.h>
+#include <linux/un.h>
+#include <net/af_unix.h>
+#include <net/checksum.h>
+#include <net/net_namespace.h>
+#include <net/scm.h>
+#include <net/sock.h>
+#include <net/tcp_states.h>
static atomic_long_t unix_nr_socks;
static struct hlist_head bsd_socket_buckets[UNIX_HASH_SIZE / 2];
diff --git a/net/unix/diag.c b/net/unix/diag.c
index 9138af8b465e..ba715507556a 100644
--- a/net/unix/diag.c
+++ b/net/unix/diag.c
@@ -1,15 +1,16 @@
// SPDX-License-Identifier: GPL-2.0-only
-#include <linux/types.h>
-#include <linux/spinlock.h>
-#include <linux/sock_diag.h>
-#include <linux/unix_diag.h>
-#include <linux/skbuff.h>
+
#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <linux/sock_diag.h>
+#include <linux/spinlock.h>
+#include <linux/types.h>
#include <linux/uidgid.h>
-#include <net/netlink.h>
+#include <linux/unix_diag.h>
#include <net/af_unix.h>
-#include <net/tcp_states.h>
+#include <net/netlink.h>
#include <net/sock.h>
+#include <net/tcp_states.h>
static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb)
{
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 9848b7b78701..6a641d4b5542 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -63,22 +63,21 @@
* wrt receive and holding up unrelated socket operations.
*/
+#include <linux/file.h>
+#include <linux/fs.h>
#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/socket.h>
-#include <linux/un.h>
+#include <linux/mutex.h>
#include <linux/net.h>
-#include <linux/fs.h>
-#include <linux/skbuff.h>
#include <linux/netdevice.h>
-#include <linux/file.h>
#include <linux/proc_fs.h>
-#include <linux/mutex.h>
+#include <linux/skbuff.h>
+#include <linux/socket.h>
+#include <linux/string.h>
+#include <linux/un.h>
#include <linux/wait.h>
-
-#include <net/sock.h>
#include <net/af_unix.h>
#include <net/scm.h>
+#include <net/sock.h>
#include <net/tcp_states.h>
struct unix_sock *unix_get_socket(struct file *filp)
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
index 357b3e5f3847..55118ae897d6 100644
--- a/net/unix/sysctl_net_unix.c
+++ b/net/unix/sysctl_net_unix.c
@@ -8,7 +8,6 @@
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/sysctl.h>
-
#include <net/af_unix.h>
static struct ctl_table unix_table[] = {
diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
index bca2d86ba97d..86598a959eaa 100644
--- a/net/unix/unix_bpf.c
+++ b/net/unix/unix_bpf.c
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Cong Wang <cong.wang@bytedance.com> */
-#include <linux/skmsg.h>
#include <linux/bpf.h>
-#include <net/sock.h>
+#include <linux/skmsg.h>
#include <net/af_unix.h>
+#include <net/sock.h>
#define unix_sk_has_data(__sk, __psock) \
({ !skb_queue_empty(&__sk->sk_receive_queue) || \
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v1 net-next 1/4] af_unix: Sort headers.
2025-03-18 3:48 ` [PATCH v1 net-next 1/4] af_unix: Sort headers Kuniyuki Iwashima
@ 2025-03-18 23:07 ` Joe Damato
2025-03-18 23:50 ` Kuniyuki Iwashima
0 siblings, 1 reply; 13+ messages in thread
From: Joe Damato @ 2025-03-18 23:07 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Kuniyuki Iwashima, netdev
On Mon, Mar 17, 2025 at 08:48:48PM -0700, Kuniyuki Iwashima wrote:
> This is a prep patch to make the following changes cleaner.
>
> No functional change intended.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> include/net/af_unix.h | 4 +--
> net/unix/af_unix.c | 62 +++++++++++++++++++-------------------
> net/unix/diag.c | 15 ++++-----
> net/unix/garbage.c | 17 +++++------
> net/unix/sysctl_net_unix.c | 1 -
> net/unix/unix_bpf.c | 4 +--
> 6 files changed, 51 insertions(+), 52 deletions(-)
[...]
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 7f8f3859cdb3..1ff0ac99f3f3 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
[...]
> +#include <linux/in.h>
> #include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mount.h>
> +#include <linux/namei.h>
> +#include <linux/net.h>
> +#include <linux/netdevice.h>
> #include <linux/poll.h>
> +#include <linux/proc_fs.h>
> #include <linux/rtnetlink.h>
> -#include <linux/mount.h>
> -#include <net/checksum.h>
> +#include <linux/sched/signal.h>
Not sure what the sorting rules are, but I was wondering if maybe
"linux/sched/*.h" should come after linux/*.h and not sorted within
linux/s*.h ?
> #include <linux/security.h>
> +#include <linux/seq_file.h>
> +#include <linux/signal.h>
> +#include <linux/skbuff.h>
> +#include <linux/slab.h>
> +#include <linux/socket.h>
> +#include <linux/sockios.h>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v1 net-next 1/4] af_unix: Sort headers.
2025-03-18 23:07 ` Joe Damato
@ 2025-03-18 23:50 ` Kuniyuki Iwashima
2025-03-19 15:56 ` Joe Damato
0 siblings, 1 reply; 13+ messages in thread
From: Kuniyuki Iwashima @ 2025-03-18 23:50 UTC (permalink / raw)
To: jdamato; +Cc: davem, edumazet, horms, kuba, kuni1840, kuniyu, netdev, pabeni
From: Joe Damato <jdamato@fastly.com>
Date: Tue, 18 Mar 2025 16:07:47 -0700
> > +#include <linux/in.h>
> > #include <linux/init.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/mount.h>
> > +#include <linux/namei.h>
> > +#include <linux/net.h>
> > +#include <linux/netdevice.h>
> > #include <linux/poll.h>
> > +#include <linux/proc_fs.h>
> > #include <linux/rtnetlink.h>
> > -#include <linux/mount.h>
> > -#include <net/checksum.h>
> > +#include <linux/sched/signal.h>
>
> Not sure what the sorting rules are, but I was wondering if maybe
> "linux/sched/*.h" should come after linux/*.h and not sorted within
> linux/s*.h ?
It's simply sorted in the alphabetial order.
Actually I haven't cared about the / level, so I grepped the
linux/sched/signal.h users and it looks like most didn't care.
grep -rnI --include=*.c --include=*.h "linux/sched/signal.h" -C 3
Thanks!
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v1 net-next 1/4] af_unix: Sort headers.
2025-03-18 23:50 ` Kuniyuki Iwashima
@ 2025-03-19 15:56 ` Joe Damato
0 siblings, 0 replies; 13+ messages in thread
From: Joe Damato @ 2025-03-19 15:56 UTC (permalink / raw)
To: Kuniyuki Iwashima; +Cc: davem, edumazet, horms, kuba, kuni1840, netdev, pabeni
On Tue, Mar 18, 2025 at 04:50:00PM -0700, Kuniyuki Iwashima wrote:
> From: Joe Damato <jdamato@fastly.com>
> Date: Tue, 18 Mar 2025 16:07:47 -0700
> > > +#include <linux/in.h>
> > > #include <linux/init.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/module.h>
> > > +#include <linux/mount.h>
> > > +#include <linux/namei.h>
> > > +#include <linux/net.h>
> > > +#include <linux/netdevice.h>
> > > #include <linux/poll.h>
> > > +#include <linux/proc_fs.h>
> > > #include <linux/rtnetlink.h>
> > > -#include <linux/mount.h>
> > > -#include <net/checksum.h>
> > > +#include <linux/sched/signal.h>
> >
> > Not sure what the sorting rules are, but I was wondering if maybe
> > "linux/sched/*.h" should come after linux/*.h and not sorted within
> > linux/s*.h ?
>
> It's simply sorted in the alphabetial order.
Yea, I understand that - just wasn't sure if subdirectories should
be sorted separately.
> Actually I haven't cared about the / level, so I grepped the
> linux/sched/signal.h users and it looks like most didn't care.
>
> grep -rnI --include=*.c --include=*.h "linux/sched/signal.h" -C 3
OK, fair enough.
Reviewed-by: Joe Damato <jdamato@fastly.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
2025-03-18 3:48 [PATCH v1 net-next 0/4] af_unix: Clean up headers Kuniyuki Iwashima
2025-03-18 3:48 ` [PATCH v1 net-next 1/4] af_unix: Sort headers Kuniyuki Iwashima
@ 2025-03-18 3:48 ` Kuniyuki Iwashima
2025-03-18 23:12 ` Joe Damato
2025-03-19 17:49 ` Willem de Bruijn
2025-03-18 3:48 ` [PATCH v1 net-next 3/4] af_unix: Explicitly include headers for non-pointer struct fields Kuniyuki Iwashima
` (2 subsequent siblings)
4 siblings, 2 replies; 13+ messages in thread
From: Kuniyuki Iwashima @ 2025-03-18 3:48 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
net/af_unix.h is included by core and some LSMs, but most definitions
need not be.
Let's move struct unix_{vertex,edge} to net/unix/garbage.c and other
definitions to net/unix/af_unix.h.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
include/net/af_unix.h | 76 +-------------------------------------
net/unix/af_unix.c | 2 +
net/unix/af_unix.h | 75 +++++++++++++++++++++++++++++++++++++
net/unix/diag.c | 2 +
net/unix/garbage.c | 18 +++++++++
net/unix/sysctl_net_unix.c | 2 +
net/unix/unix_bpf.c | 2 +
7 files changed, 102 insertions(+), 75 deletions(-)
create mode 100644 net/unix/af_unix.h
diff --git a/include/net/af_unix.h b/include/net/af_unix.h
index c8dfdb41916d..b5d70baba52b 100644
--- a/include/net/af_unix.h
+++ b/include/net/af_unix.h
@@ -17,61 +17,17 @@ static inline struct unix_sock *unix_get_socket(struct file *filp)
}
#endif
-extern unsigned int unix_tot_inflight;
-void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver);
-void unix_del_edges(struct scm_fp_list *fpl);
-void unix_update_edges(struct unix_sock *receiver);
-int unix_prepare_fpl(struct scm_fp_list *fpl);
-void unix_destroy_fpl(struct scm_fp_list *fpl);
-void unix_gc(void);
-void wait_for_unix_gc(struct scm_fp_list *fpl);
-
-struct unix_vertex {
- struct list_head edges;
- struct list_head entry;
- struct list_head scc_entry;
- unsigned long out_degree;
- unsigned long index;
- unsigned long scc_index;
-};
-
-struct unix_edge {
- struct unix_sock *predecessor;
- struct unix_sock *successor;
- struct list_head vertex_entry;
- struct list_head stack_entry;
-};
-
-struct sock *unix_peer_get(struct sock *sk);
-
-#define UNIX_HASH_MOD (256 - 1)
-#define UNIX_HASH_SIZE (256 * 2)
-#define UNIX_HASH_BITS 8
-
struct unix_address {
refcount_t refcnt;
int len;
struct sockaddr_un name[];
};
-struct unix_skb_parms {
- struct pid *pid; /* Skb credentials */
- kuid_t uid;
- kgid_t gid;
- struct scm_fp_list *fp; /* Passed files */
-#ifdef CONFIG_SECURITY_NETWORK
- u32 secid; /* Security ID */
-#endif
- u32 consumed;
-} __randomize_layout;
-
struct scm_stat {
atomic_t nr_fds;
unsigned long nr_unix_fds;
};
-#define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
-
/* The AF_UNIX socket */
struct unix_sock {
/* WARNING: sk has to be the first member */
@@ -84,6 +40,7 @@ struct unix_sock {
struct unix_vertex *vertex;
spinlock_t lock;
struct socket_wq peer_wq;
+#define peer_wait peer_wq.wait
wait_queue_entry_t peer_wake;
struct scm_stat scm_stat;
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
@@ -94,35 +51,4 @@ struct unix_sock {
#define unix_sk(ptr) container_of_const(ptr, struct unix_sock, sk)
#define unix_peer(sk) (unix_sk(sk)->peer)
-#define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
-#define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
-
-#define peer_wait peer_wq.wait
-
-long unix_inq_len(struct sock *sk);
-long unix_outq_len(struct sock *sk);
-
-int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
- int flags);
-int __unix_stream_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
- int flags);
-#ifdef CONFIG_SYSCTL
-int unix_sysctl_register(struct net *net);
-void unix_sysctl_unregister(struct net *net);
-#else
-static inline int unix_sysctl_register(struct net *net) { return 0; }
-static inline void unix_sysctl_unregister(struct net *net) {}
-#endif
-
-#ifdef CONFIG_BPF_SYSCALL
-extern struct proto unix_dgram_proto;
-extern struct proto unix_stream_proto;
-
-int unix_dgram_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
-int unix_stream_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
-void __init unix_bpf_build_proto(void);
-#else
-static inline void __init unix_bpf_build_proto(void)
-{}
-#endif
#endif
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 1ff0ac99f3f3..6390e04fe916 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -118,6 +118,8 @@
#include <net/sock.h>
#include <net/tcp_states.h>
+#include "af_unix.h"
+
static atomic_long_t unix_nr_socks;
static struct hlist_head bsd_socket_buckets[UNIX_HASH_SIZE / 2];
static spinlock_t bsd_socket_locks[UNIX_HASH_SIZE / 2];
diff --git a/net/unix/af_unix.h b/net/unix/af_unix.h
new file mode 100644
index 000000000000..ed4aedc42813
--- /dev/null
+++ b/net/unix/af_unix.h
@@ -0,0 +1,75 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __AF_UNIX_H
+#define __AF_UNIX_H
+
+#include <linux/uidgid.h>
+
+#define UNIX_HASH_MOD (256 - 1)
+#define UNIX_HASH_SIZE (256 * 2)
+#define UNIX_HASH_BITS 8
+
+#define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
+#define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
+
+struct sock *unix_peer_get(struct sock *sk);
+
+struct unix_skb_parms {
+ struct pid *pid; /* skb credentials */
+ kuid_t uid;
+ kgid_t gid;
+ struct scm_fp_list *fp; /* Passed files */
+#ifdef CONFIG_SECURITY_NETWORK
+ u32 secid; /* Security ID */
+#endif
+ u32 consumed;
+} __randomize_layout;
+
+#define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
+
+/* GC for SCM_RIGHTS */
+extern unsigned int unix_tot_inflight;
+void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver);
+void unix_del_edges(struct scm_fp_list *fpl);
+void unix_update_edges(struct unix_sock *receiver);
+int unix_prepare_fpl(struct scm_fp_list *fpl);
+void unix_destroy_fpl(struct scm_fp_list *fpl);
+void unix_gc(void);
+void wait_for_unix_gc(struct scm_fp_list *fpl);
+
+/* SOCK_DIAG */
+long unix_inq_len(struct sock *sk);
+long unix_outq_len(struct sock *sk);
+
+/* sysctl */
+#ifdef CONFIG_SYSCTL
+int unix_sysctl_register(struct net *net);
+void unix_sysctl_unregister(struct net *net);
+#else
+static inline int unix_sysctl_register(struct net *net)
+{
+ return 0;
+}
+
+static inline void unix_sysctl_unregister(struct net *net)
+{
+}
+#endif
+
+/* BPF SOCKMAP */
+int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size, int flags);
+int __unix_stream_recvmsg(struct sock *sk, struct msghdr *msg, size_t size, int flags);
+
+#ifdef CONFIG_BPF_SYSCALL
+extern struct proto unix_dgram_proto;
+extern struct proto unix_stream_proto;
+
+int unix_dgram_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
+int unix_stream_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
+void __init unix_bpf_build_proto(void);
+#else
+static inline void __init unix_bpf_build_proto(void)
+{
+}
+#endif
+
+#endif
diff --git a/net/unix/diag.c b/net/unix/diag.c
index ba715507556a..c7e8c7d008f6 100644
--- a/net/unix/diag.c
+++ b/net/unix/diag.c
@@ -12,6 +12,8 @@
#include <net/sock.h>
#include <net/tcp_states.h>
+#include "af_unix.h"
+
static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb)
{
/* might or might not have a hash table lock */
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 6a641d4b5542..8c8c7360349d 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -80,6 +80,24 @@
#include <net/sock.h>
#include <net/tcp_states.h>
+#include "af_unix.h"
+
+struct unix_vertex {
+ struct list_head edges;
+ struct list_head entry;
+ struct list_head scc_entry;
+ unsigned long out_degree;
+ unsigned long index;
+ unsigned long scc_index;
+};
+
+struct unix_edge {
+ struct unix_sock *predecessor;
+ struct unix_sock *successor;
+ struct list_head vertex_entry;
+ struct list_head stack_entry;
+};
+
struct unix_sock *unix_get_socket(struct file *filp)
{
struct inode *inode = file_inode(filp);
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
index 55118ae897d6..236b7faa9254 100644
--- a/net/unix/sysctl_net_unix.c
+++ b/net/unix/sysctl_net_unix.c
@@ -10,6 +10,8 @@
#include <linux/sysctl.h>
#include <net/af_unix.h>
+#include "af_unix.h"
+
static struct ctl_table unix_table[] = {
{
.procname = "max_dgram_qlen",
diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
index 86598a959eaa..979dd4c4261a 100644
--- a/net/unix/unix_bpf.c
+++ b/net/unix/unix_bpf.c
@@ -6,6 +6,8 @@
#include <net/af_unix.h>
#include <net/sock.h>
+#include "af_unix.h"
+
#define unix_sk_has_data(__sk, __psock) \
({ !skb_queue_empty(&__sk->sk_receive_queue) || \
!skb_queue_empty(&__psock->ingress_skb) || \
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
2025-03-18 3:48 ` [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/ Kuniyuki Iwashima
@ 2025-03-18 23:12 ` Joe Damato
2025-03-19 17:49 ` Willem de Bruijn
1 sibling, 0 replies; 13+ messages in thread
From: Joe Damato @ 2025-03-18 23:12 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Kuniyuki Iwashima, netdev
On Mon, Mar 17, 2025 at 08:48:49PM -0700, Kuniyuki Iwashima wrote:
> net/af_unix.h is included by core and some LSMs, but most definitions
> need not be.
>
> Let's move struct unix_{vertex,edge} to net/unix/garbage.c and other
> definitions to net/unix/af_unix.h.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> include/net/af_unix.h | 76 +-------------------------------------
> net/unix/af_unix.c | 2 +
> net/unix/af_unix.h | 75 +++++++++++++++++++++++++++++++++++++
> net/unix/diag.c | 2 +
> net/unix/garbage.c | 18 +++++++++
> net/unix/sysctl_net_unix.c | 2 +
> net/unix/unix_bpf.c | 2 +
> 7 files changed, 102 insertions(+), 75 deletions(-)
> create mode 100644 net/unix/af_unix.h
Nice clean up.
Reviewed-by: Joe Damato <jdamato@fastly.com>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
2025-03-18 3:48 ` [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/ Kuniyuki Iwashima
2025-03-18 23:12 ` Joe Damato
@ 2025-03-19 17:49 ` Willem de Bruijn
2025-03-19 18:15 ` Kuniyuki Iwashima
1 sibling, 1 reply; 13+ messages in thread
From: Willem de Bruijn @ 2025-03-19 17:49 UTC (permalink / raw)
To: Kuniyuki Iwashima, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
Kuniyuki Iwashima wrote:
> net/af_unix.h is included by core and some LSMs, but most definitions
> need not be.
>
> Let's move struct unix_{vertex,edge} to net/unix/garbage.c and other
> definitions to net/unix/af_unix.h.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
One trade-off with these kinds of refactors is that it adds an
indirection in git history: a git blame on a line no longer points to
the relevant commit.
Whether the trade-off is worth it is subjective, your call. Just
making it explicit.
I still manually check out pre UDP/UDPLite split often to go back in
udp history, for instance.
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
2025-03-19 17:49 ` Willem de Bruijn
@ 2025-03-19 18:15 ` Kuniyuki Iwashima
2025-03-19 19:48 ` Willem de Bruijn
0 siblings, 1 reply; 13+ messages in thread
From: Kuniyuki Iwashima @ 2025-03-19 18:15 UTC (permalink / raw)
To: willemdebruijn.kernel
Cc: davem, edumazet, horms, kuba, kuni1840, kuniyu, netdev, pabeni
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: Wed, 19 Mar 2025 13:49:31 -0400
> Kuniyuki Iwashima wrote:
> > net/af_unix.h is included by core and some LSMs, but most definitions
> > need not be.
> >
> > Let's move struct unix_{vertex,edge} to net/unix/garbage.c and other
> > definitions to net/unix/af_unix.h.
> >
> > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
>
> One trade-off with these kinds of refactors is that it adds an
> indirection in git history: a git blame on a line no longer points to
> the relevant commit.
Right, and git has a useful option for that.
>
> Whether the trade-off is worth it is subjective, your call. Just
> making it explicit.
>
> I still manually check out pre UDP/UDPLite split often to go back in
> udp history, for instance.
I often use -C5 (track 5 times for line/file moves) and hope this
helps you :)
$ git blame -C1 net/unix/af_unix.h
Blaming lines: 100% (75/75), done.
b24413180f5600 include/net/af_unix.h (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) /* SPDX-License-Identifier: GPL-2.0 */
d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 2) #ifndef __AF_UNIX_H
d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 3) #define __AF_UNIX_H
d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 4)
cae9910e73446c net/unix/diag.c (Felipe Gasper 2019-05-20 19:43:51 -0500 5) #include <linux/uidgid.h>
^1da177e4c3f41 include/net/af_unix.h (Linus Torvalds 2005-04-16 15:20:36 -0700 6)
Thanks!
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
2025-03-19 18:15 ` Kuniyuki Iwashima
@ 2025-03-19 19:48 ` Willem de Bruijn
0 siblings, 0 replies; 13+ messages in thread
From: Willem de Bruijn @ 2025-03-19 19:48 UTC (permalink / raw)
To: Kuniyuki Iwashima, willemdebruijn.kernel
Cc: davem, edumazet, horms, kuba, kuni1840, kuniyu, netdev, pabeni
Kuniyuki Iwashima wrote:
> From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> Date: Wed, 19 Mar 2025 13:49:31 -0400
> > Kuniyuki Iwashima wrote:
> > > net/af_unix.h is included by core and some LSMs, but most definitions
> > > need not be.
> > >
> > > Let's move struct unix_{vertex,edge} to net/unix/garbage.c and other
> > > definitions to net/unix/af_unix.h.
> > >
> > > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> >
> > One trade-off with these kinds of refactors is that it adds an
> > indirection in git history: a git blame on a line no longer points to
> > the relevant commit.
>
> Right, and git has a useful option for that.
>
>
> >
> > Whether the trade-off is worth it is subjective, your call. Just
> > making it explicit.
> >
> > I still manually check out pre UDP/UDPLite split often to go back in
> > udp history, for instance.
>
> I often use -C5 (track 5 times for line/file moves) and hope this
> helps you :)
>
> $ git blame -C1 net/unix/af_unix.h
> Blaming lines: 100% (75/75), done.
> b24413180f5600 include/net/af_unix.h (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) /* SPDX-License-Identifier: GPL-2.0 */
> d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 2) #ifndef __AF_UNIX_H
> d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 3) #define __AF_UNIX_H
> d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 4)
> cae9910e73446c net/unix/diag.c (Felipe Gasper 2019-05-20 19:43:51 -0500 5) #include <linux/uidgid.h>
> ^1da177e4c3f41 include/net/af_unix.h (Linus Torvalds 2005-04-16 15:20:36 -0700 6)
Thanks! I can't believe I did not know about this. That
certainly mitigates the busywork around refactoring a bit.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v1 net-next 3/4] af_unix: Explicitly include headers for non-pointer struct fields.
2025-03-18 3:48 [PATCH v1 net-next 0/4] af_unix: Clean up headers Kuniyuki Iwashima
2025-03-18 3:48 ` [PATCH v1 net-next 1/4] af_unix: Sort headers Kuniyuki Iwashima
2025-03-18 3:48 ` [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/ Kuniyuki Iwashima
@ 2025-03-18 3:48 ` Kuniyuki Iwashima
2025-03-18 3:48 ` [PATCH v1 net-next 4/4] af_unix: Clean up #include under net/unix/ Kuniyuki Iwashima
2025-03-25 11:40 ` [PATCH v1 net-next 0/4] af_unix: Clean up headers patchwork-bot+netdevbpf
4 siblings, 0 replies; 13+ messages in thread
From: Kuniyuki Iwashima @ 2025-03-18 3:48 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
include/net/af_unix.h indirectly includes some definitions for structs.
Let's include such headers explicitly.
linux/atomic.h : scm_stat.nr_fds
linux/net.h : unix_sock.peer_wq
linux/path.h : unix_sock.path
linux/spinlock.h : unix_sock.lock
linux/wait.h : unix_sock.peer_wake
uapi/linux/un.h : unix_address.name[]
linux/socket.h is removed as the structs there are not used directly,
and linux/un.h is clarified with uapi as un.h only exists under
include/uapi.
While at it, duplicate headers are removed from .c files.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
include/net/af_unix.h | 8 ++++++--
net/unix/af_unix.c | 3 ---
net/unix/diag.c | 3 ---
net/unix/garbage.c | 5 -----
net/unix/unix_bpf.c | 1 -
5 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/include/net/af_unix.h b/include/net/af_unix.h
index b5d70baba52b..b588069ece7e 100644
--- a/include/net/af_unix.h
+++ b/include/net/af_unix.h
@@ -2,11 +2,15 @@
#ifndef __LINUX_NET_AFUNIX_H
#define __LINUX_NET_AFUNIX_H
+#include <linux/atomic.h>
#include <linux/mutex.h>
+#include <linux/net.h>
+#include <linux/path.h>
#include <linux/refcount.h>
-#include <linux/socket.h>
-#include <linux/un.h>
+#include <linux/spinlock.h>
+#include <linux/wait.h>
#include <net/sock.h>
+#include <uapi/linux/un.h>
#if IS_ENABLED(CONFIG_UNIX)
struct unix_sock *unix_get_socket(struct file *filp);
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 6390e04fe916..c081440cf576 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -92,7 +92,6 @@
#include <linux/module.h>
#include <linux/mount.h>
#include <linux/namei.h>
-#include <linux/net.h>
#include <linux/netdevice.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
@@ -110,12 +109,10 @@
#include <linux/string.h>
#include <linux/termios.h>
#include <linux/uaccess.h>
-#include <linux/un.h>
#include <net/af_unix.h>
#include <net/checksum.h>
#include <net/net_namespace.h>
#include <net/scm.h>
-#include <net/sock.h>
#include <net/tcp_states.h>
#include "af_unix.h"
diff --git a/net/unix/diag.c b/net/unix/diag.c
index c7e8c7d008f6..8b2247e05596 100644
--- a/net/unix/diag.c
+++ b/net/unix/diag.c
@@ -3,13 +3,10 @@
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/sock_diag.h>
-#include <linux/spinlock.h>
#include <linux/types.h>
-#include <linux/uidgid.h>
#include <linux/unix_diag.h>
#include <net/af_unix.h>
#include <net/netlink.h>
-#include <net/sock.h>
#include <net/tcp_states.h>
#include "af_unix.h"
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 8c8c7360349d..cd75502c47f1 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -66,18 +66,13 @@
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/kernel.h>
-#include <linux/mutex.h>
-#include <linux/net.h>
#include <linux/netdevice.h>
#include <linux/proc_fs.h>
#include <linux/skbuff.h>
#include <linux/socket.h>
#include <linux/string.h>
-#include <linux/un.h>
-#include <linux/wait.h>
#include <net/af_unix.h>
#include <net/scm.h>
-#include <net/sock.h>
#include <net/tcp_states.h>
#include "af_unix.h"
diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
index 979dd4c4261a..e0d30d6d22ac 100644
--- a/net/unix/unix_bpf.c
+++ b/net/unix/unix_bpf.c
@@ -4,7 +4,6 @@
#include <linux/bpf.h>
#include <linux/skmsg.h>
#include <net/af_unix.h>
-#include <net/sock.h>
#include "af_unix.h"
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v1 net-next 4/4] af_unix: Clean up #include under net/unix/.
2025-03-18 3:48 [PATCH v1 net-next 0/4] af_unix: Clean up headers Kuniyuki Iwashima
` (2 preceding siblings ...)
2025-03-18 3:48 ` [PATCH v1 net-next 3/4] af_unix: Explicitly include headers for non-pointer struct fields Kuniyuki Iwashima
@ 2025-03-18 3:48 ` Kuniyuki Iwashima
2025-03-25 11:40 ` [PATCH v1 net-next 0/4] af_unix: Clean up headers patchwork-bot+netdevbpf
4 siblings, 0 replies; 13+ messages in thread
From: Kuniyuki Iwashima @ 2025-03-18 3:48 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
net/unix/*.c include many unnecessary header files (rtnetlink.h,
netdevice.h, etc).
Let's clean them up.
af_unix.c:
+uapi/linux/sockios.h : Only exist under include/uapi
+uapi/linux/termios.h : Only exist under include/uapi
-linux/freezer.h : No longer use freezable_schedule_timeout()
-linux/in.h : No ipv4_is_XXX() etc
-linux/module.h : No longer support CONFIG_UNIX=m
-linux/netdevice.h : No dev used
-linux/rtnetlink.h : Not part of rtnetlink API
-linux/signal.h : signal_pending() is defined in sched/signal.h
-linux/stat.h : No struct stat used
-net/checksum.h : CHECKSUM_UNNECESSARY is defined in skbuff.h
diag.c:
+linux/dcache.h : struct dentry in sk_diag_dump_vfs()
+linux/user_namespace.h : struct user_namespace in sk_diag_dump_uid()
+uapi/linux/unix_diag.h : Only exist under include/uapi/
garbage.c:
+linux/list.h : struct unix_{vertex,edge}, etc
+linux/workqueue.h : DECLARE_WORK(unix_gc_work, ...)
-linux/file.h : No fget() etc
-linux/kernel.h : No cond_resched() etc
-linux/netdevice.h : No dev used
-linux/proc_fs.h : No procfs provided
-linux/string.h : No memcpy(), kmemdup(), etc
sysctl_net_unix.c:
+linux/string.h : kmemdup()
+net/net_namespace.h : struct net, net_eq()
-linux/mm.h : slab.h is enough
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/unix/af_unix.c | 12 ++----------
net/unix/diag.c | 4 +++-
net/unix/garbage.c | 7 ++-----
net/unix/sysctl_net_unix.c | 3 ++-
4 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index c081440cf576..f78a2492826f 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -84,36 +84,28 @@
#include <linux/fcntl.h>
#include <linux/file.h>
#include <linux/filter.h>
-#include <linux/freezer.h>
#include <linux/fs.h>
-#include <linux/in.h>
#include <linux/init.h>
#include <linux/kernel.h>
-#include <linux/module.h>
#include <linux/mount.h>
#include <linux/namei.h>
-#include <linux/netdevice.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
-#include <linux/rtnetlink.h>
#include <linux/sched/signal.h>
#include <linux/security.h>
#include <linux/seq_file.h>
-#include <linux/signal.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/socket.h>
-#include <linux/sockios.h>
#include <linux/splice.h>
-#include <linux/stat.h>
#include <linux/string.h>
-#include <linux/termios.h>
#include <linux/uaccess.h>
#include <net/af_unix.h>
-#include <net/checksum.h>
#include <net/net_namespace.h>
#include <net/scm.h>
#include <net/tcp_states.h>
+#include <uapi/linux/sockios.h>
+#include <uapi/linux/termios.h>
#include "af_unix.h"
diff --git a/net/unix/diag.c b/net/unix/diag.c
index 8b2247e05596..79b182d0e62a 100644
--- a/net/unix/diag.c
+++ b/net/unix/diag.c
@@ -1,13 +1,15 @@
// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/dcache.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/sock_diag.h>
#include <linux/types.h>
-#include <linux/unix_diag.h>
+#include <linux/user_namespace.h>
#include <net/af_unix.h>
#include <net/netlink.h>
#include <net/tcp_states.h>
+#include <uapi/linux/unix_diag.h>
#include "af_unix.h"
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index cd75502c47f1..01e2b9452c75 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -63,14 +63,11 @@
* wrt receive and holding up unrelated socket operations.
*/
-#include <linux/file.h>
#include <linux/fs.h>
-#include <linux/kernel.h>
-#include <linux/netdevice.h>
-#include <linux/proc_fs.h>
+#include <linux/list.h>
#include <linux/skbuff.h>
#include <linux/socket.h>
-#include <linux/string.h>
+#include <linux/workqueue.h>
#include <net/af_unix.h>
#include <net/scm.h>
#include <net/tcp_states.h>
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
index 236b7faa9254..e02ed6e3955c 100644
--- a/net/unix/sysctl_net_unix.c
+++ b/net/unix/sysctl_net_unix.c
@@ -5,10 +5,11 @@
* Authors: Mike Shaver.
*/
-#include <linux/mm.h>
#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/sysctl.h>
#include <net/af_unix.h>
+#include <net/net_namespace.h>
#include "af_unix.h"
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v1 net-next 0/4] af_unix: Clean up headers.
2025-03-18 3:48 [PATCH v1 net-next 0/4] af_unix: Clean up headers Kuniyuki Iwashima
` (3 preceding siblings ...)
2025-03-18 3:48 ` [PATCH v1 net-next 4/4] af_unix: Clean up #include under net/unix/ Kuniyuki Iwashima
@ 2025-03-25 11:40 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-03-25 11:40 UTC (permalink / raw)
To: Kuniyuki Iwashima; +Cc: davem, edumazet, kuba, pabeni, horms, kuni1840, netdev
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 17 Mar 2025 20:48:47 -0700 you wrote:
> AF_UNIX files include many unnecessary headers (netdevice.h and
> rtnetlink.h, etc), and this series cleans them up.
>
> Note that there are still some headers included indirectly and
> modifying them triggers rebuild, which seems mostly inevitable. [0]
>
> $ python3 include_graph.py net/unix/garbage.c linux/rtnetlink.h linux/netdevice.h
> ...
> include/net/af_unix.h
> | include/linux/net.h
> | | include/linux/once.h
> | | include/linux/sockptr.h
> | | include/uapi/linux/net.h
> | include/net/sock.h
> | | include/linux/netdevice.h <---
> ...
> | | include/net/dst.h
> | | | include/linux/rtnetlink.h <---
>
> [...]
Here is the summary with links:
- [v1,net-next,1/4] af_unix: Sort headers.
https://git.kernel.org/netdev/net-next/c/f9af583a2c76
- [v1,net-next,2/4] af_unix: Move internal definitions to net/unix/.
https://git.kernel.org/netdev/net-next/c/84960bf24031
- [v1,net-next,3/4] af_unix: Explicitly include headers for non-pointer struct fields.
https://git.kernel.org/netdev/net-next/c/3056172a261c
- [v1,net-next,4/4] af_unix: Clean up #include under net/unix/.
https://git.kernel.org/netdev/net-next/c/0083e3e37e07
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 13+ messages in thread