linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
@ 2021-12-02 14:46 Joerg Roedel
  2021-12-02 15:52 ` Tom Lendacky
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Joerg Roedel @ 2021-12-02 14:46 UTC (permalink / raw)
  To: x86, Dave Hansen
  Cc: Borislav Petkov, Ingo Molnar, Thomas Gleixner, hpa,
	Andy Lutomirski, Peter Zijlstra, Tom Lendacky, Brijesh Singh,
	linux-kernel, Joerg Roedel, Lucas De Marchi

From: Joerg Roedel <jroedel@suse.de>

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 <lucas.demarchi@intel.com>
Fixes: 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 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(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index 5e186a69db10..a2eaf265f784 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -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
diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
index a87224767ff3..fc9b6995cb22 100644
--- a/arch/x86/include/asm/pgtable_types.h
+++ b/arch/x86/include/asm/pgtable_types.h
@@ -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__ */
 
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 3102dda4b152..4fe8d43d53bb 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -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);
 
-- 
2.34.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-02 14:46 [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage Joerg Roedel
@ 2021-12-02 15:52 ` Tom Lendacky
  2021-12-02 15:55 ` Lucas De Marchi
  2021-12-02 18:15 ` [tip: x86/mm] " tip-bot2 for Joerg Roedel
  2 siblings, 0 replies; 10+ messages in thread
From: Tom Lendacky @ 2021-12-02 15:52 UTC (permalink / raw)
  To: Joerg Roedel, x86, Dave Hansen
  Cc: Borislav Petkov, Ingo Molnar, Thomas Gleixner, hpa,
	Andy Lutomirski, Peter Zijlstra, Brijesh Singh, linux-kernel,
	Joerg Roedel, Lucas De Marchi

On 12/2/21 8:46 AM, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> 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.

Tested-by: Tom Lendacky <thomas.lendacky@amd.com>

Thanks,
Tom

