From: Dave Hansen <dave.hansen@intel.com>
To: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
shuah@kernel.org, hpa@zytor.com, x86@kernel.org,
dave.hansen@linux.intel.com, bp@alien8.de, mingo@redhat.com,
tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
kirill@shutemov.name,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH v5 2/3] selftests/lam: Skip test if LAM is disabled
Date: Fri, 24 Jan 2025 08:23:09 -0800 [thread overview]
Message-ID: <81714cba-7924-4a4a-a5fc-b6f84bda352a@intel.com> (raw)
In-Reply-To: <09e6958c424a5da763f2331745cfe145962b0a83.1732728879.git.maciej.wieczor-retman@intel.com>
On 11/27/24 09:35, Maciej Wieczor-Retman wrote:
> +static inline int kernel_has_lam(void)
> +{
> + unsigned long bits;
> +
> + syscall(SYS_arch_prctl, ARCH_GET_MAX_TAG_BITS, &bits);
> + return !!bits;
> +}
Generally, I'm less picky about selftest/ code than in-kernel code. But
people really do take selftest code and use it as a starting point for
production code.
I'd much rather have overly verbose, obviously correct code:
err = syscall(SYS_arch_prctl, ARCH_GET_MAX_TAG_BITS, &bits);
/* Handle syscall failure, like pre-LAM kernels: */
if (err)
return 0
/* Tag bits are empty on non-LAM systems: */
return !!bits;
Actually, I was going to argue for that^ just on style and writing good
code. But then I spotted a bug. What happens if the kernel has
CONFIG_ADDRESS_MASKING=n, either because it is config'd off or it's old?
The:
put_user(0, (unsigned long __user *)arg2);
won't ever get run and 'bits' will be uninitialized.
So, I think this code was trying to be compact, fast and clever. But it
really just turns out to be buggy.
next prev parent reply other threads:[~2025-01-24 16:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-27 17:35 [PATCH v5 0/3] selftests/lam: get_user additions and LAM enabled check Maciej Wieczor-Retman
2024-11-27 17:35 ` [PATCH v5 1/3] selftests/lam: Move cpu_has_la57() to use cpuinfo flag Maciej Wieczor-Retman
2025-01-24 16:14 ` Dave Hansen
2025-01-24 20:17 ` Maciej Wieczor-Retman
2025-01-24 20:24 ` Dave Hansen
2025-01-24 20:29 ` Maciej Wieczor-Retman
2024-11-27 17:35 ` [PATCH v5 2/3] selftests/lam: Skip test if LAM is disabled Maciej Wieczor-Retman
2025-01-24 16:23 ` Dave Hansen [this message]
2025-01-24 20:09 ` Maciej Wieczor-Retman
2024-11-27 17:35 ` [PATCH v5 3/3] selftests/lam: Test get_user() LAM pointer handling Maciej Wieczor-Retman
2025-01-24 16:32 ` Dave Hansen
2025-01-24 20:19 ` Maciej Wieczor-Retman
2025-01-15 9:06 ` [PATCH v5 0/3] selftests/lam: get_user additions and LAM enabled check Maciej Wieczor-Retman
2025-01-23 21:52 ` Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81714cba-7924-4a4a-a5fc-b6f84bda352a@intel.com \
--to=dave.hansen@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=mingo@redhat.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox