[PATCH 10/16] x86/mm/pti: Populate valid user pud entries

From: Joerg Roedel
Date: Tue Jan 16 2018 - 11:55:41 EST


From: Joerg Roedel <jroedel@xxxxxxx>

With PAE paging we don't have PGD and P4D levels in the
page-table, instead the PUD level is the highest one.

In PAE page-tables at the top-level most bits we usually set
with _KERNPG_TABLE are reserved, resulting in a #GP when
they are loaded by the processor.

Work around this by populating PUD entries in the user
page-table only with _PAGE_PRESENT set.

I am pretty sure there is a cleaner way to do this, but
until I find it use this #ifdef solution.

Signed-off-by: Joerg Roedel <jroedel@xxxxxxx>
---
arch/x86/mm/pti.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 20be21301a59..6b6bfd13350e 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -202,8 +202,12 @@ static __init pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)
unsigned long new_pmd_page = __get_free_page(gfp);
if (!new_pmd_page)
return NULL;
-
+#ifdef CONFIG_X86_PAE
+ /* TODO: There must be a cleaner way to do this */
+ set_pud(pud, __pud(_PAGE_PRESENT | __pa(new_pmd_page)));
+#else
set_pud(pud, __pud(_KERNPG_TABLE | __pa(new_pmd_page)));
+#endif
}

return pmd_offset(pud, address);
--
2.13.6