venus: properly initialize ring monitor initial alive status
authorYiwei Zhang <zzyiwei@chromium.org>
Tue, 28 Nov 2023 20:17:29 +0000 (12:17 -0800)
committerEric Engestrom <eric@engestrom.ch>
Fri, 8 Dec 2023 11:24:46 +0000 (11:24 +0000)
This avoids a potential race condition if two threads are competing for
the monitor with the initial states, and the losing one may run into
alive status being false and abort.

Fixes: 4a4b05869a6 ("venus: check and configure new ringMonitoring feature")
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reported-by: Lina Versace <lina@kiwitree.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26179>
(cherry picked from commit 8ac7d78bf3512aa7575f9c8595494ea592ab2e58)

.pick_status.json
src/virtio/vulkan/vn_common.c
src/virtio/vulkan/vn_instance.c

index b1dbc03..6713728 100644 (file)
         "description": "venus: properly initialize ring monitor initial alive status",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "4a4b05869a6ad909417e30d46706ad6038084901",
         "notes": null
index 72101e7..27c2b05 100644 (file)
@@ -168,10 +168,8 @@ vn_relax_init(struct vn_ring *ring, const char *reason)
              ring->monitor.report_period_us);
 #endif
 
-      if (vn_ring_monitor_acquire(ring)) {
-         ring->monitor.alive = true;
+      if (vn_ring_monitor_acquire(ring))
          vn_ring_unset_status_bits(ring, VK_RING_STATUS_ALIVE_BIT_MESA);
-      }
    }
 
    return (struct vn_relax_state){
index 29aae7b..0ef092a 100644 (file)
@@ -137,6 +137,9 @@ vn_instance_init_ring(struct vn_instance *instance)
    ring->monitor.report_period_us = 3000000;
    mtx_init(&ring->monitor.mutex, mtx_plain);
 
+   /* ring monitor should be alive at all time */
+   ring->monitor.alive = true;
+
    const struct VkRingMonitorInfoMESA monitor_info = {
       .sType = VK_STRUCTURE_TYPE_RING_MONITOR_INFO_MESA,
       .maxReportingPeriodMicroseconds = ring->monitor.report_period_us,