Bug 31686

Summary: JMicron USB3 -> SATA adaptor 152d:0578 requires 'usb-storage.quirks=152d:0578:u'
Product: Mageia Reporter: Barry Jackson <zen25000>
Component: RPM PackagesAssignee: Kernel and Drivers maintainers <kernel>
Status: NEW --- QA Contact:
Severity: normal    
Priority: Normal CC: davidwhodgins
Version: Cauldron   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Source RPM: CVE:
Status comment:

Description Barry Jackson 2023-03-16 17:10:41 CET
Description of problem:
I have a JMicron USB3 -> SATA adaptor for connecting SATA HDD/SSD via USB3.

This works fine connected to a USB2 port and is reasonably fast however when connected to a USB3 port it behaves like a failing drive and booting takes about 5 mins not the 20 seconds or less that it should be.

lsusb shows this as:
Bus 002 Device 007: ID 152d:0578 JMicron Technology Corp. / JMicron USA Technology Corp. JMS578 SATA 6Gb/s

Looking at boot log [Attachment 1 [details]] I see:

A start job for unit plymouth-quit.service has begun execution.
The job identifier is 117.
Mar 13 23:27:25 localhost systemd[1]: plymouth-quit.service: start operation timed out. Terminating.
Mar 13 23:27:46 localhost kernel: sd 5:0:0:0: [sdf] tag#29 uas_eh_abort_handler 0 uas-tag 30 inflight: CMD IN 
Mar 13 23:27:46 localhost kernel: sd 5:0:0:0: [sdf] tag#29 CDB: Read(10) 28 00 00 cd 95 88 00 01 98 00
/------------------------lots more similar------------------------

Google led me to similar issues that have been reported by RPi4 users notably this thread:

https://forums.raspberrypi.com/viewtopic.php?t=245931

This led me to use the following to disable uas at boot:

Adding 'usb-storage.quirks=152d:0578:u' to the kernel command line in /etc/default/grub fixes the boot errors and the device works fine as a fast system disk using a SSD.

However if this adaptor is used for general storage as a USB hot plug device then the fix may not be configured on the system in use, which got me wondering about udev and whether this fix could be somehow added to the udev rule for this device by default.

At this point I may need some help and/or advice, so before I waste too much time on further research I am asking here in case someone has already hit this and come up with an elegant solution.
Comment 1 Barry Jackson 2023-03-16 17:19:22 CET
I have since come across this:

https://unix.stackexchange.com/questions/239782/connection-problem-with-usb3-external-storage-on-linux-uas-driver-problem

May this be the way to go?
Comment 2 Dave Hodgins 2023-03-16 18:31:15 CET
Based on the stackexchange article, it should be easy to create a udev rule
for that specific device such as ...

$ cat /etc/udev/rules.d/00-myusb.rules 
# udev rules file for my usb drive
ACTION!="add", GOTO="myusb_rules_end"
KERNEL=="sd?1", ATTRS{idVendor}=="152d", ATTRS{idProduct}=="0583", , ACTION=="add", RUN+="/bin/echo '152d:0583:u' >> /sys/module/usb_storage/parameters/quirks"
LABEL="myusb_rules_end"

I don't have such a device so can't test the rule. It may be necessary to
escape the single quotes in the RUN command by preceding each with a \.
You could also have the udev command run a script that checks to see if
it device is already listed in the quirks, and do the echo if it isn't
already there.

Assigning to the kernel team to see if there is a better way.

Assignee: bugsquad => kernel
CC: (none) => davidwhodgins

Comment 3 Barry Jackson 2023-03-16 22:17:32 CET
Thanks Dave,
I can't get a rule to write directly to .../quirks, I tried escaping the single quotes and a few other quoting combinations to no avail.
(note the ATTRS{idProduct}=="0583" was also wrong ;)

Calling a separate script from the rule works fine.

From journal:
Mar 16 20:33:55 jackodesktop (udev-worker)[302548]: sde1: /etc/udev/rules.d/00-myusb.rules:3 RUN '/bin/usbquirkadd'

[root@jackodesktop baz]# cat /sys/module/usb_storage/parameters/quirks
152d:0578:u

Now after plugging the device:
[root@jackodesktop baz]# udevadm monitor --environment|grep ID_USB_DRIVER
ID_USB_DRIVER=usb-storage

where previously it was:
ID_USB_DRIVER=uas

So the current rule is:
cat /etc/udev/rules.d/00-myusb.rules

# udev rules file for my usb drive
ACTION!="add", GOTO="myusb_rules_end"
KERNEL=="sd?1", ATTRS{idVendor}=="152d", ATTRS{idProduct}=="0578", , ACTION=="add", RUN+="/bin/usbquirkadd"
LABEL="myusb_rules_end"

Calling:
[root@jackodesktop baz]# cat /bin/usbquirkadd

#!/bin/bash
if ! grep "152d:0578:u" /sys/module/usb_storage/parameters/quirks; then
        echo "152d:0578:u" >> /sys/module/usb_storage/parameters/quirks
fi

If this could be fixed in the default udev rule for this device, then there would be no need to manually add another rule to use it.
Comment 4 Barry Jackson 2023-03-16 23:34:38 CET
I can only assume that udev is blocked from writing to /sys/module/usb_storage/parameters/quirks as well as other sensitive system folders.

This does not error (with or without escaping ' ), but neither does it write anything to quirks.

KERNEL=="sd?1", ATTRS{idVendor}=="152d", ATTRS{idProduct}=="0578", , ACTION=="add", RUN+="/bin/sh -cv echo '152d:0578:u' >> /sys/module/usb_storage/parameters/quirks"

I am out of ideas trying to avoid the extra script and it's bed time :(