All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06
@ 2015-07-06 23:13 Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 01/22] cpu: No need to zero-initialize CPUState::numa_node Andreas Färber
                   ` (22 more replies)
  0 siblings, 23 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Peter Crosthwaite, Andreas Färber, Eduardo Habkost

Hello Peter,

This is my QOM CPU patch queue. Please pull.

Note: For time reasons I did not give this queue as much testing as usual,
in particular BSD and non-x86 KVM hosts were not covered.

Regards,
Andreas

Cc: Peter Maydell <peter.maydell@linaro.org>

Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

The following changes since commit 7edd8e4660beb301d527257f8e04ebec0f841cb0:

  Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2015-07-06 14:03:44 +0100)

are available in the git repository at:

  git://github.com/afaerber/qemu-cpu.git tags/qom-cpu-for-peter

for you to fetch changes up to 116382f1504d655a1afdf3eac18d276a200428b7:

  disas: cris: QOMify target specific disas setup (2015-07-06 22:36:17 +0200)

----------------------------------------------------------------
QOM CPUState and X86CPU

* Further QOM'ification of CPU initialization
* Propagation of CPUState arguments and elimination of ENV_GET_CPU() usage
* cpu_set_pc() abstraction
* CPUClass::disas_set_info() hook

----------------------------------------------------------------
Bharata B Rao (3):
      cpu: Add Error argument to cpu_exec_init()
      cpu: Convert cpu_index into a bitmap
      target-ppc: Move cpu_exec_init() call to realize function

Eduardo Habkost (3):
      cpu: No need to zero-initialize CPUState::numa_node
      cpu: Initialize breakpoint/watchpoint lists in cpu_common_initfn()
      cpu: Reorder cpu->as, cpu->thread_id, cpu->memory_dispatch init

Peter Crosthwaite (16):
      translate-all: Change tb_flush() env argument to cpu
      gdbstub: Change gdbserver_fork() to accept cpu instead of env
      cpu: Change tcg_cpu_exec() arg to cpu, not env
      cpu: Change cpu_exec_init() arg to cpu, not env
      cpu-exec: Purge all uses of ENV_GET_CPU()
      cpu: Add wrapper for the set_pc() hook
      gdbstub: Use cpu_set_pc() helper
      hw/arm/boot: Use cpu_set_pc()
      microblaze: boot: Use cpu_set_pc()
      disas: Add print_insn to disassemble info
      disas: QOMify target specific setup
      disas: arm-a64: Make printfer and stream variable
      disas: arm: QOMify target specific disas setup
      disas: microblaze: QOMify target specific disas setup
      disas: cris: Fix 0 buffer length case
      disas: cris: QOMify target specific disas setup

 bsd-user/main.c             |   6 ++-
 cpu-exec.c                  |  28 +++++------
 cpus.c                      |   8 ++-
 disas.c                     | 119 ++++++++++++++++----------------------------
 disas/arm-a64.cc            |  22 ++++++--
 disas/cris.c                |   6 +--
 exec.c                      |  71 ++++++++++++++++++++------
 gdbstub.c                   |  14 ++----
 hw/arm/boot.c               |  24 ++++-----
 hw/microblaze/boot.c        |   5 +-
 include/disas/bfd.h         |   6 +++
 include/exec/exec-all.h     |   4 +-
 include/exec/gdbstub.h      |   2 +-
 include/qom/cpu.h           |  19 +++++++
 linux-user/main.c           |  30 +++++------
 linux-user/signal.c         |   2 +-
 qom/cpu.c                   |   9 ++++
 target-alpha/cpu.c          |   2 +-
 target-alpha/cpu.h          |   2 +-
 target-alpha/sys_helper.c   |   2 +-
 target-arm/cpu.c            |  37 +++++++++++++-
 target-arm/cpu.h            |   2 +-
 target-cris/cpu.c           |  18 ++++++-
 target-cris/cpu.h           |   2 +-
 target-i386/cpu.c           |   2 +-
 target-i386/cpu.h           |   2 +-
 target-i386/translate.c     |   2 +-
 target-lm32/cpu.c           |   2 +-
 target-lm32/cpu.h           |   2 +-
 target-m68k/cpu.c           |   2 +-
 target-m68k/cpu.h           |   2 +-
 target-microblaze/cpu.c     |  10 +++-
 target-microblaze/cpu.h     |   2 +-
 target-mips/cpu.c           |   2 +-
 target-mips/cpu.h           |   2 +-
 target-moxie/cpu.c          |   2 +-
 target-moxie/cpu.h          |   2 +-
 target-openrisc/cpu.c       |   2 +-
 target-openrisc/cpu.h       |   2 +-
 target-ppc/cpu.h            |   2 +-
 target-ppc/translate_init.c |   9 +++-
 target-s390x/cpu.c          |   2 +-
 target-s390x/cpu.h          |   2 +-
 target-sh4/cpu.c            |   2 +-
 target-sh4/cpu.h            |   2 +-
 target-sparc/cpu.c          |   2 +-
 target-sparc/cpu.h          |   2 +-
 target-tricore/cpu.c        |   2 +-
 target-tricore/cpu.h        |   2 +-
 target-unicore32/cpu.c      |   2 +-
 target-unicore32/cpu.h      |   3 +-
 target-xtensa/cpu.c         |   2 +-
 target-xtensa/cpu.h         |   2 +-
 translate-all.c             |   6 +--
 54 files changed, 315 insertions(+), 205 deletions(-)

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

* [Qemu-devel] [PULL 01/22] cpu: No need to zero-initialize CPUState::numa_node
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 02/22] cpu: Initialize breakpoint/watchpoint lists in cpu_common_initfn() Andreas Färber
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Eduardo Habkost, Andreas Färber

From: Eduardo Habkost <ehabkost@redhat.com>

QOM objects are already zero-filled when instantiated, there's no need
to explicitly set numa_node to 0.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 exec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/exec.c b/exec.c
index 251dc79..e63f748 100644
--- a/exec.c
+++ b/exec.c
@@ -541,7 +541,6 @@ void cpu_exec_init(CPUArchState *env)
         cpu_index++;
     }
     cpu->cpu_index = cpu_index;
-    cpu->numa_node = 0;
     QTAILQ_INIT(&cpu->breakpoints);
     QTAILQ_INIT(&cpu->watchpoints);
 #ifndef CONFIG_USER_ONLY
-- 
2.1.4

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

* [Qemu-devel] [PULL 02/22] cpu: Initialize breakpoint/watchpoint lists in cpu_common_initfn()
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 01/22] cpu: No need to zero-initialize CPUState::numa_node Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 03/22] cpu: Reorder cpu->as, cpu->thread_id, cpu->memory_dispatch init Andreas Färber
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Eduardo Habkost, Andreas Färber

From: Eduardo Habkost <ehabkost@redhat.com>

One small step in the simplification of cpu_exec_init().

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 exec.c    | 2 --
 qom/cpu.c | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/exec.c b/exec.c
index e63f748..b5ff469 100644
--- a/exec.c
+++ b/exec.c
@@ -541,8 +541,6 @@ void cpu_exec_init(CPUArchState *env)
         cpu_index++;
     }
     cpu->cpu_index = cpu_index;
-    QTAILQ_INIT(&cpu->breakpoints);
-    QTAILQ_INIT(&cpu->watchpoints);
 #ifndef CONFIG_USER_ONLY
     cpu->as = &address_space_memory;
     cpu->thread_id = qemu_get_thread_id();
diff --git a/qom/cpu.c b/qom/cpu.c
index 108bfa2..56c53a8 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -313,6 +313,8 @@ static void cpu_common_initfn(Object *obj)
     CPUClass *cc = CPU_GET_CLASS(obj);
 
     cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
+    QTAILQ_INIT(&cpu->breakpoints);
+    QTAILQ_INIT(&cpu->watchpoints);
 }
 
 static int64_t cpu_common_get_arch_id(CPUState *cpu)
-- 
2.1.4

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

* [Qemu-devel] [PULL 03/22] cpu: Reorder cpu->as, cpu->thread_id, cpu->memory_dispatch init
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 01/22] cpu: No need to zero-initialize CPUState::numa_node Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 02/22] cpu: Initialize breakpoint/watchpoint lists in cpu_common_initfn() Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 04/22] cpu: Add Error argument to cpu_exec_init() Andreas Färber
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Eduardo Habkost, Andreas Färber

From: Eduardo Habkost <ehabkost@redhat.com>

Instead of initializing cpu->as, cpu->thread_id, and reloading memory
map while holding cpu_list_lock(), do it earlier, before locking the CPU
list and initializing cpu_index.

This allows the code handling cpu_index and global CPU list to be
isolated from the rest.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 exec.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/exec.c b/exec.c
index b5ff469..06f6cb4 100644
--- a/exec.c
+++ b/exec.c
@@ -533,6 +533,12 @@ void cpu_exec_init(CPUArchState *env)
     CPUState *some_cpu;
     int cpu_index;
 
+#ifndef CONFIG_USER_ONLY
+    cpu->as = &address_space_memory;
+    cpu->thread_id = qemu_get_thread_id();
+    cpu_reload_memory_map(cpu);
+#endif
+
 #if defined(CONFIG_USER_ONLY)
     cpu_list_lock();
 #endif
@@ -541,11 +547,6 @@ void cpu_exec_init(CPUArchState *env)
         cpu_index++;
     }
     cpu->cpu_index = cpu_index;
-#ifndef CONFIG_USER_ONLY
-    cpu->as = &address_space_memory;
-    cpu->thread_id = qemu_get_thread_id();
-    cpu_reload_memory_map(cpu);
-#endif
     QTAILQ_INSERT_TAIL(&cpus, cpu, node);
 #if defined(CONFIG_USER_ONLY)
     cpu_list_unlock();
-- 
2.1.4

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

* [Qemu-devel] [PULL 04/22] cpu: Add Error argument to cpu_exec_init()
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (2 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 03/22] cpu: Reorder cpu->as, cpu->thread_id, cpu->memory_dispatch init Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 05/22] cpu: Convert cpu_index into a bitmap Andreas Färber
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Guan Xuetao, Eduardo Habkost, Peter Crosthwaite,
	Jia Liu, Anthony Green, Edgar E. Iglesias, Alexander Graf,
	Blue Swirl, Max Filippov, Michael Walle, open list:PowerPC,
	Bharata B Rao, Paolo Bonzini, Mark Cave-Ayland,
	Bastian Koppelmann, Leon Alrae, Andreas Färber,
	Aurelien Jarno, Richard Henderson

From: Bharata B Rao <bharata@linux.vnet.ibm.com>

Add an Error argument to cpu_exec_init() to let users collect the
error. This is in preparation to change the CPU enumeration logic
in cpu_exec_init(). With the new enumeration logic, cpu_exec_init()
can fail if cpu_index values corresponding to max_cpus have already
been handed out.

Since all current callers of cpu_exec_init() are from instance_init,
use error_abort Error argument to abort in case of an error.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 exec.c                      | 2 +-
 include/exec/exec-all.h     | 2 +-
 target-alpha/cpu.c          | 2 +-
 target-arm/cpu.c            | 2 +-
 target-cris/cpu.c           | 2 +-
 target-i386/cpu.c           | 2 +-
 target-lm32/cpu.c           | 2 +-
 target-m68k/cpu.c           | 2 +-
 target-microblaze/cpu.c     | 2 +-
 target-mips/cpu.c           | 2 +-
 target-moxie/cpu.c          | 2 +-
 target-openrisc/cpu.c       | 2 +-
 target-ppc/translate_init.c | 2 +-
 target-s390x/cpu.c          | 2 +-
 target-sh4/cpu.c            | 2 +-
 target-sparc/cpu.c          | 2 +-
 target-tricore/cpu.c        | 2 +-
 target-unicore32/cpu.c      | 2 +-
 target-xtensa/cpu.c         | 2 +-
 19 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/exec.c b/exec.c
index 06f6cb4..8abac69 100644
--- a/exec.c
+++ b/exec.c
@@ -526,7 +526,7 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
 }
 #endif
 
-void cpu_exec_init(CPUArchState *env)
+void cpu_exec_init(CPUArchState *env, Error **errp)
 {
     CPUState *cpu = ENV_GET_CPU(env);
     CPUClass *cc = CPU_GET_CLASS(cpu);
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index d678114..01d9996 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -88,7 +88,7 @@ void QEMU_NORETURN cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
 TranslationBlock *tb_gen_code(CPUState *cpu,
                               target_ulong pc, target_ulong cs_base, int flags,
                               int cflags);
-void cpu_exec_init(CPUArchState *env);
+void cpu_exec_init(CPUArchState *env, Error **errp);
 void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);
 
 #if !defined(CONFIG_USER_ONLY)
diff --git a/target-alpha/cpu.c b/target-alpha/cpu.c
index a98b7d8..e865ba7 100644
--- a/target-alpha/cpu.c
+++ b/target-alpha/cpu.c
@@ -257,7 +257,7 @@ static void alpha_cpu_initfn(Object *obj)
     CPUAlphaState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
     tlb_flush(cs, 1);
 
     alpha_translate_init();
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 80669a6..1c40cc0 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -392,7 +392,7 @@ static void arm_cpu_initfn(Object *obj)
     uint32_t Aff1, Aff0;
 
     cs->env_ptr = &cpu->env;
-    cpu_exec_init(&cpu->env);
+    cpu_exec_init(&cpu->env, &error_abort);
     cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
                                          g_free, g_free);
 
diff --git a/target-cris/cpu.c b/target-cris/cpu.c
index 16cfba9..bb8e7ea 100644
--- a/target-cris/cpu.c
+++ b/target-cris/cpu.c
@@ -170,7 +170,7 @@ static void cris_cpu_initfn(Object *obj)
     static bool tcg_initialized;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     env->pregs[PR_VR] = ccc->vr;
 
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 36b07f9..433f38b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3007,7 +3007,7 @@ static void x86_cpu_initfn(Object *obj)
     static int inited;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     object_property_add(obj, "family", "int",
                         x86_cpuid_version_get_family,
diff --git a/target-lm32/cpu.c b/target-lm32/cpu.c
index f8081f5..da4fde1 100644
--- a/target-lm32/cpu.c
+++ b/target-lm32/cpu.c
@@ -151,7 +151,7 @@ static void lm32_cpu_initfn(Object *obj)
     static bool tcg_initialized;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     env->flags = 0;
 
diff --git a/target-m68k/cpu.c b/target-m68k/cpu.c
index 4cfb725..ae3d765 100644
--- a/target-m68k/cpu.c
+++ b/target-m68k/cpu.c
@@ -168,7 +168,7 @@ static void m68k_cpu_initfn(Object *obj)
     static bool inited;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     if (tcg_enabled() && !inited) {
         inited = true;
diff --git a/target-microblaze/cpu.c b/target-microblaze/cpu.c
index c592bf7..967ea01 100644
--- a/target-microblaze/cpu.c
+++ b/target-microblaze/cpu.c
@@ -190,7 +190,7 @@ static void mb_cpu_initfn(Object *obj)
     static bool tcg_initialized;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
 
diff --git a/target-mips/cpu.c b/target-mips/cpu.c
index 958c999..1fd9f22 100644
--- a/target-mips/cpu.c
+++ b/target-mips/cpu.c
@@ -115,7 +115,7 @@ static void mips_cpu_initfn(Object *obj)
     CPUMIPSState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     if (tcg_enabled()) {
         mips_tcg_init();
diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c
index 47b617f..415c65a 100644
--- a/target-moxie/cpu.c
+++ b/target-moxie/cpu.c
@@ -66,7 +66,7 @@ static void moxie_cpu_initfn(Object *obj)
     static int inited;
 
     cs->env_ptr = &cpu->env;
-    cpu_exec_init(&cpu->env);
+    cpu_exec_init(&cpu->env, &error_abort);
 
     if (tcg_enabled() && !inited) {
         inited = 1;
diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index 39bedc1..cd6c657 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -92,7 +92,7 @@ static void openrisc_cpu_initfn(Object *obj)
     static int inited;
 
     cs->env_ptr = &cpu->env;
-    cpu_exec_init(&cpu->env);
+    cpu_exec_init(&cpu->env, &error_abort);
 
 #ifndef CONFIG_USER_ONLY
     cpu_openrisc_mmu_init(cpu);
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index d74f4f0..52d95ce 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -9633,7 +9633,7 @@ static void ppc_cpu_initfn(Object *obj)
     CPUPPCState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
     cpu->cpu_dt_id = cs->cpu_index;
 
     env->msr_mask = pcc->msr_mask;
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 69bac35..ced5592 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -212,7 +212,7 @@ static void s390_cpu_initfn(Object *obj)
 #endif
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 #if !defined(CONFIG_USER_ONLY)
     qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
     qemu_get_timedate(&tm, 0);
diff --git a/target-sh4/cpu.c b/target-sh4/cpu.c
index cccb14f..2c2060b 100644
--- a/target-sh4/cpu.c
+++ b/target-sh4/cpu.c
@@ -248,7 +248,7 @@ static void superh_cpu_initfn(Object *obj)
     CPUSH4State *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     env->movcal_backup_tail = &(env->movcal_backup);
 
diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c
index a952097..4d1da7c 100644
--- a/target-sparc/cpu.c
+++ b/target-sparc/cpu.c
@@ -802,7 +802,7 @@ static void sparc_cpu_initfn(Object *obj)
     CPUSPARCState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     if (tcg_enabled()) {
         gen_intermediate_code_init(env);
diff --git a/target-tricore/cpu.c b/target-tricore/cpu.c
index b3e5512..6fa60b1 100644
--- a/target-tricore/cpu.c
+++ b/target-tricore/cpu.c
@@ -92,7 +92,7 @@ static void tricore_cpu_initfn(Object *obj)
     CPUTriCoreState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     if (tcg_enabled()) {
         tricore_tcg_init();
diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c
index 5b32987..eda039c 100644
--- a/target-unicore32/cpu.c
+++ b/target-unicore32/cpu.c
@@ -111,7 +111,7 @@ static void uc32_cpu_initfn(Object *obj)
     static bool inited;
 
     cs->env_ptr = env;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
 #ifdef CONFIG_USER_ONLY
     env->uncached_asr = ASR_MODE_USER;
diff --git a/target-xtensa/cpu.c b/target-xtensa/cpu.c
index 2b75678..8d69d23 100644
--- a/target-xtensa/cpu.c
+++ b/target-xtensa/cpu.c
@@ -114,7 +114,7 @@ static void xtensa_cpu_initfn(Object *obj)
 
     cs->env_ptr = env;
     env->config = xcc->config;
-    cpu_exec_init(env);
+    cpu_exec_init(env, &error_abort);
 
     if (tcg_enabled() && !tcg_inited) {
         tcg_inited = true;
-- 
2.1.4

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

* [Qemu-devel] [PULL 05/22] cpu: Convert cpu_index into a bitmap
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (3 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 04/22] cpu: Add Error argument to cpu_exec_init() Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 06/22] target-ppc: Move cpu_exec_init() call to realize function Andreas Färber
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Peter Crosthwaite, Andreas Färber, Bharata B Rao

From: Bharata B Rao <bharata@linux.vnet.ibm.com>

Currently CPUState::cpu_index is monotonically increasing and a newly
created CPU always gets the next higher index. The next available
index is calculated by counting the existing number of CPUs. This is
fine as long as we only add CPUs, but there are architectures which
are starting to support CPU removal, too. For an architecture like PowerPC
which derives its CPU identifier (device tree ID) from cpu_index, the
existing logic of generating cpu_index values causes problems.

With the currently proposed method of handling vCPU removal by parking
the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generating cpu_index this way will not work for PowerPC.

This patch changes the way cpu_index is handed out by maintaining
a bit map of the CPUs that tracks both addition and removal of CPUs.

The CPU bitmap allocation logic is part of cpu_exec_init(), which is
called by instance_init routines of various CPU targets. Newly added
cpu_exec_exit() API handles the deallocation part and this routine is
called from generic CPU instance_finalize.

Note: This new CPU enumeration is for !CONFIG_USER_ONLY only.
CONFIG_USER_ONLY continues to have the old enumeration logic.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 exec.c            | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 include/qom/cpu.h |  1 +
 qom/cpu.c         |  7 +++++++
 3 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/exec.c b/exec.c
index 8abac69..a64c3ae 100644
--- a/exec.c
+++ b/exec.c
@@ -526,12 +526,57 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
 }
 #endif
 
+#ifndef CONFIG_USER_ONLY
+static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);
+
+static int cpu_get_free_index(Error **errp)
+{
+    int cpu = find_first_zero_bit(cpu_index_map, max_cpus);
+
+    if (cpu >= max_cpus) {
+        error_setg(errp, "Trying to use more CPUs than allowed max of %d",
+                   max_cpus);
+        return -1;
+    }
+
+    bitmap_set(cpu_index_map, cpu, 1);
+    return cpu;
+}
+
+void cpu_exec_exit(CPUState *cpu)
+{
+    if (cpu->cpu_index == -1) {
+        /* cpu_index was never allocated by this @cpu or was already freed. */
+        return;
+    }
+
+    bitmap_clear(cpu_index_map, cpu->cpu_index, 1);
+    cpu->cpu_index = -1;
+}
+#else
+
+static int cpu_get_free_index(Error **errp)
+{
+    CPUState *some_cpu;
+    int cpu_index = 0;
+
+    CPU_FOREACH(some_cpu) {
+        cpu_index++;
+    }
+    return cpu_index;
+}
+
+void cpu_exec_exit(CPUState *cpu)
+{
+}
+#endif
+
 void cpu_exec_init(CPUArchState *env, Error **errp)
 {
     CPUState *cpu = ENV_GET_CPU(env);
     CPUClass *cc = CPU_GET_CLASS(cpu);
-    CPUState *some_cpu;
     int cpu_index;
+    Error *local_err = NULL;
 
 #ifndef CONFIG_USER_ONLY
     cpu->as = &address_space_memory;
@@ -542,11 +587,11 @@ void cpu_exec_init(CPUArchState *env, Error **errp)
 #if defined(CONFIG_USER_ONLY)
     cpu_list_lock();
 #endif
-    cpu_index = 0;
-    CPU_FOREACH(some_cpu) {
-        cpu_index++;
+    cpu_index = cpu->cpu_index = cpu_get_free_index(&local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
     }
-    cpu->cpu_index = cpu_index;
     QTAILQ_INSERT_TAIL(&cpus, cpu, node);
 #if defined(CONFIG_USER_ONLY)
     cpu_list_unlock();
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 39f0f19..7db310e 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -672,6 +672,7 @@ void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
 
 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
+void cpu_exec_exit(CPUState *cpu);
 
 #ifdef CONFIG_SOFTMMU
 extern const struct VMStateDescription vmstate_cpu_common;
diff --git a/qom/cpu.c b/qom/cpu.c
index 56c53a8..eb9cfec 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -312,11 +312,17 @@ static void cpu_common_initfn(Object *obj)
     CPUState *cpu = CPU(obj);
     CPUClass *cc = CPU_GET_CLASS(obj);
 
+    cpu->cpu_index = -1;
     cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
     QTAILQ_INIT(&cpu->breakpoints);
     QTAILQ_INIT(&cpu->watchpoints);
 }
 
+static void cpu_common_finalize(Object *obj)
+{
+    cpu_exec_exit(CPU(obj));
+}
+
 static int64_t cpu_common_get_arch_id(CPUState *cpu)
 {
     return cpu->cpu_index;
@@ -358,6 +364,7 @@ static const TypeInfo cpu_type_info = {
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(CPUState),
     .instance_init = cpu_common_initfn,
+    .instance_finalize = cpu_common_finalize,
     .abstract = true,
     .class_size = sizeof(CPUClass),
     .class_init = cpu_class_init,
-- 
2.1.4

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

* [Qemu-devel] [PULL 06/22] target-ppc: Move cpu_exec_init() call to realize function
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (4 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 05/22] cpu: Convert cpu_index into a bitmap Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 07/22] translate-all: Change tb_flush() env argument to cpu Andreas Färber
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Peter Crosthwaite, open list:PowerPC,
	Andreas Färber, Bharata B Rao

From: Bharata B Rao <bharata@linux.vnet.ibm.com>

Move cpu_exec_init() call from instance_init to realize. This allows
any failures from cpu_exec_init() to be handled appropriately.
Also add corresponding cpu_exec_exit() call from unrealize.

cpu_dt_id assignment from instance_init is no longer needed since
correct assignment for cpu_dt_id is already present in realizefn.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-ppc/translate_init.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 52d95ce..2b72f2d 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -8928,6 +8928,11 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
+    cpu_exec_init(&cpu->env, &local_err);
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        return;
+    }
     cpu->cpu_dt_id = (cs->cpu_index / smp_threads) * max_smt
         + (cs->cpu_index % smp_threads);
 #endif
@@ -9141,6 +9146,8 @@ static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp)
     opc_handler_t **table;
     int i, j;
 
+    cpu_exec_exit(CPU(dev));
+
     for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) {
         if (env->opcodes[i] == &invalid_handler) {
             continue;
@@ -9633,8 +9640,6 @@ static void ppc_cpu_initfn(Object *obj)
     CPUPPCState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
-    cpu->cpu_dt_id = cs->cpu_index;
 
     env->msr_mask = pcc->msr_mask;
     env->mmu_model = pcc->mmu_model;
-- 
2.1.4

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

* [Qemu-devel] [PULL 07/22] translate-all: Change tb_flush() env argument to cpu
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (5 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 06/22] target-ppc: Move cpu_exec_init() call to realize function Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 08/22] gdbstub: Change gdbserver_fork() to accept cpu instead of env Andreas Färber
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Peter Crosthwaite, Riku Voipio,
	Peter Crosthwaite, Paolo Bonzini, Andreas Färber,
	Richard Henderson

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

All of the core-code usages of this API have the cpu pointer handy so
pass it in. There are only 3 architecture specific usages (2 of which
are commented out) which can just use ENV_GET_CPU() locally to get the
cpu pointer. The reduces core code usage of the CPU env, which brings
us closer to common-obj'ing these core files.

Cc: Riku Voipio <riku.voipio@iki.fi>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 exec.c                    | 3 +--
 gdbstub.c                 | 6 ++----
 include/exec/exec-all.h   | 2 +-
 linux-user/signal.c       | 2 +-
 target-alpha/sys_helper.c | 2 +-
 target-i386/translate.c   | 2 +-
 translate-all.c           | 6 ++----
 7 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/exec.c b/exec.c
index a64c3ae..a33d9b2 100644
--- a/exec.c
+++ b/exec.c
@@ -813,8 +813,7 @@ void cpu_single_step(CPUState *cpu, int enabled)
         } else {
             /* must flush all the translated code to avoid inconsistencies */
             /* XXX: only flush what is necessary */
-            CPUArchState *env = cpu->env_ptr;
-            tb_flush(env);
+            tb_flush(cpu);
         }
     }
 }
diff --git a/gdbstub.c b/gdbstub.c
index cea2a84..0fa8dd8 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1226,7 +1226,6 @@ void gdb_set_stop_cpu(CPUState *cpu)
 static void gdb_vm_state_change(void *opaque, int running, RunState state)
 {
     GDBState *s = gdbserver_state;
-    CPUArchState *env = s->c_cpu->env_ptr;
     CPUState *cpu = s->c_cpu;
     char buf[256];
     const char *type;
@@ -1261,7 +1260,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)
             cpu->watchpoint_hit = NULL;
             goto send_packet;
         }
-        tb_flush(env);
+        tb_flush(cpu);
         ret = GDB_SIGNAL_TRAP;
         break;
     case RUN_STATE_PAUSED:
@@ -1490,7 +1489,6 @@ gdb_queuesig (void)
 int
 gdb_handlesig(CPUState *cpu, int sig)
 {
-    CPUArchState *env = cpu->env_ptr;
     GDBState *s;
     char buf[256];
     int n;
@@ -1502,7 +1500,7 @@ gdb_handlesig(CPUState *cpu, int sig)
 
     /* disable single step if it was enabled */
     cpu_single_step(cpu, 0);
-    tb_flush(env);
+    tb_flush(cpu);
 
     if (sig != 0) {
         snprintf(buf, sizeof(buf), "S%02x", target_signal_to_gdb(sig));
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 01d9996..5a73bcb 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -196,7 +196,7 @@ struct TBContext {
 };
 
 void tb_free(TranslationBlock *tb);
-void tb_flush(CPUArchState *env);
+void tb_flush(CPUState *cpu);
 void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr);
 
 #if defined(USE_DIRECT_JUMP)
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 1166f2f..9d4cef4 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -2348,7 +2348,7 @@ static void setup_frame(int sig, struct target_sigaction *ka,
 
 		/* Flush instruction space. */
 		//flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
-                //		tb_flush(env);
+                //		tb_flush(CPU(sparc_env_get_cpu(env)));
 	}
         unlock_user(sf, sf_addr, sizeof(struct target_signal_frame));
 	return;
diff --git a/target-alpha/sys_helper.c b/target-alpha/sys_helper.c
index ae2e174..1c59e10 100644
--- a/target-alpha/sys_helper.c
+++ b/target-alpha/sys_helper.c
@@ -74,7 +74,7 @@ void helper_tbis(CPUAlphaState *env, uint64_t p)
 
 void helper_tb_flush(CPUAlphaState *env)
 {
-    tb_flush(env);
+    tb_flush(CPU(alpha_env_get_cpu(env)));
 }
 
 void helper_halt(uint64_t restart)
diff --git a/target-i386/translate.c b/target-i386/translate.c
index 7a1bdee..82e2245 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -6925,7 +6925,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
         gen_debug(s, pc_start - s->cs_base);
 #else
         /* start debug */
-        tb_flush(env);
+        tb_flush(CPU(x86_env_get_cpu(env)));
         qemu_set_log(CPU_LOG_INT | CPU_LOG_TB_IN_ASM);
 #endif
         break;
diff --git a/translate-all.c b/translate-all.c
index 412bc90..b27c056 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -770,10 +770,8 @@ static void page_flush_tb(void)
 
 /* flush all the translation blocks */
 /* XXX: tb_flush is currently not thread safe */
-void tb_flush(CPUArchState *env1)
+void tb_flush(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env1);
-
 #if defined(DEBUG_FLUSH)
     printf("qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%ld\n",
            (unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer),
@@ -1012,7 +1010,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
     tb = tb_alloc(pc);
     if (!tb) {
         /* flush must be done */
-        tb_flush(env);
+        tb_flush(cpu);
         /* cannot fail at this point */
         tb = tb_alloc(pc);
         /* Don't forget to invalidate previous TB info.  */
-- 
2.1.4

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

* [Qemu-devel] [PULL 08/22] gdbstub: Change gdbserver_fork() to accept cpu instead of env
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (6 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 07/22] translate-all: Change tb_flush() env argument to cpu Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 09/22] cpu: Change tcg_cpu_exec() arg to cpu, not env Andreas Färber
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Blue Swirl, Peter Crosthwaite, Riku Voipio, Andreas Färber,
	Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

All callsites to this function navigate the cpu->env_ptr only for the
function to take the env ptr back to the original cpu ptr. Change the
function to just pass in the CPU pointer instead. Removes a core code
usage of ENV_GET_CPU() (in gdbstub.c).

Cc: Riku Voipio <riku.voipio@iki.fi>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 bsd-user/main.c        | 2 +-
 gdbstub.c              | 3 +--
 include/exec/gdbstub.h | 2 +-
 linux-user/main.c      | 2 +-
 4 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index ba0b998..45a1436 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -92,7 +92,7 @@ void fork_start(void)
 void fork_end(int child)
 {
     if (child) {
-        gdbserver_fork((CPUArchState *)thread_cpu->env_ptr);
+        gdbserver_fork(thread_cpu);
     }
 }
 
diff --git a/gdbstub.c b/gdbstub.c
index 0fa8dd8..aa5ba51 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1629,9 +1629,8 @@ int gdbserver_start(int port)
 }
 
 /* Disable gdb stub for child processes.  */
-void gdbserver_fork(CPUArchState *env)
+void gdbserver_fork(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
     GDBState *s = gdbserver_state;
 
     if (gdbserver_fd < 0 || s->fd < 0) {
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index a608a26..05f57c2 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -22,7 +22,7 @@ void gdb_exit(CPUArchState *, int);
 int gdb_queuesig (void);
 int gdb_handlesig(CPUState *, int);
 void gdb_signalled(CPUArchState *, int);
-void gdbserver_fork(CPUArchState *);
+void gdbserver_fork(CPUState *);
 #endif
 /* Get or set a register.  Returns the size of the register.  */
 typedef int (*gdb_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);
diff --git a/linux-user/main.c b/linux-user/main.c
index c855bcc..12b18d0 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -130,7 +130,7 @@ void fork_end(int child)
         pthread_cond_init(&exclusive_cond, NULL);
         pthread_cond_init(&exclusive_resume, NULL);
         pthread_mutex_init(&tcg_ctx.tb_ctx.tb_lock, NULL);
-        gdbserver_fork((CPUArchState *)thread_cpu->env_ptr);
+        gdbserver_fork(thread_cpu);
     } else {
         pthread_mutex_unlock(&exclusive_lock);
         pthread_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock);
-- 
2.1.4

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

* [Qemu-devel] [PULL 09/22] cpu: Change tcg_cpu_exec() arg to cpu, not env
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (7 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 08/22] gdbstub: Change gdbserver_fork() to accept cpu instead of env Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 10/22] cpu: Change cpu_exec_init() " Andreas Färber
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

The sole caller of this function navigates the cpu->env_ptr only for
this function to take it back the cpu pointer straight away. Pass in
cpu pointer instead and grab the env pointer locally in the function.
Removes a core code usage of ENV_GET_CPU().

Reviewed-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 cpus.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/cpus.c b/cpus.c
index f547aeb..24cac2e 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1357,9 +1357,9 @@ int vm_stop_force_state(RunState state)
     }
 }
 
-static int tcg_cpu_exec(CPUArchState *env)
+static int tcg_cpu_exec(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
+    CPUArchState *env = cpu->env_ptr;
     int ret;
 #ifdef CONFIG_PROFILER
     int64_t ti;
@@ -1421,13 +1421,12 @@ static void tcg_exec_all(void)
     }
     for (; next_cpu != NULL && !exit_request; next_cpu = CPU_NEXT(next_cpu)) {
         CPUState *cpu = next_cpu;
-        CPUArchState *env = cpu->env_ptr;
 
         qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
                           (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
 
         if (cpu_can_run(cpu)) {
-            r = tcg_cpu_exec(env);
+            r = tcg_cpu_exec(cpu);
             if (r == EXCP_DEBUG) {
                 cpu_handle_guest_debug(cpu);
                 break;
-- 
2.1.4

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

* [Qemu-devel] [PULL 10/22] cpu: Change cpu_exec_init() arg to cpu, not env
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (8 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 09/22] cpu: Change tcg_cpu_exec() arg to cpu, not env Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 11/22] cpu-exec: Purge all uses of ENV_GET_CPU() Andreas Färber
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Guan Xuetao, Eduardo Habkost, Peter Crosthwaite,
	Jia Liu, Anthony Green, Mark Cave-Ayland, Michael Walle,
	Alexander Graf, Blue Swirl, Max Filippov, Peter Crosthwaite,
	open list:PowerPC, Edgar E. Iglesias, Paolo Bonzini,
	Bastian Koppelmann, Leon Alrae, Andreas Färber,
	Aurelien Jarno, Richard Henderson

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

The callers (most of them in target-foo/cpu.c) to this function all
have the cpu pointer handy. Just pass it to avoid an ENV_GET_CPU() from
core code (in exec.c).

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: Michael Walle <michael@walle.cc>
Cc: Leon Alrae <leon.alrae@imgtec.com>
Cc: Anthony Green <green@moxielogic.com>
Cc: Jia Liu <proljc@gmail.com>
Cc: Alexander Graf <agraf@suse.de>
Cc: Blue Swirl <blauwirbel@gmail.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 exec.c                      | 5 ++---
 include/exec/exec-all.h     | 2 +-
 target-alpha/cpu.c          | 2 +-
 target-arm/cpu.c            | 2 +-
 target-cris/cpu.c           | 2 +-
 target-i386/cpu.c           | 2 +-
 target-lm32/cpu.c           | 2 +-
 target-m68k/cpu.c           | 2 +-
 target-microblaze/cpu.c     | 2 +-
 target-mips/cpu.c           | 2 +-
 target-moxie/cpu.c          | 2 +-
 target-openrisc/cpu.c       | 2 +-
 target-ppc/translate_init.c | 2 +-
 target-s390x/cpu.c          | 2 +-
 target-sh4/cpu.c            | 2 +-
 target-sparc/cpu.c          | 2 +-
 target-tricore/cpu.c        | 2 +-
 target-unicore32/cpu.c      | 2 +-
 target-xtensa/cpu.c         | 2 +-
 19 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/exec.c b/exec.c
index a33d9b2..7cc9f50 100644
--- a/exec.c
+++ b/exec.c
@@ -571,9 +571,8 @@ void cpu_exec_exit(CPUState *cpu)
 }
 #endif
 
-void cpu_exec_init(CPUArchState *env, Error **errp)
+void cpu_exec_init(CPUState *cpu, Error **errp)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
     CPUClass *cc = CPU_GET_CLASS(cpu);
     int cpu_index;
     Error *local_err = NULL;
@@ -601,7 +600,7 @@ void cpu_exec_init(CPUArchState *env, Error **errp)
     }
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
     register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
-                    cpu_save, cpu_load, env);
+                    cpu_save, cpu_load, cpu->env_ptr);
     assert(cc->vmsd == NULL);
     assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
 #endif
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 5a73bcb..05c6185 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -88,7 +88,7 @@ void QEMU_NORETURN cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
 TranslationBlock *tb_gen_code(CPUState *cpu,
                               target_ulong pc, target_ulong cs_base, int flags,
                               int cflags);
-void cpu_exec_init(CPUArchState *env, Error **errp);
+void cpu_exec_init(CPUState *cpu, Error **errp);
 void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);
 
 #if !defined(CONFIG_USER_ONLY)
diff --git a/target-alpha/cpu.c b/target-alpha/cpu.c
index e865ba7..421d7e5 100644
--- a/target-alpha/cpu.c
+++ b/target-alpha/cpu.c
@@ -257,7 +257,7 @@ static void alpha_cpu_initfn(Object *obj)
     CPUAlphaState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
     tlb_flush(cs, 1);
 
     alpha_translate_init();
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 1c40cc0..5a8cdb5 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -392,7 +392,7 @@ static void arm_cpu_initfn(Object *obj)
     uint32_t Aff1, Aff0;
 
     cs->env_ptr = &cpu->env;
-    cpu_exec_init(&cpu->env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
     cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
                                          g_free, g_free);
 
diff --git a/target-cris/cpu.c b/target-cris/cpu.c
index bb8e7ea..0db209b 100644
--- a/target-cris/cpu.c
+++ b/target-cris/cpu.c
@@ -170,7 +170,7 @@ static void cris_cpu_initfn(Object *obj)
     static bool tcg_initialized;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     env->pregs[PR_VR] = ccc->vr;
 
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 433f38b..a35b045 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3007,7 +3007,7 @@ static void x86_cpu_initfn(Object *obj)
     static int inited;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     object_property_add(obj, "family", "int",
                         x86_cpuid_version_get_family,
diff --git a/target-lm32/cpu.c b/target-lm32/cpu.c
index da4fde1..c2b77c6 100644
--- a/target-lm32/cpu.c
+++ b/target-lm32/cpu.c
@@ -151,7 +151,7 @@ static void lm32_cpu_initfn(Object *obj)
     static bool tcg_initialized;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     env->flags = 0;
 
diff --git a/target-m68k/cpu.c b/target-m68k/cpu.c
index ae3d765..4f246da 100644
--- a/target-m68k/cpu.c
+++ b/target-m68k/cpu.c
@@ -168,7 +168,7 @@ static void m68k_cpu_initfn(Object *obj)
     static bool inited;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     if (tcg_enabled() && !inited) {
         inited = true;
diff --git a/target-microblaze/cpu.c b/target-microblaze/cpu.c
index 967ea01..128d032 100644
--- a/target-microblaze/cpu.c
+++ b/target-microblaze/cpu.c
@@ -190,7 +190,7 @@ static void mb_cpu_initfn(Object *obj)
     static bool tcg_initialized;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
 
diff --git a/target-mips/cpu.c b/target-mips/cpu.c
index 1fd9f22..4027d0f 100644
--- a/target-mips/cpu.c
+++ b/target-mips/cpu.c
@@ -115,7 +115,7 @@ static void mips_cpu_initfn(Object *obj)
     CPUMIPSState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     if (tcg_enabled()) {
         mips_tcg_init();
diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c
index 415c65a..6b035aa 100644
--- a/target-moxie/cpu.c
+++ b/target-moxie/cpu.c
@@ -66,7 +66,7 @@ static void moxie_cpu_initfn(Object *obj)
     static int inited;
 
     cs->env_ptr = &cpu->env;
-    cpu_exec_init(&cpu->env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     if (tcg_enabled() && !inited) {
         inited = 1;
diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index cd6c657..d97f3c0 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -92,7 +92,7 @@ static void openrisc_cpu_initfn(Object *obj)
     static int inited;
 
     cs->env_ptr = &cpu->env;
-    cpu_exec_init(&cpu->env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
 #ifndef CONFIG_USER_ONLY
     cpu_openrisc_mmu_init(cpu);
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 2b72f2d..b95ac68 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -8928,7 +8928,7 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
-    cpu_exec_init(&cpu->env, &local_err);
+    cpu_exec_init(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index ced5592..c3e21b4 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -212,7 +212,7 @@ static void s390_cpu_initfn(Object *obj)
 #endif
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 #if !defined(CONFIG_USER_ONLY)
     qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
     qemu_get_timedate(&tm, 0);
diff --git a/target-sh4/cpu.c b/target-sh4/cpu.c
index 2c2060b..5c65ab4 100644
--- a/target-sh4/cpu.c
+++ b/target-sh4/cpu.c
@@ -248,7 +248,7 @@ static void superh_cpu_initfn(Object *obj)
     CPUSH4State *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     env->movcal_backup_tail = &(env->movcal_backup);
 
diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c
index 4d1da7c..9528e3a 100644
--- a/target-sparc/cpu.c
+++ b/target-sparc/cpu.c
@@ -802,7 +802,7 @@ static void sparc_cpu_initfn(Object *obj)
     CPUSPARCState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     if (tcg_enabled()) {
         gen_intermediate_code_init(env);
diff --git a/target-tricore/cpu.c b/target-tricore/cpu.c
index 6fa60b1..2029ef6 100644
--- a/target-tricore/cpu.c
+++ b/target-tricore/cpu.c
@@ -92,7 +92,7 @@ static void tricore_cpu_initfn(Object *obj)
     CPUTriCoreState *env = &cpu->env;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     if (tcg_enabled()) {
         tricore_tcg_init();
diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c
index eda039c..fc451a1 100644
--- a/target-unicore32/cpu.c
+++ b/target-unicore32/cpu.c
@@ -111,7 +111,7 @@ static void uc32_cpu_initfn(Object *obj)
     static bool inited;
 
     cs->env_ptr = env;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
 #ifdef CONFIG_USER_ONLY
     env->uncached_asr = ASR_MODE_USER;
diff --git a/target-xtensa/cpu.c b/target-xtensa/cpu.c
index 8d69d23..da8129d 100644
--- a/target-xtensa/cpu.c
+++ b/target-xtensa/cpu.c
@@ -114,7 +114,7 @@ static void xtensa_cpu_initfn(Object *obj)
 
     cs->env_ptr = env;
     env->config = xcc->config;
-    cpu_exec_init(env, &error_abort);
+    cpu_exec_init(cs, &error_abort);
 
     if (tcg_enabled() && !tcg_inited) {
         tcg_inited = true;
-- 
2.1.4

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

* [Qemu-devel] [PULL 11/22] cpu-exec: Purge all uses of ENV_GET_CPU()
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (9 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 10/22] cpu: Change cpu_exec_init() " Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 12/22] cpu: Add wrapper for the set_pc() hook Andreas Färber
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Guan Xuetao, Eduardo Habkost, Peter Crosthwaite,
	Jia Liu, Anthony Green, Riku Voipio, Mark Cave-Ayland,
	Michael Walle, Alexander Graf, Blue Swirl, Max Filippov,
	Peter Crosthwaite, open list:PowerPC, Edgar E. Iglesias,
	Paolo Bonzini, Bastian Koppelmann, Leon Alrae,
	Andreas Färber, Aurelien Jarno, Richard Henderson

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Remove un-needed usages of ENV_GET_CPU() by converting the APIs to use
CPUState pointers and retrieving the env_ptr as minimally needed.

Scripted conversion for target-* change:

for I in target-*/cpu.h; do
    sed -i \
    's/\(^int cpu_[^_]*_exec(\)[^ ][^ ]* \*s);$/\1CPUState *cpu);/' \
    $I;
done

Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 bsd-user/main.c         |  4 +++-
 cpu-exec.c              | 28 +++++++++++++---------------
 cpus.c                  |  3 +--
 linux-user/main.c       | 28 ++++++++++++++--------------
 target-alpha/cpu.h      |  2 +-
 target-arm/cpu.h        |  2 +-
 target-cris/cpu.h       |  2 +-
 target-i386/cpu.h       |  2 +-
 target-lm32/cpu.h       |  2 +-
 target-m68k/cpu.h       |  2 +-
 target-microblaze/cpu.h |  2 +-
 target-mips/cpu.h       |  2 +-
 target-moxie/cpu.h      |  2 +-
 target-openrisc/cpu.h   |  2 +-
 target-ppc/cpu.h        |  2 +-
 target-s390x/cpu.h      |  2 +-
 target-sh4/cpu.h        |  2 +-
 target-sparc/cpu.h      |  2 +-
 target-tricore/cpu.h    |  2 +-
 target-unicore32/cpu.h  |  3 ++-
 target-xtensa/cpu.h     |  2 +-
 21 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 45a1436..f46728b 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -166,6 +166,8 @@ static void set_idt(int n, unsigned int dpl)
 
 void cpu_loop(CPUX86State *env)
 {
+    X86CPU *cpu = x86_env_get_cpu(env);
+    CPUState *cs = CPU(cpu);
     int trapnr;
     abi_ulong pc;
     //target_siginfo_t info;
@@ -512,7 +514,7 @@ void cpu_loop(CPUSPARCState *env)
     //target_siginfo_t info;
 
     while (1) {
-        trapnr = cpu_sparc_exec (env);
+        trapnr = cpu_sparc_exec(cs);
 
         switch (trapnr) {
 #ifndef TARGET_SPARC64
diff --git a/cpu-exec.c b/cpu-exec.c
index b2724c1..75694f3 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -227,10 +227,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr)
 
 /* Execute the code without caching the generated code. An interpreter
    could be used if available. */
-static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
+static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
                              TranslationBlock *orig_tb)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
     TranslationBlock *tb;
     target_ulong pc = orig_tb->pc;
     target_ulong cs_base = orig_tb->cs_base;
@@ -254,12 +253,12 @@ static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
     tb_free(tb);
 }
 
-static TranslationBlock *tb_find_slow(CPUArchState *env,
+static TranslationBlock *tb_find_slow(CPUState *cpu,
                                       target_ulong pc,
                                       target_ulong cs_base,
                                       uint64_t flags)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
+    CPUArchState *env = (CPUArchState *)cpu->env_ptr;
     TranslationBlock *tb, **ptb1;
     unsigned int h;
     tb_page_addr_t phys_pc, phys_page1;
@@ -311,9 +310,9 @@ static TranslationBlock *tb_find_slow(CPUArchState *env,
     return tb;
 }
 
-static inline TranslationBlock *tb_find_fast(CPUArchState *env)
+static inline TranslationBlock *tb_find_fast(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
+    CPUArchState *env = (CPUArchState *)cpu->env_ptr;
     TranslationBlock *tb;
     target_ulong cs_base, pc;
     int flags;
@@ -325,14 +324,13 @@ static inline TranslationBlock *tb_find_fast(CPUArchState *env)
     tb = cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)];
     if (unlikely(!tb || tb->pc != pc || tb->cs_base != cs_base ||
                  tb->flags != flags)) {
-        tb = tb_find_slow(env, pc, cs_base, flags);
+        tb = tb_find_slow(cpu, pc, cs_base, flags);
     }
     return tb;
 }
 
-static void cpu_handle_debug_exception(CPUArchState *env)
+static void cpu_handle_debug_exception(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
     CPUClass *cc = CPU_GET_CLASS(cpu);
     CPUWatchpoint *wp;
 
@@ -349,12 +347,12 @@ static void cpu_handle_debug_exception(CPUArchState *env)
 
 volatile sig_atomic_t exit_request;
 
-int cpu_exec(CPUArchState *env)
+int cpu_exec(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
     CPUClass *cc = CPU_GET_CLASS(cpu);
 #ifdef TARGET_I386
     X86CPU *x86_cpu = X86_CPU(cpu);
+    CPUArchState *env = &x86_cpu->env;
 #endif
     int ret, interrupt_request;
     TranslationBlock *tb;
@@ -407,7 +405,7 @@ int cpu_exec(CPUArchState *env)
                     /* exit request from the cpu execution loop */
                     ret = cpu->exception_index;
                     if (ret == EXCP_DEBUG) {
-                        cpu_handle_debug_exception(env);
+                        cpu_handle_debug_exception(cpu);
                     }
                     cpu->exception_index = -1;
                     break;
@@ -483,7 +481,7 @@ int cpu_exec(CPUArchState *env)
                 }
                 spin_lock(&tcg_ctx.tb_ctx.tb_lock);
                 have_tb_lock = true;
-                tb = tb_find_fast(env);
+                tb = tb_find_fast(cpu);
                 /* Note: we do it here to avoid a gcc bug on Mac OS X when
                    doing it in tb_find_slow */
                 if (tcg_ctx.tb_ctx.tb_invalidated_flag) {
@@ -543,7 +541,7 @@ int cpu_exec(CPUArchState *env)
                             if (insns_left > 0) {
                                 /* Execute remaining instructions.  */
                                 tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK);
-                                cpu_exec_nocache(env, insns_left, tb);
+                                cpu_exec_nocache(cpu, insns_left, tb);
                                 align_clocks(&sc, cpu);
                             }
                             cpu->exception_index = EXCP_INTERRUPT;
@@ -567,11 +565,11 @@ int cpu_exec(CPUArchState *env)
             /* Reload env after longjmp - the compiler may have smashed all
              * local variables as longjmp is marked 'noreturn'. */
             cpu = current_cpu;
-            env = cpu->env_ptr;
             cc = CPU_GET_CLASS(cpu);
             cpu->can_do_io = 1;
 #ifdef TARGET_I386
             x86_cpu = X86_CPU(cpu);
+            env = &x86_cpu->env;
 #endif
             if (have_tb_lock) {
                 spin_unlock(&tcg_ctx.tb_ctx.tb_lock);
diff --git a/cpus.c b/cpus.c
index 24cac2e..b00a423 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1359,7 +1359,6 @@ int vm_stop_force_state(RunState state)
 
 static int tcg_cpu_exec(CPUState *cpu)
 {
-    CPUArchState *env = cpu->env_ptr;
     int ret;
 #ifdef CONFIG_PROFILER
     int64_t ti;
@@ -1394,7 +1393,7 @@ static int tcg_cpu_exec(CPUState *cpu)
         cpu->icount_decr.u16.low = decr;
         cpu->icount_extra = count;
     }
-    ret = cpu_exec(env);
+    ret = cpu_exec(cpu);
 #ifdef CONFIG_PROFILER
     tcg_time += profile_getclock() - ti;
 #endif
diff --git a/linux-user/main.c b/linux-user/main.c
index 12b18d0..6f07644 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -280,7 +280,7 @@ void cpu_loop(CPUX86State *env)
 
     for(;;) {
         cpu_exec_start(cs);
-        trapnr = cpu_x86_exec(env);
+        trapnr = cpu_x86_exec(cs);
         cpu_exec_end(cs);
         switch(trapnr) {
         case 0x80:
@@ -674,7 +674,7 @@ void cpu_loop(CPUARMState *env)
 
     for(;;) {
         cpu_exec_start(cs);
-        trapnr = cpu_arm_exec(env);
+        trapnr = cpu_arm_exec(cs);
         cpu_exec_end(cs);
         switch(trapnr) {
         case EXCP_UDEF:
@@ -1005,7 +1005,7 @@ void cpu_loop(CPUARMState *env)
 
     for (;;) {
         cpu_exec_start(cs);
-        trapnr = cpu_arm_exec(env);
+        trapnr = cpu_arm_exec(cs);
         cpu_exec_end(cs);
 
         switch (trapnr) {
@@ -1084,7 +1084,7 @@ void cpu_loop(CPUUniCore32State *env)
 
     for (;;) {
         cpu_exec_start(cs);
-        trapnr = uc32_cpu_exec(env);
+        trapnr = uc32_cpu_exec(cs);
         cpu_exec_end(cs);
         switch (trapnr) {
         case UC32_EXCP_PRIV:
@@ -1285,7 +1285,7 @@ void cpu_loop (CPUSPARCState *env)
 
     while (1) {
         cpu_exec_start(cs);
-        trapnr = cpu_sparc_exec (env);
+        trapnr = cpu_sparc_exec(cs);
         cpu_exec_end(cs);
 
         /* Compute PSR before exposing state.  */
@@ -1566,7 +1566,7 @@ void cpu_loop(CPUPPCState *env)
 
     for(;;) {
         cpu_exec_start(cs);
-        trapnr = cpu_ppc_exec(env);
+        trapnr = cpu_ppc_exec(cs);
         cpu_exec_end(cs);
         switch(trapnr) {
         case POWERPC_EXCP_NONE:
@@ -2418,7 +2418,7 @@ void cpu_loop(CPUMIPSState *env)
 
     for(;;) {
         cpu_exec_start(cs);
-        trapnr = cpu_mips_exec(env);
+        trapnr = cpu_mips_exec(cs);
         cpu_exec_end(cs);
         switch(trapnr) {
         case EXCP_SYSCALL:
@@ -2655,7 +2655,7 @@ void cpu_loop(CPUOpenRISCState *env)
 
     for (;;) {
         cpu_exec_start(cs);
-        trapnr = cpu_exec(env);
+        trapnr = cpu_openrisc_exec(cs);
         cpu_exec_end(cs);
         gdbsig = 0;
 
@@ -2745,7 +2745,7 @@ void cpu_loop(CPUSH4State *env)
 
     while (1) {
         cpu_exec_start(cs);
-        trapnr = cpu_sh4_exec (env);
+        trapnr = cpu_sh4_exec(cs);
         cpu_exec_end(cs);
 
         switch (trapnr) {
@@ -2807,7 +2807,7 @@ void cpu_loop(CPUCRISState *env)
     
     while (1) {
         cpu_exec_start(cs);
-        trapnr = cpu_cris_exec (env);
+        trapnr = cpu_cris_exec(cs);
         cpu_exec_end(cs);
         switch (trapnr) {
         case 0xaa:
@@ -2868,7 +2868,7 @@ void cpu_loop(CPUMBState *env)
     
     while (1) {
         cpu_exec_start(cs);
-        trapnr = cpu_mb_exec (env);
+        trapnr = cpu_mb_exec(cs);
         cpu_exec_end(cs);
         switch (trapnr) {
         case 0xaa:
@@ -2973,7 +2973,7 @@ void cpu_loop(CPUM68KState *env)
 
     for(;;) {
         cpu_exec_start(cs);
-        trapnr = cpu_m68k_exec(env);
+        trapnr = cpu_m68k_exec(cs);
         cpu_exec_end(cs);
         switch(trapnr) {
         case EXCP_ILLEGAL:
@@ -3112,7 +3112,7 @@ void cpu_loop(CPUAlphaState *env)
 
     while (1) {
         cpu_exec_start(cs);
-        trapnr = cpu_alpha_exec (env);
+        trapnr = cpu_alpha_exec(cs);
         cpu_exec_end(cs);
 
         /* All of the traps imply a transition through PALcode, which
@@ -3300,7 +3300,7 @@ void cpu_loop(CPUS390XState *env)
 
     while (1) {
         cpu_exec_start(cs);
-        trapnr = cpu_s390x_exec(env);
+        trapnr = cpu_s390x_exec(cs);
         cpu_exec_end(cs);
         switch (trapnr) {
         case EXCP_INTERRUPT:
diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index 2a4d5cb..91c56d6 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -431,7 +431,7 @@ AlphaCPU *cpu_alpha_init(const char *cpu_model);
 #define cpu_init(cpu_model) CPU(cpu_alpha_init(cpu_model))
 
 void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);
-int cpu_alpha_exec(CPUAlphaState *s);
+int cpu_alpha_exec(CPUState *cpu);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
    is returned if the signal was handled by the virtual CPU.  */
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 80297b3..7e89152 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -499,7 +499,7 @@ typedef struct CPUARMState {
 #include "cpu-qom.h"
 
 ARMCPU *cpu_arm_init(const char *cpu_model);
-int cpu_arm_exec(CPUARMState *s);
+int cpu_arm_exec(CPUState *cpu);
 uint32_t do_arm_semihosting(CPUARMState *env);
 void aarch64_sync_32_to_64(CPUARMState *env);
 void aarch64_sync_64_to_32(CPUARMState *env);
diff --git a/target-cris/cpu.h b/target-cris/cpu.h
index 677b38c..d422e35 100644
--- a/target-cris/cpu.h
+++ b/target-cris/cpu.h
@@ -176,7 +176,7 @@ typedef struct CPUCRISState {
 #include "cpu-qom.h"
 
 CRISCPU *cpu_cris_init(const char *cpu_model);
-int cpu_cris_exec(CPUCRISState *s);
+int cpu_cris_exec(CPUState *cpu);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
    is returned if the signal was handled by the virtual CPU.  */
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 603aaf0..6040205 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -983,7 +983,7 @@ typedef struct CPUX86State {
 
 X86CPU *cpu_x86_init(const char *cpu_model);
 X86CPU *cpu_x86_create(const char *cpu_model, Error **errp);
-int cpu_x86_exec(CPUX86State *s);
+int cpu_x86_exec(CPUState *cpu);
 void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 void x86_cpudef_setup(void);
 int cpu_x86_support_mca_broadcast(CPUX86State *env);
diff --git a/target-lm32/cpu.h b/target-lm32/cpu.h
index 11ae68d..944777d 100644
--- a/target-lm32/cpu.h
+++ b/target-lm32/cpu.h
@@ -199,7 +199,7 @@ static inline lm32_wp_t lm32_wp_type(uint32_t dc, int idx)
 #include "cpu-qom.h"
 
 LM32CPU *cpu_lm32_init(const char *cpu_model);
-int cpu_lm32_exec(CPULM32State *s);
+int cpu_lm32_exec(CPUState *cpu);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
    is returned if the signal was handled by the virtual CPU.  */
diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h
index 5f165da..9a62f6c 100644
--- a/target-m68k/cpu.h
+++ b/target-m68k/cpu.h
@@ -117,7 +117,7 @@ typedef struct CPUM68KState {
 void m68k_tcg_init(void);
 void m68k_cpu_init_gdb(M68kCPU *cpu);
 M68kCPU *cpu_m68k_init(const char *cpu_model);
-int cpu_m68k_exec(CPUM68KState *s);
+int cpu_m68k_exec(CPUState *cpu);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
    is returned if the signal was handled by the virtual CPU.  */
diff --git a/target-microblaze/cpu.h b/target-microblaze/cpu.h
index 0dd164f..7e20e59 100644
--- a/target-microblaze/cpu.h
+++ b/target-microblaze/cpu.h
@@ -281,7 +281,7 @@ struct CPUMBState {
 
 void mb_tcg_init(void);
 MicroBlazeCPU *cpu_mb_init(const char *cpu_model);
-int cpu_mb_exec(CPUMBState *s);
+int cpu_mb_exec(CPUState *cpu);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
    is returned if the signal was handled by the virtual CPU.  */
diff --git a/target-mips/cpu.h b/target-mips/cpu.h
index 474a0e3..075c561 100644
--- a/target-mips/cpu.h
+++ b/target-mips/cpu.h
@@ -746,7 +746,7 @@ enum {
  */
 #define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0
 
-int cpu_mips_exec(CPUMIPSState *s);
+int cpu_mips_exec(CPUState *cpu);
 void mips_tcg_init(void);
 MIPSCPU *cpu_mips_init(const char *cpu_model);
 int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
diff --git a/target-moxie/cpu.h b/target-moxie/cpu.h
index c2733a2..29572aa 100644
--- a/target-moxie/cpu.h
+++ b/target-moxie/cpu.h
@@ -112,7 +112,7 @@ static inline MoxieCPU *moxie_env_get_cpu(CPUMoxieState *env)
 #define ENV_OFFSET offsetof(MoxieCPU, env)
 
 MoxieCPU *cpu_moxie_init(const char *cpu_model);
-int cpu_moxie_exec(CPUMoxieState *s);
+int cpu_moxie_exec(CPUState *cpu);
 void moxie_cpu_do_interrupt(CPUState *cs);
 void moxie_cpu_dump_state(CPUState *cpu, FILE *f,
                           fprintf_function cpu_fprintf, int flags);
diff --git a/target-openrisc/cpu.h b/target-openrisc/cpu.h
index 9e23cd0..36c4f20 100644
--- a/target-openrisc/cpu.h
+++ b/target-openrisc/cpu.h
@@ -346,7 +346,7 @@ static inline OpenRISCCPU *openrisc_env_get_cpu(CPUOpenRISCState *env)
 OpenRISCCPU *cpu_openrisc_init(const char *cpu_model);
 
 void cpu_openrisc_list(FILE *f, fprintf_function cpu_fprintf);
-int cpu_openrisc_exec(CPUOpenRISCState *s);
+int cpu_openrisc_exec(CPUState *cpu);
 void openrisc_cpu_do_interrupt(CPUState *cpu);
 bool openrisc_cpu_exec_interrupt(CPUState *cpu, int int_req);
 void openrisc_cpu_dump_state(CPUState *cpu, FILE *f,
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index c05c503..6f76674 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -1164,7 +1164,7 @@ do {                                            \
 PowerPCCPU *cpu_ppc_init(const char *cpu_model);
 void ppc_translate_init(void);
 void gen_update_current_nip(void *opaque);
-int cpu_ppc_exec (CPUPPCState *s);
+int cpu_ppc_exec (CPUState *s);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
    is returned if the signal was handled by the virtual CPU.  */
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 7b87c7d..63aebf4 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -417,7 +417,7 @@ void trigger_pgm_exception(CPUS390XState *env, uint32_t code, uint32_t ilen);
 
 S390CPU *cpu_s390x_init(const char *cpu_model);
 void s390x_translate_init(void);
-int cpu_s390x_exec(CPUS390XState *s);
+int cpu_s390x_exec(CPUState *cpu);
 
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
diff --git a/target-sh4/cpu.h b/target-sh4/cpu.h
index 4a027a6..34bb3d7 100644
--- a/target-sh4/cpu.h
+++ b/target-sh4/cpu.h
@@ -193,7 +193,7 @@ typedef struct CPUSH4State {
 
 void sh4_translate_init(void);
 SuperHCPU *cpu_sh4_init(const char *cpu_model);
-int cpu_sh4_exec(CPUSH4State * s);
+int cpu_sh4_exec(CPUState *s);
 int cpu_sh4_signal_handler(int host_signum, void *pinfo,
                            void *puc);
 int superh_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index f5c9006..0522b65 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -537,7 +537,7 @@ int sparc_cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
 void gen_intermediate_code_init(CPUSPARCState *env);
 
 /* cpu-exec.c */
-int cpu_sparc_exec(CPUSPARCState *s);
+int cpu_sparc_exec(CPUState *cpu);
 
 /* win_helper.c */
 target_ulong cpu_get_psr(CPUSPARCState *env1);
diff --git a/target-tricore/cpu.h b/target-tricore/cpu.h
index 504f156..916ee27 100644
--- a/target-tricore/cpu.h
+++ b/target-tricore/cpu.h
@@ -372,7 +372,7 @@ enum {
 };
 
 void cpu_state_reset(CPUTriCoreState *s);
-int cpu_tricore_exec(CPUTriCoreState *s);
+int cpu_tricore_exec(CPUState *cpu);
 void tricore_tcg_init(void);
 int cpu_tricore_signal_handler(int host_signum, void *pinfo, void *puc);
 
diff --git a/target-unicore32/cpu.h b/target-unicore32/cpu.h
index 14dc862..45e31e5 100644
--- a/target-unicore32/cpu.h
+++ b/target-unicore32/cpu.h
@@ -125,7 +125,6 @@ void cpu_asr_write(CPUUniCore32State *env1, target_ulong val, target_ulong mask)
 #define cpu_exec                        uc32_cpu_exec
 #define cpu_signal_handler              uc32_cpu_signal_handler
 
-int uc32_cpu_exec(CPUUniCore32State *s);
 int uc32_cpu_signal_handler(int host_signum, void *pinfo, void *puc);
 
 /* MMU modes definitions */
@@ -141,6 +140,8 @@ static inline int cpu_mmu_index(CPUUniCore32State *env)
 #include "cpu-qom.h"
 #include "exec/exec-all.h"
 
+int uc32_cpu_exec(CPUState *s);
+
 UniCore32CPU *uc32_cpu_init(const char *cpu_model);
 
 #define cpu_init(cpu_model) CPU(uc32_cpu_init(cpu_model))
diff --git a/target-xtensa/cpu.h b/target-xtensa/cpu.h
index b89c602..96bfc82 100644
--- a/target-xtensa/cpu.h
+++ b/target-xtensa/cpu.h
@@ -399,7 +399,7 @@ XtensaCPU *cpu_xtensa_init(const char *cpu_model);
 
 void xtensa_translate_init(void);
 void xtensa_breakpoint_handler(CPUState *cs);
-int cpu_xtensa_exec(CPUXtensaState *s);
+int cpu_xtensa_exec(CPUState *cpu);
 void xtensa_finalize_config(XtensaConfig *config);
 void xtensa_register_core(XtensaConfigList *node);
 void check_interrupts(CPUXtensaState *s);
-- 
2.1.4

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

* [Qemu-devel] [PULL 12/22] cpu: Add wrapper for the set_pc() hook
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (10 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 11/22] cpu-exec: Purge all uses of ENV_GET_CPU() Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 13/22] gdbstub: Use cpu_set_pc() helper Andreas Färber
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Add a wrapper around the CPUClass::set_pc() hook.

Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 include/qom/cpu.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 7db310e..5db1ea3 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -600,6 +600,20 @@ static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
 #endif
 
 /**
+ * cpu_set_pc:
+ * @cpu: The CPU to set the program counter for.
+ * @addr: Program counter value.
+ *
+ * Sets the program counter for a CPU.
+ */
+static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+
+    cc->set_pc(cpu, addr);
+}
+
+/**
  * cpu_reset_interrupt:
  * @cpu: The CPU to clear the interrupt on.
  * @mask: The interrupt mask to clear.
-- 
2.1.4

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

* [Qemu-devel] [PULL 13/22] gdbstub: Use cpu_set_pc() helper
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (11 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 12/22] cpu: Add wrapper for the set_pc() hook Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 14/22] hw/arm/boot: Use cpu_set_pc() Andreas Färber
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Use the cpu_set_pc() helper which will take care of CPUClass retrieval
for us.

Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 gdbstub.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index aa5ba51..92b2f81 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -754,12 +754,9 @@ static void gdb_breakpoint_remove_all(void)
 static void gdb_set_cpu_pc(GDBState *s, target_ulong pc)
 {
     CPUState *cpu = s->c_cpu;
-    CPUClass *cc = CPU_GET_CLASS(cpu);
 
     cpu_synchronize_state(cpu);
-    if (cc->set_pc) {
-        cc->set_pc(cpu, pc);
-    }
+    cpu_set_pc(cpu, pc);
 }
 
 static CPUState *find_cpu(uint32_t thread_id)
-- 
2.1.4

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

* [Qemu-devel] [PULL 14/22] hw/arm/boot: Use cpu_set_pc()
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (12 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 13/22] gdbstub: Use cpu_set_pc() helper Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 15/22] microblaze: boot: " Andreas Färber
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Use cpu_set_pc() across the board for setting program counters. This
removes instances of system level code having to reach into the CPU
env.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
[AF: Avoid repeated casts with local variables]
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/arm/boot.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 1e7fd28..f48ed2d 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -168,11 +168,11 @@ static void default_write_secondary(ARMCPU *cpu,
 static void default_reset_secondary(ARMCPU *cpu,
                                     const struct arm_boot_info *info)
 {
-    CPUARMState *env = &cpu->env;
+    CPUState *cs = CPU(cpu);
 
     address_space_stl_notdirty(&address_space_memory, info->smp_bootreg_addr,
                                0, MEMTXATTRS_UNSPECIFIED, NULL);
-    env->regs[15] = info->smp_loader_start;
+    cpu_set_pc(cs, info->smp_loader_start);
 }
 
 static inline bool have_dtb(const struct arm_boot_info *info)
@@ -445,19 +445,21 @@ fail:
 static void do_cpu_reset(void *opaque)
 {
     ARMCPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
     CPUARMState *env = &cpu->env;
     const struct arm_boot_info *info = env->boot_info;
 
-    cpu_reset(CPU(cpu));
+    cpu_reset(cs);
     if (info) {
         if (!info->is_linux) {
             /* Jump to the entry point.  */
-            if (env->aarch64) {
-                env->pc = info->entry;
-            } else {
-                env->regs[15] = info->entry & 0xfffffffe;
+            uint64_t entry = info->entry;
+
+            if (!env->aarch64) {
                 env->thumb = info->entry & 1;
+                entry &= 0xfffffffe;
             }
+            cpu_set_pc(cs, entry);
         } else {
             /* If we are booting Linux then we need to check whether we are
              * booting into secure or non-secure state and adjust the state
@@ -487,12 +489,8 @@ static void do_cpu_reset(void *opaque)
                 }
             }
 
-            if (CPU(cpu) == first_cpu) {
-                if (env->aarch64) {
-                    env->pc = info->loader_start;
-                } else {
-                    env->regs[15] = info->loader_start;
-                }
+            if (cs == first_cpu) {
+                cpu_set_pc(cs, info->loader_start);
 
                 if (!have_dtb(info)) {
                     if (old_param) {
-- 
2.1.4

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

* [Qemu-devel] [PULL 15/22] microblaze: boot: Use cpu_set_pc()
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (13 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 14/22] hw/arm/boot: Use cpu_set_pc() Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:13 ` [Qemu-devel] [PULL 16/22] disas: Add print_insn to disassemble info Andreas Färber
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Edgar E. Iglesias, Peter Crosthwaite, Andreas Färber,
	Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Use cpu_set_pc() for setting program counters when bootloading. This
