qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Cédric Le Goater" <clg@redhat.com>, qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: [PATCH v2 8/9] vfio: Check compatibility of CPU and IOMMU address space width
Date: Thu, 6 Mar 2025 11:33:48 +0100	[thread overview]
Message-ID: <2390cf9e-c9df-4d19-946b-68c51763ce16@linaro.org> (raw)
In-Reply-To: <20250130134346.1754143-9-clg@redhat.com>

On 30/1/25 14:43, Cédric Le Goater wrote:
> Print a warning if IOMMU address space width is smaller than the
> physical address width. In this case, PCI peer-to-peer transactions on
> BARs are not supported and failures of device MMIO regions are to be
> expected.
> 
> This can occur with the 39-bit IOMMU address space width as found on
> consumer grade processors or when using a vIOMMU device with default
> settings.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   hw/vfio/common.c | 21 +++++++++++++++++++++
>   1 file changed, 21 insertions(+)
> 
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 5c9d8657d746ce30af5ae8f9122101e086a61ef5..e5ef93c589b2bed68f790608868ec3c7779d4cb8 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -44,6 +44,8 @@
>   #include "migration/qemu-file.h"
>   #include "system/tpm.h"
>   
> +#include "hw/core/cpu.h"
> +
>   VFIODeviceList vfio_device_list =
>       QLIST_HEAD_INITIALIZER(vfio_device_list);
>   static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
> @@ -1546,12 +1548,28 @@ retry:
>       return info;
>   }
>   
> +static bool vfio_device_check_address_space(VFIODevice *vbasedev, Error **errp)
> +{
> +    uint32_t cpu_aw_bits = cpu_get_phys_bits(first_cpu);

This 'first_cpu' use is annoying. I understand the device is created
from the CLI, and passing the host physical bits limit as a device
property is not practical. We'll deal with that later...

> +    uint32_t iommu_aw_bits = vfio_device_get_aw_bits(vbasedev);
> +
> +    if (cpu_aw_bits && cpu_aw_bits > iommu_aw_bits) {
> +        error_setg(errp, "Host physical address space (%u) is larger than "
> +                   "the host IOMMU address space (%u).", cpu_aw_bits,
> +                   iommu_aw_bits);
> +        vfio_device_error_append(vbasedev, errp);
> +        return false;
> +    }
> +    return true;
> +}
> +
>   bool vfio_attach_device(char *name, VFIODevice *vbasedev,
>                           AddressSpace *as, Error **errp)
>   {
>       const VFIOIOMMUClass *ops =
>           VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY));
>       HostIOMMUDevice *hiod = NULL;
> +    Error *local_err = NULL;
>   
>       if (vbasedev->iommufd) {
>           ops = VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
> @@ -1571,6 +1589,9 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
>           return false;
>       }
>   
> +    if (!vfio_device_check_address_space(vbasedev, &local_err)) {
> +        warn_report_err(local_err);
> +    }
>       return true;
>   }
>   



  parent reply	other threads:[~2025-03-06 10:34 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
2025-02-06  8:22           ` Gerd Hoffmann
2025-03-06 10:33   ` Philippe Mathieu-Daudé [this message]
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=2390cf9e-c9df-4d19-946b-68c51763ce16@linaro.org \
    --to=philmd@linaro.org \
    --cc=alex.williamson@redhat.com \
    --cc=berrange@redhat.com \
    --cc=clg@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).