> 
> Cc: Lucas De Marchi <lucas.demarchi@intel.com>
> Fixes: 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> ---
>   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(-)
> 
> diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
> index 5e186a69db10..a2eaf265f784 100644
> --- a/arch/x86/include/asm/fixmap.h
> +++ b/arch/x86/include/asm/fixmap.h
> @@ -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
> diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
> index a87224767ff3..fc9b6995cb22 100644
> --- a/arch/x86/include/asm/pgtable_types.h
> +++ b/arch/x86/include/asm/pgtable_types.h
> @@ -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__ */
>   
> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> index 3102dda4b152..4fe8d43d53bb 100644
> --- a/arch/x86/mm/ioremap.c
> +++ b/arch/x86/mm/ioremap.c
> @@ -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);
>   
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-02 14:46 [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage Joerg Roedel
  2021-12-02 15:52 ` Tom Lendacky
@ 2021-12-02 15:55 ` Lucas De Marchi
  2021-12-03  0:25   ` Lucas De Marchi
  2021-12-02 18:15 ` [tip: x86/mm] " tip-bot2 for Joerg Roedel
  2 siblings, 1 reply; 10+ messages in thread
From: Lucas De Marchi @ 2021-12-02 15:55 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: x86, Dave Hansen, Borislav Petkov, Ingo Molnar, Thomas Gleixner,
	hpa, Andy Lutomirski, Peter Zijlstra, Tom Lendacky,
	Brijesh Singh, linux-kernel, Joerg Roedel

On Thu, Dec 02, 2021 at 03:46:46PM +0100, Joerg Roedel wrote:
>From: Joerg Roedel <jroedel@suse.de>
>
>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 <lucas.demarchi@intel.com>
>Fixes: 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
>Signed-off-by: Joerg Roedel <jroedel@suse.de>

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

Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>

Lucas De Marchi

>---
> 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(-)
>
>diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
>index 5e186a69db10..a2eaf265f784 100644
>--- a/arch/x86/include/asm/fixmap.h
>+++ b/arch/x86/include/asm/fixmap.h
>@@ -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
>diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
>index a87224767ff3..fc9b6995cb22 100644
>--- a/arch/x86/include/asm/pgtable_types.h
>+++ b/arch/x86/include/asm/pgtable_types.h
>@@ -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__ */
>
>diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
>index 3102dda4b152..4fe8d43d53bb 100644
>--- a/arch/x86/mm/ioremap.c
>+++ b/arch/x86/mm/ioremap.c
>@@ -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);
>
>-- 
>2.34.0
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [tip: x86/mm] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-02 14:46 [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage Joerg Roedel
  2021-12-02 15:52 ` Tom Lendacky
  2021-12-02 15:55 ` Lucas De Marchi
@ 2021-12-02 18:15 ` tip-bot2 for Joerg Roedel
  2 siblings, 0 replies; 10+ messages in thread
From: tip-bot2 for Joerg Roedel @ 2021-12-02 18:15 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Joerg Roedel, Dave Hansen, Lucas De Marchi, Tom Lendacky, x86,
	linux-kernel

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 <jroedel@suse.de>
AuthorDate:    Thu, 02 Dec 2021 15:46:46 +01:00
Committer:     Dave Hansen <dave.hansen@linux.intel.com>
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.

Fixes: 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Tested-by: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://lkml.kernel.org/r/20211202144646.23186-1-joro@8bytes.org
---
 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(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index 5e186a6..a2eaf26 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -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
diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
index a872247..fc9b699 100644
--- a/arch/x86/include/asm/pgtable_types.h
+++ b/arch/x86/include/asm/pgtable_types.h
@@ -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__ */
 
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 3102dda..4fe8d43 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -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);
 

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-02 15:55 ` Lucas De Marchi
@ 2021-12-03  0:25   ` Lucas De Marchi
  2021-12-03 17:28     ` Tom Lendacky
  2021-12-03 17:35     ` Dave Hansen
  0 siblings, 2 replies; 10+ messages in thread
From: Lucas De Marchi @ 2021-12-03  0:25 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: x86, Dave Hansen, Borislav Petkov, Ingo Molnar, Thomas Gleixner,
	hpa, Andy Lutomirski, Peter Zijlstra, Tom Lendacky,
	Brijesh Singh, linux-kernel, Joerg Roedel

On Thu, Dec 02, 2021 at 07:55:14AM -0800, Lucas De Marchi wrote:
>On Thu, Dec 02, 2021 at 03:46:46PM +0100, Joerg Roedel wrote:
>>From: Joerg Roedel <jroedel@suse.de>
>>
>>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 <lucas.demarchi@intel.com>
>>Fixes: 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
>>Signed-off-by: Joerg Roedel <jroedel@suse.de>
>
>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

>
>Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
>
>Lucas De Marchi
>
>>---
>>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(-)
>>
>>diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
>>index 5e186a69db10..a2eaf265f784 100644
>>--- a/arch/x86/include/asm/fixmap.h
>>+++ b/arch/x86/include/asm/fixmap.h
>>@@ -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
>>diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
>>index a87224767ff3..fc9b6995cb22 100644
>>--- a/arch/x86/include/asm/pgtable_types.h
>>+++ b/arch/x86/include/asm/pgtable_types.h
>>@@ -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__ */
>>
>>diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
>>index 3102dda4b152..4fe8d43d53bb 100644
>>--- a/arch/x86/mm/ioremap.c
>>+++ b/arch/x86/mm/ioremap.c
>>@@ -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);
>>
>>-- 
>>2.34.0
>>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-03  0:25   ` Lucas De Marchi
@ 2021-12-03 17:28     ` Tom Lendacky
  2021-12-03 17:32       ` Tom Lendacky
  2021-12-03 17:35     ` Dave Hansen
  1 sibling, 1 reply; 10+ messages in thread
From: Tom Lendacky @ 2021-12-03 17:28 UTC (permalink / raw)
  To: Lucas De Marchi, Joerg Roedel
  Cc: x86, Dave Hansen, Borislav Petkov, Ingo Molnar, Thomas Gleixner,
	hpa, Andy Lutomirski, Peter Zijlstra, Brijesh Singh,
	linux-kernel, Joerg Roedel

On 12/2/21 6:25 PM, Lucas De Marchi wrote:
> On Thu, Dec 02, 2021 at 07:55:14AM -0800, Lucas De Marchi wrote:
>> On Thu, Dec 02, 2021 at 03:46:46PM +0100, Joerg Roedel wrote:
>>> From: Joerg Roedel <jroedel@suse.de>
>>>
>>> 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 <lucas.demarchi@intel.com>
>>> Fixes: 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
>>> Signed-off-by: Joerg Roedel <jroedel@suse.de>
>>
>> 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/")

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

> 
> thanks
> Lucas De Marchi
> 
>>
>> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
>>
>> Lucas De Marchi
>>
>>> ---
>>> 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(-)
>>>
>>> diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
>>> index 5e186a69db10..a2eaf265f784 100644
>>> --- a/arch/x86/include/asm/fixmap.h
>>> +++ b/arch/x86/include/asm/fixmap.h
>>> @@ -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
>>> diff --git a/arch/x86/include/asm/pgtable_types.h 
>>> b/arch/x86/include/asm/pgtable_types.h
>>> index a87224767ff3..fc9b6995cb22 100644
>>> --- a/arch/x86/include/asm/pgtable_types.h
>>> +++ b/arch/x86/include/asm/pgtable_types.h
>>> @@ -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__ */
>>>
>>> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
>>> index 3102dda4b152..4fe8d43d53bb 100644
>>> --- a/arch/x86/mm/ioremap.c
>>> +++ b/arch/x86/mm/ioremap.c
>>> @@ -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);
>>>
>>> -- 
>>> 2.34.0
>>>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-03 17:28     ` Tom Lendacky
@ 2021-12-03 17:32       ` Tom Lendacky
  2021-12-03 18:48         ` Lucas De Marchi
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Lendacky @ 2021-12-03 17:32 UTC (permalink / raw)
  To: Lucas De Marchi, Joerg Roedel
  Cc: x86, Dave Hansen, Borislav Petkov, Ingo Molnar, Thomas Gleixner,
	hpa, Andy Lutomirski, Peter Zijlstra, Brijesh Singh,
	linux-kernel, Joerg Roedel

On 12/3/21 11:28 AM, Tom Lendacky wrote:
> On 12/2/21 6:25 PM, Lucas De Marchi wrote:
>> On Thu, Dec 02, 2021 at 07:55:14AM -0800, Lucas De Marchi wrote:
>>> On Thu, Dec 02, 2021 at 03:46:46PM +0100, Joerg Roedel wrote:
>>>> From: Joerg Roedel <jroedel@suse.de>
>>>>
>>>> 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 <lucas.demarchi@intel.com>
>>>> Fixes: 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
>>>> Signed-off-by: Joerg Roedel <jroedel@suse.de>
>>>
>>> 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.

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

Thanks,
Tom

>>
>> 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
> 
>>
>> thanks
>> Lucas De Marchi
>>
>>>
>>> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
>>>
>>> Lucas De Marchi
>>>
>>>> ---
>>>> 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(-)
>>>>
>>>> diff --git a/arch/x86/include/asm/fixmap.h 
>>>> b/arch/x86/include/asm/fixmap.h
>>>> index 5e186a69db10..a2eaf265f784 100644
>>>> --- a/arch/x86/include/asm/fixmap.h
>>>> +++ b/arch/x86/include/asm/fixmap.h
>>>> @@ -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
>>>> diff --git a/arch/x86/include/asm/pgtable_types.h 
>>>> b/arch/x86/include/asm/pgtable_types.h
>>>> index a87224767ff3..fc9b6995cb22 100644
>>>> --- a/arch/x86/include/asm/pgtable_types.h
>>>> +++ b/arch/x86/include/asm/pgtable_types.h
>>>> @@ -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__ */
>>>>
>>>> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
>>>> index 3102dda4b152..4fe8d43d53bb 100644
>>>> --- a/arch/x86/mm/ioremap.c
>>>> +++ b/arch/x86/mm/ioremap.c
>>>> @@ -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);
>>>>
>>>> -- 
>>>> 2.34.0
>>>>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-03  0:25   ` Lucas De Marchi
  2021-12-03 17:28     ` Tom Lendacky
