[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 2/7] physmem: factor out RAM/ROMD check in memory_access_is_di
From: |
David Hildenbrand |
Subject: |
[PATCH v2 2/7] physmem: factor out RAM/ROMD check in memory_access_is_direct() |
Date: |
Fri, 24 Jan 2025 16:45:27 +0100 |
Let's factor more of the generic "is this directly accessible" check,
independent of the "write" condition out.
Note that the "!mr->rom_device" check in the write case essentially
disallows the memory_region_is_romd() condition again. Further note that
RAM DEVICE regions are also RAM regions, so we can check for RAM+ROMD
first.
This is a preparation for further changes.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/exec/memory.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 7931aba2ea..086dec5086 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2987,6 +2987,10 @@ bool prepare_mmio_access(MemoryRegion *mr);
static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
{
+ /* ROM DEVICE regions only allow direct access if in ROMD mode. */
+ if (!memory_region_is_ram(mr) && !memory_region_is_romd(mr)) {
+ return false;
+ }
/*
* RAM DEVICE regions can be accessed directly using memcpy, but it might
* be MMIO and access using mempy can be wrong (e.g., using instructions
not
@@ -2996,11 +3000,9 @@ static inline bool memory_access_is_direct(MemoryRegion
*mr, bool is_write)
return false;
}
if (is_write) {
- return memory_region_is_ram(mr) && !mr->readonly &&
- !mr->rom_device;
- } else {
- return memory_region_is_ram(mr) || memory_region_is_romd(mr);
+ return !mr->readonly && !mr->rom_device;
}
+ return true;
}
/**
--
2.47.1
- [PATCH v2 0/7] physmem: teach cpu_memory_rw_debug() to write to more memory regions, David Hildenbrand, 2025/01/24
- [PATCH v2 6/7] hmp: use cpu_get_phys_page_debug() in hmp_gva2gpa(), David Hildenbrand, 2025/01/24
- [PATCH v2 1/7] physmem: factor out memory_region_is_ram_device() check in memory_access_is_direct(), David Hildenbrand, 2025/01/24
- [PATCH v2 3/7] physmem: factor out direct access check into memory_region_supports_direct_access(), David Hildenbrand, 2025/01/24
- [PATCH v2 5/7] memory: pass MemTxAttrs to memory_access_is_direct(), David Hildenbrand, 2025/01/24
- [PATCH v2 4/7] physmem: disallow direct access to RAM DEVICE in address_space_write_rom(), David Hildenbrand, 2025/01/24
- [PATCH v2 7/7] physmem: teach cpu_memory_rw_debug() to write to more memory regions, David Hildenbrand, 2025/01/24
- [PATCH v2 2/7] physmem: factor out RAM/ROMD check in memory_access_is_direct(),
David Hildenbrand <=