From patchwork Sun May 15 16:32:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 95654 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 07227B6EF2 for ; Mon, 16 May 2011 02:32:09 +1000 (EST) Received: from localhost ([::1]:41761 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLeEf-00077i-Qo for incoming@patchwork.ozlabs.org; Sun, 15 May 2011 12:32:05 -0400 Received: from eggs.gnu.org ([140.186.70.92]:38723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLeEY-00077V-88 for qemu-devel@nongnu.org; Sun, 15 May 2011 12:31:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QLeEX-0007gG-2R for qemu-devel@nongnu.org; Sun, 15 May 2011 12:31:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30613) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLeEW-0007fu-Rb for qemu-devel@nongnu.org; Sun, 15 May 2011 12:31:57 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4FGVrVj010227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 15 May 2011 12:31:54 -0400 Received: from redhat.com (vpn-201-135.tlv.redhat.com [10.35.201.135]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id p4FGVoVT004292; Sun, 15 May 2011 12:31:51 -0400 Date: Sun, 15 May 2011 19:32:04 +0300 From: "Michael S. Tsirkin" To: Alexey Zaytsev Message-ID: <20110515163105.GG24932@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Avi Kivity , qemu-devel@nongnu.org, Alexander Graf Subject: Re: [Qemu-devel] AHCI broken in current git, bisected. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Sun, May 15, 2011 at 07:58:23PM +0400, Alexey Zaytsev wrote: > Hi. > > The commit 667bb59d2358daeef179583c944becba3f1f9680 > Author: Avi Kivity > Date: Mon Apr 4 18:28:02 2011 +0300 > > ich/ahci: convert to pci_register_bar_simple() > > Signed-off-by: Avi Kivity > Signed-off-by: Michael S. Tsirkin > > breaks AHCI to the point the disks are not detected by both seabios and Linux: > > [ 8.582220] ata1: PATA max MWDMA2 cmd 0x1f0 ctl 0x3f6 bmdma 0xc000 irq 14 > [ 8.582646] ata2: PATA max MWDMA2 cmd 0x170 ctl 0x376 bmdma 0xc008 irq 15 > [ 8.603979] ACPI: PCI Interrupt Link [LNKD] enabled at IRQ 10 > [ 8.605151] ahci 0000:00:04.0: PCI INT A -> Link[LNKD] -> GSI 10 > (level, high) -> IRQ 10 > [ 9.608243] ahci 0000:00:04.0: controller reset failed (0xf000ff53) > [ 9.609948] ahci 0000:00:04.0: PCI INT A disabled > [ 9.610267] ahci: probe of 0000:00:04.0 failed with error -5 Sure enough, /* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */ pci_register_bar_simple(&d->card, 5, 0x1000, 0, d->ahci.mem); msi_init(dev, 0x50, 1, true, false); ahci_init(&d->ahci, &dev->qdev, 6); where ahci_init initializes d->ahci.mem. Coul;d you try out the following please (untested, a bit busy now)? ---> ich/ahci: fix use of uninitialized memory The commit 667bb59d2358daeef179583c944becba3f1f9680 uses d->ahci.mem before it is initialized by ahci_init(). Fix this by calling ahci_init() first thing so that it's safe to use all fields in the ahci state struct. Reported-by: Alexey Zaytsev Signed-off-by: Michael S. Tsirkin diff --git a/hw/ide/ich.c b/hw/ide/ich.c index e44339b..5ce0a88 100644 --- a/hw/ide/ich.c +++ b/hw/ide/ich.c @@ -77,6 +77,8 @@ static int pci_ich9_ahci_init(PCIDevice *dev) struct AHCIPCIState *d; d = DO_UPCAST(struct AHCIPCIState, card, dev); + ahci_init(&d->ahci, &dev->qdev, 6); + pci_config_set_vendor_id(d->card.config, PCI_VENDOR_ID_INTEL); pci_config_set_device_id(d->card.config, PCI_DEVICE_ID_INTEL_82801IR); @@ -97,8 +99,6 @@ static int pci_ich9_ahci_init(PCIDevice *dev) pci_register_bar_simple(&d->card, 5, 0x1000, 0, d->ahci.mem); msi_init(dev, 0x50, 1, true, false); - - ahci_init(&d->ahci, &dev->qdev, 6); d->ahci.irq = d->card.irq[0]; return 0;