Repository navigation
Conversation
setup_loader_term_phys_devs frees every loader_physical_device_term that is missing from the latest vkEnumeratePhysicalDevices call. A VkDevice created from such a physical device kept a pointer to it, and loader_lookup_device_dispatch_table read it on every vkGetDeviceProcAddr. All users of the pointer only need the driver, which owns the loader_device, so store the driver instead.
|
User aizu-m not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
User aizu-m not on autobuild list. Waiting for curator authorization before starting CI build. |
|
CI Vulkan-Loader build queued with queue ID 201736. |
|
CI Vulkan-Loader build # 4014 running. |
|
CI Vulkan-Loader build # 4014 passed. |
charles-lunarg
left a comment
There was a problem hiding this comment.
This isn't the right solution. There is an underlying problem when the loader receives VK_ERROR_INITIALIZATION_FAILED from vkEnumeratePhysicalDevices, it frees VkPhysicalDevice handles that the application holds, which is against the spec.
I can confirm this by adding the following code to the end of DriverUnloadingFromZeroPhysDevs.GetDeviceProcAddrAfterPhysicalDeviceRemoved
{
DeviceWrapper dev_2{inst};
dev_2.create_info.add_device_queue(DeviceQueueCreateInfo{}.add_priority(0.0f));
dev_2.CheckCreate(phys_devs[0]);
DeviceWrapper dev_3{inst};
dev_3.create_info.add_device_queue(DeviceQueueCreateInfo{}.add_priority(0.0f));
dev_3.CheckCreate(phys_devs[1]);
PFN_vkVoidFunction create_command_pool_0 = inst->vkGetDeviceProcAddr(dev_0, "vkCreateCommandPool");
ASSERT_NE(nullptr, create_command_pool_0);
PFN_vkVoidFunction create_command_pool_1 = inst->vkGetDeviceProcAddr(dev_1, "vkCreateCommandPool");
ASSERT_NE(nullptr, create_command_pool_1);
}It crashes with a heap-use-after-free when unwrapping the VkPhysicalDevice during the call to vkCreateDevice.
I can work on this unless you want to take a crack at it. If you don't/can't, I'll create an issue to track it since its a pretty serious bug (even if unlikely to be encountered in the wild).
AddressSanitizer, macOS Debug build with
LOADER_ENABLE_ADDRESS_SANITIZER=ON, new test run against the unpatched loader:Found while following up the note in #2103. That PR kept the driver loaded when its physical device disappears. The physical device object is still freed.
Investigation:
setup_loader_term_phys_devsruns on everyvkEnumeratePhysicalDevices. It frees each oldloader_physical_device_termthat is not in the new list. It does not check for live devices.terminator_CreateDevicestores that object inloader_device::phys_dev_term.loader_lookup_device_dispatch_tablereadsdev->phys_dev_term->this_icd_term->this_instancebefore the name switch. AnyvkGetDeviceProcAddrfor avk*name the trampoline does not answer itself gets there.init_extension_device_proc_terminator_dispatch, thevkCreateSwapchainKHRlog) also only wantthis_icd_term.Conclusion: the device only needs its driver. The driver owns the
loader_devicethroughlogical_device_list, so that pointer cannot dangle. The fix stores theloader_icd_terminstead. The generator and generated file are updated together andgenerate_source.py --verifypasses.The test creates a device on each of two drivers and makes one driver fail enumeration. It then calls
vkGetDeviceProcAddron both devices. Unpatched it gives the trace above. Patched it passes. macOS (Debug, ASAN,BUILD_WERROR=ON): 655/655.