Skip to contentSkip to conversation

EFI changes for v4.6 part 2

GIT PULL In review Matt Fleming 10 participants 54 messages Feb 17, 2016 – Mar 7, 2016

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

Folks, here are the remaining EFI changes for v4.6.

Two of the patches were sent in the previous v4.6 pull request on 1st February. Those include running EFI runtime services with interrupts enabled (just like Windows does) and aligning the EFI GUID formats in include/linux/efi.h to match the way they're written in the UEFI spec. They've both been reworked to address comments.

The rest of the changes are all over the tree, and range from simple fixes and cleanups to support for EFI_PROPERTIES_TABLE on x86.

The following changes since commit 35575e0e8ba633fc8276509a21f89b599b4f9006:

efi: Add Persistent Memory type name (2016-02-03 11:41:20 +0100)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git tags/efi-next

for you to fetch changes up to 83a901db98e790e5682b85b8ee85f9e545d84e27:

x86/efi: Only map kernel text for EFI mixed mode (2016-02-15 11:37:02 +0000)

----------------------------------------------------------------
* checkpatch.pl cleanup of the GUIDs in efi.h which has the added benefit of making them more closely resemble how they're presented in the UEFI specification - Peter Jones

* Now that we've verified that Windows works this way, leave interrupts enabled when invoking EFI runtime services which also reduces interrupt latencies - Ard Biesheuvel

* Reduce page table attribute inconsistencies between the EFI page tables and the standard kernel page tables by ensuring we also set _PAGE_GLOBAL in the EFI-specific paths - Sai Praneeth Prakhya

* A bunch of small fixes to the generic EFI stub and some early boot platform compatibility checks for ARM and arm64 - Ard Biesheuvel

* Add support for EFI_PROPERTIES_TABLE to x86, allowing us to apply more secure memory mapping permissions for firmware that ships with the feature enabled - Sai Praneeth Prakhya

* Fix an EFI mixed mode bug where we intend to only map the kernel image's text but end up mapping the entire image - Sai Praneeth Prakhya

----------------------------------------------------------------
Ard Biesheuvel (8):
efi/runtime-wrappers: Run UEFI Runtime Services with interrupts enabled efi/arm64: Drop __init annotation from handle_kernel_image()
arm64: vmlinux.lds.S: Handle .init.rodata.xxx and .init.bss sections efi/efistub: Prevent __init annotations from being used efi/arm-init: Use read-only early mappings
efi/arm: Check for LPAE support before booting a LPAE kernel efi/arm64: Check for h/w support before booting a >4 KB granule kernel efi/arm*: Perform hardware compatibility check

Peter Jones (1):
efi: Reformat GUID tables to follow the format in UEFI spec

Sai Praneeth (4):
x86/mm/pageattr: Use _PAGE_GLOBAL bit for EFI page table mappings x86/mm/pageattr: Don't implicitly allow _PAGE_RW in kernel_map_pages_in_pgd() x86/efi: Map EFI_MEMORY_{XP,RO} memory region bits to EFI page tables x86/efi: Only map kernel text for EFI mixed mode

 arch/arm64/kernel/vmlinux.lds.S           |  1 +
 arch/x86/include/asm/efi.h                |  2 +-
 arch/x86/mm/pageattr.c                    | 17 ++++++++
 arch/x86/platform/efi/efi.c               |  9 +++-
 arch/x86/platform/efi/efi_32.c            |  2 +-
 arch/x86/platform/efi/efi_64.c            | 55 ++++++++++++++++++++----
 drivers/firmware/efi/arm-init.c           | 14 +++---
 drivers/firmware/efi/libstub/arm-stub.c   |  4 ++
 drivers/firmware/efi/libstub/arm32-stub.c | 17 ++++++++
 drivers/firmware/efi/libstub/arm64-stub.c | 34 ++++++++++++---
 drivers/firmware/efi/libstub/efistub.h    | 12 ++++++
 drivers/firmware/efi/runtime-wrappers.c   | 71 ++++++++++++-------------------
 include/linux/efi.h                       | 63 ++++++++++++++++++---------
 13 files changed, 210 insertions(+), 91 deletions(-)
#1 lore raw

PATCH 1/13 efi: Reformat GUID tables to follow the format in UEFI spec

From: Peter Jones <[email protected]>

This makes it much easier to hunt for typos in the GUID definitions.

It also makes checkpatch complain less about efi.h GUID additions, so that if you add another one with the same style, checkpatch won't complain about it.

---
 include/linux/efi.h | 63 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 21 deletions(-)
include/linux/efi.h +42 -21
index 3c6cbbdae4aa..99b88c5a6770 100644
@@ -536,67 +536,88 @@ void efi_native_runtime_setup(void);
  *  EFI Configuration Table and GUID definitions
  */
 #define NULL_GUID \
