Re: [RFC 20/31] objtool: Add UD1 detection

From: Josh Poimboeuf
Date: Tue Sep 03 2024 - 22:25:19 EST


On Tue, Sep 03, 2024 at 10:17:48AM +0200, Peter Zijlstra wrote:
> On Mon, Sep 02, 2024 at 09:00:03PM -0700, Josh Poimboeuf wrote:
> > A UD1 isn't a BUG and shouldn't be treated like one.
> >
> > Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> > ---
> > tools/objtool/arch/x86/decode.c | 10 +++++++++-
> > 1 file changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
> > index 6b34b058a821..72d55dcd3d7f 100644
> > --- a/tools/objtool/arch/x86/decode.c
> > +++ b/tools/objtool/arch/x86/decode.c
> > @@ -528,11 +528,19 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
> > /* sysenter, sysret */
> > insn->type = INSN_CONTEXT_SWITCH;
> >
> > - } else if (op2 == 0x0b || op2 == 0xb9) {
> > + } else if (op2 == 0x0b) {
> >
> > /* ud2 */
> > insn->type = INSN_BUG;
> >
> > + } else if (op2 == 0xb9) {
> > +
> > + /*
> > + * ud1 - only used for the static call trampoline to
> > + * stop speculation. Basically used like an int3.
> > + */
> > + insn->type = INSN_TRAP;
> > +
> > } else if (op2 == 0x0d || op2 == 0x1f) {
> >
> > /* nopl/nopw */
>
> We recently grew more UD1 usage...
>
> ---
> commit 7424fc6b86c8980a87169e005f5cd4438d18efe6
> Author: Gatlin Newhouse <gatlin.newhouse@xxxxxxxxx>
> Date: Wed Jul 24 00:01:55 2024 +0000

Interesting, thanks. I'm having a senior moment as I can't remember why
this patch exists -- maybe it was code inspection? My patch desciption
is awful. I'll just drop it for now.

--
Josh