From: Cong Wang <xiyou.wangcong@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>, "# .39.x" <stable@kernel.org>,
Hugh Dickins <hughd@google.com>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH] mm: fix list corruptions on shmem shrinklist
Date: Fri, 4 Aug 2017 10:58:49 -0700 [thread overview]
Message-ID: <CAM_iQpU-BQZM2EyxBZ9_maT7WM2LH_Weu4sgBsy=oEZ+aabAbg@mail.gmail.com> (raw)
In-Reply-To: <20170803165307.172e2e1100b0170f6055894a@linux-foundation.org>
On Thu, Aug 3, 2017 at 4:53 PM, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Thu, 3 Aug 2017 16:25:46 -0700 Linus Torvalds <torvalds@linux-foundation.org> wrote:
>
>> On Thu, Aug 3, 2017 at 4:11 PM, Andrew Morton <akpm@linux-foundation.org> wrote:
>> >
>> > Where is this INIT_LIST_HEAD()?
>>
>> I think it's this one:
>>
>> list_del_init(&info->shrinklist);
>>
>> in shmem_unused_huge_shrink().
>
> OK.
>
>> > I'm not sure I'm understanding this. AFAICT all the list operations to
>> > which you refer are synchronized under spin_lock(&sbinfo->shrinklist_lock)?
>>
>> No, notice how shmem_unused_huge_shrink() does the
>>
>> list_move(&info->shrinklist, &to_remove);
>>
>> and
>>
>> list_move(&info->shrinklist, &list);
>>
>> to move to (two different) private lists under the shrinklist_lock,
>> but once it is on that private "list/to_remove" list, it is then
>> accessed outside the locked region.
>
> So the code is using sbinfo->shrinklist_lock to protect
> sbinfo->shrinklist AND to protect all the per-inode info->shrinklist's.
> Except it didn't get the coverage complete.
Normally once we move list entries from a global list to a private
one they are no longer visible to others, however in this case
they could still be accessed via setattr() path.
>
> Presumably it's too expensive to extend sbinfo->shrinklist_lock
> coverage in shmem_unused_huge_shrink() (or is it? - this is huge
> pages). An alternative would be to add a new
> shmem_inode_info.shrinklist_lock whose mandate is to protect
> shmem_inode_info.shrinklist.
Both find_lock_page() and iput() could sleep, I think this is why
we have to defer these two calls after releasing spinlock.
>
>> Honestly, I don't love this situation, or the patch, but I think the
>> patch is likely the right thing to do.
>
> Well, we could view the premature droppage of sbinfo->shrinklist_lock
> in shmem_unused_huge_shrink() to be a performance optimization and put
> some big fat comments in there explaining what's going on. But it's
> tricky and it's not known that such an optimization is warranted.
It is not for performance optimization, because we still traverse
the list with the spinlock held. A typical optimization is to use
a list_splice() with spinlock and traverse it without it, this is
used by a few places in networking subsystem.
Thanks.
--
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>
next prev parent reply other threads:[~2017-08-04 17:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 5:46 Cong Wang
2017-08-03 23:11 ` Andrew Morton
2017-08-03 23:25 ` Linus Torvalds
2017-08-03 23:53 ` Andrew Morton
2017-08-04 14:42 ` Kirill A. Shutemov
2017-08-04 17:58 ` Cong Wang [this message]
2017-08-04 18:06 ` Cong Wang
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='CAM_iQpU-BQZM2EyxBZ9_maT7WM2LH_Weu4sgBsy=oEZ+aabAbg@mail.gmail.com' \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
/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