Skip to contentSkip to conversation

target/ppc: fix mtmsr instruction for icount

PATCH Applied Pavel Dovgalyuk 5 participants 7 messages Oct 30, 2018 – Nov 7, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/ppc: fix mtmsr instruction for icount

This patch fixes processing of mtmsr instructions in icount mode. In this mode writing to interrupt/peripheral state is controlled by can_do_io flag. This flag must be set explicitly before helper function invocation.

---
 target/ppc/translate.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
target/ppc/translate.c +12 -0
index 4e59dd5..987ce6e 100644
@@ -4257,11 +4257,17 @@ static void gen_mtmsrd(DisasContext *ctx)
          *      if we enter power saving mode, we will exit the loop
          *      directly from ppc_store_msr
          */
+        if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+            gen_io_start();
+        }
         gen_update_nip(ctx, ctx->base.pc_next);
         gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
         /* Must stop the translation as machine state (may have) changed */
         /* Note that mtmsr is not always defined as context-synchronizing */
         gen_stop_exception(ctx);
+        if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+            gen_io_end();
+        }
     }
 #endif /* !defined(CONFIG_USER_ONLY) */
 }
@@ -4286,6 +4292,9 @@ static void gen_mtmsr(DisasContext *ctx)
          *      if we enter power saving mode, we will exit the loop
          *      directly from ppc_store_msr
          */
+        if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+            gen_io_start();
+        }
         gen_update_nip(ctx, ctx->base.pc_next);
 #if defined(TARGET_PPC64)
         tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
@@ -4293,6 +4302,9 @@ static void gen_mtmsr(DisasContext *ctx)
         tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
 #endif
         gen_helper_store_msr(cpu_env, msr);
+        if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+            gen_io_end();
+        }
         tcg_temp_free(msr);
         /* Must stop the translation as machine state (may have) changed */
         /* Note that mtmsr is not always defined as context-synchronizing */
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Pavel Dovgalyuk

This patch fixes processing of mtmsr instructions in icount mode. In this mode writing to interrupt/peripheral state is controlled by can_do_io flag. This flag must be set explicitly before helper function invocation.

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

r~

#2 lore raw
Quoted 7 lines

From: Richard Henderson [mailto:[email protected]]

Quoted 5 lines · Pavel Dovgalyuk

This patch fixes processing of mtmsr instructions in icount mode. In this mode writing to interrupt/peripheral state is controlled by can_do_io flag. This flag must be set explicitly before helper function invocation.

Quoted 7 lines
Quoted 5 lines
---
 target/ppc/translate.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Richard, can you check the another similar patch?

https://patchew.org/QEMU/20181030122134.11055.15711.stgit@pasha-VirtualBox/

Pavel Dovgalyuk

Applied
#3 lore raw
In reply to Pavel Dovgalyuk
Quoted 7 lines · Pavel Dovgalyuk

This patch fixes processing of mtmsr instructions in icount mode. In this mode writing to interrupt/peripheral state is controlled by can_do_io flag. This flag must be set explicitly before helper function invocation.

Applied to ppc-for-3.1, thanks.

Quoted 47 lines
---
 target/ppc/translate.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
target/ppc/translate.c +12 -0
index 4e59dd5..987ce6e 100644
@@ -4257,11 +4257,17 @@ static void gen_mtmsrd(DisasContext *ctx)
          *      if we enter power saving mode, we will exit the loop
          *      directly from ppc_store_msr
          */
+        if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+            gen_io_start();
+        }
         gen_update_nip(ctx, ctx->base.pc_next);
         gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
         /* Must stop the translation as machine state (may have) changed */
         /* Note that mtmsr is not always defined as context-synchronizing */
         gen_stop_exception(ctx);
+        if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+            gen_io_end();
+        }
     }
 #endif /* !defined(CONFIG_USER_ONLY) */
 }
@@ -4286,6 +4292,9 @@ static void gen_mtmsr(DisasContext *ctx)
          *      if we enter power saving mode, we will exit the loop
          *      directly from ppc_store_msr
          */
+        if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+            gen_io_start();
+        }
         gen_update_nip(ctx, ctx->base.pc_next);
 #if defined(TARGET_PPC64)
         tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
@@ -4293,6 +4302,9 @@ static void gen_mtmsr(DisasContext *ctx)
         tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
 #endif
         gen_helper_store_msr(cpu_env, msr);
+        if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+            gen_io_end();
+        }
         tcg_temp_free(msr);
         /* Must stop the translation as machine state (may have) changed */
         /* Note that mtmsr is not always defined as context-synchronizing */
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#4 lore raw
Quoted 11 lines

From: David Gibson [mailto:[email protected]]

Quoted 7 lines · Pavel Dovgalyuk

This patch fixes processing of mtmsr instructions in icount mode. In this mode writing to interrupt/peripheral state is controlled by can_do_io flag. This flag must be set explicitly before helper function invocation.

Applied to ppc-for-3.1, thanks.

Thanks. What about this one
https://patchew.org/QEMU/20181030122134.11055.15711.stgit@pasha-VirtualBox/
There is a mess with the subject, but the code is ok :)

Pavel Dovgalyuk

#5 lore raw
Quoted 7 lines · Pavel Dovgalyuk
Quoted 7 lines

From: David Gibson [mailto:[email protected]]

Quoted 5 lines · Pavel Dovgalyuk

This patch fixes processing of mtmsr instructions in icount mode. In this mode writing to interrupt/peripheral state is controlled by can_do_io flag. This flag must be set explicitly before helper function invocation.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Applied to ppc-for-3.1, thanks.

Thanks. What about this one
https://patchew.org/QEMU/20181030122134.11055.15711.stgit@pasha-VirtualBox/
There is a mess with the subject, but the code is ok :)

I've been procrastinating on that because I don't understand icount well enough to review it easily, and no-one has replied with Reviewed-by or Tested-by.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#6 lore raw
Quoted 13 lines · David Gibson
Quoted 12 lines · Pavel Dovgalyuk
Quoted 11 lines

From: David Gibson [mailto:[email protected]]

Quoted 7 lines · Pavel Dovgalyuk

This patch fixes processing of mtmsr instructions in icount mode. In this mode writing to interrupt/peripheral state is controlled by can_do_io flag. This flag must be set explicitly before helper function invocation.

Applied to ppc-for-3.1, thanks.

Quoted 7 lines
Quoted 3 lines

Thanks. What about this one
https://patchew.org/QEMU/20181030122134.11055.15711.stgit@pasha-VirtualBox/
There is a mess with the subject, but the code is ok :)

I've been procrastinating on that because I don't understand icount well enough to review it easily, and no-one has replied with Reviewed-by or Tested-by.

I've just sent a Tested-by tag for this - with icount enabled, QEMU will assert if an instruction that alters interrupt state doesn't set can_do_io beforehand. With this patch on top of ppc-for-3.1 then I can boot my OpenBIOS test images without QEMU asserting in icount mode. Since it should have no effect without icount enabled, it should be safe.

It might also be worth changing the title of the patch to "target/ppc: fix rfid instruction for icount" so it matches its companion patch.

ATB,

Mark.