[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YhisWkgZCK8dz5fl@alley>
Date: Fri, 25 Feb 2022 11:15:54 +0100
From: Petr Mladek <pmladek@...e.com>
To: Christophe Leroy <christophe.leroy@...roup.eu>
Cc: Aaron Tomlin <atomlin@...hat.com>,
"mcgrof@...nel.org" <mcgrof@...nel.org>,
"cl@...ux.com" <cl@...ux.com>, "mbenes@...e.cz" <mbenes@...e.cz>,
"akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
"jeyu@...nel.org" <jeyu@...nel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-modules@...r.kernel.org" <linux-modules@...r.kernel.org>,
"void@...ifault.com" <void@...ifault.com>,
"atomlin@...mlin.com" <atomlin@...mlin.com>,
"allen.lkml@...il.com" <allen.lkml@...il.com>,
"joe@...ches.com" <joe@...ches.com>,
"msuchanek@...e.de" <msuchanek@...e.de>,
"oleksandr@...alenko.name" <oleksandr@...alenko.name>
Subject: Re: [PATCH v8 09/13] module: Move kallsyms support into a separate
file
On Fri 2022-02-25 09:27:33, Christophe Leroy wrote:
>
>
> Le 25/02/2022 à 10:15, Petr Mladek a écrit :
> > On Tue 2022-02-22 14:12:59, Aaron Tomlin wrote:
> >> No functional change.
> >
> > The patch adds rcu_dereference_sched() into several locations.
> > It triggers lockdep warnings, see below.
> >
> > It is good example why avoid any hidden changes when shuffling
> > code. The changes in the code should be done in a preparatory
> > patch or not at all.
> >
> > This patch is even worse because these changes were not
> > mentioned in the commit message. It should describe what
> > is done and why.
> >
> > I wonder how many other changes are hidden in this patchset
> > and if anyone really checked them.
>
> That's probably my fault, when I reviewed version v5 of the series I
> mentionned all checkpatch and sparse reports asking Aaron to make his
> series exempt of such warnings. Most warnings where related to style
> (parenthesis alignment, blank lines, spaces, etc ...) or erroneous
> casting etc....
>
> But for that particular patch we had:
>
> kernel/module/kallsyms.c:174:23: warning: incorrect type in assignment
> (different address spaces)
> kernel/module/kallsyms.c:174:23: expected struct mod_kallsyms
> [noderef] __rcu *kallsyms
> kernel/module/kallsyms.c:174:23: got void *
> kernel/module/kallsyms.c:176:12: warning: dereference of noderef expression
> kernel/module/kallsyms.c:177:12: warning: dereference of noderef expression
> kernel/module/kallsyms.c:179:12: warning: dereference of noderef expression
> kernel/module/kallsyms.c:180:12: warning: dereference of noderef expression
> kernel/module/kallsyms.c:189:18: warning: dereference of noderef expression
> kernel/module/kallsyms.c:190:35: warning: dereference of noderef expression
> kernel/module/kallsyms.c:191:20: warning: dereference of noderef expression
> kernel/module/kallsyms.c:196:32: warning: dereference of noderef expression
> kernel/module/kallsyms.c:199:45: warning: dereference of noderef expression
>
> Aaron used rcu_dereference_sched() in order to fix that.
>
> How should this be fixed if using rcu_dereference_sched() is not correct ?
IMHO, sparse complains that _rcu pointer is not accessed using RCU
API.
rcu_dereference_sched() makes sparse happy. But lockdep complains
because the _rcu pointer is not accessed under:
rcu_read_lock_sched();
rcu_read_unlock_sched();
This is not the case here. Note that module_mutex does not
disable preemtion.
Now, the code is safe. The RCU access makes sure that "mod"
can't be freed in the meantime:
+ add_kallsyms() is called by the module loaded when the module
is being loaded. It could not get removed in parallel
by definition.
+ module_kallsyms_on_each_symbol() takes module_mutex.
It means that the module could not get removed.
IMHO, we have two possibilities here:
+ Make sparse and lockdep happy by using rcu_dereference_sched()
and calling the code under rcu_read_lock_sched().
+ Cast (struct mod_kallsyms *)mod->kallsyms when accessing
the value.
I do not have strong preference. I am fine with both.
Anyway, such a fix should be done in a separate patch!
Best Regards,
Petr
Powered by blists - more mailing lists