From patchwork Mon Jan 7 22:29:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venu Busireddy X-Patchwork-Id: 10751261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 089C4746 for ; Mon, 7 Jan 2019 22:32:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE5ED28A82 for ; Mon, 7 Jan 2019 22:32:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1FA028AA5; Mon, 7 Jan 2019 22:32:29 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4051B28A82 for ; Mon, 7 Jan 2019 22:32:29 +0000 (UTC) Received: from localhost ([127.0.0.1]:51157 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggdRc-0006tS-AX for patchwork-qemu-devel@patchwork.kernel.org; Mon, 07 Jan 2019 17:32:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggdPq-0005L3-3r for qemu-devel@nongnu.org; Mon, 07 Jan 2019 17:30:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggdPl-00050d-Fc for qemu-devel@nongnu.org; Mon, 07 Jan 2019 17:30:38 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:43824) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ggdPl-0004Ds-3S for qemu-devel@nongnu.org; Mon, 07 Jan 2019 17:30:33 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x07MIflB113285; Mon, 7 Jan 2019 22:30:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=LKkRDXabacVMKHOdqfYZYSIzQWrGPVXtqIBuchM7XyY=; b=NMiBEKyNPIyzPXUoaKteQKnNwv6DbZbIDF3gxXTROzzP4dnls6TcX3ZwND70CCIbsWSr 9i4kQHqZ66fmhNc29NxHT30PAOQJ50fmfbmZJBoP/weXoczlq+AE2ZOo/FCnK9XW6Tmv 2UbT2TDTsRdsvGeUKe23nEvVkVbCcemTDV2AYWQf19zFYDe0wuEm1STzKBTHJnF9XBdN 6wNVdeV6TM5bIBu26zpoU6oPdGKJnOGUKTYv2H69DMxjtEyl47knNbSN1YIouQs7zmKH QLKeOQ7QtvLAgCt7F1wMiNbQ1uxEjK45O7q2fPSts4U4d25b13Y/UBpwWXgFInd9U0a5 Ug== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2ptm0u0eyn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Jan 2019 22:30:12 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x07MU5nX015989 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 7 Jan 2019 22:30:06 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x07MU52o018618; Mon, 7 Jan 2019 22:30:05 GMT Received: from ban25x6uut28.us.oracle.com (/10.153.73.28) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Jan 2019 14:30:05 -0800 From: Venu Busireddy To: venu.busireddy@oracle.com, "Michael S. Tsirkin" , Marcel Apfelbaum Date: Mon, 7 Jan 2019 17:29:41 -0500 Message-Id: <1546900184-27403-3-git-send-email-venu.busireddy@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1546900184-27403-1-git-send-email-venu.busireddy@oracle.com> References: <1546900184-27403-1-git-send-email-venu.busireddy@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9129 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901070183 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v3 2/5] virtio_net: Add support for "Data Path Switching" during Live Migration. 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: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Added a new event, FAILOVER_STANDBY_CHANGED, which is emitted whenever the status of the virtio_net driver in the guest changes (either the guest successfully loads the driver after the F_STANDBY feature bit is negotiated, or the guest unloads the driver or reboots). Management stack can use this event to determine when to plug/unplug the VF device to/from the guest. Also, the Virtual Functions will be automatically removed from the guest if the guest is rebooted. To properly identify the VFIO devices that must be removed, a new property named "failover-primary" is added to the vfio-pci devices. Only the vfio-pci devices that have this property enabled are removed from the guest upon reboot. Signed-off-by: Venu Busireddy --- hw/acpi/pcihp.c | 27 +++++++++++++++++++++++++++ hw/net/virtio-net.c | 24 ++++++++++++++++++++++++ hw/vfio/pci.c | 3 +++ hw/vfio/pci.h | 1 + include/hw/pci/pci.h | 1 + qapi/net.json | 28 ++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+) diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 80d42e1..2a3ffd3 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -176,6 +176,25 @@ static void acpi_pcihp_eject_slot(AcpiPciHpState *s, unsigned bsel, unsigned slo } } +static void acpi_pcihp_cleanup_failover_primary(AcpiPciHpState *s, int bsel) +{ + BusChild *kid, *next; + PCIBus *bus = acpi_pcihp_find_hotplug_bus(s, bsel); + + if (!bus) { + return; + } + QTAILQ_FOREACH_SAFE(kid, &bus->qbus.children, sibling, next) { + DeviceState *qdev = kid->child; + PCIDevice *pdev = PCI_DEVICE(qdev); + int slot = PCI_SLOT(pdev->devfn); + + if (pdev->failover_primary) { + s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); + } + } +} + static void acpi_pcihp_update_hotplug_bus(AcpiPciHpState *s, int bsel) { BusChild *kid, *next; @@ -207,6 +226,14 @@ static void acpi_pcihp_update(AcpiPciHpState *s) int i; for (i = 0; i < ACPI_PCIHP_MAX_HOTPLUG_BUS; ++i) { + /* + * Set the acpi_pcihp_pci_status[].down bits of all the + * failover_primary devices so that the devices are ejected + * from the guest. We can't use the qdev_unplug() as well as the + * hotplug_handler to unplug the devices, because the guest may + * not be in a state to cooperate. + */ + acpi_pcihp_cleanup_failover_primary(s, i); acpi_pcihp_update_hotplug_bus(s, i); } } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 411f8fb..7b1bcde 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -248,6 +248,29 @@ static void virtio_net_drop_tx_queue_data(VirtIODevice *vdev, VirtQueue *vq) } } +static void virtio_net_failover_notify_event(VirtIONet *n, uint8_t status) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(n); + + if (virtio_has_feature(vdev->guest_features, VIRTIO_NET_F_STANDBY)) { + const char *ncn = n->netclient_name; + gchar *path = object_get_canonical_path(OBJECT(n->qdev)); + /* + * Emit FAILOVER_STANDBY_CHANGED event with enabled=true + * when the status transitions from 0 to VIRTIO_CONFIG_S_DRIVER_OK + * Emit FAILOVER_STANDBY_CHANGED event with enabled=false + * when the status transitions from VIRTIO_CONFIG_S_DRIVER_OK to 0 + */ + if ((status & VIRTIO_CONFIG_S_DRIVER_OK) && + (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK))) { + qapi_event_send_failover_standby_changed(!!ncn, ncn, path, true); + } else if ((!(status & VIRTIO_CONFIG_S_DRIVER_OK)) && + (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { + qapi_event_send_failover_standby_changed(!!ncn, ncn, path, false); + } + } +} + static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) { VirtIONet *n = VIRTIO_NET(vdev); @@ -256,6 +279,7 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) uint8_t queue_status; virtio_net_vnet_endian_status(n, status); + virtio_net_failover_notify_event(n, status); virtio_net_vhost_status(n, status); for (i = 0; i < n->max_queues; i++) { diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5c7bd96..bd83b58 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3077,6 +3077,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) vfio_register_err_notifier(vdev); vfio_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); + pdev->failover_primary = vdev->failover_primary; return; @@ -3219,6 +3220,8 @@ static Property vfio_pci_dev_properties[] = { qdev_prop_nv_gpudirect_clique, uint8_t), DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_relo, OFF_AUTOPCIBAR_OFF), + DEFINE_PROP_BOOL("failover-primary", VFIOPCIDevice, failover_primary, + false), /* * TODO - support passed fds... is this necessary? * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name), diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index b1ae4c0..06ca661 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -167,6 +167,7 @@ typedef struct VFIOPCIDevice { bool no_vfio_ioeventfd; bool enable_ramfb; VFIODisplay *dpy; + bool failover_primary; } VFIOPCIDevice; uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index e6514bb..b0111d1 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -351,6 +351,7 @@ struct PCIDevice { MSIVectorUseNotifier msix_vector_use_notifier; MSIVectorReleaseNotifier msix_vector_release_notifier; MSIVectorPollNotifier msix_vector_poll_notifier; + bool failover_primary; }; void pci_register_bar(PCIDevice *pci_dev, int region_num, diff --git a/qapi/net.json b/qapi/net.json index 8f99fd9..6a6d6fe 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -683,3 +683,31 @@ ## { 'event': 'NIC_RX_FILTER_CHANGED', 'data': { '*name': 'str', 'path': 'str' } } + +## +# @FAILOVER_STANDBY_CHANGED: +# +# Emitted whenever the virtio_net driver status changes (either the guest +# successfully loads the driver after the F_STANDBY feature bit is negotiated, +# or the guest unloads the driver or reboots). +# +# @device: Indicates the virtio_net device. +# +# @path: Indicates the device path. +# +# @enabled: true if the virtio_net driver is loaded. +# false if the virtio_net driver is unloaded or the guest reboots. +# +# Since: 4.0 +# +# Example: +# +# <- { "event": "FAILOVER_STANDBY_CHANGED", +# "data": { "device": "net0", +# "path": "/machine/peripheral/net0/virtio-backend", +# "enabled": "true" }, +# "timestamp": { "seconds": 1432121972, "microseconds": 744001 } }, +# +## +{ 'event': 'FAILOVER_STANDBY_CHANGED', + 'data': {'*device': 'str', 'path': 'str', 'enabled': 'bool'} }