All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Matthias Schwarzott <zzam@gentoo.org>
Cc: linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net,
	hirofumi@mail.parknet.co.jp
Subject: Re: [usb-storage] Re: Amazon Kindle disconnect after Synchronize Cache
Date: Tue, 9 Mar 2021 10:50:46 -0500	[thread overview]
Message-ID: <20210309155046.GA176674@rowland.harvard.edu> (raw)
In-Reply-To: <268e646f-d4ea-3190-f1b9-8e69bfc1b019@gentoo.org>

On Mon, Mar 08, 2021 at 10:59:48PM +0100, Matthias Schwarzott wrote:
> Am 07.03.21 um 17:58 schrieb Alan Stern:

> > Okay.  Can you collect a usbmon trace showing the events leading up to
> > and including a disconnection?
> > 
> The easiest reproducer is by calling sync while having a file/the device
> open (and keeping it open afterwards).
> 
> 1. I recorded usbmon trace like this:
> # cat /sys/kernel/debug/usb/usbmon/3u >
> /tmp/connect-python-sync-disconnect-usbmon.out
> 
> 2. Connect Kindle device
> 
> 3. Then trigger sync with python:
> # python -c "import time; import os; f = open('/dev/sde', 'r+b');
> time.sleep(1); os.fsync(f); time.sleep(5)"
> 
> 4. After 2 seconds Kindle disconnects (does no longer show USB-Mode screen).
> 
> 5. Ctrl+c the recording
> 
> When the final sleep in the python-command is missing, the Kindle does not
> disconnect.
> 
> > Alan Stern
> > 
> > PS: I suspect the SYNCHRONIZE CACHE commands are correlated with the
> > disconnections but don't cause them.  That is, I suspect the
> > disconnections happen when the device has been idle -- and generally the
> > host computer sends a SYNCHRONIZE CACHE command before idling a
> > removable drive.
> > 
> 
> I cannot read the usbmon trace, but wireshark displayed a command "SCSI:
> Prevent/Allow Medium Removal LUN: 0x00  ALLOW" when closing the file.
> So I suspect this command also counts as activity (!idle).

Here is the revelant part of the usbmon trace.  The second value on each 
line is a timestamp in microseconds.

> ffff88814e50d0c0 2440334800 S Bo:3:039:1 -115 31 = 55534243 79000000 00000000 00000600 00000000 00000000 00000000 000000
> ffff88814e50d0c0 2440334822 C Bo:3:039:1 0 31 >
> ffff88814e50d0c0 2440334824 S Bi:3:039:1 -115 13 <
> ffff88814e50d0c0 2440334909 C Bi:3:039:1 0 13 = 55534253 79000000 00000000 00

That is a TEST UNIT READY command, showing normal status.

> ffff88814e50d0c0 2440334922 S Bo:3:039:1 -115 31 = 55534243 7a000000 00000000 0000061e 00000001 00000000 00000000 000000
> ffff88814e50d0c0 2440334949 C Bo:3:039:1 0 31 >
> ffff88814e50d0c0 2440334951 S Bi:3:039:1 -115 13 <
> ffff88814e50d0c0 2440335817 C Bi:3:039:1 0 13 = 55534253 7a000000 00000000 00

That is a PREVENT MEDIUM REMOVAL command, sent when the device file was 
opened by the Python program.

> ffff88814e50d0c0 2441336674 S Bo:3:039:1 -115 31 = 55534243 7b000000 00000000 00000a35 00000000 00000000 00000000 000000
> ffff88814e50d0c0 2441336697 C Bo:3:039:1 0 31 >
> ffff88814e50d0c0 2441336699 S Bi:3:039:1 -115 13 <
> ffff88814e50d0c0 2441336911 C Bi:3:039:1 0 13 = 55534253 7b000000 00000000 00

That is the SYNCHRONIZE CACHE command.  Notice that the timestamp shows 
it occurred one second after the PREVENT MEDIUM REMOVAL.

> ffff88814e50d0c0 2442346649 S Bo:3:039:1 -115 31 = 55534243 7c000000 00000000 00000600 00000000 00000000 00000000 000000
> ffff88814e50d0c0 2442346700 C Bo:3:039:1 0 31 >
> ffff88814e50d0c0 2442346702 S Bi:3:039:1 -115 13 <
> ffff88814e50d0c0 2442346799 C Bi:3:039:1 0 13 = 55534253 7c000000 00000000 00

One second later, a normal TEST UNIT READY.

> ffff88814e50d0c0 2444394684 S Bo:3:039:1 -115 31 = 55534243 7d000000 00000000 00000600 00000000 00000000 00000000 000000
> ffff88814e50d0c0 2444394713 C Bo:3:039:1 0 31 >
> ffff88814e50d0c0 2444394720 S Bi:3:039:1 -115 13 <
> ffff88814e50d0c0 2444394804 C Bi:3:039:1 0 13 = 55534253 7d000000 00000000 01
> ffff88814e50d0c0 2444394821 S Bo:3:039:1 -115 31 = 55534243 7e000000 12000000 80000603 00000012 00000000 00000000 000000
> ffff88814e50d0c0 2444394866 C Bo:3:039:1 0 31 >
> ffff88822c917540 2444394928 S Bi:3:039:1 -115 18 <
> ffff88822c917540 2444395673 C Bi:3:039:1 0 18 = 70000200 0000000a 00000000 3a000000 0000
> ffff88814e50d0c0 2444395696 S Bi:3:039:1 -115 13 <
> ffff88814e50d0c0 2444395723 C Bi:3:039:1 0 13 = 55534253 7e000000 00000000 00

Two seconds later, another TEST UNIT READY.  This one returned a failure 
status, with an error code saying that the medium is not present (in 
spite of the fact that medium removal was supposed to be prevented).

The usbmon trace contains six more TEST UNIT READY commands, sent in 
quick succession, all getting the same failure result.  Notably, it does 
not show any sort of disconnection.  The final timestamp in the trace is 
2446328158, which is just five seconds after the SYNCHRONIZE CACHE 
command was sent -- there's no way to tell if anything happened after 
that.

Maybe there's something else going on under Windows that we're not aware 
of.  The only significant different I can see between this trace and the 
short Windows trace in your original email is the time interval between 
TEST UNIT READY commands; here it is two seconds but with Windows it was 
one second.  You can change the interval by writing to

	/sys/block/sde/events_poll_msecs

What happens if you set the value to 1000 before running the test?

Also, the usbmon trace shows that my guess about power management and 
device disconnections was completely wrong.  The bus does not get 
suspended and the Kindle does not disconnect, even though it seems to 
become unusable.

Alan Stern

  reply	other threads:[~2021-03-09 15:51 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             ` Alan Stern [this message]
2021-03-10 20:56               ` [usb-storage] " 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
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=20210309155046.GA176674@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-usb@vger.kernel.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.