From patchwork Tue May 31 13:57:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Xu X-Patchwork-Id: 9144923 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 20DED60761 for ; Tue, 31 May 2016 14:06:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12FD51FF27 for ; Tue, 31 May 2016 14:06:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06F52272D8; Tue, 31 May 2016 14:06:25 +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 CA3501FF27 for ; Tue, 31 May 2016 14:06:23 +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 1b7kGD-0000gR-MT; Tue, 31 May 2016 14:03:09 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b7kGC-0000g7-Gu for xen-devel@lists.xen.org; Tue, 31 May 2016 14:03:08 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id EB/9C-06230-B999D475; Tue, 31 May 2016 14:03:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRWlGSWpSXmKPExsXS1tYhoTt7pm+ 4weJ3yhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aZFQ4FS4QrJl2axtrAeJmvi5GTQ0igUmLx hl5GEFtCgFfiyLIZrBC2v8TtPesYIWpqJJ4faWQCsdkEVCRmNL9jB7FFBKQlrn2+DFTDxcEs0 Mgo0fpxNlizsICPxO/GNSwgNouAqsSW95vAbF4BB4nPZxewQCxQkFj2ZS0ziM0p4Chxof8cE8 QyB4mHX34yTWDkXcDIsIpRvTi1qCy1SNdQL6koMz2jJDcxM0fX0MBMLze1uDgxPTUnMalYLzk /dxMjMBQYgGAH487nTocYJTmYlER5H2b7hgvxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4D03HSgn WJSanlqRlpkDDEqYtAQHj5II72uQNG9xQWJucWY6ROoUo6KUOO9WkIQASCKjNA+uDRYJlxhlp YR5GYEOEeIpSC3KzSxBlX/FKM7BqCTMewFkCk9mXgnc9FdAi5mAFsdn+IAsLklESEk1MEb99J X+XTfz7eS71x/atgovmNRpsrqc+ZblphwhRo1lc/fzn1JfKmrK+/iI4/qfU8WWTJ6QWP/UyfL U7a0FYsXsK1x519QdVvq0Wdh6y9f7q7nNW63Ot2/5eSng8tnuS2sjAyfybOr68Ou60t+gpYY9 4fNiYtd6tR75rJfbpdU9afFGo39XvFYrsRRnJBpqMRcVJwIAqxqtSX8CAAA= X-Env-Sender: quan.xu@intel.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1464703385!2815320!2 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 43863 invoked from network); 31 May 2016 14:03:07 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-2.tower-21.messagelabs.com with SMTP; 31 May 2016 14:03:07 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 31 May 2016 07:01:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,395,1459839600"; d="scan'208";a="113439892" Received: from xen-commits.sh.intel.com ([10.239.82.178]) by fmsmga004.fm.intel.com with ESMTP; 31 May 2016 07:01:46 -0700 From: "Xu, Quan" To: xen-devel@lists.xen.org Date: Tue, 31 May 2016 21:57:26 +0800 Message-Id: <1464703056-4741-2-git-send-email-quan.xu@intel.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1464703056-4741-1-git-send-email-quan.xu@intel.com> References: <1464703056-4741-1-git-send-email-quan.xu@intel.com> Cc: Kevin Tian , dario.faggioli@citrix.com, Jan Beulich , Quan Xu Subject: [Xen-devel] [Patch v6 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 CC: Jan Beulich CC: Kevin Tian v6: 1. Enhance commit message, changing "No spamming can occur" to "No spamming of the log can occur". 2. Enhance log messages. Reviewed-by: Jan Beulich --- 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)