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

x86: Make ARCH_USE_MEMREMAP_PROT a generic Kconfig symbol

Turn ARCH_USE_MEMREMAP_PROT into a generic Kconfig symbol, and fix the
dependency expression to reflect that AMD_MEM_ENCRYPT depends on it,
instead of the other way around. This will permit ARCH_USE_MEMREMAP_PROT
to be selected by other architectures.

Note that the encryption related early memremap routines in
arch/x86/mm/ioremap.c cannot be built for 32-bit x86 without triggering
the following warning:

arch/x86//mm/ioremap.c: In function 'early_memremap_encrypted':
>> arch/x86/include/asm/pgtable_types.h:193:27: warning: conversion from
'long long unsigned int' to 'long unsigned int' changes
value from '9223372036854776163' to '355' [-Woverflow]
#define __PAGE_KERNEL_ENC (__PAGE_KERNEL | _PAGE_ENC)
^~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86//mm/ioremap.c:713:46: note: in expansion of macro '__PAGE_KERNEL_ENC'
return early_memremap_prot(phys_addr, size, __PAGE_KERNEL_ENC);

which essentially means they are 64-bit only anyway. However, we cannot
make them dependent on CONFIG_ARCH_HAS_MEM_ENCRYPT, since that is always
defined, even for i386 (and changing that results in a slew of build errors)

So instead, build those routines only if CONFIG_AMD_MEM_ENCRYPT is
defined.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Alexander Graf <agraf@suse.de>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Jeffrey Hugo <jhugo@codeaurora.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Jones <pjones@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20190202094119.13230-9-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Ard Biesheuvel and committed by
Ingo Molnar
ce9084ba 4e46c2a9

+6 -6
+3
arch/Kconfig
··· 885 885 architectures, and don't require runtime relocation on relocatable 886 886 kernels. 887 887 888 + config ARCH_USE_MEMREMAP_PROT 889 + bool 890 + 888 891 source "kernel/gcov/Kconfig" 889 892 890 893 source "scripts/gcc-plugins/Kconfig"
+1 -4
arch/x86/Kconfig
··· 1510 1510 bool "AMD Secure Memory Encryption (SME) support" 1511 1511 depends on X86_64 && CPU_SUP_AMD 1512 1512 select DYNAMIC_PHYSICAL_MASK 1513 + select ARCH_USE_MEMREMAP_PROT 1513 1514 ---help--- 1514 1515 Say yes to enable support for the encryption of system memory. 1515 1516 This requires an AMD processor that supports Secure Memory ··· 1529 1528 1530 1529 If set to N, then the encryption of system memory can be 1531 1530 activated with the mem_encrypt=on command line option. 1532 - 1533 - config ARCH_USE_MEMREMAP_PROT 1534 - def_bool y 1535 - depends on AMD_MEM_ENCRYPT 1536 1531 1537 1532 # Common NUMA Features 1538 1533 config NUMA
+2 -2
arch/x86/mm/ioremap.c
··· 705 705 return arch_memremap_can_ram_remap(phys_addr, size, 0); 706 706 } 707 707 708 - #ifdef CONFIG_ARCH_USE_MEMREMAP_PROT 708 + #ifdef CONFIG_AMD_MEM_ENCRYPT 709 709 /* Remap memory with encryption */ 710 710 void __init *early_memremap_encrypted(resource_size_t phys_addr, 711 711 unsigned long size) ··· 747 747 748 748 return early_memremap_prot(phys_addr, size, __PAGE_KERNEL_NOENC_WP); 749 749 } 750 - #endif /* CONFIG_ARCH_USE_MEMREMAP_PROT */ 750 + #endif /* CONFIG_AMD_MEM_ENCRYPT */ 751 751 752 752 static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss; 753 753