Commit Graph

552 Commits

Author SHA1 Message Date
Tautvis
af9afa287a modesetting: pageflip: clear new_front_bo struct in ms_do_pageflip
ms_do_pageflip function temporary creates and destroy drmmode_bo object, but
the structure is stack ( values goes uninitialized). This became problem
because in f4362fc4ec drmmode_bo struct got extra
fields which is checked during drmmode_bo_destroy and causes crash.

Signed-off-by: Tautvis <gtautvis@gmail.com>
2026-01-29 14:35:48 +01:00
John Studnicka
8fa58d3b51 modesetting: Handle reflected/rotated cursors better
Moved the cursor glyph cropping into a separate function that handles reflections and rotations.

Also, x/y are indexes into the buffer, so they should be clamped to width/height len - 1 for correctness.

Signed-off-by: John Studnicka <contact@zentec.dev>
2026-01-29 14:33:13 +01:00
stefan11111
f209e71fb9 modesetting: Use GBM_FORMAT_XRGB8888 for 24-bit depth front bo's
Same as what we use in glamor/glamor_egl.c

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2026-01-27 19:16:20 +01:00
stefan11111
50ffe711ca modesetting: map gbm bo's read/write
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2026-01-27 19:16:20 +01:00
stefan11111
f4362fc4ec modesetting: Track both the map data and address for gpu buffers
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2026-01-27 19:16:20 +01:00
John Studnicka
fb976abad0 modesetting: Clamp image dims to avoid OOB reads
Signed-off-by: John Studnicka <contact@zentec.dev>
2026-01-27 19:15:35 +01:00
John Studnicka
57a9686e65 modesetting: Rotate cursor to match screen
Signed-off-by: John Studnicka <contact@zentec.dev>
2026-01-27 19:15:35 +01:00
John Studnicka
23dfcba633 modesetting: Fall back to SW cursor for OOB dims
Signed-off-by: John Studnicka <contact@zentec.dev>
2026-01-27 19:15:35 +01:00
stefan11111
8cb69cd810 modesetting: clear bo in drmmode_create_front_bo
Fixes: https://github.com/X11Libre/xserver/issues/1740

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2026-01-01 13:23:22 +01:00
b-aaz
a53697e70e xfree86: meson: Use install_symlink function instead of a hack.
This was a old hack used before Meson 0.61.0 added install_symlink, we
are at the meson release 1.10.0 so it is safe to use the new proper
function for this task.

Also used the X server's executable name as the link target name, and as
the SUID wrapper's name.

Moved the minimum Meson version up to 0.61.0.

Signed-off-by: b-aaz <b-aazbsd@proton.me>
2025-12-21 11:39:23 +01:00
Oleh Nykyforchyn
ae689438dc xfree86/modesetting: prevent modesetting driver from
grabbing claimed slots

This patch makes modesetting driver use the return value of the extended
xf86ClaimFbSlot to prevent crashes.

Fixes: https://github.com/X11Libre/xserver/issues/1505
Signed-off-by: Oleh Nykyforchyn <oleh.nyk@gmail.com>
2025-12-10 15:00:31 +01:00
stefan11111
58143b96fd modesetting: don't leak memory for the cursor plane if libdrm is too old
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-12-08 14:23:09 +01:00
stefan11111
5ade87efc7 modesetting: Use don't skip planes that are not on the current crtc
This breaks on some nvidia cards.

Fixes: ed49ae8fe7

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-12-08 14:23:09 +01:00
Tautvis
64326cc92e Patch 5/5 modesetting: try to get gpu device fd from seatd arbiter
The device node opening with seatd, like with systemd-logind can done during probe
(see get_drm_info in hw/xfree86/os-support/shared/drm_platform.c),
but in case of failure, the modesetting driver tries to open device
node directly (open_hw function in modesetting/driver.c).

This enchanes open_hw function to try use seatd arbiter for opening device node
in as last resort manner.

To make it functional seatd_libseat_open_graphics needs to have _X_EXPORT

Signed-off-by: tautvis <gtautvis gmail com>
2025-12-05 12:29:52 +01:00
stefan11111
3f821b291e modesetting: get more values from the fallback cursor probe
The space needed to store these extra values is at worst a few dozen bytes.
In exchange for these, larger cursors glyphs can use a more optimal cursor size.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-12-02 10:14:12 +01:00
stefan11111
c01c4e7c72 modesetting: Only close the dmabuf fd if it isn't -1
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-28 18:44:22 +01:00
Icenowy Zheng
03fa63778b modesetting: fix shared pixmap dmabuf fd leakage
After the dmabuf fd exported by another screen is imported to a pixmap,
the pixmap holds a reference for the buffer, thus the FD itself finished
its job and needs to be closed to prevent a stale reference to the
buffer.

