From nobody Sat Oct 25 21:45:33 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 1521194050646241.44126505096574; Fri, 16 Mar 2018 02:54:10 -0700 (PDT) Received: from localhost ([::1]:55806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewm3t-0007ux-Oe for importer@patchew.org; Fri, 16 Mar 2018 05:54:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewm1h-0006Z8-MS for qemu-devel@nongnu.org; Fri, 16 Mar 2018 05:51:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewm1d-00049x-L6 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 05:51:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40712 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 1ewm1d-000497-GW for qemu-devel@nongnu.org; Fri, 16 Mar 2018 05:51:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60CC5D142D; Fri, 16 Mar 2018 09:51:47 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2264CC1234; Fri, 16 Mar 2018 09:51:46 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 10:51:31 +0100 Message-Id: <1521193892-15552-4-git-send-email-thuth@redhat.com> In-Reply-To: <1521193892-15552-1-git-send-email-thuth@redhat.com> References: <1521193892-15552-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 16 Mar 2018 09:51:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 16 Mar 2018 09:51:47 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 3/4] hw/audio: Fix crashes when devices are used on ISA bus without DMA 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: Eduardo Habkost , Alexey Kardashevskiy , Jason Wang , Gerd Hoffmann , Paolo Bonzini , John Snow , Pavel Pisa 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" The cs4231a, gus and sb16 sound cards crash QEMU when the user tries to instantiate them on a machine with DMA-less ISA bus (for example with "qemu-system-mips64el -M mips -device sb16"). Add proper checks to the realize functions to avoid the crashes. Signed-off-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/audio/cs4231a.c | 8 +++++++- hw/audio/gus.c | 7 ++++++- hw/audio/sb16.c | 9 +++++++-- scripts/device-crash-test | 3 --- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c index 096e8e9..aaebec1 100644 --- a/hw/audio/cs4231a.c +++ b/hw/audio/cs4231a.c @@ -28,6 +28,7 @@ #include "hw/isa/isa.h" #include "hw/qdev.h" #include "qemu/timer.h" +#include "qapi/error.h" =20 /* Missing features: @@ -663,8 +664,13 @@ static void cs4231a_realizefn (DeviceState *dev, Error= **errp) CSState *s =3D CS4231A (dev); IsaDmaClass *k; =20 - isa_init_irq (d, &s->pic, s->irq); s->isa_dma =3D isa_get_dma(isa_bus_from_device(d), s->dma); + if (!s->isa_dma) { + error_setg(errp, "ISA controller does not support DMA"); + return; + } + + isa_init_irq(d, &s->pic, s->irq); k =3D ISADMA_GET_CLASS(s->isa_dma); k->register_channel(s->isa_dma, s->dma, cs_dma_read, s); =20 diff --git a/hw/audio/gus.c b/hw/audio/gus.c index 3e864cd..8e0b27e 100644 --- a/hw/audio/gus.c +++ b/hw/audio/gus.c @@ -241,6 +241,12 @@ static void gus_realizefn (DeviceState *dev, Error **e= rrp) IsaDmaClass *k; struct audsettings as; =20 + s->isa_dma =3D isa_get_dma(isa_bus_from_device(d), s->emu.gusdma); + if (!s->isa_dma) { + error_setg(errp, "ISA controller does not support DMA"); + return; + } + AUD_register_card ("gus", &s->card); =20 as.freq =3D s->freq; @@ -272,7 +278,6 @@ static void gus_realizefn (DeviceState *dev, Error **er= rp) isa_register_portio_list(d, &s->portio_list2, (s->port + 0x100) & 0xf0= 0, gus_portio_list2, s, "gus"); =20 - s->isa_dma =3D isa_get_dma(isa_bus_from_device(d), s->emu.gusdma); k =3D ISADMA_GET_CLASS(s->isa_dma); k->register_channel(s->isa_dma, s->emu.gusdma, GUS_read_DMA, s); s->emu.himemaddr =3D s->himem; diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c index 31de264..5a4d323 100644 --- a/hw/audio/sb16.c +++ b/hw/audio/sb16.c @@ -1371,6 +1371,13 @@ static void sb16_realizefn (DeviceState *dev, Error = **errp) SB16State *s =3D SB16 (dev); IsaDmaClass *k; =20 + s->isa_hdma =3D isa_get_dma(isa_bus_from_device(isadev), s->hdma); + s->isa_dma =3D isa_get_dma(isa_bus_from_device(isadev), s->dma); + if (!s->isa_dma || !s->isa_hdma) { + error_setg(errp, "ISA controller does not support DMA"); + return; + } + isa_init_irq (isadev, &s->pic, s->irq); =20 s->mixer_regs[0x80] =3D magic_of_irq (s->irq); @@ -1389,11 +1396,9 @@ static void sb16_realizefn (DeviceState *dev, Error = **errp) isa_register_portio_list(isadev, &s->portio_list, s->port, sb16_ioport_list, s, "sb16"); =20 - s->isa_hdma =3D isa_get_dma(isa_bus_from_device(isadev), s->hdma); k =3D ISADMA_GET_CLASS(s->isa_hdma); k->register_channel(s->isa_hdma, s->hdma, SB_read_DMA, s); =20 - s->isa_dma =3D isa_get_dma(isa_bus_from_device(isadev), s->dma); k =3D ISADMA_GET_CLASS(s->isa_dma); k->register_channel(s->isa_dma, s->dma, SB_read_DMA, s); =20 diff --git a/scripts/device-crash-test b/scripts/device-crash-test index 99d20cb..8ad3f44 100755 --- a/scripts/device-crash-test +++ b/scripts/device-crash-test @@ -217,10 +217,7 @@ ERROR_WHITELIST =3D [ {'exitcode':-6, 'log':r"Object .* is not an instance of type generic-p= c-machine", 'loglevel':logging.ERROR}, {'exitcode':-6, 'log':r"Object .* is not an instance of type e500-ccsr= ", 'loglevel':logging.ERROR}, {'exitcode':-6, 'log':r"vmstate_register_with_alias_id: Assertion `!se= ->compat \|\| se->instance_id =3D=3D 0' failed", 'loglevel':logging.ERROR}, - {'exitcode':-11, 'device':'gus', 'loglevel':logging.ERROR, 'expected':= True}, {'exitcode':-11, 'device':'isa-serial', 'loglevel':logging.ERROR, 'exp= ected':True}, - {'exitcode':-11, 'device':'sb16', 'loglevel':logging.ERROR, 'expected'= :True}, - {'exitcode':-11, 'device':'cs4231a', 'loglevel':logging.ERROR, 'expect= ed':True}, {'exitcode':-11, 'machine':'isapc', 'device':'.*-iommu', 'loglevel':lo= gging.ERROR, 'expected':True}, =20 # everything else (including SIGABRT and SIGSEGV) will be a fatal erro= r: --=20 1.8.3.1