Re: [PATCH v4] fs: hide names_cachep behind runtime access machinery

From: Linus Torvalds

Date: Thu Oct 30 2025 - 14:07:38 EST


[ Adding Thomas, because he's been working on our x86 uaccess code,
and I actually think we get this all wrong for access_ok() etc ]

On Thu, 30 Oct 2025 at 09:35, Mateusz Guzik <mjguzik@xxxxxxxxx> wrote:
>
> I don't know if you are suggesting to make the entire thing fail to
> compile if included for a module, or to transparently convert
> runtime-optimized access into plain access.
>
> I presume the former.

I think *including* it should be ok, because we have things like
<asm/uaccess.h> - or your addition to <linux/fs.h> - that use it for
core functionality that is then not supported for module use.

Yeah, in a perfect world we'd have those things only in "internal"
headers and people couldn't include them even by mistake, but that
ends up being a pain.

So I don't think your

+#ifdef MODULE
+#error "this functionality is not available for modules"
+#endif

model works, because I think it might be too painful to fix (but hey,
maybe I'm wrong).

I was thinking more along the lines of forcing linker errors or
something like that.

ENTIRELY UNTESTED PATCH attached - may not compile at all, but
something like this *might* work to show when a module uses the
runtime_const infrastructure.

And I think I should have made the default runtime const value
something small. But the original use of this was just the dcache
code, and that used it purely as a pointer, so a non-fixed-up address
would cause a nice clean oops. Then I started using it for the user
access limit, and now it's actually wrong if used by modules.

Thanks for making me think about this. I thought about the module case
*originally*, but then with some of the expanded use I definitely did
not.

Linus
arch/x86/include/asm/runtime-const.h | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/runtime-const.h b/arch/x86/include/asm/runtime-const.h
index 8d983cfd06ea..01e35997587d 100644
--- a/arch/x86/include/asm/runtime-const.h
+++ b/arch/x86/include/asm/runtime-const.h
@@ -2,7 +2,18 @@
#ifndef _ASM_RUNTIME_CONST_H
#define _ASM_RUNTIME_CONST_H

-#ifdef __ASSEMBLY__
+#ifdef MODULE
+
+/*
+ * None of this is available to modules, so we force link errors
+ * if people try to use it
+ */
+extern unsigned long no_runtime_const;
+#define runtime_const_ptr(sym) ((typeof(sym))no_runtime_const)
+#define runtime_const_shift_right_32(val, sym) ((u32)no_runtime_const)
+#define runtime_const_init(type,sym) do { no_runtime_const=1; } while (0)
+
+#elif defined(__ASSEMBLY__)

.macro RUNTIME_CONST_PTR sym reg
movq $0x0123456789abcdef, %\reg