qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] PPC: Avoid temporary leaks
@ 2014-05-15 16:28 Alexander Graf
  2014-05-15 16:28 ` [Qemu-devel] [PATCH 1/2] PPC: Fix TCG chunks that don't free their temps Alexander Graf
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexander Graf @ 2014-05-15 16:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc

Other targets have had it for quite a while, now PPC has it too! Temporary
leakage tracking.

Whenever we see that not all temporaries have been properly free'd at the
end of a guest instruction block we can now scream loudly at the user.

This hopefully ensures we don't leak as much as before :).


Alexander Graf (2):
  PPC: Fix TCG chunks that don't free their temps
  PPC: Fail on leaking temporaries

 target-ppc/translate.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

-- 
1.8.1.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 1/2] PPC: Fix TCG chunks that don't free their temps
  2014-05-15 16:28 [Qemu-devel] [PATCH 0/2] PPC: Avoid temporary leaks Alexander Graf
@ 2014-05-15 16:28 ` Alexander Graf
  2014-05-15 16:28 ` [Qemu-devel] [PATCH 2/2] PPC: Fail on leaking temporaries Alexander Graf
  2014-05-15 16:34 ` [Qemu-devel] [Qemu-ppc] [PATCH 0/2] PPC: Avoid temporary leaks Alexander Graf
  2 siblings, 0 replies; 4+ messages in thread
From: Alexander Graf @ 2014-05-15 16:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc

We want to make sure that every instruction cleans up after itself and
clears every temporary it allocated.

While checking whether this is already the case, I came across a few
cases where it isn't. This patch fixes every translation I found that
doesn't free their allocated temporaries.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 target-ppc/translate.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index fde6476..3a47b13 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -1224,6 +1224,7 @@ static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
             }
             tcg_gen_xor_tl(t1, arg2, inv1);         /* add without carry */
             tcg_gen_add_tl(t0, t0, inv1);
+            tcg_temp_free(inv1);
             tcg_gen_xor_tl(cpu_ca, t0, t1);         /* bits changes w/ carry */
             tcg_temp_free(t1);
             tcg_gen_shri_tl(cpu_ca, cpu_ca, 32);    /* extract bit 32 */
@@ -3920,6 +3921,9 @@ static inline void gen_bcond(DisasContext *ctx, int type)
         gen_update_nip(ctx, ctx->nip);
         tcg_gen_exit_tb(0);
     }
+    if (type == BCOND_LR || type == BCOND_CTR) {
+        tcg_temp_free(target);
+    }
 }
 
 static void gen_bc(DisasContext *ctx)
@@ -4367,6 +4371,7 @@ static void gen_mtmsr(DisasContext *ctx)
         tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
 #endif
         gen_helper_store_msr(cpu_env, msr);
+        tcg_temp_free(msr);
         /* Must stop the translation as machine state (may have) changed */
         /* Note that mtmsr is not always defined as context-synchronizing */
         gen_stop_exception(ctx);
@@ -6501,6 +6506,7 @@ static void gen_tlbsx_booke206(DisasContext *ctx)
 
     tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
     gen_helper_booke206_tlbsx(cpu_env, t0);
+    tcg_temp_free(t0);
 #endif
 }
 
@@ -6534,6 +6540,7 @@ static void gen_tlbivax_booke206(DisasContext *ctx)
     gen_addr_reg_index(ctx, t0);
 
     gen_helper_booke206_tlbivax(cpu_env, t0);
+    tcg_temp_free(t0);
 #endif
 }
 
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 2/2] PPC: Fail on leaking temporaries
  2014-05-15 16:28 [Qemu-devel] [PATCH 0/2] PPC: Avoid temporary leaks Alexander Graf
  2014-05-15 16:28 ` [Qemu-devel] [PATCH 1/2] PPC: Fix TCG chunks that don't free their temps Alexander Graf
@ 2014-05-15 16:28 ` Alexander Graf
  2014-05-15 16:34 ` [Qemu-devel] [Qemu-ppc] [PATCH 0/2] PPC: Avoid temporary leaks Alexander Graf
  2 siblings, 0 replies; 4+ messages in thread
From: Alexander Graf @ 2014-05-15 16:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc

When QEMU gets compiled with --enable-debug-tcg we can check for temporary
leakage. Implement the necessary target code for this and fail emulation
when we hit a leakage.

This hopefully ensures that we don't get new leaks.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 target-ppc/translate.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index 3a47b13..e9e7812 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -11767,6 +11767,7 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
         max_insns = CF_COUNT_MASK;
 
     gen_tb_start();
+    tcg_clear_temp_count();
     /* Set env in case of segfault during code fetch */
     while (ctx.exception == POWERPC_EXCP_NONE
             && tcg_ctx.gen_opc_ptr < gen_opc_end) {
@@ -11866,6 +11867,12 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
              */
             break;
         }
+        if (tcg_check_temp_count()) {
+            fprintf(stderr, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
+                    opc1(ctx.opcode), opc2(ctx.opcode), opc3(ctx.opcode),
+                    ctx.opcode);
+            exit(1);
+        }
     }
     if (tb->cflags & CF_LAST_IO)
         gen_io_end();
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH 0/2] PPC: Avoid temporary leaks
  2014-05-15 16:28 [Qemu-devel] [PATCH 0/2] PPC: Avoid temporary leaks Alexander Graf
  2014-05-15 16:28 ` [Qemu-devel] [PATCH 1/2] PPC: Fix TCG chunks that don't free their temps Alexander Graf
  2014-05-15 16:28 ` [Qemu-devel] [PATCH 2/2] PPC: Fail on leaking temporaries Alexander Graf
@ 2014-05-15 16:34 ` Alexander Graf
  2 siblings, 0 replies; 4+ messages in thread
From: Alexander Graf @ 2014-05-15 16:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc


On 15.05.14 18:28, Alexander Graf wrote:
> Other targets have had it for quite a while, now PPC has it too! Temporary
> leakage tracking.
>
> Whenever we see that not all temporaries have been properly free'd at the
> end of a guest instruction block we can now scream loudly at the user.
>
> This hopefully ensures we don't leak as much as before :).

Oops - I missed that I already sent these patches before. I guess I can 
just apply them straight ahead then. Sorry for the fuss :).


Alex

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-15 16:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-15 16:28 [Qemu-devel] [PATCH 0/2] PPC: Avoid temporary leaks Alexander Graf
2014-05-15 16:28 ` [Qemu-devel] [PATCH 1/2] PPC: Fix TCG chunks that don't free their temps Alexander Graf
2014-05-15 16:28 ` [Qemu-devel] [PATCH 2/2] PPC: Fail on leaking temporaries Alexander Graf
2014-05-15 16:34 ` [Qemu-devel] [Qemu-ppc] [PATCH 0/2] PPC: Avoid temporary leaks Alexander Graf

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).