Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb-storage: Add quirk to defeat Kindle's automatic unload

Matthias reports that the Amazon Kindle automatically removes its
emulated media if it doesn't receive another SCSI command within about
one second after a SYNCHRONIZE CACHE. It does so even when the host
has sent a PREVENT MEDIUM REMOVAL command. The reason for this
behavior isn't clear, although it's not hard to make some guesses.

At any rate, the results can be unexpected for anyone who tries to
access the Kindle in an unusual fashion, and in theory they can lead
to data loss (for example, if one file is closed and synchronized
while other files are still in the middle of being written).

To avoid such problems, this patch creates a new usb-storage quirks
flag telling the driver always to issue a REQUEST SENSE following a
SYNCHRONIZE CACHE command, and adds an unusual_devs entry for the
Kindle with the flag set. This is sufficient to prevent the Kindle
from doing its automatic unload, without interfering with proper
operation.

Another possible way to deal with this would be to increase the
frequency of TEST UNIT READY polling that the kernel normally carries
out for removable-media storage devices. However that would increase
the overall load on the system and it is not as reliable, because the
user can override the polling interval. Changing the driver's
behavior is safer and has minimal overhead.

CC: <stable@vger.kernel.org>
Reported-and-tested-by: Matthias Schwarzott <zzam@gentoo.org>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20210317190654.GA497856@rowland.harvard.edu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
546aa0e4 98f153a1

+21
+7
drivers/usb/storage/transport.c
··· 656 656 need_auto_sense = 1; 657 657 } 658 658 659 + /* Some devices (Kindle) require another command after SYNC CACHE */ 660 + if ((us->fflags & US_FL_SENSE_AFTER_SYNC) && 661 + srb->cmnd[0] == SYNCHRONIZE_CACHE) { 662 + usb_stor_dbg(us, "-- sense after SYNC CACHE\n"); 663 + need_auto_sense = 1; 664 + } 665 + 659 666 /* 660 667 * If we have a failure, we're going to do a REQUEST_SENSE 661 668 * automatically. Note that we differentiate between a command
+12
drivers/usb/storage/unusual_devs.h
··· 2212 2212 US_FL_NO_READ_DISC_INFO ), 2213 2213 2214 2214 /* 2215 + * Reported by Matthias Schwarzott <zzam@gentoo.org> 2216 + * The Amazon Kindle treats SYNCHRONIZE CACHE as an indication that 2217 + * the host may be finished with it, and automatically ejects its 2218 + * emulated media unless it receives another command within one second. 2219 + */ 2220 + UNUSUAL_DEV( 0x1949, 0x0004, 0x0000, 0x9999, 2221 + "Amazon", 2222 + "Kindle", 2223 + USB_SC_DEVICE, USB_PR_DEVICE, NULL, 2224 + US_FL_SENSE_AFTER_SYNC ), 2225 + 2226 + /* 2215 2227 * Reported by Oliver Neukum <oneukum@suse.com> 2216 2228 * This device morphes spontaneously into another device if the access 2217 2229 * pattern of Windows isn't followed. Thus writable media would be dirty
+2
include/linux/usb_usual.h
··· 86 86 /* lies about caching, so always sync */ \ 87 87 US_FLAG(NO_SAME, 0x40000000) \ 88 88 /* Cannot handle WRITE_SAME */ \ 89 + US_FLAG(SENSE_AFTER_SYNC, 0x80000000) \ 90 + /* Do REQUEST_SENSE after SYNCHRONIZE_CACHE */ \ 89 91 90 92 #define US_FLAG(name, value) US_FL_##name = value , 91 93 enum { US_DO_ALL_FLAGS };