From: Alex Williamson <alex.williamson@redhat.com>
To: Ajay Garg <ajaygargnsit@gmail.com>
Cc: iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: How are iommu-mappings set up in guest-OS for dma_alloc_coherent
Date: Fri, 19 Sep 2025 10:41:23 -0600 [thread overview]
Message-ID: <20250919104123.7c6ba069.alex.williamson@redhat.com> (raw)
In-Reply-To: <CAHP4M8W+uMHkzcx-fHJ0NxYf4hrkdFBQTGWwax5wHLa0Qf37Nw@mail.gmail.com>
On Thu, 18 Sep 2025 23:24:19 +0530
Ajay Garg <ajaygargnsit@gmail.com> wrote:
> Hi everyone.
>
> Let's say we have a following setup :
>
> i)
> x86_64 host-os, booted up with iommu enabled and pass-through mode.
>
> ii)
> x86_64 guest-os, booted up using vfio+qemu+kvm and a pci-device attached to it.
>
> iii)
> A guest-os-device-driver calls "dma_alloc_coherent", after which the
> returned dma-address / iova is programmed to the pci-device's
> mmio-register.
>
>
> In the above case, how are the IOMMU mappings set up during the
> guest-os-device-driver's "dma_alloc_coherent" call?
> Does :
>
> a)
> The VMM / KVM intercept the "dma_alloc_coherent" call, and use the
> host-iommu to set up things?
>
> OR
>
> b)
> There is no interception from VMM / KVM, but rather the guest-OS
> itself has a view of the IOMMU (through the regular ACPI tables
> populated during guest boot up)?
>
> OR
>
> c)
> Anything else under the hood?
>
>
> Will be grateful for clearing the haze.
Depends on details not revealed about the VM configuration.
If the VM is configured without a vIOMMU or the vIOMMU is inactive in
the guest, all of the guest physical memory is pinned and mapped
through the physical IOMMU when the guest is started. Nothing happens
regarding the IOMMU when a coherent mapping is created in the guest,
it's already setup.
If there is an active vIOMMU in the VM, then the guest act of
programming the IOMMU results in mappings through to the host IOMMU.
This is a result of the IOMMU emulation in the VM. Thanks,
Alex
next prev parent reply other threads:[~2025-09-19 16:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 17:54 How are iommu-mappings set up in guest-OS for dma_alloc_coherent Ajay Garg
2025-09-19 16:41 ` Alex Williamson [this message]
2025-09-20 3:04 ` Ajay Garg
2025-09-20 14:34 ` Alex Williamson
[not found] ` <CAHP4M8WOkDvEf6DYe6w+V9PVHkqcu2-8YrKa7jwLBYRAqLVS+g@mail.gmail.com>
2025-09-22 14:32 ` Alex Williamson
2025-09-22 16:21 ` Ajay Garg
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=20250919104123.7c6ba069.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=ajaygargnsit@gmail.com \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.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