All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Alan Stern <stern@rowland.harvard.edu>, Greg KH <greg@kroah.com>
Cc: Matthias Schwarzott <zzam@gentoo.org>,
	usb-storage@lists.one-eyed-alien.net, linux-usb@vger.kernel.org,
	systemd-devel@lists.freedesktop.org, hirofumi@mail.parknet.co.jp
Subject: Re: [PATCH] usb-storage: Add quirk to defeat Kindle's automatic unload
Date: Thu, 18 Mar 2021 12:39:11 +0100	[thread overview]
Message-ID: <7ca46439-6b7c-ecf1-3e4f-a3a7da868a64@redhat.com> (raw)
In-Reply-To: <20210317190654.GA497856@rowland.harvard.edu>

Hi,

On 3/17/21 8:06 PM, Alan Stern wrote:
> 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.
> 
> Reported-and-tested-by: Matthias Schwarzott <zzam@gentoo.org>
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> CC: <stable@vger.kernel.org>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> 
> ---
> 
> 
> [as1953]
> 
> 
>  drivers/usb/storage/transport.c    |    7 +++++++
>  drivers/usb/storage/unusual_devs.h |   12 ++++++++++++
>  include/linux/usb_usual.h          |    2 ++
>  3 files changed, 21 insertions(+)
> 
> Index: usb-devel/drivers/usb/storage/transport.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/storage/transport.c
> +++ usb-devel/drivers/usb/storage/transport.c
> @@ -656,6 +656,13 @@ void usb_stor_invoke_transport(struct sc
>  		need_auto_sense = 1;
>  	}
>  
> +	/* Some devices (Kindle) require another command after SYNC CACHE */
> +	if ((us->fflags & US_FL_SENSE_AFTER_SYNC) &&
> +			srb->cmnd[0] == SYNCHRONIZE_CACHE) {
> +		usb_stor_dbg(us, "-- sense after SYNC CACHE\n");
> +		need_auto_sense = 1;
> +	}
> +
>  	/*
>  	 * If we have a failure, we're going to do a REQUEST_SENSE 
>  	 * automatically.  Note that we differentiate between a command
> Index: usb-devel/drivers/usb/storage/unusual_devs.h
> ===================================================================
> --- usb-devel.orig/drivers/usb/storage/unusual_devs.h
> +++ usb-devel/drivers/usb/storage/unusual_devs.h
> @@ -2212,6 +2212,18 @@ UNUSUAL_DEV( 0x1908, 0x3335, 0x0200, 0x0
>  		US_FL_NO_READ_DISC_INFO ),
>  
>  /*
> + * Reported by Matthias Schwarzott <zzam@gentoo.org>
> + * The Amazon Kindle treats SYNCHRONIZE CACHE as an indication that
> + * the host may be finished with it, and automatically ejects its
> + * emulated media unless it receives another command within one second.
> + */
> +UNUSUAL_DEV( 0x1949, 0x0004, 0x0000, 0x9999,
> +		"Amazon",
> +		"Kindle",
> +		USB_SC_DEVICE, USB_PR_DEVICE, NULL,
> +		US_FL_SENSE_AFTER_SYNC ),
> +
> +/*
>   * Reported by Oliver Neukum <oneukum@suse.com>
>   * This device morphes spontaneously into another device if the access
>   * pattern of Windows isn't followed. Thus writable media would be dirty
> Index: usb-devel/include/linux/usb_usual.h
> ===================================================================
> --- usb-devel.orig/include/linux/usb_usual.h
> +++ usb-devel/include/linux/usb_usual.h
> @@ -86,6 +86,8 @@
>  		/* lies about caching, so always sync */	\
>  	US_FLAG(NO_SAME, 0x40000000)				\
>  		/* Cannot handle WRITE_SAME */			\
> +	US_FLAG(SENSE_AFTER_SYNC, 0x80000000)			\
> +		/* Do REQUEST_SENSE after SYNCHRONIZE_CACHE */	\
>  
>  #define US_FLAG(name, value)	US_FL_##name = value ,
>  enum { US_DO_ALL_FLAGS };
> 


  reply	other threads:[~2021-03-18 11:40 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-05 16:54 Amazon Kindle disconnect after Synchronize Cache Matthias Schwarzott
2021-03-05 19:14 ` Alan Stern
     [not found]   ` <CAL411-qf+c_CB4cL=2349QqCCYimOBCYxXbsOfLbvVYOg0294g@mail.gmail.com>
2021-03-06 16:07     ` Alan Stern
2021-03-07  5:58   ` Matthias Schwarzott
2021-03-07 15:52     ` Alan Stern
2021-03-07 16:52       ` Matthias Schwarzott
2021-03-07 16:58         ` Alan Stern
2021-03-08 21:59           ` Matthias Schwarzott
2021-03-09 15:50             ` [usb-storage] " Alan Stern
2021-03-10 20:56               ` Matthias Schwarzott
2021-03-10 21:46                 ` Alan Stern
2021-03-11  6:05                   ` Matthias Schwarzott
2021-03-11 14:39                     ` Alan Stern
2021-03-16  5:26                       ` Matthias Schwarzott
2021-03-16 16:26                         ` Alan Stern
2021-03-16 16:43                           ` [systemd-devel] " Hans de Goede
2021-03-16 17:04                             ` Alan Stern
2021-03-16 21:52                               ` Matthias Schwarzott
2021-03-17 12:21                               ` Hans de Goede
2021-03-17 15:17                                 ` Alan Stern
2021-03-17 16:47                                   ` Lennart Poettering
     [not found]                                     ` <F279F9BC020000F5AE14D9EC@gwsmtp.uni-regensburg.de>
     [not found]                                       ` <C63C44570200006665972EEF@gwsmtp.uni-regensburg.de>
     [not found]                                         ` <B960C12A020000A667ECE9F9@gwsmtp.uni-regensburg.de>
     [not found]                                           ` <B72C58530200001565972EEF@gwsmtp.uni-regensburg.de>
     [not found]                                             ` <0F2319EB020000F567ECE9F9@gwsmtp.uni-regensburg.de>
     [not found]                                               ` <DE3F57520200009E65972EEF@gwsmtp.uni-regensburg.de>
     [not found]                                                 ` <52CC0074020000A3D68BC3D5@gwsmtp.uni-regensburg.de>
2021-03-18  7:03                                                   ` Antw: [EXT] " Ulrich Windl
2021-03-18 14:59                                                     ` Alan Stern
     [not found]                                                 ` <474C42CD02000091AE14D9EC@gwsmtp.uni-regensburg.de>
2021-03-18  7:04                                                   ` Ulrich Windl
     [not found]                                                   ` <D43A6F56020000F865972EEF@gwsmtp.uni-regensburg.de>
2021-03-18  7:10                                                     ` Antw: [EXT] [systemd-devel] [PATCH] usb-storage: Add quirk to defeat Kindle's automatic unload Ulrich Windl
2021-03-18 15:03                                                       ` Alan Stern
2021-03-17 17:56                                   ` [systemd-devel] [usb-storage] Re: Amazon Kindle disconnect after Synchronize Cache Matthias Schwarzott
2021-03-17 18:31                                     ` Hans de Goede
2021-03-17 19:06                                     ` [PATCH] usb-storage: Add quirk to defeat Kindle's automatic unload Alan Stern
2021-03-18 11:39                                       ` Hans de Goede [this message]
2021-03-18 13:50                                       ` [systemd-devel] " Tomasz Torcz
2021-03-18 15:07                                         ` Alan Stern
2021-03-16 21:43                           ` [usb-storage] Re: Amazon Kindle disconnect after Synchronize Cache Matthias Schwarzott

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ca46439-6b7c-ecf1-3e4f-a3a7da868a64@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=greg@kroah.com \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=systemd-devel@lists.freedesktop.org \
    --cc=usb-storage@lists.one-eyed-alien.net \
    --cc=zzam@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.