mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Ard Biesheuvel <ardb+git@google.com>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	Ard Biesheuvel <ardb@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC PATCH 3/3] x86/boot: Use alternatives based selector for 5-level paging constants
Date: Tue, 6 May 2025 18:50:32 +0200	[thread overview]
Message-ID: <aBo92LQh4WYXyRXK@gmail.com> (raw)
In-Reply-To: <20250506154532.1281909-8-ardb+git@google.com>


* Ard Biesheuvel <ardb+git@google.com> wrote:

> +static inline int __attribute_const__ choose_l5_enabled(int yes, int no)
> +{
> +	int ret = no;
> +
> +	asm_inline(ALTERNATIVE_TERNARY("jmp 6f; 8:", %c[feat], "movl %[yes], %[ret]", "")
> +		"	.pushsection .altinstr_aux,\"ax\"	\n"
> +		"6:	pushfq					\n"
> +		"	testb	$1, %a[l5en]			\n"
> +		"	jz	7f				\n"
> +		"	movl	%[yes], %[ret]			\n"
> +		"7:	popfq					\n"
> +		"	jmp	8b				\n"
> +		"	.popsection				\n"
> +		: [ret]  "+rm" (ret)
> +		: [feat] "i" (X86_FEATURE_LA57),
> +		  [yes]	 "i" (yes),
> +		  [l5en] "i" (&__pgtable_l5_enabled));
> +
> +	return ret;

So why not create a new synthethic cpufeature flag, 
X86_FEATURE_LA57_ENABLED or so, which could then be queried via the 
regular facilities? This ternary logic is not really needed, because 
the hardware isn't ternary. :)

With that we could do with only a single, obvious line of ALTERNATIVE() 
assembly:

        #define ALTERNATIVES_CONST_U32(__val1, __val2, __feature)       \
        ({                                                              \
                u32 __val;                                              \
                                                                        \
                asm_inline (ALTERNATIVE("movl $" #__val1 ", %0", "movl $" __val2 ", %0", __feature) :"=g" (__val)); \
                                                                        \
                __val;                                                  \
        })

        ...

        #define MAX_PHYSMEM_BITS ALTERNATIVE_CONST_U32(46, 52, X86_FEATURE_LA57_ENABLED)

Thanks,

	Ingo

  parent reply	other threads:[~2025-05-06 16:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06 15:45 [RFC PATCH 0/3] x86: Robustify pgtable_l5_enabled() Ard Biesheuvel
2025-05-06 15:45 ` [RFC PATCH 1/3] x86/boot: Use a single source of truth for pgtable_l5_enabled() Ard Biesheuvel
2025-05-06 15:45 ` [RFC PATCH 2/3] x86/boot: Set __pgtable_l5_enabled correctly before calling into C code Ard Biesheuvel
2025-05-10 13:54   ` David Laight
2025-05-10 14:51     ` Ard Biesheuvel
2025-05-06 15:45 ` [RFC PATCH 3/3] x86/boot: Use alternatives based selector for 5-level paging constants Ard Biesheuvel
2025-05-06 16:23   ` Linus Torvalds
2025-05-06 16:34     ` Ard Biesheuvel
2025-05-06 17:03       ` Linus Torvalds
2025-05-06 17:25         ` Ard Biesheuvel
2025-05-06 17:39           ` Ingo Molnar
2025-05-06 17:47             ` Ard Biesheuvel
2025-05-06 17:43           ` Linus Torvalds
2025-05-06 17:52             ` Ard Biesheuvel
2025-05-06 18:17               ` Linus Torvalds
2025-05-06 18:39                 ` Linus Torvalds
2025-05-06 19:14                   ` Ard Biesheuvel
2025-05-06 19:41                     ` Linus Torvalds
2025-05-06 19:50                       ` Ard Biesheuvel
2025-05-07 13:51                         ` Ard Biesheuvel
2025-05-06 16:50   ` Ingo Molnar [this message]
2025-05-06 16:58     ` Ard Biesheuvel

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=aBo92LQh4WYXyRXK@gmail.com \
    --to=mingo@kernel.org \
    --cc=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

Powered by JetHome