From patchwork Mon Jun 13 15:17:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Xu X-Patchwork-Id: 9173413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A36860573 for ; Mon, 13 Jun 2016 15:24:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B37420410 for ; Mon, 13 Jun 2016 15:24:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FE3E262AE; Mon, 13 Jun 2016 15:24:08 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0757320410 for ; Mon, 13 Jun 2016 15:24:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCTgo-00042u-19; Mon, 13 Jun 2016 15:22:10 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCTgm-00042H-Lw for xen-devel@lists.xen.org; Mon, 13 Jun 2016 15:22:08 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id E0/CF-30266-0AFCE575; Mon, 13 Jun 2016 15:22:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsVywNwkQnf++bh wg4fLdSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1owTWy6yFBwXquj/NoO1gXESXxcjJ4eQQIXE jeZ3LCC2hACvxJFlM1ghbH+Je/dWMULU1Egc61wKZrMJqEjMaH7HDmKLCEhLXPt8GSjOxcEs0 Mgo0fpxNlizsICPRPOelWANLAKqEt+an4E18Ao4Sjzq2cAEsUBBYtmXtcwgNqeAk8TmqY1MEM scJRacnsA+gZF3ASPDKkb14tSistQiXSO9pKLM9IyS3MTMHF1DAzO93NTi4sT01JzEpGK95Pz cTYzAYGAAgh2My/46HWKU5GBSEuU9dTguXIgvKT+lMiOxOCO+qDQntfgQowwHh5IEb+85oJxg UWp6akVaZg4wLGHSEhw8SiK8k88CpXmLCxJzizPTIVKnGBWlxHlrQPoEQBIZpXlwbbBYuMQoK yXMywh0iBBPQWpRbmYJqvwrRnEORiVhiCk8mXklcNNfAS1mAlrMsS8aZHFJIkJKqoGx0rrEa5 X0110l9z9sbz42W/JEXOAeQ/GdZwu7Pin9b66Y1/ipqTNHd8HJqKIUw/2Ba9pyI4T/r7x8RSp y8s/Uu6rTNp9PYu56sH6DYt6XNZq9qWbWTzdqhHM4WN9u9ylcmxa3YsHu5RE+ooqSL2+p2paL HIx02WcU2+hy/NHqI5s8c7Jm8uxTYinOSDTUYi4qTgQA3xPNMIACAAA= X-Env-Sender: quan.xu@intel.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1465831326!12625554!2 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52887 invoked from network); 13 Jun 2016 15:22:07 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-4.tower-21.messagelabs.com with SMTP; 13 Jun 2016 15:22:07 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP; 13 Jun 2016 08:21:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,466,1459839600"; d="scan'208";a="996644778" Received: from xen-commits.sh.intel.com ([10.239.82.178]) by orsmga002.jf.intel.com with ESMTP; 13 Jun 2016 08:21:51 -0700 From: "Xu, Quan" To: xen-devel@lists.xen.org Date: Mon, 13 Jun 2016 23:17:08 +0800 Message-Id: <1465831038-43005-2-git-send-email-quan.xu@intel.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1465831038-43005-1-git-send-email-quan.xu@intel.com> References: <1465831038-43005-1-git-send-email-quan.xu@intel.com> Cc: Kevin Tian , dario.faggioli@citrix.com, Jan Beulich , Quan Xu Subject: [Xen-devel] [PATCH v8 01/11] IOMMU: handle IOMMU mapping and unmapping failures X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Quan Xu Treat IOMMU mapping and unmapping failures as a fatal to the DomU If IOMMU mapping and unmapping failed, crash the DomU and propagate the error up to the call trees. No spamming of the log can occur. For DomU, we avoid logging any message for already dying domains. For Dom0, that'll still be more verbose than we'd really like, but it at least wouldn't outright flood the console. Signed-off-by: Quan Xu Reviewed-by: Kevin Tian Reviewed-by: Jan Beulich CC: Jan Beulich CC: Kevin Tian --- xen/drivers/passthrough/iommu.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 9d104d2..673e126 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -240,21 +240,47 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, unsigned int flags) { const struct domain_iommu *hd = dom_iommu(d); + int rc; if ( !iommu_enabled || !hd->platform_ops ) return 0; - return hd->platform_ops->map_page(d, gfn, mfn, flags); + rc = hd->platform_ops->map_page(d, gfn, mfn, flags); + if ( unlikely(rc) ) + { + if ( !d->is_shutting_down && printk_ratelimit() ) + printk(XENLOG_ERR + "d%d: IOMMU mapping gfn %#lx to mfn %#lx failed: %d\n", + d->domain_id, gfn, mfn, rc); + + if ( !is_hardware_domain(d) ) + domain_crash(d); + } + + return rc; } int iommu_unmap_page(struct domain *d, unsigned long gfn) { const struct domain_iommu *hd = dom_iommu(d); + int rc; if ( !iommu_enabled || !hd->platform_ops ) return 0; - return hd->platform_ops->unmap_page(d, gfn); + rc = hd->platform_ops->unmap_page(d, gfn); + if ( unlikely(rc) ) + { + if ( !d->is_shutting_down && printk_ratelimit() ) + printk(XENLOG_ERR + "d%d: IOMMU unmapping gfn %#lx failed: %d\n", + d->domain_id, gfn, rc); + + if ( !is_hardware_domain(d) ) + domain_crash(d); + } + + return rc; } static void iommu_free_pagetables(unsigned long unused)