1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21965aae3SH. Peter Anvin #ifndef _ASM_X86_PROCESSOR_FLAGS_H 31965aae3SH. Peter Anvin #define _ASM_X86_PROCESSOR_FLAGS_H 4bb898558SAl Viro 5af170c50SDavid Howells #include <uapi/asm/processor-flags.h> 6eef9c4abSTom Lendacky #include <linux/mem_encrypt.h> 7bb898558SAl Viro 8bb898558SAl Viro #ifdef CONFIG_VM86 9bb898558SAl Viro #define X86_VM_MASK X86_EFLAGS_VM 10bb898558SAl Viro #else 11bb898558SAl Viro #define X86_VM_MASK 0 /* No VM86 support */ 12bb898558SAl Viro #endif 136c690ee1SAndy Lutomirski 146c690ee1SAndy Lutomirski /* 156c690ee1SAndy Lutomirski * CR3's layout varies depending on several things. 166c690ee1SAndy Lutomirski * 176c690ee1SAndy Lutomirski * If CR4.PCIDE is set (64-bit only), then CR3[11:0] is the address space ID. 186c690ee1SAndy Lutomirski * If PAE is enabled, then CR3[11:5] is part of the PDPT address 196c690ee1SAndy Lutomirski * (i.e. it's 32-byte aligned, not page-aligned) and CR3[4:0] is ignored. 206c690ee1SAndy Lutomirski * Otherwise (non-PAE, non-PCID), CR3[3] is PWT, CR3[4] is PCD, and 216c690ee1SAndy Lutomirski * CR3[2:0] and CR3[11:5] are ignored. 226c690ee1SAndy Lutomirski * 236c690ee1SAndy Lutomirski * In all cases, Linux puts zeros in the low ignored bits and in PWT and PCD. 246c690ee1SAndy Lutomirski * 256c690ee1SAndy Lutomirski * CR3[63] is always read as zero. If CR4.PCIDE is set, then CR3[63] may be 266c690ee1SAndy Lutomirski * written as 1 to prevent the write to CR3 from flushing the TLB. 276c690ee1SAndy Lutomirski * 286c690ee1SAndy Lutomirski * On systems with SME, one bit (in a variable position!) is stolen to indicate 296c690ee1SAndy Lutomirski * that the top-level paging structure is encrypted. 306c690ee1SAndy Lutomirski * 316c690ee1SAndy Lutomirski * All of the remaining bits indicate the physical address of the top-level 326c690ee1SAndy Lutomirski * paging structure. 336c690ee1SAndy Lutomirski * 346c690ee1SAndy Lutomirski * CR3_ADDR_MASK is the mask used by read_cr3_pa(). 356c690ee1SAndy Lutomirski */ 366c690ee1SAndy Lutomirski #ifdef CONFIG_X86_64 37eef9c4abSTom Lendacky /* Mask off the address space ID and SME encryption bits. */ 38*80d0969aSKirill A. Shutemov #define CR3_ADDR_MASK __sme_clr(PHYSICAL_PAGE_MASK) 396c690ee1SAndy Lutomirski #define CR3_PCID_MASK 0xFFFull 40d6c8103bSBorislav Petkov #define CR3_NOFLUSH BIT_ULL(63) 416fd166aaSPeter Zijlstra 426c690ee1SAndy Lutomirski #else 436c690ee1SAndy Lutomirski /* 446c690ee1SAndy Lutomirski * CR3_ADDR_MASK needs at least bits 31:5 set on PAE systems, and we save 456c690ee1SAndy Lutomirski * a tiny bit of code size by setting all the bits. 466c690ee1SAndy Lutomirski */ 476c690ee1SAndy Lutomirski #define CR3_ADDR_MASK 0xFFFFFFFFull 486c690ee1SAndy Lutomirski #define CR3_PCID_MASK 0ull 4910af6235SAndy Lutomirski #define CR3_NOFLUSH 0 506c690ee1SAndy Lutomirski #endif 516c690ee1SAndy Lutomirski 522c1b9fbeSJoerg Roedel #ifdef CONFIG_PAGE_TABLE_ISOLATION 532c1b9fbeSJoerg Roedel # define X86_CR3_PTI_PCID_USER_BIT 11 542c1b9fbeSJoerg Roedel #endif 552c1b9fbeSJoerg Roedel 561965aae3SH. Peter Anvin #endif /* _ASM_X86_PROCESSOR_FLAGS_H */ 57