Skip to content

pull in leegao's multi-fd AHB mapping fix - #7

Merged
utkarshdalal merged 1 commit into
wrapper-25from
fix-host-side-memory-mapping
Jul 23, 2026
Merged

pull in leegao's multi-fd AHB mapping fix#7
utkarshdalal merged 1 commit into
wrapper-25from
fix-host-side-memory-mapping

Conversation

@utkarshdalal

Copy link
Copy Markdown
Contributor

No description provided.

@leegao leegao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one potential change on 1032 (restructure to iterate on the copied struct instead)

I'm very glad these got caught, the synchronization design is inverted from how you would normally design the mutex control (upstream vs downstream), so these are really easy to get wrong.

* head of the pNext chain, the unlink only updates pCreateInfo->pNext,
* so a copy taken earlier would still pass the unknown struct to the
* driver. */
create_info = *pCreateInfo;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I see what it's trying to say, yeah that's a legitimate type, since VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EMULATED_B8G8R8A8_CREATE_INFO_EXT is always at the head of the chain

fortunately, it'll just raise a validation warning (the WSI code already injects VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA for the system driver), but good catch

An alternative structure is to leave the copy at the top, and change the iteration to

   VkBaseInStructure *prev = &create_info;
   for (const VkBaseInStructure *s = pCreateInfo->pNext; s; s = s->pNext) {
      if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EMULATED_B8G8R8A8_CREATE_INFO_EXT) {
         is_emulated_bgra8 = true;
         prev->pNext = s->pNext; // unlink
         break;
      }
      prev = (VkBaseInStructure *) s;
   }

which has the benefit of not mutating (directly) the upstream pCreateInfo, though we do still change the linked pNext link in place instead of deep-copying everything out so it probably doesn't really matter (we also know who the caller is when this sType extension is sent in, because it's an internal callsite)

// not being able to mmap these.
WRAPPER_LOG(error, "EXT_map_memory_placed emulation failed for swapchain image, bypassing emulation");
simple_mtx_lock(&device->resource_mutex);
simple_mtx_unlock(&device->resource_mutex);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, that's a legitimate copy-paste type, good catch


if (dedicated_allocate_info && dedicated_allocate_info->image != VK_NULL_HANDLE) {
struct wrapper_image *img = get_wrapper_image_from_handle(device, dedicated_allocate_info->image);
/* resource_mutex is already held here and simple_mtx is not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah this is a great catch, it's also a good reason for why getters should never be locked by an exclusive mutex since only upstream controls (and should orchestrate) synchronizaton

You should also change this comment to a TODO to refactor the get-handles to avoid this specific footgun in the future

if (mem->alloc_size > 0) {
mem->map_size = mem->alloc_size;
} else {
off_t res = lseek(fd, 0, SEEK_END);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a potential future TODO here to fortify this in the future is to just plumb the size from AllocateMemory down to here so we don't always have to guess, but that's for later

@utkarshdalal
utkarshdalal merged commit c0f4cf9 into wrapper-25 Jul 23, 2026
2 checks passed
@utkarshdalal
utkarshdalal deleted the fix-host-side-memory-mapping branch July 23, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants