From patchwork Sun Dec 13 17:52:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Igor V. Kovalenko" X-Patchwork-Id: 41043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4F35DB70BA for ; Mon, 14 Dec 2009 04:53:25 +1100 (EST) Received: from localhost ([127.0.0.1]:36376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NJsdG-0002Vv-Gt for incoming@patchwork.ozlabs.org; Sun, 13 Dec 2009 12:53:22 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NJscm-0002VQ-17 for qemu-devel@nongnu.org; Sun, 13 Dec 2009 12:52:52 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NJsch-0002UK-Uj for qemu-devel@nongnu.org; Sun, 13 Dec 2009 12:52:51 -0500 Received: from [199.232.76.173] (port=32971 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NJsch-0002UH-Oa for qemu-devel@nongnu.org; Sun, 13 Dec 2009 12:52:47 -0500 Received: from mail-fx0-f219.google.com ([209.85.220.219]:64407) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NJsch-00023c-8o for qemu-devel@nongnu.org; Sun, 13 Dec 2009 12:52:47 -0500 Received: by fxm19 with SMTP id 19so2459671fxm.17 for ; Sun, 13 Dec 2009 09:52:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:subject:to:from:date :message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=ou9kdT9kw8qjYok1DQcu8u0TBORzOsFIk/+vgHfcd5o=; b=CBB+dmNIAQZiosGJCtpdKAVzAfnqE4Sz8nw30RvsqWxwfWcrhimKaUTKxyKkGphR4d Sj2TX69+fqIKUgIEhKChw56X2ycdbmAghgHQPBC3EMXjyATH78EQ71I47IM2NRe3KkNm xPsZcZQPb8GD8kMXtkMTx7OmuGfH/jUEt335A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:to:from:date:message-id:user-agent:mime-version :content-type:content-transfer-encoding; b=J3+nNiLnhUY4W7g4TZ0Iouz9cbB+Pv+BraEQQr8RJfyWnmMtbgZNo/l9Ze02TBAMNx sBTlm+l89dFDf5uvLgtzKjSXsARjdjVvKvfOzYJ97KpukQnc4kqodQJfq57Os+0jXTx/ LklWEpEqBzCsiUeYLFocLLKYP6KybAVtSVQAI= Received: by 10.223.4.216 with SMTP id 24mr4269628fas.67.1260726765941; Sun, 13 Dec 2009 09:52:45 -0800 (PST) Received: from skyserv (host-87-255-14-75.bigtelecom.ru [87.255.14.75]) by mx.google.com with ESMTPS id 13sm1290309fxm.1.2009.12.13.09.52.45 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 13 Dec 2009 09:52:45 -0800 (PST) Received: from localhost ([127.0.0.1] helo=[192.168.1.2]) by skyserv with esmtp (Exim 4.71) (envelope-from ) id 1NJsce-00019w-Ew for qemu-devel@nongnu.org; Sun, 13 Dec 2009 20:52:44 +0300 To: qemu-devel@nongnu.org From: "Igor V. Kovalenko" Date: Sun, 13 Dec 2009 20:52:44 +0300 Message-ID: <20091213175244.4437.60962.stgit@skyserv> User-Agent: StGit/0.15 MIME-Version: 1.0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH] workaround for cmd646 bmdma register access while no dma is active X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Igor V. Kovalenko This is a workaround only, and is a partial revert of a few changes to BMDMAState which removed pci_dev field on the way. - cmd646 pci_from_bm() expects bm->unit value to correspond with bm data being passed to callback as opaque pointer. This breaks when write to dma control register of second channel happens when no dma operation is in progress, so bm->unit is zero for second channel, and pci_from_bm() returns garbage pointer. Crash happens shortly after that while dereferencing that pointer. v0->v1: cleaned up dead code from pci_from_bm. Signed-off-by: Igor V. Kovalenko --- hw/ide/cmd646.c | 7 ++----- hw/ide/internal.h | 1 + hw/ide/piix.c | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c index e1e626e..835c98d 100644 --- a/hw/ide/cmd646.c +++ b/hw/ide/cmd646.c @@ -70,11 +70,7 @@ static void ide_map(PCIDevice *pci_dev, int region_num, static PCIIDEState *pci_from_bm(BMDMAState *bm) { - if (bm->unit == 0) { - return container_of(bm, PCIIDEState, bmdma[0]); - } else { - return container_of(bm, PCIIDEState, bmdma[1]); - } + return bm->pci_dev; } static uint32_t bmdma_readb(void *opaque, uint32_t addr) @@ -145,6 +141,7 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num, BMDMAState *bm = &d->bmdma[i]; d->bus[i].bmdma = bm; bm->bus = d->bus+i; + bm->pci_dev = d; qemu_add_vm_change_state_handler(ide_dma_restart_cb, bm); register_ioport_write(addr, 1, 1, bmdma_cmd_writeb, bm); diff --git a/hw/ide/internal.h b/hw/ide/internal.h index f937daa..eb5b404 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -474,6 +474,7 @@ struct BMDMAState { uint8_t status; uint32_t addr; + struct PCIIDEState *pci_dev; IDEBus *bus; /* current transfer state */ uint32_t cur_addr; diff --git a/hw/ide/piix.c b/hw/ide/piix.c index de36480..2776ac3 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -78,6 +78,7 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num, BMDMAState *bm = &d->bmdma[i]; d->bus[i].bmdma = bm; bm->bus = d->bus+i; + bm->pci_dev = d; qemu_add_vm_change_state_handler(ide_dma_restart_cb, bm); register_ioport_write(addr, 1, 1, bmdma_cmd_writeb, bm);