Skip to contentSkip to conversation

kaiser: allocate pgd with order 0 when pti=off

PATCH Applied Hugh Dickins 3 participants 4 messages Jan 30, 2018 – Feb 5, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kaiser: allocate pgd with order 0 when pti=off

The 4.9.77 version of "x86/pti/efi: broken conversion from efi to kernel page table" looked nicer than the 4.4.112 version, but was suboptimal on machines booted with "pti=off" (or on AMD machines): it allocated pgd with an order 1 page whatever the setting of kaiser_enabled.

Fix that by moving the definition of PGD_ALLOCATION_ORDER from asm/pgalloc.h to asm/pgtable.h, which already defines kaiser_enabled.

Fixes 1b92c48a2eeb ("x86/pti/efi: broken conversion from efi to kernel page table")
Cc Pavel Tatashin <[email protected]>
Cc Steven Sistare <[email protected]>
Cc Jiri Kosina <[email protected]>
---
 arch/x86/include/asm/pgalloc.h | 11 -----------
 arch/x86/include/asm/pgtable.h |  6 ++++++
 2 files changed, 6 insertions(+), 11 deletions(-)
arch/x86/include/asm/pgalloc.h +0 -11
index 1178a51b77f3..b6d425999f99 100644
@@ -27,17 +27,6 @@ static inline void paravirt_release_pud(unsigned long pfn) {}
  */
 extern gfp_t __userpte_alloc_gfp;
 
-#ifdef CONFIG_PAGE_TABLE_ISOLATION
-/*
- * Instead of one PGD, we acquire two PGDs.  Being order-1, it is
- * both 8k in size and 8k-aligned.  That lets us just flip bit 12
- * in a pointer to swap between the two 4k halves.
- */
-#define PGD_ALLOCATION_ORDER 1
-#else
-#define PGD_ALLOCATION_ORDER 0
-#endif
-
 /*
  * Allocate and free page tables.
  */
arch/x86/include/asm/pgtable.h +6 -0
index 2536f90cd30c..5af0401ccff2 100644
@@ -20,9 +20,15 @@
 
 #ifdef CONFIG_PAGE_TABLE_ISOLATION
 extern int kaiser_enabled;
+/*
+ * Instead of one PGD, we acquire two PGDs.  Being order-1, it is
+ * both 8k in size and 8k-aligned.  That lets us just flip bit 12
+ * in a pointer to swap between the two 4k halves.
+ */
 #else
 #define kaiser_enabled 0
 #endif
+#define PGD_ALLOCATION_ORDER kaiser_enabled
 
 void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd);
 void ptdump_walk_pgd_level_checkwx(void);
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
maintainer Applied
#1 lore raw

Patch "kaiser: allocate pgd with order 0 when pti=off" has been added to the 4.9-stable tree

This is a note to let you know that I've just added the patch titled

kaiser: allocate pgd with order 0 when pti=off

to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
kaiser-allocate-pgd-with-order-0-when-pti-off.patch
and it can be found in the queue-4.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Mon Feb 5 05:00:13 2018

From: Hugh Dickins <[email protected]>
Date: Mon, 29 Jan 2018 18:17:58 -0800
Subject: kaiser: allocate pgd with order 0 when pti=off
To: Greg Kroah-Hartman <[email protected]>
Cc: Hugh Dickins <[email protected]>, Pavel Tatashin <[email protected]>, Steven Sistare <[email protected]>, Jiri Kosina <[email protected]>, [email protected]
Message-ID: <[email protected]>

From: Hugh Dickins <[email protected]>

The 4.9.77 version of "x86/pti/efi: broken conversion from efi to kernel page table" looked nicer than the 4.4.112 version, but was suboptimal on machines booted with "pti=off" (or on AMD machines): it allocated pgd with an order 1 page whatever the setting of kaiser_enabled.

Fix that by moving the definition of PGD_ALLOCATION_ORDER from asm/pgalloc.h to asm/pgtable.h, which already defines kaiser_enabled.

Fixes 1b92c48a2eeb ("x86/pti/efi: broken conversion from efi to kernel page table")
Cc Pavel Tatashin <[email protected]>
Cc Steven Sistare <[email protected]>
Cc Jiri Kosina <[email protected]>
---
 arch/x86/include/asm/pgalloc.h |   11 -----------
 arch/x86/include/asm/pgtable.h |    6 ++++++
 2 files changed, 6 insertions(+), 11 deletions(-)
