xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Oleksandr Tyshchenko <olekstysh@gmail.com>
To: Xen Devel <xen-devel@lists.xen.org>
Cc: Julien Grall <julien.grall@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Jan Beulich <JBeulich@suse.com>
Subject: Unshared IOMMU issues
Date: Wed, 15 Feb 2017 17:52:26 +0200	[thread overview]
Message-ID: <CAPD2p-kjGW-e9t_NcuPYG9za0YeuQhu2YvHd0wRLuLfeCVzDiQ@mail.gmail.com> (raw)

Hi, all.

As it was suggested by Julien in IRC I open this thread.

Currently, I am trying to add support for IPMMU in Xen.
It is VMSA-compatible IOMMU that integrated in the newest Renesas SoCs (ARM).
This IPMMU can't share the page table with the CPU since it uses
stage-1 page table
unlike the CPU that uses stage-2.
So, the IPMMU driver has own page table inside it and maintains them
like other "unshared IOMMU" drivers usually do.

For passing all mapping updates via IOMMU I slightly
modified P2M code (p2m_set_entry) on ARM to call iommu_map_page/iommu_unmap_page
if following (need_iommu(p2m->domain) &&
!iommu_use_hap_pt(p2m->domain)) is true.
I even optimized a bit by adding iommu_map_pages/iommu_unmap_pages API
and map_pages/unmap_pages flatform ops
for passing the whole memory block (nr pages) to the IOMMU code. But
it is not scope of this thread.

I faced several generic problems that had prevented me from making
IPMMU driver (but it might be another "unshared IOMMU" driver) happy
inside XEN on ARM.
Most of them I have already resolved somehow just to see that it
worked out well for me, but I am still have doubts about how to do it
in a right way.

So, for allowing P2M core to update IOMMU mapping from the first
"set_entry" and for "unshared IOMMU" driver to be ready to handle
IOMMU mapping updates
I do two things:
1. I always allocate IOMMU page table in iommu_domain_init() for every
domain even this domain won't have any assigned devices in future.
The main reason why I do so is not to skip any IOMMU mapping updates
from P2M code (RAM, MMIOs, etc). The IOMMU driver has to be ready for
processing
IOMMU mapping updates from the *very beginning*.
Of course, the IOMMU page table will be completely deleted in iommu_teardown().
But, anyway allocating IOMMU page table if it won't be really used in
domain looks not good.
Although there is an arch_iommu_populate_page_table() solution that
could help in a such situation,
but it does not look suitable for ARM because we have no way to
translate a MFN to a GFN as Julien had noticed me in IRC.

2. Another action I do is to explicitly set need_iommu flag during
arch_iommu_domain_init() call in ARM part if following
 (iommu_enabled && !is_hardware_domain(d) && !iommu_use_hap_pt(d)) is true.
I do that since in case of domU need_iommu flag is set during device
assignment, but it is too late. For dom0 we force need_iommu flag.
There are many mapping updates to P2M by the time the first device
will have been assigned.
I see the way how this action can be dropped. For example, don't rely
on need_iommu flag before updating IOMMU mapping from P2M,
check for iommu_enabled flag instead.

I think, but I am not 100% sure that we could avoid actions above if
we would have knowledge about device assignment for particular
domain before making any updates in P2M.

Could you please suggest me a right way in resolving such problems?

-- 
Regards,

Oleksandr Tyshchenko

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

             reply	other threads:[~2017-02-15 15:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-15 15:52 Oleksandr Tyshchenko [this message]
2017-02-15 16:22 ` Unshared IOMMU issues Jan Beulich
2017-02-15 17:43   ` Oleksandr Tyshchenko
2017-02-16  9:36     ` Jan Beulich
2017-02-16 15:02       ` Oleksandr Tyshchenko
2017-02-16 15:52         ` Jan Beulich
2017-02-16 16:11           ` Julien Grall
2017-02-16 16:34             ` Jan Beulich
2017-02-16 18:09               ` Julien Grall
2017-02-16 18:58                 ` Stefano Stabellini
2017-02-17  7:43                 ` Jan Beulich
2017-02-17 15:25                   ` Julien Grall
2017-02-17 20:20                     ` Oleksandr Tyshchenko
2017-02-20  8:31                       ` Julien Grall
2017-02-21 10:39                         ` Oleksandr Tyshchenko
2017-02-22 11:39                           ` Julien Grall
2017-02-22 11:59                             ` 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=CAPD2p-kjGW-e9t_NcuPYG9za0YeuQhu2YvHd0wRLuLfeCVzDiQ@mail.gmail.com \
    --to=olekstysh@gmail.com \
    --cc=JBeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xen.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).