From nobody Sat Oct 25 21:42:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521794245845602.5273897824237; Fri, 23 Mar 2018 01:37:25 -0700 (PDT) Received: from localhost ([::1]:36581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezICT-0001g0-4e for importer@patchew.org; Fri, 23 Mar 2018 04:37:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezIBR-0001EC-Gm for qemu-devel@nongnu.org; Fri, 23 Mar 2018 04:36:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezIBM-0000AQ-HN for qemu-devel@nongnu.org; Fri, 23 Mar 2018 04:36:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53284 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ezIBM-00007v-DL for qemu-devel@nongnu.org; Fri, 23 Mar 2018 04:36:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39AD3722DD; Fri, 23 Mar 2018 08:36:11 +0000 (UTC) Received: from thh440s.str.redhat.com (dhcp-192-189.str.redhat.com [10.33.192.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 387F5215CDAC; Fri, 23 Mar 2018 08:36:06 +0000 (UTC) From: Thomas Huth To: Michael Clark , qemu-devel@nongnu.org Date: Fri, 23 Mar 2018 09:36:05 +0100 Message-Id: <1521794165-31678-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 23 Mar 2018 08:36:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 23 Mar 2018 08:36:11 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH for-2.12] hw/riscv: Fix crashes with "-nodefaults" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bastian Koppelmann , Palmer Dabbelt , Sagar Karandikar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3Ds@entry=3D0x0, [...]) at chardev/char-fe.c:210 210 } else if (s->be) { (gdb) bt 0 0x00005555558695f8 in qemu_chr_fe_init ([...], s=3Ds@entry=3D0x0, [...]) at chardev/char-fe.c:210 1 0x00005555556fb425 in sifive_uart_create ([...], chr=3D0x0, [...]) at hw/riscv/sifive_uart.c:169 2 0x00005555556f8cc4 in riscv_sifive_e_init (machine=3D[...]) at hw/riscv/sifive_e.c:164 [...] With "-nodefaults" there are no entries in serial_hds[], so qemu_chr_fe_ini= t() 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 Reviewed-by: Bastian Koppelmann --- 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, M= emoryRegion *main_mem, s->pending_read =3D 0; s->allow_tohost =3D 0; s->fromhost_inprogress =3D 0; + + if (!chr) { + chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_NULL, NULL, &error_abo= rt); + } 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 *addr= ess_space, hwaddr base, { SiFiveUARTState *s =3D g_malloc0(sizeof(SiFiveUARTState)); s->irq =3D irq; + + if (!chr) { + chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_NULL, NULL, &error_abo= rt); + } 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); --=20 1.8.3.1