arch/x86/include/asm/pgalloc.h +0 -11
@@ -27,17 +27,6 @@ static inline void paravirt_release_pud(
  */
 extern gfp_t __userpte_alloc_gfp;
 
-#ifdef CONFIG_PAGE_TABLE_ISOLATION
-/*
- * Instead of one PGD, we acquire two PGDs.  Being order-1, it is
- * both 8k in size and 8k-aligned.  That lets us just flip bit 12
- * in a pointer to swap between the two 4k halves.
- */
-#define PGD_ALLOCATION_ORDER 1
-#else
-#define PGD_ALLOCATION_ORDER 0
-#endif
-
 /*
  * Allocate and free page tables.
  */
arch/x86/include/asm/pgtable.h +6 -0
@@ -20,9 +20,15 @@
 
 #ifdef CONFIG_PAGE_TABLE_ISOLATION
 extern int kaiser_enabled;
+/*
+ * Instead of one PGD, we acquire two PGDs.  Being order-1, it is
+ * both 8k in size and 8k-aligned.  That lets us just flip bit 12
+ * in a pointer to swap between the two 4k halves.
+ */
 #else
 #define kaiser_enabled 0
 #endif
+#define PGD_ALLOCATION_ORDER kaiser_enabled
 
 void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd);
 void ptdump_walk_pgd_level_checkwx(void);

Patches currently in stable-queue which might be from [email protected] are

queue-4.9/kaiser-allocate-pgd-with-order-0-when-pti-off.patch queue-4.9/x86-pti-make-unpoison-of-pgd-for-trusted-boot-work-for-real.patch queue-4.9/kaiser-fix-intel_bts-perf-crashes.patch

Reviewed-by on v1 1/1
#2 lore raw
In reply to Hugh Dickins
Quoted 62 lines · Hugh Dickins

The 4.9.77 version of "x86/pti/efi: broken conversion from efi to kernel page table" looked nicer than the 4.4.112 version, but was suboptimal on machines booted with "pti=off" (or on AMD machines): it allocated pgd with an order 1 page whatever the setting of kaiser_enabled.

Fix that by moving the definition of PGD_ALLOCATION_ORDER from asm/pgalloc.h to asm/pgtable.h, which already defines kaiser_enabled.

Fixes 1b92c48a2eeb ("x86/pti/efi: broken conversion from efi to kernel page table")
Cc Pavel Tatashin <[email protected]>
Cc Steven Sistare <[email protected]>
Cc Jiri Kosina <[email protected]>
---
  arch/x86/include/asm/pgalloc.h | 11 -----------
  arch/x86/include/asm/pgtable.h |  6 ++++++
  2 files changed, 6 insertions(+), 11 deletions(-)
arch/x86/include/asm/pgalloc.h +0 -11
index 1178a51b77f3..b6d425999f99 100644
@@ -27,17 +27,6 @@ static inline void paravirt_release_pud(unsigned long pfn) {}
   */
  extern gfp_t __userpte_alloc_gfp;
 
-#ifdef CONFIG_PAGE_TABLE_ISOLATION
-/*
- * Instead of one PGD, we acquire two PGDs.  Being order-1, it is
- * both 8k in size and 8k-aligned.  That lets us just flip bit 12
- * in a pointer to swap between the two 4k halves.
- */
-#define PGD_ALLOCATION_ORDER 1
-#else
-#define PGD_ALLOCATION_ORDER 0
-#endif
-
  /*
   * Allocate and free page tables.
   */
arch/x86/include/asm/pgtable.h +6 -0
index 2536f90cd30c..5af0401ccff2 100644
@@ -20,9 +20,15 @@
 
  #ifdef CONFIG_PAGE_TABLE_ISOLATION
  extern int kaiser_enabled;
+/*
+ * Instead of one PGD, we acquire two PGDs.  Being order-1, it is
+ * both 8k in size and 8k-aligned.  That lets us just flip bit 12
+ * in a pointer to swap between the two 4k halves.
+ */
  #else
  #define kaiser_enabled 0
  #endif
+#define PGD_ALLOCATION_ORDER kaiser_enabled
 
  void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd);
  void ptdump_walk_pgd_level_checkwx(void);