Skip to contentSkip to conversation

hw/vfio/ap: attribute constructor for cfg_chg_events_lock

RFC PATCH Applied Rorie Reyes 3 participants 5 messages Jun 11, 2025 – Jun 12, 2025

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 hw/vfio/ap: attribute constructor for cfg_chg_events_lock

Created an attribute constructor for cfg_chg_events_lock for locking mechanism when storing event information for an AP configuration change event

Fixes fd03360215 ("Storing event information for an AP configuration change event")
---
 hw/vfio/ap.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
hw/vfio/ap.c +5 -7
index 874e0d1eaf..1df4438149 100644
@@ -52,6 +52,11 @@ static QTAILQ_HEAD(, APConfigChgEvent) cfg_chg_events =
 
 static QemuMutex cfg_chg_events_lock;
 
+static void __attribute__((constructor)) vfio_ap_global_init(void)
+{
+    qemu_mutex_init(&cfg_chg_events_lock);
+}
+
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOAPDevice, VFIO_AP_DEVICE)
 
 static void vfio_ap_compute_needs_reset(VFIODevice *vdev)
@@ -230,13 +235,6 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
     VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
     VFIODevice *vbasedev = &vapdev->vdev;
 
-    static bool lock_initialized;
-
-    if (!lock_initialized) {
-        qemu_mutex_init(&cfg_chg_events_lock);
-        lock_initialized = true;
-    }
-
     if (!vfio_device_get_name(vbasedev, errp)) {
         return;
     }
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Rorie Reyes

Created an attribute constructor for cfg_chg_events_lock for locking mechanism when storing event information for an AP configuration change event

Fixes fd03360215 ("Storing event information for an AP configuration change event")
---
  hw/vfio/ap.c | 12 +++++-------
  1 file changed, 5 insertions(+), 7 deletions(-)
hw/vfio/ap.c +0 -0
index 874e0d1eaf..1df4438149 100644

hw/vfio/ap.c static QTAILQ_HEAD(, APConfigChgEvent) cfg_chg_events = · line 58

Quoted 7 lines
hw/vfio/ap.c +4 -0
@@ -52,6 +52,11 @@ static QTAILQ_HEAD(, APConfigChgEvent) cfg_chg_events =
 
  static QemuMutex cfg_chg_events_lock;
 
+static void __attribute__((constructor)) vfio_ap_global_init(void)
+{
+    qemu_mutex_init(&cfg_chg_events_lock);
+}

I wonder why we don't have a macro for this yet (there are many other spots in the code that initialize a mutex like this).

Anyway, for your patch:

#2 lore raw
Quoted 25 lines · Thomas Huth
Quoted 18 lines · Rorie Reyes

Created an attribute constructor for cfg_chg_events_lock for locking mechanism when storing event information for an AP configuration change event

Fixes fd03360215 ("Storing event information for an AP configuration change event")

---
  hw/vfio/ap.c | 12 +++++-------

  1 file changed, 5 insertions(+), 7 deletions(-)
hw/vfio/ap.c +0 -0
index 874e0d1eaf..1df4438149 100644
@@ -52,6 +52,11 @@ static QTAILQ_HEAD(, APConfigChgEvent) 

cfg_chg_events =
    static QemuMutex cfg_chg_events_lock;
  +static void __attribute__((constructor)) vfio_ap_global_init(void)

hw/vfio/ap.c static QTAILQ_HEAD(, APConfigChgEvent) cfg_chg_events = · line 58

Quoted 3 lines
hw/vfio/ap.c +3 -0
+{
+    qemu_mutex_init(&cfg_chg_events_lock);
+}

I wonder why we don't have a macro for this yet (there are many other spots in the code that initialize a mutex like this).

Quoted 3 lines

Anyway, for your patch:

Thank you!

Reviewed-by on v1 1/1 Applied
#3 lore raw
In reply to Rorie Reyes
Quoted 30 lines · Rorie Reyes

Created an attribute constructor for cfg_chg_events_lock for locking mechanism when storing event information for an AP configuration change event

Fixes fd03360215 ("Storing event information for an AP configuration change event")
---
  hw/vfio/ap.c | 12 +++++-------
  1 file changed, 5 insertions(+), 7 deletions(-)
hw/vfio/ap.c +5 -0
index 874e0d1eaf..1df4438149 100644
@@ -52,6 +52,11 @@ static QTAILQ_HEAD(, APConfigChgEvent) cfg_chg_events =
 
  static QemuMutex cfg_chg_events_lock;
 
+static void __attribute__((constructor)) vfio_ap_global_init(void)
+{
+    qemu_mutex_init(&cfg_chg_events_lock);
+}
+
  OBJECT_DECLARE_SIMPLE_TYPE(VFIOAPDevice, VFIO_AP_DEVICE)
 
  static void vfio_ap_compute_needs_reset(VFIODevice *vdev)
@@ -230,13 +235,6 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
      VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
      VFIODevice *vbasedev = &vapdev->vdev;
 

hw/vfio/ap.c static void vfio_ap_realize(DeviceState *dev, Error **errp) · line 240

Quoted 10 lines
hw/vfio/ap.c +0 -7
-    static bool lock_initialized;
-
-    if (!lock_initialized) {
-        qemu_mutex_init(&cfg_chg_events_lock);
-        lock_initialized = true;
-    }
-
      if (!vfio_device_get_name(vbasedev, errp)) {
          return;
      }

Applied to vfio-next.

Thanks,

C.

#4 lore raw
Quoted 43 lines · Cédric Le Goater
Quoted 37 lines · Rorie Reyes

Created an attribute constructor for cfg_chg_events_lock for locking mechanism when storing event information for an AP configuration change event

Fixes fd03360215 ("Storing event information for an AP configuration change event")

---
  hw/vfio/ap.c | 12 +++++-------

  1 file changed, 5 insertions(+), 7 deletions(-)
hw/vfio/ap.c +0 -0
index 874e0d1eaf..1df4438149 100644
@@ -52,6 +52,11 @@ static QTAILQ_HEAD(, APConfigChgEvent) 

cfg_chg_events =
    static QemuMutex cfg_chg_events_lock;
  +static void __attribute__((constructor)) vfio_ap_global_init(void)

hw/vfio/ap.c +4 -0
+{
+    qemu_mutex_init(&cfg_chg_events_lock);
+}
+

  OBJECT_DECLARE_SIMPLE_TYPE(VFIOAPDevice, VFIO_AP_DEVICE) static void vfio_ap_compute_needs_reset(VFIODevice *vdev)

hw/vfio/ap.c +0 -6
@@ -230,13 +235,6 @@ static void vfio_ap_realize(DeviceState *dev, 
 Error **errp)
       VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
       VFIODevice *vbasedev = &vapdev->vdev;
   -    static bool lock_initialized;
-
-    if (!lock_initialized) {
-        qemu_mutex_init(&cfg_chg_events_lock);
-        lock_initialized = true;
-    }
-
       if (!vfio_device_get_name(vbasedev, errp)) {
           return;
Quoted 1 line

      }

Quoted 6 lines

Applied to vfio-next.

Thanks,

C.

Thank you!