From nobody Sat Sep 28 21:00:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1546883988681673.2029435943754; Mon, 7 Jan 2019 09:59:48 -0800 (PST) Received: from localhost ([127.0.0.1]:36178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggZBa-00026r-HA for importer@patchew.org; Mon, 07 Jan 2019 12:59:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggZ7e-0007B7-7n for qemu-devel@nongnu.org; Mon, 07 Jan 2019 12:55:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggZ7a-0003Ac-9Y for qemu-devel@nongnu.org; Mon, 07 Jan 2019 12:55:34 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ggZ7Y-0002xI-HW for qemu-devel@nongnu.org; Mon, 07 Jan 2019 12:55:28 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x07HsGCr057449; Mon, 7 Jan 2019 17:55:21 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2ptn7qq37k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Jan 2019 17:55:21 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x07HtLFh024016 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 7 Jan 2019 17:55:21 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x07HtKdE030085; Mon, 7 Jan 2019 17:55:20 GMT Received: from ban25x6uut28.us.oracle.com (/10.153.73.28) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Jan 2019 09:55:20 -0800 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=GYSSbM2dP/ffT9saV7ZsC9XarM+4zqBgClXC9DaD8YE=; b=iPxvoqWXTUi3GJsWUG4ny8A6wVObHzemm3OEpd8vi8AW3Slb/TZ+BIw22rZQ5XD564DI lY7xnR7iuZRSr8T3srua/iRkuExwmPFvj4WnzLf+PP3q64s0JMF3RaglmPyphFkDnkqo HOiJgrimIFV5N9W3xdIb4hHFxkGBPLPuaSrA+c9QQLz5u9t+EW5310JTh4tQyPNvD878 QKIhPZPbWZQLzhnvVKpIdip1Ebf7rXMsMcl8+4ZPaZfZ4AXedR/kXLFSI1zmw4UHnmZ7 RM5AtdMEMdI7hBWHMsWySc2uE9GTp7sEswytZspsjKMq7OPd7/QKPNi6NXypEugr/zQ4 CQ== From: Venu Busireddy To: venu.busireddy@oracle.com, "Michael S. Tsirkin" , Marcel Apfelbaum Date: Mon, 7 Jan 2019 12:54:49 -0500 Message-Id: <1546883690-17798-5-git-send-email-venu.busireddy@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1546883690-17798-1-git-send-email-venu.busireddy@oracle.com> References: <1546883690-17798-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-1901070153 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 4/5] vfio-pci: Add FAILOVER_PRIMARY_CHANGED event to shorten downtime during failover 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: Si-Wei Liu , virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Si-Wei Liu When a VF is hotplugged into the guest, datapath switching will be performed immediately, which is sub-optimal in terms of timing, and could end up with substantial network downtime. One of ways to shorten this downtime is to switch the datapath only after the VF is seen to get enabled by guest, indicated by the bus master bit in VF's PCI config space getting enabled. The FAILOVER_PRIMARY_CHANGED event is emitted at that time to indicate this condition. Then management stack can kick off datapath switching upon receiving the event. Signed-off-by: Si-Wei Liu Signed-off-by: Venu Busireddy --- hw/vfio/pci.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++ qapi/net.json | 26 ++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index bd83b58..adcc95a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -34,6 +34,7 @@ #include "pci.h" #include "trace.h" #include "qapi/error.h" +#include "qapi/qapi-events-net.h" =20 #define MSIX_CAP_LENGTH 12 =20 @@ -42,6 +43,7 @@ =20 static void vfio_disable_interrupts(VFIOPCIDevice *vdev); static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled); +static void vfio_failover_notify(VFIOPCIDevice *vdev, bool status); =20 /* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -1170,6 +1172,8 @@ void vfio_pci_write_config(PCIDevice *pdev, { VFIOPCIDevice *vdev =3D PCI_VFIO(pdev); uint32_t val_le =3D cpu_to_le32(val); + bool may_notify =3D false; + bool master_was =3D false; =20 trace_vfio_pci_write_config(vdev->vbasedev.name, addr, val, len); =20 @@ -1180,6 +1184,14 @@ void vfio_pci_write_config(PCIDevice *pdev, __func__, vdev->vbasedev.name, addr, val, len); } =20 + /* Bus Master Enabling/Disabling */ + if (pdev->failover_primary && current_cpu && + range_covers_byte(addr, len, PCI_COMMAND)) { + master_was =3D !!(pci_get_word(pdev->config + PCI_COMMAND) & + PCI_COMMAND_MASTER); + may_notify =3D true; + } + /* MSI/MSI-X Enabling/Disabling */ if (pdev->cap_present & QEMU_PCI_CAP_MSI && ranges_overlap(addr, len, pdev->msi_cap, vdev->msi_cap_size)) { @@ -1235,6 +1247,14 @@ void vfio_pci_write_config(PCIDevice *pdev, /* Write everything to QEMU to keep emulated bits correct */ pci_default_write_config(pdev, addr, val, len); } + + if (may_notify) { + bool master_now =3D !!(pci_get_word(pdev->config + PCI_COMMAND) & + PCI_COMMAND_MASTER); + if (master_was !=3D master_now) { + vfio_failover_notify(vdev, master_now); + } + } } =20 /* @@ -2801,6 +2821,17 @@ static void vfio_unregister_req_notifier(VFIOPCIDevi= ce *vdev) vdev->req_enabled =3D false; } =20 +static void vfio_failover_notify(VFIOPCIDevice *vdev, bool status) +{ + PCIDevice *pdev =3D &vdev->pdev; + const char *n; + gchar *path; + + n =3D pdev->qdev.id ? pdev->qdev.id : vdev->vbasedev.name; + path =3D object_get_canonical_path(OBJECT(vdev)); + qapi_event_send_failover_primary_changed(!!n, n, path, status); +} + static void vfio_realize(PCIDevice *pdev, Error **errp) { VFIOPCIDevice *vdev =3D PCI_VFIO(pdev); @@ -3109,10 +3140,36 @@ static void vfio_instance_finalize(Object *obj) vfio_put_group(group); } =20 +static void vfio_exit_failover_notify(VFIOPCIDevice *vdev) +{ + PCIDevice *pdev =3D &vdev->pdev; + + /* + * Guest driver may not get the chance to disable bus mastering + * before the device object gets to be unrealized. In that event, + * send out a "disabled" notification on behalf of guest driver. + */ + if (pdev->failover_primary && + pdev->bus_master_enable_region.enabled) { + vfio_failover_notify(vdev, false); + } +} + static void vfio_exitfn(PCIDevice *pdev) { VFIOPCIDevice *vdev =3D PCI_VFIO(pdev); =20 + /* + * During the guest reboot sequence, it is sometimes possible that + * the guest may not get sufficient time to complete the entire driver + * removal sequence, near the end of which a PCI config space write to + * disable bus mastering can be intercepted by device. In such cases, + * the FAILOVER_PRIMARY_CHANGED "disable" event will not be emitted. It + * is imperative to generate the event on the guest's behalf if the + * guest fails to make it. + */ + vfio_exit_failover_notify(vdev); + vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); diff --git a/qapi/net.json b/qapi/net.json index 633ac87..a5b8d70 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -757,3 +757,29 @@ ## { 'command': 'query-standby-status', 'data': { '*device': 'str' }, 'returns': ['StandbyStatusInfo'] } + +## +# @FAILOVER_PRIMARY_CHANGED: +# +# Emitted whenever the driver of failover primary is loaded or unloaded +# by the guest. +# +# @device: device name +# +# @path: device path +# +# @enabled: true if driver is loaded thus device is enabled in guest +# +# Since: 3.0 +# +# Example: +# +# <- { "event": "FAILOVER_PRIMARY_CHANGED", +# "data": { "device": "vfio-0", +# "path": "/machine/peripheral/vfio-0" }, +# "enabled": "true" }, +# "timestamp": { "seconds": 1539935213, "microseconds": 753529 } } +# +## +{ 'event': 'FAILOVER_PRIMARY_CHANGED', + 'data': { '*device': 'str', 'path': 'str', 'enabled': 'bool' } }