[PATCH 02/15] system/memory: Factor address_space_memory_is_io() out

Philippe Mathieu-Daudé posted 15 patches 5 days, 3 hours ago
There is a newer version of this series
[PATCH 02/15] system/memory: Factor address_space_memory_is_io() out
Posted by Philippe Mathieu-Daudé 5 days, 3 hours ago
Factor address_space_memory_is_io() out of cpu_physical_memory_is_io()
passing the address space and range length as argument.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/system/memory.h | 10 ++++++++++
 system/physmem.c        | 21 ++++++++++++---------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/include/system/memory.h b/include/system/memory.h
index aa85fc27a10..6cfa22d7a80 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -3029,6 +3029,16 @@ static inline MemoryRegion *address_space_translate(AddressSpace *as,
 bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,
                                 bool is_write, MemTxAttrs attrs);
 
+/**
+ * address_space_memory_is_io: check whether an address space range is
+ *                             I/O memory.
+ *
+ * @as: #AddressSpace to be accessed
+ * @addr: address within that address space
+ * @len: length of the area to be checked
+ */
+bool address_space_memory_is_io(AddressSpace *as, hwaddr addr, hwaddr len);
+
 /* address_space_map: map a physical memory region into a host virtual address
  *
  * May map a subset of the requested range, given by and returned in @plen.
diff --git a/system/physmem.c b/system/physmem.c
index 8a8be3a80e2..18b3d38dc0c 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -3358,6 +3358,17 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr,
     return flatview_access_valid(fv, addr, len, is_write, attrs);
 }
 
+bool address_space_memory_is_io(AddressSpace *as, hwaddr addr, hwaddr len)
+{
+    MemoryRegion*mr;
+
+    RCU_READ_LOCK_GUARD();
+    mr = address_space_translate(as, addr, &addr, &len, false,
+                                 MEMTXATTRS_UNSPECIFIED);
+
+    return !(memory_region_is_ram(mr) || memory_region_is_romd(mr));
+}
+
 static hwaddr
 flatview_extend_translation(FlatView *fv, hwaddr addr,
                             hwaddr target_len,
@@ -3754,15 +3765,7 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
 
 bool cpu_physical_memory_is_io(hwaddr phys_addr)
 {
-    MemoryRegion*mr;
-    hwaddr l = 1;
-
-    RCU_READ_LOCK_GUARD();
-    mr = address_space_translate(&address_space_memory,
-                                 phys_addr, &phys_addr, &l, false,
-                                 MEMTXATTRS_UNSPECIFIED);
-
-    return !(memory_region_is_ram(mr) || memory_region_is_romd(mr));
+    return address_space_memory_is_io(&address_space_memory, phys_addr, 1);
 }
 
 int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque)
-- 
2.51.0


Re: [PATCH 02/15] system/memory: Factor address_space_memory_is_io() out
Posted by Richard Henderson 4 days, 21 hours ago
On 9/29/25 11:32, Philippe Mathieu-Daudé wrote:
> Factor address_space_memory_is_io() out of cpu_physical_memory_is_io()
> passing the address space and range length as argument.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/system/memory.h | 10 ++++++++++
>   system/physmem.c        | 21 ++++++++++++---------
>   2 files changed, 22 insertions(+), 9 deletions(-)
> 
> diff --git a/include/system/memory.h b/include/system/memory.h
> index aa85fc27a10..6cfa22d7a80 100644
> --- a/include/system/memory.h
> +++ b/include/system/memory.h
> @@ -3029,6 +3029,16 @@ static inline MemoryRegion *address_space_translate(AddressSpace *as,
>   bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,
>                                   bool is_write, MemTxAttrs attrs);
>   
> +/**
> + * address_space_memory_is_io: check whether an address space range is
> + *                             I/O memory.
> + *
> + * @as: #AddressSpace to be accessed
> + * @addr: address within that address space
> + * @len: length of the area to be checked
> + */
> +bool address_space_memory_is_io(AddressSpace *as, hwaddr addr, hwaddr len);

I don't think 'len' makes sense.
What are you doing if [addr, addr+len) crosses MemoryRegions?


> +bool address_space_memory_is_io(AddressSpace *as, hwaddr addr, hwaddr len)
> +{
> +    MemoryRegion*mr;

Missing space.

> +
> +    RCU_READ_LOCK_GUARD();
> +    mr = address_space_translate(as, addr, &addr, &len, false,
> +                                 MEMTXATTRS_UNSPECIFIED);

Just pass NULL as the plen parameter.


r~