removes an instance of system level code having to reach into the CPU
env.

Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
[AF: Avoid duplicated CPU() casts through local variable]
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/microblaze/boot.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c
index 4c44317..3e8820f 100644
--- a/hw/microblaze/boot.c
+++ b/hw/microblaze/boot.c
@@ -48,13 +48,14 @@ static struct
 static void main_cpu_reset(void *opaque)
 {
     MicroBlazeCPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
     CPUMBState *env = &cpu->env;
 
-    cpu_reset(CPU(cpu));
+    cpu_reset(cs);
     env->regs[5] = boot_info.cmdline;
     env->regs[6] = boot_info.initrd_start;
     env->regs[7] = boot_info.fdt;
-    env->sregs[SR_PC] = boot_info.bootstrap_pc;
+    cpu_set_pc(cs, boot_info.bootstrap_pc);
     if (boot_info.machine_cpu_reset) {
         boot_info.machine_cpu_reset(cpu);
     }
-- 
2.1.4

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

* [Qemu-devel] [PULL 16/22] disas: Add print_insn to disassemble info
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (14 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 15/22] microblaze: boot: " Andreas Färber
@ 2015-07-06 23:13 ` Andreas Färber
  2015-07-06 23:14 ` [Qemu-devel] [PULL 17/22] disas: QOMify target specific setup Andreas Färber
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Add the print_insn pointer to the disassemble info structure. This is
to prepare for QOMification support, where a QOM CPU hook function will
be responsible for setting the print_insn() function. Add this function
to the existing struct to consolidate such that only the one struct
needs to be passed to the new QOM API.

Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 disas.c             | 68 ++++++++++++++++++++++++++---------------------------
 include/disas/bfd.h |  6 +++++
 2 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/disas.c b/disas.c
index 576c6a4..363c3bf 100644
--- a/disas.c
+++ b/disas.c
@@ -201,7 +201,6 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
     target_ulong pc;
     int count;
     CPUDebug s;
-    int (*print_insn)(bfd_vma pc, disassemble_info *info) = NULL;
 
     INIT_DISASSEMBLE_INFO(s.info, out, fprintf);
 
@@ -224,7 +223,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
     } else {
         s.info.mach = bfd_mach_i386_i386;
     }
