qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Auger <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, eric.auger@redhat.com,
	qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	alex.williamson@redhat.com, clg@redhat.com,
	jean-philippe@linaro.org, mst@redhat.com, pbonzini@redhat.com
Cc: peter.maydell@linaro.org, peterx@redhat.com, david@redhat.com,
	philmd@linaro.org
Subject: [PATCH v2 01/12] memory: Let ReservedRegion use Range
Date: Wed, 13 Sep 2023 10:01:36 +0200	[thread overview]
Message-ID: <20230913080423.523953-2-eric.auger@redhat.com> (raw)
In-Reply-To: <20230913080423.523953-1-eric.auger@redhat.com>

A reserved region is a range tagged with a type. Let's directly use
the Range type in the prospect to reuse some of the library helpers
shipped with the Range type.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

---

v1 -> v2:
- Added Philippe and David's R-b
---
 include/exec/memory.h            | 4 ++--
 hw/core/qdev-properties-system.c | 9 ++++++---
 hw/virtio/virtio-iommu.c         | 6 +++---
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 68284428f8..184cb3a01b 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -24,6 +24,7 @@
 #include "qemu/bswap.h"
 #include "qemu/queue.h"
 #include "qemu/int128.h"
+#include "qemu/range.h"
 #include "qemu/notify.h"
 #include "qom/object.h"
 #include "qemu/rcu.h"
@@ -79,8 +80,7 @@ extern unsigned int global_dirty_tracking;
 typedef struct MemoryRegionOps MemoryRegionOps;
 
 struct ReservedRegion {
-    hwaddr low;
-    hwaddr high;
+    Range range;
     unsigned type;
 };
 
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 6d5d43eda2..8d486eeefd 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -699,7 +699,7 @@ static void get_reserved_region(Object *obj, Visitor *v, const char *name,
     int rc;
 
     rc = snprintf(buffer, sizeof(buffer), "0x%"PRIx64":0x%"PRIx64":%u",
-                  rr->low, rr->high, rr->type);
+                  range_lob(&rr->range), range_upb(&rr->range), rr->type);
     assert(rc < sizeof(buffer));
 
     visit_type_str(v, name, &p, errp);
