Skip to contentSkip to conversation

target-mips/translate.c: Free TCG in OPC_DINSV

PATCH In review Dongxue Zhang 3 participants 12 messages Jul 28, 2014 – Jul 29, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 target-mips/translate.c: Free TCG in OPC_DINSV

Free t0 and t1 in opcode OPC_DINSV.

---
 target-mips/translate.c | 3 +++
 1 file changed, 3 insertions(+)
target-mips/translate.c +3 -0
index d7b8c4d..c381366 100644
@@ -15300,6 +15300,9 @@ static void decode_opc (CPUMIPSState *env, DisasContext *ctx)
                     gen_load_gpr(t1, rs);
 
                     gen_helper_dinsv(cpu_gpr[rt], cpu_env, t1, t0);
+
+                    tcg_temp_free(t0);
+                    tcg_temp_free(t1);
                     break;
                 }
             default:            /* Invalid */
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH 2/2 target-mips/translate.c: Add judgement for msb and lsb

Use 'if' to make sure the real msb greater than the lsb. As the compiler may not do this.

---
 target-mips/translate.c | 9 +++++++++
 1 file changed, 9 insertions(+)
target-mips/translate.c +9 -0
index c381366..e2cce31 100644
@@ -3946,14 +3946,23 @@ static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
         break;
 #if defined(TARGET_MIPS64)
     case OPC_DINSM:
+        if (lsb > (msb + 32)) {
+            goto fail;
+        }
         gen_load_gpr(t0, rt);
         tcg_gen_deposit_tl(t0, t0, t1, lsb, msb + 32 - lsb + 1);
         break;
     case OPC_DINSU:
+        if (lsb > msb) {
+            goto fail;
+        }
         gen_load_gpr(t0, rt);
         tcg_gen_deposit_tl(t0, t0, t1, lsb + 32, msb - lsb + 1);
         break;
     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;
Signature · 1 line
1.8.1.2
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

Quoted 2 lines · Dongxue Zhang

Use 'if' to make sure the real msb greater than the lsb. As the compiler may not do this.

What are you trying to fix exactly? These cases are defined as "unpredictable" in the MIPS ISA manual, which is what is implemented in QEMU. In addition on the MIPS64R2 implementations I tested (Cavium Octeon, Loongson 3) these cases do not trigger a reserved instruction exception.

Quoted 10 lines
---
 target-mips/translate.c | 9 +++++++++
 1 file changed, 9 insertions(+)
target-mips/translate.c +0 -0
index c381366..e2cce31 100644

target-mips/translate.c static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt, · line 3951

Quoted 6 lines
target-mips/translate.c +3 -0
@@ -3946,14 +3946,23 @@ static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
         break;
 #if defined(TARGET_MIPS64)
     case OPC_DINSM:
+        if (lsb > (msb + 32)) {
+            goto fail;
+        }

This test is always false, as lsb and msb are 5 bits values.

Quoted 22 lines
target-mips/translate.c +6 -0
         gen_load_gpr(t0, rt);
         tcg_gen_deposit_tl(t0, t0, t1, lsb, msb + 32 - lsb + 1);
         break;
     case OPC_DINSU:
+        if (lsb > msb) {
+            goto fail;
+        }
         gen_load_gpr(t0, rt);
         tcg_gen_deposit_tl(t0, t0, t1, lsb + 32, msb - lsb + 1);
         break;
     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;
Signature · 1 line
1.8.1.2
Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

Quoted 7 lines · Aurelien Jarno
Quoted 2 lines · Dongxue Zhang

Use 'if' to make sure the real msb greater than the lsb. As the compiler may not do this.

What are you trying to fix exactly? These cases are defined as "unpredictable" in the MIPS ISA manual, which is what is implemented in QEMU.

This may be true, but the TCG README doesn't define negative lengths as being "unspecified behaviour" (ie guaranteed to at least not crash even if the result isn't specified), and in fact the implementation of tcg_gen_deposit will assert on negative lengths. We shouldn't implement guest unpredictable cases as "crash QEMU".

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

