summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAleksandr Partanen <alex.pentagrid@gmail.com>2025-04-10 17:46:04 +0300
committerEdgar E. Iglesias <edgar.iglesias@amd.com>2025-05-06 18:39:43 +0200
commita4b20f737cda06bb8706a83e27f7fa89863ae689 (patch)
tree24575a6f6d10dd8541aee42e603ed2511ca21405
parenta9e0c9c0f14e19d23443ac24c8080b4708d2eab8 (diff)
downloadfocaccia-qemu-a4b20f737cda06bb8706a83e27f7fa89863ae689.tar.gz
focaccia-qemu-a4b20f737cda06bb8706a83e27f7fa89863ae689.zip
xen: mapcache: Fix finding matching entry
If we have request without lock and hit unlocked or invalid
entry during the search, we remap it immediately,
even if we have matching entry in next entries in bucket.
This leads to duplication of mappings of the same size,
and to possibility of selecting the wrong element
during invalidation and underflow it's entry->lock counter

Signed-off-by: Aleksandr Partanen <alex.pentagrid@gmail.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@amd.com>
-rw-r--r--hw/xen/xen-mapcache.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
index 698b5c53ed..2c8f861fdb 100644
--- a/hw/xen/xen-mapcache.c
+++ b/hw/xen/xen-mapcache.c
@@ -376,12 +376,12 @@ tryagain:
 
     entry = &mc->entry[address_index % mc->nr_buckets];
 
-    while (entry && (lock || entry->lock) && entry->vaddr_base &&
-            (entry->paddr_index != address_index || entry->size != cache_size ||
+    while (entry && (!entry->vaddr_base ||
+            entry->paddr_index != address_index || entry->size != cache_size ||
              !test_bits(address_offset >> XC_PAGE_SHIFT,
                  test_bit_size >> XC_PAGE_SHIFT,
                  entry->valid_mapping))) {
-        if (!free_entry && !entry->lock) {
+        if (!free_entry && (!entry->lock || !entry->vaddr_base)) {
             free_entry = entry;
             free_pentry = pentry;
         }