From patchwork Mon Oct 17 19:53:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 683372 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 3syTzg4dRvz9sfH for ; Tue, 18 Oct 2016 07:18:23 +1100 (AEDT) Received: from localhost ([::1]:35713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwEMW-0002lZ-8P for incoming@patchwork.ozlabs.org; Mon, 17 Oct 2016 16:18:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwDy7-0004um-5k for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:53:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwDy6-0008RU-5N for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:53:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwDy5-0008Qv-Ta for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:53:06 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21D59C04B924 for ; Mon, 17 Oct 2016 19:53:05 +0000 (UTC) Received: from gimli.home (ovpn-116-107.phx2.redhat.com [10.3.116.107]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9HJr4ck028132; Mon, 17 Oct 2016 15:53:04 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Mon, 17 Oct 2016 13:53:04 -0600 Message-ID: <20161017195302.17307.20082.stgit@gimli.home> In-Reply-To: <20161017194945.17307.78340.stgit@gimli.home> References: <20161017194945.17307.78340.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 17 Oct 2016 19:53:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/19] vfio: Pass an error object to vfio_get_group 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: Eric Auger , Markus Armbruster Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger Pass an error object to prepare for migration to VFIO-PCI realize. For the time being let's just simply report the error in vfio platform's vfio_base_device_init(). A subsequent patch will duly propagate the error up to vfio_platform_realize. Signed-off-by: Eric Auger Reviewed-by: Markus Armbruster Signed-off-by: Alex Williamson --- hw/vfio/common.c | 24 ++++++++++++------------ hw/vfio/pci.c | 3 +-- hw/vfio/platform.c | 11 ++++++++--- include/hw/vfio/vfio-common.h | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 85a7759..90b1ebb 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1123,12 +1123,11 @@ static void vfio_disconnect_container(VFIOGroup *group) } } -VFIOGroup *vfio_get_group(int groupid, AddressSpace *as) +VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp) { VFIOGroup *group; char path[32]; struct vfio_group_status status = { .argsz = sizeof(status) }; - Error *err = NULL; QLIST_FOREACH(group, &vfio_group_list, next) { if (group->groupid == groupid) { @@ -1136,8 +1135,8 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as) if (group->container->space->as == as) { return group; } else { - error_report("vfio: group %d used in multiple address spaces", - group->groupid); + error_setg(errp, "group %d used in multiple address spaces", + group->groupid); return NULL; } } @@ -1148,28 +1147,29 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as) snprintf(path, sizeof(path), "/dev/vfio/%d", groupid); group->fd = qemu_open(path, O_RDWR); if (group->fd < 0) { - error_report("vfio: error opening %s: %m", path); + error_setg_errno(errp, errno, "failed to open %s", path); goto free_group_exit; } if (ioctl(group->fd, VFIO_GROUP_GET_STATUS, &status)) { - error_report("vfio: error getting group status: %m"); + error_setg_errno(errp, errno, "failed to get group %d status", groupid); goto close_fd_exit; } if (!(status.flags & VFIO_GROUP_FLAGS_VIABLE)) { - error_report("vfio: error, group %d is not viable, please ensure " - "all devices within the iommu_group are bound to their " - "vfio bus driver.", groupid); + error_setg(errp, "group %d is not viable", groupid); + error_append_hint(errp, + "Please ensure all devices within the iommu_group " + "are bound to their vfio bus driver.\n"); goto close_fd_exit; } group->groupid = groupid; QLIST_INIT(&group->device_list); - if (vfio_connect_container(group, as, &err)) { - error_reportf_err(err, "vfio: failed to setup container for group %d", - groupid); + if (vfio_connect_container(group, as, errp)) { + error_prepend(errp, "failed to setup container for group %d: ", + groupid); goto close_fd_exit; } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 3d84126..fdb0616 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2563,9 +2563,8 @@ static int vfio_initfn(PCIDevice *pdev) trace_vfio_initfn(vdev->vbasedev.name, groupid); - group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev)); + group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev), &err); if (!group) { - error_setg(&err, "failed to get group %d", groupid); ret = -ENOENT; goto error; } diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index a559e7b..7bf525b 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -552,6 +552,7 @@ static int vfio_base_device_init(VFIODevice *vbasedev) ssize_t len; struct stat st; int groupid; + Error *err = NULL; int ret; /* @sysfsdev takes precedence over @host */ @@ -592,10 +593,10 @@ static int vfio_base_device_init(VFIODevice *vbasedev) trace_vfio_platform_base_device_init(vbasedev->name, groupid); - group = vfio_get_group(groupid, &address_space_memory); + group = vfio_get_group(groupid, &address_space_memory, &err); if (!group) { - error_report("vfio: failed to get group %d", groupid); - return -ENOENT; + ret = -ENOENT; + goto error; } QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { @@ -619,6 +620,10 @@ static int vfio_base_device_init(VFIODevice *vbasedev) vfio_put_group(group); } +error: + if (err) { + error_reportf_err(err, ERR_PREFIX, vbasedev->name); + } return ret; } diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b26b6cf..286fa31 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -155,7 +155,7 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled); void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); -VFIOGroup *vfio_get_group(int groupid, AddressSpace *as); +VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp); void vfio_put_group(VFIOGroup *group); int vfio_get_device(VFIOGroup *group, const char *name, VFIODevice *vbasedev);