Re: [PATCH] x86: add 'runtime constant' infrastructure

From: Borislav Petkov
Date: Sun Jun 09 2024 - 07:23:12 EST


On Sat, Jun 08, 2024 at 12:35:05PM -0700, Linus Torvalds wrote:
> Ingo / Peter / Borislav - I enabled this for 32-bit x86 too, because it
> was literally trivial (had to remove a "q" from "movq"). I did a
> test-build and it looks find, but I didn't actually try to boot it.

Will do once you have your final version. I still have an Atom, 32-bit
only laptop lying around here.

> +#define runtime_const_ptr(sym) ({ \
> + typeof(sym) __ret; \
> + asm("mov %1,%0\n1:\n" \
> + ".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \
> + ".long 1b - %c2 - .\n\t" \
> + ".popsection" \
> + :"=r" (__ret) \
> + :"i" ((unsigned long)0x0123456789abcdefull), \
> + "i" (sizeof(long))); \
> + __ret; })

You might wanna use asm symbolic names for the operands so that it is
more readable:

#define runtime_const_ptr(sym) ({ \
typeof(sym) __ret; \
asm("mov %[constant] ,%[__ret]\n1:\n" \
".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \
".long 1b - %c[sizeoflong] - .\n\t" \
".popsection" \
: [__ret] "=r" (__ret) \
: [constant] "i" ((unsigned long)0x0123456789abcdefull), \
[sizeoflong] "i" (sizeof(long))); \
__ret; })

For example.

> +// The 'typeof' will create at _least_ a 32-bit type, but
> +// will happily also take a bigger type and the 'shrl' will
> +// clear the upper bits

Can we pls use the multiline comments, like you do below in the same
file.

Otherwise, it looks ok to me and it boots in a guest.

I'll take the final version for a spin on real hw in a couple of days,
once the review dust settles.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette