Skip to content

Commit ea3b5e6

Browse files
kirylIngo Molnar
authored and
Ingo Molnar
committed
x86/mm/ident_map: Add 5-level paging support
Add additional page table level handing. It's mostly mechanical. The only quirk is that with p4d folded, 'pgd' is equal to 'p4d' in kernel_ident_mapping_init(). The pgd entry has to point to the pud page table in this case. Signed-off-by: Kirill A. Shutemov <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0318e5a commit ea3b5e6

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

arch/x86/mm/ident_map.c

+44-7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,34 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
4545
return 0;
4646
}
4747

48+
static int ident_p4d_init(struct x86_mapping_info *info, p4d_t *p4d_page,
49+
unsigned long addr, unsigned long end)
50+
{
51+
unsigned long next;
52+
53+
for (; addr < end; addr = next) {
54+
p4d_t *p4d = p4d_page + p4d_index(addr);
55+
pud_t *pud;
56+
57+
next = (addr & P4D_MASK) + P4D_SIZE;
58+
if (next > end)
59+
next = end;
60+
61+
if (p4d_present(*p4d)) {
62+
pud = pud_offset(p4d, 0);
63+
ident_pud_init(info, pud, addr, next);
64+
continue;
65+
}
66+
pud = (pud_t *)info->alloc_pgt_page(info->context);
67+
if (!pud)
68+
return -ENOMEM;
69+
ident_pud_init(info, pud, addr, next);
70+
set_p4d(p4d, __p4d(__pa(pud) | _KERNPG_TABLE));
71+
}
72+
73+
return 0;
74+
}
75+
4876
int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,
4977
unsigned long pstart, unsigned long pend)
5078
{
@@ -55,27 +83,36 @@ int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,
5583

5684
for (; addr < end; addr = next) {
5785
pgd_t *pgd = pgd_page + pgd_index(addr);
58-
pud_t *pud;
86+
p4d_t *p4d;
5987

6088
next = (addr & PGDIR_MASK) + PGDIR_SIZE;
6189
if (next > end)
6290
next = end;
6391

6492
if (pgd_present(*pgd)) {
65-
pud = pud_offset(pgd, 0);
66-
result = ident_pud_init(info, pud, addr, next);
93+
p4d = p4d_offset(pgd, 0);
94+
result = ident_p4d_init(info, p4d, addr, next);
6795
if (result)
6896
return result;
6997
continue;
7098
}
7199

72-
pud = (pud_t *)info->alloc_pgt_page(info->context);
73-
if (!pud)
100+
p4d = (p4d_t *)info->alloc_pgt_page(info->context);
101+
if (!p4d)
74102
return -ENOMEM;
75-
result = ident_pud_init(info, pud, addr, next);
103+
result = ident_p4d_init(info, p4d, addr, next);
76104
if (result)
77105
return result;
78-
set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE));
106+
if (IS_ENABLED(CONFIG_X86_5LEVEL)) {
107+
set_pgd(pgd, __pgd(__pa(p4d) | _KERNPG_TABLE));
108+
} else {
109+
/*
110+
* With p4d folded, pgd is equal to p4d.
111+
* The pgd entry has to point to the pud page table in this case.
112+
*/
113+
pud_t *pud = pud_offset(p4d, 0);
114+
set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE));
115+
}
79116
}
80117

81118
return 0;

0 commit comments

Comments
 (0)