Skip to contentSkip to conversation

cpus: Remove system reset() API from user emulation

PATCH In review Philippe Mathieu-Daudé 5 participants 10 messages Dec 20, 2022 – Dec 29, 2022 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover cpus: Remove system reset() API from user emulation

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in allowing the user emulation access the sysemu/reset API.

Philippe Mathieu-Daudé (5):
target/i386: Restrict qapi/qapi-events-run-state.h to system emulation target/i386: Restrict sysemu/reset.h to system emulation target/loongarch: Restrict sysemu/reset.h to system emulation target/s390x: Restrict sysemu/reset.h to system emulation hw/core: Only build CPU reset handlers with system emulation

 hw/core/meson.build    | 2 +-
 target/i386/cpu.c      | 2 +-
 target/i386/helper.c   | 2 +-
 target/loongarch/cpu.c | 2 ++
 target/s390x/cpu.c     | 4 +++-
 5 files changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/5 target/i386: Restrict qapi/qapi-events-run-state.h to system emulation

shutdown / powerdown / suspend_disk / resume / watchdog are events irrlevant to user emulation.

---
 target/i386/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/helper.c +1 -1
index 0ac2da066d..dcce27bac1 100644
@@ -18,12 +18,12 @@
  */
 
 #include "qemu/osdep.h"
-#include "qapi/qapi-events-run-state.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "sysemu/runstate.h"
 #include "kvm/kvm_i386.h"
 #ifndef CONFIG_USER_ONLY
+#include "qapi/qapi-events-run-state.h"
 #include "sysemu/hw_accel.h"
 #include "monitor/monitor.h"
 #endif
Signature · 1 line
2.38.1
#2 lore raw

PATCH 2/5 target/i386: Restrict sysemu/reset.h to system emulation

In reply to Philippe Mathieu-Daudé

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in allowing the user emulation access the sysemu/reset API.

---
 target/i386/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +1 -1
index 435980dd3a..91961359c7 100644
@@ -24,7 +24,6 @@
 #include "qemu/hw-version.h"
 #include "cpu.h"
 #include "tcg/helper-tcg.h"
-#include "sysemu/reset.h"
 #include "sysemu/hvf.h"
 #include "kvm/kvm_i386.h"
 #include "sev.h"
@@ -37,6 +36,7 @@
 #ifndef CONFIG_USER_ONLY
 #include "qapi/qapi-commands-machine-target.h"
 #include "exec/address-spaces.h"
+#include "sysemu/reset.h"
 #include "hw/boards.h"
 #include "hw/i386/sgx-epc.h"
 #endif
Signature · 1 line
2.38.1
#3 lore raw

PATCH 3/5 target/loongarch: Restrict sysemu/reset.h to system emulation

In reply to Philippe Mathieu-Daudé

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in allowing the user emulation access the sysemu/reset API.

---
 target/loongarch/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target/loongarch/cpu.c +2 -0
index 0fb853d915..441dfbab74 100644
@@ -16,7 +16,9 @@
 #include "internals.h"
 #include "fpu/softfloat-helpers.h"
 #include "cpu-csr.h"
+#ifndef CONFIG_USER_ONLY
 #include "sysemu/reset.h"
+#endif
 
 const char * const regnames[32] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
Signature · 1 line
2.38.1
#4 lore raw

PATCH 4/5 target/s390x: Restrict sysemu/reset.h to system emulation

In reply to Philippe Mathieu-Daudé

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in allowing the user emulation access the sysemu/reset API.

---
 target/s390x/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
target/s390x/cpu.c +3 -1
index 96562c516d..b10a8541ff 100644
@@ -26,7 +26,6 @@
 #include "s390x-internal.h"
 #include "kvm/kvm_s390x.h"
 #include "sysemu/kvm.h"
-#include "sysemu/reset.h"
 #include "qemu/module.h"
 #include "trace.h"
 #include "qapi/qapi-types-machine.h"
@@ -35,6 +34,9 @@
 #include "fpu/softfloat-helpers.h"
 #include "disas/capstone.h"
 #include "sysemu/tcg.h"
+#ifndef CONFIG_USER_ONLY
+#include "sysemu/reset.h"
+#endif
 
 #define CR0_RESET       0xE0UL
 #define CR14_RESET      0xC2000000UL;
Signature · 1 line
2.38.1
Reviewed-by on v1 4/5
#5 lore raw

Re: [PATCH 4/5] target/s390x: Restrict sysemu/reset.h to system emulation

Quoted 22 lines · Philippe Mathieu-Daudé

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in allowing the user emulation access the sysemu/reset API.

---
  target/s390x/cpu.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
target/s390x/cpu.c +0 -1
index 96562c516d..b10a8541ff 100644
@@ -26,7 +26,6 @@
  #include "s390x-internal.h"
  #include "kvm/kvm_s390x.h"
  #include "sysemu/kvm.h"
-#include "sysemu/reset.h"
  #include "qemu/module.h"
  #include "trace.h"
  #include "qapi/qapi-types-machine.h"

target/s390x/cpu.c line 42

Quoted 9 lines
target/s390x/cpu.c +3 -0
@@ -35,6 +34,9 @@
  #include "fpu/softfloat-helpers.h"
  #include "disas/capstone.h"
  #include "sysemu/tcg.h"
+#ifndef CONFIG_USER_ONLY
+#include "sysemu/reset.h"
+#endif
 
  #define CR0_RESET       0xE0UL
  #define CR14_RESET      0xC2000000UL;
#6 lore raw

PATCH 5/5 hw/core: Only build CPU reset handlers with system emulation

In reply to Philippe Mathieu-Daudé

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in providing the sysemu/reset handlers there.

---
 hw/core/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/meson.build +1 -1
index 7a4d02b6c0..ce6fdb0064 100644
@@ -3,7 +3,6 @@ hwcore_ss.add(files(
   'bus.c',
   'qdev-properties.c',
   'qdev.c',
-  'reset.c',
   'resettable.c',
   'vmstate-if.c',
   # irq.c needed for qdev GPIO handling:
@@ -15,6 +14,7 @@ if have_system
   hwcore_ss.add(files(
     'hotplug.c',
     'qdev-hotplug.c',
+    'reset.c',
   ))
 else
   hwcore_ss.add(files(
Signature · 1 line
2.38.1
#7 lore raw

Re: [PATCH 5/5] hw/core: Only build CPU reset handlers with system emulation

Quoted 4 lines · Philippe Mathieu-Daudé

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in providing the sysemu/reset handlers there.

We do reset the CPU, the linux-user code calls cpu_reset() after creating it (and this is required for correct behaviour). What we don't need (and what this patch is making system-only) is the "register a global reset function" API (which is non-functional in user-mode binaries because nothing ever calls the qemu_devices_reset() function to say "run all the hooks", so it makes sense not to compile it in).

thanks
-- PMM

Reviewed-by on the v1 series
#8 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in allowing the user emulation access the sysemu/reset API.

Philippe Mathieu-Daudé (5):
target/i386: Restrict qapi/qapi-events-run-state.h to system emulation target/i386: Restrict sysemu/reset.h to system emulation target/loongarch: Restrict sysemu/reset.h to system emulation target/s390x: Restrict sysemu/reset.h to system emulation hw/core: Only build CPU reset handlers with system emulation

r~

Reviewed-by on the v1 series
#9 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

In user emulation, threads -- implemented as CPU -- are created/destroyed, but never reset. There is no point in allowing the user emulation access the sysemu/reset API.

Quoted 8 lines

Philippe Mathieu-Daudé (5):
  target/i386: Restrict qapi/qapi-events-run-state.h to system emulation
  target/i386: Restrict sysemu/reset.h to system emulation target/loongarch: Restrict sysemu/reset.h to system emulation target/s390x: Restrict sysemu/reset.h to system emulation hw/core: Only build CPU reset handlers with system emulation

Quoted 7 lines

 hw/core/meson.build    | 2 +-
 target/i386/cpu.c      | 2 +-
 target/i386/helper.c   | 2 +-
 target/loongarch/cpu.c | 2 ++
 target/s390x/cpu.c     | 4 +++-

 5 files changed, 8 insertions(+), 4 deletions(-)