<div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Alex,</div><div class="gmail_default" style="font-size:small"><br></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><span style="font-size:13px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">This is why we have an IOMMU.  The guest drivers and the device operate<br></span><span style="font-size:13px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">in the guest physical address space, the IOMMU handles the translation<br></span><span style="font-size:13px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">to the host physical address space.</span></blockquote><div class="gmail_default" style="font-size:small"><span style="font-size:13px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div class="gmail_default" style="">Thanks. I guess this is the answer I need. I will check the code to have a better understanding.</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">Again, thank you!</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">Best,</div><div class="gmail_default" style="">Huaicheng </div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 5, 2018 at 9:59 PM Alex Williamson <<a href="mailto:alex.williamson@redhat.com">alex.williamson@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, 5 Jun 2018 18:52:43 -0700<br>
Huaicheng Li <<a href="mailto:huaicheng@cs.uchicago.edu" target="_blank">huaicheng@cs.uchicago.edu</a>> wrote:<br>
<br>
> Hi Alex,<br>
> <br>
> VFIO does not setup<br>
> > mappings per DMA buffer, it maps all of guest physical memory through<br>
> > the IOMMU so that the device can DMA to any GPA and it's already<br>
> > mapped.  We call this transparent assignment, the guest can perform DMA<br>
> > without any knowledge of or interaction with the host IOMMU.  <br>
> <br>
> <br>
> Could you briefly explain how all of guest physical memory is mapped<br>
> through IOMMU.<br>
> I do see a ``vfio_dma_map`` call with `size` almost equal to my guest<br>
> memory size, is<br>
> this the place where IOMMU is instructed to enable such transparent<br>
> assignment you<br>
> mentioned?<br>
<br>
I don't know that I have a brief explanation for this, you'll need to<br>
look at the code.  The entry point to vfio is the MemoryListener (which<br>
calls vfio_dma_map) attached to the device AddressSpace, which is the<br>
system memory address space when a guest IOMMU is not present.<br>
RAMBlocks are mapped through MemoryRegions and sections of those come<br>
in through the MemoryListner to be populated through the IOMMU.<br>
<br>
> Since the guest driver is issuing IOs with GPA, how does the<br>
> device do<br>
> DMA to the corresponding physical DMA address?<br>
<br>
This is why we have an IOMMU.  The guest drivers and the device operate<br>
in the guest physical address space, the IOMMU handles the translation<br>
to the host physical address space.<br>
<br>
> Is the GPA->HPA a static<br>
> mapping<br>
> so the HPA can be calculated instead of walking the page tables (which<br>
> those DMA APIs<br>
> do)?<br>
<br>
Without a guest IOMMU, the translations are almost entirely static, for<br>
instance the RAM in your computer doesn't spontaneously decide to<br>
relocate itself in the physical address space of your system, neither<br>
does RAM in a VM.  All of guest physical memory is pinned in the host<br>
and mapped through the IOMMU.  Regardless of this, there is no page<br>
table walking to create these mappings.  Each RAMBlock is just a range<br>
of memory with a start and end offset in the guest physical address<br>
space.  Thanks,<br>
<br>
Alex<br>
</blockquote></div>