Signed-off-by: Icenowy Zheng's avatarIcenowy Zheng <uwu@icenowy.me>
2025-11-28 18:44:22 +01:00
stefan11111
6be7fe9d12 modesetting: print message when reverse prime mode is enabled
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-28 18:44:22 +01:00
stefan11111
5460be02c9 modesetting: read DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP when parsing async flip capabilities
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-26 10:53:36 +01:00
stefan11111
7b301ee278 modesetting: small formating changes and extra NULL checks
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-26 10:51:48 +01:00
Oleh Nykyforchyn
77830f2284 modesetting: make DevPrivateKeyRec struct static
dixRegisterPrivateKey() assumes that DevPrivateKeyRec struct passed
to it is zero-filled before the first use, otherwise assert() fails.
Therefore these structs are usually static, which assures that they
are initialized to 0. A newly introduced key in the modesetting driver
was not static, and the driver crashed. This should be corrected.

Signed-off-by: Oleh Nykyforchyn <oleh.nyk@gmail.com>
2025-11-22 13:24:44 +01:00
stefan11111
7293fc12fe modesetting: map gbm bo's if possible
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-21 10:17:51 +01:00
Chase
fcbb2bafce treewide: replace __FUNCTION__ by __func__
prefer C99 standard over non-standard legacy symbols

Signed-off-by: Chase <chinkle3@illinois.edu>
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-18 13:29:47 +01:00
stefan11111
434331e129 modesetting: Split chosing gbm format into drmmode_gbm_format_for_depth
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-17 18:55:20 +01:00
stefan11111
68e3e9fcb1 modesetting: rename drmmode_bo_has_bo to drmmode_bo_get_bo
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-17 18:55:20 +01:00
stefan11111
db77a579c6 modesetting: don't return a value from drmmode_bo_destroy
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-17 18:55:20 +01:00
stefan11111
49c9aaac82 modesetting: Move the compatibility GBM_BO_USE_FRONT_RENDERING define to the top of the file
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-17 18:55:20 +01:00
stefan11111
8bb2fc9d76 modesetting: Create the front buffer with GBM_BO_USE_FRONT_RENDERING
Also renamed `drmmode_create_bo` to `drmmode_create_front_bo`,
better reflecting how it is used.

According to the mesa docs: https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/gbm/main/gbm.h :
```
   /**
    * The buffer will be used for front buffer rendering.  On some
    * platforms this may (for example) disable framebuffer compression
    * to avoid problems with compression flags data being out of sync
    * with pixel data.
    */
   GBM_BO_USE_FRONT_RENDERING = (1 << 6),
```

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-10 11:08:59 +01:00
stefan11111
53f1095118 modesetting: Fix leak when disabling hw cursor
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-10 10:31:55 +01:00
stefan11111
bd540a8f46 modesetting: don't probe size_hints if the cursor is already probed
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-10 10:28:00 +01:00
stefan11111
ed49ae8fe7 modesetting: clean up drmmode_crtc_create_planes
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-10 10:28:00 +01:00
stefan11111
e5df974aab modesetting: get the SIZE_HINTS cursor plane property in drmmode_crtc_create_planes
We were duplicating this code needlessly and in an error-prone way.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-10 10:28:00 +01:00
Enrico Weigelt, metux IT consult
6bc92a5674 modesetting: replace tabs by whitespace
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-07 16:42:27 +01:00
stefan11111
516239c164 modesetting: Fix -Wunused-variable warnings
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-07 15:38:15 +01:00
notbabaisyou
6c924809e4 modesetting: Make the async-flipping key global. 2025-11-06 15:56:07 +01:00
Qiang Yu
c5fad50afe modesetting: fix PRESENT_FLIP_REASON_BUFFER_FORMAT gets overwritten
When dmabuf_capable is enabled, ms_present_check_unflip may return
with reason PRESENT_FLIP_REASON_BUFFER_FORMAT to be reported back
to client by PresentCompleteModeSuboptimalCopy. We should not
overwrite it by page flip reasons anyway when exit.

This fix also avoid changing vblank->exec_msc in present_scmd_pixmap()
which caused by page flip reasons to prevent a present to be executed
immediatly. So that we can cancel pending vblanks when new vblanks with
same msc arrive. This happens when application just starts.

This problem can be observed at least using radeonsi OGL driver, start
xserver with dmabuf_capable enabled, no window manager, glxgears will
stuck for the first several seconds. If using a composite window manager
like Mutter, we can't observe the glxgears stuck, but the prensent
complete event still shows unexpected Copy mode instead of
PresentCompleteModeSuboptimalCopy or Skip mode.

