From: Thomas Huth <thuth@redhat.com>
To: Michael Clark <mjc@sifive.com>, qemu-devel@nongnu.org
Cc: Palmer Dabbelt <palmer@sifive.com>,
Sagar Karandikar <sagark@eecs.berkeley.edu>,
Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Subject: [Qemu-devel] [PATCH for-2.12] hw/riscv: Fix crashes with "-nodefaults"
Date: Fri, 23 Mar 2018 09:36:05 +0100 [thread overview]
Message-ID: <1521794165-31678-1-git-send-email-thuth@redhat.com> (raw)
Most of the RISC-V boards currently crash when they are started with
"-nodefaults", e.g.:
$ gdb --args riscv32-softmmu/qemu-system-riscv32 -nodefaults -M sifive_e
[...]
(gdb) r
Program received signal SIGSEGV, Segmentation fault.
qemu_chr_fe_init ([...], s=s@entry=0x0, [...])
at chardev/char-fe.c:210
210 } else if (s->be) {
(gdb) bt
0 0x00005555558695f8 in qemu_chr_fe_init ([...], s=s@entry=0x0, [...])
at chardev/char-fe.c:210
1 0x00005555556fb425 in sifive_uart_create ([...], chr=0x0, [...])
at hw/riscv/sifive_uart.c:169
2 0x00005555556f8cc4 in riscv_sifive_e_init (machine=[...])
at hw/riscv/sifive_e.c:164
[...]
With "-nodefaults" there are no entries in serial_hds[], so qemu_chr_fe_init()
finally tries to dereference a NULL pointer. Let's fix this problem by
creating a "null" chardev in this case instead.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
For other boards / targets, see also:
https://lists.gnu.org/archive/html/qemu-devel/2018-03/msg05073.html
hw/riscv/riscv_htif.c | 5 +++++
hw/riscv/sifive_uart.c | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/hw/riscv/riscv_htif.c b/hw/riscv/riscv_htif.c
index 3e17f30..d3d31ff 100644
--- a/hw/riscv/riscv_htif.c
+++ b/hw/riscv/riscv_htif.c
@@ -245,9 +245,14 @@ HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem,
s->pending_read = 0;
s->allow_tohost = 0;
s->fromhost_inprogress = 0;
+
+ if (!chr) {
+ chr = qemu_chardev_new(NULL, TYPE_CHARDEV_NULL, NULL, &error_abort);
+ }
qemu_chr_fe_init(&s->chr, chr, &error_abort);
qemu_chr_fe_set_handlers(&s->chr, htif_can_recv, htif_recv, htif_event,
htif_be_change, s, NULL, true);
+
if (base) {
memory_region_init_io(&s->mmio, NULL, &htif_mm_ops, s,
TYPE_HTIF_UART, size);
diff --git a/hw/riscv/sifive_uart.c b/hw/riscv/sifive_uart.c
index b0c3798..2bde8bb 100644
--- a/hw/riscv/sifive_uart.c
+++ b/hw/riscv/sifive_uart.c
@@ -166,9 +166,14 @@ SiFiveUARTState *sifive_uart_create(MemoryRegion *address_space, hwaddr base,
{
SiFiveUARTState *s = g_malloc0(sizeof(SiFiveUARTState));
s->irq = irq;
+
+ if (!chr) {
+ chr = qemu_chardev_new(NULL, TYPE_CHARDEV_NULL, NULL, &error_abort);
+ }
qemu_chr_fe_init(&s->chr, chr, &error_abort);
qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx, uart_event,
uart_be_change, s, NULL, true);
+
memory_region_init_io(&s->mmio, NULL, &uart_ops, s,
TYPE_SIFIVE_UART, SIFIVE_UART_MAX);
memory_region_add_subregion(address_space, base, &s->mmio);
--
1.8.3.1
next reply other threads:[~2018-03-23 8:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 8:36 Thomas Huth [this message]
2018-03-23 8:58 ` [Qemu-devel] [PATCH for-2.12] hw/riscv: Fix crashes with "-nodefaults" Bastian Koppelmann
2018-03-23 9:56 ` Peter Maydell
2018-03-23 12:31 ` Thomas Huth
2018-03-23 13:12 ` Peter Maydell
2018-03-23 14:02 ` Paolo Bonzini
2018-03-23 14:04 ` Peter Maydell
2018-03-23 14:13 ` Paolo Bonzini
2018-03-23 14:28 ` Peter Maydell
2018-03-23 15:03 ` Paolo Bonzini
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=1521794165-31678-1-git-send-email-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=kbastian@mail.uni-paderborn.de \
--cc=mjc@sifive.com \
--cc=palmer@sifive.com \
--cc=qemu-devel@nongnu.org \
--cc=sagark@eecs.berkeley.edu \
/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).