Quoted 9 lines · Peter Maydell
Quoted 7 lines · Aurelien Jarno
Quoted 2 lines · Dongxue Zhang

Use 'if' to make sure the real msb greater than the lsb. As the compiler may not do this.

What are you trying to fix exactly? These cases are defined as "unpredictable" in the MIPS ISA manual, which is what is implemented in QEMU.

Quoted 5 lines

This may be true, but the TCG README doesn't define negative lengths as being "unspecified behaviour" (ie guaranteed to at least not crash even if the result isn't specified), and in fact the implementation of tcg_gen_deposit will assert on negative lengths. We shouldn't implement guest unpredictable cases as "crash QEMU".

Well I tried this code under QEMU, and it clearly doesn't crash. It seems the assert are not enabled with the default configuration options. That said I agree it's something to avoid, but I don't think triggering a RI exception is the thing to do (even if it is correct according the MIPS ISA manual) when real silicon output a random result instead.

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

Quoted 9 lines · Aurelien Jarno
Quoted 5 lines · Peter Maydell

This may be true, but the TCG README doesn't define negative lengths as being "unspecified behaviour" (ie guaranteed to at least not crash even if the result isn't specified), and in fact the implementation of tcg_gen_deposit will assert on negative lengths. We shouldn't implement guest unpredictable cases as "crash QEMU".

Well I tried this code under QEMU, and it clearly doesn't crash. It seems the assert are not enabled with the default configuration options.

Try --enable-debug...

Quoted 3 lines

That said I agree it's something to avoid, but I don't think triggering a RI exception is the thing to do (even if it is correct according the MIPS ISA manual) when real silicon output a random result instead.

Yes, you could emit code to do that instead if you like.

thanks
-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

Quoted 8 lines · Peter Maydell
Quoted 7 lines · Aurelien Jarno
Quoted 5 lines · Peter Maydell

This may be true, but the TCG README doesn't define negative lengths as being "unspecified behaviour" (ie guaranteed to at least not crash even if the result isn't specified), and in fact the implementation of tcg_gen_deposit will assert on negative lengths. We shouldn't implement guest unpredictable cases as "crash QEMU".

Quoted 4 lines
Quoted 2 lines

Well I tried this code under QEMU, and it clearly doesn't crash. It seems the assert are not enabled with the default configuration options.

Try --enable-debug...

That's my point, it's only in debug mode, not in the default configuration.

Quoted 5 lines
Quoted 3 lines

That said I agree it's something to avoid, but I don't think triggering a RI exception is the thing to do (even if it is correct according the MIPS ISA manual) when real silicon output a random result instead.

Yes, you could emit code to do that instead if you like.

When I said random, it didn't say in the sense of random generator, but in the sense a result that might depend on the input value and the silicon implementation. It would be silly to emit code just for that, but it would be smart for example to skip the deposit op in that case instead of triggering an exception.

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
author
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

Quoted 8 lines · Aurelien Jarno
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Aurelien Jarno
Quoted 5 lines · Peter Maydell

This may be true, but the TCG README doesn't define negative lengths as being "unspecified behaviour" (ie guaranteed to at least not crash even if the result isn't specified), and in fact the implementation of tcg_gen_deposit will assert on negative lengths. We shouldn't implement guest unpredictable cases as "crash QEMU".

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Well I tried this code under QEMU, and it clearly doesn't crash. It seems the assert are not enabled with the default configuration options.

Try --enable-debug...

That's my point, it's only in debug mode, not in the default configuration.

Maybe remove the tcg_debug_assert in tcg_gen_deposit_i64 and tcg_gen_deposit_i64 is a better way. But it may cause other mistake in other architecture, i'm not sure.

Quoted 11 lines
Quoted 5 lines
Quoted 4 lines

That said I agree it's something to avoid, but I don't think triggering a RI exception is the thing to do (even if it is correct according the MIPS ISA manual) when real silicon output a random result instead.

