thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ed5979
From 67bbeb056f75adc6c964468d876531ab68366fe0 Mon Sep 17 00:00:00 2001
ed5979
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
ed5979
Date: Thu, 9 Mar 2023 08:24:36 -0500
ed5979
Subject: [PATCH 07/12] edu: add smp_mb__after_rmw()
ed5979
ed5979
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
ed5979
RH-MergeRequest: 158: qatomic: add smp_mb__before/after_rmw()
ed5979
RH-Bugzilla: 2175660
ed5979
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
ed5979
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
ed5979
RH-Acked-by: David Hildenbrand <david@redhat.com>
ed5979
RH-Acked-by: Eric Auger <eric.auger@redhat.com>
ed5979
RH-Commit: [4/9] 2ad6fd6cb33fde39d2d017d94c0dde2152ad70c4 (eesposit/qemu-kvm)
ed5979
ed5979
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2175660
ed5979
ed5979
commit 2482aeea4195ad84cf3d4e5b15b28ec5b420ed5a
ed5979
Author: Paolo Bonzini <pbonzini@redhat.com>
ed5979
Date:   Thu Mar 2 11:16:13 2023 +0100
ed5979
ed5979
    edu: add smp_mb__after_rmw()
ed5979
ed5979
    Ensure ordering between clearing the COMPUTING flag and checking
ed5979
    IRQFACT, and between setting the IRQFACT flag and checking
ed5979
    COMPUTING.  This ensures that no wakeups are lost.
ed5979
ed5979
    Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
ed5979
    Reviewed-by: David Hildenbrand <david@redhat.com>
ed5979
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ed5979
ed5979
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
ed5979
---
ed5979
 hw/misc/edu.c | 5 +++++
ed5979
 1 file changed, 5 insertions(+)
ed5979
ed5979
diff --git a/hw/misc/edu.c b/hw/misc/edu.c
ed5979
index e935c418d4..a1f8bc77e7 100644
ed5979
--- a/hw/misc/edu.c
ed5979
+++ b/hw/misc/edu.c
ed5979
@@ -267,6 +267,8 @@ static void edu_mmio_write(void *opaque, hwaddr addr, uint64_t val,
ed5979
     case 0x20:
ed5979
         if (val & EDU_STATUS_IRQFACT) {
ed5979
             qatomic_or(&edu->status, EDU_STATUS_IRQFACT);
ed5979
+            /* Order check of the COMPUTING flag after setting IRQFACT.  */
ed5979
+            smp_mb__after_rmw();
ed5979
         } else {
ed5979
             qatomic_and(&edu->status, ~EDU_STATUS_IRQFACT);
ed5979
         }
ed5979
@@ -349,6 +351,9 @@ static void *edu_fact_thread(void *opaque)
ed5979
         qemu_mutex_unlock(&edu->thr_mutex);
ed5979
         qatomic_and(&edu->status, ~EDU_STATUS_COMPUTING);
ed5979
 
ed5979
+        /* Clear COMPUTING flag before checking IRQFACT.  */
ed5979
+        smp_mb__after_rmw();
ed5979
+
ed5979
         if (qatomic_read(&edu->status) & EDU_STATUS_IRQFACT) {
ed5979
             qemu_mutex_lock_iothread();
ed5979
             edu_raise_irq(edu, FACT_IRQ);
ed5979
-- 
ed5979
2.39.1
ed5979