From nobody Wed Nov 27 12:30:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699282057608450.32598577856277; Mon, 6 Nov 2023 06:47:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r00jI-0004Sb-Pb; Mon, 06 Nov 2023 09:37:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r00j5-0003aj-9O for qemu-devel@nongnu.org; Mon, 06 Nov 2023 09:37:16 -0500 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r00j0-0000lQ-EH for qemu-devel@nongnu.org; Mon, 06 Nov 2023 09:37:15 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4SPDSv5fjmz4xjb; Tue, 7 Nov 2023 01:37:03 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SPDSs23TSz4xjV; Tue, 7 Nov 2023 01:37:01 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , "Michael S. Tsirkin" Subject: [PULL 01/22] memory: Let ReservedRegion use Range Date: Mon, 6 Nov 2023 15:36:32 +0100 Message-ID: <20231106143653.302391-2-clg@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231106143653.302391-1-clg@redhat.com> References: <20231106143653.302391-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=Ju2X=GT=redhat.com=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1699282058371100001 From: Eric Auger 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 Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: "Michael S. Tsirkin" Signed-off-by: C=C3=A9dric Le Goater --- 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 9087d027690a88627f600cf3de45ea9e8c926763..d94314d6fc3b3de6ef1fa7c4f70= 837728a8309fb 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; =20 struct ReservedRegion { - hwaddr low; - hwaddr high; + Range range; unsigned type; }; =20 diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 2f1dbb3fd75176f7b2004e733bdfcb34557aa95f..b5ccafa29e901d09b6bb6e7e1f3= cdb46e9ad92da 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -705,7 +705,7 @@ static void get_reserved_region(Object *obj, Visitor *v= , const char *name, int rc; =20 rc =3D 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)); =20 visit_type_str(v, name, &p, errp); @@ -717,6 +717,7 @@ static void set_reserved_region(Object *obj, Visitor *v= , const char *name, Property *prop =3D opaque; ReservedRegion *rr =3D object_field_prop_ptr(obj, prop); const char *endptr; + uint64_t lob, upb; char *str; int ret; =20 @@ -724,7 +725,7 @@ static void set_reserved_region(Object *obj, Visitor *v= , const char *name, return; } =20 - ret =3D qemu_strtou64(str, &endptr, 16, &rr->low); + ret =3D qemu_strtou64(str, &endptr, 16, &lob); if (ret) { error_setg(errp, "start address of '%s'" " must be a hexadecimal integer", name); @@ -734,7 +735,7 @@ static void set_reserved_region(Object *obj, Visitor *v= , const char *name, goto separator_error; } =20 - ret =3D qemu_strtou64(endptr + 1, &endptr, 16, &rr->high); + ret =3D qemu_strtou64(endptr + 1, &endptr, 16, &upb); if (ret) { error_setg(errp, "end address of '%s'" " must be a hexadecimal integer", name); @@ -744,6 +745,8 @@ static void set_reserved_region(Object *obj, Visitor *v= , const char *name, goto separator_error; } =20 + range_set_bounds(&rr->range, lob, upb); + ret =3D 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 be51635895ce88cb69ec987a5c7d3fa33a703c9e..e5e46e1b557e19edc461b117dbf= ddcfd8f1dcc5d 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(VirtIOIO= MMU *s, uint32_t ep, prop.head.type =3D cpu_to_le16(VIRTIO_IOMMU_PROBE_T_RESV_MEM); prop.head.length =3D cpu_to_le16(length); prop.subtype =3D subtype; - prop.start =3D cpu_to_le64(s->reserved_regions[i].low); - prop.end =3D cpu_to_le64(s->reserved_regions[i].high); + prop.start =3D cpu_to_le64(range_lob(&s->reserved_regions[i].range= )); + prop.end =3D cpu_to_le64(range_upb(&s->reserved_regions[i].range)); =20 memcpy(buf, &prop, size); =20 @@ -897,7 +897,7 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemory= Region *mr, hwaddr addr, for (i =3D 0; i < s->nb_reserved_regions; i++) { ReservedRegion *reg =3D &s->reserved_regions[i]; =20 - if (addr >=3D reg->low && addr <=3D reg->high) { + if (range_contains(®->range, addr)) { switch (reg->type) { case VIRTIO_IOMMU_RESV_MEM_T_MSI: entry.perm =3D flag; --=20 2.41.0