@ 2021-12-03 17:35     ` Dave Hansen
  2021-12-03 19:11       ` Lucas De Marchi
  1 sibling, 1 reply; 10+ messages in thread
From: Dave Hansen @ 2021-12-03 17:35 UTC (permalink / raw)
  To: Lucas De Marchi, Joerg Roedel
  Cc: x86, Dave Hansen, Borislav Petkov, Ingo Molnar, Thomas Gleixner,
	hpa, Andy Lutomirski, Peter Zijlstra, Tom Lendacky,
	Brijesh Singh, linux-kernel, Joerg Roedel

On 12/2/21 4:25 PM, Lucas De Marchi wrote:
> 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-03 17:32       ` Tom Lendacky
@ 2021-12-03 18:48         ` Lucas De Marchi
  0 siblings, 0 replies; 10+ messages in thread
From: Lucas De Marchi @ 2021-12-03 18:48 UTC (permalink / raw)
  To: Tom Lendacky
  Cc: Joerg Roedel, x86, Dave Hansen, Borislav Petkov, Ingo Molnar,
	Thomas Gleixner, hpa, Andy Lutomirski, Peter Zijlstra,
	Brijesh Singh, linux-kernel, Joerg Roedel

On Fri, Dec 03, 2021 at 11:32:45AM -0600, Tom Lendacky wrote:
>On 12/3/21 11:28 AM, Tom Lendacky wrote:
>>On 12/2/21 6:25 PM, Lucas De Marchi wrote:
>>>On Thu, Dec 02, 2021 at 07:55:14AM -0800, Lucas De Marchi wrote:
>>>>On Thu, Dec 02, 2021 at 03:46:46PM +0100, Joerg Roedel wrote:
>>>>>From: Joerg Roedel <jroedel@suse.de>
>>>>>
>>>>>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 <lucas.demarchi@intel.com>
>>>>>Fixes: 27dff0f58bde ("x86/mm: Nuke PAGE_KERNEL_IO")
>>>>>Signed-off-by: Joerg Roedel <jroedel@suse.de>
>>>>
>>>>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.
>
>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

