qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Auger <eauger@redhat.com>
To: "Cédric Le Goater" <clg@redhat.com>, qemu-devel@nongnu.org
Cc: "Peter Xu" <peterx@redhat.com>, "Fabiano Rosas" <farosas@suse.de>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Avihai Horon" <avihaih@nvidia.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"David Hildenbrand" <david@redhat.com>
Subject: Re: [PATCH v6 7/9] memory: Add Error** argument to memory_get_xlat_addr()
Date: Wed, 15 May 2024 11:25:10 +0200	[thread overview]
Message-ID: <17e133f9-36ff-4a17-8a38-dbe5a6278b9d@redhat.com> (raw)
In-Reply-To: <20240514153130.394307-8-clg@redhat.com>



On 5/14/24 17:31, Cédric Le Goater wrote:
> Let the callers do the reporting. This will be useful in
> vfio_iommu_map_dirty_notify().
> 
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: David Hildenbrand <david@redhat.com>
> Reviewed-by: Peter Xu <peterx@redhat.com>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
> 
>  Changes in v6:
> 
>  - Fixed memory_get_xlat_addr documentation (Avihai)
>  
>  include/exec/memory.h  | 15 ++++++++++++++-
>  hw/vfio/common.c       | 13 +++++++++----
>  hw/virtio/vhost-vdpa.c |  5 ++++-
>  system/memory.c        | 10 +++++-----
>  4 files changed, 32 insertions(+), 11 deletions(-)
> 
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index d417d7f363dbbca6553c449582a93d5da73cca40..9cdd64e9c69b63f9d27cebc2e8cb366e22ed7577 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -774,9 +774,22 @@ void ram_discard_manager_register_listener(RamDiscardManager *rdm,
>  void ram_discard_manager_unregister_listener(RamDiscardManager *rdm,
>                                               RamDiscardListener *rdl);
>  
> +/**
> + * memory_get_xlat_addr: Extract addresses from a TLB entry
> + *
> + * @iotlb: pointer to an #IOMMUTLBEntry
> + * @vaddr: virtual address
> + * @ram_addr: RAM address
> + * @read_only: indicates if writes are allowed
> + * @mr_has_discard_manager: indicates memory is controlled by a
> + *                          RamDiscardManager
> + * @errp: pointer to Error*, to store an error if it happens.
> + *
> + * Return: true on success, else false setting @errp with error.
> + */
>  bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
>                            ram_addr_t *ram_addr, bool *read_only,
> -                          bool *mr_has_discard_manager);
> +                          bool *mr_has_discard_manager, Error **errp);
>  
>  typedef struct CoalescedMemoryRange CoalescedMemoryRange;
>  typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 4e2ef3d3034e72aa6a546bcb9ea1f31a0bbd5b1b..919c4c52bc1590fd6c0bda37ba5881f58ff2ffff 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -253,12 +253,13 @@ static bool vfio_listener_skipped_section(MemoryRegionSection *section)
>  
>  /* Called with rcu_read_lock held.  */
>  static bool vfio_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
> -                               ram_addr_t *ram_addr, bool *read_only)
> +                               ram_addr_t *ram_addr, bool *read_only,
> +                               Error **errp)
>  {
>      bool ret, mr_has_discard_manager;
>  
>      ret = memory_get_xlat_addr(iotlb, vaddr, ram_addr, read_only,
> -                               &mr_has_discard_manager);
> +                               &mr_has_discard_manager, errp);
>      if (ret && mr_has_discard_manager) {
>          /*
>           * Malicious VMs might trigger discarding of IOMMU-mapped memory. The
> @@ -288,6 +289,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>      hwaddr iova = iotlb->iova + giommu->iommu_offset;
>      void *vaddr;
>      int ret;
> +    Error *local_err = NULL;
>  
>      trace_vfio_iommu_map_notify(iotlb->perm == IOMMU_NONE ? "UNMAP" : "MAP",
>                                  iova, iova + iotlb->addr_mask);
> @@ -304,7 +306,8 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>      if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) {
>          bool read_only;
>  
> -        if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) {
> +        if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, &local_err)) {
> +            error_report_err(local_err);
>              goto out;
>          }
>          /*
> @@ -1213,6 +1216,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>      VFIOContainerBase *bcontainer = giommu->bcontainer;
>      hwaddr iova = iotlb->iova + giommu->iommu_offset;
>      ram_addr_t translated_addr;
> +    Error *local_err = NULL;
>      int ret = -EINVAL;
>  
>      trace_vfio_iommu_map_dirty_notify(iova, iova + iotlb->addr_mask);
> @@ -1224,7 +1228,8 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>      }
>  
>      rcu_read_lock();
> -    if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL)) {
> +    if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL, &local_err)) {
> +        error_report_err(local_err);
>          goto out_unlock;
>      }
>  
> diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
> index e827b9175fc61f1ef419e48d90a440b00449312a..ed99ab87457d8f31b98ace960713f48d47b27102 100644
> --- a/hw/virtio/vhost-vdpa.c
> +++ b/hw/virtio/vhost-vdpa.c
> @@ -208,6 +208,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>      void *vaddr;
>      int ret;
>      Int128 llend;
> +    Error *local_err = NULL;
>  
>      if (iotlb->target_as != &address_space_memory) {
>          error_report("Wrong target AS \"%s\", only system memory is allowed",
> @@ -227,7 +228,9 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>      if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) {
>          bool read_only;
>  
> -        if (!memory_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, NULL)) {
> +        if (!memory_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, NULL,
> +                                  &local_err)) {
> +            error_report_err(local_err);
>              return;
>          }
>          ret = vhost_vdpa_dma_map(s, VHOST_VDPA_GUEST_PA_ASID, iova,
> diff --git a/system/memory.c b/system/memory.c
> index 642a449f8c867d38c62a748a4dfd5c055637c205..9540caa8a1f4da8501bf5ae9d7eedde8b775e1dc 100644
> --- a/system/memory.c
> +++ b/system/memory.c
> @@ -2179,7 +2179,7 @@ void ram_discard_manager_unregister_listener(RamDiscardManager *rdm,
>  /* Called with rcu_read_lock held.  */
>  bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
>                            ram_addr_t *ram_addr, bool *read_only,
> -                          bool *mr_has_discard_manager)
> +                          bool *mr_has_discard_manager, Error **errp)
>  {
>      MemoryRegion *mr;
>      hwaddr xlat;
> @@ -2197,7 +2197,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
>      mr = address_space_translate(&address_space_memory, iotlb->translated_addr,
>                                   &xlat, &len, writable, MEMTXATTRS_UNSPECIFIED);
>      if (!memory_region_is_ram(mr)) {
> -        error_report("iommu map to non memory area %" HWADDR_PRIx "", xlat);
> +        error_setg(errp, "iommu map to non memory area %" HWADDR_PRIx "", xlat);
>          return false;
>      } else if (memory_region_has_ram_discard_manager(mr)) {
>          RamDiscardManager *rdm = memory_region_get_ram_discard_manager(mr);
> @@ -2216,8 +2216,8 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
>           * were already restored before IOMMUs are restored.
>           */
>          if (!ram_discard_manager_is_populated(rdm, &tmp)) {
> -            error_report("iommu map to discarded memory (e.g., unplugged via"
> -                         " virtio-mem): %" HWADDR_PRIx "",
> +            error_setg(errp, "iommu map to discarded memory (e.g., unplugged"
> +                         " via virtio-mem): %" HWADDR_PRIx "",
>                           iotlb->translated_addr);
>              return false;
>          }
> @@ -2228,7 +2228,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
>       * check that it did not truncate too much.
>       */
>      if (len & iotlb->addr_mask) {
> -        error_report("iommu has granularity incompatible with target AS");
> +        error_setg(errp, "iommu has granularity incompatible with target AS");
>          return false;
>      }
>  
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric



  reply	other threads:[~2024-05-15  9:26 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 15:31 [PATCH v6 0/9] vfio: Improve error reporting (part 2 Cédric Le Goater
2024-05-14 15:31 ` [PATCH v6 1/9] vfio: Add Error** argument to .set_dirty_page_tracking() handler Cédric Le Goater
2024-05-15  6:40   ` Eric Auger
2024-05-15 16:55     ` Cédric Le Goater
2024-05-14 15:31 ` [PATCH v6 2/9] vfio: Add Error** argument to vfio_devices_dma_logging_start() Cédric Le Goater
2024-05-15  6:53   ` Eric Auger
2024-05-15 17:09     ` Cédric Le Goater
2024-05-14 15:31 ` [PATCH v6 3/9] migration: Extend migration_file_set_error() with Error* argument Cédric Le Goater
2024-05-15  7:04   ` Eric Auger
2024-05-15 17:15     ` Cédric Le Goater
2024-05-14 15:31 ` [PATCH v6 4/9] vfio/migration: Add an Error** argument to vfio_migration_set_state() Cédric Le Goater
2024-05-15  7:20   ` Eric Auger
2024-05-16  7:17     ` Cédric Le Goater
2024-05-16  8:18   ` Avihai Horon
2024-05-16 12:07     ` Cédric Le Goater
2024-05-14 15:31 ` [PATCH v6 5/9] vfio/migration: Add Error** argument to .vfio_save_config() handler Cédric Le Goater
2024-05-15  9:20   ` Eric Auger
2024-05-16  8:22   ` Avihai Horon
2024-05-14 15:31 ` [PATCH v6 6/9] vfio: Reverse test on vfio_get_xlat_addr() Cédric Le Goater
2024-05-15  9:22   ` Eric Auger
2024-05-14 15:31 ` [PATCH v6 7/9] memory: Add Error** argument to memory_get_xlat_addr() Cédric Le Goater
2024-05-15  9:25   ` Eric Auger [this message]
2024-05-16  8:25   ` Avihai Horon
2024-05-14 15:31 ` [PATCH v6 8/9] vfio: Add Error** argument to .get_dirty_bitmap() handler Cédric Le Goater
2024-05-15  9:34   ` Eric Auger
2024-05-16  8:42   ` Avihai Horon
2024-05-16 12:22     ` Cédric Le Goater
2024-05-14 15:31 ` [PATCH v6 9/9] vfio: Also trace event failures in vfio_save_complete_precopy() Cédric Le Goater
2024-05-15  9:34   ` Eric Auger

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=17e133f9-36ff-4a17-8a38-dbe5a6278b9d@redhat.com \
    --to=eauger@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=avihaih@nvidia.com \
    --cc=clg@redhat.com \
    --cc=david@redhat.com \
    --cc=farosas@suse.de \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --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).