Linux Modules
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Aaron Tomlin <atomlin@redhat.com>,
	"mcgrof@kernel.org" <mcgrof@kernel.org>,
	"cl@linux.com" <cl@linux.com>, "mbenes@suse.cz" <mbenes@suse.cz>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"jeyu@kernel.org" <jeyu@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-modules@vger.kernel.org" <linux-modules@vger.kernel.org>,
	"void@manifault.com" <void@manifault.com>,
	"atomlin@atomlin.com" <atomlin@atomlin.com>,
	"allen.lkml@gmail.com" <allen.lkml@gmail.com>,
	"joe@perches.com" <joe@perches.com>,
	"msuchanek@suse.de" <msuchanek@suse.de>,
	"oleksandr@natalenko.name" <oleksandr@natalenko.name>
Subject: Re: [PATCH v8 09/13] module: Move kallsyms support into a separate file
Date: Fri, 25 Feb 2022 11:15:54 +0100	[thread overview]
Message-ID: <YhisWkgZCK8dz5fl@alley> (raw)
In-Reply-To: <f9449aa6-be9d-9021-66e7-fb0272909ee7@csgroup.eu>

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

  reply	other threads:[~2022-02-25 10:15 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22 14:12 [PATCH v8 00/13] module: core code clean up Aaron Tomlin
2022-02-22 14:12 ` [PATCH v8 01/13] module: Move all into module/ Aaron Tomlin
2022-02-22 17:58   ` Christophe Leroy
2022-02-22 20:00   ` Allen
2022-02-22 14:12 ` [PATCH v8 02/13] module: Simple refactor in preparation for split Aaron Tomlin
2022-02-22 17:58   ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 03/13] module: Make internal.h and decompress.c more compliant Aaron Tomlin
2022-02-22 14:12 ` [PATCH v8 04/13] module: Move livepatch support to a separate file Aaron Tomlin
2022-02-22 17:58   ` Christophe Leroy
2022-02-25  9:34   ` Petr Mladek
2022-02-25 10:33     ` Aaron Tomlin
2022-02-25 16:49     ` Christophe Leroy
2022-02-28 10:56       ` Petr Mladek
2022-02-28 11:46         ` Christophe Leroy
2022-02-28 13:05           ` Petr Mladek
2022-02-22 14:12 ` [PATCH v8 05/13] module: Move latched RB-tree " Aaron Tomlin
2022-02-22 17:58   ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 06/13] module: Move strict rwx " Aaron Tomlin
2022-02-22 17:59   ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 07/13] module: Move extra signature support out of core code Aaron Tomlin
2022-02-22 17:59   ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 08/13] module: Move kmemleak support to a separate file Aaron Tomlin
2022-02-22 17:59   ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 09/13] module: Move kallsyms support into " Aaron Tomlin
2022-02-22 17:59   ` Christophe Leroy
2022-02-25  9:15   ` Petr Mladek
2022-02-25  9:27     ` Christophe Leroy
2022-02-25 10:15       ` Petr Mladek [this message]
2022-02-25 10:27         ` Aaron Tomlin
2022-02-25 12:21           ` Aaron Tomlin
2022-02-25 12:57             ` Christophe Leroy
2022-02-26 20:27               ` Luis Chamberlain
2022-02-28  9:02                 ` Christophe Leroy
2022-02-28  9:31                   ` Aaron Tomlin
2022-02-28  9:33                     ` Christophe Leroy
2022-02-22 14:13 ` [PATCH v8 10/13] module: Move procfs " Aaron Tomlin
2022-02-22 17:59   ` Christophe Leroy
2022-02-22 14:13 ` [PATCH v8 11/13] module: Move sysfs " Aaron Tomlin
2022-02-22 17:59   ` Christophe Leroy
2022-02-22 14:13 ` [PATCH v8 12/13] module: Move kdb_modules list out of core code Aaron Tomlin
2022-02-22 18:05   ` Christophe Leroy
2022-02-22 14:13 ` [PATCH v8 13/13] module: Move version support into a separate file Aaron Tomlin
2022-02-22 18:06   ` Christophe Leroy

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=YhisWkgZCK8dz5fl@alley \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=allen.lkml@gmail.com \
    --cc=atomlin@atomlin.com \
    --cc=atomlin@redhat.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=cl@linux.com \
    --cc=jeyu@kernel.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mcgrof@kernel.org \
    --cc=msuchanek@suse.de \
    --cc=oleksandr@natalenko.name \
    --cc=void@manifault.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