-    EFI_GUID(  0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
+	EFI_GUID(0x00000000, 0x0000, 0x0000, \
+		 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
 
 #define MPS_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+	EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, \
+		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
 #define ACPI_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+	EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, \
+		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
 #define ACPI_20_TABLE_GUID    \
-    EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
+	EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, \
+		 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
 
 #define SMBIOS_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+	EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, \
+		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
 #define SMBIOS3_TABLE_GUID    \
-    EFI_GUID(  0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 )
+	EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, \
+		 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
 
 #define SAL_SYSTEM_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+	EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, \
+		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
 #define HCDP_TABLE_GUID	\
-    EFI_GUID(  0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 )
+	EFI_GUID(0xf951938d, 0x620b, 0x42ef, \
+		 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
 
 #define UGA_IO_PROTOCOL_GUID \
-    EFI_GUID(  0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0xb, 0x7, 0xa2 )
+	EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, \
+		 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
 
 #define EFI_GLOBAL_VARIABLE_GUID \
-    EFI_GUID(  0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c )
+	EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, \
+		 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
 
 #define UV_SYSTEM_TABLE_GUID \
-    EFI_GUID(  0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93 )
+	EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, \
+		 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
 
 #define LINUX_EFI_CRASH_GUID \
-    EFI_GUID(  0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0 )
+	EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, \
+		 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
 
 #define LOADED_IMAGE_PROTOCOL_GUID \
-    EFI_GUID(  0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+	EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \
+		 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
 
 #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
-    EFI_GUID(  0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a )
+	EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
+		 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
 
 #define EFI_UGA_PROTOCOL_GUID \
-    EFI_GUID(  0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 )
+	EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, \
+		 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
 
 #define EFI_PCI_IO_PROTOCOL_GUID \
-    EFI_GUID(  0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a )
+	EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, \
+		 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
 
 #define EFI_FILE_INFO_ID \
-    EFI_GUID(  0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+	EFI_GUID(0x9576e92, 0x6d3f, 0x11d2, \
+		 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
 
 #define EFI_SYSTEM_RESOURCE_TABLE_GUID \
-    EFI_GUID(  0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80 )
+	EFI_GUID(0xb122a263, 0x3661, 0x4f68, \
+		 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
 
 #define EFI_FILE_SYSTEM_GUID \
-    EFI_GUID(  0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+	EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \
+		 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
 
 #define DEVICE_TREE_GUID \
-    EFI_GUID(  0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 )
+	EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \
+		 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
 
 #define EFI_PROPERTIES_TABLE_GUID \
-    EFI_GUID(  0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5 )
+	EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, \
+		 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
 
 typedef struct {
 	efi_guid_t guid;
Signature · 1 line
2.6.2
#3 lore raw

PATCH 2/13 efi/runtime-wrappers: Run UEFI Runtime Services with interrupts enabled

In reply to Matt Fleming

From: Ard Biesheuvel <[email protected]>

The UEFI spec allows Runtime Services to be invoked with interrupts enabled. The only reason we were disabling interrupts was to prevent recursive calls into the services on the same CPU, which will lead to deadlock. However, the only context where such invocations may occur legally is from efi-pstore via efivars, and that code has been updated to call a non-blocking alternative when invoked from a non-interruptible context.

So instead, update the ordinary, blocking UEFI Runtime Services wrappers to execute with interrupts enabled. This aims to prevent excessive interrupt latencies on uniprocessor platforms with slow variable stores.

Note that other OSes such as Windows call UEFI Runtime Services with interrupts enabled as well.

Cc Andy Lutomirski <[email protected]>
Cc Linus Torvalds <torvalds-de/[email protected]>
Cc Sai Praneeth Prakhya <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 drivers/firmware/efi/runtime-wrappers.c | 71 +++++++++++++--------------------
 1 file changed, 28 insertions(+), 43 deletions(-)
drivers/firmware/efi/runtime-wrappers.c +28 -43
index 7b8b2f2702ca..de6953039af6 100644
@@ -63,23 +63,21 @@ static DEFINE_SPINLOCK(efi_runtime_lock);
 
 static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(get_time, tm, tc);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
 static efi_status_t virt_efi_set_time(efi_time_t *tm)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(set_time, tm);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -87,23 +85,21 @@ static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
 					     efi_bool_t *pending,
 					     efi_time_t *tm)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(get_wakeup_time, enabled, pending, tm);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
 static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(set_wakeup_time, enabled, tm);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -113,13 +109,12 @@ static efi_status_t virt_efi_get_variable(efi_char16_t *name,
 					  unsigned long *data_size,
 					  void *data)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(get_variable, name, vendor, attr, data_size,
 			       data);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -127,12 +122,11 @@ static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
 					       efi_char16_t *name,
 					       efi_guid_t *vendor)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(get_next_variable, name_size, name, vendor);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -142,13 +136,12 @@ static efi_status_t virt_efi_set_variable(efi_char16_t *name,
 					  unsigned long data_size,
 					  void *data)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(set_variable, name, vendor, attr, data_size,
 			       data);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -157,15 +150,14 @@ virt_efi_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
 				  u32 attr, unsigned long data_size,
 				  void *data)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	if (!spin_trylock_irqsave(&efi_runtime_lock, flags))
+	if (!spin_trylock(&efi_runtime_lock))
 		return EFI_NOT_READY;
 
 	status = efi_call_virt(set_variable, name, vendor, attr, data_size,
 			       data);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -175,16 +167,15 @@ static efi_status_t virt_efi_query_variable_info(u32 attr,
 						 u64 *remaining_space,
 						 u64 *max_variable_size)
 {
-	unsigned long flags;
 	efi_status_t status;
 
 	if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
 		return EFI_UNSUPPORTED;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(query_variable_info, attr, storage_space,
 			       remaining_space, max_variable_size);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -194,29 +185,27 @@ virt_efi_query_variable_info_nonblocking(u32 attr,
 					 u64 *remaining_space,
 					 u64 *max_variable_size)
 {
-	unsigned long flags;
 	efi_status_t status;
 
 	if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
 		return EFI_UNSUPPORTED;
 
-	if (!spin_trylock_irqsave(&efi_runtime_lock, flags))
+	if (!spin_trylock(&efi_runtime_lock))
 		return EFI_NOT_READY;
 
 	status = efi_call_virt(query_variable_info, attr, storage_space,
 			       remaining_space, max_variable_size);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
 static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
 {
-	unsigned long flags;
 	efi_status_t status;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(get_next_high_mono_count, count);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -225,26 +214,23 @@ static void virt_efi_reset_system(int reset_type,
 				  unsigned long data_size,
 				  efi_char16_t *data)
 {
-	unsigned long flags;
-
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	__efi_call_virt(reset_system, reset_type, status, data_size, data);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 }
 
 static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
 					    unsigned long count,
 					    unsigned long sg_list)
 {
-	unsigned long flags;
 	efi_status_t status;
 
 	if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
 		return EFI_UNSUPPORTED;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(update_capsule, capsules, count, sg_list);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
@@ -253,16 +239,15 @@ static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
 						u64 *max_size,
 						int *reset_type)
 {
-	unsigned long flags;
 	efi_status_t status;
 
 	if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
 		return EFI_UNSUPPORTED;
 
-	spin_lock_irqsave(&efi_runtime_lock, flags);
+	spin_lock(&efi_runtime_lock);
 	status = efi_call_virt(query_capsule_caps, capsules, count, max_size,
 			       reset_type);
-	spin_unlock_irqrestore(&efi_runtime_lock, flags);
+	spin_unlock(&efi_runtime_lock);
 	return status;
 }
 
Signature · 1 line
2.6.2
#5 lore raw

PATCH 3/13 x86/mm/pageattr: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Matt Fleming

From: Sai Praneeth <[email protected]>

Since EFI page tables can be treated as kernel page tables they should be global. All the other page mapping functions in pageattr.c set the _PAGE_GLOBAL bit and we want to avoid inconsistencies when we map a page in the EFI code paths, for example when that page is split in __split_large_page(), etc. It also makes it easier to validate that the EFI region mappings have the correct attributes because there are fewer differences compared with regular kernel mappings.

---
 arch/x86/mm/pageattr.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/x86/mm/pageattr.c +14 -0
index 632d34d20237..bf312da41a6d 100644
@@ -909,6 +909,20 @@ static void populate_pte(struct cpa_data *cpa,
 
 	pte = pte_offset_kernel(pmd, start);
 
+	/*
+	 * Set the GLOBAL flags only if the PRESENT flag is
+	 * set otherwise pte_present will return true even on
+	 * a non present pte. The canon_pgprot will clear
+	 * _PAGE_GLOBAL for the ancient hardware that doesn't
+	 * support it.
+	 */
+	if (pgprot_val(pgprot) & _PAGE_PRESENT)
+		pgprot_val(pgprot) |= _PAGE_GLOBAL;
+	else
+		pgprot_val(pgprot) &= ~_PAGE_GLOBAL;
+
+	pgprot = canon_pgprot(pgprot);
+
 	while (num_pages-- && start < end) {
 		set_pte(pte, pfn_pte(cpa->pfn, pgprot));
 
Signature · 1 line
2.6.2
#7 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

On Feb 23, 2016 1:09 AM, <&quot;tip-bot for Sai Praneeth &lt;[email protected]&gt;&quot;@zytor.com> wrote:

Something's wrong with tip-bot. This should say:

commit 397630150632639b3ca5b4414accd5011c45e276

Author: Sai Praneeth <[email protected]>
Date:   Wed Feb 17 12:35:56 2016 +0000

x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Since EFI page tables can be treated as kernel page tables they should be global. All the other page mapping functions in pageattr.c set the _PAGE_GLOBAL bit and we want to avoid inconsistencies when we map a page in the EFI code paths, for example when that page is split in __split_large_page(), etc. It also makes it easier to validate that the EFI region mappings have the correct attributes because there are fewer differences compared with regular kernel mappings.

But the actual patch is:

@@ -909,6 +909,20 @@ static void populate_pte(struct cpa_data *cpa,

        pte = pte_offset_kernel(pmd, start);

+ /*

+        * Set the GLOBAL flags only if the PRESENT flag is
+        * set otherwise pte_present will return true even on
+        * a non present pte. The canon_pgprot will clear
+        * _PAGE_GLOBAL for the ancient hardware that doesn't
+        * support it.
+        */

+ if (pgprot_val(pgprot) & _PAGE_PRESENT)
+ pgprot_val(pgprot) |= _PAGE_GLOBAL;
+ else
+ pgprot_val(pgprot) &= ~_PAGE_GLOBAL;
+
+ pgprot = canon_pgprot(pgprot);
+

The comment is confusing. This code is setting GLOBAL if PRESENT is set even if not requested, but the comment is about setting GLOBAL *only* if PRESENT is set.

Can you explain:

a) Why this wasn't already broken. (were there no callers who set GLOBAL but not PRESENT? If there weren't any, why is that part needed?)

b) Why setting GLOBAL for EFI mappings is useful.

c) Why setting GLOBAL for EFI mappings is safe. Don't we unmap the EFI mappings when we're not actively using them in new kernels? If so, don't we explicitly want them *not* to be GLOBAL to avoid needing an extra-expensive global flush?

d) Why this doesn't break any non-EFI code.

--Andy

#8 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 4 lines · Andy Lutomirski

On Feb 23, 2016 1:09 AM, <&quot;tip-bot for Sai Praneeth &lt;[email protected]&gt;&quot;@zytor.com> wrote:

Something's wrong with tip-bot. This should say:

Yeah, there's about 50 tipbot emails that are just pure garbage. They don't even show in my mailers, because they are so corrupt.

The raw email has some insane encoding too, for reasons I can't begin to fathom.

This is an example of what tipbot *used* to send out in the headers:

From: tip-bot for Dave Hansen <[email protected]>
Subject: [tip:mm/pkeys] mm/core, x86/mm/pkeys:
Add execute-only protection keys support

and this is what it sent out in the last crazy setup:

From: =?UTF-8?B?dGlwLWJvdCBmb3IgU2FpIFByYW5lZXRoIDx0aXBib3RAenl0b3IuY29tPg==?=@zytor.com
Subject:
=?UTF-8?B?W3RpcDplZmkvY29yZV0geDg2L21tL3BhdDogVXNlIF9QQUdFX0dMT0JBTCBiaXQ=?= =?UTF-8?B?IGZvciBFRkkgcGFnZSB0YWJsZSBtYXBwaW5ncw==?=

despite neither subject nor author having any odd characters in them.

(That's just two header lines - all the other ones are corrupt in similar ways too)

The thing that seems to really make things unreadable is that the content encoding lines have this corrupted quoting too:

MIME-Version: =?UTF-8?B?MS4w?=
Content-Transfer-Encoding: =?UTF-8?B?OGJpdA==?=
Content-Type: =?UTF-8?B?dGV4dC9wbGFpbjsgY2hhcnNldD1VVEYtOA==?=
Content-Disposition: =?UTF-8?B?aW5saW5l?=

rather than what it *should* be:

Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline

so the whole header situation is a complete mess.

The fact that you can see the patch at all and comment on the *contents* of the email is impressive. My mail reader just says "this is garbage" and shows me nothing at all.

Linus

maintainer
#9 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 3 lines · Linus Torvalds

The fact that you can see the patch at all and comment on the *contents* of the email is impressive. My mail reader just says "this is garbage" and shows me nothing at all.

Yeah, mutt says:

[-- application/x-=?UTF-8?B?dGV4dC9wbGFpbjsgY2hhcnNldD1VVEYtOA==?= is unsupported (use 'v' to view this part) --]

in the mail body. But then one can open it and it defaults to text:

---Attachment: application/x-=?UTF-8?B?dGV4dC9wbGFpbjsgY2hhcnNldD1VVEYtOA==?= (all) No matching mailcap entry found. Viewing as text.

Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#10 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Linus Torvalds
Quoted 46 lines · Linus Torvalds
Quoted 4 lines · Andy Lutomirski

On Feb 23, 2016 1:09 AM, <&quot;tip-bot for Sai Praneeth &lt;[email protected]&gt;&quot;@zytor.com> wrote:

Something's wrong with tip-bot. This should say:

Yeah, there's about 50 tipbot emails that are just pure garbage. They don't even show in my mailers, because they are so corrupt.

The raw email has some insane encoding too, for reasons I can't begin to fathom.

This is an example of what tipbot *used* to send out in the headers:

From: tip-bot for Dave Hansen <[email protected]>
Subject: [tip:mm/pkeys] mm/core, x86/mm/pkeys:
Add execute-only protection keys support

and this is what it sent out in the last crazy setup:

From:
=?UTF-8?B?dGlwLWJvdCBmb3IgU2FpIFByYW5lZXRoIDx0aXBib3RAenl0b3IuY29tPg==?=@zytor.com
Subject:
=?UTF-8?B?W3RpcDplZmkvY29yZV0geDg2L21tL3BhdDogVXNlIF9QQUdFX0dMT0JBTCBiaXQ=?=
=?UTF-8?B?IGZvciBFRkkgcGFnZSB0YWJsZSBtYXBwaW5ncw==?=

despite neither subject nor author having any odd characters in them.

(That's just two header lines - all the other ones are corrupt in similar ways too)

The thing that seems to really make things unreadable is that the content encoding lines have this corrupted quoting too:

MIME-Version: =?UTF-8?B?MS4w?=
Content-Transfer-Encoding: =?UTF-8?B?OGJpdA==?=
Content-Type: =?UTF-8?B?dGV4dC9wbGFpbjsgY2hhcnNldD1VVEYtOA==?=
Content-Disposition: =?UTF-8?B?aW5saW5l?=

rather than what it *should* be:

Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline

Quoted 7 lines

so the whole header situation is a complete mess.

The fact that you can see the patch at all and comment on the *contents* of the email is impressive. My mail reader just says "this is garbage" and shows me nothing at all.

Linus

Someone decided to change the behavior of the Perl module I used for encoding to unconditionally encode almost everything, claiming some kind of strict RFC compliance. An upgrade caused this to happen. I have switched modules to one which should do what one actually wants.

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.
#11 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 54 lines · H. Peter Anvin
Quoted 52 lines · Linus Torvalds
Quoted 4 lines · Andy Lutomirski

On Feb 23, 2016 1:09 AM, <&quot;tip-bot for Sai Praneeth &lt;[email protected]&gt;&quot;@zytor.com> wrote:

Something's wrong with tip-bot. This should say:

Yeah, there's about 50 tipbot emails that are just pure garbage. They don't even show in my mailers, because they are so corrupt.

The raw email has some insane encoding too, for reasons I can't begin to fathom.

This is an example of what tipbot *used* to send out in the headers:

From: tip-bot for Dave Hansen <[email protected]>
Subject: [tip:mm/pkeys] mm/core, x86/mm/pkeys:
Add execute-only protection keys support

and this is what it sent out in the last crazy setup:

From:
=?UTF-8?B?dGlwLWJvdCBmb3IgU2FpIFByYW5lZXRoIDx0aXBib3RAenl0b3IuY29tPg==?=@zytor.com
Subject:
=?UTF-8?B?W3RpcDplZmkvY29yZV0geDg2L21tL3BhdDogVXNlIF9QQUdFX0dMT0JBTCBiaXQ=?=
=?UTF-8?B?IGZvciBFRkkgcGFnZSB0YWJsZSBtYXBwaW5ncw==?=

despite neither subject nor author having any odd characters in them.

(That's just two header lines - all the other ones are corrupt in similar ways too)

The thing that seems to really make things unreadable is that the content encoding lines have this corrupted quoting too:

MIME-Version: =?UTF-8?B?MS4w?=
Content-Transfer-Encoding: =?UTF-8?B?OGJpdA==?=
Content-Type: =?UTF-8?B?dGV4dC9wbGFpbjsgY2hhcnNldD1VVEYtOA==?=
Content-Disposition: =?UTF-8?B?aW5saW5l?=

rather than what it *should* be:

Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline

so the whole header situation is a complete mess.

The fact that you can see the patch at all and comment on the *contents* of the email is impressive. My mail reader just says "this is garbage" and shows me nothing at all.

Quoted 6 lines
Quoted 1 line

Linus

Someone decided to change the behavior of the Perl module I used for encoding to unconditionally encode almost everything, claiming some kind of strict RFC compliance. An upgrade caused this to happen. I have switched modules to one which should do what one actually wants.

For the record: I implemented escaping only to placate vger's spam filters...

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.
#12 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Linus Torvalds
Quoted 8 lines · Linus Torvalds
Quoted 4 lines · Andy Lutomirski

On Feb 23, 2016 1:09 AM, <&quot;tip-bot for Sai Praneeth &lt;[email protected]&gt;&quot;@zytor.com> wrote:

Something's wrong with tip-bot. This should say:

Yeah, there's about 50 tipbot emails that are just pure garbage. They don't even show in my mailers, because they are so corrupt.

It should now all be fixed.

We were unlucky in that I just happened to push out a bunch of new commits after the script broke. Normally I'd have noticed this after just a few commits.

Sorry about this!

Thanks,

Ingo

#13 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Andy Lutomirski
Quoted 42 lines · Andy Lutomirski

On Feb 23, 2016 1:09 AM, <&quot;tip-bot for Sai Praneeth &lt;[email protected]&gt;&quot;@zytor.com> wrote:

Something's wrong with tip-bot. This should say:

commit 397630150632639b3ca5b4414accd5011c45e276

Author: Sai Praneeth <[email protected]>
Date:   Wed Feb 17 12:35:56 2016 +0000

x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Since EFI page tables can be treated as kernel page tables they should be global. All the other page mapping functions in pageattr.c set the _PAGE_GLOBAL bit and we want to avoid inconsistencies when we map a page in the EFI code paths, for example when that page is split in __split_large_page(), etc. It also makes it easier to validate that the EFI region mappings have the correct attributes because there are fewer differences compared with regular kernel mappings.

But the actual patch is:

arch/x86/mm/pageattr.c +14 -0
@@ -909,6 +909,20 @@ static void populate_pte(struct cpa_data *cpa,
 
        pte = pte_offset_kernel(pmd, start);
 
+       /*
+        * Set the GLOBAL flags only if the PRESENT flag is
+        * set otherwise pte_present will return true even on
+        * a non present pte. The canon_pgprot will clear
+        * _PAGE_GLOBAL for the ancient hardware that doesn't
+        * support it.
+        */
+       if (pgprot_val(pgprot) & _PAGE_PRESENT)
+               pgprot_val(pgprot) |= _PAGE_GLOBAL;
+       else
+               pgprot_val(pgprot) &= ~_PAGE_GLOBAL;
+
+       pgprot = canon_pgprot(pgprot);
+
 
Quoted 3 lines

The comment is confusing. This code is setting GLOBAL if PRESENT is set even if not requested, but the comment is about setting GLOBAL *only* if PRESENT is set.

As you rightly said the code is about making a page GLOBAL if PRESENT is set and we do set PRESENT bit before mapping so that page is GLOBAL. This code was taken from the other parts of pageattr.c. The point is that we don't want differences between whether things were mapped in the EFI page tables directly (i.e. using populate_pte()) or later split from large pages via the split_large_page() code path. If this is still confusing could you please elaborate on it further.

Quoted 7 lines

Can you explain:

a) Why this wasn't already broken. (were there no callers who set GLOBAL but not PRESENT? If there weren't any, why is that part needed?)

I don't think previous implementation is broken and this is not a bug fix as such. Before this patch some EFI region mappings had GLOBAL bit set (which followed split large page path) and some aren't (which used populate_pte). This patch just aligns the mappings done via two different code paths as mentioned above. As a whole it also maintains consistency with kernel mappings.

Quoted 1 line

b) Why setting GLOBAL for EFI mappings is useful.

We did this for consistency among EFI mappings. This has some advantages as mentioned in the commit message. It also makes it less confusing when starting at the PGT_DUMP traces if _PAGE_GLOBAL is used consistently.

We don't actually do anything special with _PAGE_GLOBAL in EFI.

Quoted 4 lines

c) Why setting GLOBAL for EFI mappings is safe. Don't we unmap the EFI mappings when we're not actively using them in new kernels? If so, don't we explicitly want them *not* to be GLOBAL to avoid needing an extra-expensive global flush?

This is a valid point. I know that EFI runtime regions persist during and after boot if we have a UEFI firmware and other commits made EFI regions have separate page table but I am not clear about the effect of global flush. I think Matt/Boris could comment on it.

Quoted 1 line

d) Why this doesn't break any non-EFI code.

We touch this code path only when mapping EFI runtime regions to VA space, i.e. we added pgd field in cpa only as a support for mapping efi runtime regions.

Quoted 1 line

--Andy

#14 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 43 lines · Sai Praneeth Prakhya
Quoted 42 lines · Andy Lutomirski

On Feb 23, 2016 1:09 AM, <&quot;tip-bot for Sai Praneeth &lt;[email protected]&gt;&quot;@zytor.com> wrote:

Something's wrong with tip-bot. This should say:

commit 397630150632639b3ca5b4414accd5011c45e276

Author: Sai Praneeth <[email protected]>
Date:   Wed Feb 17 12:35:56 2016 +0000

x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Since EFI page tables can be treated as kernel page tables they should be global. All the other page mapping functions in pageattr.c set the _PAGE_GLOBAL bit and we want to avoid inconsistencies when we map a page in the EFI code paths, for example when that page is split in __split_large_page(), etc. It also makes it easier to validate that the EFI region mappings have the correct attributes because there are fewer differences compared with regular kernel mappings.

But the actual patch is:

arch/x86/mm/pageattr.c +14 -0
@@ -909,6 +909,20 @@ static void populate_pte(struct cpa_data *cpa,
 
        pte = pte_offset_kernel(pmd, start);
 
+       /*
+        * Set the GLOBAL flags only if the PRESENT flag is
+        * set otherwise pte_present will return true even on
+        * a non present pte. The canon_pgprot will clear
+        * _PAGE_GLOBAL for the ancient hardware that doesn't
+        * support it.
+        */
+       if (pgprot_val(pgprot) & _PAGE_PRESENT)
+               pgprot_val(pgprot) |= _PAGE_GLOBAL;
+       else
+               pgprot_val(pgprot) &= ~_PAGE_GLOBAL;
+
+       pgprot = canon_pgprot(pgprot);
+
 
Quoted 11 lines
Quoted 3 lines

The comment is confusing. This code is setting GLOBAL if PRESENT is set even if not requested, but the comment is about setting GLOBAL *only* if PRESENT is set.

As you rightly said the code is about making a page GLOBAL if PRESENT is set and we do set PRESENT bit before mapping so that page is GLOBAL. This code was taken from the other parts of pageattr.c. The point is that we don't want differences between whether things were mapped in the EFI page tables directly (i.e. using populate_pte()) or later split from large pages via the split_large_page() code path. If this is still confusing could you please elaborate on it further.

At least the comment should say "Set the GLOBAL flag if and only if...". But why is this code here in the first place? What is passing a pgprot with global unset into this code in the first place?

Quoted 9 lines
Quoted 8 lines

Can you explain:

a) Why this wasn't already broken. (were there no callers who set GLOBAL but not PRESENT? If there weren't any, why is that part needed?)

Quoted 6 lines

I don't think previous implementation is broken and this is not a bug fix as such. Before this patch some EFI region mappings had GLOBAL bit set (which followed split large page path) and some aren't (which used populate_pte). This patch just aligns the mappings done via two different code paths as mentioned above. As a whole it also maintains consistency with kernel mappings.

But your code also *clears* GLOBAL if PRESENT is clear, and your comment talks about that. Does this ever actually happen in practice?

I'd much rather see WARN_ON_ONCE((pgprot_val(pgprot) & (_PAGE_PRESENT | _PAGE_GLOBAL)) == _PAGE_GLOBAL) in here, if that makes sense in the context of the callers of the function.

Quoted 8 lines
Quoted 2 lines

b) Why setting GLOBAL for EFI mappings is useful.

We did this for consistency among EFI mappings. This has some advantages as mentioned in the commit message. It also makes it less confusing when starting at the PGT_DUMP traces if _PAGE_GLOBAL is used consistently.

We don't actually do anything special with _PAGE_GLOBAL in EFI.

You're making a choice of whether to set _PAGE_GLOBAL, and I think you've made the wrong choice.

Normally, the only pages with are _PAGE_GLOBAL are those that are in the normal kernel mappings (swapper_pg_dir and normal mm_struct pgds). By allowing _PAGE_GLOBAL to be set in EFI mappings, you're breaking that convention, which forces you to use extra-expensive __flush_tlb_all calls in efi_call_virt.

I think you should explicitly *clear* _PAGE_GLOBAL in the EFI mappings instead. This would allow you to use write_cr3 by itself, which would make the code simpler and faster.

Quoted 10 lines
Quoted 5 lines

c) Why setting GLOBAL for EFI mappings is safe. Don't we unmap the EFI mappings when we're not actively using them in new kernels? If so, don't we explicitly want them *not* to be GLOBAL to avoid needing an extra-expensive global flush?

This is a valid point. I know that EFI runtime regions persist during and after boot if we have a UEFI firmware and other commits made EFI regions have separate page table but I am not clear about the effect of global flush. I think Matt/Boris could comment on it.

It's straightfoward on existing kernels. If _PAGE_GLOBAL is set, TLB entries persist across cr3 writes. If _PAGE_GLOBAL is clear, then TLB entries are flushed by cr3 writes.

With PCID enabled (which is only in a not-quite-ready patch set I have), the story is a bit more complicated, but it works essentially the same way unless you explicitly opt out.

Quoted 6 lines
Quoted 2 lines

d) Why this doesn't break any non-EFI code.

We touch this code path only when mapping EFI runtime regions to VA space, i.e. we added pgd field in cpa only as a support for mapping efi runtime regions.

populate_pgd is called from non-EFI code as well though, isn't it?

--Andy

#15 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 11 lines · Andy Lutomirski
Quoted 8 lines · Sai Praneeth Prakhya

As you rightly said the code is about making a page GLOBAL if PRESENT is set and we do set PRESENT bit before mapping so that page is GLOBAL. This code was taken from the other parts of pageattr.c. The point is that we don't want differences between whether things were mapped in the EFI page tables directly (i.e. using populate_pte()) or later split from large pages via the split_large_page() code path. If this is still confusing could you please elaborate on it further.

Quoted 3 lines

At least the comment should say "Set the GLOBAL flag if and only if...". But why is this code here in the first place? What is passing a pgprot with global unset into this code in the first place?

This comes from populate_pgd(),

static int populate_pgd(struct cpa_data *cpa, unsigned long addr)

  {
	  pgprot_t pgprot = __pgprot(_KERNPG_TABLE);
Quoted 9 lines
Quoted 6 lines

I don't think previous implementation is broken and this is not a bug fix as such. Before this patch some EFI region mappings had GLOBAL bit set (which followed split large page path) and some aren't (which used populate_pte). This patch just aligns the mappings done via two different code paths as mentioned above. As a whole it also maintains consistency with kernel mappings.

But your code also *clears* GLOBAL if PRESENT is clear, and your comment talks about that. Does this ever actually happen in practice?

Not when mapping EFI regions, no (we explicitly set _PAGE_PRESENT in kernel_map_pages_in_pgd(), but this logic is duplicated from __split_large_page() which can be called from non-EFI code.

Quoted 3 lines

I'd much rather see WARN_ON_ONCE((pgprot_val(pgprot) & (_PAGE_PRESENT | _PAGE_GLOBAL)) == _PAGE_GLOBAL) in here, if that makes sense in the context of the callers of the function.

I think that'd be a nice cleanup, along with pulling all the pgprot twiddling out into a single function.

Quoted 15 lines
Quoted 5 lines

We did this for consistency among EFI mappings. This has some advantages as mentioned in the commit message. It also makes it less confusing when starting at the PGT_DUMP traces if _PAGE_GLOBAL is used consistently.

We don't actually do anything special with _PAGE_GLOBAL in EFI.

You're making a choice of whether to set _PAGE_GLOBAL, and I think you've made the wrong choice.

Normally, the only pages with are _PAGE_GLOBAL are those that are in the normal kernel mappings (swapper_pg_dir and normal mm_struct pgds). By allowing _PAGE_GLOBAL to be set in EFI mappings, you're breaking that convention, which forces you to use extra-expensive __flush_tlb_all calls in efi_call_virt.

Quoted 3 lines

I think you should explicitly *clear* _PAGE_GLOBAL in the EFI mappings instead. This would allow you to use write_cr3 by itself, which would make the code simpler and faster.

This is interesting.

When I suggested to Sai that he write this patch my main motivation was consistency for all mappings. We've got that now, but perhaps it's the wrong consistency ;)

If we go with the no-PAGE_GLOBAL approach, we need changes to ensure we never set _PAGE_GLOBAL for the EFI mappings, because before this patch was applied sometimes we did and sometimes we didn't, depending on whether a page was split or not.

I'm racking my brain to think of how your suggestion might have unintended consequences because diagnosing stale TLB entry bugs is simply the worst job ever. I can't think of anything. The only scenarios where we'd see problems is if a) we have new global mappings in the EFI page tables or b) we have different global mappings.

Since we reference swapper_pg_dir from the PMD level downwards b) shouldn't be a problem, and the only differences between swapper_pg_dir and efi_pgd should be the EFI mappings, which saves us from a).

Quoted 8 lines
Quoted 4 lines

This is a valid point. I know that EFI runtime regions persist during and after boot if we have a UEFI firmware and other commits made EFI regions have separate page table but I am not clear about the effect of global flush. I think Matt/Boris could comment on it.

It's straightfoward on existing kernels. If _PAGE_GLOBAL is set, TLB entries persist across cr3 writes. If _PAGE_GLOBAL is clear, then TLB entries are flushed by cr3 writes.

This is safe for EFI right now because of the big __flush_tlb_all() in efi_call_virt().

Quoted 3 lines

With PCID enabled (which is only in a not-quite-ready patch set I have), the story is a bit more complicated, but it works essentially the same way unless you explicitly opt out.

Hmm... is series that posted somewhere?

Quoted 5 lines
Quoted 3 lines

We touch this code path only when mapping EFI runtime regions to VA space, i.e. we added pgd field in cpa only as a support for mapping efi runtime regions.

populate_pgd is called from non-EFI code as well though, isn't it?

Nope. The "if (cpa->pgd)" guard ensures that we only call that function for the EFI mapping code - no one else sets ->pgd.

maintainer
#16 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 5 lines · Matt Fleming
Quoted 5 lines

Normally, the only pages with are _PAGE_GLOBAL are those that are in the normal kernel mappings (swapper_pg_dir and normal mm_struct pgds). By allowing _PAGE_GLOBAL to be set in EFI mappings, you're breaking that convention, which forces you to use extra-expensive __flush_tlb_all calls in efi_call_virt.

Hold on, do you mean the __flush_tlb_all() in the CONFIG_EFI_MIXED code?

That's mixed mode. I think you mean the FLUSH_TLB_ALL in efi_call. That's EFI on 64-bit but that is mandated by the spec, AFAIR.

So the EFI runtime crap should not change once it is mapped. And those should be global. It is only natural.

Quoted 2 lines

Nope. The "if (cpa->pgd)" guard ensures that we only call that function for the EFI mapping code - no one else sets ->pgd.

But it could - there's no guarantee. kernel_map_pages_in_pgd() is an exported facility.

Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#17 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 11 lines · Borislav Petkov
Quoted 5 lines · Matt Fleming
Quoted 5 lines

Normally, the only pages with are _PAGE_GLOBAL are those that are in the normal kernel mappings (swapper_pg_dir and normal mm_struct pgds). By allowing _PAGE_GLOBAL to be set in EFI mappings, you're breaking that convention, which forces you to use extra-expensive __flush_tlb_all calls in efi_call_virt.

Hold on, do you mean the __flush_tlb_all() in the CONFIG_EFI_MIXED code?

That's mixed mode. I think you mean the FLUSH_TLB_ALL in efi_call. That's EFI on 64-bit but that is mandated by the spec, AFAIR.

I mean the one in efi_call_virt. Why would the spec mandate a TLB flush at all? EFI runtime services have no business touching the paging structures directly. Heck, the 32-bit ones don't even know the *format* of the paging structures.

Quoted 3 lines

So the EFI runtime crap should not change once it is mapped. And those should be global. It is only natural.

Why is it natural?

Long-term, I'd rather see EFI runtime services use an actual mm_struct and use_mm.

--Andy

#18 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 8 lines · Andy Lutomirski
Quoted 3 lines

So the EFI runtime crap should not change once it is mapped. And those should be global. It is only natural.

Why is it natural?

Long-term, I'd rather see EFI runtime services use an actual mm_struct and use_mm.

Definitely.

The EFI runtime page mapping may be unchanging, but that doesn't mean we should be mapping it all the time - the mapping may not change, but we will change away from it.

So marking those pages global is very wrong.

Linus

#19 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 7 lines · Linus Torvalds
Quoted 6 lines · Andy Lutomirski
Quoted 3 lines

So the EFI runtime crap should not change once it is mapped. And those should be global. It is only natural.

Why is it natural?

Quoted 8 lines
Quoted 2 lines

Long-term, I'd rather see EFI runtime services use an actual mm_struct and use_mm.

Definitely.

The EFI runtime page mapping may be unchanging, but that doesn't mean we should be mapping it all the time - the mapping may not change, but we will change away from it.

There is movement towards hanging the EFI memory map off of mm_struct for x86. ARM and arm64 already do this and there were some patches from Sylvain (Cc'd) to do this for the purposes of having a task context that could be preempted while in the middle of an EFI runtime call for some Intel platforms,

https://lkml.kernel.org/r/[email protected]

Apart from the code simplification and not being required to open-code the %cr3 diddling, are there other benefits of mm_struct and use_mm() that make it appealing in the non-preemptible case?

Not that those aren't reasons enough.

Quoted 1 line

So marking those pages global is very wrong.

Ingo, Andy, how do you want to handle this patch? Maybe just drop it from tip/efi/core while we prod around making all the EFI mappings non-global? Nothing else depends on it, it can be dropped without any harm.

#20 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 23 lines · Matt Fleming
Quoted 7 lines · Linus Torvalds
Quoted 6 lines · Andy Lutomirski
Quoted 3 lines

So the EFI runtime crap should not change once it is mapped. And those should be global. It is only natural.

Why is it natural?

Quoted 8 lines
Quoted 2 lines

Long-term, I'd rather see EFI runtime services use an actual mm_struct and use_mm.

Definitely.

The EFI runtime page mapping may be unchanging, but that doesn't mean we should be mapping it all the time - the mapping may not change, but we will change away from it.

There is movement towards hanging the EFI memory map off of mm_struct for x86. ARM and arm64 already do this and there were some patches from Sylvain (Cc'd) to do this for the purposes of having a task context that could be preempted while in the middle of an EFI runtime call for some Intel platforms,

Quoted 7 lines

https://lkml.kernel.org/r/[email protected]

Apart from the code simplification and not being required to open-code the %cr3 diddling, are there other benefits of mm_struct and use_mm() that make it appealing in the non-preemptible case?

Not that those aren't reasons enough.

If we add PCID support, then use_mm will get the benefits (~200ns savings for a round trip) for free.

Quoted 7 lines
Quoted 2 lines

So marking those pages global is very wrong.

Ingo, Andy, how do you want to handle this patch? Maybe just drop it from tip/efi/core while we prod around making all the EFI mappings non-global? Nothing else depends on it, it can be dropped without any harm.

If the patch is harmless as is, I'm okay with letting it stay.

--Andy

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#21 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Matt Fleming

2016-02-24 20:45 GMT+01:00 Matt Fleming <[email protected]>:

Quoted 17 lines · Linus Torvalds
Quoted 7 lines · Andy Lutomirski
Quoted 6 lines
Quoted 3 lines

So the EFI runtime crap should not change once it is mapped. And those should be global. It is only natural.

Why is it natural?

Quoted 8 lines
Quoted 2 lines

Long-term, I'd rather see EFI runtime services use an actual mm_struct and use_mm.

Definitely.

The EFI runtime page mapping may be unchanging, but that doesn't mean we should be mapping it all the time - the mapping may not change, but we will change away from it.

Quoted 7 lines

There is movement towards hanging the EFI memory map off of mm_struct for x86. ARM and arm64 already do this and there were some patches from Sylvain (Cc'd) to do this for the purposes of having a task context that could be preempted while in the middle of an EFI runtime call for some Intel platforms,

https://lkml.kernel.org/r/[email protected]

I was thinking we could use the efi kthread to handle the efi services generically, not only for the interruptible case, and have a way to decide if we allow interruptions inside the efi call itself or not.

Then all runtime services would use an mm_struct. The drawback is that you will need two context switchs to be able to execute the runtime service.

Signature · 1 line
Sylvain
#22 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 24 lines · Sylvain Chouleur

2016-02-24 20:45 GMT+01:00 Matt Fleming <[email protected]>:

Quoted 23 lines · Linus Torvalds
Quoted 7 lines · Andy Lutomirski
Quoted 6 lines
Quoted 3 lines

So the EFI runtime crap should not change once it is mapped. And those should be global. It is only natural.

Why is it natural?

Quoted 8 lines
Quoted 2 lines

Long-term, I'd rather see EFI runtime services use an actual mm_struct and use_mm.

Definitely.

The EFI runtime page mapping may be unchanging, but that doesn't mean we should be mapping it all the time - the mapping may not change, but we will change away from it.

There is movement towards hanging the EFI memory map off of mm_struct for x86. ARM and arm64 already do this and there were some patches from Sylvain (Cc'd) to do this for the purposes of having a task context that could be preempted while in the middle of an EFI runtime call for some Intel platforms,

Quoted 8 lines
Quoted 1 line

https://lkml.kernel.org/r/[email protected]

I was thinking we could use the efi kthread to handle the efi services generically, not only for the interruptible case, and have a way to decide if we allow interruptions inside the efi call itself or not.

Then all runtime services would use an mm_struct. The drawback is that you will need two context switchs to be able to execute the runtime service.

I would be surprised if the asynchronous nature of having a special EFI kthread would buy you any benefit in general. And in fact, in the efi-pstore code you can be invoked in IRQ context and you really don't want to start talking to a kthread.

#23 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Andy Lutomirski
Quoted 10 lines · Andy Lutomirski
Quoted 9 lines · Borislav Petkov
Quoted 5 lines · Matt Fleming
Quoted 5 lines

Normally, the only pages with are _PAGE_GLOBAL are those that are in the normal kernel mappings (swapper_pg_dir and normal mm_struct pgds). By allowing _PAGE_GLOBAL to be set in EFI mappings, you're breaking that convention, which forces you to use extra-expensive __flush_tlb_all calls in efi_call_virt.

Hold on, do you mean the __flush_tlb_all() in the CONFIG_EFI_MIXED code?

Quoted 7 lines
Quoted 2 lines

That's mixed mode. I think you mean the FLUSH_TLB_ALL in efi_call. That's EFI on 64-bit but that is mandated by the spec, AFAIR.

I mean the one in efi_call_virt. Why would the spec mandate a TLB flush at all? EFI runtime services have no business touching the paging structures directly. Heck, the 32-bit ones don't even know the *format* of the paging structures.

Right, and it would necessitate copying out arguments because the firmware won't understand where/how the kernel has mapped things.

No firmware is going to be doing that.

#24 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 19 lines · Matt Fleming
Quoted 10 lines · Andy Lutomirski
Quoted 9 lines · Borislav Petkov
Quoted 5 lines · Matt Fleming
Quoted 5 lines

Normally, the only pages with are _PAGE_GLOBAL are those that are in the normal kernel mappings (swapper_pg_dir and normal mm_struct pgds). By allowing _PAGE_GLOBAL to be set in EFI mappings, you're breaking that convention, which forces you to use extra-expensive __flush_tlb_all calls in efi_call_virt.

Hold on, do you mean the __flush_tlb_all() in the CONFIG_EFI_MIXED code?

Quoted 7 lines
Quoted 2 lines

That's mixed mode. I think you mean the FLUSH_TLB_ALL in efi_call. That's EFI on 64-bit but that is mandated by the spec, AFAIR.

I mean the one in efi_call_virt. Why would the spec mandate a TLB flush at all? EFI runtime services have no business touching the paging structures directly. Heck, the 32-bit ones don't even know the *format* of the paging structures.

Quoted 4 lines

Right, and it would necessitate copying out arguments because the firmware won't understand where/how the kernel has mapped things.

No firmware is going to be doing that.

Just so I understand correctly: could we get away with putting the EFI virtual runtime mappings at positive (user) addresses for 64-bit UEFI, or is there some reason that we need the high bit set?

If we could use positive addresses, then we could use the existing use_mm infrastructure directly with no funny business at all except to the extent that we might need to use unusual APIs to set up the VMAs (if we use real VMAs) in the first place. (We could cheat and allocate a single monstrous VM_MIXEDMAP or VM_PFNMAP vma with a .fault handler that always fails.) If we have to use negative addresses, then we'll always be stuck with a funny pgd, but we could still probably use use_mm instead of manually fiddling with cr3.

Some day I want to experiment with calling runtime services at CPL 3, too :) We'd want to add some infrastructure to permit kernel threads to run through the entry/exit code as if they were user processes, but there's nothing conceptually wrong with that. We already allow kernel threads to call execve and "return" to real user mode, so it's not much of a stretch. The main issue would be dealing with signal handling and such -- we'd want to report faults back to the kernel thread's CPL3-invocation thunks rather than delivering a signal at CPL 3.

Hmm, now it's time to muse about how the interface would work. If we kept it in line with existing practice, we'd add an API to make a special kernel thread with an attached user context. To enter CPL3, you'd return from the thread's main function. When user mode was done (fault or syscall), new hooks in the entry code (similar to seccomp and the die notifier stuff) would re-enter the main function with some arguments indicating what happened.

If we wanted to make it a bit easier to use, we'd have to allocate an extra kernel sack, and we could have:

void invoke_cpl3(struct cpl3_context *ctx);

where ctx contains memory for an extra stack as well as a bunch of data indicating the reason that it returned.

The latter is harder to implement but probably much easier to use.

If anyone wants to work on this, ping me and I'll help and do a bunch of review.

--Andy

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#25 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 14 lines · Andy Lutomirski
Quoted 9 lines
Quoted 4 lines

I mean the one in efi_call_virt. Why would the spec mandate a TLB flush at all? EFI runtime services have no business touching the paging structures directly. Heck, the 32-bit ones don't even know the *format* of the paging structures.

Right, and it would necessitate copying out arguments because the firmware won't understand where/how the kernel has mapped things.

No firmware is going to be doing that.

Just so I understand correctly: could we get away with putting the EFI virtual runtime mappings at positive (user) addresses for 64-bit UEFI, or is there some reason that we need the high bit set?

Quoted 7 lines

If we could use positive addresses, then we could use the existing use_mm infrastructure directly with no funny business at all except to the extent that we might need to use unusual APIs to set up the VMAs (if we use real VMAs) in the first place. (We could cheat and allocate a single monstrous VM_MIXEDMAP or VM_PFNMAP vma with a .fault handler that always fails.) If we have to use negative addresses, then we'll always be stuck with a funny pgd, but we could still probably use use_mm instead of manually fiddling with cr3.

Would be nice to get an answer to these questions. The more we isolate firmware execution into 'regular' MM concepts, the more robust it all becomes.

Quoted 1 line

Some day I want to experiment with calling runtime services at CPL 3, too :)

That would be an interesting isolation method as well ...

Thanks,

Ingo

#26 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Andy Lutomirski
Quoted 20 lines · Andy Lutomirski
Quoted 19 lines · Matt Fleming
Quoted 17 lines · Andy Lutomirski
Quoted 11 lines · Borislav Petkov
Quoted 5 lines · Matt Fleming
Quoted 5 lines

Normally, the only pages with are _PAGE_GLOBAL are those that are in the normal kernel mappings (swapper_pg_dir and normal mm_struct pgds). By allowing _PAGE_GLOBAL to be set in EFI mappings, you're breaking that convention, which forces you to use extra-expensive __flush_tlb_all calls in efi_call_virt.

Hold on, do you mean the __flush_tlb_all() in the CONFIG_EFI_MIXED code?

That's mixed mode. I think you mean the FLUSH_TLB_ALL in efi_call. That's EFI on 64-bit but that is mandated by the spec, AFAIR.

I mean the one in efi_call_virt. Why would the spec mandate a TLB flush at all? EFI runtime services have no business touching the paging structures directly. Heck, the 32-bit ones don't even know the *format* of the paging structures.

Quoted 8 lines
Quoted 4 lines

Right, and it would necessitate copying out arguments because the firmware won't understand where/how the kernel has mapped things.

No firmware is going to be doing that.

Just so I understand correctly: could we get away with putting the EFI virtual runtime mappings at positive (user) addresses for 64-bit UEFI, or is there some reason that we need the high bit set?

Good question. There are multiple parts to this answer:

1) Some firmware is known to break when entered via the identity

    addresses (VA==PA) 

2) Kexec cares the most about where we map things because the region has to be static across Kexec reboots. We do pass the kernel's EFI memory map regions between Kexec kernels but that region clearly needs to be available across kernel versions

It shouldn't be possible to conflict with userspace mappings or anything like that because we should never be accessing userspace addresses during EFI runtime services calls - all relevant data is copied to a kernel buffer or such. Userspace isn't even mapped now we've got completely separate EFI page tables.

I don't think there's anything else that would stop us clearing the high bit and moving the EFI virtual mapping region somewhere else. Boris?

Quoted 8 lines

If we could use positive addresses, then we could use the existing use_mm infrastructure directly with no funny business at all except to the extent that we might need to use unusual APIs to set up the VMAs (if we use real VMAs) in the first place. (We could cheat and allocate a single monstrous VM_MIXEDMAP or VM_PFNMAP vma with a .fault handler that always fails.) If we have to use negative addresses, then we'll always be stuck with a funny pgd, but we could still probably use use_mm instead of manually fiddling with cr3.

We don't use VMAs at the moment.

Having a custom .fault handler could be a very interesting idea because we've talked about wanting to do EFI-specific things in the past if we fault while executing firmware, e.g. printing warnings in the kernel log indicating the firmware is known to be buggy because it performed an access not compliant with the spec. See 1) above.

Quoted 9 lines

Some day I want to experiment with calling runtime services at CPL 3, too :) We'd want to add some infrastructure to permit kernel threads to run through the entry/exit code as if they were user processes, but there's nothing conceptually wrong with that. We already allow kernel threads to call execve and "return" to real user mode, so it's not much of a stretch. The main issue would be dealing with signal handling and such -- we'd want to report faults back to the kernel thread's CPL3-invocation thunks rather than delivering a signal at CPL 3.

Right, more isolation is better. I'm not sure we could get all the way to CPL 3 but I wouldn't begrudge anyone trying.

maintainer
#27 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Borislav Petkov
Quoted 2 lines · Borislav Petkov

That's mixed mode. I think you mean the FLUSH_TLB_ALL in efi_call. That's EFI on 64-bit but that is mandated by the spec, AFAIR.

Ok, so mfleming set me straight on IRC - that's tip/master I should be staring at.

In any case, I think we should do __flush_tlb_all() in efi_call_cirt() just in case, for the simple reason that EFI could be installing some funky TLB entries which we don't want. I'm not saying it does and it probably won't but what's stopping it?

Or am I being overly paranoid?

Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#28 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 7 lines · Borislav Petkov
Quoted 2 lines · Borislav Petkov

That's mixed mode. I think you mean the FLUSH_TLB_ALL in efi_call. That's EFI on 64-bit but that is mandated by the spec, AFAIR.

Ok, so mfleming set me straight on IRC - that's tip/master I should be staring at.

Quoted 6 lines

In any case, I think we should do __flush_tlb_all() in efi_call_cirt() just in case, for the simple reason that EFI could be installing some funky TLB entries which we don't want. I'm not saying it does and it probably won't but what's stopping it?

Or am I being overly paranoid?

