From patchwork Thu Feb 2 18:35:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9552921 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 D4992604A7 for ; Thu, 2 Feb 2017 18:38:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5EF328411 for ; Thu, 2 Feb 2017 18:38:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA9EA284BA; Thu, 2 Feb 2017 18:38:22 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM 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 244B528411 for ; Thu, 2 Feb 2017 18:38:22 +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 1cZMEc-0003lU-2M; Thu, 02 Feb 2017 18:35:54 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZMEa-0003kO-Ad for xen-devel@lists.xenproject.org; Thu, 02 Feb 2017 18:35:52 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 37/2E-22326-70C73985; Thu, 02 Feb 2017 18:35:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42I5NlG2Q5e9ZnK EQfspZovvWyYzOTB6HP5whSWAMYo1My8pvyKBNePIqpSCN9oVjc+/MDUwLlHqYuTiEBKYyijx /MhbdghnB5PEi0cTWLoYOTnYBAwl/j7ZxAZiiwiISZzePY0JpIhZoIVZ4urvy0wgCWEBB4l9c 3oZQWwWAVWJviuPwJp5Bdwk1r2ZBBaXEJCTOHlsMiuIzSngLtH2dioTxLZ2RokNa7YxQRRlSM zrmcMKYXtJLLpxCcpWk7h6bhPzBEa+BYwMqxg1ilOLylKLdI3M9JKKMtMzSnITM3N0DQ3M9HJ Ti4sT01NzEpOK9ZLzczcxAkOFAQh2MJ5ZEHiIUZKDSUmUd4rW5AghvqT8lMqMxOKM+KLSnNTi Q4wyHBxKErzLqoBygkWp6akVaZk5wKCFSUtw8CiJ8M4DSfMWFyTmFmemQ6ROMepynLpx+iWTE Etefl6qlDjvdpAiAZCijNI8uBGwCLrEKCslzMsIdJQQT0FqUW5mCar8K0ZxDkYlYd5TIFN4Mv NK4Da9AjqCCeiIn48ngRxRkoiQkmpgPDrraIyDdKkGj0rObdHs52c/HYz3VlD/tC3BdlLsz7h 58R/cbj77GH9dYm5AmNva5OfW0fO6+Iv/ruSdwrLkcpuXTmZV3xWRuZGaKUEHtkYf/rVlTipD xKtMtX1L566O4mtQ6VqTud1F+LNohsEGky6fjHkb1821u5STbRQW47Qy9fFT1ueBSizFGYmGW sxFxYkAX7bxi5sCAAA= X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-10.tower-21.messagelabs.com!1486060549!49195355!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46706 invoked from network); 2 Feb 2017 18:35:50 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Feb 2017 18:35:50 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 00D8F20204; Thu, 2 Feb 2017 18:35:48 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (c-50-131-44-19.hsd1.ca.comcast.net [50.131.44.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 274F9202FF; Thu, 2 Feb 2017 18:35:46 +0000 (UTC) From: Stefano Stabellini To: stefanha@gmail.com Date: Thu, 2 Feb 2017 10:35:39 -0800 Message-Id: <1486060541-29146-3-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486060541-29146-1-git-send-email-sstabellini@kernel.org> References: <1486060541-29146-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP Cc: peter.maydell@linaro.org, sstabellini@kernel.org, Eduardo Habkost , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, Paolo Bonzini , anthony.perard@citrix.com, xen-devel@lists.xenproject.org, John Snow , Richard Henderson Subject: [Xen-devel] [PULL 3/5] xen-platform: add missing disk unplug option 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: Paul Durrant The Xen HVM unplug protocol [1] specifies a mechanism to allow guests to request unplug of 'aux' disks (which is stated to mean all IDE disks, except the primary master). This patch adds support for that unplug request. NOTE: The semantics of what happens if unplug of all disks and 'aux' disks is simultaneously requests is not clear. The patch makes that assumption that an 'all' request overrides an 'aux' request. [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=docs/misc/hvm-emulated-unplug.markdown Signed-off-by: Paul Durrant Reviewed-by: Stefano Stabellini ---- Cc: Stefano Stabellini Cc: Anthony Perard Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: John Snow --- hw/i386/xen/xen_platform.c | 27 +++++++++++++++------------ hw/ide/piix.c | 4 ++-- include/hw/ide.h | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index 7d41ebb..6010f35 100644 --- a/hw/i386/xen/xen_platform.c +++ b/hw/i386/xen/xen_platform.c @@ -107,8 +107,12 @@ static void pci_unplug_nics(PCIBus *bus) pci_for_each_device(bus, 0, unplug_nic, NULL); } -static void unplug_disks(PCIBus *b, PCIDevice *d, void *o) +static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque) { + uint32_t flags = *(uint32_t *)opaque; + bool aux = (flags & UNPLUG_AUX_IDE_DISKS) && + !(flags & UNPLUG_ALL_DISKS); + /* We have to ignore passthrough devices */ if (!strcmp(d->name, "xen-pci-passthrough")) { return; @@ -116,12 +120,14 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *o) switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) { case PCI_CLASS_STORAGE_IDE: - pci_piix3_xen_ide_unplug(DEVICE(d)); + pci_piix3_xen_ide_unplug(DEVICE(d), aux); break; case PCI_CLASS_STORAGE_SCSI: case PCI_CLASS_STORAGE_EXPRESS: - object_unparent(OBJECT(d)); + if (!aux) { + object_unparent(OBJECT(d)); + } break; default: @@ -129,9 +135,9 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *o) } } -static void pci_unplug_disks(PCIBus *bus) +static void pci_unplug_disks(PCIBus *bus, uint32_t flags) { - pci_for_each_device(bus, 0, unplug_disks, NULL); + pci_for_each_device(bus, 0, unplug_disks, &flags); } static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val) @@ -144,17 +150,14 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v /* Unplug devices. Value is a bitmask of which devices to unplug, with bit 0 the disk devices, bit 1 the network devices, and bit 2 the non-primary-master IDE devices. */ - if (val & UNPLUG_ALL_DISKS) { + if (val & (UNPLUG_ALL_DISKS | UNPLUG_AUX_IDE_DISKS)) { DPRINTF("unplug disks\n"); - pci_unplug_disks(pci_dev->bus); + pci_unplug_disks(pci_dev->bus, val); } if (val & UNPLUG_ALL_NICS) { DPRINTF("unplug nics\n"); pci_unplug_nics(pci_dev->bus); } - if (val & UNPLUG_AUX_IDE_DISKS) { - DPRINTF("unplug auxiliary disks not supported\n"); - } break; } case 2: @@ -335,14 +338,14 @@ static void xen_platform_ioport_writeb(void *opaque, hwaddr addr, * If VMDP was to control both disk and LAN it would use 4. * If it controlled just disk or just LAN, it would use 8 below. */ - pci_unplug_disks(pci_dev->bus); + pci_unplug_disks(pci_dev->bus, UNPLUG_ALL_DISKS); pci_unplug_nics(pci_dev->bus); } break; case 8: switch (val) { case 1: - pci_unplug_disks(pci_dev->bus); + pci_unplug_disks(pci_dev->bus, UNPLUG_ALL_DISKS); break; case 2: pci_unplug_nics(pci_dev->bus); diff --git a/hw/ide/piix.c b/hw/ide/piix.c index d5777fd..7e2d767 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -165,7 +165,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp) pci_piix_init_ports(d); } -int pci_piix3_xen_ide_unplug(DeviceState *dev) +int pci_piix3_xen_ide_unplug(DeviceState *dev, bool aux) { PCIIDEState *pci_ide; DriveInfo *di; @@ -174,7 +174,7 @@ int pci_piix3_xen_ide_unplug(DeviceState *dev) pci_ide = PCI_IDE(dev); - for (i = 0; i < 4; i++) { + for (i = aux ? 1 : 0; i < 4; i++) { di = drive_get_by_index(IF_IDE, i); if (di != NULL && !di->media_cd) { BlockBackend *blk = blk_by_legacy_dinfo(di); diff --git a/include/hw/ide.h b/include/hw/ide.h index bc8bd32..3ae087c 100644 --- a/include/hw/ide.h +++ b/include/hw/ide.h @@ -17,7 +17,7 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table, PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); -int pci_piix3_xen_ide_unplug(DeviceState *dev); +int pci_piix3_xen_ide_unplug(DeviceState *dev, bool aux); void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); /* ide-mmio.c */