97168e
From 7693449b235bbab6d32a1b87fa1d0e101c786f3b Mon Sep 17 00:00:00 2001
97168e
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
Date: Thu, 9 Mar 2023 08:11:14 -0500
97168e
Subject: [PATCH 05/13] edu: add smp_mb__after_rmw()
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: [5/10] 300901290e08b253b1278eedc39cd07c1e202b96
97168e
97168e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168472
97168e
97168e
commit 2482aeea4195ad84cf3d4e5b15b28ec5b420ed5a
97168e
Author: Paolo Bonzini <pbonzini@redhat.com>
97168e
Date:   Thu Mar 2 11:16:13 2023 +0100
97168e
97168e
    edu: add smp_mb__after_rmw()
97168e
97168e
    Ensure ordering between clearing the COMPUTING flag and checking
97168e
    IRQFACT, and between setting the IRQFACT flag and checking
97168e
    COMPUTING.  This ensures that no wakeups are lost.
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
 hw/misc/edu.c | 5 +++++
97168e
 1 file changed, 5 insertions(+)
97168e
97168e
diff --git a/hw/misc/edu.c b/hw/misc/edu.c
97168e
index e935c418d4..a1f8bc77e7 100644
97168e
--- a/hw/misc/edu.c
97168e
+++ b/hw/misc/edu.c
97168e
@@ -267,6 +267,8 @@ static void edu_mmio_write(void *opaque, hwaddr addr, uint64_t val,
97168e
     case 0x20:
97168e
         if (val & EDU_STATUS_IRQFACT) {
97168e
             qatomic_or(&edu->status, EDU_STATUS_IRQFACT);
97168e
+            /* Order check of the COMPUTING flag after setting IRQFACT.  */
97168e
+            smp_mb__after_rmw();
97168e
         } else {
97168e
             qatomic_and(&edu->status, ~EDU_STATUS_IRQFACT);
97168e
         }
97168e
@@ -349,6 +351,9 @@ static void *edu_fact_thread(void *opaque)
97168e
         qemu_mutex_unlock(&edu->thr_mutex);
97168e
         qatomic_and(&edu->status, ~EDU_STATUS_COMPUTING);
97168e
 
97168e
+        /* Clear COMPUTING flag before checking IRQFACT.  */
97168e
+        smp_mb__after_rmw();
97168e
+
97168e
         if (qatomic_read(&edu->status) & EDU_STATUS_IRQFACT) {
97168e
             qemu_mutex_lock_iothread();
97168e
             edu_raise_irq(edu, FACT_IRQ);
97168e
-- 
97168e
2.37.3
97168e