mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 17:30:02 +00:00
![Tom Lendacky](/assets/img/avatar_default.png)
Changes to the existing page table macros will allow the SME support to be enabled in a simple fashion with minimal changes to files that use these macros. Since the memory encryption mask will now be part of the regular pagetable macros, we introduce two new macros (_PAGE_TABLE_NOENC and _KERNPG_TABLE_NOENC) to allow for early pagetable creation/initialization without the encryption mask before SME becomes active. Two new pgprot() macros are defined to allow setting or clearing the page encryption mask. The FIXMAP_PAGE_NOCACHE define is introduced for use with MMIO. SME does not support encryption for MMIO areas so this define removes the encryption mask from the page attribute. Two new macros are introduced (__sme_pa() / __sme_pa_nodebug()) to allow creating a physical address with the encryption mask. These are used when working with the cr3 register so that the PGD can be encrypted. The current __va() macro is updated so that the virtual address is generated based off of the physical address without the encryption mask thus allowing the same virtual address to be generated regardless of whether encryption is enabled for that physical location or not. Also, an early initialization function is added for SME. If SME is active, this function: - Updates the early_pmd_flags so that early page faults create mappings with the encryption mask. - Updates the __supported_pte_mask to include the encryption mask. - Updates the protection_map entries to include the encryption mask so that user-space allocations will automatically have the encryption mask applied. Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Borislav Petkov <bp@suse.de> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Petkov <bp@alien8.de> Cc: Brijesh Singh <brijesh.singh@amd.com> Cc: Dave Young <dyoung@redhat.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Larry Woodman <lwoodman@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Michael S. Tsirkin <mst@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Radim Krčmář <rkrcmar@redhat.com> Cc: Rik van Riel <riel@redhat.com> Cc: Toshimitsu Kani <toshi.kani@hpe.com> Cc: kasan-dev@googlegroups.com Cc: kvm@vger.kernel.org Cc: linux-arch@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: linux-efi@vger.kernel.org Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/b36e952c4c39767ae7f0a41cf5345adf27438480.1500319216.git.thomas.lendacky@amd.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
76 lines
2.3 KiB
C
76 lines
2.3 KiB
C
#ifndef _ASM_X86_PAGE_DEFS_H
|
|
#define _ASM_X86_PAGE_DEFS_H
|
|
|
|
#include <linux/const.h>
|
|
#include <linux/types.h>
|
|
#include <linux/mem_encrypt.h>
|
|
|
|
/* PAGE_SHIFT determines the page size */
|
|
#define PAGE_SHIFT 12
|
|
#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
|
|
#define PAGE_MASK (~(PAGE_SIZE-1))
|
|
|
|
#define PMD_PAGE_SIZE (_AC(1, UL) << PMD_SHIFT)
|
|
#define PMD_PAGE_MASK (~(PMD_PAGE_SIZE-1))
|
|
|
|
#define PUD_PAGE_SIZE (_AC(1, UL) << PUD_SHIFT)
|
|
#define PUD_PAGE_MASK (~(PUD_PAGE_SIZE-1))
|
|
|
|
#define __PHYSICAL_MASK ((phys_addr_t)(__sme_clr((1ULL << __PHYSICAL_MASK_SHIFT) - 1)))
|
|
#define __VIRTUAL_MASK ((1UL << __VIRTUAL_MASK_SHIFT) - 1)
|
|
|
|
/* Cast *PAGE_MASK to a signed type so that it is sign-extended if
|
|
virtual addresses are 32-bits but physical addresses are larger
|
|
(ie, 32-bit PAE). */
|
|
#define PHYSICAL_PAGE_MASK (((signed long)PAGE_MASK) & __PHYSICAL_MASK)
|
|
#define PHYSICAL_PMD_PAGE_MASK (((signed long)PMD_PAGE_MASK) & __PHYSICAL_MASK)
|
|
#define PHYSICAL_PUD_PAGE_MASK (((signed long)PUD_PAGE_MASK) & __PHYSICAL_MASK)
|
|
|
|
#define HPAGE_SHIFT PMD_SHIFT
|
|
#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT)
|
|
#define HPAGE_MASK (~(HPAGE_SIZE - 1))
|
|
#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
|
|
|
|
#define HUGE_MAX_HSTATE 2
|
|
|
|
#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
|
|
|
|
#define VM_DATA_DEFAULT_FLAGS \
|
|
(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
|
|
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
|
|
|
|
#define __PHYSICAL_START ALIGN(CONFIG_PHYSICAL_START, \
|
|
CONFIG_PHYSICAL_ALIGN)
|
|
|
|
#define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START)
|
|
|
|
#ifdef CONFIG_X86_64
|
|
#include <asm/page_64_types.h>
|
|
#define IOREMAP_MAX_ORDER (PUD_SHIFT)
|
|
#else
|
|
#include <asm/page_32_types.h>
|
|
#define IOREMAP_MAX_ORDER (PMD_SHIFT)
|
|
#endif /* CONFIG_X86_64 */
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
extern int devmem_is_allowed(unsigned long pagenr);
|
|
|
|
extern unsigned long max_low_pfn_mapped;
|
|
extern unsigned long max_pfn_mapped;
|
|
|
|
static inline phys_addr_t get_max_mapped(void)
|
|
{
|
|
return (phys_addr_t)max_pfn_mapped << PAGE_SHIFT;
|
|
}
|
|
|
|
bool pfn_range_is_mapped(unsigned long start_pfn, unsigned long end_pfn);
|
|
|
|
extern unsigned long init_memory_mapping(unsigned long start,
|
|
unsigned long end);
|
|
|
|
extern void initmem_init(void);
|
|
|
|
#endif /* !__ASSEMBLY__ */
|
|
|
|
#endif /* _ASM_X86_PAGE_DEFS_H */
|