-    print_insn = print_insn_i386;
+    s.info.print_insn = print_insn_i386;
 #elif defined(TARGET_ARM)
     if (flags & 4) {
         /* We might not be compiled with the A64 disassembler
@@ -232,12 +231,12 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
          * fall through to the default print_insn_od case.
          */
 #if defined(CONFIG_ARM_A64_DIS)
-        print_insn = print_insn_arm_a64;
+        s.info.print_insn = print_insn_arm_a64;
 #endif
     } else if (flags & 1) {
-        print_insn = print_insn_thumb1;
+        s.info.print_insn = print_insn_thumb1;
     } else {
-        print_insn = print_insn_arm;
+        s.info.print_insn = print_insn_arm;
     }
     if (flags & 2) {
 #ifdef TARGET_WORDS_BIGENDIAN
@@ -247,7 +246,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
 #endif
     }
 #elif defined(TARGET_SPARC)
-    print_insn = print_insn_sparc;
+    s.info.print_insn = print_insn_sparc;
 #ifdef TARGET_SPARC64
     s.info.mach = bfd_mach_sparc_v9b;
 #endif
@@ -266,49 +265,49 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
 #endif
     }
     s.info.disassembler_options = (char *)"any";
-    print_insn = print_insn_ppc;
+    s.info.print_insn = print_insn_ppc;
 #elif defined(TARGET_M68K)
