From: Oleksandr Tyshchenko <olekstysh@gmail.com>
To: xen-devel@lists.xenproject.org
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: [RFC PATCH 4/9] xen/arm: p2m: Update IOMMU mapping whenever possible if page table is not shared
Date: Wed, 15 Mar 2017 22:05:24 +0200 [thread overview]
Message-ID: <1489608329-7275-5-git-send-email-olekstysh@gmail.com> (raw)
In-Reply-To: <1489608329-7275-1-git-send-email-olekstysh@gmail.com>
From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Update IOMMU mapping if the IOMMU doesn't share page table with the CPU.
The best place to do so on ARM is p2m_set_entry(). Use mfn as an indicator
of the required action. If mfn is valid call iommu_map_pages(),
otherwise - iommu_unmap_pages().
Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
---
xen/arch/arm/p2m.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 1fc6ca3..84d3a09 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -979,7 +979,8 @@ static int __p2m_set_entry(struct p2m_domain *p2m,
if ( p2m_valid(orig_pte) && entry->p2m.base != orig_pte.p2m.base )
p2m_free_entry(p2m, orig_pte, level);
- if ( need_iommu(p2m->domain) && (p2m_valid(orig_pte) || p2m_valid(*entry)) )
+ if ( need_iommu(p2m->domain) && iommu_use_hap_pt(d) &&
+ (p2m_valid(orig_pte) || p2m_valid(*entry)) )
rc = iommu_iotlb_flush(p2m->domain, gfn_x(sgfn), 1UL << page_order);
else
rc = 0;
@@ -997,6 +998,9 @@ int p2m_set_entry(struct p2m_domain *p2m,
p2m_type_t t,
p2m_access_t a)
{
+ unsigned long orig_nr = nr;
+ gfn_t orig_sgfn = sgfn;
+ mfn_t orig_smfn = smfn;
int rc = 0;
while ( nr )
@@ -1029,6 +1033,40 @@ int p2m_set_entry(struct p2m_domain *p2m,
nr -= (1 << order);
}
+ if ( likely(!rc) )
+ {
+ /*
+ * It's time to update IOMMU mapping if the latter doesn't
+ * share page table with the CPU. Pass the whole memory block to let
+ * the IOMMU code decide what to do with it.
+ * The reason to update IOMMU mapping outside "while loop" is that
+ * the IOMMU might not support the pages/superpages the CPU can deal
+ * with (4K, 2M, 1G) and as result this will lead to non-optimal
+ * mapping.
+ * Also we assume that the IOMMU mapping should be updated only
+ * if CPU mapping passed successfully.
+ */
+ if ( need_iommu(p2m->domain) && !iommu_use_hap_pt(p2m->domain) )
+ {
+ if ( !mfn_eq(orig_smfn, INVALID_MFN) )
+ {
+ unsigned int flags = p2m_get_iommu_flags(t);
+
+ rc = iommu_map_pages(p2m->domain,
+ gfn_x(orig_sgfn),
+ mfn_x(orig_smfn),
+ orig_nr,
+ flags);
+ }
+ else
+ {
+ rc = iommu_unmap_pages(p2m->domain,
+ gfn_x(orig_sgfn),
+ orig_nr);
+ }
+ }
+ }
+
return rc;
}
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-03-15 20:05 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-15 20:05 [RFC PATCH 0/9] "Non-shared" IOMMU support on ARM Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 1/9] xen/device-tree: Add dt_count_phandle_with_args helper Oleksandr Tyshchenko
2017-03-16 15:39 ` Julien Grall
2017-03-17 11:24 ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 2/9] iommu: Add ability to map/unmap the number of pages Oleksandr Tyshchenko
2017-03-22 15:44 ` Jan Beulich
2017-03-22 18:01 ` Oleksandr Tyshchenko
2017-03-23 9:07 ` Jan Beulich
2017-03-23 12:47 ` Oleksandr Tyshchenko
2017-04-27 16:56 ` Oleksandr Tyshchenko
2017-04-28 6:23 ` Jan Beulich
2017-04-28 10:16 ` Oleksandr Tyshchenko
2017-04-28 10:29 ` Jan Beulich
2017-04-28 10:44 ` Oleksandr Tyshchenko
2017-04-19 17:31 ` Julien Grall
2017-04-21 11:46 ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 3/9] xen/arm: p2m: Add helper to convert p2m type to IOMMU flags Oleksandr Tyshchenko
2017-04-19 17:28 ` Julien Grall
2017-04-21 11:47 ` Oleksandr Tyshchenko
2017-03-15 20:05 ` Oleksandr Tyshchenko [this message]
2017-04-19 17:46 ` [RFC PATCH 4/9] xen/arm: p2m: Update IOMMU mapping whenever possible if page table is not shared Julien Grall
2017-04-21 14:18 ` Oleksandr Tyshchenko
2017-04-21 16:27 ` Julien Grall
2017-04-21 18:44 ` Oleksandr Tyshchenko
2017-04-24 11:41 ` Julien Grall
2017-04-24 16:08 ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 5/9] iommu/arm: Re-define iommu_use_hap_pt(d) as iommu_hap_pt_share Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 6/9] iommu: Pass additional use_iommu argument to iommu_domain_init() Oleksandr Tyshchenko
2017-03-22 15:48 ` Jan Beulich
2017-03-23 12:50 ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 7/9] iommu/arm: Add alloc_page_table platform callback Oleksandr Tyshchenko
2017-03-22 15:49 ` Jan Beulich
2017-03-23 12:57 ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 8/9] iommu: Split iommu_hwdom_init() into arch specific parts Oleksandr Tyshchenko
2017-03-22 15:54 ` Jan Beulich
2017-03-22 18:40 ` Oleksandr Tyshchenko
2017-03-23 9:08 ` Jan Beulich
2017-03-23 12:40 ` Oleksandr Tyshchenko
2017-03-23 13:28 ` Jan Beulich
2017-04-19 18:09 ` Julien Grall
2017-04-21 12:18 ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 9/9] xen: Add use_iommu flag to createdomain domctl Oleksandr Tyshchenko
2017-03-22 15:56 ` Jan Beulich
2017-03-23 16:36 ` Oleksandr Tyshchenko
2017-03-23 17:05 ` Jan Beulich
2017-03-24 11:19 ` Oleksandr Tyshchenko
2017-03-24 11:38 ` Jan Beulich
2017-03-24 13:05 ` Oleksandr Tyshchenko
2017-04-19 18:26 ` Julien Grall
2017-04-21 14:41 ` Oleksandr Tyshchenko
2017-04-25 15:23 ` Wei Liu
2017-04-25 16:07 ` Oleksandr Tyshchenko
2017-04-26 10:05 ` Ian Jackson
2017-04-27 10:41 ` Oleksandr Tyshchenko
2017-03-16 15:31 ` [RFC PATCH 0/9] "Non-shared" IOMMU support on ARM Julien Grall
2017-03-17 11:24 ` Oleksandr Tyshchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1489608329-7275-5-git-send-email-olekstysh@gmail.com \
--to=olekstysh@gmail.com \
--cc=JBeulich@suse.com \
--cc=al1img@gmail.com \
--cc=andr2000@gmail.com \
--cc=andrii.anisov@gmail.com \
--cc=joculator@gmail.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=vlad.babchuk@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).