From patchwork Wed Jun 8 08:58:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Xu X-Patchwork-Id: 9163723 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 F289560467 for ; Wed, 8 Jun 2016 09:05:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2B5828345 for ; Wed, 8 Jun 2016 09:05:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D749728392; Wed, 8 Jun 2016 09:05:33 +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 BE36028345 for ; Wed, 8 Jun 2016 09:05:32 +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 1bAZOa-00043Y-K5; Wed, 08 Jun 2016 09:03:28 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bAZOY-00043F-Mn for xen-devel@lists.xen.org; Wed, 08 Jun 2016 09:03:26 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id EA/15-32412-E5FD7575; Wed, 08 Jun 2016 09:03:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNLMWRWlGSWpSXmKPExsVywNwkQjf2fni 4wf2TmhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aJLRdZCo4LVfR/m8HawDiJr4uRk0NIoFJi 6bnZzCC2hACvxJFlM1ghbH+JtQues0LU1Ejs2bSGBcRmE1CRmNH8jh3EFhGQlrj2+TJjFyMXB 7NAI6NE68fZQA0cHMICPhIvD+SA1LAIqEo8W36BEcTmFXCUaFx2mR1ivoLEsi9rmUHKOQWcJL YeK4VY5SixbfcTlgmMvAsYGVYxqhenFpWlFula6iUVZaZnlOQmZuboGhqY6uWmFhcnpqfmJCY V6yXn525iBAYCAxDsYFzb6nyIUZKDSUmUV9E9PFyILyk/pTIjsTgjvqg0J7X4EKMMB4eSBO+u e0A5waLU9NSKtMwcYEjCpCU4eJREeKVA0rzFBYm5xZnpEKlTjIpS4ryiIAkBkERGaR5cGywOL jHKSgnzMgIdIsRTkFqUm1mCKv+KUZyDUUmYdwrIFJ7MvBK46a+AFjMBLV5+BGxxSSJCSqqBsf 6p39wf7t0THe7OTZ61epvAgYbfSY7ll7wfH248dr42dml+jUupxA+5/8uv35x8M2Ci/QLR1f9 u7LiWqrRfQ777Tre2fFbfmqBiWUvnIw9XNJ0yYni98cBPu1eOhtknqlJj3GaUSTfOeOArs0Ti 7M0vm9VPG2sdMV9rq5HC86nR9/dGVpF8MSWW4oxEQy3mouJEABxe17R+AgAA X-Env-Sender: quan.xu@intel.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1465376603!7391024!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 54906 invoked from network); 8 Jun 2016 09:03:25 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-14.tower-206.messagelabs.com with SMTP; 8 Jun 2016 09:03:25 -0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 08 Jun 2016 02:03:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,438,1459839600"; d="scan'208";a="983223870" Received: from xen-commits.sh.intel.com ([10.239.82.178]) by fmsmga001.fm.intel.com with ESMTP; 08 Jun 2016 02:03:24 -0700 From: "Xu, Quan" To: xen-devel@lists.xen.org Date: Wed, 8 Jun 2016 16:58:54 +0800 Message-Id: <1465376344-28290-2-git-send-email-quan.xu@intel.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1465376344-28290-1-git-send-email-quan.xu@intel.com> References: <1465376344-28290-1-git-send-email-quan.xu@intel.com> Cc: Kevin Tian , dario.faggioli@citrix.com, Jan Beulich , Quan Xu Subject: [Xen-devel] [PATCH v7 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)