-    print_insn = print_insn_m68k;
+    s.info.print_insn = print_insn_m68k;
 #elif defined(TARGET_MIPS)
 #ifdef TARGET_WORDS_BIGENDIAN
-    print_insn = print_insn_big_mips;
+    s.info.print_insn = print_insn_big_mips;
 #else
-    print_insn = print_insn_little_mips;
+    s.info.print_insn = print_insn_little_mips;
 #endif
 #elif defined(TARGET_SH4)
     s.info.mach = bfd_mach_sh4;
-    print_insn = print_insn_sh;
+    s.info.print_insn = print_insn_sh;
 #elif defined(TARGET_ALPHA)
     s.info.mach = bfd_mach_alpha_ev6;
-    print_insn = print_insn_alpha;
+    s.info.print_insn = print_insn_alpha;
 #elif defined(TARGET_CRIS)
     if (flags != 32) {
         s.info.mach = bfd_mach_cris_v0_v10;
-        print_insn = print_insn_crisv10;
+        s.info.print_insn = print_insn_crisv10;
     } else {
         s.info.mach = bfd_mach_cris_v32;
-        print_insn = print_insn_crisv32;
+        s.info.print_insn = print_insn_crisv32;
     }
 #elif defined(TARGET_S390X)
     s.info.mach = bfd_mach_s390_64;
