From ce1645619f819540a1465d0c0c90576b07a01b9d Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Mon, 21 Sep 2026 17:37:52 +0800 Subject: [PATCH] fix(youko): mitigate the flaky USB-SATA HDD bridge The two 4TB HDDs sit behind a JMicron JMS567 that resets and throws UDMA-CRC / I/O errors (the disks themselves are healthy). Best-effort mitigations while the enclosure stays in use: - kernel: usbcore.autosuspend=-1, usb-storage.delay_use=10, pcie_aspm=off - udev: keep the bridge's power/control=on (never autosuspend) - disable APM/standby on the HDDs (spindown is a common reset trigger) - enable smartd (watch the CRC count and disk health) The kernel parameters need a reboot to take effect. --- hosts/12kingdoms-youko/default.nix | 47 ++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/hosts/12kingdoms-youko/default.nix b/hosts/12kingdoms-youko/default.nix index 6d492e23..99ea3b56 100644 --- a/hosts/12kingdoms-youko/default.nix +++ b/hosts/12kingdoms-youko/default.nix @@ -31,11 +31,46 @@ in # scheduling). The VMs now use ordinary memory. "transparent_hugepage=madvise" - # https://kubevirt.io/user-guide/compute/host-devices/ - # - # PCI passthrough - # "amd_iommu=on" # enable IOMMU - # "iommu=pt" # use passthrough mode - # "pcie_acs_override=downstream" # enable ACS override + # --- mitigations for the flaky USB-SATA bridge the two 4TB HDDs sit behind. + # It is a JMicron JMS567 that resets and throws link (UDMA-CRC) + I/O errors. + "usbcore.autosuspend=-1" # no USB autosuspend + "usb-storage.delay_use=10" # give the bridge time to settle after probing + "pcie_aspm=off" # ASPM can also make the link flap ]; + + # Keep the bridge powered: a suspended device is what most often triggers a + # reset on resume. + services.udev.extraRules = '' + ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="152d", ATTR{idProduct}=="0567", TEST=="power/control", ATTR{power/control}="on" + ''; + + # A spindown/spinup is a common trigger for the bridge resetting, so disable + # APM/standby on the HDDs. Best effort: hdparm may not get through the bridge. + systemd.services.hdd-no-spindown = { + description = "Disable APM/standby on the USB HDDs"; + after = [ + "dev-sda.device" + "dev-sdb.device" + ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + script = '' + ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 /dev/sda || true + ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 /dev/sdb || true + ''; + }; + + # Watch the disks with SMART. UDMA_CRC_Error_Count growth is the early warning + # for the bridge/link problem. + services.smartd = { + enable = true; + notifications.wall.enable = true; + devices = [ + { device = "/dev/sda"; } + { device = "/dev/sdb"; } + ]; + }; }