linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Gavin Guo <gavinguo@igalia.com>
To: Hugh Dickins <hughd@google.com>, Oscar Salvador <osalvador@suse.de>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	muchun.song@linux.dev, akpm@linux-foundation.org,
	kernel-dev@igalia.com, stable@vger.kernel.org,
	Florent Revest <revest@google.com>, Gavin Shan <gshan@redhat.com>
Subject: Re: [PATCH v2] mm/hugetlb: fix a deadlock with pagecache_folio and hugetlb_fault_mutex_table
Date: Thu, 22 May 2025 14:06:29 +0800	[thread overview]
Message-ID: <64ca8b7f-2b1f-40e8-b314-d59a3094d99f@igalia.com> (raw)
In-Reply-To: <54bd3d6c-d763-ae09-6ee2-7ef192a97ca9@google.com>

On 5/21/25 23:58, Hugh Dickins wrote:
> On Wed, 21 May 2025, Oscar Salvador wrote:
>> On Wed, May 21, 2025 at 08:10:46AM -0700, Hugh Dickins wrote:
>>> Unless you have a very strong argument why this folio is invisible to
>>> the rest of the world, including speculative accessors like compaction
>>> (and the name "pagecache_folio" suggests very much the reverse): the
>>> pattern of unlocking a lock when you see it locked is like (or worse
>>> than) having no locking at all - it is potentially unlocking someone
>>> else's lock.
>>
>> hugetlb_fault() locks 'pagecache_folio' and unlocks it after returning
>> from hugetlb_wp().
>> This patch introduces the possibility that hugetlb_wp() can also unlock it for
>> the reasons explained.
>> So, when hugetlb_wp() returns back to hugetlb_fault(), we
>>
>> 1) either still hold the lock (because hugetlb_fault() took it)
>> 2) or we do not anymore because hugetlb_wp() unlocked it for us.
>>
>> So it is not that we are unlocking anything blindly, because if the lock
>> is still 'taken' (folio_test_locked() returned true) it is because we,
>> hugetlb_fault() took it and we are still holding it.
> 
> If we unlocked it, anyone else could have taken it immediately after.
> 
> Hugh
> _______________________________________________
> Kernel-dev mailing list -- kernel-dev@igalia.com
> To unsubscribe send an email to kernel-dev-leave@igalia.com

Sigh, I should have thought of that as well. Next time, I'll be more 
careful.


      parent reply	other threads:[~2025-05-22  6:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-21 11:57 Gavin Guo
2025-05-21 13:33 ` Oscar Salvador
2025-05-21 15:10 ` Hugh Dickins
2025-05-21 15:53   ` Oscar Salvador
2025-05-21 15:58     ` Hugh Dickins
2025-05-21 19:44       ` Oscar Salvador
2025-05-22  6:06       ` Gavin Guo [this message]

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=64ca8b7f-2b1f-40e8-b314-d59a3094d99f@igalia.com \
    --to=gavinguo@igalia.com \
    --cc=akpm@linux-foundation.org \
    --cc=gshan@redhat.com \
    --cc=hughd@google.com \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=revest@google.com \
    --cc=stable@vger.kernel.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