From patchwork Tue May 19 04:42:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 473712 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EF859140D58 for ; Tue, 19 May 2015 14:45:29 +1000 (AEST) Received: from localhost ([::1]:43921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuZPD-0006Id-Eb for incoming@patchwork.ozlabs.org; Tue, 19 May 2015 00:45:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuZOm-0005XE-Lt for qemu-devel@nongnu.org; Tue, 19 May 2015 00:45:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuZOl-0004IE-9b for qemu-devel@nongnu.org; Tue, 19 May 2015 00:45:00 -0400 Received: from [59.151.112.132] (port=41757 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuZOk-0004Dc-Nk for qemu-devel@nongnu.org; Tue, 19 May 2015 00:44:59 -0400 X-IronPort-AV: E=Sophos;i="5.01,1,1399996800"; d="scan'208";a="92352544" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 19 May 2015 12:48:49 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t4J4goqk004613; Tue, 19 May 2015 12:42:50 +0800 Received: from G08FNSTD131468.g08.fujitsu.local (10.167.226.78) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 19 May 2015 12:44:17 +0800 From: Chen Fan To: Date: Tue, 19 May 2015 12:42:43 +0800 Message-ID: <1bfcb9f3c55f8a4e5652c4bd1c57d3681a45b22e.1432008287.git.chen.fan.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.78] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com Subject: [Qemu-devel] [RFC v7 01/11] vfio: extract vfio_get_hot_reset_info as a single function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org the function is used to get affected devices by bus reset. so here extract it, and can used for aer soon. Signed-off-by: Chen Fan --- hw/vfio/pci.c | 63 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index e0e339a..fe4963f 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2641,6 +2641,48 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos) } } +/* + * return negative with errno, return 0 on success. + * if success, the point of ret_info fill with the affected device reset info. + * + */ +static int vfio_get_hot_reset_info(VFIOPCIDevice *vdev, + struct vfio_pci_hot_reset_info **ret_info) +{ + struct vfio_pci_hot_reset_info *info; + int ret, count; + + *ret_info = NULL; + + info = g_malloc0(sizeof(*info)); + info->argsz = sizeof(*info); + + ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); + if (ret && errno != ENOSPC) { + ret = -errno; + goto error; + } + + count = info->count; + + info = g_realloc(info, sizeof(*info) + + (count * sizeof(struct vfio_pci_dependent_device))); + info->argsz = sizeof(*info) + + (count * sizeof(struct vfio_pci_dependent_device)); + + ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); + if (ret) { + ret = -errno; + goto error; + } + + *ret_info = info; + + ret = 0; +error: + return ret; +} + static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos) { PCIDevice *pdev = &vdev->pdev; @@ -2792,32 +2834,19 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) vfio_pci_pre_reset(vdev); vdev->vbasedev.needs_reset = false; - info = g_malloc0(sizeof(*info)); - info->argsz = sizeof(*info); - - ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); - if (ret && errno != ENOSPC) { - ret = -errno; + ret = vfio_get_hot_reset_info(vdev, &info); + if (ret) { if (!vdev->has_pm_reset) { error_report("vfio: Cannot reset device %04x:%02x:%02x.%x, " "no available reset mechanism.", vdev->host.domain, vdev->host.bus, vdev->host.slot, vdev->host.function); + } else { + error_report("vfio: hot reset info failed: %m"); } goto out_single; } - count = info->count; - info = g_realloc(info, sizeof(*info) + (count * sizeof(*devices))); - info->argsz = sizeof(*info) + (count * sizeof(*devices)); devices = &info->devices[0]; - - ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); - if (ret) { - ret = -errno; - error_report("vfio: hot reset info failed: %m"); - goto out_single; - } - trace_vfio_pci_hot_reset_has_dep_devices(vdev->vbasedev.name); /* Verify that we have all the groups required */