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 01/13] memory: Let ReservedRegion use Range
Date: Mon, 4 Sep 2023 10:03:44 +0200 [thread overview]
Message-ID: <20230904080451.424731-2-eric.auger@redhat.com> (raw)
In-Reply-To: <20230904080451.424731-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>
---
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(®->range, addr)) {
switch (reg->type) {
case VIRTIO_IOMMU_RESV_MEM_T_MSI:
entry.perm = flag;
--
2.41.0
next prev parent reply other threads:[~2023-09-04 8:06 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-04 8:03 [PATCH 00/13] VIRTIO-IOMMU/VFIO: Don't assume 64b IOVA space Eric Auger
2023-09-04 8:03 ` Eric Auger [this message]
2023-09-04 8:12 ` [PATCH 01/13] memory: Let ReservedRegion use Range Philippe Mathieu-Daudé
2023-09-04 14:22 ` Eric Auger
2023-09-06 7:17 ` David Hildenbrand
2023-09-11 18:40 ` Peter Xu
2023-09-04 8:03 ` [PATCH 02/13] memory: Introduce memory_region_iommu_set_iova_ranges Eric Auger
2023-09-11 18:41 ` Peter Xu
2023-09-14 13:38 ` David Hildenbrand
2023-09-04 8:03 ` [PATCH 03/13] vfio: Collect container iova range info Eric Auger
2023-09-04 8:03 ` [PATCH 04/13] virtio-iommu: Rename reserved_regions into prop_resv_regions Eric Auger
2023-09-04 8:03 ` [PATCH 05/13] virtio-iommu: Introduce per IOMMUDevice reserved regions Eric Auger
2023-09-04 8:03 ` [PATCH 06/13] range: Introduce range_inverse_array() Eric Auger
2023-09-04 8:18 ` Philippe Mathieu-Daudé
2023-09-04 14:21 ` Eric Auger
2023-09-04 8:03 ` [PATCH 07/13] virtio-iommu: Implement set_iova_ranges() callback Eric Auger
2023-09-04 8:03 ` [PATCH 08/13] range: Make range_compare() public Eric Auger
2023-09-04 8:19 ` Philippe Mathieu-Daudé
2023-09-04 8:03 ` [PATCH 09/13] util/reserved-region: Add new ReservedRegion helpers Eric Auger
2023-09-04 8:03 ` [PATCH 10/13] virtio-iommu: Consolidate host reserved regions and property set ones Eric Auger
2023-09-04 8:03 ` [PATCH 11/13] test: Add some tests for range and resv-mem helpers Eric Auger
2023-09-04 8:03 ` [PATCH 12/13] virtio-iommu: Resize memory region according to the max iova info Eric Auger
2023-09-04 8:21 ` Philippe Mathieu-Daudé
2023-09-04 8:03 ` [PATCH 13/13] vfio: Remove 64-bit IOVA address space assumption Eric Auger
2023-09-05 8:22 ` [PATCH 00/13] VIRTIO-IOMMU/VFIO: Don't assume 64b IOVA space YangHang Liu
2023-09-05 9:15 ` Eric Auger
2023-09-05 9:50 ` Eric Auger
2023-09-05 17:55 ` Alex Williamson
2023-09-06 6:40 ` 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=20230904080451.424731-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).