From: "H. Peter Anvin" <hpa@zytor.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Peter Zijlstra <peterz@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
Thomas Gleixner <tglx@linutronix.de>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
the arch/x86 maintainers <x86@kernel.org>,
linux-arch <linux-arch@vger.kernel.org>
Subject: Re: [PATCH] x86: add 'runtime constant' infrastructure
Date: Tue, 11 Jun 2024 13:15:43 -0700 [thread overview]
Message-ID: <BFD0AF77-C95E-4B8B-B475-DCBD808CA5C0@zytor.com> (raw)
In-Reply-To: <8eb5960f-17f9-4d94-9b52-dea8b475e9dc@zytor.com>
On June 11, 2024 12:43:02 PM PDT, "H. Peter Anvin" <hpa@zytor.com> wrote:
>On 6/10/24 06:38, Rasmus Villemoes wrote:
>> On 10/06/2024 12.43, Peter Zijlstra wrote:
>>> On Sat, Jun 08, 2024 at 12:35:05PM -0700, Linus Torvalds wrote:
>>
>>>> Comments?
>>>
>>> It obviously has the constraint of never running the code before the
>>> corresponding runtime_const_init() has been done, otherwise things will
>>> go sideways in a hurry, but this also makes the whole thing a *lot*
>>> simpler.
>>>
>>> The only thing I'm not sure about is it having a section per symbol,
>>> given how jump_label and static_call took off, this might not be
>>> scalable.
>>>
>>> Yes, the approach is super simple and straight forward, but imagine
>>> there being like a 100 symbols soon :/
>>>
>>> The below hackery -- it very much needs cleanup and is only compiled on
>>> x86_64 and does not support modules, boots for me.
>>
>> As can be seen in my other reply, yes, I'm also worried about the
>> scalability and would like to see this applied to more stuff.
>>
>> But if we do this, surely that's what scripts/sorttable is for, right?
>>
>> Alternatively, if we just keep emitting to per-symbol
>> __runtime_const_##sym sections but collect them in one __runtime_const,
>> just using __runtime_const { *(SORT_BY_NAME(__runtime_const_*)) } in the
>> linker script should already be enough to allow that binary search to
>> work (with whatever : AT(ADDR() ... ) magic is also required), with no
>> post-processing at build or runtime required.
>>
>
>As far as one section per symbol, this is *exactly* what the linker table infrastructure was intended to make clean and scalable.
>
>I think rejecting it was a big mistake. It is really a very useful general piece of infrastructure, and IMNSHO the whole notion of "oh, we won't ever need that many such tables" is just plain wrong (as evidenced here.)
>
>Either way, the problem isn't that hard; you end up doing something like:
>
>struct runtime_const {
> unsigned int size;
> reladdr_t entries[0];
>};
>
>#define DECLARE_RUNTIME_CONST(sym,type) \
>extern struct runtime_const sym;\
>asm(".pushsection \"runtime_const_" #sym ".Start\",\"a\"\n\t"
> ".globl " #sym "\n"
> #sym ": .int 2f - 1f\n\t"
> "1:\n"
> ".popsection\n\t"
> ".pushsection \"runtime_const_" #sym "._end\",\"a\"\n\t"
> "2:\n"
> ".popsection\n\t");
>
>... and add a common suffix, say, ".entry", for the entry section names. Then SORT_BY_NAME() will handle the rest.
>
> -hpa
>
Ok, the section naming is obviously bogus, but...
I just had an idea how to clearly make this type-safe as a benefit. I'm at a school event right now but I'll hack up a demo as soon as I get home.
next prev parent reply other threads:[~2024-06-11 20:16 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-08 19:35 Linus Torvalds
2024-06-08 20:55 ` Linus Torvalds
2024-06-09 3:11 ` Linus Torvalds
2024-06-10 12:10 ` Ard Biesheuvel
2024-06-09 11:22 ` Borislav Petkov
2024-06-09 11:47 ` H. Peter Anvin
2024-06-09 15:47 ` Linus Torvalds
2024-06-10 9:50 ` Rasmus Villemoes
2024-06-10 17:58 ` Linus Torvalds
2024-06-10 10:43 ` Peter Zijlstra
2024-06-10 12:02 ` Borislav Petkov
2024-06-10 18:20 ` Linus Torvalds
2024-06-10 20:39 ` H. Peter Anvin
2024-06-11 0:50 ` Linus Torvalds
2024-06-11 1:09 ` Linus Torvalds
2024-06-11 1:24 ` Linus Torvalds
2024-06-11 18:22 ` H. Peter Anvin
2024-06-11 13:21 ` Borislav Petkov
2024-06-10 13:38 ` Rasmus Villemoes
2024-06-11 19:43 ` H. Peter Anvin
2024-06-11 20:15 ` H. Peter Anvin [this message]
2024-06-11 20:26 ` Linus Torvalds
2024-06-10 18:06 ` Linus Torvalds
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=BFD0AF77-C95E-4B8B-B475-DCBD808CA5C0@zytor.com \
--to=hpa@zytor.com \
--cc=bp@alien8.de \
--cc=jpoimboe@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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
all inboxes | Powered by JetHome®