I think you may be overly paranoid here. At least no working 32-bit EFI does this because we run it in compat mode. Any paging entries it inserts would be misinterpreted and likely immediately cause a crash. Also, the EFI code doesn't know a virtual address through which to reference the paging structures in the first place -- it could read CR3, but that gives a physical address, and it's not at all clear to me what even the crazier firmware authors would do with a physical address that doesn't live in EFI-defined ranges.

--Andy

#29 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

In reply to Matt Fleming
Quoted 16 lines · Matt Fleming
Quoted 11 lines · Andy Lutomirski
Quoted 8 lines · Sai Praneeth Prakhya

As you rightly said the code is about making a page GLOBAL if PRESENT is set and we do set PRESENT bit before mapping so that page is GLOBAL. This code was taken from the other parts of pageattr.c. The point is that we don't want differences between whether things were mapped in the EFI page tables directly (i.e. using populate_pte()) or later split from large pages via the split_large_page() code path. If this is still confusing could you please elaborate on it further.

Quoted 3 lines

At least the comment should say "Set the GLOBAL flag if and only if...". But why is this code here in the first place? What is passing a pgprot with global unset into this code in the first place?

Quoted 5 lines

This comes from populate_pgd(),

  static int populate_pgd(struct cpa_data *cpa, unsigned long addr)
  {
          pgprot_t pgprot = __pgprot(_KERNPG_TABLE);

which reminds me: aren't we supposed to *not* set GLOBAL on _PAGE_TABLE entries?

Quoted 31 lines
Quoted 10 lines

You're making a choice of whether to set _PAGE_GLOBAL, and I think you've made the wrong choice.

Normally, the only pages with are _PAGE_GLOBAL are those that are in the normal kernel mappings (swapper_pg_dir and normal mm_struct pgds). By allowing _PAGE_GLOBAL to be set in EFI mappings, you're breaking that convention, which forces you to use extra-expensive __flush_tlb_all calls in efi_call_virt.

Quoted 3 lines

I think you should explicitly *clear* _PAGE_GLOBAL in the EFI mappings instead. This would allow you to use write_cr3 by itself, which would make the code simpler and faster.

This is interesting.

When I suggested to Sai that he write this patch my main motivation was consistency for all mappings. We've got that now, but perhaps it's the wrong consistency ;)

