linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org,
	syzbot+5b19bad23ac7f44bf8b8@syzkaller.appspotmail.com,
	Suren Baghdasaryan <surenb@google.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>
Subject: Re: [PATCH v2] mm: fix vma_start_write_killable() signal handling
Date: Wed, 26 Nov 2025 19:44:17 +0000	[thread overview]
Message-ID: <aSdYkYYAuATwYqbD@casper.infradead.org> (raw)
In-Reply-To: <d70b3309-348c-4aa9-9b62-33b8191955fe@lucifer.local>

On Wed, Nov 26, 2025 at 06:55:52PM +0000, Lorenzo Stoakes wrote:
> > It's only "impossible" currently due to some fairly esoteric reasoning.
> > As far as _this_ function is concerned, it's entirely possible.
> > I don't want to leave this trap for the next person who calls
> > __vma_enter_locked(TASK_KILLABLE).
> 
> Calls __vma_enter_locked(TASK_KILLABLE) _when detaching_, otherwise
> refcount will always be >0.
> 
> So we're only looking at us changing vma_mark_detached() to use
> TASK_KILLABLE.
> 
> As this is such a subtle corner case I still think it warrants a
> warning. Or at least a VM_WARN_ON_ONCE(1).
> 
> A killable detacher is, as Vlasta points out, kind of an unwise thing to do
> anyway right?

I missed where that was said?

> >
> > > > +			/*
> > > > +			 * We got a fatal signal, but the last reader went
> > > > +			 * away as well.  Resolve the race in favour of
> > >
> > > This is very subtle, I don't think this really explains this clearly
> > > enough.
> > >
> > > Maybe put something like:
> > >
> > > 	/* Couldn't wait on readers probably due to a fatal signal, so unlock. */
> > >
> > > Before the refcount_sub_and_test()
> >
> > I think this falls into the "saying what you're doing, not why
> > you're doing it" trap.  Whereas my comment is at a higher level --
> > there's a race where both exit conditions are true at the same time.
> > The rcuwait_wait_event() picked one option, but we would rather resolve
> > the race in the opposite direction.
> 
> I find your comment unclear, and I think it's too succinct. I was trying to
> provide the most succinct-yet-still-clear example, but if you prefer higher
> level you're going to need more detail here.
> 
> It assumes you 'just know' that:
> 
> - refcount_sub_and_test(VMA_LOCK_OFFSET, &vma->vm_refcnt) means unlock

Actually, I don't know that.  All I know is local to this function --
that's the value we added earlier before waiting; now we need to
subtract it since we're no longer waiting.

> - err can only be set due to a fatal signal in a non-uninterruptible task
>   mode

The comment says that in the first five words!

> - spurious readers can cause an incremented reference count

I don't know what a "spurious reader" is.  There was a reader when we
started waiting.  Now there isn't one.

> - that a race can exist between a spuriously raised reference count and the
>   previous reference count check between read above and refcount subtract here
> 
> - a reference count of 0 means detached
> 
> - err = 0 means we are treating this VMA as detached resolving this race
>   'in favour of' the VMA being detached.
> 
> Let's get some of this information in here please.

I don't think that here is the place to document these things!  And
certainly not in a patch that we're trying to get applied five days
before the merge window opens.  There's plenty of time to get the
comments and the variable names sorted out; can we focus on the right
way to fix this bug?

> Again I think we'd be better off with at least a VM_WARN_ON_ONCE() given
> this is a rather obscure corner case.

Are you satisfied with the WARN_ON(!detaching)?


  reply	other threads:[~2025-11-26 19:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-26 17:44 Matthew Wilcox (Oracle)
2025-11-26 18:06 ` Lorenzo Stoakes
2025-11-26 18:28   ` Matthew Wilcox
2025-11-26 18:43     ` Suren Baghdasaryan
2025-11-26 18:53       ` Vlastimil Babka
2025-11-26 19:34         ` Matthew Wilcox
2025-11-26 19:00       ` Lorenzo Stoakes
2025-11-26 18:55     ` Lorenzo Stoakes
2025-11-26 19:44       ` Matthew Wilcox [this message]
2025-11-26 20:33         ` Lorenzo Stoakes
2025-11-26 20:35           ` Lorenzo Stoakes
2025-11-26 22:09           ` Matthew Wilcox
2025-11-27  6:26             ` Lorenzo Stoakes
2025-11-27  9:05             ` Vlastimil Babka

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=aSdYkYYAuATwYqbD@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=surenb@google.com \
    --cc=syzbot+5b19bad23ac7f44bf8b8@syzkaller.appspotmail.com \
    --cc=vbabka@suse.cz \
    /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