97168e
From 01c09f31978154f0d2fd699621ae958a8c3ea2a5 Mon Sep 17 00:00:00 2001
97168e
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
Date: Thu, 9 Mar 2023 08:15:24 -0500
97168e
Subject: [PATCH 08/13] physmem: add missing memory barrier
97168e
97168e
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
RH-MergeRequest: 263: qatomic: add smp_mb__before/after_rmw()
97168e
RH-Bugzilla: 2168472
97168e
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
97168e
RH-Acked-by: Eric Auger <eric.auger@redhat.com>
97168e
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
97168e
RH-Acked-by: David Hildenbrand <david@redhat.com>
97168e
RH-Commit: [8/10] f6a9659f7cf40b78de6e85e4a7c06842273aa770
97168e
97168e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168472
97168e
97168e
commit 33828ca11da08436e1b32f3e79dabce3061a0427
97168e
Author: Paolo Bonzini <pbonzini@redhat.com>
97168e
Date:   Fri Mar 3 14:36:32 2023 +0100
97168e
97168e
    physmem: add missing memory barrier
97168e
97168e
    Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
97168e
    Reviewed-by: David Hildenbrand <david@redhat.com>
97168e
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
97168e
97168e
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
---
97168e
 softmmu/physmem.c | 3 +++
97168e
 1 file changed, 3 insertions(+)
97168e
97168e
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
97168e
index 4d0ef5f92f..2b96fad302 100644
97168e
--- a/softmmu/physmem.c
97168e
+++ b/softmmu/physmem.c
97168e
@@ -3087,6 +3087,8 @@ void cpu_register_map_client(QEMUBH *bh)
97168e
     qemu_mutex_lock(&map_client_list_lock);
97168e
     client->bh = bh;
97168e
     QLIST_INSERT_HEAD(&map_client_list, client, link);
97168e
+    /* Write map_client_list before reading in_use.  */
97168e
+    smp_mb();
97168e
     if (!qatomic_read(&bounce.in_use)) {
97168e
         cpu_notify_map_clients_locked();
97168e
     }
97168e
@@ -3279,6 +3281,7 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
97168e
     qemu_vfree(bounce.buffer);
97168e
     bounce.buffer = NULL;
97168e
     memory_region_unref(bounce.mr);
97168e
+    /* Clear in_use before reading map_client_list.  */
97168e
     qatomic_mb_set(&bounce.in_use, false);
97168e
     cpu_notify_map_clients();
97168e
 }
97168e
-- 
97168e
2.37.3
97168e