Module: Mesa
Branch: main
Commit: ecd50e70d4d23802c4c102ca2e5723ebf4a19c0c
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ecd50e70d4d23802c4c102ca2e5723ebf4a19c0c

Author: Yiwei Zhang <zzyi...@chromium.org>
Date:   Thu Jan 11 20:47:10 2024 -0800

venus: populate oom from ring submit alloc failures

ring_seqno_valid indicates a successful ring cmd submission, and can be
used to avoid invalid reply decoding due to failed submit alloc.
Otherwise, the garbled VkResult will mislead into initialization failure
instead of oom.

Below cts failure is fixed:
dEQP-VK.api.device_init.create_instance_device_intentional_alloc_fail.basic

Fixes: ec131c6e553 ("venus: use instance allocator for ring allocs")
Signed-off-by: Yiwei Zhang <zzyi...@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27026>

---

 src/virtio/vulkan/vn_ring.c | 14 +++++++++-----
 src/virtio/vulkan/vn_ring.h |  4 +++-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/virtio/vulkan/vn_ring.c b/src/virtio/vulkan/vn_ring.c
index f44d4ea6211..461e97b7c4e 100644
--- a/src/virtio/vulkan/vn_ring.c
+++ b/src/virtio/vulkan/vn_ring.c
@@ -633,7 +633,6 @@ vn_ring_submit_command(struct vn_ring *ring,
    vn_cs_encoder_commit(&submit->command);
 
    size_t reply_offset = 0;
-   submit->reply_shmem = NULL;
    if (submit->reply_size) {
       submit->reply_shmem = vn_instance_reply_shmem_alloc(
          ring->instance, submit->reply_size, &reply_offset);
@@ -653,11 +652,16 @@ vn_ring_submit_command(struct vn_ring *ring,
    mtx_unlock(&ring->mutex);
 
    if (submit->reply_size) {
-      void *reply_ptr = submit->reply_shmem->mmap_ptr + reply_offset;
-      submit->reply =
-         VN_CS_DECODER_INITIALIZER(reply_ptr, submit->reply_size);
-      if (submit->ring_seqno_valid)
+      if (likely(submit->ring_seqno_valid)) {
+         void *reply_ptr = submit->reply_shmem->mmap_ptr + reply_offset;
+         submit->reply =
+            VN_CS_DECODER_INITIALIZER(reply_ptr, submit->reply_size);
          vn_ring_wait_seqno(ring, submit->ring_seqno);
+      } else {
+         vn_renderer_shmem_unref(ring->instance->renderer,
+                                 submit->reply_shmem);
+         submit->reply_shmem = NULL;
+      }
    }
 }
 
diff --git a/src/virtio/vulkan/vn_ring.h b/src/virtio/vulkan/vn_ring.h
index a3961cdc965..b452e77ebbb 100644
--- a/src/virtio/vulkan/vn_ring.h
+++ b/src/virtio/vulkan/vn_ring.h
@@ -77,7 +77,7 @@ struct vn_ring_submit_command {
    struct vn_renderer_shmem *reply_shmem;
    struct vn_cs_decoder reply;
 
-   /* valid when instance ring submission succeeds */
+   /* valid when ring submission succeeds */
    bool ring_seqno_valid;
    uint32_t ring_seqno;
 };
@@ -95,6 +95,8 @@ vn_ring_submit_command_init(struct vn_ring *ring,
    submit->reply_size = reply_size;
    submit->reply_shmem = NULL;
 
+   submit->ring_seqno_valid = false;
+
    return &submit->command;
 }
 

Reply via email to