Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: fix Desktop crash at launch on Wayland with NVIDIA and an iGPU (#13892)

Indrajit swain061d5257738d
diff --git a/studio/src-tauri/src/linux_webkit.rs b/studio/src-tauri/src/linux_webkit.rs
index fda015b348d..1bc9412ef2c 100644
--- a/studio/src-tauri/src/linux_webkit.rs
+++ b/studio/src-tauri/src/linux_webkit.rs
@@ -30,9 +30,6 @@ const APPLIED_WORKAROUND: &str = "UNSLOTH_WEBKIT_RENDERER_WORKAROUND";
const FORCE_SHARED_MEMORY_MIN_VERSION: (u32, u32) = (2, 44);
// both the proprietary and open nvidia modules publish this; nouveau does not and is unaffected
const NVIDIA_DRIVER_VERSION_PATH: &str = "/proc/driver/nvidia/version";
-// The open modules announce themselves in the same file the presence probe already reads.
-const OPEN_KERNEL_MODULE_MARKER: &str = "Open Kernel Module";
-const DRM_CLASS_DIR: &str = "/sys/class/drm";
const NVIDIA_REASON: &str = "NVIDIA driver loaded (no Wayland session)";
const NVIDIA_APPIMAGE_X11_REASON: &str = "NVIDIA driver loaded (AppImage on X11)";
@@ -41,8 +38,6 @@ const NVIDIA_APPIMAGE_GLES_REASON: &str =
"NVIDIA driver loaded; AppImage without a usable GLES library";
const WAYLAND_REASON: &str = "Wayland session";
const APPIMAGE_GLES_REASON: &str = "AppImage without a usable GLES library";
-const COMPOSITING_REASON: &str =
- "Wayland session on NVIDIA with mixed GPU vendors and the open kernel module";
const COMPOSITING_FORCED_REASON: &str = "compositing workaround requested by the environment";
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -53,6 +48,9 @@ enum RenderingWorkaround {
/// lets selection reach FORCE_SHM. Unpatched libraries ignore the variable.
ForceSharedMemoryOnNvidia,
DisableCompositingOnNvidiaX11,
+ /// Compositing off on top of the NVIDIA Wayland transport, not instead of it: since
+ /// WebKitGTK 2.53 non-composited mode still renders over DMA-BUF (#13875).
+ DisableCompositingOnNvidiaWayland,
DisableDmabuf,
/// Not a transport at all. The others choose how buffers reach the compositor; this
/// stops WebKit compositing on the GPU at all.
@@ -67,6 +65,7 @@ impl RenderingWorkaround {
Self::DisableCompositingOnNvidiaX11 => {
&[FORCE_SHARED_MEMORY, FORCE_DMABUF, DISABLE_COMPOSITING]
}
+ Self::DisableCompositingOnNvidiaWayland => &[DISABLE_DMABUF, DISABLE_COMPOSITING],
Self::DisableDmabuf => &[DISABLE_DMABUF],
Self::DisableCompositing => &[DISABLE_COMPOSITING],
}
@@ -135,8 +134,6 @@ fn rendering_plan(
nvidia_driver_loaded: bool,
wayland_socket: bool,
x11_open: bool,
- mixed_gpu_vendors: bool,
- open_kernel_module: bool,
) -> RenderingPlan {
// Either renderer variable is an operator override when present, `=0` and an empty
// value included, unless the marker says we wrote it. Without that test a launch
@@ -187,36 +184,19 @@ fn rendering_plan(
&& gles_usable
&& supports_force_shared_memory(webkit_version);
- // A freeze, not a transport failure, and none of the switches below reach it. The
- // WebKit web process stops executing about 45 seconds in and never resumes: every
- // frontend timer stops together while the native watchdog, in another process, keeps
- // answering. One Wayland NVIDIA host froze under FORCE_SHM, under DISABLE_DMABUF and
- // under neither, and ran clean with compositing off or off Wayland.
- //
- // Not gated on Wayland plus NVIDIA alone: a second host on the same driver and the
- // same WebKitGTK does not freeze, and that predicate would take accelerated
- // compositing off a machine that is demonstrably fine. The two axes separating them
- // are mixed GPU vendors (an Intel iGPU beside the NVIDIA dGPU) and the open kernel
- // module. Requiring BOTH is overfitted on purpose: with one host on each side neither
- // axis is established, so the conservative rule leaves every measured machine as it is
- // today. Anyone outside it reporting the same freeze gets the setting above.
+ // Opt-in only. Do not auto-apply it on Wayland NVIDIA mixed-GPU open-module hosts (#9734):
+ // #13875 has that shape and crashes with Error 71 under it, while DISABLE_DMABUF works.
let setting = env(DISABLE_COMPOSITING_SETTING);
let requested = |wanted: bool| setting.as_deref().and_then(compositing_setting) == Some(wanted);
- if !requested(false)
- && (requested(true)
- || (wayland_session && nvidia_driver_loaded && mixed_gpu_vendors && open_kernel_module))
- {
- let reason = if requested(true) {
- COMPOSITING_FORCED_REASON
- } else {
- COMPOSITING_REASON
- };
- let workaround = if requested(true) && nvidia_x11 {
+ if requested(true) {
+ let workaround = if nvidia_x11 {
RenderingWorkaround::DisableCompositingOnNvidiaX11
+ } else if nvidia_driver_loaded && !force_dmabuf && wayland_session {
+ RenderingWorkaround::DisableCompositingOnNvidiaWayland
} else {
RenderingWorkaround::DisableCompositing
};
- return RenderingPlan::Apply(workaround, reason);
+ return RenderingPlan::Apply(workaround, COMPOSITING_FORCED_REASON);
}
// Per display server, not per GPU. Wayland: DISABLE_DMABUF, FORCE_SHM still hits the
@@ -349,43 +329,6 @@ fn nvidia_driver_loaded() -> bool {
std::path::Path::new(NVIDIA_DRIVER_VERSION_PATH).exists()
}
-/// Is more than one GPU vendor present, e.g. an Intel iGPU beside an NVIDIA dGPU?
-///
-/// Reads PCI vendor ids out of sysfs, opening no device and no GL context, so it is safe
-/// before GTK init. That is the same constraint that stops the NVIDIA probe asking which
-/// GPU will actually render.
-fn mixed_gpu_vendors_in(dir: &str) -> bool {
- let Ok(entries) = std::fs::read_dir(dir) else {
- return false;
- };
- let mut seen: Vec<String> = Vec::new();
- for entry in entries.flatten() {
- let name = entry.file_name();
- let name = name.to_string_lossy();
- // cardN only. `cardN-CONNECTOR` entries are outputs of a card already counted, and
- // renderDN is the same device under a second node.
- if !name.starts_with("card") || name.contains('-') {
- continue;
- }
- // A card with no readable vendor is a virtual framebuffer (simpledrm and friends),
- // and such hosts are not rare. Counting "missing" as a vendor of its own would make
- // every one of them look hybrid.
- let Ok(vendor) = std::fs::read_to_string(entry.path().join("device/vendor")) else {
- continue;
- };
- let vendor = vendor.trim().to_owned();
- if !vendor.is_empty() && !seen.iter().any(|known| *known == vendor) {
- seen.push(vendor);
- }
- }
- seen.len() > 1
-}
-
-/// The open kernel modules say so in the file the presence probe already reads.
-fn open_kernel_module_at(path: &str) -> bool {
- std::fs::read_to_string(path).is_ok_and(|text| text.contains(OPEN_KERNEL_MODULE_MARKER))
-}
-
fn gles_is_usable() -> bool {
// Match libepoxy's runtime load, including unresolved dependencies.
unsafe {
@@ -435,8 +378,6 @@ pub fn configure_renderer() -> Option<(&'static [&'static str], &'static str)> {
nvidia_driver_loaded(),
wayland_socket_present(),
x11_display_open(std::env::var_os(X11_DISPLAY), X11_SOCKET_DIR),
- mixed_gpu_vendors_in(DRM_CLASS_DIR),
- open_kernel_module_at(NVIDIA_DRIVER_VERSION_PATH),
) {
RenderingPlan::Apply(workaround, reason) => {
let variables = workaround.variables();
@@ -519,22 +460,10 @@ mod tests {
nvidia_driver_loaded,
wayland_socket,
x11_open,
- // Every pre-existing case models a single-vendor host on the proprietary
- // module, which is what they asserted before the compositing rule existed.
- // Keeping that default here is what makes those assertions still mean the
- // same thing: the new rule cannot fire in any of them.
- false,
- false,
)
}
- /// The compositing rule's own inputs, which no other case varies.
- fn plan_on_graphics(
- vars: &[(&str, &str)],
- nvidia_driver_loaded: bool,
- mixed_gpu_vendors: bool,
- open_kernel_module: bool,
- ) -> RenderingPlan {
+ fn plan_on_graphics(vars: &[(&str, &str)], nvidia_driver_loaded: bool) -> RenderingPlan {
let live = named(vars, WAYLAND_DISPLAY);
rendering_plan(
|name| {
@@ -547,8 +476,6 @@ mod tests {
nvidia_driver_loaded,
live,
named(vars, X11_DISPLAY),
- mixed_gpu_vendors,
- open_kernel_module,
)
}
@@ -736,6 +663,13 @@ mod tests {
(&[(GDK_BACKEND, "x11")][..], true),
(&[][..], false),
(&[(WAYLAND_DISPLAY, "wayland-0")][..], false),
+ (
+ &[
+ (WAYLAND_DISPLAY, "wayland-0"),
+ (DISABLE_COMPOSITING_SETTING, "1"),
+ ][..],
+ true,
+ ),
];
for (session, nvidia) in hosts {
let first = plan_on_host(session, MODERN_WEBKIT, true, nvidia);
@@ -1223,57 +1157,58 @@ mod tests {
RenderingPlan::PreserveEnvironment
);
}
- // The compositing rule. Two real hosts sit on either side of it, and these tests are
- // named after what each one measured rather than after the branch it exercises.
const WAYLAND: &[(&str, &str)] = &[(WAYLAND_DISPLAY, "wayland-0")];
#[test]
- fn the_freezing_host_gets_compositing_turned_off() {
- // Ubuntu 26.04, GNOME Wayland, Intel Arc iGPU beside an RTX 4050 Mobile, open
- // kernel module. Froze at about 45s under FORCE_SHM, under DISABLE_DMABUF and
- // under neither, and kept polling for a full run with compositing off.
+ fn wayland_nvidia_hosts_get_the_dmabuf_workaround_whatever_the_gpu_mix() {
+ // #13875 (Arrow Lake iGPU + RTX 5080, open module) crashed with Error 71 under
+ // compositing off alone, and the planner no longer sees vendors or modules.
assert_eq!(
- plan_on_graphics(WAYLAND, true, true, true),
- RenderingPlan::Apply(RenderingWorkaround::DisableCompositing, COMPOSITING_REASON)
+ plan_on_graphics(WAYLAND, true),
+ RenderingPlan::Apply(RenderingWorkaround::DisableDmabuf, NVIDIA_WAYLAND_REASON)
);
}
#[test]
- fn the_healthy_nvidia_wayland_host_is_left_alone() {
- // Linux Mint 22, Cinnamon on Wayland, two discrete NVIDIA cards on the proprietary
- // module, same driver and same WebKitGTK as the host above, and it does not freeze.
- // Gating on Wayland plus NVIDIA alone would take compositing off a machine that is
- // measurably fine, so it keeps the transport workaround it has today.
- let plan = plan_on_graphics(WAYLAND, true, false, false);
- assert_ne!(
- plan,
- RenderingPlan::Apply(RenderingWorkaround::DisableCompositing, COMPOSITING_REASON)
+ fn forcing_compositing_off_on_nvidia_wayland_keeps_dmabuf_off() {
+ // On WebKitGTK 2.54 compositing off alone still renders over DMA-BUF and hits the
+ // same explicit-sync Error 71 as #13875.
+ let forced: &[(&str, &str)] = &[
+ (WAYLAND_DISPLAY, "wayland-0"),
+ (DISABLE_COMPOSITING_SETTING, "1"),
+ ];
+ assert_eq!(
+ plan_on_graphics(forced, true),
+ RenderingPlan::Apply(
+ RenderingWorkaround::DisableCompositingOnNvidiaWayland,
+ COMPOSITING_FORCED_REASON
+ )
);
assert_eq!(
- plan,
- RenderingPlan::Apply(RenderingWorkaround::DisableDmabuf, NVIDIA_WAYLAND_REASON)
+ RenderingWorkaround::DisableCompositingOnNvidiaWayland.variables(),
+ &[DISABLE_DMABUF, DISABLE_COMPOSITING]
+ );
+ // FORCE_DMABUF stands the NVIDIA branch down here too.
+ let standing_down: &[(&str, &str)] = &[
+ (WAYLAND_DISPLAY, "wayland-0"),
+ (DISABLE_COMPOSITING_SETTING, "1"),
+ (FORCE_DMABUF, "1"),
+ ];
+ assert_eq!(
+ plan_on_graphics(standing_down, true),
+ RenderingPlan::Apply(
+ RenderingWorkaround::DisableCompositing,
+ COMPOSITING_FORCED_REASON
+ )
);
- }
-
- #[test]
- fn either_axis_alone_is_not_enough() {
- // With one host on each side neither axis is established on its own, so a machine
- // matching only one keeps today's behaviour.
- for (mixed, open) in [(true, false), (false, true)] {
- assert_eq!(
- plan_on_graphics(WAYLAND, true, mixed, open),
- RenderingPlan::Apply(RenderingWorkaround::DisableDmabuf, NVIDIA_WAYLAND_REASON),
- "mixed_gpu_vendors={mixed} open_kernel_module={open}"
- );
- }
}
#[test]
fn nvidia_x11_takes_its_dedicated_compositing_fallback() {
let appimage: &[(&str, &str)] = &[(APPIMAGE, "/tmp/Unsloth.AppImage"), (X11_DISPLAY, ":0")];
assert_eq!(
- plan_on_graphics(appimage, true, false, false),
+ plan_on_graphics(appimage, true),
RenderingPlan::Apply(
RenderingWorkaround::DisableCompositingOnNvidiaX11,
NVIDIA_APPIMAGE_X11_REASON
@@ -1281,7 +1216,7 @@ mod tests {
);
let native: &[(&str, &str)] = &[(X11_DISPLAY, ":0")];
assert_eq!(
- plan_on_graphics(native, true, false, false),
+ plan_on_graphics(native, true),
RenderingPlan::Apply(
RenderingWorkaround::DisableCompositingOnNvidiaX11,
NVIDIA_REASON
@@ -1291,11 +1226,9 @@ mod tests {
#[test]
fn the_setting_settles_a_report_without_a_new_predicate() {
- // Both directions without shipping code: a host outside the rule that reports the
- // same freeze, and a host inside it that the rule is wrong about.
let forced: &[(&str, &str)] = &[(DISABLE_COMPOSITING_SETTING, "1")];
assert_eq!(
- plan_on_graphics(forced, false, false, false),
+ plan_on_graphics(forced, false),
RenderingPlan::Apply(
RenderingWorkaround::DisableCompositing,
COMPOSITING_FORCED_REASON
@@ -1306,7 +1239,7 @@ mod tests {
(DISABLE_COMPOSITING_SETTING, "0"),
];
assert_eq!(
- plan_on_graphics(off, true, true, true),
+ plan_on_graphics(off, true),
RenderingPlan::Apply(RenderingWorkaround::DisableDmabuf, NVIDIA_WAYLAND_REASON)
);
@@ -1315,7 +1248,7 @@ mod tests {
(DISABLE_COMPOSITING_SETTING, "0"),
];
assert_eq!(
- plan_on_graphics(nvidia_x11_off, true, false, false),
+ plan_on_graphics(nvidia_x11_off, true),
RenderingPlan::Apply(
RenderingWorkaround::ForceSharedMemoryOnNvidia,
NVIDIA_APPIMAGE_X11_REASON
@@ -1323,7 +1256,7 @@ mod tests {
);
let native_off: &[(&str, &str)] = &[(DISABLE_COMPOSITING_SETTING, "0")];
assert_eq!(
- plan_on_graphics(native_off, true, false, false),
+ plan_on_graphics(native_off, true),
RenderingPlan::Apply(
RenderingWorkaround::ForceSharedMemoryOnNvidia,
NVIDIA_REASON
@@ -1336,7 +1269,7 @@ mod tests {
// An unrecognized opt-out is no longer a no-op: it leaves the host on the fallback.
for off in ["0", "false", "no", "off", "FALSE", "Off", " 0 ", "\tno\n"] {
assert_eq!(
- plan_on_graphics(&[(DISABLE_COMPOSITING_SETTING, off)], true, false, false),
+ plan_on_graphics(&[(DISABLE_COMPOSITING_SETTING, off)], true),
RenderingPlan::Apply(
RenderingWorkaround::ForceSharedMemoryOnNvidia,
NVIDIA_REASON
@@ -1346,7 +1279,7 @@ mod tests {
}
for on in ["1", "true", "yes", "on", "TRUE", "On", " 1 "] {
assert_eq!(
- plan_on_graphics(&[(DISABLE_COMPOSITING_SETTING, on)], false, false, false),
+ plan_on_graphics(&[(DISABLE_COMPOSITING_SETTING, on)], false),
RenderingPlan::Apply(
RenderingWorkaround::DisableCompositing,
COMPOSITING_FORCED_REASON
@@ -1356,13 +1289,8 @@ mod tests {
}
for unknown in ["", "maybe", "2", "-1", "enabled"] {
assert_eq!(
- plan_on_graphics(
- &[(DISABLE_COMPOSITING_SETTING, unknown)],
- true,
- false,
- false
- ),
- plan_on_graphics(&[], true, false, false),
+ plan_on_graphics(&[(DISABLE_COMPOSITING_SETTING, unknown)], true),
+ plan_on_graphics(&[], true),
"{unknown:?} should not read as an instruction"
);
}
@@ -1377,7 +1305,7 @@ mod tests {
let native: &[(&str, &str)] = &[(DISABLE_COMPOSITING_SETTING, "1")];
for vars in [forced, native] {
assert_eq!(
- plan_on_graphics(vars, true, false, false),
+ plan_on_graphics(vars, true),
RenderingPlan::Apply(
RenderingWorkaround::DisableCompositingOnNvidiaX11,
COMPOSITING_FORCED_REASON
@@ -1390,54 +1318,8 @@ mod tests {
fn an_operator_who_set_the_variable_keeps_their_environment() {
let theirs: &[(&str, &str)] = &[(WAYLAND_DISPLAY, "wayland-0"), (DISABLE_COMPOSITING, "1")];
assert_eq!(
- plan_on_graphics(theirs, true, true, true),
+ plan_on_graphics(theirs, true),
RenderingPlan::PreserveEnvironment
);
}
-
- #[test]
- fn a_virtual_framebuffer_does_not_make_a_host_look_hybrid() {
- // A card with no readable vendor is a virtual framebuffer, and hosts pair one with
- // real GPUs. Counting a missing vendor as its own would make them all match.
- let dir = std::env::temp_dir().join(format!("unsloth-drm-{}", std::process::id()));
- let _ = std::fs::remove_dir_all(&dir);
- let card = |name: &str| dir.join(name).join("device");
- std::fs::create_dir_all(card("card0")).unwrap();
- std::fs::create_dir_all(card("card1")).unwrap();
- std::fs::write(card("card1").join("vendor"), "0x10de\n").unwrap();
- let path = dir.to_string_lossy().into_owned();
- assert!(!mixed_gpu_vendors_in(&path), "one real vendor is not mixed");
-
- // A connector entry is an output of a card already counted, not a second device.
- std::fs::create_dir_all(card("card1-DP-1")).unwrap();
- std::fs::write(card("card1-DP-1").join("vendor"), "0x8086\n").unwrap();
- assert!(!mixed_gpu_vendors_in(&path), "connectors are not devices");
-
- std::fs::create_dir_all(card("card2")).unwrap();
- std::fs::write(card("card2").join("vendor"), "0x8086\n").unwrap();
- assert!(mixed_gpu_vendors_in(&path), "Intel beside NVIDIA is mixed");
- let _ = std::fs::remove_dir_all(&dir);
- }
-
- #[test]
- fn the_open_module_is_read_from_the_file_the_probe_already_opens() {
- let dir = std::env::temp_dir().join(format!("unsloth-nvrm-{}", std::process::id()));
- std::fs::create_dir_all(&dir).unwrap();
- let open = dir.join("open");
- let proprietary = dir.join("proprietary");
- std::fs::write(
- &open,
- "NVRM version: NVIDIA UNIX Open Kernel Module for x86_64 580.173.02\n",
- )
- .unwrap();
- std::fs::write(
- &proprietary,
- "NVRM version: NVIDIA UNIX x86_64 Kernel Module 580.173.02\n",
- )
- .unwrap();
- assert!(open_kernel_module_at(&open.to_string_lossy()));
- assert!(!open_kernel_module_at(&proprietary.to_string_lossy()));
- assert!(!open_kernel_module_at("/nonexistent/nvidia/version"));
- let _ = std::fs::remove_dir_all(&dir);
- }
}