qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: Richard Henderson <rth@twiddle.net>
Cc: leon.alrae@imgtec.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 1/3] target-mips: Copy restrictions from ext/ins to dext/dins
Date: Mon, 3 Aug 2015 23:31:28 +0200	[thread overview]
Message-ID: <20150803213128.GA19612@aurel32.net> (raw)
In-Reply-To: <1438630553-21240-1-git-send-email-rth@twiddle.net>

On 2015-08-03 12:35, Richard Henderson wrote:
> The checks in dins is required to avoid triggering an assertion
> in tcg_gen_deposit_tl.  The check in dext is just for completeness.
> Fold the other D cases in via fallthru.
> 
> In this case the errant dins appears to be data, not code, as
> translation failed to stop after a break insn.
> 
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  target-mips/translate.c | 45 +++++++++++++++++++++++++--------------------
>  1 file changed, 25 insertions(+), 20 deletions(-)
> 
> diff --git a/target-mips/translate.c b/target-mips/translate.c
> index d1de35a..1cba415 100644
> --- a/target-mips/translate.c
> +++ b/target-mips/translate.c
> @@ -4750,48 +4750,53 @@ static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
>      gen_load_gpr(t1, rs);
>      switch (opc) {
>      case OPC_EXT:
> -        if (lsb + msb > 31)
> +        if (lsb + msb > 31) {
>              goto fail;
> +        }
>          tcg_gen_shri_tl(t0, t1, lsb);
>          if (msb != 31) {
> -            tcg_gen_andi_tl(t0, t0, (1 << (msb + 1)) - 1);
> +            tcg_gen_andi_tl(t0, t0, (1U << (msb + 1)) - 1);

Is this change really needed?

>          } else {
>              tcg_gen_ext32s_tl(t0, t0);
>          }
>          break;
>  #if defined(TARGET_MIPS64)
> -    case OPC_DEXTM:
> -        tcg_gen_shri_tl(t0, t1, lsb);
> -        if (msb != 31) {
> -            tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1 + 32)) - 1);
> -        }
> -        break;
>      case OPC_DEXTU:
> -        tcg_gen_shri_tl(t0, t1, lsb + 32);
> -        tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
> -        break;
> +        lsb += 32;
> +        goto do_dext;
> +    case OPC_DEXTM:
> +        msb += 32;
> +        goto do_dext;
>      case OPC_DEXT:
> +    do_dext:
> +        if (lsb + msb > 63) {
> +            goto fail;
> +        }

Note that DEXT can't fail as both lsb and msb are in the range 0..31.
DEXTU and DEXTM can.

>          tcg_gen_shri_tl(t0, t1, lsb);
> -        tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
> +        if (msb != 63) {
> +            tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
> +        }
>          break;
>  #endif
>      case OPC_INS:
> -        if (lsb > msb)
> +        if (lsb > msb) {
>              goto fail;
> +        }
>          gen_load_gpr(t0, rt);
>          tcg_gen_deposit_tl(t0, t0, t1, lsb, msb - lsb + 1);
>          tcg_gen_ext32s_tl(t0, t0);
>          break;
>  #if defined(TARGET_MIPS64)
> -    case OPC_DINSM:
> -        gen_load_gpr(t0, rt);
> -        tcg_gen_deposit_tl(t0, t0, t1, lsb, msb + 32 - lsb + 1);
> -        break;
>      case OPC_DINSU:
> -        gen_load_gpr(t0, rt);
> -        tcg_gen_deposit_tl(t0, t0, t1, lsb + 32, msb - lsb + 1);
> -        break;
> +        lsb += 32;
> +        /* FALLTHRU */
> +    case OPC_DINSM:
> +        msb += 32;

The same way DINSM can't fail.

> +        /* FALLTHRU */
>      case OPC_DINS:
> +        if (lsb > msb) {
> +            goto fail;
> +        }
>          gen_load_gpr(t0, rt);
>          tcg_gen_deposit_tl(t0, t0, t1, lsb, msb - lsb + 1);
>          break;

Despite the above comments:

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>

Should we try to get this one into 2.4, if not already too late?

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

  reply	other threads:[~2015-08-03 21:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03 18:49 [Qemu-devel] [PATCH 0/3] target-mips fixes Richard Henderson
2015-08-03 18:49 ` [Qemu-devel] [PATCH 1/3] target-mips: Copy restrictions from ext/ins to dext/dins Richard Henderson
2015-08-03 19:29   ` Richard Henderson
2015-08-03 19:35   ` [Qemu-devel] [PATCH v2 " Richard Henderson
2015-08-03 21:31     ` Aurelien Jarno [this message]
2015-08-03 21:41       ` Richard Henderson
2015-08-03 22:09         ` Aurelien Jarno
2015-08-04  8:22           ` Leon Alrae
2015-08-04 10:49     ` Leon Alrae
2015-08-03 18:49 ` [Qemu-devel] [PATCH 2/3] target-mips: Stop translation after unconditional exceptions Richard Henderson
2015-08-03 21:31   ` Aurelien Jarno
2015-08-03 21:47     ` Richard Henderson
2015-08-03 18:49 ` [Qemu-devel] [PATCH 3/3] target-mips: Use CPU_LOG_INT for logging related to interrupts Richard Henderson
2015-08-03 21:31   ` Aurelien Jarno

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=20150803213128.GA19612@aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=leon.alrae@imgtec.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).