From: Alex Williamson <alex.williamson@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: "Cédric Le Goater" <clg@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 8/9] vfio: Check compatibility of CPU and IOMMU address space width
Date: Fri, 31 Jan 2025 15:18:29 -0700 [thread overview]
Message-ID: <20250131151829.6461eeb0.alex.williamson@redhat.com> (raw)
In-Reply-To: <24w7fzx5rf2zdnowtjmuvwuirydryc366xumjf3isgzrhei2ty@ymyjyzdbggr2>
On Fri, 31 Jan 2025 14:23:58 +0100
Gerd Hoffmann <kraxel@redhat.com> wrote:
> On Fri, Jan 31, 2025 at 01:42:31PM +0100, Cédric Le Goater wrote:
> > + Gerd for insights regarding vIOMMU support in edk2.
> >
> > > > +static bool vfio_device_check_address_space(VFIODevice *vbasedev, Error **errp)
> > > > +{
> > > > + uint32_t cpu_aw_bits = cpu_get_phys_bits(first_cpu);
> > > > + uint32_t iommu_aw_bits = vfio_device_get_aw_bits(vbasedev);
> > > > +
> > > > + if (cpu_aw_bits && cpu_aw_bits > iommu_aw_bits) {
> > >
> > > Should we be testing the 64-bit MMIO window and maximum RAM GPA rather
> > > than the vCPU physical address width?
>
> Placing the 64-bit mmio window is done by the guest firmware,
> so this isn't something qemu can check before boot.
>
> > > However, we've decided to do exactly that for the 64-bit MMIO window.
> > > It's not that the vCPU width being greater than the IOMMU width is a
> > > fundamental problem, it's that we've chosen a 64-bit MMIO policy that
> > > makes this become a problem and QEMU only has a convenient mechanism to
> > > check the host IOMMU width when a vfio device is present. Arguably,
> > > when a vIOMMU is present guest firmware should be enlightened to
> > > understand the address width of that vIOMMU when placing the 64-bit
> > > MMIO window. I'd say the failure to do so is a current firmware bug.
>
> edk2 has no iommu driver ...
>
> Is there some simple way to figure what the iommu width is (inside the
> guest)?
If the guest firmware is exposing a DMAR table (VT-d), there's a host
address width field in that table. Otherwise there are capability
registers on the DRHD units that could be queried. AMD-Vi seems to
have similar information in the IVinfo table linked from the IVRS
table. Maybe an iterative solution is ok, starting with the most
common IOMMU types and assuming others are 64-bits wide until proven
otherwise.
>
> Note that there is a 'guest-phys-bits' property for x86 CPUs, which is a
> hint for the guest what the usable address width is. It was added
> because there are cases where the guest simply can't figure that it is
> not possible to use the full physical address space of the cpu. There
> are some non-obvious limitations around 5-level paging. Intel has some
> CPUs with phys-bits > 48 but only 4-level EPT for example.
>
> So one option to handle this is to make sure guest-phys-bits is not
> larger than the iommu width.
Right, as Cédric notes that's sort of what happens here, but my concern
was that the we're kind of incorrectly linking the cpu address width to
the platform address width, which isn't specifically the requirement.
It's valid to have CPU physical address width great than IOMMU address
width, that exists on bare metal, but guest firmware needs to take
IOMMU address width into account in placing the 64-bit MMIO window if
we want PCI BARs to be DMA addressable. Thanks,
Alex
next prev parent reply other threads:[~2025-01-31 22:19 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 13:43 [PATCH v2 0/9]vfio: Improve error reporting when MMIO region mapping fails Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 1/9] util/error: Introduce warn_report_once_err() Cédric Le Goater
2025-01-30 14:25 ` Markus Armbruster
2025-01-30 16:03 ` Cédric Le Goater
2025-01-30 16:28 ` Cédric Le Goater
2025-01-30 17:55 ` Alex Williamson
2025-01-30 21:26 ` Cédric Le Goater
2025-01-31 8:30 ` Markus Armbruster
2025-01-30 13:43 ` [PATCH v2 2/9] vfio/pci: Replace "iommu_device" by "vIOMMU" Cédric Le Goater
2025-02-10 14:28 ` Philippe Mathieu-Daudé
2025-01-30 13:43 ` [PATCH v2 3/9] vfio: Rephrase comment in vfio_listener_region_add() error path Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 4/9] vfio: Introduce vfio_get_vfio_device() Cédric Le Goater
2025-02-10 14:32 ` Philippe Mathieu-Daudé
2025-02-10 16:19 ` Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 5/9] vfio: Improve error reporting when MMIO region mapping fails Cédric Le Goater
2025-02-10 14:36 ` Philippe Mathieu-Daudé
2025-02-10 16:17 ` Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 6/9] vfio: Remove reports of DMA mapping errors in backends Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 7/9] cpu: Introduce cpu_get_phys_bits() Cédric Le Goater
2025-02-10 14:40 ` Philippe Mathieu-Daudé
2025-03-06 10:37 ` Philippe Mathieu-Daudé
2025-03-06 14:41 ` Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 8/9] vfio: Check compatibility of CPU and IOMMU address space width Cédric Le Goater
2025-01-30 18:58 ` Alex Williamson
2025-01-31 12:42 ` Cédric Le Goater
2025-01-31 13:23 ` Gerd Hoffmann
2025-01-31 17:03 ` Cédric Le Goater
2025-02-06 7:54 ` Gerd Hoffmann
2025-02-06 17:05 ` Cédric Le Goater
2025-01-31 22:18 ` Alex Williamson [this message]
2025-02-06 8:22 ` Gerd Hoffmann
2025-03-06 10:33 ` Philippe Mathieu-Daudé
2025-09-05 13:04 ` Daniel Kral
2025-09-08 8:35 ` Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 9/9] vfio: Remove superfluous error report in vfio_listener_region_add() Cédric Le Goater
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=20250131151829.6461eeb0.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).