Add set_memory_decrypted_nozero() with the existing x86 decryption behavior and use it for VGA_MAP_MEM(). Video memory needs a decrypted mapping without an explicit memset() of the mapped range.
This prepares the VGA caller for adding zeroing to set_memory_decrypted().
Cc: Thomas Gleixner tglx@kernel.org Cc: Ingo Molnar mingo@redhat.com Cc: Borislav Petkov bp@alien8.de Cc: Dave Hansen dave.hansen@linux.intel.com Cc: Andy Lutomirski luto@kernel.org Cc: Peter Zijlstra peterz@infradead.org Cc: x86@kernel.org Signed-off-by: Aneesh Kumar K.V (Arm) aneesh.kumar@kernel.org --- arch/x86/include/asm/set_memory.h | 1 + arch/x86/include/asm/vga.h | 4 ++-- arch/x86/mm/pat/set_memory.c | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h index 39271a5ea925..dfac1dde3714 100644 --- a/arch/x86/include/asm/set_memory.h +++ b/arch/x86/include/asm/set_memory.h @@ -52,6 +52,7 @@ int set_memory_4k(unsigned long addr, int numpages); bool set_memory_enc_stop_conversion(void); int set_memory_encrypted(unsigned long addr, int numpages); int set_memory_decrypted(unsigned long addr, int numpages); +int set_memory_decrypted_nozero(unsigned long addr, int numpages);
int set_memory_np_noalias(unsigned long addr, int numpages); int set_memory_nonglobal(unsigned long addr, int numpages); diff --git a/arch/x86/include/asm/vga.h b/arch/x86/include/asm/vga.h index 46f9b2deab4d..e1e91dfa399d 100644 --- a/arch/x86/include/asm/vga.h +++ b/arch/x86/include/asm/vga.h @@ -14,7 +14,7 @@ * On the PC, we can just recalculate addresses and then * access the videoram directly without any black magic. * To support memory encryption however, we need to access - * the videoram as decrypted memory. + * the videoram as decrypted memory without clearing its contents. */
#define VGA_MAP_MEM(x, s) \ @@ -22,7 +22,7 @@ unsigned long start = (unsigned long)phys_to_virt(x); \ \ if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) \ - set_memory_decrypted(start, (s) >> PAGE_SHIFT); \ + set_memory_decrypted_nozero(start, (s) >> PAGE_SHIFT); \ \ start; \ }) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index b1d5c5a0ffb4..16f3f57f973b 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2549,6 +2549,13 @@ int set_memory_decrypted(unsigned long addr, int numpages) } EXPORT_SYMBOL_GPL(set_memory_decrypted);
+/* Device memory needs a decrypted mapping without writes to its contents. */ +int set_memory_decrypted_nozero(unsigned long addr, int numpages) +{ + return __set_memory_enc_dec(addr, numpages, false); +} +EXPORT_SYMBOL_GPL(set_memory_decrypted_nozero); + int set_pages_uc(struct page *page, int numpages) { unsigned long addr = (unsigned long)page_address(page);