Skip to content

Commit 78185a9

Browse files
kirylgregkh
authored andcommitted
asm-generic: provide generic_pmdp_establish()
[ Upstream commit c58f0bb ] Patch series "Do not lose dirty bit on THP pages", v4. Vlastimil noted that pmdp_invalidate() is not atomic and we can lose dirty and access bits if CPU sets them after pmdp dereference, but before set_pmd_at(). The bug can lead to data loss, but the race window is tiny and I haven't seen any reports that suggested that it happens in reality. So I don't think it worth sending it to stable. Unfortunately, there's no way to address the issue in a generic way. We need to fix all architectures that support THP one-by-one. All architectures that have THP supported have to provide atomic pmdp_invalidate() that returns previous value. If generic implementation of pmdp_invalidate() is used, architecture needs to provide atomic pmdp_estabish(). pmdp_estabish() is not used out-side generic implementation of pmdp_invalidate() so far, but I think this can change in the future. This patch (of 12): This is an implementation of pmdp_establish() that is only suitable for an architecture that doesn't have hardware dirty/accessed bits. In this case we can't race with CPU which sets these bits and non-atomic approach is fine. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Kirill A. Shutemov <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: David Daney <[email protected]> Cc: David Miller <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Nitin Gupta <[email protected]> Cc: Ralf Baechle <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vineet Gupta <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 305e567 commit 78185a9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

include/asm-generic/pgtable.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,21 @@ extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
309309
extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
310310
#endif
311311

312+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
313+
/*
314+
* This is an implementation of pmdp_establish() that is only suitable for an
315+
* architecture that doesn't have hardware dirty/accessed bits. In this case we
316+
* can't race with CPU which sets these bits and non-atomic aproach is fine.
317+
*/
318+
static inline pmd_t generic_pmdp_establish(struct vm_area_struct *vma,
319+
unsigned long address, pmd_t *pmdp, pmd_t pmd)
320+
{
321+
pmd_t old_pmd = *pmdp;
322+
set_pmd_at(vma->vm_mm, address, pmdp, pmd);
323+
return old_pmd;
324+
}
325+
#endif
326+
312327
#ifndef __HAVE_ARCH_PMDP_INVALIDATE
313328
extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
314329
pmd_t *pmdp);

0 commit comments

Comments
 (0)