From patchwork Wed Mar 15 20:05:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 9626581 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 40B9F604A9 for ; Wed, 15 Mar 2017 20:10:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FCA82856F for ; Wed, 15 Mar 2017 20:10:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2485228674; Wed, 15 Mar 2017 20:10:31 +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 2042028675 for ; Wed, 15 Mar 2017 20:10:30 +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 1coFBK-00008C-63; Wed, 15 Mar 2017 20:06:02 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coFBJ-00005C-4B for xen-devel@lists.xenproject.org; Wed, 15 Mar 2017 20:06:01 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id AE/48-05091-8AE99C85; Wed, 15 Mar 2017 20:06:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPIsWRWlGSWpSXmKPExsXiVRvkpLt83sk IgxN9+hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8a/78YFO9QqPqz7yNTAuF+2i5GLQ0hgOqPE 1atbGEEcFoGXLBI7nrUDOZwcEgL9rBIbnmZD2DESTQ9b2bsYOYDsaonX+ytAwkICShKvd25mg hg0h0ni9OUZbCAJNgEDif3vnrCD2CJARfdWTQYrYhY4wyjxeRGIw8khLBAo8a33LFgRi4CqxP q3n8DivAJOEvu6P7FBLJaTuHmukxnE5hRwlnjxtIUVYrOTxLQFJ5knMAosYGRYxahRnFpUllq ka2Sql1SUmZ5RkpuYmaNraGCsl5taXJyYnpqTmFSsl5yfu4kRGFj1DAyMOxhbT/gdYpTkYFIS 5VXJPRkhxJeUn1KZkVicEV9UmpNafIhRhoNDSYK3Zy5QTrAoNT21Ii0zBxjiMGkJDh4lEV4fk DRvcUFibnFmOkTqFKMux4f+w2+YhFjy8vNSpcR5j4IUCYAUZZTmwY2AxdslRlkpYV5GBgYGIZ 6C1KLczBJU+VeM4hyMSsK85iBTeDLzSuA2vQI6ggnoiLcfToAcUZKIkJJqYCwOM+N8vF/66I8 PN+6a+jXPnPzZ4lLbH/nWyg0rpfomdvooXJzutTGuYIZ9YpXRVrkQ3WWpBmKx1ZfiV1RyLDuo 6XbQu29aumRh4dfuJ7vly3//dwlbOc/9nkeKYqg4TwDj8TSeulki9r1tB3zCTbs+yK55PmXKQ ud7kx59vrTBkTHsXdFMPSWW4oxEQy3mouJEAG4uDXuyAgAA X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1489608359!82899160!1 X-Originating-IP: [74.125.82.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13292 invoked from network); 15 Mar 2017 20:05:59 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-7.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 15 Mar 2017 20:05:59 -0000 Received: by mail-wm0-f66.google.com with SMTP id x124so810037wmf.3 for ; Wed, 15 Mar 2017 13:05:59 -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=ZBDeXsGaTSRURjFPiJ3hVHjetcGYlQZnKSqgrHqG4SA=; b=VdUqwzd3jKiraChibxOLc+YEbW4fLyB3ktUEveLoWr6OIDtnOhMNlRkM58li/FqlFv FCZTCtrxH3tQM+kFg/VLND2RudHlBQKy3DznirEtUes0FhPS37G9oa/+4ONXAur1Ay/V FhJKvC46N6O7JlfR/Qrme+t0E7GvaYShgpeILhRqYHwKo7tqnvOJR6leCcPzfDO5v8dK 0H7trNQaXBAQJn6JEA9pwD5uvBD5eYdUq80dWcZK4c1IxZk8JbD6h93D8nMBifrQhG/I UFpFWdwYeQyETMlIDXjhg0dG9A0aI1bVMdF7gfVCU+8F+/8qrOJYPsM4q1Yk00XM3jwU I03A== 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=ZBDeXsGaTSRURjFPiJ3hVHjetcGYlQZnKSqgrHqG4SA=; b=IB4kCEv1J0dqAHpAxHIxNcX/yWcC9gOehefjHg2L4PzzZBAirgoiT9q1U4k7v9GSFp h0Ln55yMVV7WtmZlPykJm3Ox6GwhWqJ1g/A43BE/elUTICpNZw74CT5cT45Ar/t2hk4c sNv+e0pqplAffXyg51z9WkcugZ7YNf2oZ3hJS0VzsJ9j2D4kjBMFaqSCVTlf/ZJ+2R/j nPsSndRJwXTOnlcaFiNGsYmE+m36l6xm2RdprxKadOx1TqDLPIXlk3FScex9jRd7+wDQ 6iZHyE2DAJdSFqy3rTH2rDv+u9l9mBE8t7nNUvbVYqoGR6qGDVWQvDYa3s2iHJTZKJ6U hX7Q== X-Gm-Message-State: AFeK/H3U6tqQxBkqgcqMSMcr14iSBSciiz9nfGKVy0yMKQ6+JgiquhupN8bx/4S6lAhCbA== X-Received: by 10.28.217.136 with SMTP id q130mr5707936wmg.132.1489608359344; Wed, 15 Mar 2017 13:05:59 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id b130sm1651516wma.17.2017.03.15.13.05.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Mar 2017 13:05:58 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Wed, 15 Mar 2017 22:05:28 +0200 Message-Id: <1489608329-7275-9-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489608329-7275-1-git-send-email-olekstysh@gmail.com> References: <1489608329-7275-1-git-send-email-olekstysh@gmail.com> Cc: sstabellini@kernel.org, vlad.babchuk@gmail.com, al1img@gmail.com, andrii.anisov@gmail.com, olekstysh@gmail.com, andr2000@gmail.com, julien.grall@arm.com, JBeulich@suse.com, joculator@gmail.com Subject: [Xen-devel] [RFC PATCH 8/9] iommu: Split iommu_hwdom_init() into arch specific parts 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 Logic on ARM was changed a bit. Taking into account that we are here because we have the IOMMU that doesn't share page table with the CPU and need_iommu flag is set just call arch_iommu_populate_page_table() to allow unshared IOMMU to allocate resources. No functional change for x86 part. Signed-off-by: Oleksandr Tyshchenko --- xen/drivers/passthrough/arm/iommu.c | 7 +++++++ xen/drivers/passthrough/iommu.c | 30 +----------------------------- xen/drivers/passthrough/x86/iommu.c | 36 ++++++++++++++++++++++++++++++++++++ xen/include/xen/iommu.h | 1 + 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index f132032..2198723 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -19,6 +19,7 @@ #include #include #include +#include static const struct iommu_ops *iommu_ops; @@ -59,6 +60,12 @@ void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d) return; } +void __hwdom_init arch_iommu_hwdom_init(struct domain *d) +{ + if ( need_iommu(d) && !iommu_use_hap_pt(d) ) + arch_iommu_populate_page_table(d); +} + int arch_iommu_domain_init(struct domain *d) { return iommu_dt_domain_init(d); diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 6c17c59..cfe3bd1 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -177,36 +177,8 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) 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_page(d, gfn, mfn, 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); - } + arch_iommu_hwdom_init(d); return hd->platform_ops->hwdom_init(d); } diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index 69cd6c5..b353449 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -118,6 +118,42 @@ void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d) panic("Presently, iommu must be enabled for PVH hardware domain\n"); } +void __hwdom_init arch_iommu_hwdom_init(struct domain *d) +{ + const struct domain_iommu *hd = dom_iommu(d); + + 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_page(d, gfn, mfn, 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); + } +} + int arch_iommu_domain_init(struct domain *d) { struct domain_iommu *hd = dom_iommu(d); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 3150d7b..43cbb80 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -65,6 +65,7 @@ void arch_iommu_domain_destroy(struct domain *d); int arch_iommu_domain_init(struct domain *d); int arch_iommu_populate_page_table(struct domain *d); void arch_iommu_check_autotranslated_hwdom(struct domain *d); +void arch_iommu_hwdom_init(struct domain *d); int iommu_construct(struct domain *d);