From: Peter Xu <peterx@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm <qemu-arm@nongnu.org>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <rth@twiddle.net>,
"Alex Bennée" <alex.bennee@linaro.org>,
"patches@linaro.org" <patches@linaro.org>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Alex Williamson" <alex.williamson@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 14/27] iommu: Add IOMMU index concept to IOMMU API
Date: Fri, 25 May 2018 10:50:45 +0800 [thread overview]
Message-ID: <20180525025045.GJ12122@xz-mi> (raw)
In-Reply-To: <CAFEAcA9SXirTw=H3wznVZDTmO1OB-LRNJAQ1MsyYm62SqvMqRQ@mail.gmail.com>
On Thu, May 24, 2018 at 11:54:17AM +0100, Peter Maydell wrote:
> On 24 May 2018 at 07:23, Peter Xu <peterx@redhat.com> wrote:
> > On Wed, May 23, 2018 at 12:47:16PM +0100, Peter Maydell wrote:
> >> On 23 May 2018 at 02:06, Peter Xu <peterx@redhat.com> wrote:
> >> > Could you elaborate a bit more on why IOMMU notifier failed to
> >> > corporate when passing in MemTxAttrs? I am not sure I caught the idea
> >> > here, but can we copy the MemTxAttrs into IOMMUTLBEntry when
> >> > translating, then in IOMMU notifiers we can know the attrs (if that is
> >> > what MPC wants)?
> >>
> >> (1) The notifier API lets you register a notifier before you've
> >> called the translate API
> >
> > Yes.
> >
> >> (2) An IOMMUTLBEntry can be valid for more than just the txattrs
> >> that it was passed in (for instance, if an IOMMU doesn't care
> >> about txattrs at all, then the resulting TLB entry is valid for
> >> any txattrs; or if the IOMMU only cares about attrs.secure the
> >> resulting TLB entries are valid for both attrs.user=0 and
> >> attrs.user=1).
> >
> > [1]
> >
> > Yes exactly, that's why I thought copying the txattrs into IOTLB
> > should work.
>
> I'm a bit confused about why the IOMMUTLBEntry is relevant here.
> That's the thing returned from the translate method, so there's
> no point in copying txattrs into it, because the caller by definition
> already had them. At the point where the IOMMU notices a guest
> changed the config, it doesn't have an IOMMUTLBEntry or a set of
> tx attrs.
Yes the txattrs is not for the translate() callers, but for IOMMU
notifiers only. Thanks for the pointer below [1], I think it's very
similar to what Paolo mentioned there at [1], the major difference is
that Paolo suggested to put txattrs into both IOMMUNotify and
memory_region_notify_one(), while my above suggestion is that we can
directly copy it into IOMMUTLBEntry - note that both IOMMUNotify and
memory_region_notify_one will have a IOMMUTLBEntry parameter. Though
I am not 100% clear on Paolo's suggestion on why to add two txattrs
parameters for each function (since I thought all the values in
txattrs to be passed to either IOMMUNotify or memory_region_notify_one
should be valid, so I am not sure why we need to "indicate which
attributes matter (0 = indifferent, 1 = matter)").
>
> >> (3) when the IOMMU calls the notifier because the guest config
> >> changed it doesn't have tx attributes, so it would have to
> >> fabricate some; and the guest config will invalidate transactions
> >> with some combinations of tx attributes and not others.
> >
> > IMHO it doesn't directly matter with what we are discussing now. That
> > IOMMU_NOTIFIER_[UN]MAP flag tells what kind of message would the
> > notifier be interested in from "what kind of mapping it is". IMHO
> > it's not really related to some other attributes when translation
> > happens - in our case, it does not directly related to what txattrs
> > value is. Here as mentioned at [1] above IMHO we can still check this
> > against txattrs in the notifier handler, then we ignore messages that
> > we don't care about. Actually the IOMMU_NOTIFIER_[UN]MAP flags can be
> > removed and we can just do similar things (e.g., we can skip MAP
> > messages if we only care about UNMAP messages), but since it's a
> > general concept and easy to be generalized, so we provided these
> > MAP/UNMAP flags to ease the notifier hooks.
> >
> > In other words, I think we can also add more flags for SECURE or not.
> > However I still don't see a reason (from above three points) on why we
> > can't pass in txattrs directly into translate(), and at the same time
> > we copy the txattrs into IOTLB so that IOMMUTLBEntry can contain some
> > context information. [2]
>
> I'm afraid I really don't understand the design you're proposing
> here. But overall I think the point of divergence is that
> the mapping from "transaction attributes" to "translation contexts"
> (ie, effectively different page tables) is not 1:1. So for instance:
>
> Our current IOMMUs which don't care about txattrs:
>
> [any txattr at all] -> the one and only translation context
>
> An IOMMU which cares about attrs.secure, and also treats
> attrs.unspecified like secure:
> [any txattr with attrs.secure = 1] \-> 'secure' context'
> MEMATTRS_UNSPECIFIED /
>
> [txattrs with secure = 1] -> 'nonsecure' context
(This part is a bit interesting - the "secure" bit is actually flipped
between txattrs and the context...)
>
> An IOMMU which cares about attrs.secure and attrs.user:
> [secure=1,user=1] -> 'secure user' context
> [secure=0,user=1] -> 'ns user' context
> [secure=1,user=0] -> 's priv' context
> [secure=0,user=0] -> 'ns priv' context
>
> The IOMMU index captures this idea that there is not a 1:1
> mapping, so we have a way to think about and refer to the
> actual set of translation contexts that the IOMMU has.
Yes. I'd say I am not really against this iommu_idx idea. My only
worry is that I'm not sure whether that'll be good enough for the
future usage of IOMMU, e.g., the requester ID issue to be discussed
and solved. My understanding is that the txattrs is already a
superset of the iommu_idx concept. Meanwhile, the iommu_idx concept
is not easy to understand. So it'll be nice if we can solve the
problem with what we already have now (no new concept like iommu_idx),
easier to understand, meanwhile it even covers more possibilities in
the future (we can easily generate iommu_idx by txattrs, but not other
way round).
>
> >> As Paolo pointed out you could also implement this by rather
> >> of having an iommu_index concept, instead having some kind
> >> of "here is a mask of which txattrs fields matter, and here's
> >> another parameter with which txattrs fields are affected".
> >> That makes it awkward though to implement "txattrs.unspecified
> >> acts like txattrs.secure == 1" type behaviour, though, which is
> >> easy with an index abstraction layer. It also would be harder
> >> to implement the default 'replay' method, I think.
> >
> > Please refer to my above comment at [2] - I am still confused on why
> > we must use this iommu_idx concept. How about we just introduce
> > IOMMU_NOTIFIER_SECURE (or something similar) and let TCG code register
> > with that? Though for the rest of notifiers we'll need to touch up
> > too to make sure all existing notifiers will still receive all the
> > message, no matter whether it's secure or not.
>
> I think I would definitely prefer not to have the secure/nonsecure
> specific thing in the API. We've got good experience with TCG
> where we abstract away the specifics of what an MMU cares about
> into an mmu_index, and I'd like to keep that approach. Otherwise,
> you immediately get into "and now we need to change the API again
> to handle IOMMUs which care about attrs.user"; and then again
> for attrs.requester_id; and now what about IOMMUs that care
> about both secure and user... Better to have an abstraction so
> that we don't need to keep changing the core code. In particular,
> TCG doesn't know whether it's secure/nonsecure that matters -- that
> is mostly handled by the target-specific parts, and TCG core code
> just passes attributes around.
IMHO the notifier flags are of course extra - we can introduce new
flags, or we can just handle them in the notifier hooks without
touching that part (especially if we copy the txattrs into
IOMMUTLBEntry we don't even need to touch the notifier API). IMHO the
thing that matters more is what we need to pass to the translate() and
whether the iommu_idx concept is a must. I am really fine with either
way to implement the IOMMU notifiers when we can make sure whether
iommu_idx is a must.
Again, I am totally not against the iommu_idx concept - I am just
afraid one day that'll be not enough for us and we still need to
rework on that part.
>
> > I'd also appreciate if you could paste me the link for Paolo's
> > message, since I cannot find it.
>
> This is the one I had in mind:
> https://lists.gnu.org/archive/html/qemu-devel/2018-05/msg03522.html
[1]
Really sorry to chime in so late no matter what; I didn't noticed the
RFC series. These comments are for sure more suitable for RFCs.
>
> >> It will only need to do so for IOMMUs that care about that field.
> >>
> >> (See also the other thread with Eric Auger talking about
> >> maybe caring about requester_id like that. Needing to look
> >> at requester_id is an area I haven't thought too much about,
> >> and it is a bit of an odd one because it's a much larger
> >> space than any of the other parts of the txattrs. In some
> >> cases it ought to be possible to say "requester_id lets
> >> us determine an iommu index, and there are a lot fewer
> >> than 2^16 actual iommu indexes because a lot of the requestor_id
> >> values indicate the same actual iommu translation", I suspect.)
> >
> > AFAIK requester_id will only be the same in very rare cases, for
> > example, when multiple PCI devices (no matter whether it's PCI or
> > PCIe) are under the same PCIe-to-PCI bridge, then all these devices
> > will use the bridge's requester ID as their own. In most cases, each
> > PCIe device will have their own unique requester ID. So it'll be
> > common that requester ID number can be at least equal to the number of
> > devices.
>
> I haven't looked at this, but my understanding is that at the moment
> we do per-device requester_id by having each PCI device get its own
> IOMMUMemoryRegion mapped into its address space. So we'd only need
> to look at requester_id for the case of devices with multiple
> subfunctions(?), and presumably most devices only have a handful
> of those.
Not sure I fully understand this, do you mean that requester ID can
actually be bound to the DMA address space (and the IOMMU memory
regions) for the device? I am not sure, maybe yes...
Though ppassing txattrs (and requester ID) from the translate()
function still seems more reasonable. I assume that looks more like
what the real hardware does - the requester ID should be embeded in
the PCIe packet when sending the DMA request (or page translation
request). And for me the translate() emulates the page translation
requests, that's why passing in txattrs is very easy to understand at
least for me (while the iommu_idx is not easy to understand;
especially the "index" let me think about "which IOMMU is responsible
for this").
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2018-05-25 2:51 UTC|newest]
Thread overview: 114+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-21 14:03 [Qemu-devel] [PATCH 00/27] iommu: support txattrs, support TCG execution, implement TZ MPC Peter Maydell
2018-05-21 14:03 ` [Qemu-devel] [PATCH 01/27] memory.h: Improve IOMMU related documentation Peter Maydell
2018-05-21 19:46 ` Richard Henderson
2018-05-22 9:16 ` Alex Bennée
2018-05-22 11:40 ` Auger Eric
2018-05-21 14:03 ` [Qemu-devel] [PATCH 02/27] Make tb_invalidate_phys_addr() take a MemTxAttrs argument Peter Maydell
2018-05-21 23:54 ` Richard Henderson
2018-05-22 9:21 ` Alex Bennée
2018-05-21 14:03 ` [Qemu-devel] [PATCH 03/27] Make address_space_translate{, _cached}() " Peter Maydell
2018-05-22 10:49 ` Alex Bennée
2018-05-22 16:12 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 04/27] Make address_space_map() " Peter Maydell
2018-05-22 10:49 ` Alex Bennée
2018-05-22 16:13 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 05/27] Make address_space_access_valid() " Peter Maydell
2018-05-22 10:50 ` Alex Bennée
2018-05-22 16:14 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 06/27] Make flatview_extend_translation() " Peter Maydell
2018-05-22 10:56 ` Alex Bennée
2018-05-22 16:15 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 07/27] Make memory_region_access_valid() " Peter Maydell
2018-05-22 10:57 ` Alex Bennée
2018-05-22 16:17 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 08/27] Make MemoryRegion valid.accepts callback " Peter Maydell
2018-05-22 10:58 ` Alex Bennée
2018-05-22 16:20 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 09/27] Make flatview_access_valid() " Peter Maydell
2018-05-22 10:58 ` Alex Bennée
2018-05-22 16:33 ` Richard Henderson
2018-05-22 16:37 ` Peter Maydell
2018-05-21 14:03 ` [Qemu-devel] [PATCH 10/27] Make flatview_translate() " Peter Maydell
2018-05-22 10:58 ` Alex Bennée
2018-05-22 16:33 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 11/27] Make address_space_get_iotlb_entry() " Peter Maydell
2018-05-22 11:00 ` Alex Bennée
2018-05-22 17:29 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 12/27] Make flatview_do_translate() " Peter Maydell
2018-05-22 11:00 ` Alex Bennée
2018-05-22 17:29 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 13/27] Make address_space_translate_iommu " Peter Maydell
2018-05-22 11:00 ` Alex Bennée
2018-05-22 17:30 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 14/27] iommu: Add IOMMU index concept to IOMMU API Peter Maydell
2018-05-22 3:03 ` Peter Xu
2018-05-22 8:40 ` Peter Maydell
2018-05-22 11:02 ` Peter Xu
2018-05-22 11:11 ` Peter Maydell
2018-05-23 1:06 ` Peter Xu
2018-05-23 11:47 ` Peter Maydell
2018-05-24 6:23 ` Peter Xu
2018-05-24 10:54 ` Peter Maydell
2018-05-25 2:50 ` Peter Xu [this message]
2018-05-25 9:27 ` Auger Eric
2018-05-25 9:34 ` Peter Maydell
2018-05-22 12:58 ` Auger Eric
2018-05-22 13:22 ` Peter Maydell
2018-05-22 14:11 ` Auger Eric
2018-05-22 14:19 ` Peter Maydell
2018-05-22 14:22 ` Auger Eric
2018-05-22 17:42 ` Richard Henderson
2018-05-22 17:51 ` Peter Maydell
2018-05-22 17:52 ` Richard Henderson
2018-05-21 14:03 ` [Qemu-devel] [PATCH 15/27] iommu: Add IOMMU index argument to notifier APIs Peter Maydell
2018-05-22 17:45 ` Richard Henderson
2018-05-23 9:08 ` Alex Bennée
2018-06-04 13:03 ` Peter Maydell
2018-06-04 15:09 ` Alex Bennée
2018-06-04 15:23 ` Peter Maydell
2018-05-24 15:29 ` Auger Eric
2018-05-24 17:03 ` Peter Maydell
2018-05-24 19:13 ` Auger Eric
2018-05-21 14:03 ` [Qemu-devel] [PATCH 16/27] iommu: Add IOMMU index argument to translate method Peter Maydell
2018-05-22 18:06 ` Richard Henderson
2018-05-23 9:11 ` Alex Bennée
2018-05-21 14:03 ` [Qemu-devel] [PATCH 17/27] exec.c: Handle IOMMUs in address_space_translate_for_iotlb() Peter Maydell
2018-05-23 9:51 ` Alex Bennée
2018-05-23 11:52 ` Peter Maydell
2018-05-24 19:54 ` Auger Eric
2018-05-25 8:52 ` Peter Maydell
2018-05-25 9:50 ` Auger Eric
2018-05-25 9:59 ` Peter Maydell
2018-05-21 14:03 ` [Qemu-devel] [PATCH 18/27] hw/misc/tz-mpc.c: Implement the Arm TrustZone Memory Protection Controller Peter Maydell
2018-05-22 11:30 ` Auger Eric
2018-05-22 11:56 ` Peter Maydell
2018-05-22 12:23 ` Auger Eric
2018-05-23 10:41 ` Alex Bennée
2018-05-21 14:03 ` [Qemu-devel] [PATCH 19/27] hw/misc/tz-mpc.c: Implement registers Peter Maydell
2018-05-23 10:44 ` Alex Bennée
2018-05-21 14:03 ` [Qemu-devel] [PATCH 20/27] hw/misc/tz-mpc.c: Implement correct blocked-access behaviour Peter Maydell
2018-05-23 10:49 ` Alex Bennée
2018-05-23 11:54 ` Peter Maydell
2018-05-21 14:03 ` [Qemu-devel] [PATCH 21/27] hw/misc/tz_mpc.c: Honour the BLK_LUT settings in translate Peter Maydell
2018-05-21 14:03 ` [Qemu-devel] [PATCH 22/27] vmstate.h: Provide VMSTATE_BOOL_SUB_ARRAY Peter Maydell
2018-05-23 11:01 ` Alex Bennée
2018-05-21 14:03 ` [Qemu-devel] [PATCH 23/27] hw/core/or-irq: Support more than 16 inputs to an OR gate Peter Maydell
2018-05-21 14:34 ` Paolo Bonzini
2018-05-21 15:02 ` Peter Maydell
2018-05-30 16:59 ` Paolo Bonzini
2018-05-30 17:35 ` Peter Maydell
2018-05-31 10:21 ` Paolo Bonzini
2018-05-31 10:50 ` Peter Maydell
2018-05-31 11:50 ` Paolo Bonzini
2018-05-31 11:59 ` Peter Maydell
2018-05-21 14:03 ` [Qemu-devel] [PATCH 24/27] hw/misc/iotkit-secctl.c: Implement SECMPCINTSTATUS Peter Maydell
2018-05-21 14:04 ` [Qemu-devel] [PATCH 25/27] hw/arm/iotkit: Instantiate MPC Peter Maydell
2018-05-23 11:38 ` Alex Bennée
2018-05-21 14:04 ` [Qemu-devel] [PATCH 26/27] hw/arm/iotkit: Wire up MPC interrupt lines Peter Maydell
2018-05-23 11:39 ` Alex Bennée
2018-05-21 14:04 ` [Qemu-devel] [PATCH 27/27] hw/arm/mps2-tz.c: Instantiate MPCs Peter Maydell
2018-05-23 11:41 ` Alex Bennée
2018-05-21 15:10 ` [Qemu-devel] [PATCH 00/27] iommu: support txattrs, support TCG execution, implement TZ MPC no-reply
2018-05-30 16:58 ` Paolo Bonzini
2018-05-31 9:54 ` Peter Maydell
2018-05-31 13:37 ` Peter Maydell
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=20180525025045.GJ12122@xz-mi \
--to=peterx@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=patches@linaro.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).