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 * 316449dcb0SKirill A. Shutemov * On systemms with LAM, bits 61 and 62 are used to indicate LAM mode. 326449dcb0SKirill A. Shutemov * 336c690ee1SAndy Lutomirski * All of the remaining bits indicate the physical address of the top-level 346c690ee1SAndy Lutomirski * paging structure. 356c690ee1SAndy Lutomirski * 366c690ee1SAndy Lutomirski * CR3_ADDR_MASK is the mask used by read_cr3_pa(). 376c690ee1SAndy Lutomirski */ 386c690ee1SAndy Lutomirski #ifdef CONFIG_X86_64 39eef9c4abSTom Lendacky /* Mask off the address space ID and SME encryption bits. */ 4080d0969aSKirill A. Shutemov #define CR3_ADDR_MASK __sme_clr(PHYSICAL_PAGE_MASK) 416c690ee1SAndy Lutomirski #define CR3_PCID_MASK 0xFFFull 42d6c8103bSBorislav Petkov #define CR3_NOFLUSH BIT_ULL(63) 436fd166aaSPeter Zijlstra 446c690ee1SAndy Lutomirski #else 456c690ee1SAndy Lutomirski /* 466c690ee1SAndy Lutomirski * CR3_ADDR_MASK needs at least bits 31:5 set on PAE systems, and we save 476c690ee1SAndy Lutomirski * a tiny bit of code size by setting all the bits. 486c690ee1SAndy Lutomirski */ 496c690ee1SAndy Lutomirski #define CR3_ADDR_MASK 0xFFFFFFFFull 506c690ee1SAndy Lutomirski #define CR3_PCID_MASK 0ull 5110af6235SAndy Lutomirski #define CR3_NOFLUSH 0 526c690ee1SAndy Lutomirski #endif 536c690ee1SAndy Lutomirski 54*ea4654e0SBreno Leitao #ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION 552c1b9fbeSJoerg Roedel # define X86_CR3_PTI_PCID_USER_BIT 11 562c1b9fbeSJoerg Roedel #endif 572c1b9fbeSJoerg Roedel 581965aae3SH. Peter Anvin #endif /* _ASM_X86_PROCESSOR_FLAGS_H */ 59