-    print_insn = print_insn_s390;
+    s.info.print_insn = print_insn_s390;
 #elif defined(TARGET_MICROBLAZE)
     s.info.mach = bfd_arch_microblaze;
-    print_insn = print_insn_microblaze;
+    s.info.print_insn = print_insn_microblaze;
 #elif defined(TARGET_MOXIE)
     s.info.mach = bfd_arch_moxie;
-    print_insn = print_insn_moxie;
+    s.info.print_insn = print_insn_moxie;
 #elif defined(TARGET_LM32)
     s.info.mach = bfd_mach_lm32;
-    print_insn = print_insn_lm32;
+    s.info.print_insn = print_insn_lm32;
 #endif
-    if (print_insn == NULL) {
-        print_insn = print_insn_od_target;
+    if (s.info.print_insn == NULL) {
+        s.info.print_insn = print_insn_od_target;
     }
 
     for (pc = code; size > 0; pc += count, size -= count) {
 	fprintf(out, "0x" TARGET_FMT_lx ":  ", pc);
-	count = print_insn(pc, &s.info);
+	count = s.info.print_insn(pc, &s.info);
 #if 0
         {
             int i;
@@ -452,7 +451,6 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
 {
     int count, i;
     CPUDebug s;
-    int (*print_insn)(bfd_vma pc, disassemble_info *info);
 
     INIT_DISASSEMBLE_INFO(s.info, (FILE *)mon, monitor_fprintf);
 
@@ -476,13 +474,13 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
     } else {
         s.info.mach = bfd_mach_i386_i386;
     }
-    print_insn = print_insn_i386;
+    s.info.print_insn = print_insn_i386;
 #elif defined(TARGET_ARM)
-    print_insn = print_insn_arm;
+    s.info.print_insn = print_insn_arm;
 #elif defined(TARGET_ALPHA)
-    print_insn = print_insn_alpha;
+    s.info.print_insn = print_insn_alpha;
 #elif defined(TARGET_SPARC)
-    print_insn = print_insn_sparc;
+    s.info.print_insn = print_insn_sparc;
 #ifdef TARGET_SPARC64
     s.info.mach = bfd_mach_sparc_v9b;
 #endif
@@ -500,27 +498,27 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
     if ((flags >> 16) & 1) {
         s.info.endian = BFD_ENDIAN_LITTLE;
     }
-    print_insn = print_insn_ppc;
+    s.info.print_insn = print_insn_ppc;
 #elif defined(TARGET_M68K)
-    print_insn = print_insn_m68k;
+    s.info.print_insn = print_insn_m68k;
 #elif defined(TARGET_MIPS)
 #ifdef TARGET_WORDS_BIGENDIAN
-    print_insn = print_insn_big_mips;
+    s.info.print_insn = print_insn_big_mips;
 #else
-    print_insn = print_insn_little_mips;
+    s.info.print_insn = print_insn_little_mips;
 #endif
 #elif defined(TARGET_SH4)
     s.info.mach = bfd_mach_sh4;
-    print_insn = print_insn_sh;
+    s.info.print_insn = print_insn_sh;
 #elif defined(TARGET_S390X)
     s.info.mach = bfd_mach_s390_64;
-    print_insn = print_insn_s390;
+    s.info.print_insn = print_insn_s390;
 #elif defined(TARGET_MOXIE)
     s.info.mach = bfd_arch_moxie;
-    print_insn = print_insn_moxie;
+    s.info.print_insn = print_insn_moxie;
 #elif defined(TARGET_LM32)
     s.info.mach = bfd_mach_lm32;
-    print_insn = print_insn_lm32;
+    s.info.print_insn = print_insn_lm32;
 #else
     monitor_printf(mon, "0x" TARGET_FMT_lx
                    ": Asm output not supported on this arch\n", pc);
@@ -529,7 +527,7 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
 
     for(i = 0; i < nb_insn; i++) {
 	monitor_printf(mon, "0x" TARGET_FMT_lx ":  ", pc);
-        count = print_insn(pc, &s.info);
+        count = s.info.print_insn(pc, &s.info);
 	monitor_printf(mon, "\n");
 	if (count < 0)
 	    break;
diff --git a/include/disas/bfd.h b/include/disas/bfd.h
index 8bd703c..a112e9c 100644
--- a/include/disas/bfd.h
+++ b/include/disas/bfd.h
@@ -313,6 +313,11 @@ typedef struct disassemble_info {
   void (*print_address_func)
     (bfd_vma addr, struct disassemble_info *info);
 
+    /* Function called to print an instruction. The function is architecture
+     * specific.
+     */
+    int (*print_insn)(bfd_vma addr, struct disassemble_info *info);
+
   /* Function called to determine if there is a symbol at the given ADDR.
      If there is, the function returns 1, otherwise it returns 0.
      This is used by ports which support an overlay manager where
@@ -463,6 +468,7 @@ int generic_symbol_at_address(bfd_vma, struct disassemble_info *);
   (INFO).read_memory_func = buffer_read_memory, \
   (INFO).memory_error_func = perror_memory, \
   (INFO).print_address_func = generic_print_address, \
+  (INFO).print_insn = NULL, \
   (INFO).symbol_at_address_func = generic_symbol_at_address, \
   (INFO).flags = 0, \
   (INFO).bytes_per_line = 0, \
-- 
2.1.4

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

* [Qemu-devel] [PULL 17/22] disas: QOMify target specific setup
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (15 preceding siblings ...)
  2015-07-06 23:13 ` [Qemu-devel] [PULL 16/22] disas: Add print_insn to disassemble info Andreas Färber
@ 2015-07-06 23:14 ` Andreas Färber
  2015-07-06 23:14 ` [Qemu-devel] [PULL 18/22] disas: arm-a64: Make printfer and stream variable Andreas Färber
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Add a QOM function hook for target-specific disassembly setup. This
allows removal of the #ifdeffery currently implementing target specific
disas setup from disas.c.

Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 disas.c           | 22 ++++++++++++++++++----
 include/qom/cpu.h |  4 ++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/disas.c b/disas.c
index 363c3bf..ff5425d 100644
--- a/disas.c
+++ b/disas.c
@@ -1,5 +1,6 @@
 /* General "disassemble this chunk" code.  Used for debugging. */
 #include "config.h"
+#include "qemu-common.h"
 #include "disas/bfd.h"
 #include "elf.h"
 #include <errno.h>
@@ -198,6 +199,7 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info)
 void target_disas(FILE *out, CPUState *cpu, target_ulong code,
                   target_ulong size, int flags)
 {
+    CPUClass *cc = CPU_GET_CLASS(cpu);
     target_ulong pc;
     int count;
     CPUDebug s;
@@ -215,6 +217,11 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
 #else
     s.info.endian = BFD_ENDIAN_LITTLE;
 #endif
+
+    if (cc->disas_set_info) {
+        cc->disas_set_info(cpu, &s.info);
+    }
+
 #if defined(TARGET_I386)
     if (flags == 2) {
         s.info.mach = bfd_mach_x86_64;
@@ -449,6 +456,7 @@ monitor_fprintf(FILE *stream, const char *fmt, ...)
 void monitor_disas(Monitor *mon, CPUState *cpu,
                    target_ulong pc, int nb_insn, int is_physical, int flags)
 {
+    CPUClass *cc = CPU_GET_CLASS(cpu);
     int count, i;
     CPUDebug s;
 
@@ -466,6 +474,11 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
 #else
     s.info.endian = BFD_ENDIAN_LITTLE;
 #endif
+
+    if (cc->disas_set_info) {
+        cc->disas_set_info(cpu, &s.info);
+    }
+
 #if defined(TARGET_I386)
     if (flags == 2) {
         s.info.mach = bfd_mach_x86_64;
@@ -519,11 +532,12 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
 #elif defined(TARGET_LM32)
     s.info.mach = bfd_mach_lm32;
     s.info.print_insn = print_insn_lm32;
-#else
-    monitor_printf(mon, "0x" TARGET_FMT_lx
-                   ": Asm output not supported on this arch\n", pc);
-    return;
 #endif
+    if (!s.info.print_insn) {
+        monitor_printf(mon, "0x" TARGET_FMT_lx
+                       ": Asm output not supported on this arch\n", pc);
+        return;
+    }
 
     for(i = 0; i < nb_insn; i++) {
 	monitor_printf(mon, "0x" TARGET_FMT_lx ":  ", pc);
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 5db1ea3..8016724 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -23,6 +23,7 @@
 #include <signal.h>
 #include <setjmp.h>
 #include "hw/qdev-core.h"
+#include "disas/bfd.h"
 #include "exec/hwaddr.h"
 #include "exec/memattrs.h"
 #include "qemu/queue.h"
@@ -117,6 +118,7 @@ struct TranslationBlock;
  * @cpu_exec_enter: Callback for cpu_exec preparation.
  * @cpu_exec_exit: Callback for cpu_exec cleanup.
  * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
+ * @disas_set_info: Setup architecture specific components of disassembly info
  *
  * Represents a CPU family or model.
  */
@@ -172,6 +174,8 @@ typedef struct CPUClass {
     void (*cpu_exec_enter)(CPUState *cpu);
     void (*cpu_exec_exit)(CPUState *cpu);
     bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
+
+    void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
 } CPUClass;
 
 #ifdef HOST_WORDS_BIGENDIAN
-- 
2.1.4

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

* [Qemu-devel] [PULL 18/22] disas: arm-a64: Make printfer and stream variable
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (16 preceding siblings ...)
  2015-07-06 23:14 ` [Qemu-devel] [PULL 17/22] disas: QOMify target specific setup Andreas Färber
@ 2015-07-06 23:14 ` Andreas Färber
  2015-07-06 23:14 ` [Qemu-devel] [PULL 19/22] disas: arm: QOMify target specific disas setup Andreas Färber
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

In a normal disassembly flow, the printf() and stream being used varies
from disas job to job. In particular it varies if mixing monitor_disas
and target_disas.

Make both the printf() function and target stream settable in the
QEMUDisassmbler class.

Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>
Tested-by: Claudio Fontana <claudio.fontana@huawei.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 disas/arm-a64.cc | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/disas/arm-a64.cc b/disas/arm-a64.cc
index e04f946..b0803f9 100644
--- a/disas/arm-a64.cc
+++ b/disas/arm-a64.cc
@@ -35,16 +35,25 @@ static Disassembler *vixl_disasm = NULL;
  */
 class QEMUDisassembler : public Disassembler {
 public:
-    explicit QEMUDisassembler(FILE *stream) : stream_(stream) { }
+    QEMUDisassembler() : printf_(NULL), stream_(NULL) { }
     ~QEMUDisassembler() { }
 
+    void SetStream(FILE *stream) {
+        stream_ = stream;
+    }
+
+    void SetPrintf(int (*printf_fn)(FILE *, const char *, ...)) {
+        printf_ = printf_fn;
+    }
+
 protected:
     virtual void ProcessOutput(const Instruction *instr) {
-        fprintf(stream_, "%08" PRIx32 "      %s",
+        printf_(stream_, "%08" PRIx32 "      %s",
                 instr->InstructionBits(), GetOutput());
     }
 
 private:
+    int (*printf_)(FILE *, const char *, ...);
     FILE *stream_;
 };
 
@@ -53,9 +62,9 @@ static int vixl_is_initialized(void)
     return vixl_decoder != NULL;
 }
 
-static void vixl_init(FILE *f) {
+static void vixl_init() {
     vixl_decoder = new Decoder();
-    vixl_disasm = new QEMUDisassembler(f);
+    vixl_disasm = new QEMUDisassembler();
     vixl_decoder->AppendVisitor(vixl_disasm);
 }
 
@@ -78,9 +87,12 @@ int print_insn_arm_a64(uint64_t addr, disassemble_info *info)
     }
 
     if (!vixl_is_initialized()) {
-        vixl_init(info->stream);
+        vixl_init();
     }
 
+    ((QEMUDisassembler *)vixl_disasm)->SetPrintf(info->fprintf_func);
+    ((QEMUDisassembler *)vixl_disasm)->SetStream(info->stream);
+
     instrval = bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24;
     instr = reinterpret_cast<const Instruction *>(&instrval);
     vixl_disasm->MapCodeAddress(addr, instr);
-- 
2.1.4

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

* [Qemu-devel] [PULL 19/22] disas: arm: QOMify target specific disas setup
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (17 preceding siblings ...)
  2015-07-06 23:14 ` [Qemu-devel] [PULL 18/22] disas: arm-a64: Make printfer and stream variable Andreas Färber
@ 2015-07-06 23:14 ` Andreas Färber
  2015-07-06 23:14 ` [Qemu-devel] [PULL 20/22] disas: microblaze: " Andreas Färber
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Move the target_disas() ARM specifics to the QOM disas_set_info hook
and delete the ARM specific code in disas.c.

This has the extra advantage of the more fully featured target_disas()
implementation now applying to monitor_disas().

Currently, target_disas() has multi-endian, thumb and AArch64
support whereas the existing monitor_disas() support only has vanilla
AA32 support.

E.G. Running an AA64 linux kernel the following -d in_asm disas happens
(taget_disas()):

IN:
0x0000000040000000:  580000c0      ldr x0, pc+24 (addr 0x40000018)
0x0000000040000004:  aa1f03e1      mov x1, xzr

However before this patch, disasing the same from the monitor:

(qemu) xp/i 0x40000000
0x0000000040000000:  580000c0      stmdapl  r0, {r6, r7}

After this patch:
(qemu) xp/i 0x40000000
0x0000000040000000:  580000c0      ldr x0, pc+24 (addr 0x40000018)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 disas.c          | 32 --------------------------------
 target-arm/cpu.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/disas.c b/disas.c
index ff5425d..fde5029 100644
--- a/disas.c
+++ b/disas.c
@@ -151,14 +151,6 @@ bfd_vma bfd_getb16 (const bfd_byte *addr)
   return (bfd_vma) v;
 }
 
-#ifdef TARGET_ARM
-static int
-print_insn_thumb1(bfd_vma pc, disassemble_info *info)
-{
-  return print_insn_arm(pc | 1, info);
-}
-#endif
-
 static int print_insn_objdump(bfd_vma pc, disassemble_info *info,
                               const char *prefix)
 {
@@ -191,7 +183,6 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info)
 /* Disassemble this for me please... (debugging). 'flags' has the following
    values:
     i386 - 1 means 16 bit code, 2 means 64 bit code
-    arm  - bit 0 = thumb, bit 1 = reverse endian, bit 2 = A64
     ppc  - bits 0:15 specify (optionally) the machine instruction set;
            bit 16 indicates little endian.
     other targets - unused
@@ -231,27 +222,6 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
         s.info.mach = bfd_mach_i386_i386;
     }
     s.info.print_insn = print_insn_i386;
-#elif defined(TARGET_ARM)
-    if (flags & 4) {
-        /* We might not be compiled with the A64 disassembler
-         * because it needs a C++ compiler; in that case we will
-         * fall through to the default print_insn_od case.
-         */
-#if defined(CONFIG_ARM_A64_DIS)
-        s.info.print_insn = print_insn_arm_a64;
-#endif
-    } else if (flags & 1) {
-        s.info.print_insn = print_insn_thumb1;
-    } else {
-        s.info.print_insn = print_insn_arm;
-    }
-    if (flags & 2) {
-#ifdef TARGET_WORDS_BIGENDIAN
-        s.info.endian = BFD_ENDIAN_LITTLE;
-#else
-        s.info.endian = BFD_ENDIAN_BIG;
-#endif
-    }
 #elif defined(TARGET_SPARC)
     s.info.print_insn = print_insn_sparc;
 #ifdef TARGET_SPARC64
@@ -488,8 +458,6 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
         s.info.mach = bfd_mach_i386_i386;
     }
     s.info.print_insn = print_insn_i386;
-#elif defined(TARGET_ARM)
-    s.info.print_insn = print_insn_arm;
 #elif defined(TARGET_ALPHA)
     s.info.print_insn = print_insn_alpha;
 #elif defined(TARGET_SPARC)
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 5a8cdb5..8b4323d 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -382,6 +382,39 @@ static inline void unset_feature(CPUARMState *env, int feature)
     env->features &= ~(1ULL << feature);
 }
 
+static int
+print_insn_thumb1(bfd_vma pc, disassemble_info *info)
+{
+  return print_insn_arm(pc | 1, info);
+}
+
+static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
+{
+    ARMCPU *ac = ARM_CPU(cpu);
+    CPUARMState *env = &ac->env;
+
+    if (is_a64(env)) {
+        /* We might not be compiled with the A64 disassembler
+         * because it needs a C++ compiler. Leave print_insn
+         * unset in this case to use the caller default behaviour.
+         */
+#if defined(CONFIG_ARM_A64_DIS)
+        info->print_insn = print_insn_arm_a64;
+#endif
+    } else if (env->thumb) {
+        info->print_insn = print_insn_thumb1;
+    } else {
+        info->print_insn = print_insn_arm;
+    }
+    if (env->bswap_code) {
+#ifdef TARGET_WORDS_BIGENDIAN
+        info->endian = BFD_ENDIAN_LITTLE;
+#else
+        info->endian = BFD_ENDIAN_BIG;
+#endif
+    }
+}
+
 #define ARM_CPUS_PER_CLUSTER 8
 
 static void arm_cpu_initfn(Object *obj)
@@ -1368,6 +1401,8 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
     cc->gdb_core_xml_file = "arm-core.xml";
     cc->gdb_stop_before_watchpoint = true;
     cc->debug_excp_handler = arm_debug_excp_handler;
+
+    cc->disas_set_info = arm_disas_set_info;
 }
 
 static void cpu_register(const ARMCPUInfo *info)
-- 
2.1.4

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

* [Qemu-devel] [PULL 20/22] disas: microblaze: QOMify target specific disas setup
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (18 preceding siblings ...)
  2015-07-06 23:14 ` [Qemu-devel] [PULL 19/22] disas: arm: QOMify target specific disas setup Andreas Färber
@ 2015-07-06 23:14 ` Andreas Färber
  2015-07-06 23:14 ` [Qemu-devel] [PULL 21/22] disas: cris: Fix 0 buffer length case Andreas Färber
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Edgar E. Iglesias, Peter Crosthwaite, Andreas Färber,
	Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Move the target_disas() MB specifics to the QOM disas_set_info hook
and delete the MB specific code in disas.c.

This also now adds support for monitor_disas() to Microblaze.

E.g.
(qemu) xp 0x90000000
0000000090000000: 0x94208001

And before this patch:
(qemu) xp/i 0x90000000
0x90000000: Asm output not supported on this arch

After:
(qemu) xp/i 0x90000000
0x90000000:  mfs    r1, rmsr

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 disas.c                 | 3 ---
 target-microblaze/cpu.c | 8 ++++++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/disas.c b/disas.c
index fde5029..937e08b 100644
--- a/disas.c
+++ b/disas.c
@@ -268,9 +268,6 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
 #elif defined(TARGET_S390X)
     s.info.mach = bfd_mach_s390_64;
     s.info.print_insn = print_insn_s390;
-#elif defined(TARGET_MICROBLAZE)
-    s.info.mach = bfd_arch_microblaze;
-    s.info.print_insn = print_insn_microblaze;
 #elif defined(TARGET_MOXIE)
     s.info.mach = bfd_arch_moxie;
     s.info.print_insn = print_insn_moxie;
diff --git a/target-microblaze/cpu.c b/target-microblaze/cpu.c
index 128d032..9ac509a 100644
--- a/target-microblaze/cpu.c
+++ b/target-microblaze/cpu.c
@@ -119,6 +119,12 @@ static void mb_cpu_reset(CPUState *s)
 #endif
 }
 
+static void mb_disas_set_info(CPUState *cpu, disassemble_info *info)
+{
+    info->mach = bfd_arch_microblaze;
+    info->print_insn = print_insn_microblaze;
+}
+
 static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cs = CPU(dev);
@@ -256,6 +262,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
     dc->vmsd = &vmstate_mb_cpu;
     dc->props = mb_properties;
     cc->gdb_num_core_regs = 32 + 5;
+
+    cc->disas_set_info = mb_disas_set_info;
 }
 
 static const TypeInfo mb_cpu_type_info = {
-- 
2.1.4

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

* [Qemu-devel] [PULL 21/22] disas: cris: Fix 0 buffer length case
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (19 preceding siblings ...)
  2015-07-06 23:14 ` [Qemu-devel] [PULL 20/22] disas: microblaze: " Andreas Färber
@ 2015-07-06 23:14 ` Andreas Färber
  2015-07-06 23:14 ` [Qemu-devel] [PULL 22/22] disas: cris: QOMify target specific disas setup Andreas Färber
  2015-07-07  0:24 ` [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Crosthwaite, Andreas Färber, Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Cris has the complication of variable length instructions and has
a check in place to clamp memory reads in case the disas request
doesn't have enough bytes for the instruction being disas'd. This
breaks down in the case where disassembling for the monitor where
the buffer length is defaulted to 0.

The buffer length should never be zero for a regular target_disas,
so we can safely assume the 0 case is for the monitor in which case
consider the buffer length to be the max for cris instructions.

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 disas/cris.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/disas/cris.c b/disas/cris.c
index e6cff7a..1b76a09 100644
--- a/disas/cris.c
+++ b/disas/cris.c
@@ -2575,9 +2575,9 @@ print_insn_cris_generic (bfd_vma memaddr,
      If we can't get any data, or we do not get enough data, we print
      the error message.  */
 
-  nbytes = info->buffer_length;
-  if (nbytes > MAX_BYTES_PER_CRIS_INSN)
-	  nbytes = MAX_BYTES_PER_CRIS_INSN;
+  nbytes = info->buffer_length ? info->buffer_length
+                               : MAX_BYTES_PER_CRIS_INSN;
+  nbytes = MIN(nbytes, MAX_BYTES_PER_CRIS_INSN);
   status = (*info->read_memory_func) (memaddr, buffer, nbytes, info);  
 
   /* If we did not get all we asked for, then clear the rest.
-- 
2.1.4

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

* [Qemu-devel] [PULL 22/22] disas: cris: QOMify target specific disas setup
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (20 preceding siblings ...)
  2015-07-06 23:14 ` [Qemu-devel] [PULL 21/22] disas: cris: Fix 0 buffer length case Andreas Färber
@ 2015-07-06 23:14 ` Andreas Färber
  2015-07-07  0:24 ` [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
  22 siblings, 0 replies; 28+ messages in thread
From: Andreas Färber @ 2015-07-06 23:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Edgar E. Iglesias, Peter Crosthwaite, Andreas Färber,
	Peter Crosthwaite

From: Peter Crosthwaite <crosthwaitepeter@gmail.com>

Move the target_disas() cris specifics to the QOM disas_set_info() hook
and delete the cris specific code in disas.c.

This also now adds support for monitor_disas() to cris.

E.g.
(qemu) xp 0x40004000
0000000040004000: 0x1e6f25f0

And before this patch:
(qemu) xp/i 0x40004000
0x40004000: Asm output not supported on this arch

After:
(qemu) xp/i 0x40004000
0x40004000:  di
(qemu) xp/i 0x40004002
0x40004002:  move.d 0xb003c004,$r1

Note: second example is 6-byte misaligned instruction!

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 disas.c           |  8 --------
 target-cris/cpu.c | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/disas.c b/disas.c
index 937e08b..69a6066 100644
--- a/disas.c
+++ b/disas.c
@@ -257,14 +257,6 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
 #elif defined(TARGET_ALPHA)
     s.info.mach = bfd_mach_alpha_ev6;
     s.info.print_insn = print_insn_alpha;
-#elif defined(TARGET_CRIS)
-    if (flags != 32) {
-        s.info.mach = bfd_mach_cris_v0_v10;
-        s.info.print_insn = print_insn_crisv10;
-    } else {
-        s.info.mach = bfd_mach_cris_v32;
-        s.info.print_insn = print_insn_crisv32;
-    }
 #elif defined(TARGET_S390X)
     s.info.mach = bfd_mach_s390_64;
     s.info.print_insn = print_insn_s390;
diff --git a/target-cris/cpu.c b/target-cris/cpu.c
index 0db209b..b17e849 100644
--- a/target-cris/cpu.c
+++ b/target-cris/cpu.c
@@ -161,6 +161,20 @@ static void cris_cpu_set_irq(void *opaque, int irq, int level)
 }
 #endif
 
+static void cris_disas_set_info(CPUState *cpu, disassemble_info *info)
+{
+    CRISCPU *cc = CRIS_CPU(cpu);
+    CPUCRISState *env = &cc->env;
+
+    if (env->pregs[PR_VR] != 32) {
+        info->mach = bfd_mach_cris_v0_v10;
+        info->print_insn = print_insn_crisv10;
+    } else {
+        info->mach = bfd_mach_cris_v32;
+        info->print_insn = print_insn_crisv32;
+    }
+}
+
 static void cris_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
@@ -292,6 +306,8 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->gdb_num_core_regs = 49;
     cc->gdb_stop_before_watchpoint = true;
+
+    cc->disas_set_info = cris_disas_set_info;
 }
 
 static const TypeInfo cris_cpu_type_info = {
-- 
2.1.4

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

* Re: [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06
  2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
                   ` (21 preceding siblings ...)
  2015-07-06 23:14 ` [Qemu-devel] [PULL 22/22] disas: cris: QOMify target specific disas setup Andreas Färber
@ 2015-07-07  0:24 ` Andreas Färber
  2015-07-07  2:25   ` Peter Crosthwaite
  22 siblings, 1 reply; 28+ messages in thread
From: Andreas Färber @ 2015-07-07  0:24 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Peter Crosthwaite; +Cc: Eduardo Habkost

Am 07.07.2015 um 01:13 schrieb Andreas Färber:
> Hello Peter,
> 
> This is my QOM CPU patch queue. Please pull.
> 
> Note: For time reasons I did not give this queue as much testing as usual,
> in particular BSD and non-x86 KVM hosts were not covered.
> 
> Regards,
> Andreas
> 
> Cc: Peter Maydell <peter.maydell@linaro.org>
> 
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> 
> The following changes since commit 7edd8e4660beb301d527257f8e04ebec0f841cb0:
> 
>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2015-07-06 14:03:44 +0100)
> 
> are available in the git repository at:
> 
>   git://github.com/afaerber/qemu-cpu.git tags/qom-cpu-for-peter
> 
> for you to fetch changes up to 116382f1504d655a1afdf3eac18d276a200428b7:
> 
>   disas: cris: QOMify target specific disas setup (2015-07-06 22:36:17 +0200)
> 
> ----------------------------------------------------------------
> QOM CPUState and X86CPU
> 
> * Further QOM'ification of CPU initialization
> * Propagation of CPUState arguments and elimination of ENV_GET_CPU() usage
> * cpu_set_pc() abstraction
> * CPUClass::disas_set_info() hook
> 
> ----------------------------------------------------------------
[...]

Self-nack, hurry is never good:

  /aarch64/qom/xlnx-ep108:
qemu-system-aarch64: Trying to use more CPUs than allowed max of 1
Broken pipe
FAIL

Peter C., any ideas why this is regressing?

Sorry,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)

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

* Re: [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06
  2015-07-07  0:24 ` [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
@ 2015-07-07  2:25   ` Peter Crosthwaite
  2015-07-07  3:56     ` Bharata B Rao
  2015-07-07  4:07     ` Peter Crosthwaite
  0 siblings, 2 replies; 28+ messages in thread
From: Peter Crosthwaite @ 2015-07-07  2:25 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Peter Maydell, qemu-devel@nongnu.org Developers, Eduardo Habkost

On Mon, Jul 6, 2015 at 5:24 PM, Andreas Färber <afaerber@suse.de> wrote:
> Am 07.07.2015 um 01:13 schrieb Andreas Färber:
>> Hello Peter,
>>
>> This is my QOM CPU patch queue. Please pull.
>>
>> Note: For time reasons I did not give this queue as much testing as usual,
>> in particular BSD and non-x86 KVM hosts were not covered.
>>
>> Regards,
>> Andreas
>>
>> Cc: Peter Maydell <peter.maydell@linaro.org>
>>
>> Cc: Eduardo Habkost <ehabkost@redhat.com>
>> Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>>
>> The following changes since commit 7edd8e4660beb301d527257f8e04ebec0f841cb0:
>>
>>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2015-07-06 14:03:44 +0100)
>>
>> are available in the git repository at:
>>
>>   git://github.com/afaerber/qemu-cpu.git tags/qom-cpu-for-peter
>>
>> for you to fetch changes up to 116382f1504d655a1afdf3eac18d276a200428b7:
>>
>>   disas: cris: QOMify target specific disas setup (2015-07-06 22:36:17 +0200)
>>
>> ----------------------------------------------------------------
>> QOM CPUState and X86CPU
>>
>> * Further QOM'ification of CPU initialization
>> * Propagation of CPUState arguments and elimination of ENV_GET_CPU() usage
>> * cpu_set_pc() abstraction
>> * CPUClass::disas_set_info() hook
>>
>> ----------------------------------------------------------------
> [...]
>
> Self-nack, hurry is never good:
>
>   /aarch64/qom/xlnx-ep108:
> qemu-system-aarch64: Trying to use more CPUs than allowed max of 1
> Broken pipe
> FAIL
>
> Peter C., any ideas why this is regressing?
>

This:

+    if (cpu >= max_cpus) {
+        error_setg(errp, "Trying to use more CPUs than allowed max of %d\n",
+                    max_cpus);
+        return -1;

xlnx-ep108 doesn't care about the -smp argument, it creates all 6 CPUs
regardless of -smp. This is because the number of CPUs is not flexible
in reality. It is also a heterogeneous arch (with R5s abd A53s) so
trying to limit the grand total of CPUs is ambiguous (do you remove
a53s or r5s for -smp < 6?).

Can this check be dropped or is this a bug in xlnx where we should
overcome by just forcing smp_cpus = 6 at machine level?

Regards,
Peter


> Sorry,
> Andreas
>
> --
> SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
> 21284 (AG Nürnberg)
>

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

* Re: [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06
  2015-07-07  2:25   ` Peter Crosthwaite
@ 2015-07-07  3:56     ` Bharata B Rao
  2015-07-07  4:14       ` Peter Crosthwaite
  2015-07-07  4:07     ` Peter Crosthwaite
  1 sibling, 1 reply; 28+ messages in thread
From: Bharata B Rao @ 2015-07-07  3:56 UTC (permalink / raw)
  To: Peter Crosthwaite
  Cc: Peter Maydell, Andreas Färber, Eduardo Habkost,
	qemu-devel@nongnu.org Developers

On Tue, Jul 7, 2015 at 7:55 AM, Peter Crosthwaite
<peter.crosthwaite@xilinx.com> wrote:
> On Mon, Jul 6, 2015 at 5:24 PM, Andreas Färber <afaerber@suse.de> wrote:
>> Am 07.07.2015 um 01:13 schrieb Andreas Färber:
>>> Hello Peter,
>>>
>>> This is my QOM CPU patch queue. Please pull.
>>>
>>> Note: For time reasons I did not give this queue as much testing as usual,
>>> in particular BSD and non-x86 KVM hosts were not covered.
>>>
>>> Regards,
>>> Andreas
>>>
>>> Cc: Peter Maydell <peter.maydell@linaro.org>
>>>
>>> Cc: Eduardo Habkost <ehabkost@redhat.com>
>>> Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>>>
>>> The following changes since commit 7edd8e4660beb301d527257f8e04ebec0f841cb0:
>>>
>>>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2015-07-06 14:03:44 +0100)
>>>
>>> are available in the git repository at:
>>>
>>>   git://github.com/afaerber/qemu-cpu.git tags/qom-cpu-for-peter
>>>
>>> for you to fetch changes up to 116382f1504d655a1afdf3eac18d276a200428b7:
>>>
>>>   disas: cris: QOMify target specific disas setup (2015-07-06 22:36:17 +0200)
>>>
>>> ----------------------------------------------------------------
>>> QOM CPUState and X86CPU
>>>
>>> * Further QOM'ification of CPU initialization
>>> * Propagation of CPUState arguments and elimination of ENV_GET_CPU() usage
>>> * cpu_set_pc() abstraction
>>> * CPUClass::disas_set_info() hook
>>>
>>> ----------------------------------------------------------------
>> [...]
>>
>> Self-nack, hurry is never good:
>>
>>   /aarch64/qom/xlnx-ep108:
>> qemu-system-aarch64: Trying to use more CPUs than allowed max of 1
>> Broken pipe
>> FAIL
>>
>> Peter C., any ideas why this is regressing?
>>
>
> This:
>
> +    if (cpu >= max_cpus) {
> +        error_setg(errp, "Trying to use more CPUs than allowed max of %d\n",
> +                    max_cpus);
> +        return -1;
>
> xlnx-ep108 doesn't care about the -smp argument, it creates all 6 CPUs
> regardless of -smp. This is because the number of CPUs is not flexible
> in reality. It is also a heterogeneous arch (with R5s abd A53s) so
> trying to limit the grand total of CPUs is ambiguous (do you remove
> a53s or r5s for -smp < 6?).
>
> Can this check be dropped or is this a bug in xlnx where we should
> overcome by just forcing smp_cpus = 6 at machine level?

That check is needed to fail CPU realization when an attempt is made
to relialize (eg. via hotplug) more than allowed max number of CPUs.

Regards,
Bharata.

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

* Re: [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06
  2015-07-07  2:25   ` Peter Crosthwaite
  2015-07-07  3:56     ` Bharata B Rao
@ 2015-07-07  4:07     ` Peter Crosthwaite
  1 sibling, 0 replies; 28+ messages in thread
From: Peter Crosthwaite @ 2015-07-07  4:07 UTC (permalink / raw)
  To: Andreas Färber, Bharata B Rao
  Cc: Peter Maydell, qemu-devel@nongnu.org Developers, Eduardo Habkost

On Mon, Jul 6, 2015 at 7:25 PM, Peter Crosthwaite
<peter.crosthwaite@xilinx.com> wrote:
> On Mon, Jul 6, 2015 at 5:24 PM, Andreas Färber <afaerber@suse.de> wrote:
>> Am 07.07.2015 um 01:13 schrieb Andreas Färber:
>>> Hello Peter,
>>>
>>> This is my QOM CPU patch queue. Please pull.
>>>
>>> Note: For time reasons I did not give this queue as much testing as usual,
>>> in particular BSD and non-x86 KVM hosts were not covered.
>>>
>>> Regards,
>>> Andreas
>>>
>>> Cc: Peter Maydell <peter.maydell@linaro.org>
>>>
>>> Cc: Eduardo Habkost <ehabkost@redhat.com>
>>> Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>>>
>>> The following changes since commit 7edd8e4660beb301d527257f8e04ebec0f841cb0:
>>>
>>>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2015-07-06 14:03:44 +0100)
>>>
>>> are available in the git repository at:
>>>
>>>   git://github.com/afaerber/qemu-cpu.git tags/qom-cpu-for-peter
>>>
>>> for you to fetch changes up to 116382f1504d655a1afdf3eac18d276a200428b7:
>>>
>>>   disas: cris: QOMify target specific disas setup (2015-07-06 22:36:17 +0200)
>>>
>>> ----------------------------------------------------------------
>>> QOM CPUState and X86CPU
>>>
>>> * Further QOM'ification of CPU initialization
>>> * Propagation of CPUState arguments and elimination of ENV_GET_CPU() usage
>>> * cpu_set_pc() abstraction
>>> * CPUClass::disas_set_info() hook
>>>
>>> ----------------------------------------------------------------
>> [...]
>>
>> Self-nack, hurry is never good:
>>
>>   /aarch64/qom/xlnx-ep108:
>> qemu-system-aarch64: Trying to use more CPUs than allowed max of 1
>> Broken pipe
>> FAIL
>>
>> Peter C., any ideas why this is regressing?
>>
>
> This:
>
> +    if (cpu >= max_cpus) {
> +        error_setg(errp, "Trying to use more CPUs than allowed max of %d\n",
> +                    max_cpus);
> +        return -1;
>
> xlnx-ep108 doesn't care about the -smp argument, it creates all 6 CPUs
> regardless of -smp. This is because the number of CPUs is not flexible
> in reality. It is also a heterogeneous arch (with R5s abd A53s) so
> trying to limit the grand total of CPUs is ambiguous (do you remove
> a53s or r5s for -smp < 6?).
>
> Can this check be dropped or is this a bug in xlnx where we should
> overcome by just forcing smp_cpus = 6 at machine level?
>
> Regards,
> Peter
>

This is the fix (patch 5):

@@ -531,11 +531,11 @@ static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);

 static int cpu_get_free_index(Error **errp)
 {
-    int cpu = find_first_zero_bit(cpu_index_map, max_cpus);
+    int cpu = find_first_zero_bit(cpu_index_map, MAX_CPUMASK_BITS);

-    if (cpu >= max_cpus) {
-        error_setg(errp, "Trying to use more CPUs than allowed max of %d",
-                   max_cpus);
+    if (cpu >= MAX_CPUMASK_BITS) {
+        error_setg(errp, "Trying to use more CPUs than max of %d",
+                   MAX_CPUMASK_BITS);
         return -1;
     }

My thinking is, that the existing linear allocator for cpu-indicies
does not have max_cpus based maximum index enforcement and adding it
is not necessarily in the scope of Bharata's patch series. Given than
this extra feature regresses without being critical to PPC CPU hotplug
removal, we can just remove it from the patch and instead only enforce
that the indicies are within the hard limits of the bitmap itself.

We can follow-up with a more correct max check once we have the needed
fix to either ep108 or core code, but this edit is hopefully enough
for this PULL?

An amended version of the PULL with the fix squashed in is available at:

https://github.com/pcrost/qemu.git qom-cpu-for-peter

Regards,
Peter

>
>> Sorry,
>> Andreas
>>
>> --
>> SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
>> GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
>> 21284 (AG Nürnberg)
>>

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

* Re: [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06
  2015-07-07  3:56     ` Bharata B Rao
@ 2015-07-07  4:14       ` Peter Crosthwaite
  0 siblings, 0 replies; 28+ messages in thread
From: Peter Crosthwaite @ 2015-07-07  4:14 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: qemu-devel@nongnu.org Developers, Peter Maydell,
	Andreas Färber, Eduardo Habkost

On Mon, Jul 6, 2015 at 8:56 PM, Bharata B Rao <bharata.rao@gmail.com> wrote:
> On Tue, Jul 7, 2015 at 7:55 AM, Peter Crosthwaite
> <peter.crosthwaite@xilinx.com> wrote:
>> On Mon, Jul 6, 2015 at 5:24 PM, Andreas Färber <afaerber@suse.de> wrote:
>>> Am 07.07.2015 um 01:13 schrieb Andreas Färber:
>>>> Hello Peter,
>>>>
>>>> This is my QOM CPU patch queue. Please pull.
>>>>
>>>> Note: For time reasons I did not give this queue as much testing as usual,
>>>> in particular BSD and non-x86 KVM hosts were not covered.
>>>>
>>>> Regards,
>>>> Andreas
>>>>
>>>> Cc: Peter Maydell <peter.maydell@linaro.org>
>>>>
>>>> Cc: Eduardo Habkost <ehabkost@redhat.com>
>>>> Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>>>>
>>>> The following changes since commit 7edd8e4660beb301d527257f8e04ebec0f841cb0:
>>>>
>>>>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2015-07-06 14:03:44 +0100)
>>>>
>>>> are available in the git repository at:
>>>>
>>>>   git://github.com/afaerber/qemu-cpu.git tags/qom-cpu-for-peter
>>>>
>>>> for you to fetch changes up to 116382f1504d655a1afdf3eac18d276a200428b7:
>>>>
>>>>   disas: cris: QOMify target specific disas setup (2015-07-06 22:36:17 +0200)
>>>>
>>>> ----------------------------------------------------------------
>>>> QOM CPUState and X86CPU
>>>>
>>>> * Further QOM'ification of CPU initialization
>>>> * Propagation of CPUState arguments and elimination of ENV_GET_CPU() usage
>>>> * cpu_set_pc() abstraction
>>>> * CPUClass::disas_set_info() hook
>>>>
>>>> ----------------------------------------------------------------
>>> [...]
>>>
>>> Self-nack, hurry is never good:
>>>
>>>   /aarch64/qom/xlnx-ep108:
>>> qemu-system-aarch64: Trying to use more CPUs than allowed max of 1
>>> Broken pipe
>>> FAIL
>>>
>>> Peter C., any ideas why this is regressing?
>>>
>>
>> This:
>>
>> +    if (cpu >= max_cpus) {
>> +        error_setg(errp, "Trying to use more CPUs than allowed max of %d\n",
>> +                    max_cpus);
>> +        return -1;
>>
>> xlnx-ep108 doesn't care about the -smp argument, it creates all 6 CPUs
>> regardless of -smp. This is because the number of CPUs is not flexible
>> in reality. It is also a heterogeneous arch (with R5s abd A53s) so
>> trying to limit the grand total of CPUs is ambiguous (do you remove
>> a53s or r5s for -smp < 6?).
>>
>> Can this check be dropped or is this a bug in xlnx where we should
>> overcome by just forcing smp_cpus = 6 at machine level?
>
> That check is needed to fail CPU realization when an attempt is made
> to relialize (eg. via hotplug) more than allowed max number of CPUs.
>

What was the behaviour before this patch series for this case? I can't
see any check in original code.  had another read of your commit
messages. It seems the main purpose of your change is to ensure CPU
indicies are unique rather than within any limits so this new check is
secondary to what you were trying to do. Can we just drop it?

Regards,
Peter

> Regards,
> Bharata.
>

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

end of thread, other threads:[~2015-07-07  4:14 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-06 23:13 [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 01/22] cpu: No need to zero-initialize CPUState::numa_node Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 02/22] cpu: Initialize breakpoint/watchpoint lists in cpu_common_initfn() Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 03/22] cpu: Reorder cpu->as, cpu->thread_id, cpu->memory_dispatch init Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 04/22] cpu: Add Error argument to cpu_exec_init() Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 05/22] cpu: Convert cpu_index into a bitmap Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 06/22] target-ppc: Move cpu_exec_init() call to realize function Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 07/22] translate-all: Change tb_flush() env argument to cpu Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 08/22] gdbstub: Change gdbserver_fork() to accept cpu instead of env Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 09/22] cpu: Change tcg_cpu_exec() arg to cpu, not env Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 10/22] cpu: Change cpu_exec_init() " Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 11/22] cpu-exec: Purge all uses of ENV_GET_CPU() Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 12/22] cpu: Add wrapper for the set_pc() hook Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 13/22] gdbstub: Use cpu_set_pc() helper Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 14/22] hw/arm/boot: Use cpu_set_pc() Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 15/22] microblaze: boot: " Andreas Färber
2015-07-06 23:13 ` [Qemu-devel] [PULL 16/22] disas: Add print_insn to disassemble info Andreas Färber
2015-07-06 23:14 ` [Qemu-devel] [PULL 17/22] disas: QOMify target specific setup Andreas Färber
2015-07-06 23:14 ` [Qemu-devel] [PULL 18/22] disas: arm-a64: Make printfer and stream variable Andreas Färber
2015-07-06 23:14 ` [Qemu-devel] [PULL 19/22] disas: arm: QOMify target specific disas setup Andreas Färber
2015-07-06 23:14 ` [Qemu-devel] [PULL 20/22] disas: microblaze: " Andreas Färber
2015-07-06 23:14 ` [Qemu-devel] [PULL 21/22] disas: cris: Fix 0 buffer length case Andreas Färber
2015-07-06 23:14 ` [Qemu-devel] [PULL 22/22] disas: cris: QOMify target specific disas setup Andreas Färber
2015-07-07  0:24 ` [Qemu-devel] [PULL 00/22] QOM CPUState patch queue 2015-07-06 Andreas Färber
2015-07-07  2:25   ` Peter Crosthwaite
2015-07-07  3:56     ` Bharata B Rao
2015-07-07  4:14       ` Peter Crosthwaite
2015-07-07  4:07     ` Peter Crosthwaite

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.