]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - arch/x86/include/asm/pgtable_64.h
x86/mm: Replace compile-time checks for 5-level paging with runtime-time checks
[mirror_ubuntu-jammy-kernel.git] / arch / x86 / include / asm / pgtable_64.h
index 81462e9a34f6af49645a08f55c7d67e0144dbb77..81dda8d1d0bd266840be28e8946d05d574b7b54f 100644 (file)
@@ -217,29 +217,26 @@ static inline pgd_t pti_set_user_pgd(pgd_t *pgdp, pgd_t pgd)
 
 static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d)
 {
-#if defined(CONFIG_PAGE_TABLE_ISOLATION) && !defined(CONFIG_X86_5LEVEL)
-       p4dp->pgd = pti_set_user_pgd(&p4dp->pgd, p4d.pgd);
-#else
-       *p4dp = p4d;
-#endif
+       pgd_t pgd;
+
+       if (pgtable_l5_enabled || !IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION)) {
+               *p4dp = p4d;
+               return;
+       }
+
+       pgd = native_make_pgd(p4d_val(p4d));
+       pgd = pti_set_user_pgd((pgd_t *)p4dp, pgd);
+       *p4dp = native_make_p4d(pgd_val(pgd));
 }
 
 static inline void native_p4d_clear(p4d_t *p4d)
 {
-#ifdef CONFIG_X86_5LEVEL
        native_set_p4d(p4d, native_make_p4d(0));
-#else
-       native_set_p4d(p4d, (p4d_t) { .pgd = native_make_pgd(0)});
-#endif
 }
 
 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
 {
-#ifdef CONFIG_PAGE_TABLE_ISOLATION
        *pgdp = pti_set_user_pgd(pgdp, pgd);
-#else
-       *pgdp = pgd;
-#endif
 }
 
 static inline void native_pgd_clear(pgd_t *pgd)