Yes, you could emit code to do that instead if you like.

When I said random, it didn't say in the sense of random generator, but in the sense a result that might depend on the input value and the silicon implementation. It would be silly to emit code just for that, but it would be smart for example to skip the deposit op in that case instead of triggering an exception.

I think, debug mode shouldn't crash the qemu with an unpredictable operation, so i want to fix it. And you say there shouldn't raise RI, i agree with you.

Or when lsb > msb, just leave the code and do nothing. What do you think about this way?

#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

Quoted 3 lines · Elta

I think, debug mode shouldn't crash the qemu with an unpredictable operation,
so i want to fix it. And you say there shouldn't raise RI, i agree with you.

Agreed.

Quoted 3 lines

Or when lsb > msb, just leave the code and do nothing. What do you think about
this way?

Yes, you can use something like:

    if (lsb <= msb) {
        deposit(...)
    }
Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

Ok, I got you. I will re-build a new patch for all the bitops.

2014-07-29 22:08 GMT+08:00 Aurelien Jarno <[email protected]>:

Quoted 22 lines · Elta
Quoted 3 lines

I think, debug mode shouldn't crash the qemu with an unpredictable operation,
so i want to fix it. And you say there shouldn't raise RI, i agree with

you.

Agreed.

Quoted 3 lines

Or when lsb > msb, just leave the code and do nothing. What do you think about
this way?

Yes, you can use something like:

    if (lsb <= msb) {
        deposit(...)
    }

--
Aurelien Jarno GPG: 4096R/1DDD8C9B
[email protected] http://www.aurel32.net

#10 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-mips/translate.c: Add judgement for msb and lsb

In reply to Aurelien Jarno
Quoted 9 lines · Aurelien Jarno
Quoted 8 lines · Peter Maydell
Quoted 7 lines · Aurelien Jarno
Quoted 5 lines · Peter Maydell

This may be true, but the TCG README doesn't define negative lengths as being "unspecified behaviour" (ie guaranteed to at least not crash even if the result isn't specified), and in fact the implementation of tcg_gen_deposit will assert on negative lengths. We shouldn't implement guest unpredictable cases as "crash QEMU".

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Well I tried this code under QEMU, and it clearly doesn't crash. It seems the assert are not enabled with the default configuration options.

Try --enable-debug...

That's my point, it's only in debug mode, not in the default configuration.

Debug builds are pretty common though, it's not exactly something obscure like "only crashes on SPARC hosts".

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

That said I agree it's something to avoid, but I don't think triggering a RI exception is the thing to do (even if it is correct according the MIPS ISA manual) when real silicon output a random result instead.

Yes, you could emit code to do that instead if you like.

When I said random, it didn't say in the sense of random generator, but in the sense a result that might depend on the input value and the silicon implementation. It would be silly to emit code just for that, but it would be smart for example to skip the deposit op in that case instead of triggering an exception.

That's what I had in mind, yes.

thanks
-- PMM

#11 lore raw
In reply to Dongxue Zhang
Quoted 12 lines · Dongxue Zhang

Free t0 and t1 in opcode OPC_DINSV.

---
 target-mips/translate.c | 3 +++
 1 file changed, 3 insertions(+)
target-mips/translate.c +0 -0
index d7b8c4d..c381366 100644

target-mips/translate.c static void decode_opc (CPUMIPSState *env, DisasContext *ctx) · line 15308

Quoted 9 lines
target-mips/translate.c +3 -0
@@ -15300,6 +15300,9 @@ static void decode_opc (CPUMIPSState *env, DisasContext *ctx)
                     gen_load_gpr(t1, rs);
 
                     gen_helper_dinsv(cpu_gpr[rt], cpu_env, t1, t0);
+
+                    tcg_temp_free(t0);
+                    tcg_temp_free(t1);
                     break;
                 }
             default:            /* Invalid */

Good catch, I applied the patch.

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net