If we go with the no-PAGE_GLOBAL approach, we need changes to ensure we never set _PAGE_GLOBAL for the EFI mappings, because before this patch was applied sometimes we did and sometimes we didn't, depending on whether a page was split or not.

I'm racking my brain to think of how your suggestion might have unintended consequences because diagnosing stale TLB entry bugs is simply the worst job ever. I can't think of anything. The only scenarios where we'd see problems is if a) we have new global mappings in the EFI page tables or b) we have different global mappings.

Quoted 4 lines

Since we reference swapper_pg_dir from the PMD level downwards b) shouldn't be a problem, and the only differences between swapper_pg_dir and efi_pgd should be the EFI mappings, which saves us from a).

:)

Anyway, there's certainly no need to do this right now.

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

This is a valid point. I know that EFI runtime regions persist during and after boot if we have a UEFI firmware and other commits made EFI regions have separate page table but I am not clear about the effect of global flush. I think Matt/Boris could comment on it.

It's straightfoward on existing kernels. If _PAGE_GLOBAL is set, TLB entries persist across cr3 writes. If _PAGE_GLOBAL is clear, then TLB entries are flushed by cr3 writes.

Quoted 8 lines

This is safe for EFI right now because of the big __flush_tlb_all() in efi_call_virt().

Quoted 3 lines

