Skip to contentSkip to conversation

target/ppc/excp_helper: Take BQL before calling cpu_interrupt()

PATCH Applied Thomas Huth 4 participants 5 messages Jun 13, 2017 – Jun 15, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/ppc/excp_helper: Take BQL before calling cpu_interrupt()

Since the introduction of MTTCG, using the msgsnd instruction abort()s if being called without holding the BQL. So let's protect that part of the code now with qemu_mutex_lock_iothread().

---
 target/ppc/excp_helper.c | 3 +++
 1 file changed, 3 insertions(+)
target/ppc/excp_helper.c +3 -0
index 9cb2123..3a9f086 100644
@@ -17,6 +17,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
+#include "qemu/main-loop.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "exec/exec-all.h"
@@ -1132,6 +1133,7 @@ void helper_msgsnd(target_ulong rb)
         return;
     }
 
+    qemu_mutex_lock_iothread();
     CPU_FOREACH(cs) {
         PowerPCCPU *cpu = POWERPC_CPU(cs);
         CPUPPCState *cenv = &cpu->env;
@@ -1141,5 +1143,6 @@ void helper_msgsnd(target_ulong rb)
             cpu_interrupt(cs, CPU_INTERRUPT_HARD);
         }
     }
+    qemu_mutex_unlock_iothread();
 }
 #endif
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Thomas Huth

Since the introduction of MTTCG, using the msgsnd instruction abort()s if being called without holding the BQL. So let's protect that part of the code now with qemu_mutex_lock_iothread().

p.s. I was checking the ppc code for other CPU_FOREACH patterns and I noticed the tlb_flush calls could probably use the tlb_flush_all_cpus API instead of manually looping themselves. You should also double check the semantics to make sure none of them need to use the _synced variant and a cpu_exit if the flush needs to complete w.r.t the originating CPU.

Quoted 25 lines
---
 target/ppc/excp_helper.c | 3 +++
 1 file changed, 3 insertions(+)
target/ppc/excp_helper.c +2 -0
index 9cb2123..3a9f086 100644
@@ -17,6 +17,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
+#include "qemu/main-loop.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "exec/exec-all.h"
@@ -1132,6 +1133,7 @@ void helper_msgsnd(target_ulong rb)
         return;
     }
 
+    qemu_mutex_lock_iothread();
     CPU_FOREACH(cs) {
         PowerPCCPU *cpu = POWERPC_CPU(cs);
         CPUPPCState *cenv = &cpu->env;

target/ppc/excp_helper.c void helper_msgsnd(target_ulong rb) · line 1148

Quoted 6 lines
target/ppc/excp_helper.c +1 -0
@@ -1141,5 +1143,6 @@ void helper_msgsnd(target_ulong rb)
             cpu_interrupt(cs, CPU_INTERRUPT_HARD);
         }
     }
+    qemu_mutex_unlock_iothread();
 }
 #endif

--
Alex Bennée

Applied
#4 lore raw
In reply to Thomas Huth
Quoted 6 lines · Thomas Huth

Since the introduction of MTTCG, using the msgsnd instruction abort()s if being called without holding the BQL. So let's protect that part of the code now with qemu_mutex_lock_iothread().

Applied to ppc-for-2.10.

Quoted 31 lines
---
 target/ppc/excp_helper.c | 3 +++
 1 file changed, 3 insertions(+)
target/ppc/excp_helper.c +3 -0
index 9cb2123..3a9f086 100644
@@ -17,6 +17,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
+#include "qemu/main-loop.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "exec/exec-all.h"
@@ -1132,6 +1133,7 @@ void helper_msgsnd(target_ulong rb)
         return;
     }
 
+    qemu_mutex_lock_iothread();
     CPU_FOREACH(cs) {
         PowerPCCPU *cpu = POWERPC_CPU(cs);
         CPUPPCState *cenv = &cpu->env;
@@ -1141,5 +1143,6 @@ void helper_msgsnd(target_ulong rb)
             cpu_interrupt(cs, CPU_INTERRUPT_HARD);
         }
     }
+    qemu_mutex_unlock_iothread();
 }
 #endif
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
#2 lore raw
In reply to Alex Bennée
Quoted 6 lines · Alex Bennée
Quoted 4 lines · Thomas Huth

Since the introduction of MTTCG, using the msgsnd instruction abort()s if being called without holding the BQL. So let's protect that part of the code now with qemu_mutex_lock_iothread().

Quoted 8 lines
Quoted 2 lines

p.s. I was checking the ppc code for other CPU_FOREACH patterns and I noticed the tlb_flush calls could probably use the tlb_flush_all_cpus API instead of manually looping themselves.

Will that be synchronous call? In PPC, we do lazy tlb flush, the tlb flushes are batched until a synchronization point (for optimization). The batching is achieved using a tlb_need_flush (global/local) and when there is isync/ptesync or an exception, the actual flush is done. At this point we need to make sure that the flush is synchronous.

Quoted 3 lines

You should also double check the semantics to make sure none of them need to use the _synced variant and a cpu_exit if the flush needs to complete w.r.t the originating CPU.

Regards,
Nikunj

#3 lore raw
Quoted 11 lines · Nikunj A Dadhania
Quoted 9 lines · Alex Bennée
Quoted 6 lines · Thomas Huth

Since the introduction of MTTCG, using the msgsnd instruction abort()s if being called without holding the BQL. So let's protect that part of the code now with qemu_mutex_lock_iothread().

Quoted 8 lines
Quoted 5 lines

p.s. I was checking the ppc code for other CPU_FOREACH patterns and I noticed the tlb_flush calls could probably use the tlb_flush_all_cpus API instead of manually looping themselves.

Will that be synchronous call? In PPC, we do lazy tlb flush, the tlb flushes are batched until a synchronization point (for optimization).

No by default the non-synced flushes will occur at the end of the current executing block (cpu->exit_request is set and the work is done when we exit the run-loop).

Quoted 3 lines

The batching is achieved using a tlb_need_flush (global/local) and when there is isync/ptesync or an exception, the actual flush is done. At this point we need to make sure that the flush is synchronous.

If you want to ensure the flush is synchronous you need to call the _all_cpus_synced variants and do a cpu_loop_exit in your helper. This ensures that all the flushes queued up will be executed before execution starts at the next PC of the calling thread.

Quoted 7 lines
Quoted 4 lines

You should also double check the semantics to make sure none of them need to use the _synced variant and a cpu_exit if the flush needs to complete w.r.t the originating CPU.

Regards,
Nikunj

--
Alex Bennée