System
- GPU: GeForce RTX 4060 (VBIOS 95.07.36.40.0C)
- Driver: 610.57.04, proprietary kernel module
- Kernel: Linux 7.2.3, NixOS 26.11
- Vulkan loader and headers: 1.4.357
- nvidia-bug-report.log.gz attached
Summary
vkGetMemoryHostPointerPropertiesEXT returns VK_SUCCESS with memoryTypeBits = 0xc for a pointer that the driver then refuses to import. The refusal itself (vkAllocateMemory returns VK_ERROR_OUT_OF_DEVICE_MEMORY) is acceptable. The problem is what happens after it: every later vkAllocateMemory on the same VkInstance fails with VK_ERROR_OUT_OF_DEVICE_MEMORY. That includes a plain 1 MiB device-local allocation with no import, and allocations on a second VkDevice created from the same instance after the failure. Only a new VkInstance recovers: its device allocates normally in the same process.
Under strace -e ioctl, the failing plain allocation makes no ioctl at all (the same allocation makes 12 in a control run), so the user-space driver rejects it without asking the kernel.
Two pointer kinds trigger it:
file: a regular file on disk, mappedPROT_READ | PROT_WRITE, MAP_SHARED.readonly: a memfd mappedPROT_READ, MAP_SHARED.
A memfd mapped read-write imports correctly, and allocations after it keep working.
Expected
The refused import returns an error, and the instance stays usable. Ideally vkGetMemoryHostPointerPropertiesEXT also reports memoryTypeBits = 0 (or an error) for a pointer that cannot be imported.
Impact
A Wayland compositor that imports client wl_shm buffers through this extension loses all GPU memory allocation after one client sends an unimportable buffer, until it destroys and recreates its whole VkInstance with every GPU object on it. A single misbehaving client can break the desktop session. Applications must pre-validate every pointer themselves and cannot rely on the driver’s refusal being harmless.
Reproduction
Build: cc -O1 -o import_poison import_poison.c -lvulkan, then run ./import_poison none, ./import_poison file and ./import_poison readonly. Return code -2 is VK_ERROR_OUT_OF_DEVICE_MEMORY.
Output on this system:
device: NVIDIA GeForce RTX 4060, driver 610.57.4
case: none
1. plain device-local alloc before the import: 0
2. no import attempted (control run)
3. plain device-local alloc after the import: 0
4. plain device-local alloc on a NEW VkDevice, same process: 0
5. plain device-local alloc on a NEW VkInstance + VkDevice, same process: 0
device: NVIDIA GeForce RTX 4060, driver 610.57.4
case: file
1. plain device-local alloc before the import: 0
vkGetMemoryHostPointerPropertiesEXT = 0, memoryTypeBits 0xc
2. host-pointer import (expected to be refused): -2
3. plain device-local alloc after the import: -2
4. plain device-local alloc on a NEW VkDevice, same process: -2
5. plain device-local alloc on a NEW VkInstance + VkDevice, same process: 0
device: NVIDIA GeForce RTX 4060, driver 610.57.4
case: readonly
1. plain device-local alloc before the import: 0
vkGetMemoryHostPointerPropertiesEXT = 0, memoryTypeBits 0xc
2. host-pointer import (expected to be refused): -2
3. plain device-local alloc after the import: -2
4. plain device-local alloc on a NEW VkDevice, same process: -2
5. plain device-local alloc on a NEW VkInstance + VkDevice, same process: 0
(The driver version line decodes driverVersion with the Vulkan bit layout, so 610.57.04 prints as 610.57.4.)
import_poison.c:
// VK_EXT_external_memory_host: after one refused import, later vkAllocateMemory calls fail.
// build: cc -O1 -o import_poison import_poison.c -lvulkan
// run: ./import_poison [file|readonly|none] (default: file)
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <vulkan/vulkan.h>
static VkPhysicalDevice phys;
static VkPhysicalDeviceMemoryProperties mp;
static PFN_vkGetMemoryHostPointerPropertiesEXT host_props;
#define CK(x) do { VkResult r_ = (x); if (r_ != VK_SUCCESS) { printf("%s = %d\n", #x, r_); exit(1); } } while (0)
static uint32_t pick(uint32_t bits, VkMemoryPropertyFlags want) {
for (uint32_t i = 0; i < mp.memoryTypeCount; i++)
if ((bits & (1u << i)) && (mp.memoryTypes[i].propertyFlags & want) == want) return i;
printf("no memory type for bits 0x%x flags 0x%x\n", bits, want);
exit(1);
}
static VkDevice make_device(void) {
float prio = 1.0f;
VkDeviceQueueCreateInfo qci = { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, .queueFamilyIndex = 0,
.queueCount = 1, .pQueuePriorities = &prio };
const char *exts[] = { VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME };
VkDeviceCreateInfo dci = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .queueCreateInfoCount = 1,
.pQueueCreateInfos = &qci, .enabledExtensionCount = 1, .ppEnabledExtensionNames = exts };
VkDevice d;
CK(vkCreateDevice(phys, &dci, NULL, &d));
host_props = (PFN_vkGetMemoryHostPointerPropertiesEXT)vkGetDeviceProcAddr(d, "vkGetMemoryHostPointerPropertiesEXT");
return d;
}
// 1 MiB device-local allocation: the call that must keep working
static VkResult plain_alloc(VkDevice d) {
VkMemoryAllocateInfo ai = { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = 1 << 20,
.memoryTypeIndex = pick(~0u, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) };
VkDeviceMemory m;
VkResult r = vkAllocateMemory(d, &ai, NULL, &m);
if (r == VK_SUCCESS) vkFreeMemory(d, m, NULL);
return r;
}
static VkResult import_ptr(VkDevice d, void *ptr, size_t len) {
VkMemoryHostPointerPropertiesEXT hp = { .sType = VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT };
VkResult r = host_props(d, VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT, ptr, &hp);
printf(" vkGetMemoryHostPointerPropertiesEXT = %d, memoryTypeBits 0x%x\n", r, hp.memoryTypeBits);
if (r != VK_SUCCESS || hp.memoryTypeBits == 0) return r;
VkImportMemoryHostPointerInfoEXT imp = { .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT,
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT, .pHostPointer = ptr };
VkMemoryAllocateInfo ai = { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .pNext = &imp,
.allocationSize = len, .memoryTypeIndex = pick(hp.memoryTypeBits, 0) };
VkDeviceMemory m;
r = vkAllocateMemory(d, &ai, NULL, &m);
if (r == VK_SUCCESS) vkFreeMemory(d, m, NULL);
return r;
}
static void *map_case(const char *mode, size_t len) {
if (!strcmp(mode, "file")) {
// a regular file on disk, mapped MAP_SHARED read-write
char path[] = "./import_poison_XXXXXX";
int fd = mkstemp(path);
unlink(path);
if (fd < 0 || ftruncate(fd, len) < 0) { perror("regular file"); exit(1); }
return mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
}
if (!strcmp(mode, "readonly")) {
// anonymous shared memory, mapped read-only
int fd = memfd_create("ro", MFD_CLOEXEC);
if (fd < 0 || ftruncate(fd, len) < 0) { perror("memfd"); exit(1); }
return mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
}
return NULL;
}
int main(int argc, char **argv) {
const char *mode = argc > 1 ? argv[1] : "file";
VkApplicationInfo app = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_3 };
VkInstanceCreateInfo ici = { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app };
VkInstance inst;
CK(vkCreateInstance(&ici, NULL, &inst));
uint32_t n = 8;
VkPhysicalDevice pds[8];
CK(vkEnumeratePhysicalDevices(inst, &n, pds));
for (uint32_t i = 0; i < n; i++) {
VkPhysicalDeviceProperties p;
vkGetPhysicalDeviceProperties(pds[i], &p);
if (p.vendorID == 0x10de) {
phys = pds[i];
printf("device: %s, driver %u.%u.%u\n", p.deviceName, p.driverVersion >> 22,
(p.driverVersion >> 14) & 0xff, (p.driverVersion >> 6) & 0xff);
}
}
if (!phys) { printf("no NVIDIA device\n"); return 1; }
vkGetPhysicalDeviceMemoryProperties(phys, &mp);
const size_t len = 256 * 1024;
VkDevice d1 = make_device();
printf("case: %s\n", mode);
printf(" 1. plain device-local alloc before the import: %d\n", plain_alloc(d1));
void *ptr = map_case(mode, len);
if (ptr) printf(" 2. host-pointer import (expected to be refused): %d\n", import_ptr(d1, ptr, len));
else printf(" 2. no import attempted (control run)\n");
printf(" 3. plain device-local alloc after the import: %d\n", plain_alloc(d1));
VkDevice d2 = make_device();
printf(" 4. plain device-local alloc on a NEW VkDevice, same process: %d\n", plain_alloc(d2));
vkDestroyDevice(d2, NULL);
vkDestroyDevice(d1, NULL);
vkDestroyInstance(inst, NULL);
VkInstance inst2;
CK(vkCreateInstance(&ici, NULL, &inst2));
n = 8;
CK(vkEnumeratePhysicalDevices(inst2, &n, pds));
phys = VK_NULL_HANDLE;
for (uint32_t i = 0; i < n; i++) {
VkPhysicalDeviceProperties p;
vkGetPhysicalDeviceProperties(pds[i], &p);
if (p.vendorID == 0x10de) phys = pds[i];
}
VkDevice d3 = make_device();
printf(" 5. plain device-local alloc on a NEW VkInstance + VkDevice, same process: %d\n", plain_alloc(d3));
vkDestroyDevice(d3, NULL);
vkDestroyInstance(inst2, NULL);
return 0;
}
Related public reports of the same behaviour
- Driver 595.91.07, read-only range: Linux/NVIDIA: a refused host import of a read-only range makes every later vkAllocateMemory fail · Issue #1022 · boykopovar/AnyPS5 · GitHub
- Driver 580.178.04, GTX 1050 Ti, udmabuf import: AGC: Vulkan device creation fails on the NVIDIA proprietary driver since #943 (dma-buf import probe) · Issue #1289 · boykopovar/AnyPS5 · GitHub
Both projects worked around it on the application side.
nvidia-bug-report.log.gz (693.1 KB)