From patchwork Wed Apr 12 20:41:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 673569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEB12C77B6E for ; Wed, 12 Apr 2023 20:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbjDLUlk (ORCPT ); Wed, 12 Apr 2023 16:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjDLUlg (ORCPT ); Wed, 12 Apr 2023 16:41:36 -0400 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E477955A6 for ; Wed, 12 Apr 2023 13:41:34 -0700 (PDT) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1a661032878so2443725ad.2 for ; Wed, 12 Apr 2023 13:41:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681332094; x=1683924094; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MEEcR42CCThkOQQn6/7gtQrk4W4CinNrHZLfB9vLVrE=; b=FkMMOY0BpH9XFbyc5ZTcsOqGzmrFPMn5feuneCtYUnU2wis4nKwMHeNzfe2c5IqgWa yH//PzQD2zSB/FPIq0zDrp27sDjHAyytBWYCe+1V8IbdW7qjwOBAMXkbrgw+ZdUf3aP9 hWIycSIPkghZrf4Wg2CgWt2GhIppt2KoVxAP+zpdwjQrI+NzAWg9+t8qes7MIxLtoIlj 90TlbneYvE9sPfsacDJZfJe3qMtw5BREjhyYjwkSlGYmBPvcieK0Ne5IsOcCclmt+Cn1 3ZHyo8c/tTY9Sj46s9t1pVw2TzaKTZN/LlGhBkfoOWMwUiHLReU9u0A6ZVrBUrcuanAs GWZg== X-Gm-Message-State: AAQBX9fLME5Yj+G1VrB2xoFKmGMW86J5PDDa10THG8sinxa1D6o2GqIZ w4n29JtG/dFptpgD51ZLu8I= X-Google-Smtp-Source: AKy350bbHOrtYsxrXlzvaamQc8cwbQepwdqBlH4kx+8vAbo11slEdh8W8hHKTlP5T2WlseCiyVjAGQ== X-Received: by 2002:a05:6a00:188c:b0:63a:ea04:4966 with SMTP id x12-20020a056a00188c00b0063aea044966mr238205pfh.8.1681332094272; Wed, 12 Apr 2023 13:41:34 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:d89d:35dd:5938:1993]) by smtp.gmail.com with ESMTPSA id l19-20020a62be13000000b006249928aba2sm12123364pff.59.2023.04.12.13.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 13:41:33 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Avri Altman , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke , Mike Christie , Tomas Henzl , "James E.J. Bottomley" Subject: [PATCH 1/3] scsi: sd: Let sd_shutdown() fail future I/O Date: Wed, 12 Apr 2023 13:41:23 -0700 Message-Id: <20230412204125.3222615-2-bvanassche@acm.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230412204125.3222615-1-bvanassche@acm.org> References: <20230412204125.3222615-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org System shutdown happens as follows (see e.g. the systemd source file src/shutdown/shutdown.c): * sync() is called. * reboot(RB_AUTOBOOT/RB_HALT_SYSTEM/RB_POWER_OFF) is called. * If the reboot() system call returns, log an error message. The reboot() system call causes the kernel to call kernel_restart(), kernel_halt() or kernel_power_off(). Each of these functions calls device_shutdown(). device_shutdown() calls sd_shutdown(). After sd_shutdown() has been called the .shutdown() callback of the LLD will be called. This makes it unsafe to submit I/O after sd_shutdown() has finished. Let sd_shutdown() fail future I/O such that LLD .shutdown() callbacks can be simplified. Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Mike Christie Cc: Tomas Henzl Signed-off-by: Bart Van Assche --- drivers/scsi/sd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 4bb87043e6db..629f5889caf2 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3699,12 +3699,13 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start) static void sd_shutdown(struct device *dev) { struct scsi_disk *sdkp = dev_get_drvdata(dev); + struct request_queue *q; if (!sdkp) return; /* this can happen */ if (pm_runtime_suspended(dev)) - return; + goto fail_future_io; if (sdkp->WCE && sdkp->media_present) { sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n"); @@ -3715,6 +3716,12 @@ static void sd_shutdown(struct device *dev) sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); sd_start_stop_device(sdkp, 0); } + +fail_future_io: + q = sdkp->disk->queue; + blk_queue_flag_set(QUEUE_FLAG_DYING, q); + blk_mq_freeze_queue(q); + blk_mq_unfreeze_queue(q); } static int sd_suspend_common(struct device *dev, bool ignore_stop_errors) From patchwork Wed Apr 12 20:41:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 672795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D146FC7619A for ; Wed, 12 Apr 2023 20:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229634AbjDLUlq (ORCPT ); Wed, 12 Apr 2023 16:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjDLUlp (ORCPT ); Wed, 12 Apr 2023 16:41:45 -0400 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FBE159E0 for ; Wed, 12 Apr 2023 13:41:44 -0700 (PDT) Received: by mail-pl1-f175.google.com with SMTP id q2so17618691pll.7 for ; Wed, 12 Apr 2023 13:41:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681332104; x=1683924104; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H9HN99QwsksXCBCaVQ2bJ/Ic4jm/KkGkP0u89WLoXno=; b=kIsEDYtq4O/DDLoVLCly8RZ/Dh3C4M8IQ/cXnZSb3aZNoz3FlzoOtG17tC9ccQUE7T TAjbyAz8J8lH3/mBO81HvX4ilBcx+8eaDzeAysiUXUEbNwhjwX3sPzRefk2/RoCiK9ui AuqsmbzSmzziQ4PawMurt8Wx4K9HyXQp0YBYpAWOcjKrlvJhUCfvpUsyfR4KQi4ZMp1F h+LQx0MlfuUBilPyBHuMkOOj6eA1By9pKv8Z+SZP6uCW6C/QeQdQWxHBFTFGG6bdZVP0 mxe0lyW5SJEZGYOakSamapQakV6sJJ8QWBn1URPFF9/17pRSeDG2EUBHMZB/e+1o160j M50Q== X-Gm-Message-State: AAQBX9e090YLICkCrcFGRbIEPOUmlt6uDd+FDlwqVO1CFnliihso7Ob6 LlBrZ41PAheYCpJVkrwNgE4uKcA7f28= X-Google-Smtp-Source: AKy350ZCetmhvvIr7NOVHfo92KeeZZKGFX+N8Zbc1OXE9YnpFtQsP1fwSfb1GHDhdDDJ28EJKJG/0A== X-Received: by 2002:a05:6a20:be1e:b0:eb:c8dc:a565 with SMTP id ge30-20020a056a20be1e00b000ebc8dca565mr2836379pzb.7.1681332103874; Wed, 12 Apr 2023 13:41:43 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:d89d:35dd:5938:1993]) by smtp.gmail.com with ESMTPSA id l19-20020a62be13000000b006249928aba2sm12123364pff.59.2023.04.12.13.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 13:41:43 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Avri Altman , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Asutosh Das , Tomas Henzl , "James E.J. Bottomley" , Bean Huo , Stanley Chu , Asutosh Das Subject: [PATCH 2/3] scsi: ufs: Simplify ufshcd_wl_shutdown() Date: Wed, 12 Apr 2023 13:41:24 -0700 Message-Id: <20230412204125.3222615-3-bvanassche@acm.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230412204125.3222615-1-bvanassche@acm.org> References: <20230412204125.3222615-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Now that sd_shutdown() fails future I/O the code for quiescing LUNs in ufshcd_wl_shutdown() is superfluous. Remove the code for quiescing LUNs. Also remove the ufshcd_rpm_get_sync() call because it is not necessary to resume a UFS device before submitting a START STOP UNIT command. Cc: Asutosh Das Cc: Tomas Henzl Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 9434328ba323..784787cf08c3 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -9768,22 +9768,12 @@ static int ufshcd_wl_resume(struct device *dev) static void ufshcd_wl_shutdown(struct device *dev) { struct scsi_device *sdev = to_scsi_device(dev); - struct ufs_hba *hba; - - hba = shost_priv(sdev->host); + struct ufs_hba *hba = shost_priv(sdev->host); down(&hba->host_sem); hba->shutting_down = true; up(&hba->host_sem); - /* Turn on everything while shutting down */ - ufshcd_rpm_get_sync(hba); - scsi_device_quiesce(sdev); - shost_for_each_device(sdev, hba->host) { - if (sdev == hba->ufs_device_wlun) - continue; - scsi_device_quiesce(sdev); - } __ufshcd_wl_suspend(hba, UFS_SHUTDOWN_PM); } From patchwork Wed Apr 12 20:41:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 673568 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E331C7619A for ; Wed, 12 Apr 2023 20:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbjDLUl4 (ORCPT ); Wed, 12 Apr 2023 16:41:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbjDLUly (ORCPT ); Wed, 12 Apr 2023 16:41:54 -0400 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8236D59ED for ; Wed, 12 Apr 2023 13:41:53 -0700 (PDT) Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-51b0f9d7d70so653149a12.1 for ; Wed, 12 Apr 2023 13:41:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681332113; x=1683924113; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iE3M16v/3jVwdoM92bNIaScesnw7812ie0MPO/4++BY=; b=MtlE9UeBa7EqLIWeiACRr99jeD0PTQc6LMzPrRjUXaoLZVBEfL+6iEvObh+VflZbUy aHbcodSb+12JHmowEutGh3yTVpHgycJuhnL/gm9BDHupYldW98xP5crBd93bYzr3vLb6 nF7jq/KBo9GSrhI0V1lOVw06A0mFU8kSYE1dC4R2LbPPI50kQaIOumM5wnFHBc3EQod4 N2MD5NlS5PDBJHJghkIXC9Izq6IntYwCFCK7xdjWWZWEfkBvYkd9E9x6tEaaieKPTe+9 7f3TmRwQurLoxuCBJ8YRA6TrtXCqLyOrG3OTzCZ6YN6mWXIoesQ9zh0aqlC+aT2DPBoW ry+w== X-Gm-Message-State: AAQBX9e3+IeMC1iMZnbd8Dtjb4jh2AR/3wa5N1ahRX4l3HHJovcn+nj1 80F07Ohc0vpHYmlqicncdbc= X-Google-Smtp-Source: AKy350YpRnvvJnO8oFKeB2Ret3DCLEYXNyfVGbvgExrFhk6mwdKfrROSRZpmLSn9SCLkg0QKxnbbcA== X-Received: by 2002:a05:6a00:10d5:b0:63a:33d5:9224 with SMTP id d21-20020a056a0010d500b0063a33d59224mr213591pfu.18.1681332112960; Wed, 12 Apr 2023 13:41:52 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:d89d:35dd:5938:1993]) by smtp.gmail.com with ESMTPSA id l19-20020a62be13000000b006249928aba2sm12123364pff.59.2023.04.12.13.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 13:41:52 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Avri Altman , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Stanley Chu , Asutosh Das Subject: [PATCH 3/3] scsi: ufs: Increase the START STOP UNIT timeout from one to ten seconds Date: Wed, 12 Apr 2023 13:41:25 -0700 Message-Id: <20230412204125.3222615-4-bvanassche@acm.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230412204125.3222615-1-bvanassche@acm.org> References: <20230412204125.3222615-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org One UFS vendor asked to increase the UFS timeout from 1 s to 3 s. Another UFS vendor asked to increase the UFS timeout from 1 s to 10 s. Hence this patch that increases the UFS timeout to 10 s. This patch can cause the total timeout to exceed 20 s, the Android shutdown timeout. This is fine since the loop around ufshcd_execute_start_stop() exists to deal with unit attentions and because unit attentions are reported quickly. Fixes: dcd5b7637c6d ("scsi: ufs: Reduce the START STOP UNIT timeout") Fixes: 8f2c96420c6e ("scsi: ufs: core: Reduce the power mode change timeout") Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 784787cf08c3..6831eb1afc30 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -9182,7 +9182,8 @@ static int ufshcd_execute_start_stop(struct scsi_device *sdev, }; return scsi_execute_cmd(sdev, cdb, REQ_OP_DRV_IN, /*buffer=*/NULL, - /*bufflen=*/0, /*timeout=*/HZ, /*retries=*/0, &args); + /*bufflen=*/0, /*timeout=*/10 * HZ, /*retries=*/0, + &args); } /**