With PCID enabled (which is only in a not-quite-ready patch set I have), the story is a bit more complicated, but it works essentially the same way unless you explicitly opt out.

Hmm... is series that posted somewhere?

It's living here:

https://git.kernel.org/cgit/linux/kernel/git/luto/linux.git/log/?h=x86/pcid

at least until someone figures out how to squash the races in the bookkeeping.

I intentionally never load PCID == 0 with the "don't flush" bit set specifically so that direct PCID-unaware CR3 loads (like the EFI code does all over the place) keep working.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

We touch this code path only when mapping EFI runtime regions to VA space, i.e. we added pgd field in cpa only as a support for mapping efi runtime regions.

populate_pgd is called from non-EFI code as well though, isn't it?

Nope. The "if (cpa->pgd)" guard ensures that we only call that function for the EFI mapping code - no one else sets ->pgd.

OK, although a comment might be nice.

--Andy

#30 lore raw

Re: [tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Quoted 2 lines · Andy Lutomirski

OK, although a comment might be nice.

Something like this?

---

Quoted 1 line

From ac40fc0269d4d8cc9051982c177ee140d6e1b761 Mon Sep 17 00:00:00 2001

From: Matt Fleming <[email protected]>
Date: Thu, 25 Feb 2016 15:54:50 +0000
Subject: [PATCH] x86/mm/pat: Document the (currently) EFI-only code path

It's not at all obvious that populate_pgd() and friends are only executed when mapping EFI virtual memory regions or that no other pageattr callers pass a ->pgd value.

Cc Borislav Petkov <[email protected]>
Cc Sai Praneeth Prakhya <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 arch/x86/mm/pageattr.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/mm/pageattr.c +7 -1
index 14c38ae80409..8fee5b6f8f66 100644
@@ -1125,8 +1125,14 @@ static int populate_pgd(struct cpa_data *cpa, unsigned long addr)
 static int __cpa_process_fault(struct cpa_data *cpa, unsigned long vaddr,
 			       int primary)
 {
-	if (cpa->pgd)
+	if (cpa->pgd) {
+		/*
+		 * Right now, we only execute this code path when mapping
+		 * the EFI virtual memory map regions, no other users
+		 * provide a ->pgd value. This may change in the future.
+		 */
 		return populate_pgd(cpa, vaddr);
+	}
 
 	/*
 	 * Ignore all non primary paths.
Signature · 1 line
2.6.2
#31 lore raw

PATCH 4/13 efi/arm64: Drop __init annotation from handle_kernel_image()

In reply to Matt Fleming

From: Ard Biesheuvel <[email protected]>

After moving arm64-stub.c to libstub/, all of its sections are emitted as .init.xxx sections automatically, and the __init annotation of handle_kernel_image() causes it to end up in .init.init.text, which is not recognized as an __init section by the linker scripts. So drop the annotation.

---
 drivers/firmware/efi/libstub/arm64-stub.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/firmware/efi/libstub/arm64-stub.c +7 -7
index 78dfbd34b6bf..9e0342745e4f 100644
@@ -13,13 +13,13 @@
 #include <asm/efi.h>
 #include <asm/sections.h>
 
-efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
-					unsigned long *image_addr,
-					unsigned long *image_size,
-					unsigned long *reserve_addr,
-					unsigned long *reserve_size,
-					unsigned long dram_base,
-					efi_loaded_image_t *image)
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
+				 unsigned long *image_addr,
+				 unsigned long *image_size,
+				 unsigned long *reserve_addr,
+				 unsigned long *reserve_size,
+				 unsigned long dram_base,
+				 efi_loaded_image_t *image)
 {
 	efi_status_t status;
 	unsigned long kernel_size, kernel_memsize = 0;
Signature · 1 line
2.6.2
#33 lore raw

PATCH 5/13 arm64: vmlinux.lds.S: Handle .init.rodata.xxx and .init.bss sections

In reply to Matt Fleming

From: Ard Biesheuvel <[email protected]>

The EFI stub is typically built into the decompressor (x86, ARM) so none of its symbols are annotated as __init. However, on arm64, the stub is linked into the kernel proper, and the code is __init annotated at the section level by prepending all names of SHF_ALLOC sections with '.init'.

This results in section names like .init.rodata.str1.8 (for string literals) and .init.bss (which is tiny), both of which can be moved into the .init.data output section.

---
 arch/arm64/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/vmlinux.lds.S +1 -0
index e3928f578891..cbf4db440e9c 100644
@@ -134,6 +134,7 @@ SECTIONS
 		CON_INITCALL
 		SECURITY_INITCALL
 		INIT_RAM_FS
+		*(.init.rodata.* .init.bss)	/* from the EFI stub */
 	}
 	.exit.data : {
 		ARM_EXIT_KEEP(EXIT_DATA)
Signature · 1 line
2.6.2
#35 lore raw

PATCH 6/13 efi/efistub: Prevent __init annotations from being used

In reply to Matt Fleming

From: Ard Biesheuvel <[email protected]>

__init annotations should not be used in the EFI stub, since the code is either included in the decompressor (x86, ARM) where they have no effect, or the whole stub is __init annotated at the section level (arm64), by renaming the sections, in which case the __init annotations will be redundant, and will result in section names like .init.init.text, and our linker script does not expect that. So un-#define __init so that its inadvertent use will force a build error.

---
 drivers/firmware/efi/libstub/efistub.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/firmware/efi/libstub/efistub.h +10 -0
index 6b6548fda089..86ff7bfa6ace 100644
@@ -5,6 +5,16 @@
 /* error code which can't be mistaken for valid address */
 #define EFI_ERROR	(~0UL)
 
+/*
+ * __init annotations should not be used in the EFI stub, since the code is
+ * either included in the decompressor (x86, ARM) where they have no effect,
+ * or the whole stub is __init annotated at the section level (arm64), by
+ * renaming the sections, in which case the __init annotation will be
+ * redundant, and will result in section names like .init.init.text, and our
+ * linker script does not expect that.
+ */
+#undef __init
+
 void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
 
 efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image,
Signature · 1 line
2.6.2
#37 lore raw

PATCH 7/13 efi/arm-init: Use read-only early mappings

In reply to Matt Fleming

From: Ard Biesheuvel <[email protected]>

The early mappings of the EFI system table contents and the UEFI memory map are read-only from the OS point of view. So map them read-only to protect them from inadvertent modification.

---
 drivers/firmware/efi/arm-init.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/firmware/efi/arm-init.c +7 -7
index 9e15d571b53c..aa1f743152a2 100644
@@ -61,8 +61,8 @@ static int __init uefi_init(void)
 	char vendor[100] = "unknown";
 	int i, retval;
 
-	efi.systab = early_memremap(efi_system_table,
-				    sizeof(efi_system_table_t));
+	efi.systab = early_memremap_ro(efi_system_table,
+				       sizeof(efi_system_table_t));
 	if (efi.systab == NULL) {
 		pr_warn("Unable to map EFI system table.\n");
 		return -ENOMEM;
@@ -86,8 +86,8 @@ static int __init uefi_init(void)
 			efi.systab->hdr.revision & 0xffff);
 
 	/* Show what we know for posterity */
-	c16 = early_memremap(efi_to_phys(efi.systab->fw_vendor),
-			     sizeof(vendor) * sizeof(efi_char16_t));
+	c16 = early_memremap_ro(efi_to_phys(efi.systab->fw_vendor),
+				sizeof(vendor) * sizeof(efi_char16_t));
 	if (c16) {
 		for (i = 0; i < (int) sizeof(vendor) - 1 && *c16; ++i)
 			vendor[i] = c16[i];
@@ -100,8 +100,8 @@ static int __init uefi_init(void)
 		efi.systab->hdr.revision & 0xffff, vendor);
 
 	table_size = sizeof(efi_config_table_64_t) * efi.systab->nr_tables;
-	config_tables = early_memremap(efi_to_phys(efi.systab->tables),
-				       table_size);
+	config_tables = early_memremap_ro(efi_to_phys(efi.systab->tables),
+					  table_size);
 	if (config_tables == NULL) {
 		pr_warn("Unable to map EFI config table array.\n");
 		retval = -ENOMEM;
@@ -185,7 +185,7 @@ void __init efi_init(void)
 	efi_system_table = params.system_table;
 
 	memmap.phys_map = params.mmap;
-	memmap.map = early_memremap(params.mmap, params.mmap_size);
+	memmap.map = early_memremap_ro(params.mmap, params.mmap_size);
 	if (memmap.map == NULL) {
 		/*
 		* If we are booting via UEFI, the UEFI memory map is the only
Signature · 1 line
2.6.2
#39 lore raw

PATCH 8/13 efi/arm: Check for LPAE support before booting a LPAE kernel

In reply to Matt Fleming

From: Ard Biesheuvel <[email protected]>

A kernel built with support for LPAE cannot boot to a state where it can inform the user about it if it fails due to missing LPAE support in the hardware.

If we happen to be booting via UEFI, we can fail gracefully so check for LPAE support in the hardware on CONFIG_ARM_LPAE builds before entering the kernel proper.

---
 drivers/firmware/efi/libstub/arm32-stub.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/firmware/efi/libstub/arm32-stub.c +17 -0
index 495ebd657e38..6f42be4d0084 100644
@@ -9,6 +9,23 @@
 #include <linux/efi.h>
 #include <asm/efi.h>
 
+efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)
+{
+	int block;
+
+	/* non-LPAE kernels can run anywhere */
+	if (!IS_ENABLED(CONFIG_ARM_LPAE))
+		return EFI_SUCCESS;
+
+	/* LPAE kernels need compatible hardware */
+	block = cpuid_feature_extract(CPUID_EXT_MMFR0, 0);
+	if (block < 5) {
+		pr_efi_err(sys_table_arg, "This LPAE kernel is not supported by your CPU\n");
+		return EFI_UNSUPPORTED;
+	}
+	return EFI_SUCCESS;
+}
+
 efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
 				 unsigned long *image_addr,
 				 unsigned long *image_size,
Signature · 1 line
2.6.2
#41 lore raw

PATCH 9/13 efi/arm64: Check for h/w support before booting a >4 KB granule kernel

In reply to Matt Fleming

From: Ard Biesheuvel <[email protected]>

A kernel built with support for a page size that is not supported by the hardware it runs on cannot boot to a state where it can inform the user about it.

If we happen to be booting via UEFI, we can fail gracefully so check if the currently configured page size is supported by the hardware before entering the kernel proper. Note that UEFI mandates support for 4 KB pages, so in that case, no check is needed.

---
 drivers/firmware/efi/libstub/arm64-stub.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/firmware/efi/libstub/arm64-stub.c +20 -0
index 9e0342745e4f..aef04ad60e0d 100644
@@ -12,6 +12,26 @@
 #include <linux/efi.h>
 #include <asm/efi.h>
 #include <asm/sections.h>
+#include <asm/sysreg.h>
+
+efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)
+{
+	u64 tg;
+
+	/* UEFI mandates support for 4 KB granule, no need to check */
+	if (IS_ENABLED(CONFIG_ARM64_4K_PAGES))
+		return EFI_SUCCESS;
+
+	tg = (read_cpuid(ID_AA64MMFR0_EL1) >> ID_AA64MMFR0_TGRAN_SHIFT) & 0xf;
+	if (tg != ID_AA64MMFR0_TGRAN_SUPPORTED) {
+		if (IS_ENABLED(CONFIG_ARM64_64K_PAGES))
+			pr_efi_err(sys_table_arg, "This 64 KB granule kernel is not supported by your CPU\n");
+		else
+			pr_efi_err(sys_table_arg, "This 16 KB granule kernel is not supported by your CPU\n");
+		return EFI_UNSUPPORTED;
+	}
+	return EFI_SUCCESS;
+}
 
 efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 				 unsigned long *image_addr,
Signature · 1 line
2.6.2
#43 lore raw

Re: [PATCH 09/13] efi/arm64: Check for h/w support before booting a >4 KB granule kernel

In reply to Matt Fleming
Quoted 11 lines · Matt Fleming

From: Ard Biesheuvel <[email protected]>

A kernel built with support for a page size that is not supported by the hardware it runs on cannot boot to a state where it can inform the user about it.

If we happen to be booting via UEFI, we can fail gracefully so check if the currently configured page size is supported by the hardware before entering the kernel proper. Note that UEFI mandates support for 4 KB pages, so in that case, no check is needed.

Quoted 5 lines

Hi Matt,

This patch turned up in -next with 'granule' replaced with 'granular', both in the commit log and in the patch itself. The term 'granule' is part of the idiom used by the ARM Architecture Reference Manual, and so changing it silently to 'granular' is not entirely appropriate here (although harmless in practice, obviously). In general, I would appreciate it if in the future, such changes were not made silently somewhere in the merge pipeline.

Thanks,
Ard.

Quoted 38 lines
---
 drivers/firmware/efi/libstub/arm64-stub.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/firmware/efi/libstub/arm64-stub.c +20 -1
index 9e0342745e4f..aef04ad60e0d 100644
@@ -12,6 +12,26 @@
 #include <linux/efi.h>
 #include <asm/efi.h>
 #include <asm/sections.h>
+#include <asm/sysreg.h>
+
+efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)
+{
+       u64 tg;
+
+       /* UEFI mandates support for 4 KB granule, no need to check */
+       if (IS_ENABLED(CONFIG_ARM64_4K_PAGES))
+               return EFI_SUCCESS;
+
+       tg = (read_cpuid(ID_AA64MMFR0_EL1) >> ID_AA64MMFR0_TGRAN_SHIFT) & 0xf;
+       if (tg != ID_AA64MMFR0_TGRAN_SUPPORTED) {
+               if (IS_ENABLED(CONFIG_ARM64_64K_PAGES))
+                       pr_efi_err(sys_table_arg, "This 64 KB granule kernel is not supported by your CPU\n");
+               else
+                       pr_efi_err(sys_table_arg, "This 16 KB granule kernel is not supported by your CPU\n");
+               return EFI_UNSUPPORTED;
+       }
+       return EFI_SUCCESS;
+}
 
 efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
                                 unsigned long *image_addr,
--

2.6.2

#44 lore raw

Re: [PATCH 09/13] efi/arm64: Check for h/w support before booting a >4 KB granule kernel

Quoted 10 lines · Ard Biesheuvel

Hi Matt,

This patch turned up in -next with 'granule' replaced with 'granular', both in the commit log and in the patch itself. The term 'granule' is part of the idiom used by the ARM Architecture Reference Manual, and so changing it silently to 'granular' is not entirely appropriate here (although harmless in practice, obviously). In general, I would appreciate it if in the future, such changes were not made silently somewhere in the merge pipeline.

Sorry about this Ard. I'll make sure this doesn't happen again in future.

Ingo, is there any chance we can fixup this patch in-place and revert back to the original wording before it gets to Linus' during the merge window?

#45 lore raw

Re: [PATCH 09/13] efi/arm64: Check for h/w support before booting a >4 KB granule kernel

Quoted 12 lines · Matt Fleming
Quoted 10 lines · Ard Biesheuvel

Hi Matt,

This patch turned up in -next with 'granule' replaced with 'granular', both in the commit log and in the patch itself. The term 'granule' is part of the idiom used by the ARM Architecture Reference Manual, and so changing it silently to 'granular' is not entirely appropriate here (although harmless in practice, obviously). In general, I would appreciate it if in the future, such changes were not made silently somewhere in the merge pipeline.

Quoted 3 lines

Sorry about this Ard. I'll make sure this doesn't happen again in future.

Thanks

Quoted 3 lines

Ingo, is there any chance we can fixup this patch in-place and revert back to the original wording before it gets to Linus' during the merge window?

To be honest, I don't care deeply about the commit log, as long as the code changes are reverted.

Thanks,
Ard.

#46 lore raw

PATCH 10/13 efi/arm*: Perform hardware compatibility check

In reply to Matt Fleming

From: Ard Biesheuvel <[email protected]>

Before proceeding with relocating the kernel and parsing the command line, insert a call to check_platform_features() to allow an arch specific check to be performed whether the current kernel can execute on the current hardware.

---
 drivers/firmware/efi/libstub/arm-stub.c | 4 ++++
 drivers/firmware/efi/libstub/efistub.h  | 2 ++
 2 files changed, 6 insertions(+)
drivers/firmware/efi/libstub/arm-stub.c +4 -0
index 3397902e4040..6086a874fa3c 100644
@@ -190,6 +190,10 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
 
 	pr_efi(sys_table, "Booting Linux Kernel...\n");
 
+	status = check_platform_features(sys_table);
+	if (status != EFI_SUCCESS)
+		goto fail;
+
 	/*
 	 * Get a handle to the loaded image protocol.  This is used to get
 	 * information about the running image, such as size and the command
drivers/firmware/efi/libstub/efistub.h +2 -0
index 86ff7bfa6ace..981c6035ce09 100644
@@ -53,4 +53,6 @@ void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
 		     unsigned long desc_size, efi_memory_desc_t *runtime_map,
 		     int *count);
 
+efi_status_t check_platform_features(efi_system_table_t *sys_table_arg);
+
 #endif
Signature · 1 line
2.6.2
#48 lore raw

PATCH 11/13 x86/mm/pageattr: Don't implicitly allow _PAGE_RW in kernel_map_pages_in_pgd()

In reply to Matt Fleming

From: Sai Praneeth <[email protected]>

As part of the preparation for the EFI_MEMORY_RO flag added in the UEFI 2.5 specification, we need the ability to map pages in kernel page tables without _PAGE_RW being set.

Modify kernel_map_pages_in_pgd() to require its callers to pass _PAGE_RW if the pages need to be mapped read/write. Otherwise, we'll map the pages as read-only.

Cc Borislav Petkov <[email protected]>
Cc "Lee, Chun-Yi" <[email protected]>
Cc Ricardo Neri <[email protected]>
Cc Ravi Shankar <[email protected]>
---
 arch/x86/mm/pageattr.c         | 3 +++
 arch/x86/platform/efi/efi_64.c | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
arch/x86/mm/pageattr.c +3 -0
index bf312da41a6d..14c38ae80409 100644
@@ -1971,6 +1971,9 @@ int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
 	if (!(page_flags & _PAGE_NX))
 		cpa.mask_clr = __pgprot(_PAGE_NX);
 
+	if (!(page_flags & _PAGE_RW))
+		cpa.mask_clr = __pgprot(_PAGE_RW);
+
 	cpa.mask_set = __pgprot(_PAGE_PRESENT | page_flags);
 
 	retval = __change_page_attr_set_clr(&cpa, 0);
arch/x86/platform/efi/efi_64.c +4 -4
index b492521503fe..b0965b27e47f 100644
@@ -233,7 +233,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
 	 * phys_efi_set_virtual_address_map().
 	 */
 	pfn = pa_memmap >> PAGE_SHIFT;
-	if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, _PAGE_NX)) {
+	if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, _PAGE_NX | _PAGE_RW)) {
 		pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap);
 		return 1;
 	}
