From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BEF3C433E0 for ; Fri, 7 Aug 2020 09:52:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D7E12177B for ; Fri, 7 Aug 2020 09:52:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728337AbgHGJwD (ORCPT ); Fri, 7 Aug 2020 05:52:03 -0400 Received: from comms.puri.sm ([159.203.221.185]:47890 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727037AbgHGJwB (ORCPT ); Fri, 7 Aug 2020 05:52:01 -0400 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id F19AADFFF7; Fri, 7 Aug 2020 02:51:27 -0700 (PDT) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l325WMJvISft; Fri, 7 Aug 2020 02:51:27 -0700 (PDT) Subject: Re: [PATCH] scsi: sd: add runtime pm to open / release From: Martin Kepplinger To: Alan Stern Cc: James Bottomley , Bart Van Assche , Can Guo , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@puri.sm References: <20200729143213.GC1530967@rowland.harvard.edu> <1596033995.4356.15.camel@linux.ibm.com> <1596034432.4356.19.camel@HansenPartnership.com> <1596037482.4356.37.camel@HansenPartnership.com> <20200729182515.GB1580638@rowland.harvard.edu> <1596047349.4356.84.camel@HansenPartnership.com> <20200730151030.GB6332@rowland.harvard.edu> <9b80ca7c-39f8-e52d-2535-8b0baf93c7d1@puri.sm> Autocrypt: addr=martin.kepplinger@puri.sm; keydata= mQINBFULfZABEADRxJqDOYAHfrp1w8Egcv88qoru37k1x0Ugy8S6qYtKLAAt7boZW+q5gPv3 Sj2KjfkWA7gotXpASN21OIfE/puKGwhDLAySY1DGNMQ0gIVakUO0ji5GJPjeB9JlmN5hbA87 Si9k3yKQQfv7Cf9Lr1iZaV4A4yjLP/JQMImaCVdC5KyqJ98Luwci1GbsLIGX3EEjfg1+MceO dnJTKZpBAKd1J7S2Ib3dRwvALdiD7zqMGqkw5xrtwasatS7pc6o/BFgA9GxbeIzKmvW/hc3Q amS/sB12BojyzdUJ3TnIoAqvwKTGcv5VYo2Z+3FV+/MJVXPo8cj2vmfxQx1WG4n6X0pK4X8A BkCKw2N/evMZblNqAzzGVtoJvqQYkzQ20Fm+d3wFl6lS1db4MB+kU13G8kEIE22Q3i6kx4NA N49FLlPeDabGfJUyDaZp5pmKdcd7/FIGH/HjShjx7g+LKSwWNMkDygr4WARAP4h8zYDZuNqe ofPvMLqJxHeexBPIGF/+OwMyTvM7otP5ODuFmq6OqjNPf1irJmkiFv3yEa+Ip0vZzwl4XvrZ U0IKjSy2rbRLg22NsJT0XVZJbutIXYSvIHGqSxzzfiOOLnRjR++fbeEoVlRJ4NZHDKCh3pJv LNd+j03jXr4Rm058YLgO7164yr7FhMZniBJw6z648rk8/8gGPQARAQABtC1NYXJ0aW4gS2Vw cGxpbmdlciA8bWFydGluLmtlcHBsaW5nZXJAcHVyaS5zbT6JAk4EEwEIADgWIQTyCCuID55C OTRobj9QA5jfWrOH0wUCXPSlkwIbAwULCQgHAgYVCAkKCwIEFgIDAQIeAQIXgAAKCRBQA5jf WrOH06/FEACC/GTz88DOdWR5JgghjtOhaW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ekMtxgNYb/8oDry09UFHbGHLsWn6oBo= Message-ID: <425990b3-4b0b-4dcf-24dc-4e7e60d5869d@puri.sm> Date: Fri, 7 Aug 2020 11:51:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 In-Reply-To: <9b80ca7c-39f8-e52d-2535-8b0baf93c7d1@puri.sm> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04.08.20 11:39, Martin Kepplinger wrote: > On 30.07.20 17:10, Alan Stern wrote: >> On Thu, Jul 30, 2020 at 10:52:14AM +0200, Martin Kepplinger wrote: >>> Maybe I should just start a new discussion with a patch, but the below >>> is what makes sense to me (when I understand you correctly) and seems to >>> work. I basically add a new flag, so that the old flags behave unchanged >>> and only call it during *runtime* resume for SD cards: >>> >>> >>> --- a/drivers/scsi/scsi_error.c >>> +++ b/drivers/scsi/scsi_error.c >>> @@ -553,15 +553,21 @@ int scsi_check_sense(struct scsi_cmnd *scmd) >>> * information that we should pass up to the upper-level >>> driver >>> * so that we can deal with it there. >>> */ >>> - if (scmd->device->expecting_cc_ua) { >>> + if (scmd->device->expecting_cc_ua || >>> + scmd->device->expecting_media_change) { >>> /* >>> * Because some device does not queue unit >>> * attentions correctly, we carefully check >>> * additional sense code and qualifier so as >>> - * not to squash media change unit attention. >>> + * not to squash media change unit attention; >>> + * unless expecting_media_change is set, indicating >>> + * that the media (most likely) didn't change >>> + * but a device only believes so (for example >>> + * because of suspend/resume). >>> */ >>> - if (sshdr.asc != 0x28 || sshdr.ascq != 0x00) { >>> - scmd->device->expecting_cc_ua = 0; >>> + if ((sshdr.asc != 0x28 || sshdr.ascq != 0x00) || >>> + scmd->device->expecting_media_change) { >>> + scmd->device->expecting_media_change = 0; >>> return NEEDS_RETRY; >>> } >>> } >>> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c >>> index d90fefffe31b..b647fab2b663 100644 >>> --- a/drivers/scsi/sd.c >>> +++ b/drivers/scsi/sd.c >>> @@ -114,6 +114,7 @@ static void sd_shutdown(struct device *); >>> static int sd_suspend_system(struct device *); >>> static int sd_suspend_runtime(struct device *); >>> static int sd_resume(struct device *); >>> +static int sd_resume_runtime(struct device *); >>> static void sd_rescan(struct device *); >>> static blk_status_t sd_init_command(struct scsi_cmnd *SCpnt); >>> static void sd_uninit_command(struct scsi_cmnd *SCpnt); >>> @@ -574,7 +575,7 @@ static const struct dev_pm_ops sd_pm_ops = { >>> .poweroff = sd_suspend_system, >>> .restore = sd_resume, >>> .runtime_suspend = sd_suspend_runtime, >>> - .runtime_resume = sd_resume, >>> + .runtime_resume = sd_resume_runtime, >>> }; >>> >>> static struct scsi_driver sd_template = { >>> @@ -3652,6 +3653,21 @@ static int sd_resume(struct device *dev) >>> return ret; >>> } >>> >>> +static int sd_resume_runtime(struct device *dev) >>> +{ >>> + struct scsi_disk *sdkp = dev_get_drvdata(dev); >>> + >>> + /* Some SD cardreaders report media change when resuming from >>> suspend >>> + * because they can't keep track during suspend. */ >>> + >>> + /* XXX This is not unproblematic though: We won't notice when a card >>> + * was really changed during runtime suspend! We basically rely >>> on users >>> + * to unmount or suspend before doing so. */ >>> + sdkp->device->expecting_media_change = 1; >>> + >>> + return sd_resume(dev); >>> +} >>> + >>> /** >>> * init_sd - entry point for this driver (both when built in or when >>> * a module). >>> diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h >>> index bc5909033d13..8c8f053f71c8 100644 >>> --- a/include/scsi/scsi_device.h >>> +++ b/include/scsi/scsi_device.h >>> @@ -169,6 +169,8 @@ struct scsi_device { >>> * this device */ >>> unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN >>> * because we did a bus reset. */ >>> + unsigned expecting_media_change:1; /* Expecting media change >>> ASC/ASCQ >>> + when it actually doesn't >>> change */ >>> unsigned use_10_for_rw:1; /* first try 10-byte read / write */ >>> unsigned use_10_for_ms:1; /* first try 10-byte mode sense/select */ >>> unsigned set_dbd_for_ms:1; /* Set "DBD" field in mode sense */ >> >> That's pretty much what James was suggesting, except for one thing: You >> must not set sdkp->device->expecting_media_change to 1 for all devices >> in sd_runtime_resume(). Only for devices which may generate a spurious >> Unit Attention following runtime resume -- and maybe not even for all of >> them, depending on what the user wants. >> >> Alan Stern >> > > when I mount the SD card myself or via Nautilus, things work. When I put > sth like: > > /dev/sda1 /mnt/sda1 auto auto,nofail 0 2 > > into fstab, I *still* get (constantly) when accessing the files: > > [ 50.838061] sd 0:0:0:0: [sda] tag#0 device offline or changed > > why could that be? is there another place we would add such a new flag > (not only resume())? > > martin > it's really strange: below is the change I'm trying. Of course that's only for testing the functionality, nothing how a patch could look like. While I remember it had worked, now (weirdly since I tried that mounting via fstab) it doesn't anymore! What I understand (not much): I handle the error with "retry" via the new flag, but scsi_decide_disposition() returns SUCCESS because of "no more retries"; but it's the first and only time it's called. How can this be? What am I missing? --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -565,6 +565,13 @@ int scsi_check_sense(struct scsi_cmnd *scmd) return NEEDS_RETRY; } } + if (scmd->device->expecting_media_change) { + if (sshdr.asc == 0x28 && sshdr.ascq == 0x00) { + scmd->device->expecting_media_change = 0; + return NEEDS_RETRY; + } + } + /* * we might also expect a cc/ua if another LUN on the target * reported a UA with an ASC/ASCQ of 3F 0E - diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index d90fefffe31b..bb583e403b81 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3642,6 +3642,8 @@ static int sd_resume(struct device *dev) if (!sdkp) /* E.g.: runtime resume at the start of sd_probe() */ return 0; + sdkp->device->expecting_media_change = 1; + if (!sdkp->device->manage_start_stop) return 0; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index bc5909033d13..f5fc1af68e00 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -169,6 +169,7 @@ struct scsi_device { * this device */ unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN * because we did a bus reset. */ + unsigned expecting_media_change:1; unsigned use_10_for_rw:1; /* first try 10-byte read / write */ unsigned use_10_for_ms:1; /* first try 10-byte mode sense/select */ unsigned set_dbd_for_ms:1; /* Set "DBD" field in mode sense */