From: Jerome Glisse <j.glisse-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Cc: alexander.deucher-5C7GfCeVMHo@public.gmane.org
Subject: IOMMU and domain binding/unbinding logic
Date: Thu, 26 Mar 2015 12:50:47 -0400 [thread overview]
Message-ID: <20150326165046.GA2965@gmail.com> (raw)
Hi,
I was looking at IOMMUv2 and AMD APU kfd driver registration and initialization
(drivers/gpu/drm/amd/amdkfd/kfd_device.c). I am left puzzle with 2 things.
General IOMMU question, my understanding is that each device is associated with
one domain only (ignoring device that have several alias if such thing exist).
So i would assume that when some one wants to attach a new domain to a device
it would fail if the device is already attached to a domain (other than the
passthrough domain or some common dma domain). But i fail to see anywhere in
the code for such test (wether in drivers/iommu/iommu.c or in any iommu driver
code). On contrary if i look at driver code the first thing it does in the
attach callback is unbind the currently bound domain.
So if there are some active DMA mapping in current bound domain they are lost
and even worst once the driver call the dma_unmap api it will possibly free
new unrelated mapping. Which sounds really buggy.
Of course there are very few user of the iommu api, mostly for virtualization
and AMD kfd driver. In virtualization case i think the passthrough implicitly
force that no host driver are bound to the device and hence no domain. So no
issue there AFAICT.
In the kfd driver things are different, kfd driver initialization happens
after GPU driver initialization (drivers/gpu/drm/radeon/radeon_kms.c look
for radeon_kfd_device_probe() radeon_kfd_device_init()). At this point the
GPU driver already allocated a bunch of memory and mapped it through the
pci_map_page() (which endup in dma_map_page()). So assuming we are not in
passthrough there are live and working/in use mapping.
Now the issue is that kfd call amd_iommu_init_device() which allocates a
new iommu domain and replace currently bound domain with it. This new
domain is however different from previously (default domain) in that it
does not have PD_DMA_OPS_MASK domain flags set and as such if i am reading
code properly will lead to all dma_map_page() to fail (or any other dma-op
for that matter).
So how comes it still looks like it is working properly ? My best guest
it is because it is by default in passthrough, but i haven't checked that
theory.
I am sure i am missing something very obvious somewhere in the code but
after spending couple hour staring at it, it is still eluding me.
Cheers,
Jérôme
next reply other threads:[~2015-03-26 16:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-26 16:50 Jerome Glisse [this message]
[not found] ` <20150326165046.GA2965-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-03-26 17:09 ` IOMMU and domain binding/unbinding logic Joerg Roedel
[not found] ` <20150326170935.GX4441-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-03-26 17:58 ` Jerome Glisse
[not found] ` <20150326175857.GA3196-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-03-30 9:46 ` Joerg Roedel
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=20150326165046.GA2965@gmail.com \
--to=j.glisse-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=alexander.deucher-5C7GfCeVMHo@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.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