<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, May 31, 2018 at 2:21 PM, Scott D Phillips <span dir="ltr"><<a href="mailto:scott.d.phillips@intel.com" target="_blank">scott.d.phillips@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> writes:<br>
<br>
> ---<br>
> src/intel/vulkan/anv_<wbr>allocator.c | 54 ++++++++++++++++++++++++++++++<wbr>+++++++++-<br>
> 1 file changed, 53 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/src/intel/vulkan/anv_<wbr>allocator.c b/src/intel/vulkan/anv_<wbr>allocator.c<br>
> index 697da5f..f18e015 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>allocator.c<br>
> +++ b/src/intel/vulkan/anv_<wbr>allocator.c<br>
> @@ -1240,7 +1240,8 @@ anv_bo_cache_lookup(struct anv_bo_cache *cache, uint32_t gem_handle)<br>
> #define ANV_BO_CACHE_SUPPORTED_FLAGS \<br>
> (EXEC_OBJECT_WRITE | \<br>
> EXEC_OBJECT_ASYNC | \<br>
> - EXEC_OBJECT_SUPPORTS_48B_<wbr>ADDRESS)<br>
> + EXEC_OBJECT_SUPPORTS_48B_<wbr>ADDRESS | \<br>
> + EXEC_OBJECT_PINNED)<br>
> <br>
> VkResult<br>
> anv_bo_cache_alloc(struct anv_device *device,<br>
> @@ -1269,6 +1270,14 @@ anv_bo_cache_alloc(struct anv_device *device,<br>
> <br>
> bo->bo.flags = bo_flags;<br>
> <br>
> + if (!anv_vma_alloc(device, &bo->bo)) {<br>
> + anv_gem_close(device, bo->bo.gem_handle);<br>
> + vk_free(&device->alloc, bo);<br>
> + return vk_errorf(device->instance, NULL,<br>
> + VK_ERROR_OUT_OF_DEVICE_MEMORY,<br>
> + "failed to allocate virtual address for BO");<br>
> + }<br>
> +<br>
> assert(bo->bo.gem_handle);<br>
> <br>
> pthread_mutex_lock(&cache-><wbr>mutex);<br>
> @@ -1310,6 +1319,38 @@ anv_bo_cache_import(struct anv_device *device,<br>
> new_flags |= (bo->bo.flags | bo_flags) & EXEC_OBJECT_WRITE;<br>
> new_flags |= (bo->bo.flags & bo_flags) & EXEC_OBJECT_ASYNC;<br>
> new_flags |= (bo->bo.flags & bo_flags) & EXEC_OBJECT_SUPPORTS_48B_<wbr>ADDRESS;<br>
> + new_flags |= (bo->bo.flags | bo_flags) & EXEC_OBJECT_PINNED;<br>
> +<br>
> + /* It's theoretically possible for a BO to get imported such that it's<br>
> + * both pinned and not pinned. The only way this can happen is if it<br>
> + * gets imported as both a semaphore and a memory object and that would<br>
> + * be an application error. Just fail out in that case.<br>
> + */<br>
> + if ((bo->bo.flags & EXEC_OBJECT_PINNED) !=<br>
> + (bo_flags & EXEC_OBJECT_PINNED)) {<br>
> + pthread_mutex_unlock(&cache-><wbr>mutex);<br>
> + return vk_errorf(device->instance, NULL,<br>
> + VK_ERROR_INVALID_EXTERNAL_<wbr>HANDLE,<br>
> + "The same BO was imported two different ways");<br>
> + }<br>
> +<br>
> + /* It's also theoretically possible that someone could export a BO from<br>
> + * one heap and import it into another or to import the same BO into two<br>
> + * different heaps. If this happens, we could potentially end up both<br>
> + * allowing and disallowing 48-bit addresses. There's not much we can<br>
> + * do about it if we're pinning so we just throw a warning and hope no<br>
> + * app is actually that stupid.<br>
> + */<br>
> + if ((new_flags & EXEC_OBJECT_PINNED) &&<br>
> + (bo->bo.flags & EXEC_OBJECT_SUPPORTS_48B_<wbr>ADDRESS) &&<br>
> + !(bo_flags & EXEC_OBJECT_SUPPORTS_48B_<wbr>ADDRESS)) {<br>
> + vk_debug_report(&device-><wbr>instance->debug_report_<wbr>callbacks,<br>
> + VK_DEBUG_REPORT_WARNING_BIT_<wbr>EXT,<br>
> + VK_DEBUG_REPORT_OBJECT_TYPE_<wbr>DEVICE_EXT,<br>
> + (uint64_t) (uintptr_t) device,<br>
> + 0, 0, "anv",<br>
> + "Import of the same BO on multiple heaps");<br>
> + }<br>
<br>
</div></div>Hmm, it seems like we should error here too. If the BO is getting used<br>
in a way that doesn't support 48 bit addresses then at best we can hit<br>
one of our known iffy cases, and at worst we might cram a 64 bit address<br>
into a narrower offset field and then possibly get GPU hangs. Or if<br>
there is no such case like this then I think it probably needs some more<br>
explanation about why this isn't an error.<br>
</blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">I think the worst case is that someone will try to make a vertex buffer out of it and maybe get cache corruption. I think that case can theoretically lead to hangs (if it's used for the gpu_memcpy of surface states) but it's pretty hard to hit. I think leaving it as a warning is probably ok.<br></div></div>