Skip to content

Sync upstream changes#6

Open
github-actions[bot] wants to merge 42 commits into
mainfrom
upstream
Open

Sync upstream changes#6
github-actions[bot] wants to merge 42 commits into
mainfrom
upstream

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 1, 2026

Automated sync from upstream repository

maxiicodes and others added 30 commits February 27, 2026 00:20
Several glibc functions now return a const pointer if the input is a
const pointer and a non-const pointer if the input is non-const, causing
a build failure.

Fix this by declaring the output pointers as const if they are never
modified, and for the lone failure where the output is modified, instead
make the input non-const.

Signed-off-by: Maximilian Hofmann <maxi@maxiicodes.dev>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1599>
Using SOCK_CLOEXEC and MSG_CMSG_CLOEXEC are good practice for socket
communication, but venus client/server model doesn't involve any racy
exec on parallel threads.

Meanwhile, the ad-hoc server forked from the proxy client is after
socket pair, and we manually close up corresponding fds on both client
and server side.

As for passing resource fds via socket, there's no requirement to set
FD_CLOEXEC both internally and towards the virgl resource side.

Just to ease MacOS adoption.

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1603>
We do not have signalfd() in macOS so we use kqueue() to listen for
SIGCHLD. Also do not include <threads.h> when we do not have
ENABLE_RENDER_SERVER_WORKER_THREAD.

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
macOS does not have clock_nanosleep()

Co-authored-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
macOS does not support SOCK_SEQPACKET so we have to make use of SOCK_STREAM.
That means we have to take care of framing. Thankfully, the SCM_RIGHTS
buffer will always be complete and ordered so we send that with a header
indicating the number of bytes for the packet followed by the packet.

Co-authored-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
When the peer closes the socket (e.g. QEMU dies abnormally),
recvmsg() returns 0 on SOCK_STREAM.  The existing loop only
checked for s < 0, so a zero return caused want -= 0 (a no-op)
and the loop spun at 100% CPU forever.

Add s == 0 checks in both recvmsg and sendmsg paths of
render_socket and proxy_socket, returning false to signal
disconnection.  This lets the render server exit cleanly
when QEMU terminates without calling proxy_server_destroy().

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
kqueue file descriptors do not support fcntl(F_SETFL, O_NONBLOCK)
on macOS.  The kqueue code added in "server: add support for building
on macOS" attempted to set O_NONBLOCK this way, which failed silently.

Remove the broken fcntl call.  Non-blocking behavior is already
achieved in render_worker_jail_drain_sigchld_fd() via kevent() with
a zero timeout, which is the correct approach for kqueue.

Fixes: eb2b98b4 ("server: add support for building on macOS")
Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
Rename proxy_socket_is_seqpacket and render_socket_is_seqpacket to
proxy_socket_is_valid and render_socket_is_valid. The functions now
validate the expected socket type per platform: SOCK_STREAM on macOS,
SOCK_SEQPACKET elsewhere. This removes the #ifndef __APPLE__ guards
at every call site.

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
This is to prepare for clean process spawn on non-Linux platforms e.g.
MacOS and Windows. Also close the fds before ownership transfer. Inspired from
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1601

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1607>
This helps skip:
- render_worker_jail_create
- render_server_run

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1607>
This ensures we don't unexpectedly unset VK_RING_STATUS_IDLE_BIT_MESA
when the ring is still idle when spurious wakeups occur. The bug pattern
would be driver side stuck in ring seqno progression. This change also
properly handles cnd_wait errors.

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1610>
The absolute wait target should be update only when real timeout occurs
but not spurious wakeups. The bug pattern would be driver side unable to
detect heartbeat, ending up with a false-positive ring alive status
expiration. The chance to hit this is really low though.

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1610>
On macOS, Metal shader compilation uses XPC (Mach port-based IPC).
Pure fork() without exec() inherits stale XPC connections from the
parent process, causing Metal to fail silently in worker subprocesses.

Use posix_spawn() to create worker processes on macOS.  posix_spawn()
atomically creates a fresh process image without an intermediate
forked state, ensuring valid XPC connections for Metal.
POSIX_SPAWN_CLOEXEC_DEFAULT closes all file descriptors by default;
only the context fd is explicitly inherited via addinherit_np().

The spawned worker receives its context via command-line arguments
(--ctx-fd, --ctx-id, --init-flags, --ctx-name) and enters
render_context_main() directly, bypassing the server socket loop.

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1601>
If Y_0_TOP is not set, we should not flip the cursor data. Downstream consumers like QEMU expect the returned buffer to be the cursor in a format where y=0 is bottom. This fixes a bug where QEMU renders an inverted mouse cursor if using a gl-accelerated display with certain wayland compositors (for example wl-roots based) in the guest.

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1611>
When vrend_renderer_init() hits cleanup_and_fail, it calls
vrend_renderer_fini(), which in turn calls vrend_free_fences().
vrend_free_fences() asserts that the sync thread has already been freed:

