From patchwork Wed Oct 7 15:43:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 527332 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 67B1C140D8B for ; Thu, 8 Oct 2015 02:44:15 +1100 (AEDT) Received: from localhost ([::1]:58284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zjqt2-0001ad-VL for incoming@patchwork.ozlabs.org; Wed, 07 Oct 2015 11:44:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjqsF-0000kf-Vj for qemu-devel@nongnu.org; Wed, 07 Oct 2015 11:43:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZjqsE-0006Qh-Py for qemu-devel@nongnu.org; Wed, 07 Oct 2015 11:43:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34199) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjqsE-0006Qa-KB for qemu-devel@nongnu.org; Wed, 07 Oct 2015 11:43:22 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 4D147A10A8; Wed, 7 Oct 2015 15:43:22 +0000 (UTC) Received: from gimli.home (ovpn-113-42.phx2.redhat.com [10.3.113.42]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t97FhLhp028456; Wed, 7 Oct 2015 11:43:21 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Wed, 07 Oct 2015 09:43:21 -0600 Message-ID: <20151007154321.22135.51315.stgit@gimli.home> In-Reply-To: <20151007153840.22135.78451.stgit@gimli.home> References: <20151007153840.22135.78451.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Laurent Vivier , Thomas Huth , David Gibson Subject: [Qemu-devel] [PULL 5/9] vfio: Generalize vfio_listener_region_add failure path 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 From: David Gibson If a DMA mapping operation fails in vfio_listener_region_add() it checks to see if we've already completed initial setup of the container. If so it reports an error so the setup code can fail gracefully, otherwise throws a hw_error(). There are other potential failure cases in vfio_listener_region_add() which could benefit from the same logic, so move it to its own fail: block. Later patches can use this to extend other failure cases to fail as gracefully as possible under the circumstances. Signed-off-by: David Gibson Reviewed-by: Thomas Huth Reviewed-by: Laurent Vivier Signed-off-by: Alex Williamson --- hw/vfio/common.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 1545f62..95a4850 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -399,19 +399,23 @@ static void vfio_listener_region_add(MemoryListener *listener, error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", " "0x%"HWADDR_PRIx", %p) = %d (%m)", container, iova, end - iova, vaddr, ret); + goto fail; + } - /* - * On the initfn path, store the first error in the container so we - * can gracefully fail. Runtime, there's not much we can do other - * than throw a hardware error. - */ - if (!container->initialized) { - if (!container->error) { - container->error = ret; - } - } else { - hw_error("vfio: DMA mapping failed, unable to continue"); + return; + +fail: + /* + * On the initfn path, store the first error in the container so we + * can gracefully fail. Runtime, there's not much we can do other + * than throw a hardware error. + */ + if (!container->initialized) { + if (!container->error) { + container->error = ret; } + } else { + hw_error("vfio: DMA mapping failed, unable to continue"); } }