From patchwork Wed May 18 08:08:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Xu X-Patchwork-Id: 9116751 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4B1BC9FC87 for ; Wed, 18 May 2016 08:14:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E30D20123 for ; Wed, 18 May 2016 08:14:30 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 8665D202EC for ; Wed, 18 May 2016 08:14:29 +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 1b2wai-0004ge-La; Wed, 18 May 2016 08:12:28 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b2wag-0004gB-SN for xen-devel@lists.xen.org; Wed, 18 May 2016 08:12:26 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id C2/7F-03443-AE32C375; Wed, 18 May 2016 08:12:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVywNykQvelsk2 4wfnNyhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8ba7gvsBa8FK9Y1X2NtYDzI28XIySEkUCGx YtJVNhBbQoBX4siyGawQtr/E6k2vWSBqaiQ6d+9jBrHZBBQlNlxczgRiiwhIS1z7fJmxi5GLg 1mgkVGi9eNssGZhAR+JbY3/wIpYBFQlfm6+BtbMK+Ao8brvPQvEAgWJZV/WgsU5BZwkViycwA 6xzFFi/vJpzBMYeRcwMqxi1ChOLSpLLdI1NNVLKspMzyjJTczM0TU0MNbLTS0uTkxPzUlMKtZ Lzs/dxAgMBwYg2MG4ZrvnIUZJDiYlUd6t8jbhQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4byoB 5QSLUtNTK9Iyc4CBCZOW4OBREuE1AQanEG9xQWJucWY6ROoUo6KUOO9tkD4BkERGaR5cGywaL jHKSgnzMgIdIsRTkFqUm1mCKv+KUZyDUUmY9x/IFJ7MvBK46a+AFjMBLb4lBra4JBEhJdXAGK O/jyntbeGe8LipdXv8tBb8rFy9IHNxI+PFC48fnZ7SMTfZqVlxtkj15qCdEbaOsb4LRT/qbli Y0xvldiP1CJ/wkgUGV1g3HrGvjzkimcuWx/+du6th1+X6lmX9AV88BU0NT5tZXknIr7Pg09/U 9e7jPru4aXPZD1+zjam1dWaUvzXnleo3JZbijERDLeai4kQA/eVQlIECAAA= X-Env-Sender: quan.xu@intel.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1463559142!40094725!3 X-Originating-IP: [192.55.52.120] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26710 invoked from network); 18 May 2016 08:12:25 -0000 Received: from mga04.intel.com (HELO mga04.intel.com) (192.55.52.120) by server-13.tower-31.messagelabs.com with SMTP; 18 May 2016 08:12:25 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP; 18 May 2016 01:12:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,328,1459839600"; d="scan'208";a="979407846" Received: from xen-commits.sh.intel.com ([10.239.82.178]) by orsmga002.jf.intel.com with ESMTP; 18 May 2016 01:12:23 -0700 From: Quan Xu To: xen-devel@lists.xen.org Date: Wed, 18 May 2016 16:08:23 +0800 Message-Id: <1463558911-98187-3-git-send-email-quan.xu@intel.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1463558911-98187-1-git-send-email-quan.xu@intel.com> References: <1463558911-98187-1-git-send-email-quan.xu@intel.com> Cc: Kevin Tian , dario.faggioli@citrix.com, Jan Beulich , Quan Xu Subject: [Xen-devel] [PATCH v5 02/10] 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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 --- xen/drivers/passthrough/iommu.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 9d104d2..7c70306 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -240,21 +240,49 @@ 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 mfn %#lx failed %d.", + 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.", + d->domain_id, gfn, rc); + + if ( !is_hardware_domain(d) ) + domain_crash(d); + } + + return rc; } static void iommu_free_pagetables(unsigned long unused)