@samitouri / QOSamiQemu / commits / c1d78ba63c

physmem: xen: Conditionalize use of the mapcache

Conditionalize use of the mapcache. This is in preparation to optionally disable the mapcache at runtime. Signed-off-by: Edgar E. Iglesias <edgar.iglesias@amd.com> Acked-by: Peter Xu <peterx@redhat.com> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

Edgar E. Iglesias committed Jul 23, 2025 at 11:56 UTC c1d78ba63cf520841635594049ecf437b432b791
1 file changed +8 -6
system/physmem.c
+8 -6
@@ -578,7 +578,9 @@ MemoryRegion *flatview_translate(FlatView *fv, hwaddr addr, hwaddr *xlat,
578 is_write, true, &as, attrs);
579 mr = section.mr;
580
581 - if (xen_enabled() && memory_access_is_direct(mr, is_write, attrs)) {
581 + if (xen_map_cache_enabled() &&
582 + memory_access_is_direct(mr, is_write, attrs)) {
583 + /* mapcache: Next page may be unmapped or in a different bucket/VA. */
584 hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr;
585 *plen = MIN(page, *plen);
586 }
@@ -2577,7 +2579,7 @@ static void reclaim_ramblock(RAMBlock *block)
2579 {
2580 if (block->flags & RAM_PREALLOC) {
2581 ;
2580 - } else if (xen_enabled()) {
2582 + } else if (xen_map_cache_enabled()) {
2583 xen_invalidate_map_cache_entry(block->host);
2584 #if !defined(_WIN32) && !defined(EMSCRIPTEN)
2585 } else if (block->fd >= 0) {
@@ -2736,7 +2738,7 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr,
2738 len = *size;
2739 }
2740
2739 - if (xen_enabled() && block->host == NULL) {
2741 + if (xen_map_cache_enabled() && block->host == NULL) {
2742 /* We need to check if the requested address is in the RAM
2743 * because we don't want to map the entire memory in QEMU.
2744 * In that case just map the requested area.
@@ -2785,7 +2787,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
2787 RAMBlock *block;
2788 uint8_t *host = ptr;
2789
2788 - if (xen_enabled()) {
2790 + if (xen_map_cache_enabled()) {
2791 ram_addr_t ram_addr;
2792 RCU_READ_LOCK_GUARD();
2793 ram_addr = xen_ram_addr_from_mapcache(ptr);
@@ -3787,7 +3789,7 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
3789 if (is_write) {
3790 invalidate_and_set_dirty(mr, addr1, access_len);
3791 }
3790 - if (xen_enabled()) {
3792 + if (xen_map_cache_enabled()) {
3793 xen_invalidate_map_cache_entry(buffer);
3794 }
3795 memory_region_unref(mr);
@@ -3898,7 +3900,7 @@ void address_space_cache_destroy(MemoryRegionCache *cache)
3900 return;
3901 }
3902
3901 - if (xen_enabled()) {
3903 + if (xen_map_cache_enabled()) {
3904 xen_invalidate_map_cache_entry(cache->ptr);
3905 }
3906 memory_region_unref(cache->mrs.mr);