Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/ioremap: Selectively build arch override encryption functions

In preparation for other uses of the cc_platform_has() function
besides AMD's memory encryption support, selectively build the
AMD memory encryption architecture override functions only when
CONFIG_AMD_MEM_ENCRYPT=y. These functions are:

- early_memremap_pgprot_adjust()
- arch_memremap_can_ram_remap()

Additionally, routines that are only invoked by these architecture
override functions can also be conditionally built. These functions are:

- memremap_should_map_decrypted()
- memremap_is_efi_data()
- memremap_is_setup_data()
- early_memremap_is_setup_data()

And finally, phys_mem_access_encrypted() is conditionally built as well,
but requires a static inline version of it when CONFIG_AMD_MEM_ENCRYPT is
not set.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210928191009.32551-2-bp@alien8.de

authored by

Tom Lendacky and committed by
Borislav Petkov
402fe0cb 9e1ff307

+9 -1
+8
arch/x86/include/asm/io.h
··· 391 391 #define arch_io_reserve_memtype_wc arch_io_reserve_memtype_wc 392 392 #endif 393 393 394 + #ifdef CONFIG_AMD_MEM_ENCRYPT 394 395 extern bool arch_memremap_can_ram_remap(resource_size_t offset, 395 396 unsigned long size, 396 397 unsigned long flags); ··· 399 398 400 399 extern bool phys_mem_access_encrypted(unsigned long phys_addr, 401 400 unsigned long size); 401 + #else 402 + static inline bool phys_mem_access_encrypted(unsigned long phys_addr, 403 + unsigned long size) 404 + { 405 + return true; 406 + } 407 + #endif 402 408 403 409 /** 404 410 * iosubmit_cmds512 - copy data to single MMIO location, in 512-bit units
+1 -1
arch/x86/mm/ioremap.c
··· 508 508 memunmap((void *)((unsigned long)addr & PAGE_MASK)); 509 509 } 510 510 511 + #ifdef CONFIG_AMD_MEM_ENCRYPT 511 512 /* 512 513 * Examine the physical address to determine if it is an area of memory 513 514 * that should be mapped decrypted. If the memory is not part of the ··· 747 746 return arch_memremap_can_ram_remap(phys_addr, size, 0); 748 747 } 749 748 750 - #ifdef CONFIG_AMD_MEM_ENCRYPT 751 749 /* Remap memory with encryption */ 752 750 void __init *early_memremap_encrypted(resource_size_t phys_addr, 753 751 unsigned long size)