Skip to content

Commit 505a60e

Browse files
kiryltorvalds
authored andcommitted
asm-generic: introduce 5level-fixup.h
We are going to switch core MM to 5-level paging abstraction. This is preparation step which adds <asm-generic/5level-fixup.h> As with 4level-fixup.h, the new header allows quickly make all architectures compatible with 5-level paging in core MM. In long run we would like to switch architectures to properly folded p4d level by using <asm-generic/pgtable-nop4d.h>, but it requires more changes to arch-specific code. Signed-off-by: Kirill A. Shutemov <[email protected]> Acked-by: Michal Hocko <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6fb8956 commit 505a60e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

include/asm-generic/4level-fixup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
1616
NULL: pmd_offset(pud, address))
1717

18-
#define pud_alloc(mm, pgd, address) (pgd)
1918
#define pud_offset(pgd, start) (pgd)
2019
#define pud_none(pud) 0
2120
#define pud_bad(pud) 0
@@ -35,4 +34,6 @@
3534
#undef pud_addr_end
3635
#define pud_addr_end(addr, end) (end)
3736

37+
#include <asm-generic/5level-fixup.h>
38+
3839
#endif

include/asm-generic/5level-fixup.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef _5LEVEL_FIXUP_H
2+
#define _5LEVEL_FIXUP_H
3+
4+
#define __ARCH_HAS_5LEVEL_HACK
5+
#define __PAGETABLE_P4D_FOLDED
6+
7+
#define P4D_SHIFT PGDIR_SHIFT
8+
#define P4D_SIZE PGDIR_SIZE
9+
#define P4D_MASK PGDIR_MASK
10+
#define PTRS_PER_P4D 1
11+
12+
#define p4d_t pgd_t
13+
14+
#define pud_alloc(mm, p4d, address) \
15+
((unlikely(pgd_none(*(p4d))) && __pud_alloc(mm, p4d, address)) ? \
16+
NULL : pud_offset(p4d, address))
17+
18+
#define p4d_alloc(mm, pgd, address) (pgd)
19+
#define p4d_offset(pgd, start) (pgd)
20+
#define p4d_none(p4d) 0
21+
#define p4d_bad(p4d) 0
22+
#define p4d_present(p4d) 1
23+
#define p4d_ERROR(p4d) do { } while (0)
24+
#define p4d_clear(p4d) pgd_clear(p4d)
25+
#define p4d_val(p4d) pgd_val(p4d)
26+
#define p4d_populate(mm, p4d, pud) pgd_populate(mm, p4d, pud)
27+
#define p4d_page(p4d) pgd_page(p4d)
28+
#define p4d_page_vaddr(p4d) pgd_page_vaddr(p4d)
29+
30+
#define __p4d(x) __pgd(x)
31+
#define set_p4d(p4dp, p4d) set_pgd(p4dp, p4d)
32+
33+
#undef p4d_free_tlb
34+
#define p4d_free_tlb(tlb, x, addr) do { } while (0)
35+
#define p4d_free(mm, x) do { } while (0)
36+
#define __p4d_free_tlb(tlb, x, addr) do { } while (0)
37+
38+
#undef p4d_addr_end
39+
#define p4d_addr_end(addr, end) (end)
40+
41+
#endif

include/linux/mm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,11 +1619,14 @@ int __pte_alloc_kernel(pmd_t *pmd, unsigned long address);
16191619
* Remove it when 4level-fixup.h has been removed.
16201620
*/
16211621
#if defined(CONFIG_MMU) && !defined(__ARCH_HAS_4LEVEL_HACK)
1622+
1623+
#ifndef __ARCH_HAS_5LEVEL_HACK
16221624
static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
16231625
{
16241626
return (unlikely(pgd_none(*pgd)) && __pud_alloc(mm, pgd, address))?
16251627
NULL: pud_offset(pgd, address);
16261628
}
1629+
#endif /* !__ARCH_HAS_5LEVEL_HACK */
16271630

16281631
static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
16291632
{

0 commit comments

Comments
 (0)