@@ -711,6 +711,7 @@ static void set_reserved_region(Object *obj, Visitor *v, const char *name,
     Property *prop = opaque;
     ReservedRegion *rr = object_field_prop_ptr(obj, prop);
     const char *endptr;
+    uint64_t lob, upb;
     char *str;
     int ret;
 
@@ -718,7 +719,7 @@ static void set_reserved_region(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    ret = qemu_strtou64(str, &endptr, 16, &rr->low);
+    ret = qemu_strtou64(str, &endptr, 16, &lob);
     if (ret) {
         error_setg(errp, "start address of '%s'"
                    " must be a hexadecimal integer", name);
@@ -728,7 +729,7 @@ static void set_reserved_region(Object *obj, Visitor *v, const char *name,
         goto separator_error;
     }
 
-    ret = qemu_strtou64(endptr + 1, &endptr, 16, &rr->high);
+    ret = qemu_strtou64(endptr + 1, &endptr, 16, &upb);
     if (ret) {
         error_setg(errp, "end address of '%s'"
                    " must be a hexadecimal integer", name);
@@ -738,6 +739,8 @@ static void set_reserved_region(Object *obj, Visitor *v, const char *name,
         goto separator_error;
     }
 
+    range_set_bounds(&rr->range, lob, upb);
+
     ret = qemu_strtoui(endptr + 1, &endptr, 10, &rr->type);
     if (ret) {
         error_setg(errp, "type of '%s'"
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index be51635895..e5e46e1b55 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -645,8 +645,8 @@ static ssize_t virtio_iommu_fill_resv_mem_prop(VirtIOIOMMU *s, uint32_t ep,
         prop.head.type = cpu_to_le16(VIRTIO_IOMMU_PROBE_T_RESV_MEM);
         prop.head.length = cpu_to_le16(length);
         prop.subtype = subtype;
-        prop.start = cpu_to_le64(s->reserved_regions[i].low);
-        prop.end = cpu_to_le64(s->reserved_regions[i].high);
+        prop.start = cpu_to_le64(range_lob(&s->reserved_regions[i].range));
+        prop.end = cpu_to_le64(range_upb(&s->reserved_regions[i].range));
 
         memcpy(buf, &prop, size);
 
@@ -897,7 +897,7 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr,
     for (i = 0; i < s->nb_reserved_regions; i++) {
         ReservedRegion *reg = &s->reserved_regions[i];
 
-        if (addr >= reg->low && addr <= reg->high) {
+        if (range_contains(&reg->range, addr)) {
             switch (reg->type) {
             case VIRTIO_IOMMU_RESV_MEM_T_MSI:
                 entry.perm = flag;
-- 
2.41.0



  reply	other threads:[~2023-09-13  8:07 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13  8:01 [PATCH v2 00/12] VIRTIO-IOMMU/VFIO: Don't assume 64b IOVA space Eric Auger
2023-09-13  8:01 ` Eric Auger [this message]
2023-09-13 12:43   ` [PATCH v2 01/12] memory: Let ReservedRegion use Range Cédric Le Goater
2023-09-13  8:01 ` [PATCH v2 02/12] memory: Introduce memory_region_iommu_set_iova_ranges Eric Auger
2023-09-13 12:43   ` Cédric Le Goater
2023-09-20  7:40     ` Eric Auger
2023-09-13  8:01 ` [PATCH v2 03/12] vfio: Collect container iova range info Eric Auger
2023-09-13 12:55   ` Cédric Le Goater
2023-09-20  7:38     ` Eric Auger
2023-09-19 15:44   ` Alex Williamson
2023-09-20  7:15     ` Eric Auger
2023-09-20  7:39     ` Eric Auger
2023-09-13  8:01 ` [PATCH v2 04/12] virtio-iommu: Rename reserved_regions into prop_resv_regions Eric Auger
2023-09-13 13:01   ` Cédric Le Goater
2023-09-13  8:01 ` [PATCH v2 05/12] virtio-iommu: Introduce per IOMMUDevice reserved regions Eric Auger
2023-09-29 15:52   ` Jean-Philippe Brucker
2023-10-03 15:48     ` Eric Auger
2023-09-13  8:01 ` [PATCH v2 06/12] range: Introduce range_inverse_array() Eric Auger
2023-09-19 16:29   ` Alex Williamson
2023-09-20  7:24     ` Eric Auger
2023-09-13  8:01 ` [PATCH v2 07/12] virtio-iommu: Implement set_iova_ranges() callback Eric Auger
2023-09-29 16:15   ` Jean-Philippe Brucker
2023-10-10 14:36     ` Eric Auger
2023-09-13  8:01 ` [PATCH v2 08/12] range: Make range_compare() public Eric Auger
2023-09-13  8:01 ` [PATCH v2 09/12] util/reserved-region: Add new ReservedRegion helpers Eric Auger
2023-09-29 16:16   ` Jean-Philippe Brucker
2023-10-10 13:51     ` Eric Auger
2023-09-13  8:01 ` [PATCH v2 10/12] virtio-iommu: Consolidate host reserved regions and property set ones Eric Auger
2023-09-13  8:01 ` [PATCH v2 11/12] test: Add some tests for range and resv-mem helpers Eric Auger
2023-09-13  8:01 ` [PATCH v2 12/12] vfio: Remove 64-bit IOVA address space assumption Eric Auger
2023-09-19 17:22   ` Alex Williamson
2023-09-20  7:28     ` Eric Auger
2023-09-26 20:00     ` Eric Auger
2023-10-10 17:16     ` Eric Auger
2023-09-20 20:02   ` Alex Williamson
2023-10-11 17:32     ` Eric Auger
2023-09-26  8:06 ` [PATCH v2 00/12] VIRTIO-IOMMU/VFIO: Don't assume 64b IOVA space YangHang Liu

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=20230913080423.523953-2-eric.auger@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --cc=david@redhat.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=jean-philippe@linaro.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.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).