@@ -262,7 +262,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
 		pfn = md->phys_addr >> PAGE_SHIFT;
 		npages = md->num_pages;
 
-		if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, npages, 0)) {
+		if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, npages, _PAGE_RW)) {
 			pr_err("Failed to map 1:1 memory\n");
 			return 1;
 		}
@@ -279,7 +279,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
 	text = __pa(_text);
 	pfn = text >> PAGE_SHIFT;
 
-	if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, 0)) {
+	if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, _PAGE_RW)) {
 		pr_err("Failed to map kernel text 1:1\n");
 		return 1;
 	}
@@ -294,7 +294,7 @@ void __init efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages)
 
 static void __init __map_region(efi_memory_desc_t *md, u64 va)
 {
-	unsigned long flags = 0;
+	unsigned long flags = _PAGE_RW;
 	unsigned long pfn;
 	pgd_t *pgd = efi_pgd;
 
Signature · 1 line
2.6.2
#50 lore raw

PATCH 12/13 x86/efi: Map EFI_MEMORY_{XP,RO} memory region bits to EFI page tables

In reply to Matt Fleming

From: Sai Praneeth <[email protected]>

Now that we have EFI memory region bits that indicate which regions do not need execute permission or read/write permission in the page tables, let's use them.

We also check for EFI_NX_PE_DATA and only enforce the restrictive mappings if it's present (to allow us to ignore buggy firmware that sets bits it didn't mean to and to preserve backwards compatibility).

