linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>, linux-mm@kvack.org
Cc: Oscar Salvador <osalvador@suse.de>
Subject: Re: [PATCH 0/5] Remove some races around folio_test_hugetlb
Date: Tue, 5 Mar 2024 10:10:08 +0100	[thread overview]
Message-ID: <d8c9e038-21fc-4611-a0f9-fc6748098b81@redhat.com> (raw)
In-Reply-To: <20240301214712.2853147-1-willy@infradead.org>

On 01.03.24 22:47, Matthew Wilcox (Oracle) wrote:
> Oscar and I have been exchanging a bit of email recently about the
> bug reported here:
> https://lore.kernel.org/all/ZXNhGsX32y19a2Xv@casper.infradead.org
> 
> I've come to the conclusion that folio_test_hugetlb() is just too fragile
> as it can give both false positives and false negatives, as well as
> resulting in the above bug.  With this patch series, it becomes a lot
> more robust.  In the memory-failure case, we always hold the hugetlb_lock
> so it's perfectly reliable.  In the compaction caase, it's unreliable, but
> the failures are acceptable and we recheck after taking the hugetlb_lock.
> 
> The cost of this reliability is that we now consume the word I recently
> freed in folio->page[1].  I think this is acceptable; we've still gained
> a completely reliable folio_test_hugetlb() (which we didn't have before
> I started messing around with the folio dtors).  Non-hugetlb users
> can use large_id as a pointer to something else entirely, or even as a
> non-pointer, as long as they can guarantee it can't conflict (ie don't
> use it as a bitfield).

That probably means that we have to always set the lowest bit to use it 
for something else, or use another bit.

I was wondering if

a) We could move that to another subpage. In hugetlb folios we have 
plenty of space for such things. I guess we'd have be able to detect the 
folio size without holding a reference, to make sure we can touch 
another subpage.

b) We could overload _nr_pages_mapped. We'd effectively have to steal 
one bit from _nr_pages_mapped to make this work.


Maybe what works is using the existing mechanism (hugetlb flag), and 
then storing the pointer in __nr_pages_mapped.

So depending on the hugetlb flag, we can interpret __nr_pages_mapped 
either as the pointer or as the old variant.

Mostly only folio_large_is_mapped() would need care for now, to ignore 
_nr_pages_mapped if the hugetlb flag is set.

-- 
Cheers,

David / dhildenb



  parent reply	other threads:[~2024-03-05  9:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 21:47 [PATCH 0/5] Remove some races around folio_test_hugetlb Matthew Wilcox (Oracle)
2024-03-01 21:47 ` [PATCH 1/5] hugetlb: Make folio_test_hugetlb safer to call Matthew Wilcox (Oracle)
2024-03-05  6:43   ` Oscar Salvador
2024-03-05  8:39   ` David Hildenbrand
2024-03-01 21:47 ` [PATCH 2/5] hugetlb: Add hugetlb_pfn_folio Matthew Wilcox (Oracle)
2024-03-05  6:58   ` Oscar Salvador
2024-03-01 21:47 ` [PATCH 3/5] memory-failure: Use hugetlb_pfn_folio Matthew Wilcox (Oracle)
2024-03-01 21:47 ` [PATCH 4/5] memory-failure: Reorganise get_huge_page_for_hwpoison() Matthew Wilcox (Oracle)
2024-03-01 21:47 ` [PATCH 5/5] compaction: Use hugetlb_pfn_folio in isolate_migratepages_block Matthew Wilcox (Oracle)
2024-03-04  9:09 ` [PATCH 0/5] Remove some races around folio_test_hugetlb Miaohe Lin
2024-03-04 17:08   ` Matthew Wilcox
2024-03-06  7:58     ` Miaohe Lin
2024-03-07 21:16       ` Matthew Wilcox
2024-03-05  9:10 ` David Hildenbrand [this message]
2024-03-05 20:35   ` Matthew Wilcox
2024-03-06 15:18     ` David Hildenbrand
2024-03-07  4:31       ` Matthew Wilcox
2024-03-07  9:20         ` David Hildenbrand
2024-03-07 21:14           ` Matthew Wilcox
2024-03-07 21:38             ` David Hildenbrand
2024-03-08  4:31             ` Matthew Wilcox
2024-03-08  8:46               ` David Hildenbrand

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=d8c9e038-21fc-4611-a0f9-fc6748098b81@redhat.com \
    --to=david@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=osalvador@suse.de \
    --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;
as well as URLs for NNTP newsgroup(s).