Skip to content

Commit 6449dcb

Browse files
kirylhansendc
authored andcommitted
x86: CPUID and CR3/CR4 flags for Linear Address Masking
Enumerate Linear Address Masking and provide defines for CR3 and CR4 flags. The new CONFIG_ADDRESS_MASKING option enables the feature support in kernel. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Alexander Potapenko <glider@google.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Alexander Potapenko <glider@google.com> Link: https://lore.kernel.org/all/20230312112612.31869-4-kirill.shutemov%40linux.intel.com
1 parent 5ef495e commit 6449dcb

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

arch/x86/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,17 @@ config RANDOMIZE_MEMORY_PHYSICAL_PADDING
22902290

22912291
If unsure, leave at the default value.
22922292

2293+
config ADDRESS_MASKING
2294+
bool "Linear Address Masking support"
2295+
depends on X86_64
2296+
help
2297+
Linear Address Masking (LAM) modifies the checking that is applied
2298+
to 64-bit linear addresses, allowing software to use of the
2299+
untranslated address bits for metadata.
2300+
2301+
The capability can be used for efficient address sanitizers (ASAN)
2302+
implementation and for optimizations in JITs.
2303+
22932304
config HOTPLUG_CPU
22942305
def_bool y
22952306
depends on SMP

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
#define X86_FEATURE_LKGS (12*32+18) /* "" Load "kernel" (userspace) GS */
322322
#define X86_FEATURE_AMX_FP16 (12*32+21) /* "" AMX fp16 Support */
323323
#define X86_FEATURE_AVX_IFMA (12*32+23) /* "" Support for VPMADD52[H,L]UQ */
324+
#define X86_FEATURE_LAM (12*32+26) /* Linear Address Masking */
324325

325326
/* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */
326327
#define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */

arch/x86/include/asm/processor-flags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* On systems with SME, one bit (in a variable position!) is stolen to indicate
2929
* that the top-level paging structure is encrypted.
3030
*
31+
* On systemms with LAM, bits 61 and 62 are used to indicate LAM mode.
32+
*
3133
* All of the remaining bits indicate the physical address of the top-level
3234
* paging structure.
3335
*

arch/x86/include/uapi/asm/processor-flags.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
#define X86_CR3_PCID_BITS 12
8383
#define X86_CR3_PCID_MASK (_AC((1UL << X86_CR3_PCID_BITS) - 1, UL))
8484

85+
#define X86_CR3_LAM_U57_BIT 61 /* Activate LAM for userspace, 62:57 bits masked */
86+
#define X86_CR3_LAM_U57 _BITULL(X86_CR3_LAM_U57_BIT)
87+
#define X86_CR3_LAM_U48_BIT 62 /* Activate LAM for userspace, 62:48 bits masked */
88+
#define X86_CR3_LAM_U48 _BITULL(X86_CR3_LAM_U48_BIT)
8589
#define X86_CR3_PCID_NOFLUSH_BIT 63 /* Preserve old PCID */
8690
#define X86_CR3_PCID_NOFLUSH _BITULL(X86_CR3_PCID_NOFLUSH_BIT)
8791

@@ -132,6 +136,8 @@
132136
#define X86_CR4_PKE _BITUL(X86_CR4_PKE_BIT)
133137
#define X86_CR4_CET_BIT 23 /* enable Control-flow Enforcement Technology */
134138
#define X86_CR4_CET _BITUL(X86_CR4_CET_BIT)
139+
#define X86_CR4_LAM_SUP_BIT 28 /* LAM for supervisor pointers */
140+
#define X86_CR4_LAM_SUP _BITUL(X86_CR4_LAM_SUP_BIT)
135141

136142
/*
137143
* x86-64 Task Priority Register, CR8

0 commit comments

Comments
 (0)