public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Gabriel Ryan <gabe@cs.columbia.edu>
Cc: Christian Brauner <brauner@kernel.org>,
	Abhishek Shah <abhishek.shah@columbia.edu>,
	linux-kernel@vger.kernel.org, andrii@kernel.org, ast@kernel.org,
	bpf@vger.kernel.org, cgroups@vger.kernel.org,
	daniel@iogearbox.net, hannes@cmpxchg.org,
	john.fastabend@gmail.com, kafai@fb.com, kpsingh@kernel.org,
	lizefan.x@bytedance.com, netdev@vger.kernel.org,
	songliubraving@fb.com, yhs@fb.com
Subject: Re: data-race in cgroup_get_tree / proc_cgroup_show
Date: Sun, 28 Aug 2022 08:22:02 -1000	[thread overview]
Message-ID: <YwuySgH4j6h2CGvk@slm.duckdns.org> (raw)
In-Reply-To: <CALbthtdFY+GHTzGH9OujzqpOtWZAqsU3MAsjv5OpwZUW6gVa7A@mail.gmail.com>

On Mon, Aug 22, 2022 at 01:04:58PM -0400, Gabriel Ryan wrote:
> Hi Christian,
> 
> We ran a quick test and confirm your suggestion would eliminate the
> data race alert we observed. If the data race is benign (and it
> appears to be), using WRITE_ONCE(cgrp_dfl_visible, true) instead of
> cmpxchg in cgroup_get_tree() would probably also be ok.

I don't see how the data race can lead to anything but would the following
work?

Thanks.

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index ffaccd6373f1e..a90fdba881bdb 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2172,7 +2172,7 @@ static int cgroup_get_tree(struct fs_context *fc)
 	struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
 	int ret;
 
-	cgrp_dfl_visible = true;
+	WRITE_ONCE(cgrp_dfl_visible, true);
 	cgroup_get_live(&cgrp_dfl_root.cgrp);
 	ctx->root = &cgrp_dfl_root;
 
@@ -6056,7 +6056,7 @@ int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns,
 		struct cgroup *cgrp;
 		int ssid, count = 0;
 
-		if (root == &cgrp_dfl_root && !cgrp_dfl_visible)
+		if (root == &cgrp_dfl_root && !READ_ONCE(cgrp_dfl_visible))
 			continue;
 
 		seq_printf(m, "%d:", root->hierarchy_id);


-- 
tejun

  reply	other threads:[~2022-08-28 18:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAEHB249jcoG=sMGLUgqw3Yf+SjZ7ZkUfF_M+WcyQGCAe77o2kA@mail.gmail.com>
2022-08-19  7:22 ` data-race in cgroup_get_tree / proc_cgroup_show Christian Brauner
2022-08-22 17:04   ` Gabriel Ryan
2022-08-28 18:22     ` Tejun Heo [this message]
2022-08-29  7:27       ` Christian Brauner
2022-09-04 19:23         ` [PATCH cgroup/for-6.1] cgroup: Remove data-race around cgrp_dfl_visible Tejun Heo

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=YwuySgH4j6h2CGvk@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=abhishek.shah@columbia.edu \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gabe@cs.columbia.edu \
    --cc=hannes@cmpxchg.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.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