[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=whvmGhOzJJr1LeZ7vdSNt_CE+VJCUJ9FcLe0-Nv8UqgoA@mail.gmail.com>
Date: Sat, 8 Feb 2025 12:03:09 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: David Laight <david.laight.linux@...il.com>
Cc: Al Viro <viro@...iv.linux.org.uk>, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>
Subject: Re: [PATCH next 1/1] fs: Mark get_sigset_argpack() __always_inline
On Sat, 8 Feb 2025 at 11:06, David Laight <david.laight.linux@...il.com> wrote:
>
> Can the 'alternatives' be flipped so the .o doesn't contain loads of nops?
Sadly, no. The instructions generate #UD if the CPU doesn't support SMAP.
Now, arguably the alternatives *should* be fixed up before the first
user space access and thus it would be safe to switch, but honestly, I
don't want to risk some early code doing odd things. The potential
pain would be too damn high.
> It'd be nice to see the clac and lfence.
Heh. I agree 100%, which is why my personal tree has a patch like this:
-#define LOCK_PREFIX_HERE \
- ".pushsection .smp_locks,\"a\"\n" \
- ".balign 4\n" \
- ".long 671f - .\n" /* offset */ \
- ".popsection\n" \
- "671:"
+#define LOCK_PREFIX_HERE
...
-#define barrier_nospec() alternative("", "lfence",
X86_FEATURE_LFENCE_RDTSC)
+#define barrier_nospec() asm volatile("lfence":::"memory")
...
-#define ASM_CLAC \
- ALTERNATIVE "", "clac", X86_FEATURE_SMAP
-
-#define ASM_STAC \
- ALTERNATIVE "", "stac", X86_FEATURE_SMAP
+#define ASM_CLAC clac
+#define ASM_STAC stac
...
- /* Note: a barrier is implicit in alternative() */
- alternative("", "clac", X86_FEATURE_SMAP);
+ asm volatile("clac":::"memory");
...
- /* Note: a barrier is implicit in alternative() */
- alternative("", "stac", X86_FEATURE_SMAP);
+ asm volatile("stac":::"memory");
...
-#define ASM_BARRIER_NOSPEC ALTERNATIVE "", "lfence",
X86_FEATURE_LFENCE_RDTSC
+#define ASM_BARRIER_NOSPEC lfence
but I've never made it a real usable patch for others. It would have
to be some "modern CPU only" config variable, and nobody else has ever
complained about this until now.
Linus
Powered by blists - more mailing lists