Linux IOMMU Development
 help / color / mirror / Atom feed
From: Jerome Glisse <j.glisse-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Cc: alexander.deucher-5C7GfCeVMHo@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: Re: IOMMU and domain binding/unbinding logic
Date: Thu, 26 Mar 2015 13:58:58 -0400	[thread overview]
Message-ID: <20150326175857.GA3196@gmail.com> (raw)
In-Reply-To: <20150326170935.GX4441-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>

On Thu, Mar 26, 2015 at 06:09:35PM +0100, Joerg Roedel wrote:
> Hi Jerome,
> 
> On Thu, Mar 26, 2015 at 12:50:47PM -0400, Jerome Glisse wrote:
> > 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.
> 
> Your guess is correct, devices that might potentially use IOMMUv2
> functionality are identity mapped by default. The reason is that IOMMU
> hardware implements two dimensional paging, where the addresses in the
> guest page-tables (the ones translating PASID requests) are translated
> by the host page-tables. So to be able to use CPU page-tables (mm->pgd)
> for the IOMMU, the host page-tables need to be identity mapped.

Well this still doesn't explain how things works. So assume that you
boot computer and that the IOMMU bind to the GPU is not passthrough and
perform real remapping of bus address to physical address. You have :

  radeon_gpu_driver_init() {
    general_buffer = dma_map_page(gpu_dev, page);
    radeon_kfd_init() {
      amd_iommu_init_device(gpu_dev) {
        // bind new DOMAIN and detach old one, all previous dma address
        // are now invalid and will point to physical address directly,
        // if dma address where identity mapped at gpu_driver init time
        // than things are fine.
        //
        // Otherwise hw is accessing some random memory other then what
        // it believe general_buffer is at ie the first dma_map_page()
        // returned dma_addr != page_to_phys(page)
      }
    }

More over after amd_iommu_init_device(gpu_dev), any dma_map_page() should
fails as it will return ERR_PTR(-EINVAL) because get_domain(dev) (from
drivers/iommu/amd_iommu.c) will return ERR_PTR(-EBUSY) as the new domain
is not DMA capable.

Of course if dev.archdata.dma_ops is pointing to nommu_dma_ops then every
things is fine, but here i am wondering for the case where the ops are
actualy amd_iommu_dma_ops. In the first place ie at iommu initialization
or when hotpluging a new device (as in the hotpluging case it always set
dev.archdata.dma_ops to amd_iommu_dma_ops AFAICT.

Cheers,
Jérôme

  parent reply	other threads:[~2015-03-26 17:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-26 16:50 IOMMU and domain binding/unbinding logic Jerome Glisse
     [not found] ` <20150326165046.GA2965-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-03-26 17:09   ` Joerg Roedel
     [not found]     ` <20150326170935.GX4441-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-03-26 17:58       ` Jerome Glisse [this message]
     [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=20150326175857.GA3196@gmail.com \
    --to=j.glisse-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=alexander.deucher-5C7GfCeVMHo@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=joro-zLv9SwRftAIdnm+yROfE0A@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