Mesa (main): lavapipe: add an env var to enable poisoning memory allocations

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 1 01:34:38 UTC 2022


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Mon Mar 28 17:39:08 2022 -0400

lavapipe: add an env var to enable poisoning memory allocations

it's not random, but it's definitely not zero or any other expected
value, which means it's going to break anything that was passing due to lucky
uninitialized values

Reviewed-by: Emma Anholt <emma at anholt.net>
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15620>

---

 src/gallium/frontends/lavapipe/lvp_device.c  | 4 ++++
 src/gallium/frontends/lavapipe/lvp_private.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c
index 4747ed941c8..057020af5d8 100644
--- a/src/gallium/frontends/lavapipe/lvp_device.c
+++ b/src/gallium/frontends/lavapipe/lvp_device.c
@@ -1675,6 +1675,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDevice(
       return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
    device->queue.state = device + 1;
+   device->poison_mem = debug_get_bool_option("LVP_POISON_MEMORY", false);
 
    struct vk_device_dispatch_table dispatch_table;
    vk_device_dispatch_table_from_entrypoints(&dispatch_table,
@@ -1988,6 +1989,9 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_AllocateMemory(
       if (!mem->pmem) {
          goto fail;
       }
+      if (device->poison_mem)
+         /* this is a value that will definitely break things */
+         memset(mem->pmem, UINT8_MAX / 2 + 1, pAllocateInfo->allocationSize);
    }
 
    mem->type_index = pAllocateInfo->memoryTypeIndex;
diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h
index 32de5840fa8..5e8c8a4fa45 100644
--- a/src/gallium/frontends/lavapipe/lvp_private.h
+++ b/src/gallium/frontends/lavapipe/lvp_private.h
@@ -211,6 +211,7 @@ struct lvp_device {
    struct lvp_instance *                       instance;
    struct lvp_physical_device *physical_device;
    struct pipe_screen *pscreen;
+   bool poison_mem;
 };
 
 void lvp_device_get_cache_uuid(void *uuid);



More information about the mesa-commit mailing list