From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Thomas Huth" <thuth@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"John Snow" <jsnow@redhat.com>,
"Jose R . Ziviani" <jziviani@suse.de>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH-for-6.2 2/2] hw/display: Do not allow multiple identical VGA devices
Date: Thu, 18 Nov 2021 20:20:20 +0100 [thread overview]
Message-ID: <20211118192020.61245-3-philmd@redhat.com> (raw)
In-Reply-To: <20211118192020.61245-1-philmd@redhat.com>
vga_common_init() create a MemoryRegion named "vga.vram",
used as a singleton for the device class. When creating
the same device type multiple times, we get:
$ qemu-system-mips64 -M pica61 -device isa-cirrus-vga
RAMBlock "vga.vram" already registered, abort!
Aborted (core dumped)
Commit 7852a77f598 ("vga: don't abort when adding a duplicate
isa-vga device") added a check for a single device, generalize
it to all VGA devices which call vga_common_init():
$ qemu-system-mips64 -M pica61 -device isa-cirrus-vga
qemu-system-mips64: -device isa-cirrus-vga: at most one isa-cirrus-vga device is permitted
Reported-by: John Snow <jsnow@redhat.com>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/44
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
hw/display/vga-isa.c | 9 ---------
hw/display/vga.c | 13 +++++++++++++
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/hw/display/vga-isa.c b/hw/display/vga-isa.c
index 2782012196a..b930c8d2667 100644
--- a/hw/display/vga-isa.c
+++ b/hw/display/vga-isa.c
@@ -62,15 +62,6 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
MemoryRegion *vga_io_memory;
const MemoryRegionPortio *vga_ports, *vbe_ports;
- /*
- * make sure this device is not being added twice, if so
- * exit without crashing qemu
- */
- if (object_resolve_path_type("", TYPE_ISA_VGA, NULL)) {
- error_setg(errp, "at most one %s device is permitted", TYPE_ISA_VGA);
- return;
- }
-
s->global_vmstate = true;
if (!vga_common_init(s, OBJECT(dev), errp)) {
return;
diff --git a/hw/display/vga.c b/hw/display/vga.c
index a6759c7e934..8f0d5cc9019 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -2172,6 +2172,19 @@ bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
{
int i, j, v, b;
+ if (obj) {
+ const char *typename = object_get_typename(obj);
+
+ /*
+ * make sure this device is not being added twice,
+ * if so exit without crashing qemu
+ */
+ if (object_resolve_path_type("", typename, NULL)) {
+ error_setg(errp, "at most one %s device is permitted", typename);
+ return false;
+ }
+ }
+
for(i = 0;i < 256; i++) {
v = 0;
for(j = 0; j < 8; j++) {
--
2.31.1
next prev parent reply other threads:[~2021-11-18 19:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 19:20 [PATCH-for-6.2 0/2] hw/display: Do not allow multiple (identical) VGA devices Philippe Mathieu-Daudé
2021-11-18 19:20 ` [PATCH-for-6.2 1/2] hw/display: Add Error* handle to vga_common_init() Philippe Mathieu-Daudé
2021-11-18 19:20 ` Philippe Mathieu-Daudé [this message]
2021-11-19 9:20 ` [PATCH-for-6.2 2/2] hw/display: Do not allow multiple identical VGA devices Paolo Bonzini
2021-11-19 9:42 ` Philippe Mathieu-Daudé
2021-11-19 10:10 ` Daniel P. Berrangé
2021-11-19 8:21 ` [PATCH-for-6.2 0/2] hw/display: Do not allow multiple (identical) " Mark Cave-Ayland
2021-11-19 9:49 ` Philippe Mathieu-Daudé
2021-11-19 9:58 ` Thomas Huth
2021-11-19 10:17 ` Philippe Mathieu-Daudé
2021-11-19 11:10 ` Thomas Huth
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=20211118192020.61245-3-philmd@redhat.com \
--to=philmd@redhat.com \
--cc=jsnow@redhat.com \
--cc=jziviani@suse.de \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.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).