Re: [PATCH] mm/huge_memory: fix dereferencing invalid pmd migration entry

From: David Hildenbrand
Date: Thu Apr 17 2025 - 03:18:55 EST


On 17.04.25 07:36, Hugh Dickins wrote:
On Wed, 16 Apr 2025, David Hildenbrand wrote:

Why not something like

struct folio *entry_folio;

if (folio) {
if (is_pmd_migration_entry(*pmd))
entry_folio = pfn_swap_entry_folio(pmd_to_swp_entry(*pmd)));
else
entry_folio = pmd_folio(*pmd));

if (folio != entry_folio)
return;
}

My own preference is to not add unnecessary code:
if folio and pmd_migration entry, we're not interested in entry_folio.
But yes it could be written in lots of other ways.

While I don't disagree about "not adding unnecessary code" in general, in this particular case just looking the folio up properly might be the better alternative to reasoning about locking rules with conditional input parameters :)

--
Cheers,

David / dhildenb