From patchwork Thu May 4 23:50:48 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: 679265 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 B1C7CC7EE23 for ; Thu, 4 May 2023 23:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbjEDXvQ (ORCPT ); Thu, 4 May 2023 19:51:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbjEDXvP (ORCPT ); Thu, 4 May 2023 19:51:15 -0400 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 860E912E8F for ; Thu, 4 May 2023 16:51:13 -0700 (PDT) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1aaec6f189cso7821985ad.3 for ; Thu, 04 May 2023 16:51:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683244273; x=1685836273; 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=qSdj1gKKC/HzoWTj9GEbdbZJmfBJJsK5g1c/vX2YoJk=; b=icCCxFnul/rO90z3dJ5eZ9woeE3S4uFrOnzdDlfHsv/2qqrit7emVRBaFFL8Puo1FU HGbZkprbFyhcY+OZ328+YRuQm51RUYXpwrYqZ995ydC3Wfos6IL7f50RI6N1MuZRLEP+ PkL3VUPoWsb1q/7nfEdLRGf8ShKestcseMmFwLovkmhDQa8OoR/47F8S05GhKnDt6813 if+PL0HtbH2aZdk7Ix+RciSKfG5b/60EolAefZoEt9P/8kwbz/uoxMfugFf7rbM9YGr0 YHGoSX/gZICbbbw6bdwJ4UrGKOljgykK8h1Pso9NlHi0WwbYd+KwvsdZFo3YIg9jVBYT qMpg== X-Gm-Message-State: AC+VfDyZiZdOr+V3jW96bqxVH3Ldp2fe/6qaZmuiudaZ2Oo8R7Iz5rwE Yi+JHwMfcumfiPSj/5DhKXraYHTcIqw= X-Google-Smtp-Source: ACHHUZ5FdsUM9bgVsJUTVax4IvN9bMtYBDkcfmB21DUoBAaxlLcX81k0giropRNXeL6wLbuEQDq4rw== X-Received: by 2002:a17:902:ea09:b0:1ab:1878:845b with SMTP id s9-20020a170902ea0900b001ab1878845bmr6512790plg.26.1683244272963; Thu, 04 May 2023 16:51:12 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id j13-20020a170902758d00b001aad4be4503sm143169pll.2.2023.05.04.16.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 16:51:12 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Ming Lei , Ye Bin , Hannes Reinecke , "James E.J. Bottomley" Subject: [PATCH 1/5] scsi: core: Rework scsi_host_block() Date: Thu, 4 May 2023 16:50:48 -0700 Message-Id: <20230504235052.4423-2-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230504235052.4423-1-bvanassche@acm.org> References: <20230504235052.4423-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Make scsi_host_block() easier to read by converting it to the widely used early-return style. This patch reworks code introduced by commit f983622ae605 ("scsi: core: Avoid calling synchronize_rcu() for each device in scsi_host_block()"). Cc: Ming Lei Cc: Ye Bin Cc: Hannes Reinecke Signed-off-by: Bart Van Assche Reviewed-by: Mike Christie --- drivers/scsi/scsi_lib.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index b7c569a42aa4..758a57616dd3 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -2939,11 +2939,20 @@ scsi_target_unblock(struct device *dev, enum scsi_device_state new_state) } EXPORT_SYMBOL_GPL(scsi_target_unblock); +/** + * scsi_host_block - Try to transition all logical units to the SDEV_BLOCK state + * @shost: device to block + * + * Pause SCSI command processing for all logical units associated with the SCSI + * host and wait until pending scsi_queue_rq() calls have finished. + * + * Returns zero if successful or a negative error code upon failure. + */ int scsi_host_block(struct Scsi_Host *shost) { struct scsi_device *sdev; - int ret = 0; + int ret; /* * Call scsi_internal_device_block_nowait so we can avoid @@ -2955,7 +2964,7 @@ scsi_host_block(struct Scsi_Host *shost) mutex_unlock(&sdev->state_mutex); if (ret) { scsi_device_put(sdev); - break; + return ret; } } @@ -2965,10 +2974,9 @@ scsi_host_block(struct Scsi_Host *shost) */ WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING); - if (!ret) - synchronize_rcu(); + synchronize_rcu(); - return ret; + return 0; } EXPORT_SYMBOL_GPL(scsi_host_block); From patchwork Thu May 4 23:50:49 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: 679707 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 C39D6C7EE26 for ; Thu, 4 May 2023 23:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229927AbjEDXvR (ORCPT ); Thu, 4 May 2023 19:51:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbjEDXvP (ORCPT ); Thu, 4 May 2023 19:51:15 -0400 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0784012E95 for ; Thu, 4 May 2023 16:51:15 -0700 (PDT) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1ab267e3528so8373635ad.0 for ; Thu, 04 May 2023 16:51:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683244274; x=1685836274; 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=VZc+Et9tF0UXe9FM/xTBBxaabqXfpabHUxRRUCkqqME=; b=In+Dgr8RvGQehv4jY2bLnO/4b5LdqQ2g0cRMV2zuk7Nn2t7zZq3pfIjl87j1I75SUM FrF7Q31Q6t2SatfgBvNEUwiqYJSEVwDFrEdmtCeiEzktXg5NOGeSvhnvjomjphr4v/ye NgLGwMGjh5o9YiqSIxEoLnYwC4NiuxMg3Sxt9DrUR2HHKbwyfoexDgPhR4gp1zbydpR5 6lunypB9Ri/HwfuZbJz+Gn6vrdGYc+XwGwYi1xehkryZfOHWgWTIi8raVsNXq5QNMzi6 +s+6HUYXq69i1poiBWLWlvLeaHFVE3w33JyqsWDi+a0GD3HUar1kSmyxzZbCdVNUaY4a NFJQ== X-Gm-Message-State: AC+VfDwZWVjVPZZX32zDBBWFwAT/RGErI1bJQC5zwpL3yndOsgVEvvOJ 0NPsNvy3iAJ8dPuPgOIHwC4= X-Google-Smtp-Source: ACHHUZ6A62KETF+PbJWDXJhKugddm8FVLgj8gsNi7eSoWDWKGdLjhMJyVhjN4IIZ5u3xFmPg9jD4Dg== X-Received: by 2002:a17:902:ce83:b0:1a5:2db2:2bb with SMTP id f3-20020a170902ce8300b001a52db202bbmr6351494plg.15.1683244274387; Thu, 04 May 2023 16:51:14 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id j13-20020a170902758d00b001aad4be4503sm143169pll.2.2023.05.04.16.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 16:51:13 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Mike Christie , "James E.J. Bottomley" Subject: [PATCH 2/5] scsi: core: Support setting BLK_MQ_F_BLOCKING Date: Thu, 4 May 2023 16:50:49 -0700 Message-Id: <20230504235052.4423-3-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230504235052.4423-1-bvanassche@acm.org> References: <20230504235052.4423-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prepare for adding code in ufshcd_queuecommand() that may sleep. This patch is similar to a patch posted last year by Mike Christie. See also https://lore.kernel.org/all/20220308003957.123312-2-michael.christie@oracle.com/ Cc: Mike Christie Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 10 +++------- include/scsi/scsi_host.h | 3 +++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 758a57616dd3..894af68babc2 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1982,6 +1982,8 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) tag_set->flags = BLK_MQ_F_SHOULD_MERGE; tag_set->flags |= BLK_ALLOC_POLICY_TO_MQ_FLAG(shost->hostt->tag_alloc_policy); + if (shost->hostt->queuecommand_may_block) + tag_set->flags |= BLK_MQ_F_BLOCKING; tag_set->driver_data = shost; if (shost->host_tagset) tag_set->flags |= BLK_MQ_F_TAG_HCTX_SHARED; @@ -2968,13 +2970,7 @@ scsi_host_block(struct Scsi_Host *shost) } } - /* - * SCSI never enables blk-mq's BLK_MQ_F_BLOCKING flag so - * calling synchronize_rcu() once is enough. - */ - WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING); - - synchronize_rcu(); + blk_mq_wait_quiesce_done(&shost->tag_set); return 0; } diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 0f29799efa02..37a8a2608dc2 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -458,6 +458,9 @@ struct scsi_host_template { /* True if the host uses host-wide tagspace */ unsigned host_tagset:1; + /* The queuecommand callback may block. See also BLK_MQ_F_BLOCKING. */ + unsigned queuecommand_may_block:1; + /* * Countdown for host blocking with no commands outstanding. */ From patchwork Thu May 4 23:50:50 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: 679264 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 215FCC77B7C for ; Thu, 4 May 2023 23:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229951AbjEDXvY (ORCPT ); Thu, 4 May 2023 19:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbjEDXvU (ORCPT ); Thu, 4 May 2023 19:51:20 -0400 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FBF713291 for ; Thu, 4 May 2023 16:51:19 -0700 (PDT) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1aaea3909d1so10238205ad.2 for ; Thu, 04 May 2023 16:51:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683244279; x=1685836279; 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=6DQ9zd8GvGmSw/78qAuY9Lsrz4TpocdRjZ2BdVTCWGg=; b=YXwu1CMnAbat4cdf3tCpkHRHW7r2XoA+yS4c3jdCDWoQTauZIdHU8IcZHxKX7YnLHR ZlOy7D9SiOFEAQjjPvM/XxVcIoX+Irr8ce9/UxzUuSd/PilS/xKs1U89yiTMy8nDlKaE AqKT9R17FqrIDfTcNMEXmPtxR/4Qr+tmGsJBMHY8h60nr40af/d4HGW7XU+X5epdaXvf 3LExgvNjRsAzfL21y5N4S3yuFSYiXLZ76mHUHSgsMSRawLn9V++L2jkhB9i9HV8p73m3 SJqxhA+MOoCGkyRvCtlEbU5UP7JTxvC+LioRgnPspMd3eNr2rZxJVINfGQjyet45AdsC HM+w== X-Gm-Message-State: AC+VfDzhtFqi7wfFulAk6AfQ2xRTTzcAMSmcoD5JgWXVxnnDrKCXZlrB Q8cwIs8Os6OLSiMYUdq5mOM= X-Google-Smtp-Source: ACHHUZ5m5etfFdOfk7QGqJrgJj6bgjQNEqwnaAkqIQjNXeSdWeeqO9HLDCQmh4tc1Gi2a0CCgnlZJQ== X-Received: by 2002:a17:903:2306:b0:1a8:1f43:70f3 with SMTP id d6-20020a170903230600b001a81f4370f3mr6582542plh.63.1683244278995; Thu, 04 May 2023 16:51:18 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id j13-20020a170902758d00b001aad4be4503sm143169pll.2.2023.05.04.16.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 16:51:18 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Stanley Chu , Avri Altman , Bean Huo , Asutosh Das Subject: [PATCH 3/5] scsi: ufs: Enable the BLK_MQ_F_BLOCKING flag Date: Thu, 4 May 2023 16:50:50 -0700 Message-Id: <20230504235052.4423-4-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230504235052.4423-1-bvanassche@acm.org> References: <20230504235052.4423-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prepare for adding code in ufshcd_queuecommand() that may sleep. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 2b8c2613f7d7..a1bce9c6aee5 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8755,6 +8755,7 @@ static const struct scsi_host_template ufshcd_driver_template = { .max_host_blocked = 1, .track_queue_depth = 1, .skip_settle_delay = 1, + .queuecommand_may_block = true, .sdev_groups = ufshcd_driver_groups, .rpm_autosuspend_delay = RPM_AUTOSUSPEND_DELAY_MS, }; From patchwork Thu May 4 23:50:51 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: 679706 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 8BFB4C77B7C for ; Thu, 4 May 2023 23:51:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229953AbjEDXvb (ORCPT ); Thu, 4 May 2023 19:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbjEDXva (ORCPT ); Thu, 4 May 2023 19:51:30 -0400 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12BC313293 for ; Thu, 4 May 2023 16:51:29 -0700 (PDT) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1aaebed5bd6so7824305ad.1 for ; Thu, 04 May 2023 16:51:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683244288; x=1685836288; 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=6hJO4H87eOprV7wY9RkTcEehuFFsAgczKpnmXGyKNCQ=; b=G2WBRgU3Zj7OkBIycBLB1vkL/0F0tuy/odkP2qBa0b23XpoRWWzBsthXHWG0IqgnoZ fJRpDISG5DKBxLaRnLqJjbPVwcnr+RQSS9IsvroGAi8vnagAL1VTRCH+5xaCx1f0BAMM 1WxhefBzZMD7WBl9E+gKbh7+6opnP7Us8wZyvevDDfGpl/HcmB0dFuke4uD9p34OxpPq rkGO3CPFBvxiRTXIqwzWuNtbjJo3CAXzI+KI8exsq7E+hYo/KMOR4e0/ghNTQhRe5wQR tnjepHVJ4AaFo/rJ52qDvLegYS3Rd3bFRCNL08oQ3BV7GOBGSgsa/CaY34jgC/oAJbyu BjZQ== X-Gm-Message-State: AC+VfDx2zFjLaBIT44yktiZ160udrYUKVRn/wCqWBYJJxIQKFiQYQMkm ybOM0gd8EsDJVNFoRt/y39Y= X-Google-Smtp-Source: ACHHUZ6bvdxAY5N++r7Q1zZMr+YOQDVv6oGzZTJxQW9hayDWXB2mJMviyvjLIsh+WBgY0QFZzNdXsQ== X-Received: by 2002:a17:902:e5c3:b0:1a9:a672:12b8 with SMTP id u3-20020a170902e5c300b001a9a67212b8mr5540781plf.68.1683244288416; Thu, 04 May 2023 16:51:28 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id j13-20020a170902758d00b001aad4be4503sm143169pll.2.2023.05.04.16.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 16:51:28 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Stanley Chu , Avri Altman , Manivannan Sadhasivam , Asutosh Das , Bean Huo , Can Guo , Arthur Simchaev Subject: [PATCH 4/5] scsi: ufs: core: Unexport ufshcd_hold() and ufshcd_release() Date: Thu, 4 May 2023 16:50:51 -0700 Message-Id: <20230504235052.4423-5-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230504235052.4423-1-bvanassche@acm.org> References: <20230504235052.4423-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Unexport these functions since these are only used by the UFS core. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 2 -- include/ufs/ufshcd.h | 3 --- 2 files changed, 5 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index a1bce9c6aee5..54f91d7d0192 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1847,7 +1847,6 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) out: return rc; } -EXPORT_SYMBOL_GPL(ufshcd_hold); static void ufshcd_gate_work(struct work_struct *work) { @@ -1950,7 +1949,6 @@ void ufshcd_release(struct ufs_hba *hba) __ufshcd_release(hba); spin_unlock_irqrestore(hba->host->host_lock, flags); } -EXPORT_SYMBOL_GPL(ufshcd_release); static ssize_t ufshcd_clkgate_delay_show(struct device *dev, struct device_attribute *attr, char *buf) diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index d6da1efb0212..13824462452d 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1358,9 +1358,6 @@ void ufshcd_fixup_dev_quirks(struct ufs_hba *hba, int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, bool ascii); -int ufshcd_hold(struct ufs_hba *hba, bool async); -void ufshcd_release(struct ufs_hba *hba); - void ufshcd_clkgate_delay_set(struct device *dev, unsigned long value); u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba); From patchwork Thu May 4 23:50:52 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: 679263 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 DA49EC7EE21 for ; Thu, 4 May 2023 23:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229953AbjEDXvv (ORCPT ); Thu, 4 May 2023 19:51:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbjEDXvu (ORCPT ); Thu, 4 May 2023 19:51:50 -0400 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA1FE86AD for ; Thu, 4 May 2023 16:51:48 -0700 (PDT) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1aaf70676b6so8269155ad.3 for ; Thu, 04 May 2023 16:51:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683244308; x=1685836308; 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=ac+lV3ttBDC6WYKknPpj/rlfwz2YKXKPkx3DE1oGOH8=; b=PSaTnrtR2T8aZENj3n7dSzT/IWGzllz7LVTKqFEScgG/nGmGRMCmzU47nfWR1HD1IB gui0Qc4snJTU+FU8PUSud5jVBS4xhdoeJCjE/1+VHivjoz48MJef90z2Zebxr7yYAgXV 9halvdiQTCxxNgUK9e4BPtn8Sxi8e2nt4l0TS9X65+McgjnaA1zs4xaF6bVB7/oWchvq 6KHqypsZN1wfClxsW1bmnuzmIsaOCB5R6AwOHvSqzcF2y/xFEMqPLwxpmLIVm5VrVtIq iQMx5+LhPUtP/rVw3MSvl5OOq8Ja7a2wHTNvflQQytDgCUfm0xkjKvF0x6d9Om+6gbwa JdbA== X-Gm-Message-State: AC+VfDx2TAWZFnPG1EPXVK/4a2kQyiQKk5eAdf7G4pKi68Rgw4hRvUvw OD6dp8lcRtVfI1av1YwsU7Y= X-Google-Smtp-Source: ACHHUZ4yNqnkBiFDLJ+T5GzcezzpmgCxsFDeaRdG4freKoJXS7fp6ITPvORsDIU2y2ZVkLHBtJmN2g== X-Received: by 2002:a17:902:d4d2:b0:1ab:14da:981 with SMTP id o18-20020a170902d4d200b001ab14da0981mr6685912plg.35.1683244307980; Thu, 04 May 2023 16:51:47 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id j13-20020a170902758d00b001aad4be4503sm143169pll.2.2023.05.04.16.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 16:51:47 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Avri Altman , Jinyoung Choi , Peter Wang , Daniil Lunev , Adrian Hunter , Can Guo , Manivannan Sadhasivam , Asutosh Das , Arthur Simchaev , Stanley Chu Subject: [PATCH 5/5] scsi: ufs: Ungate the clock synchronously Date: Thu, 4 May 2023 16:50:52 -0700 Message-Id: <20230504235052.4423-6-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230504235052.4423-1-bvanassche@acm.org> References: <20230504235052.4423-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Ungating the clock asynchronously causes ufshcd_queuecommand() to return SCSI_MLQUEUE_HOST_BUSY and hence causes commands to be requeued. This is suboptimal. Allow ufshcd_queuecommand() to sleep such that clock ungating does not trigger command requeuing. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufs-sysfs.c | 2 +- drivers/ufs/core/ufshcd-crypto.c | 2 +- drivers/ufs/core/ufshcd-priv.h | 2 +- drivers/ufs/core/ufshcd.c | 75 ++++++++++---------------------- 4 files changed, 26 insertions(+), 55 deletions(-) diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c index 883f0e44b54e..cdf3d5f2b77b 100644 --- a/drivers/ufs/core/ufs-sysfs.c +++ b/drivers/ufs/core/ufs-sysfs.c @@ -168,7 +168,7 @@ static ssize_t auto_hibern8_show(struct device *dev, } pm_runtime_get_sync(hba->dev); - ufshcd_hold(hba, false); + ufshcd_hold(hba); ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER); ufshcd_release(hba); pm_runtime_put_sync(hba->dev); diff --git a/drivers/ufs/core/ufshcd-crypto.c b/drivers/ufs/core/ufshcd-crypto.c index 198360fe5e8e..f2c4422cab86 100644 --- a/drivers/ufs/core/ufshcd-crypto.c +++ b/drivers/ufs/core/ufshcd-crypto.c @@ -24,7 +24,7 @@ static int ufshcd_program_key(struct ufs_hba *hba, u32 slot_offset = hba->crypto_cfg_register + slot * sizeof(*cfg); int err = 0; - ufshcd_hold(hba, false); + ufshcd_hold(hba); if (hba->vops && hba->vops->program_key) { err = hba->vops->program_key(hba, cfg, slot); diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index d53b93c21a0c..22cac71090ae 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -84,7 +84,7 @@ unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, bool ascii); -int ufshcd_hold(struct ufs_hba *hba, bool async); +void ufshcd_hold(struct ufs_hba *hba); void ufshcd_release(struct ufs_hba *hba); int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd); diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 54f91d7d0192..e4f490a25def 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1189,7 +1189,7 @@ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, bool timeout = false, do_last_check = false; ktime_t start; - ufshcd_hold(hba, false); + ufshcd_hold(hba); spin_lock_irqsave(hba->host->host_lock, flags); /* * Wait for all the outstanding tasks/transfer requests. @@ -1310,7 +1310,7 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba, u64 timeout_us) } /* let's not get into low power until clock scaling is completed */ - ufshcd_hold(hba, false); + ufshcd_hold(hba); out: return ret; @@ -1647,7 +1647,7 @@ static ssize_t ufshcd_clkscale_enable_store(struct device *dev, goto out; ufshcd_rpm_get_sync(hba); - ufshcd_hold(hba, false); + ufshcd_hold(hba); hba->clk_scaling.is_enabled = value; @@ -1761,17 +1761,15 @@ static void ufshcd_ungate_work(struct work_struct *work) * ufshcd_hold - Enable clocks that were gated earlier due to ufshcd_release. * Also, exit from hibern8 mode and set the link as active. * @hba: per adapter instance - * @async: This indicates whether caller should ungate clocks asynchronously. */ -int ufshcd_hold(struct ufs_hba *hba, bool async) +void ufshcd_hold(struct ufs_hba *hba) { - int rc = 0; bool flush_result; unsigned long flags; if (!ufshcd_is_clkgating_allowed(hba) || !hba->clk_gating.is_initialized) - goto out; + return; spin_lock_irqsave(hba->host->host_lock, flags); hba->clk_gating.active_reqs++; @@ -1788,15 +1786,10 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) */ if (ufshcd_can_hibern8_during_gating(hba) && ufshcd_is_link_hibern8(hba)) { - if (async) { - rc = -EAGAIN; - hba->clk_gating.active_reqs--; - break; - } spin_unlock_irqrestore(hba->host->host_lock, flags); flush_result = flush_work(&hba->clk_gating.ungate_work); if (hba->clk_gating.is_suspended && !flush_result) - goto out; + return; spin_lock_irqsave(hba->host->host_lock, flags); goto start; } @@ -1827,12 +1820,6 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) */ fallthrough; case REQ_CLKS_ON: - if (async) { - rc = -EAGAIN; - hba->clk_gating.active_reqs--; - break; - } - spin_unlock_irqrestore(hba->host->host_lock, flags); flush_work(&hba->clk_gating.ungate_work); /* Make sure state is CLKS_ON before returning */ @@ -1844,8 +1831,6 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) break; } spin_unlock_irqrestore(hba->host->host_lock, flags); -out: - return rc; } static void ufshcd_gate_work(struct work_struct *work) @@ -2075,7 +2060,7 @@ static void ufshcd_exit_clk_gating(struct ufs_hba *hba) ufshcd_remove_clk_gating_sysfs(hba); /* Ungate the clock if necessary. */ - ufshcd_hold(hba, false); + ufshcd_hold(hba); hba->clk_gating.is_initialized = false; ufshcd_release(hba); @@ -2471,7 +2456,7 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) if (hba->quirks & UFSHCD_QUIRK_BROKEN_UIC_CMD) return 0; - ufshcd_hold(hba, false); + ufshcd_hold(hba); mutex_lock(&hba->uic_cmd_mutex); ufshcd_add_delay_before_dme_cmd(hba); @@ -2874,12 +2859,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag); - /* - * Allows the UFS error handler to wait for prior ufshcd_queuecommand() - * calls. - */ - rcu_read_lock(); - switch (hba->ufshcd_state) { case UFSHCD_STATE_OPERATIONAL: break; @@ -2925,13 +2904,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) hba->req_abort_count = 0; - err = ufshcd_hold(hba, true); - if (err) { - err = SCSI_MLQUEUE_HOST_BUSY; - goto out; - } - WARN_ON(ufshcd_is_clkgating_allowed(hba) && - (hba->clk_gating.state != CLKS_ON)); + ufshcd_hold(hba); lrbp = &hba->lrb[tag]; lrbp->cmd = cmd; @@ -2959,8 +2932,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) ufshcd_send_command(hba, tag, hwq); out: - rcu_read_unlock(); - if (ufs_trigger_eh()) { unsigned long flags; @@ -3254,7 +3225,7 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, BUG_ON(!hba); - ufshcd_hold(hba, false); + ufshcd_hold(hba); mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index, selector); @@ -3328,7 +3299,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, return -EINVAL; } - ufshcd_hold(hba, false); + ufshcd_hold(hba); mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index, @@ -3424,7 +3395,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba, return -EINVAL; } - ufshcd_hold(hba, false); + ufshcd_hold(hba); mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index, @@ -4242,7 +4213,7 @@ int ufshcd_uic_change_pwr_mode(struct ufs_hba *hba, u8 mode) uic_cmd.command = UIC_CMD_DME_SET; uic_cmd.argument1 = UIC_ARG_MIB(PA_PWRMODE); uic_cmd.argument3 = mode; - ufshcd_hold(hba, false); + ufshcd_hold(hba); ret = ufshcd_uic_pwr_ctrl(hba, &uic_cmd); ufshcd_release(hba); @@ -4349,7 +4320,7 @@ void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) if (update && !pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { ufshcd_rpm_get_sync(hba); - ufshcd_hold(hba, false); + ufshcd_hold(hba); ufshcd_auto_hibern8_enable(hba); ufshcd_release(hba); ufshcd_rpm_put_sync(hba); @@ -4942,7 +4913,7 @@ static int ufshcd_verify_dev_init(struct ufs_hba *hba) int err = 0; int retries; - ufshcd_hold(hba, false); + ufshcd_hold(hba); mutex_lock(&hba->dev_cmd.lock); for (retries = NOP_OUT_RETRIES; retries > 0; retries--) { err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_NOP, @@ -6227,14 +6198,14 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba) ufshcd_setup_vreg(hba, true); ufshcd_config_vreg_hpm(hba, hba->vreg_info.vccq); ufshcd_config_vreg_hpm(hba, hba->vreg_info.vccq2); - ufshcd_hold(hba, false); + ufshcd_hold(hba); if (!ufshcd_is_clkgating_allowed(hba)) ufshcd_setup_clocks(hba, true); ufshcd_release(hba); pm_op = hba->is_sys_suspended ? UFS_SYSTEM_PM : UFS_RUNTIME_PM; ufshcd_vops_resume(hba, pm_op); } else { - ufshcd_hold(hba, false); + ufshcd_hold(hba); if (ufshcd_is_clkscaling_supported(hba) && hba->clk_scaling.is_enabled) ufshcd_suspend_clkscaling(hba); @@ -6242,7 +6213,7 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba) } ufshcd_scsi_block_requests(hba); /* Drain ufshcd_queuecommand() */ - synchronize_rcu(); + blk_mq_wait_quiesce_done(&hba->host->tag_set); cancel_work_sync(&hba->eeh_work); } @@ -6887,7 +6858,7 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba, return PTR_ERR(req); req->end_io_data = &wait; - ufshcd_hold(hba, false); + ufshcd_hold(hba); spin_lock_irqsave(host->host_lock, flags); @@ -7123,7 +7094,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, cmd_type = DEV_CMD_TYPE_NOP; fallthrough; case UPIU_TRANSACTION_QUERY_REQ: - ufshcd_hold(hba, false); + ufshcd_hold(hba); mutex_lock(&hba->dev_cmd.lock); err = ufshcd_issue_devman_upiu_cmd(hba, req_upiu, rsp_upiu, desc_buff, buff_len, @@ -7189,7 +7160,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r u16 ehs_len; /* Protects use of hba->reserved_slot. */ - ufshcd_hold(hba, false); + ufshcd_hold(hba); mutex_lock(&hba->dev_cmd.lock); down_read(&hba->clk_scaling_lock); @@ -7423,7 +7394,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); - ufshcd_hold(hba, false); + ufshcd_hold(hba); reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); /* If command is already aborted/completed, return FAILED. */ if (!(test_bit(tag, &hba->outstanding_reqs))) { @@ -9407,7 +9378,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) * If we can't transition into any of the low power modes * just gate the clocks. */ - ufshcd_hold(hba, false); + ufshcd_hold(hba); hba->clk_gating.is_suspended = true; if (ufshcd_is_clkscaling_supported(hba))