Re: [PATCH v1 04/19] x86/insn-eval: Handle return values from the decoder

From: Borislav Petkov
Date: Mon Dec 28 2020 - 14:07:03 EST


On Mon, Dec 28, 2020 at 10:51:15AM -0800, Sean Christopherson wrote:
> This patch is incomplete/inconsistent, and arguably wrong.
>
> - get_eff_addr_reg() and get_eff_addr_modrm() still ignore the return of
> insn_get_modrm() after this patch.

Ah, will fix, thx.

> - Calling insn_get_modrm() from get_eff_addr_sib() is unnecessary (unless the
> caller passed uninitialized garbage in @insn) as get_eff_addr_sib() is
> called if and only if sib.nbytes!=0, and sib.nbytes can be non-zero if and
> only if the modrm and sib have been got.
>
> - get_addr_ref_16() does insn_get_displacement, i.e. guarantees the modrm is
> parsed, while the 32/64 variants do not.
>
> What about adding a prereq patch (or three) to call insn_get_displacement() in
> insn_get_addr_ref() prior to switching on insn->addr_bytes? Then the various
> internal helpers could be changed to either omit the sanity checks entirely or
> WARN on invalid calls? Or better yet, add an INSN_WARN_ON() macro that compiles
> out the checks by default? E.g. something like:

So the idea is one construction site at a time (that's a German saying :)).

This set deals with whacking the insn decoder into returning
proper error/success values. The next set should do
simplifications/fixes/cleanups/whatever but not all at the same time for
obvious reasons.

So yeah, I'm all for omitting useless code but let's do that ontop.

Thx.

--
Regards/Gruss,
Boris.

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