[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250311074218.5629-1-kuniyu@amazon.com>
Date: Tue, 11 Mar 2025 00:41:54 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <aleksandr.mikhalitsyn@...onical.com>
CC: <arnd@...db.de>, <bluca@...ian.org>, <brauner@...nel.org>,
<cgroups@...r.kernel.org>, <davem@...emloft.net>, <edumazet@...gle.com>,
<hannes@...xchg.org>, <kuba@...nel.org>, <kuniyu@...zon.com>,
<leon@...nel.org>, <linux-kernel@...r.kernel.org>, <mkoutny@...e.com>,
<mzxreary@...inter.de>, <netdev@...r.kernel.org>, <pabeni@...hat.com>,
<tj@...nel.org>, <willemb@...gle.com>
Subject: Re: [PATCH net-next 1/4] net: unix: print cgroup_id and peer_cgroup_id in fdinfo
From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
Date: Sun, 9 Mar 2025 14:28:12 +0100
Please add few sentences here, why this interface is needed,
why accessing peer sk's sk_cgrp_data is not racy (e.g. sk_cgrp_data
never changes after creation (I'm not sure this is the case though)),
etc.
In case this interface is racy for the use case, please drop the patch.
> Cc: linux-kernel@...r.kernel.org
> Cc: netdev@...r.kernel.org
> Cc: cgroups@...r.kernel.org
> Cc: "David S. Miller" <davem@...emloft.net>
> Cc: Eric Dumazet <edumazet@...gle.com>
> Cc: Jakub Kicinski <kuba@...nel.org>
> Cc: Paolo Abeni <pabeni@...hat.com>
> Cc: Willem de Bruijn <willemb@...gle.com>
> Cc: Leon Romanovsky <leon@...nel.org>
> Cc: Arnd Bergmann <arnd@...db.de>
> Cc: Christian Brauner <brauner@...nel.org>
> Cc: Kuniyuki Iwashima <kuniyu@...zon.com>
> Cc: Lennart Poettering <mzxreary@...inter.de>
> Cc: Luca Boccassi <bluca@...ian.org>
> Cc: Tejun Heo <tj@...nel.org>
> Cc: Johannes Weiner <hannes@...xchg.org>
> Cc: "Michal Koutný" <mkoutny@...e.com>
> Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
> ---
> net/unix/af_unix.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 7f8f3859cdb3..2b2c0036efc9 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -117,6 +117,7 @@
> #include <linux/file.h>
> #include <linux/btf_ids.h>
> #include <linux/bpf-cgroup.h>
> +#include <linux/cgroup.h>
>
> static atomic_long_t unix_nr_socks;
> static struct hlist_head bsd_socket_buckets[UNIX_HASH_SIZE / 2];
> @@ -861,6 +862,11 @@ static void unix_show_fdinfo(struct seq_file *m, struct socket *sock)
> int nr_fds = 0;
>
> if (sk) {
> +#ifdef CONFIG_SOCK_CGROUP_DATA
> + struct sock *peer;
> + u64 sk_cgroup_id = 0;
Please keep reverse xmas tree order for net patches.
https://docs.kernel.org/process/maintainer-netdev.html#local-variable-ordering-reverse-xmas-tree-rcs
Also, no need to initialise sk_cgroup_id, so it should be:
struct sock *peer;
u64 sk_cgroup_id;
> +#endif
> +
> s_state = READ_ONCE(sk->sk_state);
> u = unix_sk(sk);
>
> @@ -874,6 +880,21 @@ static void unix_show_fdinfo(struct seq_file *m, struct socket *sock)
> nr_fds = unix_count_nr_fds(sk);
>
> seq_printf(m, "scm_fds: %u\n", nr_fds);
> +
> +#ifdef CONFIG_SOCK_CGROUP_DATA
> + sk_cgroup_id = cgroup_id(sock_cgroup_ptr(&sk->sk_cgrp_data));
> + seq_printf(m, "cgroup_id: %llu\n", sk_cgroup_id);
> +
> + peer = unix_peer_get(sk);
> + if (peer) {
> + u64 peer_cgroup_id = 0;
Same here, no need to initialise peer_cgroup_id.
> +
> + peer_cgroup_id = cgroup_id(sock_cgroup_ptr(&peer->sk_cgrp_data));
> + sock_put(peer);
> +
> + seq_printf(m, "peer_cgroup_id: %llu\n", peer_cgroup_id);
> + }
> +#endif
> }
> }
> #else
> --
> 2.43.0
Thanks!
Powered by blists - more mailing lists