Skip to content

Commit 57fae93

Browse files
Dev Jainakpm00
authored andcommitted
mm: introduce FPB_RESPECT_WRITE for PTE batching infrastructure
Patch 6 ("mm: Optimize mprotect() by PTE batching") optimizes mprotect() by batch clearing the ptes, masking in the new protections, and batch setting the ptes. Suppose that the first pte of the batch is writable - with the current implementation of folio_pte_batch(), it is not guaranteed that the other ptes in the batch are already writable too, so we may incorrectly end up setting the writable bit on all ptes via modify_prot_commit_ptes(). Therefore, introduce FPB_RESPECT_WRITE so that all ptes in the batch are writable or not. Link: https://lkml.kernel.org/r/20250718090244.21092-5-dev.jain@arm.com Signed-off-by: Dev Jain <dev.jain@arm.com> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Ryan Roberts <ryan.roberts@arm.com> Reviewed-by: Zi Yan <ziy@nvidia.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Barry Song <baohua@kernel.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: David Hildenbrand <david@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Jann Horn <jannh@google.com> Cc: Joey Gouly <joey.gouly@arm.com> Cc: Kevin Brodsky <kevin.brodsky@arm.com> Cc: Lance Yang <ioworker0@gmail.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Peter Xu <peterx@redhat.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Will Deacon <will@kernel.org> Cc: Yang Shi <yang@os.amperecomputing.com> Cc: Yicong Yang <yangyicong@hisilicon.com> Cc: Zhenhua Huang <quic_zhenhuah@quicinc.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 0aa3657 commit 57fae93

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mm/internal.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,25 +208,30 @@ typedef int __bitwise fpb_t;
208208
/* Compare PTEs respecting the soft-dirty bit. */
209209
#define FPB_RESPECT_SOFT_DIRTY ((__force fpb_t)BIT(1))
210210

211+
/* Compare PTEs respecting the writable bit. */
212+
#define FPB_RESPECT_WRITE ((__force fpb_t)BIT(2))
213+
211214
/*
212215
* Merge PTE write bits: if any PTE in the batch is writable, modify the
213216
* PTE at @ptentp to be writable.
214217
*/
215-
#define FPB_MERGE_WRITE ((__force fpb_t)BIT(2))
218+
#define FPB_MERGE_WRITE ((__force fpb_t)BIT(3))
216219

217220
/*
218221
* Merge PTE young and dirty bits: if any PTE in the batch is young or dirty,
219222
* modify the PTE at @ptentp to be young or dirty, respectively.
220223
*/
221-
#define FPB_MERGE_YOUNG_DIRTY ((__force fpb_t)BIT(3))
224+
#define FPB_MERGE_YOUNG_DIRTY ((__force fpb_t)BIT(4))
222225

223226
static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
224227
{
225228
if (!(flags & FPB_RESPECT_DIRTY))
226229
pte = pte_mkclean(pte);
227230
if (likely(!(flags & FPB_RESPECT_SOFT_DIRTY)))
228231
pte = pte_clear_soft_dirty(pte);
229-
return pte_wrprotect(pte_mkold(pte));
232+
if (likely(!(flags & FPB_RESPECT_WRITE)))
233+
pte = pte_wrprotect(pte);
234+
return pte_mkold(pte);
230235
}
231236

232237
/**

0 commit comments

Comments
 (0)