linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Suren Baghdasaryan <surenb@google.com>,
	Matthew Wilcox <willy@infradead.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org,
	syzbot+5b19bad23ac7f44bf8b8@syzkaller.appspotmail.com,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>
Subject: Re: [PATCH v2] mm: fix vma_start_write_killable() signal handling
Date: Wed, 26 Nov 2025 19:53:13 +0100	[thread overview]
Message-ID: <ae18d781-86a3-4539-9441-079b7f45e726@suse.cz> (raw)
In-Reply-To: <CAJuCfpHheus2oiv94r14afjVV00XZnfqHY0p+H8fxjxCSYjg9g@mail.gmail.com>

On 11/26/25 7:43 PM, Suren Baghdasaryan wrote:
> On Wed, Nov 26, 2025 at 6:28 PM Matthew Wilcox <willy@infradead.org> wrote:
>>
>> On Wed, Nov 26, 2025 at 06:06:53PM +0000, Lorenzo Stoakes wrote:
>>> On Wed, Nov 26, 2025 at 05:44:58PM +0000, Matthew Wilcox (Oracle) wrote:
>>>> If we get a signal, we need to restore the vm_refcnt.  We don't think
>>>> that the refcount can actually be decremented to zero here as it
>>>> requires the VMA to be detached, and the vma_mark_detached() uses
>>>> TASK_UNINTERRUPTIBLE.  However, that's a bit subtle, so handle it
>>>> as if the refcount was zero at the start of this function.
>>>>
>>>> Reported-by: syzbot+5b19bad23ac7f44bf8b8@syzkaller.appspotmail.com

Closes: https://lore.kernel.org/all/69252076.a70a0220.d98e3.009b.GAE@google.com/

Unfortunately the reported-by code doesn't work as message id

>>>> Fixes: 2197bb60f890 ("mm: add vma_start_write_killable()")
>>>> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>>>> Cc: Suren Baghdasaryan <surenb@google.com>
>>>> Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
>>>> Cc: Vlastimil Babka <vbabka@suse.cz>
>>>> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> 
> Reviewed-by: Suren Baghdasaryan <surenb@google.com>
> 
>>>> ---
>>>>  mm/mmap_lock.c | 8 ++++++++
>>>>  1 file changed, 8 insertions(+)
>>>>
>>>> diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
>>>> index e6e5570d1ec7..3c9bf2f96280 100644
>>>> --- a/mm/mmap_lock.c
>>>> +++ b/mm/mmap_lock.c
>>>> @@ -74,6 +74,14 @@ static inline int __vma_enter_locked(struct vm_area_struct *vma,
>>>>                refcount_read(&vma->vm_refcnt) == tgt_refcnt,
>>>>                state);
>>>>     if (err) {
>>>> +           if (refcount_sub_and_test(VMA_LOCK_OFFSET, &vma->vm_refcnt)) {
>>>
>>> Really think we should WARN_ON_ONCE() as Vlasta suggested.

Thanks Lorenzo!

Can we at least add a "WARN_ON_ONCE(!detaching);" before "err = 0;".

>>> It's an 'impossible' situation so we should make that clear. And we should
>>> find out about it if the impossible happens... :)
>>
>> 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).
>>
>>>> +                   /*
>>>> +                    * 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.
>>
>>> And:
>>>
>>>       /* Shouldn't be possible - VMA entirely detached, so treat it as such. */
>>>
>>> Before err = 0?
>>
>> Again though, saying it's "not possible" relies on knowing all the
>> callers of this function behave a particular way, and there's no
>> guarantee they'll continue to do so.
> 
> I agree with Matthew. Returning 0 here would work correctly even if
> vma_mark_detached() starts using TASK_INTERRUPTIBLE and 0 becomes
> possible. The comment also seems appropriate to me.
> Thanks!
> 
>>



  reply	other threads:[~2025-11-26 18:52 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 [this message]
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
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=ae18d781-86a3-4539-9441-079b7f45e726@suse.cz \
    --to=vbabka@suse.cz \
    --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=willy@infradead.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