Re: [GIT pull] x86/urgent for v5.15-rc3

From: Borislav Petkov
Date: Sun Sep 26 2021 - 14:16:01 EST


On Sun, Sep 26, 2021 at 10:21:18AM -0700, Linus Torvalds wrote:
> On Sun, Sep 26, 2021 at 3:30 AM Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
> >
> > - Prevent undefined behaviour to the potential unaligned accesss in the
> > instroction decoder library.
>
> What a horrible fix that is.
>
> This is why we have "get_unaligned()". It might use memcpy()
> internally on some architectures (it doesn't really any more - Arnd
> cleaned it all up and now it uses a pointer that is marked unaligned),
> but more importantly it explains _why_ something is done the way it's
> done, rather than be an odd memcpy().
>
> Oh well. The memcpy works, and compilers will do the right thing for
> it, but it's ugly.
>
> In this case, it's actually *doubly* ugly, though, because we
> literally have functions to "load unaligned data in little-endian
> format".
>
> So instead of doing a "memcpy()", followed by a magic special macro
> that does a "switch (sizeof(t))" and does a "le*_to_cpu()" on the
> result, the code could literally have used the functions that do this
> all for them.
>
> Ugh. Pulled. But it's ugly.

Yeah, that came up during review:

https://lore.kernel.org/lkml/CAP-5=fU2XBoOa2=00VCuWYqsLUzMSMzUXY63ZJt9rz-NJ+vYwA@xxxxxxxxxxxxxx/

and the follow-on messages and AFAICT the only hurdle to using
get_unaligned() is exporting it into tools/ for use by the version of
the insn decoder there in tools/arch/x86/lib/insn.c.

There's this other rather "theoretical" thing of Intel PT
decoding being done on any arch but get_unaligned() from
include/asm-generic/unaligned.h looks as generic and as arch-agnostic as
they get, to me...

But let me add the gents to Cc.

--
Regards/Gruss,
Boris.

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