From nobody Sun Apr 5 13:09:13 2026 Received: from mail-244121.protonmail.ch (mail-244121.protonmail.ch [109.224.244.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69B0133C52A for ; Fri, 20 Feb 2026 12:48:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.121 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771591731; cv=none; b=MtFl8WwDGIOTD/MSUOlAh2vq8aHKrD/ioWAZX9Gum96YP0aftP8ek7fCWLtpT1PbOkwmy8w/YFePkwfDKIHkHcsEXcwgfRmXeJBNZM4F3VQXctEvxxnpu9MgO7f7H9AKBkb6WhXZIEljvAGzEyYmY5oW27EedWPFafZZ3U1fpG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771591731; c=relaxed/simple; bh=fwo5yrA8tnFuCVXwTTZLFXEh6Y+zgupXZpxGFTof1go=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TmvnFj6/KxxK+npL3sHw+9BcXeccI6cGrclSchR3CeQH6PpaWRbzV9EK7R4LupNR41K+gpb/khyd/fq0xgvS6BPz7eHp1lNap3FRkIND2xvcBp359YQUPNTHZo7Db9aa5NvVu6lBPB5FKfQikwGuIQs0FWCINUZ9UbX6uU6lK9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=gGAFAX6H; arc=none smtp.client-ip=109.224.244.121 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="gGAFAX6H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1771591728; x=1771850928; bh=EfDYb9D9OTmQ3+6P96JtLixgE1pE8l5HhltUA1Ccqv4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=gGAFAX6Hcr2yGw69nPOYZ01GxILBwgTpGiFgnrlC7paKctg2BLe7s1OWGXi0JyOsh p0qKDfcQEEJj7w92CxVOB+1xKYRxiJ47jTk3XMs6mLKN58hypv+dJuGqaRlS2bXdPG WY321kVbfzwypQSF2pz8CN3WSxERfOXaT6ZI4ZOineeRVZUaAV6N+FxHr9SPrN3IlM XwYO7l9rec8DUdXEvq29Bpxy6jnUsjqJGCp31xOf4WlreDtlp+zuL9a9xgwIGCkABP Y3y5hrLaF8HsGLB6Srl0ENYWEW4YrsfyQG1MAaA2EjbeGvCIoHqSOA6JzYSiQNpBqH 8cX5hZ8Pjk6sA== Date: Fri, 20 Feb 2026 12:48:46 +0000 To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" From: Maciej Wieczor-Retman Cc: m.wieczorretman@pm.me, Maciej Wieczor-Retman , linux-kernel@vger.kernel.org Subject: [PATCH v1 1/4] x86/process: Shorten the default LAM tag width Message-ID: <19e0b13f42dcf87fbde2d32aad18d89441620acb.1771589807.git.m.wieczorretman@pm.me> In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: a880345925fd6a2bf680effe6d92394e01d0fa4c Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Maciej Wieczor-Retman With the announcement of ChkTag, it's worth preparing a stable x86 linear address masking (lam) user interface. One important aspect of lam is the tag width, and aligning it with other industry solutions can provide a more popular, generalized interface that other technologies could utilize. ChkTag will use 4-bit tags and since that's the direction other memory tagging implementations seem to be taking too (for example Arm's MTE) it's reasonable to converge lam in linux to the same specification. Even though x86's LAM supports 6-bit tags it is beneficial to default lam to 4 bits as ChkTag will likely be the main user of the interface and such connection should simplify things in the future. Set the default tag width to 4 bits and make it variable. While static keys were considered to implement it, the LAM tag width isn't used in any performance intensive code paths, and doesn't justify anything more than a simple global variable. Signed-off-by: Maciej Wieczor-Retman --- arch/x86/include/asm/mmu_context.h | 3 +++ arch/x86/kernel/process_64.c | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_= context.h index 73bf3b1b44e8..13999d48abd6 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -86,6 +86,9 @@ static inline void switch_ldt(struct mm_struct *prev, str= uct mm_struct *next) #endif =20 #ifdef CONFIG_ADDRESS_MASKING + +extern unsigned long lam_available_bits; + static inline unsigned long mm_lam_cr3_mask(struct mm_struct *mm) { /* diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 432c0a004c60..04968b303e66 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -797,7 +797,10 @@ static long prctl_map_vdso(const struct vdso_image *im= age, unsigned long addr) =20 #ifdef CONFIG_ADDRESS_MASKING =20 -#define LAM_U57_BITS 6 +#define LAM_MAX_BITS 6 +#define LAM_DEFAULT_BITS 4 + +unsigned long lam_available_bits =3D LAM_DEFAULT_BITS; =20 static void enable_lam_func(void *__mm) { @@ -811,10 +814,10 @@ static void enable_lam_func(void *__mm) } } =20 -static void mm_enable_lam(struct mm_struct *mm) +static void mm_enable_lam(struct mm_struct *mm, unsigned long nr_bits) { mm->context.lam_cr3_mask =3D X86_CR3_LAM_U57; - mm->context.untag_mask =3D ~GENMASK(62, 57); + mm->context.untag_mask =3D ~GENMASK(57 + lam_available_bits - 1, 57); =20 /* * Even though the process must still be single-threaded at this @@ -850,12 +853,12 @@ static int prctl_enable_tagged_addr(struct mm_struct = *mm, unsigned long nr_bits) return -EBUSY; } =20 - if (!nr_bits || nr_bits > LAM_U57_BITS) { + if (!nr_bits || nr_bits > lam_available_bits) { mmap_write_unlock(mm); return -EINVAL; } =20 - mm_enable_lam(mm); + mm_enable_lam(mm, nr_bits); =20 mmap_write_unlock(mm); =20 @@ -965,7 +968,7 @@ long do_arch_prctl_64(struct task_struct *task, int opt= ion, unsigned long arg2) if (!cpu_feature_enabled(X86_FEATURE_LAM)) return put_user(0, (unsigned long __user *)arg2); else - return put_user(LAM_U57_BITS, (unsigned long __user *)arg2); + return put_user(lam_available_bits, (unsigned long __user *)arg2); #endif case ARCH_SHSTK_ENABLE: case ARCH_SHSTK_DISABLE: --=20 2.53.0