glxgears window msc is 0 at the beginning, it will send present request
with target msc = 1, 2, 3, ... N before server send back the complete
event for target msc = 1. But server side window msc is way bigger than N,
so it will think all these present requests are outdated and just show the
Nth request at the next vblank. [1 .. N-1] requests should be skipped.
But without this fix, all [1 .. N] presents will be executed with Copy
mode which causes stuck.

Fixes: a94dd953 ("modesetting: add support for TearFree page flips")
2025-11-06 15:56:07 +01:00
notbabaisyou
e26da636bf modesetting: Allow selecting more optimal modifiers. 2025-11-06 15:56:07 +01:00
notbabaisyou
0c6cb9532b modesetting: Omit DRM_FORMAT_MOD_INVALID.
Previously it was possible for the invalid modifier to be placed in the IN_FORMATS or IN_FORMATS_ASYNC arrays, this is of course not wanted as this can cause problems with devices that lack support for explicit modifiers.
2025-11-06 15:56:07 +01:00
Ville Syrjälä
d3ec45f01c modesetting: Use IN_FORMATS_ASYNC for async flips
Use the IN_FORMATS_ASYNC blob (as opposed to the normal
IN_FORMATS blob) to determine which formats/modifiers are
supported. This will allow the client to allocate buffers
which can actually be async flipped.

In order to guarantee that the most optimal modifier is
always used we also need to force a modifier renegotiation
when swicthing between sync and async flips. Otherwise eg.
sync flips might end up using a less optimal sync+async
modifier instead of a more optimal sync-only modifier.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
Link: https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1816
2025-11-06 15:56:07 +01:00
Ville Syrjälä
a345c59673 modesetting: Parse the IN_FORMATS_ASYNC blob
The kernel has gained another format/modifier blob to indicate
which formats/modifiers support async flips since Linux 6.16. Parse it.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
2025-11-06 15:56:07 +01:00
Ville Syrjälä
a87fb7577e modesetting: Enable universal planes client cap
Enable the universal planes client cap so that we actually
get access to the primary plane's IN_FORMATS blob. We will
now start to parse the blob.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
2025-11-06 15:56:07 +01:00
Ville Syrjälä
671a8ee04c modesetting: Don't try to use modifiers when allocating the root pixmap
We want the root pixmap to use conservative tiling modifiers in
order to make sure modeset/etc can never fail due to hardware
watermark restictions/etc.

Currenlty this is all dead code anyway because we aren't actually
parsing the IN_FORMATS blob (missing universal plane client cap).
But we want to start parsing that, so let's first make sure we
don't get any behavioural changes from doing so.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
2025-11-06 15:56:07 +01:00
Tautvis
16a1be1939 modesetting: call xf86_cursors_fini during CloseScreen
Add matching call for xf86_cursors_init to clean memory, as during
initialization it allocates memory (depends, but is something like ~256Kb)
and it leaks when XServer resets.

Signed-off-by: Tautvis <gtautvis@gmail.com>
2025-11-04 12:12:58 +01:00
stefan11111
585810fb13 modesetting: Handle bo allocation failure
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-03 17:15:14 +01:00
stefan11111
cf4b49ac84 modesetting: Create the largest possible cursor image buffer.
Since https://github.com/X11Libre/xserver/pull/1234 landed,
the user has a way to set the hw cursor size to the size they want.

The fallback probe works around driver bugs by probing very late,
so it initializes the cursor image buffer with the largest size the driver supports.

With this change, the SIZE_HINTS probe will also initialize
the cursor image buffer with the largest size it finds,
which is what @notbabaisyou 's code originally did.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-30 12:34:52 +01:00
stefan11111
011d7bfac3 modesetting: handle some allocation failures
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-27 15:16:12 +01:00
stefan11111
8b8cde2cb2 modesetting: add "CursorSize" option
On certain setups, it might still be useful to force a particular cursor
size via xorg.conf.
For example, if on a system the automatic probes fail, or if the user wants
a particular cursor size, that is higher that the minimum size.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-21 16:12:46 +02:00
stefan11111
cf092cd469 modesetting: probe using the old method if SIZE_HINTS isn't available
On most cards, SIZE_HINTS isn't available.
Without this, most users would have to set the fallback cursor size themselves,
or rely on the 64x64 default.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-21 16:12:46 +02:00
stefan11111
6f7731c44c modesetting: Fix cursor buffer not getting cleared when the pitch changes.
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-21 16:12:46 +02:00
stefan11111
036432980b modesetting: Initialize the cursor image with the smallest size supported by all CRTCs.
We try to find the smallest size we can use for the cursor image.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-13 14:01:04 +02:00