Re: [PATCH v6 12/16] cpus: add handle_interrupt to the CpusAccel interface

2020-09-01 Thread Richard Henderson
On 9/1/20 12:21 AM, Claudio Fontana wrote:
> kvm: uses the generic handler
> qtest: uses the generic handler
> whpx: changed to use the generic handler (identical implementation)
> hax: changed to use the generic handler (identical implementation)
> hvf: changed to use the generic handler (identical implementation)
> tcg: adapt tcg-cpus to point to the tcg-specific handler
> 
> Signed-off-by: Claudio Fontana 
> ---
>  accel/tcg/tcg-all.c| 26 --
>  accel/tcg/tcg-cpus.c   | 28 
>  hw/core/cpu.c  | 13 -
>  include/hw/core/cpu.h  | 14 --
>  include/sysemu/cpus.h  |  2 ++
>  softmmu/cpus.c | 18 ++
>  target/i386/hax-all.c  | 10 --
>  target/i386/hvf/hvf.c  |  9 -
>  target/i386/whpx-all.c | 10 --
>  9 files changed, 48 insertions(+), 82 deletions(-)

Reviewed-by: Richard Henderson 

r~





Re: [PATCH v6 12/16] cpus: add handle_interrupt to the CpusAccel interface

2020-09-01 Thread Claudio Fontana
On 9/1/20 11:38 AM, Roman Bolshakov wrote:
> On Tue, Sep 01, 2020 at 09:21:57AM +0200, Claudio Fontana wrote:
>> kvm: uses the generic handler
>> qtest: uses the generic handler
>> whpx: changed to use the generic handler (identical implementation)
>> hax: changed to use the generic handler (identical implementation)
>> hvf: changed to use the generic handler (identical implementation)
>> tcg: adapt tcg-cpus to point to the tcg-specific handler
>>
>> Signed-off-by: Claudio Fontana 
>> ---
>>  accel/tcg/tcg-all.c| 26 --
>>  accel/tcg/tcg-cpus.c   | 28 
>>  hw/core/cpu.c  | 13 -
>>  include/hw/core/cpu.h  | 14 --
>>  include/sysemu/cpus.h  |  2 ++
>>  softmmu/cpus.c | 18 ++
>>  target/i386/hax-all.c  | 10 --
>>  target/i386/hvf/hvf.c  |  9 -
>>  target/i386/whpx-all.c | 10 --
>>  9 files changed, 48 insertions(+), 82 deletions(-)
>>
>> diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
>> index 01957b130d..af9bf5c5bb 100644
>> --- a/accel/tcg/tcg-all.c
>> +++ b/accel/tcg/tcg-all.c
>> @@ -47,31 +47,6 @@ typedef struct TCGState {
>>  #define TCG_STATE(obj) \
>>  OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)
>>  
>> -/* mask must never be zero, except for A20 change call */
>> -static void tcg_handle_interrupt(CPUState *cpu, int mask)
>> -{
>> -int old_mask;
>> -g_assert(qemu_mutex_iothread_locked());
>> -
>> -old_mask = cpu->interrupt_request;
>> -cpu->interrupt_request |= mask;
>> -
>> -/*
>> - * If called from iothread context, wake the target cpu in
>> - * case its halted.
>> - */
>> -if (!qemu_cpu_is_self(cpu)) {
>> -qemu_cpu_kick(cpu);
>> -} else {
>> -atomic_set(_neg(cpu)->icount_decr.u16.high, -1);
>> -if (icount_enabled() &&
>> -!cpu->can_do_io
>> -&& (mask & ~old_mask) != 0) {
>> -cpu_abort(cpu, "Raised interrupt while not in I/O function");
>> -}
>> -}
>> -}
>> -
>>  /*
>>   * We default to false if we know other options have been enabled
>>   * which are currently incompatible with MTTCG. Otherwise when each
>> @@ -128,7 +103,6 @@ static int tcg_init(MachineState *ms)
>>  TCGState *s = TCG_STATE(current_accel());
>>  
>>  tcg_exec_init(s->tb_size * 1024 * 1024);
>> -cpu_interrupt_handler = tcg_handle_interrupt;
>>  mttcg_enabled = s->mttcg_enabled;
>>  cpus_register_accel(_cpus);
>>  
>> diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
>> index 72696f6d86..2bb209e2c6 100644
>> --- a/accel/tcg/tcg-cpus.c
>> +++ b/accel/tcg/tcg-cpus.c
>> @@ -533,9 +533,37 @@ static int64_t tcg_get_elapsed_ticks(void)
>>  return cpu_get_ticks();
>>  }
>>  
>> +/* mask must never be zero, except for A20 change call */
>> +static void tcg_handle_interrupt(CPUState *cpu, int mask)
>> +{
>> +int old_mask;
>> +g_assert(qemu_mutex_iothread_locked());
>> +
>> +old_mask = cpu->interrupt_request;
>> +cpu->interrupt_request |= mask;
>> +
>> +/*
>> + * If called from iothread context, wake the target cpu in
>> + * case its halted.
>> + */
>> +if (!qemu_cpu_is_self(cpu)) {
>> +qemu_cpu_kick(cpu);
>> +} else {
>> +atomic_set(_neg(cpu)->icount_decr.u16.high, -1);
>> +if (icount_enabled() &&
>> +!cpu->can_do_io
>> +&& (mask & ~old_mask) != 0) {
>> +cpu_abort(cpu, "Raised interrupt while not in I/O function");
>> +}
>> +}
>> +}
>> +
>>  const CpusAccel tcg_cpus = {
>>  .create_vcpu_thread = tcg_start_vcpu_thread,
>>  .kick_vcpu_thread = tcg_kick_vcpu_thread,
>> +
>> +.handle_interrupt = tcg_handle_interrupt,
>> +
>>  .get_virtual_clock = tcg_get_virtual_clock,
>>  .get_elapsed_ticks = tcg_get_elapsed_ticks,
>>  };
>> diff --git a/hw/core/cpu.c b/hw/core/cpu.c
>> index fa8602493b..451b3d5ee7 100644
>> --- a/hw/core/cpu.c
>> +++ b/hw/core/cpu.c
>> @@ -35,8 +35,6 @@
>>  #include "qemu/plugin.h"
>>  #include "sysemu/hw_accel.h"
>>  
>> -CPUInterruptHandler cpu_interrupt_handler;
>> -
>>  CPUState *cpu_by_arch_id(int64_t id)
>>  {
>>  CPUState *cpu;
>> @@ -394,17 +392,6 @@ static vaddr cpu_adjust_watchpoint_address(CPUState 
>> *cpu, vaddr addr, int len)
>>  return addr;
>>  }
>>  
>> -static void generic_handle_interrupt(CPUState *cpu, int mask)
>> -{
>> -cpu->interrupt_request |= mask;
>> -
>> -if (!qemu_cpu_is_self(cpu)) {
>> -qemu_cpu_kick(cpu);
>> -}
>> -}
>> -
>> -CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
>> -
>>  static void cpu_class_init(ObjectClass *klass, void *data)
>>  {
>>  DeviceClass *dc = DEVICE_CLASS(klass);
>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
>> index 8f145733ce..efd33d87fd 100644
>> --- a/include/hw/core/cpu.h
>> +++ b/include/hw/core/cpu.h
>> @@ -838,12 +838,6 @@ bool cpu_exists(int64_t id);
>>   */
>>  CPUState 

Re: [PATCH v6 12/16] cpus: add handle_interrupt to the CpusAccel interface

2020-09-01 Thread Roman Bolshakov
On Tue, Sep 01, 2020 at 09:21:57AM +0200, Claudio Fontana wrote:
> kvm: uses the generic handler
> qtest: uses the generic handler
> whpx: changed to use the generic handler (identical implementation)
> hax: changed to use the generic handler (identical implementation)
> hvf: changed to use the generic handler (identical implementation)
> tcg: adapt tcg-cpus to point to the tcg-specific handler
> 
> Signed-off-by: Claudio Fontana 
> ---
>  accel/tcg/tcg-all.c| 26 --
>  accel/tcg/tcg-cpus.c   | 28 
>  hw/core/cpu.c  | 13 -
>  include/hw/core/cpu.h  | 14 --
>  include/sysemu/cpus.h  |  2 ++
>  softmmu/cpus.c | 18 ++
>  target/i386/hax-all.c  | 10 --
>  target/i386/hvf/hvf.c  |  9 -
>  target/i386/whpx-all.c | 10 --
>  9 files changed, 48 insertions(+), 82 deletions(-)
> 
> diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
> index 01957b130d..af9bf5c5bb 100644
> --- a/accel/tcg/tcg-all.c
> +++ b/accel/tcg/tcg-all.c
> @@ -47,31 +47,6 @@ typedef struct TCGState {
>  #define TCG_STATE(obj) \
>  OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)
>  
> -/* mask must never be zero, except for A20 change call */
> -static void tcg_handle_interrupt(CPUState *cpu, int mask)
> -{
> -int old_mask;
> -g_assert(qemu_mutex_iothread_locked());
> -
> -old_mask = cpu->interrupt_request;
> -cpu->interrupt_request |= mask;
> -
> -/*
> - * If called from iothread context, wake the target cpu in
> - * case its halted.
> - */
> -if (!qemu_cpu_is_self(cpu)) {
> -qemu_cpu_kick(cpu);
> -} else {
> -atomic_set(_neg(cpu)->icount_decr.u16.high, -1);
> -if (icount_enabled() &&
> -!cpu->can_do_io
> -&& (mask & ~old_mask) != 0) {
> -cpu_abort(cpu, "Raised interrupt while not in I/O function");
> -}
> -}
> -}
> -
>  /*
>   * We default to false if we know other options have been enabled
>   * which are currently incompatible with MTTCG. Otherwise when each
> @@ -128,7 +103,6 @@ static int tcg_init(MachineState *ms)
>  TCGState *s = TCG_STATE(current_accel());
>  
>  tcg_exec_init(s->tb_size * 1024 * 1024);
> -cpu_interrupt_handler = tcg_handle_interrupt;
>  mttcg_enabled = s->mttcg_enabled;
>  cpus_register_accel(_cpus);
>  
> diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
> index 72696f6d86..2bb209e2c6 100644
> --- a/accel/tcg/tcg-cpus.c
> +++ b/accel/tcg/tcg-cpus.c
> @@ -533,9 +533,37 @@ static int64_t tcg_get_elapsed_ticks(void)
>  return cpu_get_ticks();
>  }
>  
> +/* mask must never be zero, except for A20 change call */
> +static void tcg_handle_interrupt(CPUState *cpu, int mask)
> +{
> +int old_mask;
> +g_assert(qemu_mutex_iothread_locked());
> +
> +old_mask = cpu->interrupt_request;
> +cpu->interrupt_request |= mask;
> +
> +/*
> + * If called from iothread context, wake the target cpu in
> + * case its halted.
> + */
> +if (!qemu_cpu_is_self(cpu)) {
> +qemu_cpu_kick(cpu);
> +} else {
> +atomic_set(_neg(cpu)->icount_decr.u16.high, -1);
> +if (icount_enabled() &&
> +!cpu->can_do_io
> +&& (mask & ~old_mask) != 0) {
> +cpu_abort(cpu, "Raised interrupt while not in I/O function");
> +}
> +}
> +}
> +
>  const CpusAccel tcg_cpus = {
>  .create_vcpu_thread = tcg_start_vcpu_thread,
>  .kick_vcpu_thread = tcg_kick_vcpu_thread,
> +
> +.handle_interrupt = tcg_handle_interrupt,
> +
>  .get_virtual_clock = tcg_get_virtual_clock,
>  .get_elapsed_ticks = tcg_get_elapsed_ticks,
>  };
> diff --git a/hw/core/cpu.c b/hw/core/cpu.c
> index fa8602493b..451b3d5ee7 100644
> --- a/hw/core/cpu.c
> +++ b/hw/core/cpu.c
> @@ -35,8 +35,6 @@
>  #include "qemu/plugin.h"
>  #include "sysemu/hw_accel.h"
>  
> -CPUInterruptHandler cpu_interrupt_handler;
> -
>  CPUState *cpu_by_arch_id(int64_t id)
>  {
>  CPUState *cpu;
> @@ -394,17 +392,6 @@ static vaddr cpu_adjust_watchpoint_address(CPUState 
> *cpu, vaddr addr, int len)
>  return addr;
>  }
>  
> -static void generic_handle_interrupt(CPUState *cpu, int mask)
> -{
> -cpu->interrupt_request |= mask;
> -
> -if (!qemu_cpu_is_self(cpu)) {
> -qemu_cpu_kick(cpu);
> -}
> -}
> -
> -CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
> -
>  static void cpu_class_init(ObjectClass *klass, void *data)
>  {
>  DeviceClass *dc = DEVICE_CLASS(klass);
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 8f145733ce..efd33d87fd 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -838,12 +838,6 @@ bool cpu_exists(int64_t id);
>   */
>  CPUState *cpu_by_arch_id(int64_t id);
>  
> -#ifndef CONFIG_USER_ONLY
> -
> -typedef void (*CPUInterruptHandler)(CPUState *, int);
> -
> -extern CPUInterruptHandler cpu_interrupt_handler;
> -
>  /**
>   

[PATCH v6 12/16] cpus: add handle_interrupt to the CpusAccel interface

2020-09-01 Thread Claudio Fontana
kvm: uses the generic handler
qtest: uses the generic handler
whpx: changed to use the generic handler (identical implementation)
hax: changed to use the generic handler (identical implementation)
hvf: changed to use the generic handler (identical implementation)
tcg: adapt tcg-cpus to point to the tcg-specific handler

Signed-off-by: Claudio Fontana 
---
 accel/tcg/tcg-all.c| 26 --
 accel/tcg/tcg-cpus.c   | 28 
 hw/core/cpu.c  | 13 -
 include/hw/core/cpu.h  | 14 --
 include/sysemu/cpus.h  |  2 ++
 softmmu/cpus.c | 18 ++
 target/i386/hax-all.c  | 10 --
 target/i386/hvf/hvf.c  |  9 -
 target/i386/whpx-all.c | 10 --
 9 files changed, 48 insertions(+), 82 deletions(-)

diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 01957b130d..af9bf5c5bb 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -47,31 +47,6 @@ typedef struct TCGState {
 #define TCG_STATE(obj) \
 OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)
 
-/* mask must never be zero, except for A20 change call */
-static void tcg_handle_interrupt(CPUState *cpu, int mask)
-{
-int old_mask;
-g_assert(qemu_mutex_iothread_locked());
-
-old_mask = cpu->interrupt_request;
-cpu->interrupt_request |= mask;
-
-/*
- * If called from iothread context, wake the target cpu in
- * case its halted.
- */
-if (!qemu_cpu_is_self(cpu)) {
-qemu_cpu_kick(cpu);
-} else {
-atomic_set(_neg(cpu)->icount_decr.u16.high, -1);
-if (icount_enabled() &&
-!cpu->can_do_io
-&& (mask & ~old_mask) != 0) {
-cpu_abort(cpu, "Raised interrupt while not in I/O function");
-}
-}
-}
-
 /*
  * We default to false if we know other options have been enabled
  * which are currently incompatible with MTTCG. Otherwise when each
@@ -128,7 +103,6 @@ static int tcg_init(MachineState *ms)
 TCGState *s = TCG_STATE(current_accel());
 
 tcg_exec_init(s->tb_size * 1024 * 1024);
-cpu_interrupt_handler = tcg_handle_interrupt;
 mttcg_enabled = s->mttcg_enabled;
 cpus_register_accel(_cpus);
 
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
index 72696f6d86..2bb209e2c6 100644
--- a/accel/tcg/tcg-cpus.c
+++ b/accel/tcg/tcg-cpus.c
@@ -533,9 +533,37 @@ static int64_t tcg_get_elapsed_ticks(void)
 return cpu_get_ticks();
 }
 
+/* mask must never be zero, except for A20 change call */
+static void tcg_handle_interrupt(CPUState *cpu, int mask)
+{
+int old_mask;
+g_assert(qemu_mutex_iothread_locked());
+
+old_mask = cpu->interrupt_request;
+cpu->interrupt_request |= mask;
+
+/*
+ * If called from iothread context, wake the target cpu in
+ * case its halted.
+ */
+if (!qemu_cpu_is_self(cpu)) {
+qemu_cpu_kick(cpu);
+} else {
+atomic_set(_neg(cpu)->icount_decr.u16.high, -1);
+if (icount_enabled() &&
+!cpu->can_do_io
+&& (mask & ~old_mask) != 0) {
+cpu_abort(cpu, "Raised interrupt while not in I/O function");
+}
+}
+}
+
 const CpusAccel tcg_cpus = {
 .create_vcpu_thread = tcg_start_vcpu_thread,
 .kick_vcpu_thread = tcg_kick_vcpu_thread,
+
+.handle_interrupt = tcg_handle_interrupt,
+
 .get_virtual_clock = tcg_get_virtual_clock,
 .get_elapsed_ticks = tcg_get_elapsed_ticks,
 };
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index fa8602493b..451b3d5ee7 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -35,8 +35,6 @@
 #include "qemu/plugin.h"
 #include "sysemu/hw_accel.h"
 
-CPUInterruptHandler cpu_interrupt_handler;
-
 CPUState *cpu_by_arch_id(int64_t id)
 {
 CPUState *cpu;
@@ -394,17 +392,6 @@ static vaddr cpu_adjust_watchpoint_address(CPUState *cpu, 
vaddr addr, int len)
 return addr;
 }
 
-static void generic_handle_interrupt(CPUState *cpu, int mask)
-{
-cpu->interrupt_request |= mask;
-
-if (!qemu_cpu_is_self(cpu)) {
-qemu_cpu_kick(cpu);
-}
-}
-
-CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
-
 static void cpu_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 8f145733ce..efd33d87fd 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -838,12 +838,6 @@ bool cpu_exists(int64_t id);
  */
 CPUState *cpu_by_arch_id(int64_t id);
 
-#ifndef CONFIG_USER_ONLY
-
-typedef void (*CPUInterruptHandler)(CPUState *, int);
-
-extern CPUInterruptHandler cpu_interrupt_handler;
-
 /**
  * cpu_interrupt:
  * @cpu: The CPU to set an interrupt on.
@@ -851,17 +845,9 @@ extern CPUInterruptHandler cpu_interrupt_handler;
  *
  * Invokes the interrupt handler.
  */
-static inline void cpu_interrupt(CPUState *cpu, int mask)
-{
-cpu_interrupt_handler(cpu, mask);
-}
-
-#else /* USER_ONLY */
 
 void cpu_interrupt(CPUState *cpu, int mask);
 
-#endif /*