From: Michal Hocko <mhocko@kernel.org>
To: ak <akaraliou.dev@gmail.com>
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org,
hillf.zj@alibaba-inc.com, minchan@kernel.org, linux-mm@kvack.org,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Subject: Re: [PATCH] mm: vmscan: make unregister_shrinker() safer
Date: Mon, 18 Dec 2017 21:46:10 +0100 [thread overview]
Message-ID: <20171218204610.GS16951@dhcp22.suse.cz> (raw)
In-Reply-To: <04b38213-5330-bf47-8865-eee7e18b8612@gmail.com>
On Mon 18-12-17 21:34:20, ak wrote:
> On 12/18/2017 11:49 AM, Michal Hocko wrote:
>
> > On Sat 16-12-17 22:29:37, Aliaksei Karaliou wrote:
> > > unregister_shrinker() does not have any sanitizing inside so
> > > calling it twice will oops because of double free attempt or so.
> > > This patch makes unregister_shrinker() safer and allows calling
> > > it on resource freeing path without explicit knowledge of whether
> > > shrinker was successfully registered or not.
> > Tetsuo has made it half way to this already [1]. So maybe we should
> > fold shrinker->nr_deferred = NULL to his patch and finally merge it.
> >
> > [1] http://lkml.kernel.org/r/1511523385-6433-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp
>
> Yeah, no problem from my side.
> I'm sorry, it seems that I haven't done enough research to realize
> that someone is already looking at that place.
Absolutely no reason to be worried. This happens all the time ;)
> The only my concern/question is whether we should also add some
> paranoid stuff in that extra branch (check that list is empty for
> example) or not.
I wouldn't bother. There are two reasons to actually care here: a) to
make registration code easier (so that they can call unregister_shrinker
even on path with failed register_shrinker - e.g. sget_userns would
become more complex if we had to special case the failure) and b) to not
blow up on the double unregister which is an alternative of a).
We really do not need this to be super clever, it is an internal
function.
> > > Signed-off-by: Aliaksei Karaliou <akaraliou.dev@gmail.com>
> > > ---
> > > mm/vmscan.c | 4 ++++
> > > 1 file changed, 4 insertions(+)
> > >
> > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > index 65c4fa26abfa..7cb56db5e9ca 100644
> > > --- a/mm/vmscan.c
> > > +++ b/mm/vmscan.c
> > > @@ -281,10 +281,14 @@ EXPORT_SYMBOL(register_shrinker);
> > > */
> > > void unregister_shrinker(struct shrinker *shrinker)
> > > {
> > > + if (!shrinker->nr_deferred)
> > > + return;
> > > +
> > > down_write(&shrinker_rwsem);
> > > list_del(&shrinker->list);
> > > up_write(&shrinker_rwsem);
> > > kfree(shrinker->nr_deferred);
> > > + shrinker->nr_deferred = NULL;
> > > }
> > > EXPORT_SYMBOL(unregister_shrinker);
> > > --
> > > 2.11.0
> > >
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2017-12-18 20:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-16 19:29 Aliaksei Karaliou
2017-12-18 8:49 ` Michal Hocko
2017-12-18 18:34 ` ak
2017-12-18 20:46 ` Michal Hocko [this message]
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=20171218204610.GS16951@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=akaraliou.dev@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=hillf.zj@alibaba-inc.com \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
/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