All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Muchun Song <songmuchun@bytedance.com>
Cc: yanghui <yanghui.def@bytedance.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linux Memory Management List <linux-mm@kvack.org>
Subject: Re: [PATCH] mm/mempolicy: fix a race between offset_il_node and mpol_rebind_task
Date: Sat, 14 Aug 2021 04:11:54 +0100	[thread overview]
Message-ID: <YRc0ev6dO3KDTYjZ@casper.infradead.org> (raw)
In-Reply-To: <CAMZfGtXi3k_nFoLo+2LJCd2zJCr+326qDOAsAz610jpaKMqO9w@mail.gmail.com>

On Sat, Aug 14, 2021 at 10:37:23AM +0800, Muchun Song wrote:
> On Sat, Aug 14, 2021 at 12:58 AM Matthew Wilcox <willy@infradead.org> wrote:
> >
> > On Sat, Aug 14, 2021 at 12:40:53AM +0800, yanghui wrote:
> > > +++ b/mm/mempolicy.c
> > > @@ -193,7 +193,7 @@ static int mpol_new_interleave(struct mempolicy *pol, const nodemask_t *nodes)
> > >  {
> > >       if (nodes_empty(*nodes))
> > >               return -EINVAL;
> > > -     pol->nodes = *nodes;
> > > +     WRITE_ONCE(pol->nodes, *nodes);
> >
> > typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
> >
> > If MAX_NUMNODES is large enough, is WRITE_ONCE going to work?  It could
> > be 128 bits, and few architectures have an atomic 128-bit store
> > instruction.
> >
> 
> Hi Matthew,
> 
> In my memory, the WRITE_ONCE will become memcpy if
> the size is greater than sizeof(long). But I found that it didn't
> support the size over sizeof(long) nowadays. So you are
> right. It doesn't work when MAX_NUMNODES is large enough.
> 
> If we don't use WRITE_ONCE/READ_ONCE here, it seems
> like no problem. At least we can sure offset_il_node returns
> a valid node id. What is your opinion about this fix?

Yes, I think that's a reasonable fix.  Include a comment about how
copying pol->nodes to the stack might race with a change to pol->nodes,
but that doesn't matter as long as we don't look at pol->nodes later?


  reply	other threads:[~2021-08-14  3:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 16:40 [PATCH] mm/mempolicy: fix a race between offset_il_node and mpol_rebind_task yanghui
2021-08-13 16:57 ` Matthew Wilcox
2021-08-14  2:37   ` Muchun Song
2021-08-14  3:11     ` Matthew Wilcox [this message]
2021-08-13 23:16 ` kernel test robot
2021-08-13 23:16   ` kernel test robot
2021-08-14  1:35   ` Nathan Chancellor
2021-08-14  1:35     ` Nathan Chancellor
2021-08-14  1:40 ` kernel test robot
2021-08-14  1:40   ` kernel test robot

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=YRc0ev6dO3KDTYjZ@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=songmuchun@bytedance.com \
    --cc=yanghui.def@bytedance.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.