Instead of assuming that firmware would set appropriate attributes in memory descriptor like EFI_MEMORY_RO for code and EFI_MEMORY_XP for data, we can expect some firmware out there which might only set *type* in memory descriptor to be EFI_RUNTIME_SERVICES_CODE or EFI_RUNTIME_SERVICES_DATA leaving away attribute. This will lead to improper mappings of EFI runtime regions. In order to avoid it, we check attribute and type of memory descriptor to update mappings and moreover Windows works this way.

Cc Borislav Petkov <[email protected]>
Cc "Lee, Chun-Yi" <[email protected]>
Cc Ricardo Neri <[email protected]>
Cc Ravi Shankar <[email protected]>
Cc Ard Biesheuvel <[email protected]>
---
 arch/x86/include/asm/efi.h     |  2 +-
 arch/x86/platform/efi/efi.c    |  9 +++++++--
 arch/x86/platform/efi/efi_32.c |  2 +-
 arch/x86/platform/efi/efi_64.c | 45 ++++++++++++++++++++++++++++++++++++++----
 4 files changed, 50 insertions(+), 8 deletions(-)
arch/x86/include/asm/efi.h +1 -1
index 8fd9e637629a..7bb206f73915 100644
@@ -141,7 +141,7 @@ extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pa
 extern void __init efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
 extern void __init old_map_region(efi_memory_desc_t *md);
 extern void __init runtime_code_page_mkexec(void);
-extern void __init efi_runtime_mkexec(void);
+extern void __init efi_runtime_update_mappings(void);
 extern void __init efi_dump_pagetable(void);
 extern void __init efi_apply_memmap_quirks(void);
 extern int __init efi_reuse_config(u64 tables, int nr_tables);
arch/x86/platform/efi/efi.c +7 -2
index e80826e6f3a9..994a7df84a7b 100644
@@ -934,7 +934,6 @@ static void __init __efi_enter_virtual_mode(void)
 	}
 
 	efi_sync_low_kernel_mappings();
-	efi_dump_pagetable();
 
 	if (efi_is_native()) {
 		status = phys_efi_set_virtual_address_map(
@@ -972,7 +971,13 @@ static void __init __efi_enter_virtual_mode(void)
 
 	efi.set_virtual_address_map = NULL;
 
-	efi_runtime_mkexec();
+	/*
+	 * Apply more restrictive page table mapping attributes now that
+	 * SVAM() has been called and the firmware has performed all
+	 * necessary relocation fixups for the new virtual addresses.
+	 */
+	efi_runtime_update_mappings();
+	efi_dump_pagetable();
 
 	/*
 	 * We mapped the descriptor array into the EFI pagetable above
arch/x86/platform/efi/efi_32.c +1 -1
index 58d669bc8250..338402b91d2e 100644
@@ -90,7 +90,7 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd)
 	__flush_tlb_all();
 }
 
-void __init efi_runtime_mkexec(void)
+void __init efi_runtime_update_mappings(void)
 {
 	if (__supported_pte_mask & _PAGE_NX)
 		runtime_code_page_mkexec();
arch/x86/platform/efi/efi_64.c +41 -4

54 lines not on this page · raw message

Signature · 1 line
2.6.2
#52 lore raw

PATCH 13/13 x86/efi: Only map kernel text for EFI mixed mode

In reply to Matt Fleming

From: Sai Praneeth <[email protected]>

The correct symbol to use when figuring out the size of the kernel text is '_etext', not '_end' which is the symbol for the entire kernel image includes data and debug sections.

---
 arch/x86/platform/efi/efi_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/platform/efi/efi_64.c +1 -1
index 40d2f447a9dd..49e4dd4a1f58 100644
@@ -275,7 +275,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
 	efi_scratch.phys_stack = virt_to_phys(page_address(page));
 	efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */
 
-	npages = (_end - _text) >> PAGE_SHIFT;
+	npages = (_etext - _text) >> PAGE_SHIFT;
 	text = __pa(_text);
 	pfn = text >> PAGE_SHIFT;
 
Signature · 1 line
2.6.2