[PATCH] x86: Do not dump DS/CS segment overrides for branch hints

H.J. Lu hjl.tools@gmail.com
Sat Nov 28 14:07:37 GMT 2020


On Sat, Nov 28, 2020 at 5:41 AM Borislav Petkov <bp@suse.de> wrote:
>
> Hi,
>
> the change in this thread caused one regression, here's a fix. Sorry
> about that.
>
> ---
> From: Borislav Petkov <bp@suse.de>
>
> The previous change
>
>   "x86: Ignore CS/DS/ES/SS segment-override prefixes in 64-bit mode"
>
> to ignore segment override prefixes in 64-bit mode lead to dumping
> branch hints as excessive prefixes:
>
>   ffffffff8109d5a0 <vmx_get_rflags>:
>   ...
>   ffffffff8109d601:       3e 77 0a                ds ja,pt ffffffff8109d60e <vmx_get_rflags+0x6e>
>                                                 ^^^^^
>
> In this particular case, those prefixes are not excessive but are used
> to provide branch hints - taken/not-taken - to the CPU.
>
> Assign active_seg_prefix in that particular case to consume them.
>
> opcodes /
>
> 2020-11-28 Borislav Petkov  <bp@suse.de>
>
>         * i386-dis.c (print_insn): Set active_seg_prefix for branch hint insns
>         to not dump branch hint prefixes 0x2E and 0x3E as unused prefixes.
> ---
>  opcodes/ChangeLog  |  5 +++++
>  opcodes/i386-dis.c | 10 ++++++++--
>  2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
> index 1e7e40fd9664..02fd2f5b5837 100644
> --- a/opcodes/ChangeLog
> +++ b/opcodes/ChangeLog
> @@ -1,3 +1,8 @@
> +2020-11-28 Borislav Petkov  <bp@suse.de>
> +
> +       * i386-dis.c (print_insn): Set active_seg_prefix for branch hint insns
> +       to not dump branch hint prefixes 0x2E and 0x3E as unused prefixes.
> +
>  2020-11-16  Przemyslaw Wirkus  <przemyslaw.wirkus@arm.com>
>
>         * aarch64-tbl.h (FLAGM): Handle for FLAGM feature.
> diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
> index 58cf001080bc..d1b3f50f7b70 100644
> --- a/opcodes/i386-dis.c
> +++ b/opcodes/i386-dis.c
> @@ -10910,10 +10910,16 @@ putop (const char *in_template, int sizeflag)
>               used_prefixes |= prefixes & (PREFIX_CS | PREFIX_DS);
>               *obufp++ = ',';
>               *obufp++ = 'p';
> -             if (prefixes & PREFIX_DS)
> +
> +             /* Set active_seg_prefix even if not set in 64-bit mode because
> +              * here it is a valid branch hint. */
> +             if (prefixes & PREFIX_DS) {
> +               active_seg_prefix = PREFIX_DS;
>                 *obufp++ = 't';
> -             else
> +             } else {
> +               active_seg_prefix = PREFIX_CS;
>                 *obufp++ = 'n';
> +             }
>             }
>           break;
>         case 'K':
> --
> 2.21.0
>

Please add a testcase to show that the regression is fixed.

-- 
H.J.


More information about the Binutils mailing list