Skip to contentSkip to conversation

x86/mm: Fix PAGE_KERNEL_IO removal breakage

PATCH Applied Joerg Roedel 5 participants 10 messages Dec 2, 2021 – Dec 3, 2021

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

PATCH 1/1 x86/mm: Fix PAGE_KERNEL_IO removal breakage

From: Joerg Roedel <[email protected]>

The removal of PAGE_KERNEL_IO broke SEV-ES because it changed the mapping of ioremap and some fixmap areas (like the local APIC page) from unencrypted to encrypted. Change those mappings back to be unencrypted.

Cc Lucas De Marchi <[email protected]>
Fixes 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
---
 arch/x86/include/asm/fixmap.h        |  2 +-
 arch/x86/include/asm/pgtable_types.h | 21 +++++++++++----------
 arch/x86/mm/ioremap.c                |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
index 5e186a69db10..a2eaf265f784 100644
@@ -173,7 +173,7 @@ static inline void __set_fixmap(enum fixed_addresses idx,
  * supported for MMIO addresses, so make sure that the memory encryption
  * mask is not part of the page attributes.
  */
-#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
+#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE_NOENC
 
 /*
  * Early memremap routines used for in-place encryption. The mappings created
arch/x86/include/asm/pgtable_types.h +11 -10
index a87224767ff3..fc9b6995cb22 100644
@@ -208,16 +208,17 @@ enum page_cache_mode {
 
 #define __pgprot_mask(x)	__pgprot((x) & __default_kernel_pte_mask)
 
-#define PAGE_KERNEL		__pgprot_mask(__PAGE_KERNEL            | _ENC)
-#define PAGE_KERNEL_NOENC	__pgprot_mask(__PAGE_KERNEL            |    0)
-#define PAGE_KERNEL_RO		__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
-#define PAGE_KERNEL_EXEC	__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
-#define PAGE_KERNEL_EXEC_NOENC	__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
-#define PAGE_KERNEL_ROX		__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
-#define PAGE_KERNEL_NOCACHE	__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
-#define PAGE_KERNEL_LARGE	__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
-#define PAGE_KERNEL_LARGE_EXEC	__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
-#define PAGE_KERNEL_VVAR	__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
+#define PAGE_KERNEL			__pgprot_mask(__PAGE_KERNEL            | _ENC)
+#define PAGE_KERNEL_NOENC		__pgprot_mask(__PAGE_KERNEL            |    0)
+#define PAGE_KERNEL_RO			__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
+#define PAGE_KERNEL_EXEC		__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
+#define PAGE_KERNEL_EXEC_NOENC		__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
+#define PAGE_KERNEL_ROX			__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
+#define PAGE_KERNEL_NOCACHE		__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
+#define PAGE_KERNEL_NOCACHE_NOENC	__pgprot_mask(__PAGE_KERNEL_NOCACHE    |    0)
+#define PAGE_KERNEL_LARGE		__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
+#define PAGE_KERNEL_LARGE_EXEC		__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
+#define PAGE_KERNEL_VVAR		__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
 
 #endif	/* __ASSEMBLY__ */
 
arch/x86/mm/ioremap.c +1 -1
index 3102dda4b152..4fe8d43d53bb 100644
@@ -243,7 +243,7 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
 	 * make sure the memory encryption attribute is enabled in the
 	 * resulting mapping.
 	 */
-	prot = PAGE_KERNEL;
+	prot = PAGE_KERNEL_NOENC;
 	if ((io_desc.flags & IORES_MAP_ENCRYPTED) || encrypted)
 		prot = pgprot_encrypted(prot);
 
Signature · 1 line
2.34.0
Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The removal of PAGE_KERNEL_IO broke SEV-ES because it changed the mapping of ioremap and some fixmap areas (like the local APIC page) from unencrypted to encrypted. Change those mappings back to be unencrypted.

SME was also broken and I can verify this patch fixes SME, too.

Thanks,
Tom

Quoted 69 lines
Cc Lucas De Marchi <[email protected]>
Fixes 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
---
  arch/x86/include/asm/fixmap.h        |  2 +-
  arch/x86/include/asm/pgtable_types.h | 21 +++++++++++----------
  arch/x86/mm/ioremap.c                |  2 +-
  3 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
index 5e186a69db10..a2eaf265f784 100644
@@ -173,7 +173,7 @@ static inline void __set_fixmap(enum fixed_addresses idx,
   * supported for MMIO addresses, so make sure that the memory encryption
   * mask is not part of the page attributes.
   */
-#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
+#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE_NOENC
 
  /*
   * Early memremap routines used for in-place encryption. The mappings created
arch/x86/include/asm/pgtable_types.h +11 -10
index a87224767ff3..fc9b6995cb22 100644
@@ -208,16 +208,17 @@ enum page_cache_mode {
 
  #define __pgprot_mask(x)	__pgprot((x) & __default_kernel_pte_mask)
 
-#define PAGE_KERNEL		__pgprot_mask(__PAGE_KERNEL            | _ENC)
-#define PAGE_KERNEL_NOENC	__pgprot_mask(__PAGE_KERNEL            |    0)
-#define PAGE_KERNEL_RO		__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
-#define PAGE_KERNEL_EXEC	__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
-#define PAGE_KERNEL_EXEC_NOENC	__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
-#define PAGE_KERNEL_ROX		__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
-#define PAGE_KERNEL_NOCACHE	__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
-#define PAGE_KERNEL_LARGE	__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
-#define PAGE_KERNEL_LARGE_EXEC	__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
-#define PAGE_KERNEL_VVAR	__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
+#define PAGE_KERNEL			__pgprot_mask(__PAGE_KERNEL            | _ENC)
+#define PAGE_KERNEL_NOENC		__pgprot_mask(__PAGE_KERNEL            |    0)
+#define PAGE_KERNEL_RO			__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
+#define PAGE_KERNEL_EXEC		__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
+#define PAGE_KERNEL_EXEC_NOENC		__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
+#define PAGE_KERNEL_ROX			__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
+#define PAGE_KERNEL_NOCACHE		__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
+#define PAGE_KERNEL_NOCACHE_NOENC	__pgprot_mask(__PAGE_KERNEL_NOCACHE    |    0)
+#define PAGE_KERNEL_LARGE		__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
+#define PAGE_KERNEL_LARGE_EXEC		__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
+#define PAGE_KERNEL_VVAR		__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
 
  #endif	/* __ASSEMBLY__ */
 
arch/x86/mm/ioremap.c +1 -1
index 3102dda4b152..4fe8d43d53bb 100644
@@ -243,7 +243,7 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
  	 * make sure the memory encryption attribute is enabled in the
  	 * resulting mapping.
  	 */
-	prot = PAGE_KERNEL;
+	prot = PAGE_KERNEL_NOENC;
  	if ((io_desc.flags & IORES_MAP_ENCRYPTED) || encrypted)
  		prot = pgprot_encrypted(prot);
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Joerg Roedel
Quoted 10 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The removal of PAGE_KERNEL_IO broke SEV-ES because it changed the mapping of ioremap and some fixmap areas (like the local APIC page) from unencrypted to encrypted. Change those mappings back to be unencrypted.

Cc Lucas De Marchi <[email protected]>
Fixes 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")

oops, missed the fact PAGE_KERNEL had | ENC while PAGE_KERENL_IO didn't have it. Thanks for the fixup.

Lucas De Marchi

Quoted 67 lines

---

arch/x86/include/asm/fixmap.h        |  2 +-
arch/x86/include/asm/pgtable_types.h | 21 +++++++++++----------
arch/x86/mm/ioremap.c                |  2 +-
3 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
index 5e186a69db10..a2eaf265f784 100644
@@ -173,7 +173,7 @@ static inline void __set_fixmap(enum fixed_addresses idx,
 * supported for MMIO addresses, so make sure that the memory encryption
 * mask is not part of the page attributes.
 */
-#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
+#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE_NOENC
 
 /*
 * Early memremap routines used for in-place encryption. The mappings created
arch/x86/include/asm/pgtable_types.h +11 -10
index a87224767ff3..fc9b6995cb22 100644
@@ -208,16 +208,17 @@ enum page_cache_mode {
 
 #define __pgprot_mask(x)	__pgprot((x) & __default_kernel_pte_mask)
 
-#define PAGE_KERNEL		__pgprot_mask(__PAGE_KERNEL            | _ENC)
-#define PAGE_KERNEL_NOENC	__pgprot_mask(__PAGE_KERNEL            |    0)
-#define PAGE_KERNEL_RO		__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
-#define PAGE_KERNEL_EXEC	__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
-#define PAGE_KERNEL_EXEC_NOENC	__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
-#define PAGE_KERNEL_ROX		__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
-#define PAGE_KERNEL_NOCACHE	__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
-#define PAGE_KERNEL_LARGE	__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
-#define PAGE_KERNEL_LARGE_EXEC	__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
-#define PAGE_KERNEL_VVAR	__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
+#define PAGE_KERNEL			__pgprot_mask(__PAGE_KERNEL            | _ENC)
+#define PAGE_KERNEL_NOENC		__pgprot_mask(__PAGE_KERNEL            |    0)
+#define PAGE_KERNEL_RO			__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
+#define PAGE_KERNEL_EXEC		__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
+#define PAGE_KERNEL_EXEC_NOENC		__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
+#define PAGE_KERNEL_ROX			__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
+#define PAGE_KERNEL_NOCACHE		__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
+#define PAGE_KERNEL_NOCACHE_NOENC	__pgprot_mask(__PAGE_KERNEL_NOCACHE    |    0)
+#define PAGE_KERNEL_LARGE		__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
+#define PAGE_KERNEL_LARGE_EXEC		__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
+#define PAGE_KERNEL_VVAR		__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
 
 #endif	/* __ASSEMBLY__ */
 
arch/x86/mm/ioremap.c +1 -1
index 3102dda4b152..4fe8d43d53bb 100644
@@ -243,7 +243,7 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
 	 * make sure the memory encryption attribute is enabled in the
 	 * resulting mapping.
 	 */
-	prot = PAGE_KERNEL;
+	prot = PAGE_KERNEL_NOENC;
 	if ((io_desc.flags & IORES_MAP_ENCRYPTED) || encrypted)
 		prot = pgprot_encrypted(prot);
 
Signature · 1 line
2.34.0
#3 lore raw
Quoted 8 lines · Lucas De Marchi
Quoted 7 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The removal of PAGE_KERNEL_IO broke SEV-ES because it changed the mapping of ioremap and some fixmap areas (like the local APIC page) from unencrypted to encrypted. Change those mappings back to be unencrypted.

Quoted 6 lines
Quoted 3 lines
Cc Lucas De Marchi <[email protected]>
Fixes 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")

oops, missed the fact PAGE_KERNEL had | ENC while PAGE_KERENL_IO didn't have it. Thanks for the fixup.

on a second thought, the fact that PAGE_KERNEL is _not_ the same as PAGE_KERNEL_IO, completely invalidates those 2 patches I sent. It seems I screwed it up big here.

About the first patch,
6b2a2138cf36 ("drm/i915/gem: Stop using PAGE_KERNEL_IO"), I didn't notice any regression on the i915
side though. Is it safe to keep it? Otherwise we are probably better off reverting everything.

I'm wondering why the addition of memory encryption
in 21729f81ce8a ("x86/mm: Provide general kernel support for memory encryption") didn't break io_mapping_init_wc() though as it had already done a s/PAGE_KERNEL_IO/PAGE_KERNEL/ in commit
ac96b5566926 ("io-mapping.h: s/PAGE_KERNEL_IO/PAGE_KERNEL/")

thanks
Lucas De Marchi

Quoted 72 lines

Lucas De Marchi

Quoted 67 lines

---

arch/x86/include/asm/fixmap.h        |  2 +-
arch/x86/include/asm/pgtable_types.h | 21 +++++++++++----------
arch/x86/mm/ioremap.c                |  2 +-
3 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
index 5e186a69db10..a2eaf265f784 100644
@@ -173,7 +173,7 @@ static inline void __set_fixmap(enum fixed_addresses idx,
 * supported for MMIO addresses, so make sure that the memory encryption
 * mask is not part of the page attributes.
 */
-#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
+#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE_NOENC
 
 /*
 * Early memremap routines used for in-place encryption. The mappings created
arch/x86/include/asm/pgtable_types.h +11 -10
index a87224767ff3..fc9b6995cb22 100644
@@ -208,16 +208,17 @@ enum page_cache_mode {
 
 #define __pgprot_mask(x)	__pgprot((x) & __default_kernel_pte_mask)
 
-#define PAGE_KERNEL		__pgprot_mask(__PAGE_KERNEL            | _ENC)
-#define PAGE_KERNEL_NOENC	__pgprot_mask(__PAGE_KERNEL            |    0)
-#define PAGE_KERNEL_RO		__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
-#define PAGE_KERNEL_EXEC	__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
-#define PAGE_KERNEL_EXEC_NOENC	__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
-#define PAGE_KERNEL_ROX		__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
-#define PAGE_KERNEL_NOCACHE	__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
-#define PAGE_KERNEL_LARGE	__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
-#define PAGE_KERNEL_LARGE_EXEC	__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
-#define PAGE_KERNEL_VVAR	__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
+#define PAGE_KERNEL			__pgprot_mask(__PAGE_KERNEL            | _ENC)
+#define PAGE_KERNEL_NOENC		__pgprot_mask(__PAGE_KERNEL            |    0)
+#define PAGE_KERNEL_RO			__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
+#define PAGE_KERNEL_EXEC		__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
+#define PAGE_KERNEL_EXEC_NOENC		__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
+#define PAGE_KERNEL_ROX			__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
+#define PAGE_KERNEL_NOCACHE		__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
+#define PAGE_KERNEL_NOCACHE_NOENC	__pgprot_mask(__PAGE_KERNEL_NOCACHE    |    0)
+#define PAGE_KERNEL_LARGE		__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
+#define PAGE_KERNEL_LARGE_EXEC		__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
+#define PAGE_KERNEL_VVAR		__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
 
 #endif	/* __ASSEMBLY__ */
 
arch/x86/mm/ioremap.c +1 -1
index 3102dda4b152..4fe8d43d53bb 100644
@@ -243,7 +243,7 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
 	 * make sure the memory encryption attribute is enabled in the
 	 * resulting mapping.
 	 */
-	prot = PAGE_KERNEL;
+	prot = PAGE_KERNEL_NOENC;
 	if ((io_desc.flags & IORES_MAP_ENCRYPTED) || encrypted)
 		prot = pgprot_encrypted(prot);
 
Signature · 1 line
2.34.0
#4 lore raw
Quoted 26 lines · Lucas De Marchi
Quoted 8 lines · Lucas De Marchi
Quoted 7 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The removal of PAGE_KERNEL_IO broke SEV-ES because it changed the mapping of ioremap and some fixmap areas (like the local APIC page) from unencrypted to encrypted. Change those mappings back to be unencrypted.

Quoted 6 lines
Quoted 3 lines
Cc Lucas De Marchi <[email protected]>
Fixes 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")

oops, missed the fact PAGE_KERNEL had | ENC while PAGE_KERENL_IO didn't have it. Thanks for the fixup.

on a second thought, the fact that PAGE_KERNEL is _not_ the same as PAGE_KERNEL_IO, completely invalidates those 2 patches I sent. It seems I screwed it up big here.

About the first patch,
6b2a2138cf36 ("drm/i915/gem: Stop using PAGE_KERNEL_IO"), I didn't notice any regression on the i915
side though. Is it safe to keep it? Otherwise we are probably better off reverting everything.

Quoted 5 lines

I'm wondering why the addition of memory encryption
in 21729f81ce8a ("x86/mm: Provide general kernel support for memory encryption") didn't break io_mapping_init_wc() though as it had already done a s/PAGE_KERNEL_IO/PAGE_KERNEL/ in commit
ac96b5566926 ("io-mapping.h: s/PAGE_KERNEL_IO/PAGE_KERNEL/")

If I follow it correctly, since SME/SEV-ES are X86_64 only, io_mapping_init_wc() takes the ioremap_wc() path which uses PAGE_KERNEL_IO. iomap_create_wc() is only called when CONFIG_HAVE_ATOMIC_IOMAP is set, which isn't set for X86_64.

Thanks,
Tom

Quoted 98 lines

thanks
Lucas De Marchi

Quoted 94 lines

Lucas De Marchi

Quoted 89 lines

---
arch/x86/include/asm/fixmap.h        |  2 +- arch/x86/include/asm/pgtable_types.h | 21 +++++++++++---------- arch/x86/mm/ioremap.c                |  2 +-

3 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
index 5e186a69db10..a2eaf265f784 100644
@@ -173,7 +173,7 @@ static inline void __set_fixmap(enum 
 fixed_addresses idx,
 * supported for MMIO addresses, so make sure that the memory encryption
 * mask is not part of the page attributes.
 */
-#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
+#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE_NOENC
 
 /*

* Early memremap routines used for in-place encryption. The mappings created

arch/x86/include/asm/pgtable_types.h +0 -8
index a87224767ff3..fc9b6995cb22 100644
@@ -208,16 +208,17 @@ enum page_cache_mode {
 
 #define __pgprot_mask(x)    __pgprot((x) & __default_kernel_pte_mask)
 
-#define PAGE_KERNEL        __pgprot_mask(__PAGE_KERNEL            | _ENC)
-#define PAGE_KERNEL_NOENC    __pgprot_mask(__PAGE_KERNEL            
 |    0)
-#define PAGE_KERNEL_RO        __pgprot_mask(__PAGE_KERNEL_RO         | 
 _ENC)
-#define PAGE_KERNEL_EXEC    __pgprot_mask(__PAGE_KERNEL_EXEC       | 
 _ENC)
-#define PAGE_KERNEL_EXEC_NOENC    
 __pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
-#define PAGE_KERNEL_ROX        __pgprot_mask(__PAGE_KERNEL_ROX        
 | _ENC)
-#define PAGE_KERNEL_NOCACHE    __pgprot_mask(__PAGE_KERNEL_NOCACHE    
 | _ENC)
-#define PAGE_KERNEL_LARGE    __pgprot_mask(__PAGE_KERNEL_LARGE      | 

_ENC)
-#define PAGE_KERNEL_LARGE_EXEC __pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
-#define PAGE_KERNEL_VVAR    __pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
+#define PAGE_KERNEL            __pgprot_mask(__PAGE_KERNEL | _ENC)
+#define PAGE_KERNEL_NOENC
__pgprot_mask(__PAGE_KERNEL            |    0)
+#define PAGE_KERNEL_RO
__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
+#define PAGE_KERNEL_EXEC        __pgprot_mask(__PAGE_KERNEL_EXEC | _ENC)
+#define PAGE_KERNEL_EXEC_NOENC __pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
+#define PAGE_KERNEL_ROX
__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
+#define PAGE_KERNEL_NOCACHE __pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
+#define PAGE_KERNEL_NOCACHE_NOENC __pgprot_mask(__PAGE_KERNEL_NOCACHE    |    0)
+#define PAGE_KERNEL_LARGE __pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
+#define PAGE_KERNEL_LARGE_EXEC __pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
+#define PAGE_KERNEL_VVAR        __pgprot_mask(__PAGE_KERNEL_VVAR | _ENC)

#endif    /* __ASSEMBLY__ */

arch/x86/mm/ioremap.c +1 -1
index 3102dda4b152..4fe8d43d53bb 100644
@@ -243,7 +243,7 @@ __ioremap_caller(resource_size_t phys_addr, 
 unsigned long size,
      * make sure the memory encryption attribute is enabled in the
      * resulting mapping.
      */
-    prot = PAGE_KERNEL;
+    prot = PAGE_KERNEL_NOENC;
     if ((io_desc.flags & IORES_MAP_ENCRYPTED) || encrypted)
         prot = pgprot_encrypted(prot);
Signature · 2 lines
-- 
2.34.0
#5 lore raw
Quoted 21 lines · Tom Lendacky
Quoted 20 lines · Lucas De Marchi
Quoted 8 lines · Lucas De Marchi
Quoted 7 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The removal of PAGE_KERNEL_IO broke SEV-ES because it changed the mapping of ioremap and some fixmap areas (like the local APIC page) from unencrypted to encrypted. Change those mappings back to be unencrypted.

Quoted 6 lines
Quoted 3 lines
Cc Lucas De Marchi <[email protected]>
Fixes 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")

oops, missed the fact PAGE_KERNEL had | ENC while PAGE_KERENL_IO didn't have it. Thanks for the fixup.

on a second thought, the fact that PAGE_KERNEL is _not_ the same as PAGE_KERNEL_IO, completely invalidates those 2 patches I sent. It seems I screwed it up big here.

Quoted 5 lines
Quoted 5 lines

About the first patch,
6b2a2138cf36 ("drm/i915/gem: Stop using PAGE_KERNEL_IO"), I didn't notice any regression on the i915
side though. Is it safe to keep it? Otherwise we are probably better off reverting everything.

Is i915 for just integrated graphics? In which case SME/SEV-ES aren't available on Intel.

Thanks,
Tom

Quoted 102 lines
Quoted 6 lines

I'm wondering why the addition of memory encryption
in 21729f81ce8a ("x86/mm: Provide general kernel support for memory encryption") didn't break io_mapping_init_wc() though as it had already done a s/PAGE_KERNEL_IO/PAGE_KERNEL/ in commit
ac96b5566926 ("io-mapping.h: s/PAGE_KERNEL_IO/PAGE_KERNEL/")

If I follow it correctly, since SME/SEV-ES are X86_64 only, io_mapping_init_wc() takes the ioremap_wc() path which uses PAGE_KERNEL_IO. iomap_create_wc() is only called when CONFIG_HAVE_ATOMIC_IOMAP is set, which isn't set for X86_64.

Thanks,
Tom

Quoted 90 lines

thanks
Lucas De Marchi

Quoted 86 lines

Lucas De Marchi

Quoted 81 lines

---
arch/x86/include/asm/fixmap.h        |  2 +- arch/x86/include/asm/pgtable_types.h | 21 +++++++++++---------- arch/x86/mm/ioremap.c                |  2 +-

3 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
index 5e186a69db10..a2eaf265f784 100644
@@ -173,7 +173,7 @@ static inline void __set_fixmap(enum 
 fixed_addresses idx,
 * supported for MMIO addresses, so make sure that the memory encryption
 * mask is not part of the page attributes.
 */
-#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
+#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE_NOENC
 
 /*

* Early memremap routines used for in-place encryption. The mappings created

arch/x86/include/asm/pgtable_types.h +0 -8
index a87224767ff3..fc9b6995cb22 100644
@@ -208,16 +208,17 @@ enum page_cache_mode {
 
 #define __pgprot_mask(x)    __pgprot((x) & __default_kernel_pte_mask)
 
-#define PAGE_KERNEL        __pgprot_mask(__PAGE_KERNEL            | 
 _ENC)
-#define PAGE_KERNEL_NOENC    __pgprot_mask(__PAGE_KERNEL |    0)
-#define PAGE_KERNEL_RO        __pgprot_mask(__PAGE_KERNEL_RO         
 | _ENC)
-#define PAGE_KERNEL_EXEC    __pgprot_mask(__PAGE_KERNEL_EXEC       | 
 _ENC)
-#define PAGE_KERNEL_EXEC_NOENC __pgprot_mask(__PAGE_KERNEL_EXEC       
 |    0)
-#define PAGE_KERNEL_ROX        __pgprot_mask(__PAGE_KERNEL_ROX | _ENC)
-#define PAGE_KERNEL_NOCACHE    __pgprot_mask(__PAGE_KERNEL_NOCACHE | 
 _ENC)
-#define PAGE_KERNEL_LARGE    __pgprot_mask(__PAGE_KERNEL_LARGE      | 

_ENC)
-#define PAGE_KERNEL_LARGE_EXEC __pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
-#define PAGE_KERNEL_VVAR    __pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)

arch/x86/include/asm/pgtable_types.h +5 -0
+#define PAGE_KERNEL            __pgprot_mask(__PAGE_KERNEL | _ENC)
+#define PAGE_KERNEL_NOENC __pgprot_mask(__PAGE_KERNEL            |    0)
+#define PAGE_KERNEL_RO __pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
+#define PAGE_KERNEL_EXEC        __pgprot_mask(__PAGE_KERNEL_EXEC | _ENC)
+#define PAGE_KERNEL_EXEC_NOENC __pgprot_mask(__PAGE_KERNEL_EXEC       

|    0)

arch/x86/include/asm/pgtable_types.h +2 -0
+#define PAGE_KERNEL_ROX __pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
+#define PAGE_KERNEL_NOCACHE __pgprot_mask(__PAGE_KERNEL_NOCACHE    | 

_ENC)
+#define PAGE_KERNEL_NOCACHE_NOENC
__pgprot_mask(__PAGE_KERNEL_NOCACHE    |    0)

arch/x86/include/asm/pgtable_types.h +2 -0
+#define PAGE_KERNEL_LARGE __pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
+#define PAGE_KERNEL_LARGE_EXEC __pgprot_mask(__PAGE_KERNEL_LARGE_EXEC 

| _ENC)
+#define PAGE_KERNEL_VVAR        __pgprot_mask(__PAGE_KERNEL_VVAR | _ENC)

#endif    /* __ASSEMBLY__ */

arch/x86/mm/ioremap.c +1 -1
index 3102dda4b152..4fe8d43d53bb 100644
@@ -243,7 +243,7 @@ __ioremap_caller(resource_size_t phys_addr, 
 unsigned long size,
      * make sure the memory encryption attribute is enabled in the
      * resulting mapping.
      */
-    prot = PAGE_KERNEL;
+    prot = PAGE_KERNEL_NOENC;
     if ((io_desc.flags & IORES_MAP_ENCRYPTED) || encrypted)
         prot = pgprot_encrypted(prot);
Signature · 2 lines
-- 
2.34.0
#6 lore raw
Quoted 22 lines · Tom Lendacky
Quoted 21 lines · Tom Lendacky
Quoted 20 lines · Lucas De Marchi
Quoted 8 lines · Lucas De Marchi
Quoted 7 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The removal of PAGE_KERNEL_IO broke SEV-ES because it changed the mapping of ioremap and some fixmap areas (like the local APIC page) from unencrypted to encrypted. Change those mappings back to be unencrypted.

Quoted 6 lines
Quoted 3 lines
Cc Lucas De Marchi <[email protected]>
Fixes 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")

oops, missed the fact PAGE_KERNEL had | ENC while PAGE_KERENL_IO didn't have it. Thanks for the fixup.

on a second thought, the fact that PAGE_KERNEL is _not_ the same as PAGE_KERNEL_IO, completely invalidates those 2 patches I sent. It seems I screwed it up big here.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

About the first patch,
6b2a2138cf36 ("drm/i915/gem: Stop using PAGE_KERNEL_IO"), I didn't notice any regression on the i915
side though. Is it safe to keep it? Otherwise we are probably better off reverting everything.

Is i915 for just integrated graphics? In which case SME/SEV-ES aren't available on Intel.

No, it's also for discrete graphics - so it could also be paired with an AMD cpu.

Currently the i915 driver has some assumptions about the architecture (x86/x86-64) since it used to be for integrated-only and thus Intel-only. But we are now extending it to other architectures like arm64. That's why this patch was written: I misread PAGE_KERNEL and PAGE_KERNEL_IO being the same thing nowadays, so I was switched to the one available in other archs.

thanks
Lucas De Marchi

Quoted 106 lines

Thanks,
Tom

Quoted 102 lines
Quoted 6 lines

I'm wondering why the addition of memory encryption
in 21729f81ce8a ("x86/mm: Provide general kernel support for memory encryption") didn't break io_mapping_init_wc() though as it had already done a s/PAGE_KERNEL_IO/PAGE_KERNEL/ in commit
ac96b5566926 ("io-mapping.h: s/PAGE_KERNEL_IO/PAGE_KERNEL/")

If I follow it correctly, since SME/SEV-ES are X86_64 only, io_mapping_init_wc() takes the ioremap_wc() path which uses PAGE_KERNEL_IO. iomap_create_wc() is only called when CONFIG_HAVE_ATOMIC_IOMAP is set, which isn't set for X86_64.

Thanks,
Tom

Quoted 90 lines

thanks
Lucas De Marchi

Quoted 86 lines

Lucas De Marchi

Quoted 81 lines

---
arch/x86/include/asm/fixmap.h        |  2 +- arch/x86/include/asm/pgtable_types.h | 21 +++++++++++---------- arch/x86/mm/ioremap.c                |  2 +-

3 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
index 5e186a69db10..a2eaf265f784 100644
@@ -173,7 +173,7 @@ static inline void __set_fixmap(enum 
 fixed_addresses idx,
 * supported for MMIO addresses, so make sure that the memory encryption
 * mask is not part of the page attributes.
 */
-#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
+#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE_NOENC
 
 /*

* Early memremap routines used for in-place encryption. The mappings created

arch/x86/include/asm/pgtable_types.h +0 -8
index a87224767ff3..fc9b6995cb22 100644
@@ -208,16 +208,17 @@ enum page_cache_mode {
 
 #define __pgprot_mask(x)    __pgprot((x) & __default_kernel_pte_mask)
 
-#define PAGE_KERNEL        
 __pgprot_mask(__PAGE_KERNEL            | _ENC)
-#define PAGE_KERNEL_NOENC    __pgprot_mask(__PAGE_KERNEL |    0)
-#define PAGE_KERNEL_RO        __pgprot_mask(__PAGE_KERNEL_RO         
 | _ENC)
-#define PAGE_KERNEL_EXEC    
 __pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
-#define PAGE_KERNEL_EXEC_NOENC 
 __pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
-#define PAGE_KERNEL_ROX        __pgprot_mask(__PAGE_KERNEL_ROX | _ENC)
-#define PAGE_KERNEL_NOCACHE    
 __pgprot_mask(__PAGE_KERNEL_NOCACHE | _ENC)
-#define PAGE_KERNEL_LARGE    

__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
-#define PAGE_KERNEL_LARGE_EXEC
__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
-#define PAGE_KERNEL_VVAR
__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)

arch/x86/include/asm/pgtable_types.h +5 -0
+#define PAGE_KERNEL            __pgprot_mask(__PAGE_KERNEL | _ENC)
+#define PAGE_KERNEL_NOENC __pgprot_mask(__PAGE_KERNEL            |    0)
+#define PAGE_KERNEL_RO __pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
+#define PAGE_KERNEL_EXEC        __pgprot_mask(__PAGE_KERNEL_EXEC | _ENC)
+#define PAGE_KERNEL_EXEC_NOENC 

__pgprot_mask(__PAGE_KERNEL_EXEC |    0)

arch/x86/include/asm/pgtable_types.h +2 -0
+#define PAGE_KERNEL_ROX __pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
+#define PAGE_KERNEL_NOCACHE 

__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
+#define PAGE_KERNEL_NOCACHE_NOENC
__pgprot_mask(__PAGE_KERNEL_NOCACHE    |    0)

arch/x86/include/asm/pgtable_types.h +2 -0
+#define PAGE_KERNEL_LARGE __pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
+#define PAGE_KERNEL_LARGE_EXEC 

__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
+#define PAGE_KERNEL_VVAR        __pgprot_mask(__PAGE_KERNEL_VVAR | _ENC)

#endif    /* __ASSEMBLY__ */

arch/x86/mm/ioremap.c +1 -1
index 3102dda4b152..4fe8d43d53bb 100644
@@ -243,7 +243,7 @@ __ioremap_caller(resource_size_t 
 phys_addr, unsigned long size,
      * make sure the memory encryption attribute is enabled in the
      * resulting mapping.
      */
-    prot = PAGE_KERNEL;
+    prot = PAGE_KERNEL_NOENC;
     if ((io_desc.flags & IORES_MAP_ENCRYPTED) || encrypted)
         prot = pgprot_encrypted(prot);
Signature · 2 lines
-- 
2.34.0
#7 lore raw
In reply to Lucas De Marchi
Quoted 5 lines · Lucas De Marchi

About the first patch,
6b2a2138cf36 ("drm/i915/gem: Stop using PAGE_KERNEL_IO"), I didn't notice any regression on the i915
side though. Is it safe to keep it? Otherwise we are probably better off reverting everything.

I'm just going to drop both of those for now:

	27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
	6b2a2138cf36 ("drm/i915/gem: Stop using PAGE_KERNEL_IO")

If you work out a fix, please integrate the patch from Joerg and resubmit.

#8 lore raw
Quoted 7 lines · Dave Hansen
Quoted 5 lines · Lucas De Marchi

About the first patch,
6b2a2138cf36 ("drm/i915/gem: Stop using PAGE_KERNEL_IO"), I didn't notice any regression on the i915
side though. Is it safe to keep it? Otherwise we are probably better off reverting everything.

Quoted 6 lines

I'm just going to drop both of those for now:

	27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
	6b2a2138cf36 ("drm/i915/gem: Stop using PAGE_KERNEL_IO")

If you work out a fix, please integrate the patch from Joerg and resubmit.

yeah, that seems the best approach here.

thanks
Lucas De Marchi

merge bot Applied
#9 lore raw
In reply to Joerg Roedel
The following commit has been merged into the x86/mm branch of tip:

The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     9a951429b2e1670a76b68c90880b01430fe509e4
Gitweb:        https://git.kernel.org/tip/9a951429b2e1670a76b68c90880b01430fe509e4
Author:        Joerg Roedel <[email protected]>
AuthorDate:    Thu, 02 Dec 2021 15:46:46 +01:00
Committer:     Dave Hansen <[email protected]>
CommitterDate: Thu, 02 Dec 2021 09:41:24 -08:00

x86/mm: Fix PAGE_KERNEL_IO removal breakage

The removal of PAGE_KERNEL_IO broke SEV-ES because it changed the mapping of ioremap and some fixmap areas (like the local APIC page) from unencrypted to encrypted. Change those mappings back to be unencrypted.

---
 arch/x86/include/asm/fixmap.h        |  2 +-
 arch/x86/include/asm/pgtable_types.h | 21 +++++++++++----------
 arch/x86/mm/ioremap.c                |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
index 5e186a6..a2eaf26 100644
@@ -173,7 +173,7 @@ static inline void __set_fixmap(enum fixed_addresses idx,
  * supported for MMIO addresses, so make sure that the memory encryption
  * mask is not part of the page attributes.
  */
-#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
+#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE_NOENC
 
 /*
  * Early memremap routines used for in-place encryption. The mappings created
arch/x86/include/asm/pgtable_types.h +11 -10
index a872247..fc9b699 100644
@@ -208,16 +208,17 @@ enum page_cache_mode {
 
 #define __pgprot_mask(x)	__pgprot((x) & __default_kernel_pte_mask)
 
-#define PAGE_KERNEL		__pgprot_mask(__PAGE_KERNEL            | _ENC)
-#define PAGE_KERNEL_NOENC	__pgprot_mask(__PAGE_KERNEL            |    0)
-#define PAGE_KERNEL_RO		__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
-#define PAGE_KERNEL_EXEC	__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
-#define PAGE_KERNEL_EXEC_NOENC	__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
-#define PAGE_KERNEL_ROX		__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
-#define PAGE_KERNEL_NOCACHE	__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
-#define PAGE_KERNEL_LARGE	__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
-#define PAGE_KERNEL_LARGE_EXEC	__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
-#define PAGE_KERNEL_VVAR	__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
+#define PAGE_KERNEL			__pgprot_mask(__PAGE_KERNEL            | _ENC)
+#define PAGE_KERNEL_NOENC		__pgprot_mask(__PAGE_KERNEL            |    0)
+#define PAGE_KERNEL_RO			__pgprot_mask(__PAGE_KERNEL_RO         | _ENC)
+#define PAGE_KERNEL_EXEC		__pgprot_mask(__PAGE_KERNEL_EXEC       | _ENC)
+#define PAGE_KERNEL_EXEC_NOENC		__pgprot_mask(__PAGE_KERNEL_EXEC       |    0)
+#define PAGE_KERNEL_ROX			__pgprot_mask(__PAGE_KERNEL_ROX        | _ENC)
+#define PAGE_KERNEL_NOCACHE		__pgprot_mask(__PAGE_KERNEL_NOCACHE    | _ENC)
+#define PAGE_KERNEL_NOCACHE_NOENC	__pgprot_mask(__PAGE_KERNEL_NOCACHE    |    0)
+#define PAGE_KERNEL_LARGE		__pgprot_mask(__PAGE_KERNEL_LARGE      | _ENC)
+#define PAGE_KERNEL_LARGE_EXEC		__pgprot_mask(__PAGE_KERNEL_LARGE_EXEC | _ENC)
+#define PAGE_KERNEL_VVAR		__pgprot_mask(__PAGE_KERNEL_VVAR       | _ENC)
 
 #endif	/* __ASSEMBLY__ */
 
arch/x86/mm/ioremap.c +1 -1
index 3102dda..4fe8d43 100644
@@ -243,7 +243,7 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
 	 * make sure the memory encryption attribute is enabled in the
 	 * resulting mapping.
 	 */
-	prot = PAGE_KERNEL;
+	prot = PAGE_KERNEL_NOENC;
 	if ((io_desc.flags & IORES_MAP_ENCRYPTED) || encrypted)
 		prot = pgprot_encrypted(prot);