From patchwork Fri Nov 19 19:57:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518708 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82F2CC433EF for ; Fri, 19 Nov 2021 19:57:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DEAD610A1 for ; Fri, 19 Nov 2021 19:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233181AbhKSUA5 (ORCPT ); Fri, 19 Nov 2021 15:00:57 -0500 Received: from mail-pf1-f177.google.com ([209.85.210.177]:37745 "EHLO mail-pf1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbhKSUAz (ORCPT ); Fri, 19 Nov 2021 15:00:55 -0500 Received: by mail-pf1-f177.google.com with SMTP id 8so10238273pfo.4 for ; Fri, 19 Nov 2021 11:57:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vLRJ3SCXbH4NweGhAcBFCYovJZq4yIfhx39FAmMGgmI=; b=KeU4+wFRNcZ+vAywAgPf/DmdYOBZnRCl20xXz9JbM+vRH51UgPCqOGftNnrbeEFh0Q zVRBKY1Y6NXVPzgReKIvka9KC2N4VQiZMXc7mkwmUTvLUSZ6tT3aijDJL/IQ15dTA+PR mfPktBR8u3+vQe3AgEsS11/+r1e6lD1W0ubXBjcFPoWikMxaLXl4y6scfKquvOfQRfIr RS2QiVkfKuxfa2hpRX/t+i6HoX9/Jh37zMBKe90UH57JYuaIziNtYprmzQa/akIMz6Sw EjxT8CSYElVaRlCakWoNSdrejdnqP8eomu+I1eeXnWzv/JM3v/98iSkEQhQDGgBp9k3+ wo1A== X-Gm-Message-State: AOAM530jbkN0/ksEXmxTkIvAHxe+ve0ofa0k9/TXmpy9lVGMDYRNIhKF e3T9EknxHyHsbjLD4P2CZBbd24QtsLs= X-Google-Smtp-Source: ABdhPJwiIBBWBBFQofubcKxSLzhWstk1IENSMgxPu2YNkXzVuJld6OyEMyVdYi/5F8/oMG1uf0aZfw== X-Received: by 2002:a65:5944:: with SMTP id g4mr18826990pgu.374.1637351872808; Fri, 19 Nov 2021 11:57:52 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.57.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:57:52 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Hannes Reinecke , "James E.J. Bottomley" Subject: [PATCH v2 02/20] scsi: core: Unexport scsi_track_queue_full() Date: Fri, 19 Nov 2021 11:57:25 -0800 Message-Id: <20211119195743.2817-3-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Commit 408dea0ed41c ("[PATCH] kill scsi_syms.c") exported scsi_track_queue_full() and introduced a call to that function in drivers/scsi/tmscsim.c. Commit 71bd849dbac9 ("tmscsim: replace by am53c974 driver") removed source file drivers/scsi/tmscsim.c. Since scsi_track_queue_full() is no longer used outside the SCSI core, unexport this function. Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/scsi/scsi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index f6af1562cba4..ace6d477034b 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -276,7 +276,6 @@ int scsi_track_queue_full(struct scsi_device *sdev, int depth) return scsi_change_queue_depth(sdev, depth); } -EXPORT_SYMBOL(scsi_track_queue_full); /** * scsi_vpd_inquiry - Request a device provide us with a VPD page From patchwork Fri Nov 19 19:57:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518707 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C42EC433F5 for ; Fri, 19 Nov 2021 19:58:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42518610A1 for ; Fri, 19 Nov 2021 19:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233664AbhKSUBE (ORCPT ); Fri, 19 Nov 2021 15:01:04 -0500 Received: from mail-pj1-f48.google.com ([209.85.216.48]:55935 "EHLO mail-pj1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbhKSUA7 (ORCPT ); Fri, 19 Nov 2021 15:00:59 -0500 Received: by mail-pj1-f48.google.com with SMTP id v23so8702244pjr.5 for ; Fri, 19 Nov 2021 11:57:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IhHHR2qqqrkgcfwnn5h6oeh7wYJ9pG0vF4LRNmMis84=; b=G/vLXLIPn5KYaqrVgUArD9w5aG70Mz0MUd+RGyoha9QcdZ0p+Q8TL6awg2Z74zhOcv QzopFqd0xs5BtA6kIJ30626y6Txc8QYD/UsxHnpHPeM2xv0mGG847+NkyU/uf0VrnSjK Hl/eK9txc/E5xLJ0fP4KaGxwFEL5eC3E/ysHgbCUJhvw+MC7KyHeHMj6wBLw6VvY24eT cJ5Qn9sm72CBDfmyWQt7jy1UI6sf9gDNtfjWiRO2lMiBGsFrSR6SP+7vEOvm0z9bq50U MDPbKS+5fjhQ/jVoYUME8HZQP9vteeE0LzIQZlggwg7vMQ6PLrh6RKWawrUfHqWKC4/S MBWg== X-Gm-Message-State: AOAM530ATzaCB9upCoJjH+JBA5PTOb4KJtoNBSogh04KnXpSNTIxpkfU UBLuXA8YrGzjY/R8v2TDV1w= X-Google-Smtp-Source: ABdhPJzHQZxQsv94SiDfykvrpI36sd9QKSzB7YnAWg6eTO9lIcKIuF+fqCepb3I+vmm+qjXw/8jYPQ== X-Received: by 2002:a17:90b:380e:: with SMTP id mq14mr2985928pjb.74.1637351876768; Fri, 19 Nov 2021 11:57:56 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:57:56 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Hannes Reinecke , John Garry , "James E.J. Bottomley" Subject: [PATCH v2 05/20] scsi: core: Add support for internal commands Date: Fri, 19 Nov 2021 11:57:28 -0800 Message-Id: <20211119195743.2817-6-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Hannes Reinecke Add helper functions to allow LLDs to allocate and free internal commands. This patch is based on Hannes' patch with the subject "scsi: add scsi_{get,put}_internal_cmd() helper". Cc: John Garry Signed-off-by: Hannes Reinecke [ bvanassche: changed type of the first argument of the new functions from struct scsi_device * into struct request_queue * and included changes for the timeout handlers in this patch. ] Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_error.c | 7 ++++++ drivers/scsi/scsi_lib.c | 46 +++++++++++++++++++++++++++++++++++++- include/scsi/scsi_device.h | 4 ++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index cd05f2db3339..3703ee9c89dd 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -339,6 +339,13 @@ enum blk_eh_timer_return scsi_times_out(struct request *req) if (test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state)) return BLK_EH_DONE; + /* + * The code below is for documentation purposes only since the + * dereference above of the scmd->device pointer triggers a kernel + * oops for internal commands. + */ + WARN_ON_ONCE(blk_rq_is_internal(scsi_cmd_to_rq(scmd))); + trace_scsi_dispatch_cmd_timeout(scmd); scsi_log_completion(scmd, TIMEOUT_ERROR); diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 621d841d819a..59c3c4fbcfc0 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1756,8 +1756,9 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, static enum blk_eh_timer_return scsi_timeout(struct request *req, bool reserved) { - if (reserved) + if (blk_rq_is_internal(req) || WARN_ON_ONCE(reserved)) return BLK_EH_RESET_TIMER; + return scsi_times_out(req); } @@ -1957,6 +1958,49 @@ void scsi_mq_destroy_tags(struct Scsi_Host *shost) blk_mq_free_tag_set(&shost->tag_set); } +/** + * scsi_get_internal_cmd - Allocate an internal SCSI command + * @q: request queue from which to allocate the command. This request queue may + * but does not have to be associated with a SCSI device. This request + * queue must be associated with a SCSI tag set. See also + * scsi_mq_setup_tags(). + * @data_direction: Data direction for the allocated command. + * @flags: Zero or more BLK_MQ_REQ_* flags. + * + * Allocates a request for driver-internal use. The tag of the returned SCSI + * command is guaranteed to be unique. + */ +struct scsi_cmnd *scsi_get_internal_cmd(struct request_queue *q, + enum dma_data_direction data_direction, + blk_mq_req_flags_t flags) +{ + unsigned int opf = REQ_INTERNAL; + struct request *rq; + + opf |= data_direction == DMA_TO_DEVICE ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN; + rq = blk_mq_alloc_request(q, opf, flags); + if (IS_ERR(rq)) + return ERR_CAST(rq); + return blk_mq_rq_to_pdu(rq); +} +EXPORT_SYMBOL_GPL(scsi_get_internal_cmd); + +/** + * scsi_put_internal_cmd - Free an internal SCSI command + * @scmd: SCSI command to be freed + * + * Check if @scmd is an internal command and call blk_mq_free_request() if true. + */ +void scsi_put_internal_cmd(struct scsi_cmnd *scmd) +{ + struct request *rq = blk_mq_rq_from_pdu(scmd); + + if (WARN_ON_ONCE(!blk_rq_is_internal(rq))) + return; + blk_mq_free_request(rq); +} +EXPORT_SYMBOL_GPL(scsi_put_internal_cmd); + /** * scsi_device_from_queue - return sdev associated with a request_queue * @q: The request queue to return the sdev from diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index d1c6fc83b1e3..348c12274324 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -9,6 +9,7 @@ #include #include #include +#include struct bsg_device; struct device; @@ -470,6 +471,9 @@ static inline int scsi_execute_req(struct scsi_device *sdev, return scsi_execute(sdev, cmd, data_direction, buffer, bufflen, NULL, sshdr, timeout, retries, 0, 0, resid); } +struct scsi_cmnd *scsi_get_internal_cmd(struct request_queue *q, + enum dma_data_direction data_direction, blk_mq_req_flags_t flags); +void scsi_put_internal_cmd(struct scsi_cmnd *scmd); extern void sdev_disable_disk_events(struct scsi_device *sdev); extern void sdev_enable_disk_events(struct scsi_device *sdev); extern int scsi_vpd_lun_id(struct scsi_device *, char *, size_t); From patchwork Fri Nov 19 19:57:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518706 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41FFDC433F5 for ; Fri, 19 Nov 2021 19:58:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B2EE610A1 for ; Fri, 19 Nov 2021 19:58:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232882AbhKSUBG (ORCPT ); Fri, 19 Nov 2021 15:01:06 -0500 Received: from mail-pj1-f47.google.com ([209.85.216.47]:35483 "EHLO mail-pj1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233694AbhKSUBA (ORCPT ); Fri, 19 Nov 2021 15:01:00 -0500 Received: by mail-pj1-f47.google.com with SMTP id j6-20020a17090a588600b001a78a5ce46aso11805056pji.0 for ; Fri, 19 Nov 2021 11:57:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jMovzKB6VEpk/VZdlOB5mJ28Z83h+mD0/btK5LTCbbU=; b=TDRczUOzNXrucReTCZuI4FBIq2UuM99rE2GIixeN9aL/ysBTVG7167O/ofiV5KXKbM X+Fc3EegqkaDeVG1vDnZkEHEAwJUT+rFGlDIzpv8Sn1Frsa+JgWDGwhLkynWstKmojm5 QWdw6RJq1BYP4vYKXkNMDDgw0B7k0hTSqj2X7whls93Nt8O+3bGMZ7cC3kSSV+tGjw+8 9Q/D8ldIe0feybFxFBhFP9lKWAIs2STKjmySZcjCguHAihuurfHyW9MCYykRKxRb4hMk fTJXayA50nydset6YBU5eqD+MU5Dsl+GSCENSVlPQAbEymlF0kBqbBwS2urrsyAK1noV ETFQ== X-Gm-Message-State: AOAM531OixQb1FfIWfPtR+ybO3TNgJUDILJbLn56qxCEDcH5y21lgviU UclWM4f82Br4pWavNqZA3Ek= X-Google-Smtp-Source: ABdhPJy3sFI6YXMh5uGv3dEWoj7EmK1xHV8O/T0u5oSSOjx1g6tc3/w+1PxIwDQ0046EQmA7HfYb7Q== X-Received: by 2002:a17:90a:ca11:: with SMTP id x17mr2815217pjt.61.1637351878071; Fri, 19 Nov 2021 11:57:58 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:57:57 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Hannes Reinecke , John Garry , "James E.J. Bottomley" Subject: [PATCH v2 06/20] scsi: core: Add support for reserved tags Date: Fri, 19 Nov 2021 11:57:29 -0800 Message-Id: <20211119195743.2817-7-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Allow SCSI LLDs to allocate reserved tags by passing the BLK_MQ_REQ_RESERVED flag to blk_mq_alloc_request(). Cc: Hannes Reinecke Cc: John Garry Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 4 +++- include/scsi/scsi_host.h | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 59c3c4fbcfc0..44489ddc646c 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1925,6 +1925,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) { unsigned int cmd_size, sgl_size; struct blk_mq_tag_set *tag_set = &shost->tag_set; + unsigned int reserved_tags = shost->hostt->reserved_tags; sgl_size = max_t(unsigned int, sizeof(struct scatterlist), scsi_mq_inline_sgl_size(shost)); @@ -1940,7 +1941,8 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) tag_set->ops = &scsi_mq_ops_no_commit; tag_set->nr_hw_queues = shost->nr_hw_queues ? : 1; tag_set->nr_maps = shost->nr_maps ? : 1; - tag_set->queue_depth = shost->can_queue; + tag_set->queue_depth = shost->can_queue + reserved_tags; + tag_set->reserved_tags = reserved_tags; tag_set->cmd_size = cmd_size; tag_set->numa_node = NUMA_NO_NODE; tag_set->flags = BLK_MQ_F_SHOULD_MERGE; diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 72e1a347baa6..ec0f7705e06a 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -367,10 +367,17 @@ struct scsi_host_template { /* * This determines if we will use a non-interrupt driven * or an interrupt driven scheme. It is set to the maximum number - * of simultaneous commands a single hw queue in HBA will accept. + * of simultaneous commands a single hw queue in HBA will accept. Does + * not include @reserved_tags. */ int can_queue; + /* + * Number of tags to reserve. A reserved tag can be allocated by passing + * the BLK_MQ_REQ_RESERVED flag to blk_get_request(). + */ + unsigned reserved_tags; + /* * In many instances, especially where disconnect / reconnect are * supported, our host also has an ID on the SCSI bus. If this is From patchwork Fri Nov 19 19:57:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518705 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E0C4C433EF for ; Fri, 19 Nov 2021 19:58:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6688B61B30 for ; Fri, 19 Nov 2021 19:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234135AbhKSUBL (ORCPT ); Fri, 19 Nov 2021 15:01:11 -0500 Received: from mail-pl1-f173.google.com ([209.85.214.173]:39530 "EHLO mail-pl1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234128AbhKSUBJ (ORCPT ); Fri, 19 Nov 2021 15:01:09 -0500 Received: by mail-pl1-f173.google.com with SMTP id z6so7739242plk.6 for ; Fri, 19 Nov 2021 11:58:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NZUO3LOxhFcyFhieX01niRtnpri/VHzXjqDWXyWDs7M=; b=qDcCREhzRHB305Wvec1qcOmUeCzKlmb0YF8O4jbJ1mwVMYUI7AcPICxx0YeHzL3U7h JO9GSXuF26RzBAcjs0wbspmEUnUN3ECSzH5WyReFan1M5niikmP8LucMzLmQfp194Xa6 GLyrcHtpTzgH0zwbD1spWTgd2Q4gD0/4Tu9aM4Ne1waqeW+XtaMp45FCoPICjJ5XnMPD rUr6LVZ1adbhKHYZfuePnucPvH7QRlXKbW0/N3a573Kpw9nSOIDWaa+QkicYRXImK3Wx fup1qNKAt/iOHjGMGfRtZYxb46G4TqZQ9tRuccHRd4VreJf2ka0O0VVaSiH7pXYJBobP iSeA== X-Gm-Message-State: AOAM530mZ5XdyjRIZ3Hifb/7tMd2tbgXoSs97r2Vq+XXNh2qfbSxJAPt +F9iCp5vtU5O9wqNjoTVk/E= X-Google-Smtp-Source: ABdhPJwAEDae+vPYA0ORq/2ZBvZd7GV+Y7h6IQGKEqnKxx5Bwc+7fyFzi7VwCATIhYyRBwmuj4XmOw== X-Received: by 2002:a17:90a:fa18:: with SMTP id cm24mr2751690pjb.241.1637351887254; Fri, 19 Nov 2021 11:58:07 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.58.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:58:06 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Asutosh Das , Alim Akhtar , kernel test robot , "James E.J. Bottomley" , Bean Huo , Can Guo , Avri Altman , Stanley Chu Subject: [PATCH v2 08/20] scsi: ufs: Remove is_rpmb_wlun() Date: Fri, 19 Nov 2021 11:57:31 -0800 Message-Id: <20211119195743.2817-9-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Commit edc0596cc04b ("scsi: ufs: core: Stop clearing UNIT ATTENTIONS") removed all callers of is_rpmb_wlun(). Hence also remove the function itself. Reviewed-by: Asutosh Das Reviewed-by: Alim Akhtar Reported-by: kernel test robot Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index afd38142b1c0..a3ca9ada0adc 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2650,11 +2650,6 @@ static inline u16 ufshcd_upiu_wlun_to_scsi_wlun(u8 upiu_wlun_id) return (upiu_wlun_id & ~UFS_UPIU_WLUN_ID) | SCSI_W_LUN_BASE; } -static inline bool is_rpmb_wlun(struct scsi_device *sdev) -{ - return sdev->lun == ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN); -} - static inline bool is_device_wlun(struct scsi_device *sdev) { return sdev->lun == From patchwork Fri Nov 19 19:57:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518704 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05D0DC433F5 for ; Fri, 19 Nov 2021 19:58:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3B35610A1 for ; Fri, 19 Nov 2021 19:58:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234330AbhKSUB0 (ORCPT ); Fri, 19 Nov 2021 15:01:26 -0500 Received: from mail-pg1-f173.google.com ([209.85.215.173]:39653 "EHLO mail-pg1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234128AbhKSUBS (ORCPT ); Fri, 19 Nov 2021 15:01:18 -0500 Received: by mail-pg1-f173.google.com with SMTP id r5so9522341pgi.6 for ; Fri, 19 Nov 2021 11:58:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NpmGtVZCN0eh/5cVUgS8lSbtT/POAC/Ec5Ht56f9MCA=; b=05p8grfjKv6zC8wH3z9vc7lfFnFIFoPQX5Rhce0+M+VR/aA+NK2LP5WKHGXd/6Td9V YLcuhZGwGzaSsjnMvK+uDxCw3dCs8Y1MmRxxEEdRT0ZaJpbU5mTify40fgNoEGdmdB4m aUPbCi7JP0gz16/kMUYg23fGCbDmjcRNFkivdXW8nY7+Z8bpggIBg/GVwz2TeFjt+NBX NXFo40B7NcmRwqpmk2MViBH1gtZv6uA0AqwSq4P9NXDn/QuF9nSdVEytsMJpDJoH83B8 FHUvqE2gkl39e8I0a17AYc8acKfr0rlB+tQrgLjOV5Yuz7Wc7KAwNuCe0MDSdaYLDIr1 6sWg== X-Gm-Message-State: AOAM533vlR+zotkuOznKePeAYYabQQWZHfDpNI22UeaKOF/a+vY5p8bY GE+uhp2l3t8kSxykHLlaxzU= X-Google-Smtp-Source: ABdhPJwonBWtCofDPsV+vGsyinrRBQqDroICb5ugA46WFc/s4sZXwH8C0PS1Ftl3pYub6JOAvURRHw== X-Received: by 2002:a05:6a00:234a:b0:49f:c0f7:f474 with SMTP id j10-20020a056a00234a00b0049fc0f7f474mr25569628pfj.64.1637351896264; Fri, 19 Nov 2021 11:58:16 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:58:15 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Avri Altman , Bean Huo , "James E.J. Bottomley" , Can Guo , Stanley Chu , Asutosh Das Subject: [PATCH v2 10/20] scsi: ufs: Remove dead code Date: Fri, 19 Nov 2021 11:57:33 -0800 Message-Id: <20211119195743.2817-11-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Commit 7252a3603015 ("scsi: ufs: Avoid busy-waiting by eliminating tag conflicts") guarantees that 'tag' is not in use by any SCSI command. Remove the check that returns early if a conflict occurs. Acked-by: Avri Altman Reviewed-by: Bean Huo Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index ff9532968ae7..fced4528ee90 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6730,11 +6730,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, tag = req->tag; WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); - if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { - err = -EBUSY; - goto out; - } - lrbp = &hba->lrb[tag]; WARN_ON(lrbp->cmd); lrbp->cmd = NULL; @@ -6802,8 +6797,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP, (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); -out: - blk_mq_free_request(req); out_unlock: up_read(&hba->clk_scaling_lock); return err; From patchwork Fri Nov 19 19:57:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518703 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1DADC433FE for ; Fri, 19 Nov 2021 19:58:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D6BD610A1 for ; Fri, 19 Nov 2021 19:58:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235083AbhKSUBl (ORCPT ); Fri, 19 Nov 2021 15:01:41 -0500 Received: from mail-pj1-f51.google.com ([209.85.216.51]:53872 "EHLO mail-pj1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234088AbhKSUBZ (ORCPT ); Fri, 19 Nov 2021 15:01:25 -0500 Received: by mail-pj1-f51.google.com with SMTP id iq11so8689248pjb.3 for ; Fri, 19 Nov 2021 11:58:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZUTfpKUOajvkqCjSfXNQC91Dp15DuHlS32VtdMmuaQc=; b=F9edPJAkPX/RkuCu+LHt7tJDNNuhbQdi2QRbV0PFAKW51ythQuANlqDYD/n8rtlqn5 9veC0BmwGOh4Fu0a9OH8r+ksm9n+3+va6B9jO7hCS7KkL7NU1EsWWLRwBbN2bXEW0f3+ 378TDdW5whrc8k9LERC9LRmwrhmA4yy5gzqlS5CGub9DtBTu5JirkKw4iRSAjhRZCwl4 F1l0vY6KibROd4Djhctzq0oK9ZzadKtw8oskerRf2Sqyo+ZA9uWCUU+GdubP7iZdIlVD cLb7C2q0KD8qxgZH65ch2qi4aCM8OpwkoYqpUUoZNNcQt4iopjX1TQXhptgn872/EMZj ZYTg== X-Gm-Message-State: AOAM533cJtOEp09707WA8vthdZNVBrOFrgNpws8bk3rLp5HUioqkt3+N FQBMbUo2I0BNTJaoncMNJyU= X-Google-Smtp-Source: ABdhPJwmmyL/NPdR7mPJTwXwX3oghynLQ9e7bo9f+WWzkWonkEEHvZLwFuTwin1ExVe2ZLARIlk+/w== X-Received: by 2002:a17:90a:6045:: with SMTP id h5mr2801452pjm.147.1637351903539; Fri, 19 Nov 2021 11:58:23 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:58:23 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Avri Altman , Stanley Chu , Asutosh Das Subject: [PATCH v2 12/20] scsi: ufs: Rework ufshcd_change_queue_depth() Date: Fri, 19 Nov 2021 11:57:35 -0800 Message-Id: <20211119195743.2817-13-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prepare for making sdev->host->can_queue less than hba->nutrs. This patch does not change any functionality. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index dfa5f127342b..a241ef6bbc6f 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4960,11 +4960,7 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev) */ static int ufshcd_change_queue_depth(struct scsi_device *sdev, int depth) { - struct ufs_hba *hba = shost_priv(sdev->host); - - if (depth > hba->nutrs) - depth = hba->nutrs; - return scsi_change_queue_depth(sdev, depth); + return scsi_change_queue_depth(sdev, min(depth, sdev->host->can_queue)); } static void ufshcd_hpb_destroy(struct ufs_hba *hba, struct scsi_device *sdev) From patchwork Fri Nov 19 19:57:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518702 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F210C433F5 for ; Fri, 19 Nov 2021 19:58:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BEC061B1E for ; Fri, 19 Nov 2021 19:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235415AbhKSUBq (ORCPT ); Fri, 19 Nov 2021 15:01:46 -0500 Received: from mail-pg1-f178.google.com ([209.85.215.178]:43717 "EHLO mail-pg1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234583AbhKSUB3 (ORCPT ); Fri, 19 Nov 2021 15:01:29 -0500 Received: by mail-pg1-f178.google.com with SMTP id b4so9485169pgh.10 for ; Fri, 19 Nov 2021 11:58:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JEfGaERSd8ev5avfUXESx4NC6L+Goz/+gFSlRtuLz4A=; b=3/JI6Tlx56KWlZ3cdGDVicfJWcfymuZ23MYikjPsO4HV2jDQErQV3aiN+r+HrM3ETD E6CYZfR3SZDx0ow3DNGasD44nAoV5khBaFFiu35At/wJK6X7SjVRy0SPK6aMYq1U2Dsw UYefSwh5EHaGAzNBEiqdFMvZeGETwpJuoJPrdNQkLAT38PqfWG+dVPOqxt/YVMj23jOD zMTC1mScHcZ3utXTvyDjlbUifo9lSwrw5GY7QO2lOo8oDDowzXyaVIf3OPR71ieAZuiP UDdm9S/bFVS/6tRL0/WAMkm6C1/BpO9ZXHDgAeJ5uNU4aP8BO2kyxkTTDQRuUiNCHLSH j20w== X-Gm-Message-State: AOAM533cperuAl6QbJKeSs/jLkzQljp7HchYeYKi+uB42DGVRhxQvwkj j/p6Phd6/1ia1EH2Fus+xpQ= X-Google-Smtp-Source: ABdhPJzCLTkT+uOi9Zm+KI62SOPNhIpH1OZzZ3KTXatK3RvAd1LYBn7oa0bw0Pf2mDCL3w2i0t7S9Q== X-Received: by 2002:a05:6a00:248f:b0:4a0:1e25:3155 with SMTP id c15-20020a056a00248f00b004a01e253155mr26024501pfv.21.1637351907186; Fri, 19 Nov 2021 11:58:27 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:58:26 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Avri Altman , Stanley Chu , Asutosh Das Subject: [PATCH v2 13/20] scsi: ufs: Fix a deadlock in the error handler Date: Fri, 19 Nov 2021 11:57:36 -0800 Message-Id: <20211119195743.2817-14-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The following deadlock has been observed on a test setup: * All tags allocated. * The SCSI error handler calls ufshcd_eh_host_reset_handler() * ufshcd_eh_host_reset_handler() queues work that calls ufshcd_err_handler() * ufshcd_err_handler() locks up as follows: Workqueue: ufs_eh_wq_0 ufshcd_err_handler.cfi_jt Call trace: __switch_to+0x298/0x5d8 __schedule+0x6cc/0xa94 schedule+0x12c/0x298 blk_mq_get_tag+0x210/0x480 __blk_mq_alloc_request+0x1c8/0x284 blk_get_request+0x74/0x134 ufshcd_exec_dev_cmd+0x68/0x640 ufshcd_verify_dev_init+0x68/0x35c ufshcd_probe_hba+0x12c/0x1cb8 ufshcd_host_reset_and_restore+0x88/0x254 ufshcd_reset_and_restore+0xd0/0x354 ufshcd_err_handler+0x408/0xc58 process_one_work+0x24c/0x66c worker_thread+0x3e8/0xa4c kthread+0x150/0x1b4 ret_from_fork+0x10/0x30 Fix this lockup by making ufshcd_exec_dev_cmd() allocate a reserved request. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index a241ef6bbc6f..03f4772fc2e2 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -128,8 +128,9 @@ EXPORT_SYMBOL_GPL(ufshcd_dump_regs); enum { UFSHCD_MAX_CHANNEL = 0, UFSHCD_MAX_ID = 1, - UFSHCD_CMD_PER_LUN = 32, - UFSHCD_CAN_QUEUE = 32, + UFSHCD_NUM_RESERVED = 1, + UFSHCD_CMD_PER_LUN = 32 - UFSHCD_NUM_RESERVED, + UFSHCD_CAN_QUEUE = 32 - UFSHCD_NUM_RESERVED, }; static const char *const ufshcd_state_name[] = { @@ -2941,12 +2942,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, down_read(&hba->clk_scaling_lock); - /* - * Get free slot, sleep if slots are unavailable. - * Even though we use wait_event() which sleeps indefinitely, - * the maximum wait time is bounded by SCSI request timeout. - */ - scmd = scsi_get_internal_cmd(q, DMA_TO_DEVICE, 0); + scmd = scsi_get_internal_cmd(q, DMA_TO_DEVICE, BLK_MQ_REQ_RESERVED); if (IS_ERR(scmd)) { err = PTR_ERR(scmd); goto out_unlock; @@ -8171,6 +8167,7 @@ static struct scsi_host_template ufshcd_driver_template = { .sg_tablesize = SG_ALL, .cmd_per_lun = UFSHCD_CMD_PER_LUN, .can_queue = UFSHCD_CAN_QUEUE, + .reserved_tags = UFSHCD_NUM_RESERVED, .max_segment_size = PRDT_DATA_BYTE_COUNT_MAX, .max_host_blocked = 1, .track_queue_depth = 1, @@ -9531,8 +9528,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) /* Configure LRB */ ufshcd_host_memory_configure(hba); - host->can_queue = hba->nutrs; - host->cmd_per_lun = hba->nutrs; + host->can_queue = hba->nutrs - UFSHCD_NUM_RESERVED; + host->cmd_per_lun = hba->nutrs - UFSHCD_NUM_RESERVED; host->max_id = UFSHCD_MAX_ID; host->max_lun = UFS_MAX_LUNS; host->max_channel = UFSHCD_MAX_CHANNEL; From patchwork Fri Nov 19 19:57:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518701 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63ADDC433FE for ; Fri, 19 Nov 2021 19:58:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F1F7610A1 for ; Fri, 19 Nov 2021 19:58:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236373AbhKSUBu (ORCPT ); Fri, 19 Nov 2021 15:01:50 -0500 Received: from mail-pl1-f182.google.com ([209.85.214.182]:36626 "EHLO mail-pl1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236059AbhKSUBo (ORCPT ); Fri, 19 Nov 2021 15:01:44 -0500 Received: by mail-pl1-f182.google.com with SMTP id u11so8940209plf.3 for ; Fri, 19 Nov 2021 11:58:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ervmrfr/PMXzdgfdkURGl3jdLQgRDpD/FMYszboOIRc=; b=UdBPUOOYWZY5UWIRSt1J0K/DZ1pMADqHUHvXDK9SOAYJ3G1jLQJdrz/R0f57pIx23V FHAu/lfdHLAor9gkke6IJyMlUgyG/y5APUZ60qmyyatKJSNn3m1nXlqn6uszDNZDKYw5 vvTNzxgUue0eWssPzKB+HDFTbHOb5R6YuPF5bFQplKrMFdXiV+Qpcz5hitNbE6gDW17T +qKxLf53WpUHK77+diqR+la7gbxpegamfBhiNg/nMCRADAz1x9x8nHgOzkbYR0uApTWl megyyTy/QrDPU/ut/0aUd3m1/mHFHMkcxhtcZYZ9cyKtHpgRPPdWe5oCDPU8mNIyb9co elCw== X-Gm-Message-State: AOAM532B8rg3z/KRzsyiFyGeYJ1wXGqI502uBuOmXnqxF6YiBNlfsi/c nPNLysYws/9mizRWZcPnQtA= X-Google-Smtp-Source: ABdhPJwg/7M3Emd3pj9DSdZAQuhZVfe55O3fBXYn0mf55hEPgNcv7ZiZNN8gUUvgDHxFO18w993kAw== X-Received: by 2002:a17:902:c7d5:b0:143:72b7:2ca5 with SMTP id r21-20020a170902c7d500b0014372b72ca5mr79904311pla.20.1637351921740; Fri, 19 Nov 2021 11:58:41 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:58:41 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Avri Altman , Stanley Chu , Asutosh Das Subject: [PATCH v2 17/20] scsi: ufs: Stop using the clock scaling lock in the error handler Date: Fri, 19 Nov 2021 11:57:40 -0800 Message-Id: <20211119195743.2817-18-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Instead of locking and unlocking the clock scaling lock, surround the command queueing code with an RCU reader lock and call synchronize_rcu(). This patch prepares for removal of the clock scaling lock. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6a743da7d2db..a6d3f71c6b00 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2702,6 +2702,12 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) if (!down_read_trylock(&hba->clk_scaling_lock)) return SCSI_MLQUEUE_HOST_BUSY; + /* + * Allows the UFS error handler to wait for prior ufshcd_queuecommand() + * calls. + */ + rcu_read_lock(); + switch (hba->ufshcd_state) { case UFSHCD_STATE_OPERATIONAL: break; @@ -2780,7 +2786,10 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) } ufshcd_send_command(hba, tag); + out: + rcu_read_unlock(); + up_read(&hba->clk_scaling_lock); if (ufs_trigger_eh()) { @@ -5986,8 +5995,7 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba) } ufshcd_scsi_block_requests(hba); /* Drain ufshcd_queuecommand() */ - down_write(&hba->clk_scaling_lock); - up_write(&hba->clk_scaling_lock); + synchronize_rcu(); cancel_work_sync(&hba->eeh_work); } From patchwork Fri Nov 19 19:57:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518700 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55178C433EF for ; Fri, 19 Nov 2021 19:58:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 426F2610A1 for ; Fri, 19 Nov 2021 19:58:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235083AbhKSUB4 (ORCPT ); Fri, 19 Nov 2021 15:01:56 -0500 Received: from mail-pj1-f42.google.com ([209.85.216.42]:37445 "EHLO mail-pj1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236210AbhKSUBt (ORCPT ); Fri, 19 Nov 2021 15:01:49 -0500 Received: by mail-pj1-f42.google.com with SMTP id cq22-20020a17090af99600b001a9550a17a5so11778021pjb.2 for ; Fri, 19 Nov 2021 11:58:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1/KqamDFUllDDt4JBg8BsSRY3ZHEeUO2jb7QeQ204zI=; b=daNN48NEmvvPqFm+i5hQ5IeLVGC1+MTkdZL4wPIhCQ3CKxDw3AJJzeX9t2V9nTyqgp PSCagEl3yWpqzJmd7zQt4oEc6elyGRLfgo48nFi3HDYzL25cp7rXf2PVcdqFdQU1L5fu OS+ItREtJwv6o5sx3Y8zxw/1Z+zyydpq3gFZFiyJMqjUSkUasbLKch8qgFZ9BnMotbCX yZX2zDaGb723rvOuiIDBpeLr4tewF1aV1YSTrWCes1fFU4MbLz68ZfI72oaZ/grTKXYy 1Ob7l0Tct0wEQvITRN7QxeXNXe/8lAIu0djPfyNBoolTF984k17SUsUuGsWga+ym2W6a voDw== X-Gm-Message-State: AOAM533UQP476lC+sJFsK98uDhkCy4UB6uQilpnWch0xhjzoMPPc4Hpo ijo4SUdIiaQ2Ws5CIpy7fZA= X-Google-Smtp-Source: ABdhPJyNDfqpGWCgo/JDagGmZM5Ma3MO8HhKZC41VkPjIuzl5NV6hUK5zw1b/Sg1kLsQWLXjKiRCeQ== X-Received: by 2002:a17:902:8f97:b0:143:88c2:e2d5 with SMTP id z23-20020a1709028f9700b0014388c2e2d5mr80752499plo.70.1637351927147; Fri, 19 Nov 2021 11:58:47 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:58:46 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Avri Altman , Stanley Chu , Asutosh Das , Keoseong Park Subject: [PATCH v2 18/20] scsi: ufs: Optimize the command queueing code Date: Fri, 19 Nov 2021 11:57:41 -0800 Message-Id: <20211119195743.2817-19-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Remove the clock scaling lock from ufshcd_queuecommand() since it is a performance bottleneck. Freeze request queues instead of polling the doorbell registers to wait until pending commands have completed. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 124 +++++++++++++------------------------- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 44 insertions(+), 81 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index a6d3f71c6b00..9cf4a22f1950 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1070,65 +1070,6 @@ static bool ufshcd_is_devfreq_scaling_required(struct ufs_hba *hba, return false; } -static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, - u64 wait_timeout_us) -{ - unsigned long flags; - int ret = 0; - u32 tm_doorbell; - u32 tr_doorbell; - bool timeout = false, do_last_check = false; - ktime_t start; - - ufshcd_hold(hba, false); - spin_lock_irqsave(hba->host->host_lock, flags); - /* - * Wait for all the outstanding tasks/transfer requests. - * Verify by checking the doorbell registers are clear. - */ - start = ktime_get(); - do { - if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) { - ret = -EBUSY; - goto out; - } - - tm_doorbell = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL); - tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); - if (!tm_doorbell && !tr_doorbell) { - timeout = false; - break; - } else if (do_last_check) { - break; - } - - spin_unlock_irqrestore(hba->host->host_lock, flags); - schedule(); - if (ktime_to_us(ktime_sub(ktime_get(), start)) > - wait_timeout_us) { - timeout = true; - /* - * We might have scheduled out for long time so make - * sure to check if doorbells are cleared by this time - * or not. - */ - do_last_check = true; - } - spin_lock_irqsave(hba->host->host_lock, flags); - } while (tm_doorbell || tr_doorbell); - - if (timeout) { - dev_err(hba->dev, - "%s: timedout waiting for doorbell to clear (tm=0x%x, tr=0x%x)\n", - __func__, tm_doorbell, tr_doorbell); - ret = -EBUSY; - } -out: - spin_unlock_irqrestore(hba->host->host_lock, flags); - ufshcd_release(hba); - return ret; -} - /** * ufshcd_scale_gear - scale up/down UFS gear * @hba: per adapter instance @@ -1176,37 +1117,63 @@ static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up) static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) { - #define DOORBELL_CLR_TOUT_US (1000 * 1000) /* 1 sec */ - int ret = 0; + struct scsi_device *sdev; + /* - * make sure that there are no outstanding requests when - * clock scaling is in progress + * Make sure that no commands are in progress while the clock frequency + * is being modified. + * + * Since ufshcd_exec_dev_cmd() and ufshcd_issue_devman_upiu_cmd() lock + * the clk_scaling_lock before calling blk_get_request(), lock + * clk_scaling_lock before freezing the request queues to prevent lock + * inversion. */ - ufshcd_scsi_block_requests(hba); down_write(&hba->clk_scaling_lock); - - if (!hba->clk_scaling.is_allowed || - ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) { - ret = -EBUSY; - up_write(&hba->clk_scaling_lock); - ufshcd_scsi_unblock_requests(hba); - goto out; - } - + if (!hba->clk_scaling.is_allowed) + goto busy; + blk_freeze_queue_start(hba->tmf_queue); + blk_freeze_queue_start(hba->cmd_queue); + shost_for_each_device(sdev, hba->host) + blk_freeze_queue_start(sdev->request_queue); + /* + * Calling synchronize_rcu_expedited() reduces the time required to + * freeze request queues from milliseconds to microseconds. + */ + synchronize_rcu_expedited(); + shost_for_each_device(sdev, hba->host) + if (blk_mq_freeze_queue_wait_timeout(sdev->request_queue, HZ) + <= 0) + goto unfreeze; + if (blk_mq_freeze_queue_wait_timeout(hba->cmd_queue, HZ) <= 0 || + blk_mq_freeze_queue_wait_timeout(hba->tmf_queue, HZ / 10) <= 0) + goto unfreeze; /* let's not get into low power until clock scaling is completed */ ufshcd_hold(hba, false); + return 0; -out: - return ret; +unfreeze: + shost_for_each_device(sdev, hba->host) + blk_mq_unfreeze_queue(sdev->request_queue); + blk_mq_unfreeze_queue(hba->cmd_queue); + blk_mq_unfreeze_queue(hba->tmf_queue); + +busy: + up_write(&hba->clk_scaling_lock); + return -EBUSY; } static void ufshcd_clock_scaling_unprepare(struct ufs_hba *hba, bool writelock) { + struct scsi_device *sdev; + + shost_for_each_device(sdev, hba->host) + blk_mq_unfreeze_queue(sdev->request_queue); + blk_mq_unfreeze_queue(hba->cmd_queue); + blk_mq_unfreeze_queue(hba->tmf_queue); if (writelock) up_write(&hba->clk_scaling_lock); else up_read(&hba->clk_scaling_lock); - ufshcd_scsi_unblock_requests(hba); ufshcd_release(hba); } @@ -2699,9 +2666,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); - if (!down_read_trylock(&hba->clk_scaling_lock)) - return SCSI_MLQUEUE_HOST_BUSY; - /* * Allows the UFS error handler to wait for prior ufshcd_queuecommand() * calls. @@ -2790,8 +2754,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) out: rcu_read_unlock(); - up_read(&hba->clk_scaling_lock); - if (ufs_trigger_eh()) { unsigned long flags; diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index e9bc07c69a80..7ec463c97d64 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -778,6 +778,7 @@ struct ufs_hba_monitor { * @clk_list_head: UFS host controller clocks list node head * @pwr_info: holds current power mode * @max_pwr_info: keeps the device max valid pwm + * @clk_scaling_lock: used to serialize device commands and clock scaling * @desc_size: descriptor sizes reported by device * @urgent_bkops_lvl: keeps track of urgent bkops level for device * @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for From patchwork Fri Nov 19 19:57:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 518699 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AD9EC433F5 for ; Fri, 19 Nov 2021 19:59:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 080616102A for ; Fri, 19 Nov 2021 19:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236668AbhKSUCL (ORCPT ); Fri, 19 Nov 2021 15:02:11 -0500 Received: from mail-pg1-f182.google.com ([209.85.215.182]:33602 "EHLO mail-pg1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236676AbhKSUCA (ORCPT ); Fri, 19 Nov 2021 15:02:00 -0500 Received: by mail-pg1-f182.google.com with SMTP id q132so507976pgq.0 for ; Fri, 19 Nov 2021 11:58:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HIggx46fqkobnDGo3m+G+qKCcPySQGDE1Cs2ilKyMro=; b=06eUgrhiGpWTtOvYo21+eJAXwZE/KUpCpvhp+qVDYJf78xL9N5J77gVMyHW2LxE1pd iE/tmsvIBzXBe9QcotAtGum7oxxPdZlRuN74Ssl+nBuFc8HPWVkpBQYNUOyllKu17qbz BfkpwsAmI5blIXdQ+rCvM2fn1ONUbS7vaxf60EDdC+UDlCOcNST7zUFLrRKmg2gwoTkH 4q3qZdpE3kNMIbtrx/kjjyCKSdepjEnEkWsZ5YpUo8Dbb0U26g/FbHBS1xtddspmaCbl u9W3+Q03MW6zsxldVxSg4bmHEh1NwjM3PrUA1OTWFN/X57v02T0BvHsGU+c6IUFmrnA4 T77Q== X-Gm-Message-State: AOAM532Uz+/M9d246kEl6NViXXqUmyUorF7kAIhscjCKRjGURBDTdi6y u0Y1yfj+d13nkD8TT2a0Wfo= X-Google-Smtp-Source: ABdhPJwVi3/fZ29W7LF3suG7lZazJLgbeSoECYFmOpEydW7itW1oD53CFlWgNr+SVnoTidCiD2GHKQ== X-Received: by 2002:a65:4249:: with SMTP id d9mr19513198pgq.351.1637351938021; Fri, 19 Nov 2021 11:58:58 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id g11sm379010pgn.41.2021.11.19.11.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 11:58:57 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Alexey Dobriyan , "James E.J. Bottomley" , Avri Altman , Bean Huo , Asutosh Das , Stanley Chu , Sergey Shtylyov , Can Guo , Yue Hu , Srinivas Kandagatla Subject: [PATCH v2 20/20] scsi: ufs: Fix race conditions related to driver data Date: Fri, 19 Nov 2021 11:57:43 -0800 Message-Id: <20211119195743.2817-21-bvanassche@acm.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211119195743.2817-1-bvanassche@acm.org> References: <20211119195743.2817-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Reported-by: Alexey Dobriyan Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/tc-dwc-g210-pci.c | 1 - drivers/scsi/ufs/ufshcd-pci.c | 2 -- drivers/scsi/ufs/ufshcd-pltfrm.c | 2 -- drivers/scsi/ufs/ufshcd.c | 7 +++++++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/tc-dwc-g210-pci.c b/drivers/scsi/ufs/tc-dwc-g210-pci.c index 679289e1a78e..7b08e2e07cc5 100644 --- a/drivers/scsi/ufs/tc-dwc-g210-pci.c +++ b/drivers/scsi/ufs/tc-dwc-g210-pci.c @@ -110,7 +110,6 @@ tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) return err; } - pci_set_drvdata(pdev, hba); pm_runtime_put_noidle(&pdev->dev); pm_runtime_allow(&pdev->dev); diff --git a/drivers/scsi/ufs/ufshcd-pci.c b/drivers/scsi/ufs/ufshcd-pci.c index 51424557810d..a673eedb2f05 100644 --- a/drivers/scsi/ufs/ufshcd-pci.c +++ b/drivers/scsi/ufs/ufshcd-pci.c @@ -522,8 +522,6 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) return err; } - pci_set_drvdata(pdev, hba); - hba->vops = (struct ufs_hba_variant_ops *)id->driver_data; err = ufshcd_init(hba, mmio_base, pdev->irq); diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c index eaeae83b999f..8b16bbbcb806 100644 --- a/drivers/scsi/ufs/ufshcd-pltfrm.c +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -361,8 +361,6 @@ int ufshcd_pltfrm_init(struct platform_device *pdev, goto dealloc_host; } - platform_set_drvdata(pdev, hba); - pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 14043d74389d..b78e92298407 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -9523,6 +9523,13 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) struct device *dev = hba->dev; char eh_wq_name[sizeof("ufs_eh_wq_00")]; + /* + * dev_set_drvdata() must be called before any callbacks are registered + * that use dev_get_drvdata() (frequency scaling, clock scaling, hwmon, + * sysfs). + */ + dev_set_drvdata(dev, hba); + if (!mmio_base) { dev_err(hba->dev, "Invalid memory reference for mmio_base is NULL\n");