From ce1645619f819540a1465d0c0c90576b07a01b9d Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Mon, 21 Sep 2026 17:37:52 +0800 Subject: [PATCH 1/4] 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"; } + ]; + }; } From 45a35a080dba1a52e5b920aa4976b0267827b025 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Mon, 21 Sep 2026 17:38:54 +0800 Subject: [PATCH 2/4] fix(youko): address the HDDs by-id, not /dev/sdX Follows the disko config (ata-WDC_...-); the sdX names are not stable. --- hosts/12kingdoms-youko/default.nix | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hosts/12kingdoms-youko/default.nix b/hosts/12kingdoms-youko/default.nix index 99ea3b56..622f2afa 100644 --- a/hosts/12kingdoms-youko/default.nix +++ b/hosts/12kingdoms-youko/default.nix @@ -9,6 +9,11 @@ let hostName = "youko"; # Define your hostname. + # The two HDDs behind the flaky USB-SATA bridge, addressed by-id like the + # disko config does (the /dev/sdX names are not stable). + hddPublic = "/dev/disk/by-id/ata-WDC_WD40EJRX-89T1XY0_WD-WCC7K0XDCZE6"; + hddEncrypted = "/dev/disk/by-id/ata-WDC_WD40EZRZ-22GXCB0_WD-WCC7K7VV9613"; + coreModule = mylib.genVmHostModule { inherit pkgs hostName; inherit (myvars) networking; @@ -48,18 +53,15 @@ in # 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" - ]; + after = [ "local-fs.target" ]; 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 + ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 ${hddPublic} || true + ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 ${hddEncrypted} || true ''; }; @@ -69,8 +71,8 @@ in enable = true; notifications.wall.enable = true; devices = [ - { device = "/dev/sda"; } - { device = "/dev/sdb"; } + { device = hddPublic; } + { device = hddEncrypted; } ]; }; } From 899162055a149afbe4ec28d8928458893d238e5e Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Mon, 21 Sep 2026 17:42:21 +0800 Subject: [PATCH 3/4] fix(youko): drop pcie_aspm=off, re-assert the hdparm settings hourly pcie_aspm=off was the least-justified mitigation (the flakiness is on the USB/SATA side) and costs power. Also log the disks' APM level/state and re-apply the settings hourly, since the bridge or the disk firmware can drop them (the disks were still reaching standby). --- hosts/12kingdoms-youko/default.nix | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/hosts/12kingdoms-youko/default.nix b/hosts/12kingdoms-youko/default.nix index 622f2afa..940488ec 100644 --- a/hosts/12kingdoms-youko/default.nix +++ b/hosts/12kingdoms-youko/default.nix @@ -40,7 +40,6 @@ in # 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 @@ -50,7 +49,10 @@ in ''; # 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. + # APM/standby on the HDDs. sdb in particular has ~1M load cycles (WD + # Intellipark), so stopping the idle head-parking also saves its mechanism. + # Read the settings back into the journal, and re-assert them hourly: the + # bridge or the disk's own firmware can drop them. systemd.services.hdd-no-spindown = { description = "Disable APM/standby on the USB HDDs"; after = [ "local-fs.target" ]; @@ -60,11 +62,24 @@ in RemainAfterExit = true; }; script = '' - ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 ${hddPublic} || true - ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 ${hddEncrypted} || true + for d in ${hddPublic} ${hddEncrypted}; do + echo "== $d ==" + ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 "$d" || true + ${pkgs.hdparm}/bin/hdparm -B "$d" || true + ${pkgs.hdparm}/bin/hdparm -C "$d" || true + done ''; }; + systemd.timers.hdd-no-spindown = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnBootSec = "10min"; + OnUnitActiveSec = "1h"; + Persistent = true; + }; + }; + # Watch the disks with SMART. UDMA_CRC_Error_Count growth is the early warning # for the bridge/link problem. services.smartd = { From 5bbe17ebcde17a37a5abc75aefcd05037b5d199e Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Mon, 21 Sep 2026 17:43:05 +0800 Subject: [PATCH 4/4] fix(youko): also try disabling the WD idle3 (Intellipark) timer -B 255 turns APM off and it stuck, but the disks still reach standby, so the bridge firmware is likely doing the spindown. -J 0 additionally asks the drive to stop parking its heads (sdb has ~1M load cycles). --- hosts/12kingdoms-youko/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hosts/12kingdoms-youko/default.nix b/hosts/12kingdoms-youko/default.nix index 940488ec..c25fa1da 100644 --- a/hosts/12kingdoms-youko/default.nix +++ b/hosts/12kingdoms-youko/default.nix @@ -64,8 +64,10 @@ in script = '' for d in ${hddPublic} ${hddEncrypted}; do echo "== $d ==" - ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 "$d" || true + # -B 255: APM off; -S 0: no standby timer; -J 0: WD idle3 (Intellipark) off + ${pkgs.hdparm}/bin/hdparm -B 255 -S 0 -J 0 "$d" || true ${pkgs.hdparm}/bin/hdparm -B "$d" || true + ${pkgs.hdparm}/bin/hdparm -J "$d" || true ${pkgs.hdparm}/bin/hdparm -C "$d" || true done '';