>
>Thanks,
>Tom
>
>>>
>>>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
>>
>>>
>>>thanks
>>>Lucas De Marchi
>>>
>>>>
>>>>Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
>>>>
>>>>Lucas De Marchi
>>>>
>>>>>---
>>>>>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(-)
>>>>>
>>>>>diff --git a/arch/x86/include/asm/fixmap.h 
>>>>>b/arch/x86/include/asm/fixmap.h
>>>>>index 5e186a69db10..a2eaf265f784 100644
>>>>>--- a/arch/x86/include/asm/fixmap.h
>>>>>+++ b/arch/x86/include/asm/fixmap.h
>>>>>@@ -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
>>>>>diff --git a/arch/x86/include/asm/pgtable_types.h 
>>>>>b/arch/x86/include/asm/pgtable_types.h
>>>>>index a87224767ff3..fc9b6995cb22 100644
>>>>>--- a/arch/x86/include/asm/pgtable_types.h
>>>>>+++ b/arch/x86/include/asm/pgtable_types.h
>>>>>@@ -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__ */
>>>>>
>>>>>diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
>>>>>index 3102dda4b152..4fe8d43d53bb 100644
>>>>>--- a/arch/x86/mm/ioremap.c
>>>>>+++ b/arch/x86/mm/ioremap.c
>>>>>@@ -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);
>>>>>
>>>>>-- 
>>>>>2.34.0
>>>>>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage
  2021-12-03 17:35     ` Dave Hansen
@ 2021-12-03 19:11       ` Lucas De Marchi
  0 siblings, 0 replies; 10+ messages in thread
From: Lucas De Marchi @ 2021-12-03 19:11 UTC (permalink / raw)
  To: Dave Hansen
  Cc: Joerg Roedel, x86, Dave Hansen, Borislav Petkov, Ingo Molnar,
	Thomas Gleixner, hpa, Andy Lutomirski, Peter Zijlstra,
	Tom Lendacky, Brijesh Singh, linux-kernel, Joerg Roedel

On Fri, Dec 03, 2021 at 09:35:47AM -0800, Dave Hansen wrote:
>On 12/2/21 4:25 PM, Lucas De Marchi wrote:
>> 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.

yeah, that seems the best approach here.

thanks
Lucas De Marchi

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-03 19:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 14:46 [PATCH] x86/mm: Fix PAGE_KERNEL_IO removal breakage Joerg Roedel
2021-12-02 15:52 ` Tom Lendacky
2021-12-02 15:55 ` Lucas De Marchi
2021-12-03  0:25   ` Lucas De Marchi
2021-12-03 17:28     ` Tom Lendacky
2021-12-03 17:32       ` Tom Lendacky
2021-12-03 18:48         ` Lucas De Marchi
2021-12-03 17:35     ` Dave Hansen
2021-12-03 19:11       ` Lucas De Marchi
2021-12-02 18:15 ` [tip: x86/mm] " tip-bot2 for Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).