From nobody Sun Apr 5 13:28:06 2026 Received: from mail-05.mail-europe.com (mail-05.mail-europe.com [85.9.206.169]) (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 91E0A344D86 for ; Fri, 20 Feb 2026 12:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.9.206.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771591752; cv=none; b=g99d3wKAdUEIsNIGGo4cRVoYpho53T2kPcEwHDDajPu63INzbzlguSd6DPMW05cI8xm90wUnHj91Bn8txLNpNsd6IR6KuzNh72R2km4GyG+4a6kzHBmz+HwerfCTQdkABtpF9t4D6tBDl7+xOMWXaPdPXQ0IUXVQK8uB27uINGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771591752; c=relaxed/simple; bh=q4gpatxXQY+61PGALxt6zogHQjzgxDSWP5zVWuolr0Y=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VNMzTcrSt/4qsBYELUZJhJQKV+g3d4Al6KjHmfAZ3iE2omTFe+BKphLOXlmTWY8yXwW3fz1W9PqvJkabwFftuK2nOSATRukgzePMvtaTvUw78MBv8FtNk740/JXGl1ADYQTRS+W0REffYFSSDYZjcUrydn/DWkGJ8S087yZseF0= 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=YI7iuMOr; arc=none smtp.client-ip=85.9.206.169 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="YI7iuMOr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1771591736; x=1771850936; bh=bMdZ4w4FGB99kBF7af0GSzGGKFxixfmU4A6pNZGK/tU=; 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=YI7iuMOr8IpoBWw9d196vZOIY9Zjh1Fp9wf2j1r5zBuBVBMsIc3o2Dj5ZK5mxaYBD njOiZWi5l4Ep8MaaGE8nceu92zZnMKFNjG9lMqSJD+D+ehn2yYlovAHV947NDhyOTz acuVbfTKcvv8kUGk511B7kvwK3cBJze7q+InBTh30mUtew0Scr2mnpFQhwEg5XAc5c 4u0aEAxPGd96J1Xoe3RScAjahJHrme9Ilkykfpnr9gZP+QMbSPTfY9lroDtvd6X0uY YIyXBdIa98k7bQZqstntwzUhi0qlQDpRXNzjcmQBcFLJYuGHeQV0iu4vKFXfIOdv1u EjyJe7OaNoCdA== Date: Fri, 20 Feb 2026 12:48:50 +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 2/4] x86/process: Add a debug interface to change LAM tag width Message-ID: <5ed38af72848015f3417c462e624e52891dc14ed.1771589807.git.m.wieczorretman@pm.me> In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: c0af3f3bd7e017ed5e755a048cec135bbaf30a58 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 While shortening the tag bits to converge the specifications of LAM and ChkTag, the 6 bit wide LAM (Linear Address Masking) tags should still be available to use. Since using this tag width is likely going to be for debug purposes only, using debugfs is the best choice. Signed-off-by: Maciej Wieczor-Retman --- arch/x86/kernel/process_64.c | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 04968b303e66..2f9f74cddd2a 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -41,6 +41,7 @@ #include #include #include +#include =20 #include #include @@ -802,6 +803,61 @@ static long prctl_map_vdso(const struct vdso_image *im= age, unsigned long addr) =20 unsigned long lam_available_bits =3D LAM_DEFAULT_BITS; =20 +static ssize_t lam_bits_read_file(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + char buf[2]; + unsigned int len; + + len =3D sprintf(buf, "%ld\n", lam_available_bits); + return simple_read_from_buffer(user_buf, count, ppos, buf, len); +} + +/* + * Writing a number to this file changes the used lam tag width. Valid val= ues + * are 4 bit tag width and 6 bit tag width - the second, non-default one is + * meant mostly for debug and shall be deprecated in the future. + */ +static ssize_t lam_bits_write_file(struct file *file, + const char __user *user_buf, size_t count, + loff_t *ppos) +{ + char buf[32]; + ssize_t len; + int ceiling; + u8 bits; + + len =3D min(count, sizeof(buf) - 1); + if (copy_from_user(buf, user_buf, len)) + return -EFAULT; + + buf[len] =3D '\0'; + if (kstrtou8(buf, 0, &bits)) + return -EINVAL; + + switch (bits) { + case LAM_DEFAULT_BITS: + case LAM_MAX_BITS: + lam_available_bits =3D bits; + return count; + default: + return -EINVAL; + } +} + +static const struct file_operations fops_lam_bits =3D { + .read =3D lam_bits_read_file, + .write =3D lam_bits_write_file, +}; + +static int __init create_lam_available_bits(void) +{ + debugfs_create_file("lam_available_bits", 0600, + arch_debugfs_dir, NULL, &fops_lam_bits); + return 0; +} +late_initcall(create_lam_available_bits); + static void enable_lam_func(void *__mm) { struct mm_struct *mm =3D __mm; --=20 2.53.0