Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3400363pxf; Mon, 22 Mar 2021 05:42:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTrtOZdgr2wfBDOulTTQfwio+XJmW3toPVqC6zduu87ziRrc6mvgUYqnAU+fSjAtbK3ybK X-Received: by 2002:a17:906:26c9:: with SMTP id u9mr18955061ejc.520.1616416946371; Mon, 22 Mar 2021 05:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616416946; cv=none; d=google.com; s=arc-20160816; b=qTjSfthm/0mjFCTZbPwzRcMrwfDO3/8qHj+TGDyuycEnXAs6LNvuILhj6dssz7WQ2U Rj/2t/T6exYjbX6utNBy7qGr78lZpX4ACLmMqEO6UULr11gH8xPMhVjfHPxFkoF4rgLq XmC3DMaE4LcJtBQ0t4v2OfR4wfsFJqk4iqCYaAS2d33jP6PUr3YQCtUD1wVSsdyT3orW x/u4blgb0z+VQAz7ym/0jVqi8KYn9TIwQmwsZuWmzhfPb/s6CIkqlopusU4bkpfWMHUM 8cxoLaoish20G8pCoXI5a15POAiLn5A6CIHqwN0wDdEBwzpz0TSAJ+r4wHDv04Cuh8UC 0EjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5FCndd8iW+W3nsuAfHXGMhQBXlGk4dxKwo6sCh537B0=; b=kNyCLPevBcgl5dffPZGhsL3t46KoXRf4wcMU6lu0c1DtaVbE7QfJpV1PHInFlfHPxS +BS+Y4PZocH77yRVhdqertUZfPfy1mmHSMse2sLuGZ2K7Nz0yphejowejx4P2Ju4XHeb WSq4C6Kh+8paWOpvHVyv7KEc1ixyxysYPYlnkVMbx4S/TMU9QY1IFv7efpjVoF9mAXDn fuBMi/nlppkzHpcVeFRrgB95hZs9dGWuVF3HqwpuTSojneObchiBxzLQZgX5kbmw6Ng/ UunQCxC5SKHeUPq+bOVDIknJYgSi7R39ia6TOLCwLwX9teM3zV05EkXzz6C+nZKRFb+6 esFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZhxYcjHM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si11449889eds.96.2021.03.22.05.42.02; Mon, 22 Mar 2021 05:42:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZhxYcjHM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231709AbhCVMi6 (ORCPT + 99 others); Mon, 22 Mar 2021 08:38:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:57520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbhCVMeQ (ORCPT ); Mon, 22 Mar 2021 08:34:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 845B7619A1; Mon, 22 Mar 2021 12:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416456; bh=OoSPEFPINv6Vx+HXN6zcG0dnP7MfFtDo4GM5s4E6C8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZhxYcjHMrpBRgQnsEGgCOBNzMbtJHc8AscI9NnN0odzbCeN5X/W2Vz6PImO1Nvssd bBTKTGXKa6hxOWfFN5IkdNM/LzUnpsXlSissB5kHW9RMpr4AaL+Y3UkLvRaxFsFRK4 LvGectE6rlSL/UwxplEXeGae6Di6/WuF2/do1Q0w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Matthias Schwarzott Subject: [PATCH 5.11 078/120] usb-storage: Add quirk to defeat Kindles automatic unload Date: Mon, 22 Mar 2021 13:27:41 +0100 Message-Id: <20210322121932.277196402@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121929.669628946@linuxfoundation.org> References: <20210322121929.669628946@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Stern commit 546aa0e4ea6ed81b6c51baeebc4364542fa3f3a7 upstream. 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: Reported-and-tested-by: Matthias Schwarzott Signed-off-by: Alan Stern Link: https://lore.kernel.org/r/20210317190654.GA497856@rowland.harvard.edu Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/transport.c | 7 +++++++ drivers/usb/storage/unusual_devs.h | 12 ++++++++++++ include/linux/usb_usual.h | 2 ++ 3 files changed, 21 insertions(+) --- a/drivers/usb/storage/transport.c +++ b/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 --- a/drivers/usb/storage/unusual_devs.h +++ b/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 + * 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 * This device morphes spontaneously into another device if the access * pattern of Windows isn't followed. Thus writable media would be dirty --- a/include/linux/usb_usual.h +++ b/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 };