linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: ak <akaraliou.dev@gmail.com>
To: Michal Hocko <mhocko@kernel.org>
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:34:20 +0300	[thread overview]
Message-ID: <04b38213-5330-bf47-8865-eee7e18b8612@gmail.com> (raw)
In-Reply-To: <20171218084948.GK16951@dhcp22.suse.cz>

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.


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.
>> 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
>>

--
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>

  reply	other threads:[~2017-12-18 18:34 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 [this message]
2017-12-18 20:46     ` Michal Hocko

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=04b38213-5330-bf47-8865-eee7e18b8612@gmail.com \
    --to=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=mhocko@kernel.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