target/riscv/cpu.c: duct tape fix for QMP + RV profiles introspection
PATCH 1/1 target/riscv/cpu.c: duct tape fix for QMP + RV profiles introspection
Maruks reported in [1] a problem with QMP introspection with qemu-system-riscv64 that happens after querying a profile CPU. QEMU crashes hitting an abort during satp_mode logic that, somehow, is being triggered via profile code.
For every profile CPU that goes through init we're setting an 'enabled' flag in the static RISCVProfile object. This sounded like an okay idea back when profiles were introduced, but now we've realized that QMP will querying CPUs without exiting the QEMU process while also going multiple times through cpu_init() and friends. The result is that we're in a situation where we have runtime information being stored in static arrays that persists between CPU definitions being introspected.
A proper fix is to get rid of profile->enabled and turn profiles into cpu->cfg flags like we do with every other extension. Unfortunately we've been using profile->enabled for lots of things and a redesign would be in order, one which I'm not comfortable doing right now - we're too close to the QEMU 11.2 code freeze for such a change.
For now let's silver tape a fix in cpu_init() to reset profile->enabled for all available profiles. We'll do a proper redesign in the next release cycle.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
--- target/riscv/cpu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
target/riscv/cpu.c +19 -0
@@ -1550,6 +1550,25 @@ static void riscv_cpu_init(Object *obj) cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; cpu->cfg.max_satp_mode =-1 ; +/* +* The way we're handling profiles does not cope well with QMP +* instropection. We have a static array that stores RISCVCPUProfiles +* objs that hold runtime state for the lifetime of the QEMU process. +* Thus setting profile->enabled once, e.g. when instropecting a +* profile CPU, will leave the flag set for subsequent intropections. +* +* For now, clear all 'enabled' flags to avoid misleading QMP w.r.t +* profiles being set. +* +* FIXME: a better long term solution is to remove profile->enabled +* and just use regular cpu->cfg flags, avoiding static variables +* storing dynamic state. This will help us not only with QMP but +* also single-binary support. +*/ +for (int i =0 ; riscv_profiles[i] !=NULL ; i++) { + riscv_profiles[i]->enabled = false; + } +if (mcc->def->profile) { mcc->def->profile->enabled = true; }
Signature · 1 line
2.43.0
Quoted 28 lines · Daniel Henrique Barboza
Maruks reported in [1] a problem with QMP introspection with qemu-system-riscv64 that happens after querying a profile CPU. QEMU crashes hitting an abort during
satp_modelogic that, somehow, is being
triggered via profile code.For every profile CPU that goes through init we're setting an 'enabled'
flag in the static RISCVProfile object. This sounded like an okay idea
back when profiles were introduced, but now we've realized that QMP will
querying CPUs without exiting the QEMU process while also going multiple
times throughcpu_init()and friends. The result is that we're in a situation where we have runtime information being stored in static arrays
that persists between CPU definitions being introspected.A proper fix is to get rid of
profile->enabledand turn profiles intocpu->cfgflags like we do with every other extension. Unfortunately we've been usingprofile->enabledfor lots of things and a redesign would be in order, one which I'm not comfortable doing right now - we're
too close to the QEMU 11.2 code freeze for such a change.For now let's silver tape a fix in
cpu_init()to reset profile-Quoted 1 line
enabled
Quoted 8 lines
for all available profiles. We'll do a proper redesign in the next release cycle.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Reported-by Markus Armbruster <[email protected]>Signed-off-by Daniel Henrique Barboza
Alistair
Quoted 41 lines
---
target/riscv/cpu.c | 19 +++++++++++++++++++1 file changed, 19 insertions(+)target/riscv/cpu.c +0
-0@@ -1550,6 +1550,25 @@ static void riscv_cpu_init(Object *obj) cpu->env.vext_ver = VEXT_VERSION_1_00_0; cpu->cfg.max_satp_mode = -1;
+ /*
+ * The way we're handling profiles does not cope well with QMP + * instropection. We have a static array that stores RISCVCPUProfiles
+ * objs that hold runtime state for the lifetime of the QEMU process.
+ * Thus settingprofile->enabledonce, e.g. when instropecting a + * profile CPU, will leave the flag set for subsequent intropections.
+ *
+ * For now, clear all 'enabled' flags to avoid misleading QMP w.r.t
+ * profiles being set.
+ *
+ * FIXME: a better long term solution is to remove profile-Quoted 1 line
enabled
+ * and just use regular
cpu->cfgflags, avoiding static variables
+ * storing dynamic state. This will help us not only with QMP but
+ * also single-binary support.
+ */
+ for (int i = 0; riscv_profiles[i] != NULL; i++) {
+ riscv_profiles[i]->enabled = false;
+ }
+
if (mcc->def->profile) {
mcc->def->profile->enabled= true;
}
Alistair Francis
AppliedQuoted 28 lines · Daniel Henrique Barboza
Maruks reported in [1] a problem with QMP introspection with qemu-system-riscv64 that happens after querying a profile CPU. QEMU crashes hitting an abort during
satp_modelogic that, somehow, is being
triggered via profile code.For every profile CPU that goes through init we're setting an 'enabled'
flag in the static RISCVProfile object. This sounded like an okay idea
back when profiles were introduced, but now we've realized that QMP will
querying CPUs without exiting the QEMU process while also going multiple
times throughcpu_init()and friends. The result is that we're in a situation where we have runtime information being stored in static arrays
that persists between CPU definitions being introspected.A proper fix is to get rid of
profile->enabledand turn profiles intocpu->cfgflags like we do with every other extension. Unfortunately we've been usingprofile->enabledfor lots of things and a redesign would be in order, one which I'm not comfortable doing right now - we're
too close to the QEMU 11.2 code freeze for such a change.For now let's silver tape a fix in
cpu_init()to reset profile-Quoted 1 line
enabled
Quoted 8 lines
for all available profiles. We'll do a proper redesign in the next release cycle.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Reported-by Markus Armbruster <[email protected]>Signed-off-by Daniel Henrique Barboza
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 41 lines
---
target/riscv/cpu.c | 19 +++++++++++++++++++1 file changed, 19 insertions(+)target/riscv/cpu.c +0
-0@@ -1550,6 +1550,25 @@ static void riscv_cpu_init(Object *obj) cpu->env.vext_ver = VEXT_VERSION_1_00_0; cpu->cfg.max_satp_mode = -1;
+ /*
+ * The way we're handling profiles does not cope well with QMP + * instropection. We have a static array that stores RISCVCPUProfiles
+ * objs that hold runtime state for the lifetime of the QEMU process.
+ * Thus settingprofile->enabledonce, e.g. when instropecting a + * profile CPU, will leave the flag set for subsequent intropections.
+ *
+ * For now, clear all 'enabled' flags to avoid misleading QMP w.r.t
+ * profiles being set.
+ *
+ * FIXME: a better long term solution is to remove profile-Quoted 1 line
enabled
+ * and just use regular
cpu->cfgflags, avoiding static variables
+ * storing dynamic state. This will help us not only with QMP but
+ * also single-binary support.
+ */
+ for (int i = 0; riscv_profiles[i] != NULL; i++) {
+ riscv_profiles[i]->enabled = false;
+ }
+
if (mcc->def->profile) {
mcc->def->profile->enabled= true;
}
Quoted 19 lines · Daniel Henrique Barboza
Maruks reported in [1] a problem with QMP introspection with qemu-system-riscv64 that happens after querying a profile CPU. QEMU crashes hitting an abort during
satp_modelogic that, somehow, is being triggered via profile code.For every profile CPU that goes through init we're setting an 'enabled' flag in the static RISCVProfile object. This sounded like an okay idea back when profiles were introduced, but now we've realized that QMP will querying CPUs without exiting the QEMU process while also going multiple times through
cpu_init()and friends. The result is that we're in a situation where we have runtime information being stored in static arrays that persists between CPU definitions being introspected.A proper fix is to get rid of
profile->enabledand turn profiles intocpu->cfgflags like we do with every other extension. Unfortunately we've been usingprofile->enabledfor lots of things and a redesign would be in order, one which I'm not comfortable doing right now - we're too close to the QEMU 11.2 code freeze for such a change.
Quoted 8 lines
For now let's silver tape a fix in
cpu_init()to resetprofile->enabledfor all available profiles. We'll do a proper redesign in the next release cycle.[1] https://lore.kernel.org/qemu-devel/[email protected]/
Reported-by Markus Armbruster <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>
That was quick, thank you!
Quoted 3 lines · Markus Armbruster
Quoted 1 line · Daniel Henrique Barboza
Maruks reported in [1] a problem with QMP introspection with
Just now noticed the typo :D
Alistair, can you fix it in-tree or should I re-send? Thanks,
Daniel
Quoted 31 lines
Quoted 18 lines
qemu-system-riscv64 that happens after querying a profile CPU. QEMU crashes hitting an abort during
satp_modelogic that, somehow, is being triggered via profile code.For every profile CPU that goes through init we're setting an 'enabled' flag in the static RISCVProfile object. This sounded like an okay idea back when profiles were introduced, but now we've realized that QMP will querying CPUs without exiting the QEMU process while also going multiple times through
cpu_init()and friends. The result is that we're in a situation where we have runtime information being stored in static arrays that persists between CPU definitions being introspected.A proper fix is to get rid of
profile->enabledand turn profiles intocpu->cfgflags like we do with every other extension. Unfortunately we've been usingprofile->enabledfor lots of things and a redesign would be in order, one which I'm not comfortable doing right now - we're too close to the QEMU 11.2 code freeze for such a change.Quoted 8 lines
For now let's silver tape a fix in
cpu_init()to resetprofile->enabledfor all available profiles. We'll do a proper redesign in the next release cycle.[1] https://lore.kernel.org/qemu-devel/[email protected]/
Reported-by Markus Armbruster <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>That was quick, thank you!
Tested-by Markus Armbruster <[email protected]>
Quoted 11 lines · Daniel Henrique Barboza
Quoted 3 lines · Markus Armbruster
Quoted 1 line · Daniel Henrique Barboza
Maruks reported in [1] a problem with QMP introspection with
Just now noticed the typo :D
Alistair, can you fix it in-tree or should I re-send? Thanks,
Fixed it on my side
Alistair
Quoted 51 lines
Daniel
Quoted 47 lines
Quoted 36 lines
qemu-system-riscv64 that happens after querying a profile CPU. QEMU
crashes hitting an abort duringsatp_modelogic that, somehow, is being
triggered via profile code.For every profile CPU that goes through init we're setting an 'enabled'
flag in the static RISCVProfile object. This sounded like an okay idea
back when profiles were introduced, but now we've realized that QMP will
querying CPUs without exiting the QEMU process while also going multiple
times throughcpu_init()and friends. The result is that we're in a
situation where we have runtime information being stored in static arrays
that persists between CPU definitions being introspected.A proper fix is to get rid of
profile->enabledand turn profiles intocpu->cfgflags like we do with every other extension. Unfortunately
we've been usingprofile->enabledfor lots of things and a redesign
would be in order, one which I'm not comfortable doing right now
- we're
too close to the QEMU 11.2 code freeze for such a change.For now let's silver tape a fix in
cpu_init()to reset profile-Quoted 1 line
enabled
for all available profiles. We'll do a proper redesign in the next
release cycle.Quoted 6 lines
[1]
https://lore.kernel.org/qemu-devel/[email protected]/Reported-by Markus Armbruster <[email protected]>Signed-off-by Daniel Henrique BarbozaThat was quick, thank you!
Tested-by Markus Armbruster <[email protected]>