qemu-system-i386: ../src/vrend/vrend_renderer.c:7268: vrend_free_fences:
Assertion `!vrend_state.sync_thread' failed.

This tear sync thread down to avoid above misleading error log.

Signed-off-by: Julia Zhang <Julia.Zhang@amd.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1613>
virgl_renderer_resource_map_fixed() was reading res->fd_type and res->fd
into local variables before checking whether virgl_resource_lookup()
had returned NULL, so a stale or invalid res_handle from a guest would
crash the renderer before the -EINVAL early-return could fire.

Move the initialisations below the NULL check so the lookup failure
returns cleanly.

Signed-off-by: Adam Ford <adam.ford@anodize.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1614>
Add macOS-specific dynamic library names for Vulkan loading.
Try libvulkan.1.dylib and libvulkan.dylib first (Vulkan SDK loader),
then fall back to libMoltenVK.dylib (direct MoltenVK usage).

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
Enable Objective-C compilation and link Metal.framework and
Foundation.framework on macOS.  These are required for the Metal
helper wrappers that implement cross-process GPU memory sharing
via MTLBuffer.

Add vkr_metal_helpers.h/.m with:
  - vkr_metal_get_device(): retrieve the MTLDevice backing a VkDevice
    via vkExportMetalObjectsEXT (correct for multi-GPU systems)
  - vkr_mtl_shm_alloc()/free(): allocate and release Metal shared
    memory (SHM file + mmap + MTLBuffer)

Move the with_host_darwin detection before compiler warning flags
so Objective-C arguments can be set alongside C arguments.

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
Detect VK_EXT_external_memory_metal and VK_EXT_metal_objects from
MoltenVK's physical device extension list.  Skip opaque fd export
probing when Metal external memory is available, since MoltenVK
does not support opaque fd handles.

Inject VK_KHR_external_memory_fd into the guest's view of the physical
device extension list so the Mesa Venus driver accepts the device.
MoltenVK does not natively support KHR_external_memory_fd; virglrenderer
emulates it via Metal buffers backed by POSIX SHM.

The injection sets the extension as advertised but does NOT mark
physical_dev->KHR_external_memory_fd = true.  That flag tracks native
host support and is intentionally left false: it gates the host-side
vkCreateDevice call, which must not forward KHR_external_memory_fd to
MoltenVK (rejected with VK_ERROR_EXTENSION_NOT_PRESENT).

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
lseek() behavior is undefined on POSIX shared memory objects per
POSIX.1.  On platforms where os_create_anonymous_file() uses
shm_open(), lseek() returns -1, breaking the existing size
validation.

Replace lseek(fd, 0, SEEK_END) with fstat(), which works on all fd
types.  Also page-align the expected size before comparing, since
the server rounds up SHM allocations to page boundaries.

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
lucaaamaral and others added 12 commits April 23, 2026 22:34
macOS lacks memfd_create and SHM_ANON.  Add a shm_open() path with
random name generation and immediate shm_unlink() to create anonymous
shared memory files.

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
Implement cross-process GPU memory sharing via Metal buffers backed
by POSIX shared memory.  For HOST_VISIBLE allocations on macOS,
allocate a page-aligned SHM file, mmap it, wrap as MTLBuffer using
the cached vkr_device->mtl_device, and import into Vulkan via
VK_EXT_external_memory_metal.  The SHM fd is exported as
VIRGL_RESOURCE_FD_SHM for the VMM to map into the guest address
space.

Cache the MTLDevice in struct vkr_device at vkCreateDevice time via
vkExportMetalObjectsEXT, which returns the exact MTLDevice backing
the VkPhysicalDevice (correct for multi-GPU systems).

Page-align SHM allocation in vkr_context_create_resource_from_shm()
for hv_vm_map alignment.

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
When vkCreateInstance fails, the passed VkInstance handle might become
non-NULL, which is allowed by the spec. Passing an invalid non-NULL
handle to vkDestroyInstance violates the spec, whereas NULL is allowed.

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1616>
The temp variables are all marked precise and assigning to the output
is usually a indirect mopve in this case, so we should be good here
and it avoids creating broken glsl.

Closes: https://gitlab.freedesktop.org/virgl/virglrenderer/-/work_items/650

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1619>
Remove fails that are fixed now.

Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1619>
v2 (zzyiwei): roll the exact header used by venus-protocol

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
This also adds vkEnumerateInstanceExtensionProperties support to prepare
for portability extension support.

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
MoltenVK requires loading with
`VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR` which means that we
will detect and load any library with portability enumeration extension.

v2 (zzyiwei):
- hide portability enumeration enablement behind __APPLE__
- misc refactors and clang-format

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
This is required for MoltenVK to work.

v2 (zzyiwei):
- no extra guard needed since we have it at instance level
- misc refactors

Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
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.

8 participants