From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Bernhard Beschow" <shentey@gmail.com>,
"Hervé Poussineau" <hpoussin@reactos.org>,
"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
qemu-ppc@nongnu.org, "Titus Rwantare" <titusr@google.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Peter Maydell" <peter.maydell@linaro.org>
Subject: [PATCH 1/3] hw/mips/jazz: Fix modifying QOM class internal state from instance
Date: Tue, 23 May 2023 08:44:06 +0200 [thread overview]
Message-ID: <20230523064408.57941-2-philmd@linaro.org> (raw)
In-Reply-To: <20230523064408.57941-1-philmd@linaro.org>
QOM object instance should not modify its class state (because
all other objects instanciated from this class get affected).
Instead of modifying the MIPSCPUClass 'no_data_aborts' field
in the instance machine_init() handler, set it in the machine
class_init handler. Since 2 machines require this, share the
common code in a new machine_class_ignore_data_abort() helper.
Inspired-by: Bernhard Beschow <shentey@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/mips/jazz.c | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index ca4426a92c..de2e827bf8 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -128,7 +128,6 @@ static void mips_jazz_init(MachineState *machine,
int bios_size, n, big_endian;
Clock *cpuclk;
MIPSCPU *cpu;
- MIPSCPUClass *mcc;
CPUMIPSState *env;
qemu_irq *i8259;
rc4030_dma *dmas;
@@ -177,23 +176,6 @@ static void mips_jazz_init(MachineState *machine,
env = &cpu->env;
qemu_register_reset(main_cpu_reset, cpu);
- /*
- * Chipset returns 0 in invalid reads and do not raise data exceptions.
- * However, we can't simply add a global memory region to catch
- * everything, as this would make all accesses including instruction
- * accesses be ignored and not raise exceptions.
- *
- * NOTE: this behaviour of raising exceptions for bad instruction
- * fetches but not bad data accesses was added in commit 54e755588cf1e9
- * to restore behaviour broken by c658b94f6e8c206, but it is not clear
- * whether the real hardware behaves this way. It is possible that
- * real hardware ignores bad instruction fetches as well -- if so then
- * we could replace this hijacking of CPU methods with a simple global
- * memory region that catches all memory accesses, as we do on Malta.
- */
- mcc = MIPS_CPU_GET_CLASS(cpu);
- mcc->no_data_aborts = true;
-
/* allocate RAM */
memory_region_add_subregion(address_space, 0, machine->ram);
@@ -414,6 +396,27 @@ void mips_pica61_init(MachineState *machine)
mips_jazz_init(machine, JAZZ_PICA61);
}
+static void machine_class_ignore_data_abort(MachineClass *mc)
+{
+ MIPSCPUClass *mcc = MIPS_CPU_CLASS(mc);
+
+ /*
+ * Chipset returns 0 in invalid reads and do not raise data exceptions.
+ * However, we can't simply add a global memory region to catch
+ * everything, as this would make all accesses including instruction
+ * accesses be ignored and not raise exceptions.
+ *
+ * NOTE: this behaviour of raising exceptions for bad instruction
+ * fetches but not bad data accesses was added in commit 54e755588cf1e9
+ * to restore behaviour broken by c658b94f6e8c206, but it is not clear
+ * whether the real hardware behaves this way. It is possible that
+ * real hardware ignores bad instruction fetches as well -- if so then
+ * we could replace this hijacking of CPU methods with a simple global
+ * memory region that catches all memory accesses, as we do on Malta.
+ */
+ mcc->no_data_aborts = true;
+}
+
static void mips_magnum_class_init(ObjectClass *oc, void *data)
{
MachineClass *mc = MACHINE_CLASS(oc);
@@ -423,6 +426,7 @@ static void mips_magnum_class_init(ObjectClass *oc, void *data)
mc->block_default_type = IF_SCSI;
mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
mc->default_ram_id = "mips_jazz.ram";
+ machine_class_ignore_data_abort(mc);
}
static const TypeInfo mips_magnum_type = {
@@ -440,6 +444,7 @@ static void mips_pica61_class_init(ObjectClass *oc, void *data)
mc->block_default_type = IF_SCSI;
mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
mc->default_ram_id = "mips_jazz.ram";
+ machine_class_ignore_data_abort(mc);
}
static const TypeInfo mips_pica61_type = {
--
2.38.1
next prev parent reply other threads:[~2023-05-23 6:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 6:44 [PATCH 0/3] hw: Fix abuse of QOM class internals modified by their instances Philippe Mathieu-Daudé
2023-05-23 6:44 ` Philippe Mathieu-Daudé [this message]
2023-05-23 18:26 ` [PATCH 1/3] hw/mips/jazz: Fix modifying QOM class internal state from instance Richard Henderson
2023-05-23 6:44 ` [PATCH 2/3] hw/ppc/e500plat: " Philippe Mathieu-Daudé
2023-05-23 9:03 ` Alexander Graf
2023-05-23 18:29 ` Richard Henderson
2023-05-23 6:44 ` [PATCH 3/3] hw/i2c/pmbus_device: Fix modifying QOM class internals " Philippe Mathieu-Daudé
2023-05-23 18:30 ` Richard Henderson
2023-05-23 7:10 ` [PATCH 0/3] hw: Fix abuse of QOM class internals modified by their instances Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230523064408.57941-2-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=aleksandar.rikalo@syrmia.com \
--cc=hpoussin@reactos.org \
--cc=jiaxun.yang@flygoat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=shentey@gmail.com \
--cc=titusr@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).