* [PATCH 1/2] cgroup: cgroup_subsys[ssid] is never NULL
@ 2021-11-27 14:59 Wei Yang
2021-11-27 14:59 ` [PATCH 2/2] cgroup: get the wrong css for css_alloc() during cgroup_init_subsys() Wei Yang
[not found] ` <20211127145919.31159-1-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 2 replies; 5+ messages in thread
From: Wei Yang @ 2021-11-27 14:59 UTC (permalink / raw)
To: tj-DgEjT+Ai2ygdnm+yROfE0A, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
hannes-druUgvl0LCNAfugRpC6u6w
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Wei Yang
When the check, (ssid) < CGROUP_SUBSYS_COUNT, passed, it means
cgroup_subsys[ssid] is defined to its proper value. It is not
necessary to use a true to enter the loop.
Signed-off-by: Wei Yang <richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
kernel/cgroup/cgroup-internal.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h
index bfbeabc17a9d..0c5d1df6cdef 100644
--- a/kernel/cgroup/cgroup-internal.h
+++ b/kernel/cgroup/cgroup-internal.h
@@ -163,7 +163,7 @@ extern struct file_system_type cgroup_fs_type;
*/
#define for_each_subsys(ss, ssid) \
for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT && \
- (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
+ ((ss) = cgroup_subsys[ssid]); (ssid)++)
static inline bool cgroup_is_dead(const struct cgroup *cgrp)
{
--
2.33.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] cgroup: get the wrong css for css_alloc() during cgroup_init_subsys()
2021-11-27 14:59 [PATCH 1/2] cgroup: cgroup_subsys[ssid] is never NULL Wei Yang
@ 2021-11-27 14:59 ` Wei Yang
[not found] ` <20211127145919.31159-2-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
[not found] ` <20211127145919.31159-1-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
1 sibling, 1 reply; 5+ messages in thread
From: Wei Yang @ 2021-11-27 14:59 UTC (permalink / raw)
To: tj, lizefan.x, hannes; +Cc: cgroups, linux-kernel, Wei Yang
css_alloc() needs the parent css, while cgroup_css() gets current
cgropu's css. So we are getting the wrong css during
cgroup_init_subsys().
Fortunately, cgrp_dfl_root.cgrp's css is not set yet, so the value we
pass to css_alloc() doesn't harm to the system.
Let's pass NULL directly during init, since we know there is no parent
yet.
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
kernel/cgroup/cgroup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index dffef5836ff7..452a723d4a36 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5709,7 +5709,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early)
/* Create the root cgroup state for this subsystem */
ss->root = &cgrp_dfl_root;
- css = ss->css_alloc(cgroup_css(&cgrp_dfl_root.cgrp, ss));
+ css = ss->css_alloc(NULL);
/* We don't handle early failures gracefully */
BUG_ON(IS_ERR(css));
init_and_link_css(css, ss, &cgrp_dfl_root.cgrp);
--
2.33.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] cgroup: cgroup_subsys[ssid] is never NULL
[not found] ` <20211127145919.31159-1-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2021-11-29 17:35 ` Tejun Heo
[not found] ` <YaUPej4QUZoFAuOM-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2021-11-29 17:35 UTC (permalink / raw)
To: Wei Yang
Cc: lizefan.x-EC8Uxl6Npydl57MIdRCFDg, hannes-druUgvl0LCNAfugRpC6u6w,
cgroups-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Sat, Nov 27, 2021 at 02:59:18PM +0000, Wei Yang wrote:
> When the check, (ssid) < CGROUP_SUBSYS_COUNT, passed, it means
> cgroup_subsys[ssid] is defined to its proper value. It is not
> necessary to use a true to enter the loop.
...
> #define for_each_subsys(ss, ssid) \
> for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT && \
> - (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
> + ((ss) = cgroup_subsys[ssid]); (ssid)++)
So, now the compiler has to test whether ss is NULL or not before each
iteration even though we know that it's never NULL. The whole point of that
"|| true" is telling the compiler that the pointer is never NULL.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] cgroup: get the wrong css for css_alloc() during cgroup_init_subsys()
[not found] ` <20211127145919.31159-2-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2021-11-29 17:39 ` Tejun Heo
0 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2021-11-29 17:39 UTC (permalink / raw)
To: Wei Yang
Cc: lizefan.x-EC8Uxl6Npydl57MIdRCFDg, hannes-druUgvl0LCNAfugRpC6u6w,
cgroups-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Sat, Nov 27, 2021 at 02:59:19PM +0000, Wei Yang wrote:
> css_alloc() needs the parent css, while cgroup_css() gets current
> cgropu's css. So we are getting the wrong css during
> cgroup_init_subsys().
>
> Fortunately, cgrp_dfl_root.cgrp's css is not set yet, so the value we
> pass to css_alloc() doesn't harm to the system.
>
> Let's pass NULL directly during init, since we know there is no parent
> yet.
>
> Signed-off-by: Wei Yang <richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Applied to cgroup/for-5.17 w/ minor description adjustment.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] cgroup: cgroup_subsys[ssid] is never NULL
[not found] ` <YaUPej4QUZoFAuOM-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
@ 2021-11-30 0:33 ` Wei Yang
0 siblings, 0 replies; 5+ messages in thread
From: Wei Yang @ 2021-11-30 0:33 UTC (permalink / raw)
To: Tejun Heo
Cc: Wei Yang, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
hannes-druUgvl0LCNAfugRpC6u6w, cgroups-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Mon, Nov 29, 2021 at 07:35:54AM -1000, Tejun Heo wrote:
>On Sat, Nov 27, 2021 at 02:59:18PM +0000, Wei Yang wrote:
>> When the check, (ssid) < CGROUP_SUBSYS_COUNT, passed, it means
>> cgroup_subsys[ssid] is defined to its proper value. It is not
>> necessary to use a true to enter the loop.
>...
>> #define for_each_subsys(ss, ssid) \
>> for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT && \
>> - (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
>> + ((ss) = cgroup_subsys[ssid]); (ssid)++)
>
>So, now the compiler has to test whether ss is NULL or not before each
>iteration even though we know that it's never NULL. The whole point of that
>"|| true" is telling the compiler that the pointer is never NULL.
>
That's interesting. Thanks.
>Thanks.
>
>--
>tejun
--
Wei Yang
Help you, Help me
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-30 0:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-27 14:59 [PATCH 1/2] cgroup: cgroup_subsys[ssid] is never NULL Wei Yang
2021-11-27 14:59 ` [PATCH 2/2] cgroup: get the wrong css for css_alloc() during cgroup_init_subsys() Wei Yang
[not found] ` <20211127145919.31159-2-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-11-29 17:39 ` Tejun Heo
[not found] ` <20211127145919.31159-1-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-11-29 17:35 ` [PATCH 1/2] cgroup: cgroup_subsys[ssid] is never NULL Tejun Heo
[not found] ` <YaUPej4QUZoFAuOM-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2021-11-30 0:33 ` Wei Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox