From patchwork Thu Oct 5 12:36:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 9987023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E8DD60291 for ; Thu, 5 Oct 2017 12:38:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10A9B28C2D for ; Thu, 5 Oct 2017 12:38:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05C0828C77; Thu, 5 Oct 2017 12:38:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AB23928C2D for ; Thu, 5 Oct 2017 12:38:27 +0000 (UTC) Received: from localhost ([::1]:39656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e05Q2-0002HG-Tk for patchwork-qemu-devel@patchwork.kernel.org; Thu, 05 Oct 2017 08:38:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e05OG-0001fF-C1 for qemu-devel@nongnu.org; Thu, 05 Oct 2017 08:36:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e05OD-0001tC-7s for qemu-devel@nongnu.org; Thu, 05 Oct 2017 08:36:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56636 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e05OD-0001s7-2J for qemu-devel@nongnu.org; Thu, 05 Oct 2017 08:36:33 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v95CZO9u049949 for ; Thu, 5 Oct 2017 08:36:28 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ddmbk1y8n-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 05 Oct 2017 08:36:28 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Oct 2017 13:36:27 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 5 Oct 2017 13:36:25 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v95CaPDf10027222; Thu, 5 Oct 2017 12:36:25 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 72AC8AE04D; Thu, 5 Oct 2017 13:30:53 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 35D3AAE045; Thu, 5 Oct 2017 13:30:53 +0100 (BST) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.145.171.184]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 5 Oct 2017 13:30:53 +0100 (BST) From: Pierre Morel To: qemu-devel@nongnu.org Date: Thu, 5 Oct 2017 14:36:23 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507206983-16096-1-git-send-email-pmorel@linux.vnet.ibm.com> References: <1507206983-16096-1-git-send-email-pmorel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17100512-0016-0000-0000-000004F2A16A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17100512-0017-0000-0000-0000282D1326 Message-Id: <1507206983-16096-2-git-send-email-pmorel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-05_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710050177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v1] pci: Set PCI-bus device entry before initializing bus master 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: marcel@redhat.com, cohuck@redhat.com, zyimin@linux.vnet.ibm.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When initializing the PCI-bus master pci_init_bus_master(PCIDevice *) calls pci_device_iommu_address_space(PCIDevice *) which in turn calls iommu_bus->iommu_fn(bus, opaque,devfn) If the device entry of the PCI-bus is not initialized to point to the PCIDevice structure, the iommu_fn() function, getting only bus and devno, is unable to retrieve the PCIDevice. Usually it is not a problem as the DMA address space is depending of the BUS but in an architecture like S390, each PCI Device can have its own DMA address space. Being able to setup the DMA address space at the right moment will greatly simplify the implementation. This patch proposes to setup the bus device entry before calling pci_init_bus_master() and reset the entry in case of error. Signed-off-by: Pierre Morel --- hw/pci/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 1e6fb88..3e64492 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1026,6 +1026,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, address_space_init(&pci_dev->bus_master_as, &pci_dev->bus_master_container_region, pci_dev->name); + bus->devices[devfn] = pci_dev; if (qdev_hotplug) { pci_init_bus_master(pci_dev); } @@ -1062,6 +1063,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, if (local_err) { error_propagate(errp, local_err); do_pci_unregister_device(pci_dev); + bus->devices[devfn] = NULL; return NULL; } @@ -1071,7 +1073,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, config_write = pci_default_write_config; pci_dev->config_read = config_read; pci_dev->config_write = config_write; - bus->devices[devfn] = pci_dev; pci_dev->version_id = 2; /* Current pci device vmstate version */ return pci_dev; }