From patchwork Thu Nov 24 20:11:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 9446241 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 B596B6071C for ; Thu, 24 Nov 2016 20:14:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A78A8280B0 for ; Thu, 24 Nov 2016 20:14:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C75428118; Thu, 24 Nov 2016 20:14:01 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 400C5280B0 for ; Thu, 24 Nov 2016 20:13:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cA0N0-0007D1-Sz; Thu, 24 Nov 2016 20:11:46 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cA0Mz-0007CM-5q for xen-devel@lists.xenproject.org; Thu, 24 Nov 2016 20:11:45 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 23/BA-28490-08947385; Thu, 24 Nov 2016 20:11:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmkeJIrShJLcpLzFFi42IJXDlps269p3m Ewfbpuhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bjq0+YCl4pVZxZe56pgfGteBcjJweLwC8m iY1/4kBsCQERiUMnHrJA2J4SM/7PYO9i5OIQEnjAJHFlynzWLkYOICdNor3HHqSGTUBJYu/B4 4wgtoiAtsSLVevYQGxmASeJN93f2EFsYQE/iYUz7jBC7FKVaJn6EszmFTCW2PL6JzPELnmJhe ePMIHYnAImErP2XASLCwHVTL05lXECI98CRoZVjBrFqUVlqUW6RpZ6SUWZ6RkluYmZObqGBmZ 6uanFxYnpqTmJScV6yfm5mxiBQcIABDsYDywKPMQoycGkJMq7Wcg8QogvKT+lMiOxOCO+qDQn tfgQowwHh5IEb64HUE6wKDU9tSItMwcYrjBpCQ4eJRHeHjegNG9xQWJucWY6ROoUozHHm10vH zBx3Hn04QGTEEtefl6qlDjvYXegUgGQ0ozSPLhBsDi6xCgrJczLCHSaEE9BalFuZgmq/CtGcQ 5GJWFeA5B7eDLzSuD2vQI6hQnoFMlvxiCnlCQipKQaGK2lL/XuXfFjub1w4hLTWabyjRren9S v/ZV1izLfUj7F/IzfgY+x1W0vnzL/q8nw/z3Zs6rFO0n9hmb2Z7s1//P8uNw7f0VdXzen/fKi sqbNDIHufIl96w1XX/nC2hd9/E7Nk5PXOuNKFziG2zBE5U5MYHrxUJxrr+VHxWUHXivlPNxwc vaDf0osxRmJhlrMRcWJAK7uNYmeAgAA X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-3.tower-27.messagelabs.com!1480018303!73581425!1 X-Originating-IP: [81.169.146.179] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10010 invoked from network); 24 Nov 2016 20:11:43 -0000 Received: from mo4-p04-ob.smtp.rzone.de (HELO mo4-p04-ob.smtp.rzone.de) (81.169.146.179) by server-3.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 24 Nov 2016 20:11:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1480018303; l=3768; s=domk; d=aepfle.de; h=References:In-Reply-To:Date:Subject:Cc:To:From; bh=hKexBlp6Bz5zGSMlqL9IER6sDPViotk1z1U9QcUf9F0=; b=FWpWpk52f0EUKbENBZougVrz/yVM/kHi9w/5Ow3ttYURI1jLHUOfsqmpijLw2TIoKQ LbJMwdSjerCzo21PXbkHPp7VXxCQe1nQ8ucvb05q4N7SPVWqPaVzbKEanioWncVUmv9U VfhonNjadFgpuHMEnHw5QSvpVGWuMneumKthE= X-RZG-CLASS-ID: mo04 X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+zrwiavkK6tmQaLfvzsjDHvnJrF4x7tmeNvA= Received: from probook (aftr-185-17-205-239.dynamic.mnet-online.de [185.17.205.239]) by smtp.strato.de (RZmta 39.9 SBL|AUTH) with ESMTPSA id 605806sAOKBfhBx (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 24 Nov 2016 21:11:41 +0100 (CET) Received: by probook (Postfix, from userid 1000) id 02E4250B5A; Thu, 24 Nov 2016 21:11:40 +0100 (CET) From: Olaf Hering To: Ian Jackson Date: Thu, 24 Nov 2016 20:11:29 +0000 Message-Id: <20161124201130.16558-2-olaf@aepfle.de> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161124201130.16558-1-olaf@aepfle.de> References: <20161124201130.16558-1-olaf@aepfle.de> Cc: xen-devel@lists.xenproject.org, Olaf Hering Subject: [Xen-devel] [PATCH qemu-xen-traditional 1/2] xen_platform: unplug also SCSI disks X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Olaf Hering Using 'vdev=sd[a-o]' will create an emulated LSI controller, which can be used by the emulated BIOS to boot from disk. If the HVM domU has also PV driver the disk may appear twice in the guest. To avoid this an unplug of the emulated hardware is needed, similar to what is done for IDE and NIC drivers already. Since the SCSI controller provides only disks the entire controller can be unplugged at once. Impact of the change for classic and pvops based guest kernels: vdev=sda:disk0 before: pvops: disk0=pv xvda + emulated sda classic: disk0=pv sda + emulated sdq after: pvops: disk0=pv xvda classic: disk0=pv sda vdev=hda:disk0, vdev=sda:disk1 before: pvops: disk0=pv xvda disk1=emulated sda classic: disk0=pv hda disk1=pv sda + emulated sdq after: pvops: disk0=pv xvda disk1=not accessible by blkfront, index hda==index sda classic: disk0=pv hda disk1=pv sda vdev=hda:disk0, vdev=sda:disk1, vdev=sdb:disk2 before: pvops: disk0=pv xvda disk1=emulated sda disk2=pv xvdb + emulated sdb classic: disk0=pv hda disk1=pv sda + emulated sdq disk2=pv sdb + emulated sdr after: pvops: disk0=pv xvda disk1=not accessible by blkfront, index hda==index sda disk2=pv xvdb classic: disk0=pv hda disk1=pv sda disk2=pv sda Upstream commit 78f66897ddf58d1ffe5e0b95f7c1a1dad103a8da Signed-off-by: Olaf Hering --- hw/pci.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/xen_platform.c | 4 +++- qemu-xen.h | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/hw/pci.c b/hw/pci.c index c423285..7d8e3b6 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -871,6 +871,47 @@ void pci_unplug_netifs(void) } } +void pci_unplug_scsi(void) +{ + PCIBus *bus; + PCIDevice *dev; + PCIIORegion *region; + int x; + int i; + + /* We only support one PCI bus */ + for (bus = first_bus; bus; bus = NULL) { + for (x = 0; x < 256; x++) { + dev = bus->devices[x]; + if (dev && + dev->config[0xa] == 0 && + dev->config[0xb] == 1 +#ifdef CONFIG_PASSTHROUGH + && test_pci_devfn(x) != 1 +#endif + ) { + /* Found a scsi disk. Remove it from the bus. Note that + we don't free it here, since there could still be + references to it floating around. There are only + ever one or two structures leaked, and it's not + worth finding them all. */ + bus->devices[x] = NULL; + for (i = 0; i < PCI_NUM_REGIONS; i++) { + region = &dev->io_regions[i]; + if (region->addr == (uint32_t)-1 || + region->size == 0) + continue; + if (region->type == PCI_ADDRESS_SPACE_IO) { + isa_unassign_ioport(region->addr, region->size); + } else if (region->type == PCI_ADDRESS_SPACE_MEM) { + unregister_iomem(region->addr); + } + } + } + } + } +} + typedef struct { PCIDevice dev; PCIBus *bus; diff --git a/hw/xen_platform.c b/hw/xen_platform.c index d282f8e..0a94e0d 100644 --- a/hw/xen_platform.c +++ b/hw/xen_platform.c @@ -154,8 +154,10 @@ static void platform_fixed_ioport_write2(void *opaque, uint32_t addr, uint32_t v /* Unplug devices. Value is a bitmask of which devices to unplug, with bit 0 the IDE devices, bit 1 the network devices, and bit 2 the non-primary-master IDE devices. */ - if (val & UNPLUG_ALL_IDE_DISKS) + if (val & UNPLUG_ALL_IDE_DISKS) { ide_unplug_harddisks(); + pci_unplug_scsi(); + } if (val & UNPLUG_ALL_NICS) { pci_unplug_netifs(); net_tap_shutdown_all(); diff --git a/qemu-xen.h b/qemu-xen.h index 0598668..d315623 100644 --- a/qemu-xen.h +++ b/qemu-xen.h @@ -47,6 +47,7 @@ void unset_vram_mapping(void *opaque); #endif void pci_unplug_netifs(void); +void pci_unplug_scsi(void); void destroy_hvm_domain(void); void unregister_iomem(target_phys_addr_t start);