qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, qemu-stable@nongnu.org,
	Michael Tokarev <mjt@tls.msk.ru>
Subject: Re: [PATCH] target/i386: Do not re-compute new pc with CF_PCREL
Date: Mon, 21 Oct 2024 10:21:18 -0700	[thread overview]
Message-ID: <26fa8078-35e1-4c11-ab5c-1c8ae08d296f@linaro.org> (raw)
In-Reply-To: <20240101230617.129349-1-richard.henderson@linaro.org>

On 1/1/24 15:06, Richard Henderson wrote:
> With PCREL, we have a page-relative view of EIP, and an
> approximation of PC = EIP+CSBASE that is good enough to
> detect page crossings.  If we try to recompute PC after
> masking EIP, we will mess up that approximation and write
> a corrupt value to EIP.
> 
> We already handled masking properly for PCREL, so the
> fix in b5e0d5d2 was only needed for the !PCREL path.
> 
> Cc: qemu-stable@nongnu.org
> Fixes: b5e0d5d22fbf ("target/i386: Fix 32-bit wrapping of pc/eip computation")
> Reported-by: Michael Tokarev <mjt@tls.msk.ru>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/i386/tcg/translate.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
> index 037bc47e7c..e68375b19d 100644
> --- a/target/i386/tcg/translate.c
> +++ b/target/i386/tcg/translate.c
> @@ -2845,10 +2845,6 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num)
>           }
>       }
>       new_eip &= mask;
> -    new_pc = new_eip + s->cs_base;
> -    if (!CODE64(s)) {
> -        new_pc = (uint32_t)new_pc;
> -    }
>   
>       gen_update_cc_op(s);
>       set_cc_op(s, CC_OP_DYNAMIC);
> @@ -2864,6 +2860,8 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num)
>               tcg_gen_andi_tl(cpu_eip, cpu_eip, mask);
>               use_goto_tb = false;
>           }
> +    } else if (!CODE64(s)) {
> +        new_pc = (uint32_t)(new_eip + s->cs_base);
>       }
>   
>       if (use_goto_tb && translator_use_goto_tb(&s->base, new_pc)) {

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>


      reply	other threads:[~2024-10-21 17:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-01 23:06 [PATCH] target/i386: Do not re-compute new pc with CF_PCREL Richard Henderson
2024-10-21 17:21 ` Pierrick Bouvier [this message]

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=26fa8078-35e1-4c11-ab5c-1c8ae08d296f@linaro.org \
    --to=pierrick.bouvier@linaro.org \
    --cc=mjt@tls.msk.ru \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=richard.henderson@linaro.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;
as well as URLs for NNTP newsgroup(s).