Re: [PATCH] x86/mm: Fix pmd_modify() dropping the dirty bit

From: Dave Hansen

Date: Thu Sep 03 2026 - 11:43:32 EST


On 9/3/26 04:54, Kiryl Shutsemau wrote:
>> Closes: https://lore.kernel.org/r/CAJxLxMUGu1-L+O_nAONOwOXnS=cNbNApCWqdthRjd76LThtSPg@xxxxxxxxxxxxxx/
>> Fixes: bb3aadf7d446 ("x86/mm: Start actually marking _PAGE_SAVED_DIRTY")
> Hm. I don't understand why would this commit explicitly exclude
> _PAGE_DIRTY from the mask:
>
> - val &= _HPAGE_CHG_MASK;
> + val &= (_HPAGE_CHG_MASK & ~_PAGE_DIRTY);
>
> Rick, could you comment? It doesn't look like a typo.

My guess is that it's some remnant from an earlier version of the patch.
The asymmetry with pte_modify() vs. pmd_modify() just can't be explained
any other way. It _might_ have been some attempt to say, "Hey
_PAGE_DIRTY is now a part of the pgprot_t since it's part of the
'permissions' of a shadow stack PTE" that got abandoned.

But I don't see anything wrong with the fix at all.

It does give me pause that this has been losing user data for so long,
but it must just be a weird combination of features that few folks use
together (huge pages + MADV_FREE).