From: Kees Cook <keescook@chromium.org>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
Peter Zijlstra <peterz@infradead.org>,
Dave Hansen <dave.hansen@intel.com>,
linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH v2 3/3] efi: x86: Wire up IBT annotation in memory attributes table
Date: Thu, 9 Feb 2023 08:37:48 -0800 [thread overview]
Message-ID: <63e5215c.630a0220.1f01a.2993@mx.google.com> (raw)
In-Reply-To: <CAMj1kXHZwKPifJu1Y+hvjivJWU9YMJHyR84Y23nMsYrCxM0uYw@mail.gmail.com>
On Thu, Feb 09, 2023 at 05:23:02PM +0100, Ard Biesheuvel wrote:
> On Thu, 9 Feb 2023 at 17:13, Kees Cook <keescook@chromium.org> wrote:
> >
> > On Wed, Feb 08, 2023 at 08:55:19PM +0000, Mark Rutland wrote:
> > > On Wed, Feb 08, 2023 at 09:14:53PM +0100, Peter Zijlstra wrote:
> > > > On Wed, Feb 08, 2023 at 07:17:15AM -0800, Dave Hansen wrote:
> > > > > On 2/6/23 04:49, Ard Biesheuvel wrote:
> > > > > > --- a/arch/x86/kernel/apm_32.c
> > > > > > +++ b/arch/x86/kernel/apm_32.c
> > > > > > @@ -609,7 +609,7 @@ static long __apm_bios_call(void *_call)
> > > > > >
> > > > > > apm_irq_save(flags);
> > > > > > firmware_restrict_branch_speculation_start();
> > > > > > - ibt = ibt_save();
> > > > > > + ibt = ibt_save(true);
> > > > >
> > > > > My only nit with these is the bare use of 'true'/'false'. It's
> > > > > impossible to tell at the call-site what the 'true' means. So, if you
> > > > > happen to respin these and see a nice way to remedy this I'd appreciate it.
> > > >
> > > > I've often wished for a named argument extention to C, much like named
> > > > initializers, such that one can write:
> > > >
> > > > ibt_save(.disable = true);
> > > >
> > > > Because the thing you mention is very common with boolean arguments, the
> > > > what gets lost in the argument name and true/false just isn't very
> > > > telling.
> > > >
> > > > But yeah, even if by some miracle all compiler guys were like, YES! and
> > > > implemented it tomorrow, we couldn't use it for a good few years anyway
> > > > :-/
> > >
> > > Well... ;)
> > >
> > > | [mark@lakrids:~]% cat args.c
> > > | #include <stdbool.h>
> > > | #include <stdio.h>
> > > |
> > > | struct foo_args {
> > > | bool enable;
> > > | unsigned long other;
> > > | };
> > > |
> > > | void __foo(struct foo_args args)
> > > | {
> > > | printf("foo:\n"
> > > | " enable: %s\n"
> > > | " other: 0x%lx\n",
> > > | args.enable ? "YES" : "NO",
> > > | args.other);
> > > | }
> > > |
> > > | #define foo(args...) \
> > > | __foo((struct foo_args) { args })
> > > |
> > > |
> > > | int main(int argc, char *argv[])
> > > | {
> > > | foo(true);
> > > | foo(.enable = true);
> > > | foo(false, .other=0xdead);
> > > | }
> > > | [mark@lakrids:~]% gcc args.c -o args
> > > | [mark@lakrids:~]% ./args
> > > | foo:
> > > | enable: YES
> > > | other: 0x0
> > > | foo:
> > > | enable: YES
> > > | other: 0x0
> > > | foo:
> > > | enable: NO
> > > | other: 0xdead
> >
> > I am horrified and delighted.
>
> +1
>
> > And the resulting codegen is identical:
> > https://godbolt.org/z/eKTMPYc17
> >
> > Without this fancy solution, what I'd seen is just using an enum:
> >
> > enum do_the_thing {
> > THING_DISABLE = 0,
> > THING_ENABLE,
> > };
> >
> > void foo(enum do_the_thing enable)
> > {
> > if (enable) { ... }
> > }
> >
> > foo(THING_ENABLE);
> >
>
> I have no strong preference one way or the other, but given that
> apm_32.c is not the epicenter of new development, and the call from
> EFI code is self-documenting already ('
> ibt_save(efi_disable_ibt_for_runtime)', I'm inclined to just queue the
> patch as-is, and leave it to whoever feels inclined to spend more free
> time on this to come up with some nice polish to put on top.
>
> Unless anyone minds?
Yeah, this was just commentary. I think the patch is fine as-is.
--
Kees Cook
next prev parent reply other threads:[~2023-02-09 16:37 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-06 12:49 [PATCH v2 0/3] efi: Enable BTI for EFI runtimes services Ard Biesheuvel
2023-02-06 12:49 ` [PATCH v2 1/3] efi: Discover BTI support in runtime services regions Ard Biesheuvel
2023-02-06 12:49 ` [PATCH v2 2/3] efi: arm64: Wire up BTI annotation in memory attributes table Ard Biesheuvel
2023-02-08 13:00 ` Will Deacon
2023-02-08 13:03 ` Ard Biesheuvel
2023-02-08 14:25 ` Mark Rutland
2023-02-08 14:36 ` Ard Biesheuvel
2023-02-09 14:21 ` Ard Biesheuvel
2023-02-09 15:13 ` Mark Rutland
2023-02-09 15:48 ` Will Deacon
2023-02-20 15:53 ` Mark Brown
2023-02-20 16:46 ` Ard Biesheuvel
2023-02-06 12:49 ` [PATCH v2 3/3] efi: x86: Wire up IBT " Ard Biesheuvel
2023-02-08 15:17 ` Dave Hansen
2023-02-08 20:14 ` Peter Zijlstra
2023-02-08 20:55 ` Mark Rutland
2023-02-09 16:13 ` Kees Cook
2023-02-09 16:23 ` Ard Biesheuvel
2023-02-09 16:27 ` Dave Hansen
2023-02-09 16:37 ` Kees Cook [this message]
2023-02-08 17:30 ` Peter Zijlstra
2023-02-08 12:35 ` [PATCH v2 0/3] efi: Enable BTI for EFI runtimes services 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=63e5215c.630a0220.1f01a.2993@mx.google.com \
--to=keescook@chromium.org \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will@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