From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <aleksandr.mikhalitsyn@canonical.com>
Cc: <arnd@arndb.de>, <bluca@debian.org>, <brauner@kernel.org>,
<cgroups@vger.kernel.org>, <davem@davemloft.net>,
<edumazet@google.com>, <hannes@cmpxchg.org>, <kuba@kernel.org>,
<kuniyu@amazon.com>, <leon@kernel.org>,
<linux-kernel@vger.kernel.org>, <mkoutny@suse.com>,
<mzxreary@0pointer.de>, <netdev@vger.kernel.org>,
<pabeni@redhat.com>, <tj@kernel.org>, <willemb@google.com>
Subject: Re: [PATCH net-next 1/4] net: unix: print cgroup_id and peer_cgroup_id in fdinfo
Date: Tue, 11 Mar 2025 00:41:54 -0700 [thread overview]
Message-ID: <20250311074218.5629-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20250309132821.103046-2-aleksandr.mikhalitsyn@canonical.com>
From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.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@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Cc: cgroups@vger.kernel.org
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
> Cc: Lennart Poettering <mzxreary@0pointer.de>
> Cc: Luca Boccassi <bluca@debian.org>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: "Michal Koutný" <mkoutny@suse.com>
> Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.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!
next prev parent reply other threads:[~2025-03-11 7:42 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-09 13:28 [PATCH net-next 0/4] Add getsockopt(SO_PEERCGROUPID) and fdinfo API to retreive socket's peer cgroup id Alexander Mikhalitsyn
2025-03-09 13:28 ` [PATCH net-next 1/4] net: unix: print cgroup_id and peer_cgroup_id in fdinfo Alexander Mikhalitsyn
2025-03-11 7:41 ` Kuniyuki Iwashima [this message]
2025-03-09 13:28 ` [PATCH net-next 2/4] net: core: add getsockopt SO_PEERCGROUPID Alexander Mikhalitsyn
2025-03-10 14:00 ` Willem de Bruijn
2025-03-11 7:52 ` Kuniyuki Iwashima
2025-03-09 13:28 ` [PATCH net-next 3/4] tools/testing/selftests/cgroup/cgroup_util: add cg_get_id helper Alexander Mikhalitsyn
2025-03-09 13:28 ` [PATCH net-next 4/4] tools/testing/selftests/cgroup: add test for SO_PEERCGROUPID Alexander Mikhalitsyn
2025-03-10 13:59 ` Willem de Bruijn
2025-03-11 8:02 ` Kuniyuki Iwashima
2025-03-09 14:36 ` [PATCH net-next 0/4] Add getsockopt(SO_PEERCGROUPID) and fdinfo API to retreive socket's peer cgroup id Tejun Heo
2025-03-10 8:52 ` Christian Brauner
2025-03-10 11:27 ` Christian Brauner
2025-03-11 7:33 ` Kuniyuki Iwashima
2025-03-11 12:02 ` Christian Brauner
2025-03-13 10:31 ` Michal Koutný
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250311074218.5629-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=aleksandr.mikhalitsyn@canonical.com \
--cc=arnd@arndb.de \
--cc=bluca@debian.org \
--cc=brauner@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hannes@cmpxchg.org \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=mzxreary@0pointer.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tj@kernel.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®