You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xserver/randr
Mario Kleiner d4944ceda1 Fix RandR leasing for more than 1 simultaneously active lease.
Due to a switched order of parameters in the xorg_list_add()
call inside ProcRRCreateLease(), adding a new lease for RandR
output leasing does not actually add the new RRLeasePtr lease
record to the list of existing leases for a X-Screen, but instead
replaces the existing list with a new list that has the new lease
as the only element, and probably leaks a bit of memory.

Therefore the server "forgets" all active leases for a screen,
except for the last added lease. If multiple leases are created
in a session, then destruction of all leases but the last one
will fail in many cases, e.g., during server shutdown in
RRCloseScreen(), or resource destruction, e.g., in
RRCrtcDestroyResource().

Most importantly, it fails if a client simply close(fd)'es the
DRM master descriptor to release a lease, quits, gets killed or
crashes. In this case the kernel will destroy the lease and shut
down the display output, then send a lease event via udev to the
ddx, which e.g., in the modesetting-ddx will trigger a call to
drmmode_validate_leases().

That function is supposed to detect the released lease and tell
the server to terminate the lease on the server side as well,
via xf86CrtcLeaseTerminated(), but this doesn't happen for all
the leases the server has forgotten. The end result is a dead
video output, as the server won't reinitialize the crtc's
corresponding to the terminated but forgotten lease.

This bug was observed when using the amdvlk AMD OSS Vulkan
driver and trying to lease multiple VKDisplay's, and also
under Mesa radv, as both Mesa Vulkan/WSI/Display and amdvlk
terminate leases by simply close()ing the lease fd, not by
sending explicit RandR protocol requests to free leases.

Leasing worked, but ending a session with multiple active
leases ended in a lot of unpleasant darkness.

Fixing the wrong argument order to xorg_list_add() fixes the
problem. Tested on single-X-Screen and dual-X-Screen setups,
with one, two or three active leases.

Please merge this for the upcoming server 21.1 branch.
Merging into server 1.20 would also make a lot of sense.

Fixes: e4e3447603
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Cc: Keith Packard <keithp@keithp.com>
(cherry picked from commit f467f85ca1)
3 years ago
..
Makefile.am Add RandR leases with modesetting driver support [v6] 7 years ago
meson.build meson: hide C API if Xorg is disabled (like autotools) 4 years ago
randr.c present: fallback get_crtc to return crtc belonging to screen with present extension 3 years ago
randrstr.h present: fallback get_crtc to return crtc belonging to screen with present extension 3 years ago
rrcrtc.c present: fix msc offset calculation in screen mode 4 years ago
rrdispatch.c Add RandR leases with modesetting driver support [v6] 7 years ago
rrinfo.c Convert top level extensions to new *allocarray functions 10 years ago
rrlease.c Fix RandR leasing for more than 1 simultaneously active lease. 3 years ago
rrmode.c Add RandR leases with modesetting driver support [v6] 7 years ago
rrmonitor.c xserver/output: rename some badly named variables/APIs. 4 years ago
rroutput.c xserver/output: rename some badly named variables/APIs. 4 years ago
rrpointer.c randr: Fix logic in RRPointerToNearestCrtc 10 years ago
rrproperty.c Add RandR leases with modesetting driver support [v6] 7 years ago
rrprovider.c present: fix msc offset calculation in screen mode 4 years ago
rrproviderproperty.c Convert top level extensions to new *allocarray functions 10 years ago
rrscreen.c xserver/output: rename some badly named variables/APIs. 4 years ago
rrsdispatch.c Add RandR leases with modesetting driver support [v6] 7 years ago
rrtransform.c randr: Silence -Wshift-negative-value warnings 9 years ago
rrtransform.h Drop trailing whitespaces 10 years ago
rrxinerama.c dispatch: Mark swapped dispatch as _X_COLD 8 years ago