From patchwork Tue Jul 25 17:26:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 9862563 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 65D7A603F9 for ; Tue, 25 Jul 2017 17:30:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58756286DB for ; Tue, 25 Jul 2017 17:30:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CE31286D1; Tue, 25 Jul 2017 17:30:07 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 09DF1286F6 for ; Tue, 25 Jul 2017 17:30:04 +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 1da3c7-0008VQ-Pz; Tue, 25 Jul 2017 17:27:19 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1da3c6-0008RZ-EN for xen-devel@lists.xenproject.org; Tue, 25 Jul 2017 17:27:18 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id E3/A9-01729-67F77795; Tue, 25 Jul 2017 17:27:18 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDIsWRWlGSWpSXmKPExsVyMfS6o25pfXm kwazvyhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b8IwuZCo7JVpyYUt7AeEysi5GTQ0hgOqPE 5e0sXYxcHCwCL1kk5n+7xwTiSAj0s0q0n+plBKmSEIiTmND1Gcoul1i4fSIbRLeSxOudm8Eah ARmM0l8/TUNrIhNwEBi/7sn7CC2CFDRvVWTwYqYBRoYJS703mQGSQgLJEls6z8O1sAioCrR/e IkE4jNK+AsMe3RPGaIbXISN891gtmcAi4SWz9tY4HY7Cyx/tgB5gmMAgsYGVYxahSnFpWlFuk aWeolFWWmZ5TkJmbm6BoamOrlphYXJ6an5iQmFesl5+duYgSGVj0DA+MOxstb/A4xSnIwKYny ftMtjxTiS8pPqcxILM6ILyrNSS0+xCjDwaEkwbu1FignWJSanlqRlpkDDHKYtAQHj5II7yuQN G9xQWJucWY6ROoUoyXHlSvrvjBxTDmwHUi+mvD/G5MQS15+XqqUOK9PHVCDAEhDRmke3DhYJF 5ilJUS5mVkYGAQ4ilILcrNLEGVf8UozsGoJMy7HmQtT2ZeCdzWV0AHMQEdNGdGKchBJYkIKak GxsObTiy8YHl252qxAFaGL5M2J19Pf7z/uECPnOjBu1fnP89suvgwpdjebM2Z+fdOL7+jJrZ7 e0+oxH5pM5V44TVyq0Q+bk8x2tYrdL9xvmLODLuT71iZZjXuWrtOebNpgZDchEcigV1y56LD0 2IWJGj85JmxI+FtT1j3uus+a7UjzsRqCjk6zVZiKc5INNRiLipOBAB6P1WBvwIAAA== X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1501003637!101583374!1 X-Originating-IP: [209.85.215.65] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7124 invoked from network); 25 Jul 2017 17:27:17 -0000 Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by server-7.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 25 Jul 2017 17:27:17 -0000 Received: by mail-lf0-f65.google.com with SMTP id y15so5623592lfd.5 for ; Tue, 25 Jul 2017 10:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QVvj1IfSWtxEBj5uMW2t6SQBTC+E1OtPkIQjzg+/zAk=; b=IPhplKwbJBxw9kF5Ansnqf0XBhjBN6kq5YEcCTgvbDqjvcUeQotwuZzMG2LcpkNkjP tgbn6lBFKemab8ZqDJ5lKY+xBAN2C4xgsLes0YxMpnJfHv8M2vgsmj4ooBi+I23YFwHX Z3DIcAtr5Nj6YMAbWPCfZ/TCdyokRjUDRpxtdH5+6+iTe9yPbplilywCQqu67koMYjmF fBzzI+UFcNV0QprcR4AwUp0bFhYyZBZWuZxyeyOj0RAr1IekRqaNwOA8BInap+n2Eh3k Ll1hkcqi3S9q3M1fsDptfDKEyb4tF6W0aD+bsj8BMw+Xrqle/UWlISQ/loIbeFOkun5j e2gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QVvj1IfSWtxEBj5uMW2t6SQBTC+E1OtPkIQjzg+/zAk=; b=g18xkXevQcM06gyBHQSiYJK8FtVE+jKaC8zKfWEk8RTfl6dVx1JFvMDZDXbGzzJM9w 2JvigwMO8fa0c04kKkTf560kSl6UxS/egOqHGxrNw2t+jQbwwDfiFuehVhFuZb9cwk4h nsCe1Dt0d9JrGPDxPS1TPVN/+gdFp12pvJi4kq6BC7Ki+d0ZAgGCYqhFQoO3oLjgJ++V gG7lZuQe3BSRphuz27jQ7/wFe3RS+AxZpB8fnr7jJN7lgoTH+Wz90NN1WTQMGFV/Ld6O mJ+36fE1MNlfPVuodwzxnmwCL+POm9nJ4VcCKnowjwz1DeYlOb4wMhKD2dVwg7Ck6YWv tfng== X-Gm-Message-State: AIVw1133S1rj1Rm/qhqYHsg3PyCJ5HSjWqt8bNnb4kXWayyKC0bjUDv7 9S3y8GX7U2qNOG/k X-Received: by 10.25.28.77 with SMTP id c74mr5731716lfc.32.1501003636598; Tue, 25 Jul 2017 10:27:16 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-59.209.223.85.sovam.net.ua. [85.223.209.59]) by smtp.gmail.com with ESMTPSA id v145sm411748lfa.21.2017.07.25.10.27.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Jul 2017 10:27:15 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 25 Jul 2017 20:26:49 +0300 Message-Id: <1501003615-15274-8-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501003615-15274-1-git-send-email-olekstysh@gmail.com> References: <1501003615-15274-1-git-send-email-olekstysh@gmail.com> Cc: Oleksandr Tyshchenko , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v2 07/13] iommu: Make decision about needing IOMMU for hardware domains in advance 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: Oleksandr Tyshchenko The hardware domains require IOMMU to be used in the most cases and a decision to use it is made at hardware domain construction time. But, it is not the best moment for the non-shared IOMMUs due to the necessity of retrieving all mapping which could happen in a period of time between IOMMU per-domain initialization and this moment. So, make a decision about needing IOMMU a bit earlier, in iommu_domain_init(). Having "d->need_iommu" flag set at the early stage we won't skip any IOMMU mapping updates. And as the result the existing in iommu_hwdom_init() code that goes through the list of the pages and tries to retrieve mapping for non-shared IOMMUs won't be needed anymore and can be just dropped. Signed-off-by: Oleksandr Tyshchenko CC: Jan Beulich CC: Julien Grall --- Changes in v1: - Changes in v2: - This is the result of reworking old patch: [PATCH v1 08/10] iommu: Split iommu_hwdom_init() into arch specific parts --- xen/drivers/passthrough/iommu.c | 44 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 19c87d1..f5e5b7e 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -52,7 +52,7 @@ custom_param("iommu", parse_iommu_param); bool_t __initdata iommu_enable = 1; bool_t __read_mostly iommu_enabled; bool_t __read_mostly force_iommu; -bool_t __hwdom_initdata iommu_dom0_strict; +bool_t __read_mostly iommu_dom0_strict; bool_t __read_mostly iommu_verbose; bool_t __read_mostly iommu_workaround_bios_bug; bool_t __read_mostly iommu_igfx = 1; @@ -141,6 +141,15 @@ int iommu_domain_init(struct domain *d, bool use_iommu) if ( !iommu_enabled ) return 0; + if ( is_hardware_domain(d) ) + { + if ( (paging_mode_translate(d) && !iommu_passthrough) || + iommu_dom0_strict ) + use_iommu = 1; + else + use_iommu = 0; + } + hd->platform_ops = iommu_get_ops(); ret = hd->platform_ops->init(d, use_iommu); if ( ret ) @@ -161,8 +170,6 @@ static void __hwdom_init check_hwdom_reqs(struct domain *d) if ( iommu_passthrough ) panic("Dom0 uses paging translated mode, dom0-passthrough must not be " "enabled\n"); - - iommu_dom0_strict = 1; } void __hwdom_init iommu_hwdom_init(struct domain *d) @@ -175,37 +182,6 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) return; register_keyhandler('o', &iommu_dump_p2m_table, "dump iommu p2m table", 0); - d->need_iommu = !!iommu_dom0_strict; - if ( need_iommu(d) && !iommu_use_hap_pt(d) ) - { - struct page_info *page; - unsigned int i = 0; - int rc = 0; - - page_list_for_each ( page, &d->page_list ) - { - unsigned long mfn = page_to_mfn(page); - unsigned long gfn = mfn_to_gmfn(d, mfn); - unsigned int mapping = IOMMUF_readable; - int ret; - - if ( ((page->u.inuse.type_info & PGT_count_mask) == 0) || - ((page->u.inuse.type_info & PGT_type_mask) - == PGT_writable_page) ) - mapping |= IOMMUF_writable; - - ret = hd->platform_ops->map_pages(d, gfn, mfn, 0, mapping); - if ( !rc ) - rc = ret; - - if ( !(i++ & 0xfffff) ) - process_pending_softirqs(); - } - - if ( rc ) - printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n", - d->domain_id, rc); - } return hd->platform_ops->hwdom_init(d); }