From patchwork Tue Nov 30 23:33:08 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: 518635 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 594C3C433F5 for ; Tue, 30 Nov 2021 23:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241059AbhK3Xgz (ORCPT ); Tue, 30 Nov 2021 18:36:55 -0500 Received: from mail-pj1-f53.google.com ([209.85.216.53]:46729 "EHLO mail-pj1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241159AbhK3Xgw (ORCPT ); Tue, 30 Nov 2021 18:36:52 -0500 Received: by mail-pj1-f53.google.com with SMTP id np6-20020a17090b4c4600b001a90b011e06so18719645pjb.5 for ; Tue, 30 Nov 2021 15:33:33 -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=F+dZM7KWrnvw9D2zFlMFJLpRTk0sjY7KdgSvJCF/dHw=; b=KQxnIiuLyTvvf+neeSW8EXJ1ziM9HuWIddkHp3yA9bXFlxEoqrEqNTrmWbtEWFi75r dCAW2oLgt5X66lQfb4cFQ0iHCjTmDiZ/NHK3so/X5l3S1XJORDHqqaOa/CxcvynOmVFG XNXO7jUwgOzXgH+K4491weRVH63pu35GstHsb9icC7O5xyx2edkYpBwMR55cPk7peGxb 9eiGBTsYqUignVmdEhf4/kLYZMS6a7hJ3TZZEuOmHBE3wX3ZU8JpukDdITFaDlAzgw2h 8ifwR3Evxn2gnnkAWp6ZELoDoeCB5bKBhfQ2/9+MkPGx4w4yNXhmx2sC2ODbaYuDWU9Q SVNw== X-Gm-Message-State: AOAM53214eErjogsGmKbGFsjGLOQWduc2eXJDE4bUrcRbCYkcNnxOEzA VcqpfVsXmY6ICtlAqQ3KehY= X-Google-Smtp-Source: ABdhPJzpiU4f9PiZuH2BX+mC30gL7rGfLvFIrrjRW09J+Ubhb1pqn66zczXt9hbbAzt8PkiD3UHQOQ== X-Received: by 2002:a17:90b:1a88:: with SMTP id ng8mr2646696pjb.180.1638315212445; Tue, 30 Nov 2021 15:33:32 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.33.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:33:31 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Ming Lei , Hannes Reinecke , Sumanesh Samanta , "James E.J. Bottomley" Subject: [PATCH v3 01/17] scsi: core: Fix scsi_device_max_queue_depth() Date: Tue, 30 Nov 2021 15:33:08 -0800 Message-Id: <20211130233324.1402448-2-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The comment above scsi_device_max_queue_depth() and also the description of commit ca4453213951 ("scsi: core: Make sure sdev->queue_depth is <= max(shost->can_queue, 1024)") contradict the implementation of the function scsi_device_max_queue_depth(). Additionally, the maximum queue depth of a SCSI LUN never exceeds host->can_queue. Fix scsi_device_max_queue_depth() by changing max_t() into min_t(). Cc: Ming Lei Cc: Hannes Reinecke Cc: Sumanesh Samanta Fixes: ca4453213951 ("scsi: core: Make sure sdev->queue_depth is <= max(shost->can_queue, 1024)") Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei --- drivers/scsi/scsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index dee4d9c6046d..211aace69c22 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -200,11 +200,11 @@ void scsi_finish_command(struct scsi_cmnd *cmd) /* - * 1024 is big enough for saturating the fast scsi LUN now + * 1024 is big enough for saturating fast SCSI LUNs. */ int scsi_device_max_queue_depth(struct scsi_device *sdev) { - return max_t(int, sdev->host->can_queue, 1024); + return min_t(int, sdev->host->can_queue, 1024); } /** From patchwork Tue Nov 30 23:33:09 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: 520138 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 C36F5C4332F for ; Tue, 30 Nov 2021 23:33:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241075AbhK3Xg4 (ORCPT ); Tue, 30 Nov 2021 18:36:56 -0500 Received: from mail-pg1-f182.google.com ([209.85.215.182]:35571 "EHLO mail-pg1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237120AbhK3Xgy (ORCPT ); Tue, 30 Nov 2021 18:36:54 -0500 Received: by mail-pg1-f182.google.com with SMTP id j11so11634762pgs.2 for ; Tue, 30 Nov 2021 15:33:34 -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=79ANoRxFCQyQSQeGrkbytlrH447uaGQEk6m/ikz4z1g=; b=42ptKKzajKErzT44E8K2iaTmje2eLTMYuBzcF83UzP1zUs94t9I7RzGDewuEVqmSYN FCPOmcN7cS3wVdTeEhp53kvQvD9a04QVCuOXZsIzVTn9tuOq4i40CCpRjCsGomZDC2CO rsOMmj9tHHHOeGYtOnvKl1jOAJacidW50U4gta5lqMOcyU/VOq+6sFnU5wAKhjk0Nt44 uzqBdjHWdiSEhcTsXwp2WNS3pTrPUnes8uk3LFcc4dkqfJSxy+ktqG2cAmGgpBLBUTjw VHTZOwuE28R/bKjiAzAZYwOXVtJ+ykmqA9hEZHDYu75XFqLxVJ5s/VH0H7aYJDJz4Plx z09w== X-Gm-Message-State: AOAM530G3am3Qhtk1PlRZf4JO9W09Jez2dcCDnlROvRcRYy3/EpTJMmi ylYtu7r//4sn4Y0dImbdAuB8AMepCuc= X-Google-Smtp-Source: ABdhPJwI1oFULDV9YKeuO1EkUc6vtVjokVMM3+vaMGYn3k5yoNw5Pes5sm+2hUWrTBYSxA4ARKCz/A== X-Received: by 2002:a63:1016:: with SMTP id f22mr1853259pgl.566.1638315213916; Tue, 30 Nov 2021 15:33:33 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:33:33 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Keith Busch , Adrian Hunter , "James E.J. Bottomley" , Jens Axboe Subject: [PATCH v3 02/17] scsi: core: Fix a race between scsi_done() and scsi_times_out() Date: Tue, 30 Nov 2021 15:33:09 -0800 Message-Id: <20211130233324.1402448-3-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch restores the behavior of the following algorithm from the legacy block layer: - Before completing a request, test-and-set REQ_ATOM_COMPLETE atomically. Only call the block driver completion function if that flag was not yet set. - Before calling the block driver timeout function, test-and-set REQ_ATOM_COMPLETE atomically. Only call the timeout handler if that flag was not yet set. If that flag was already set, do not restart the timer. Cc: Keith Busch Reported-by: Adrian Hunter Fixes: 065990bd198e ("scsi: set timed out out mq requests to complete") Signed-off-by: Bart Van Assche Signed-off-by: Bart Van Assche Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_error.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 9cb0f9df621a..cd05f2db3339 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -331,6 +331,14 @@ enum blk_eh_timer_return scsi_times_out(struct request *req) enum blk_eh_timer_return rtn = BLK_EH_DONE; struct Scsi_Host *host = scmd->device->host; + /* + * scsi_done() may be called concurrently with scsi_times_out(). Only + * one of these two functions should proceed. Hence return early if + * scsi_done() won the race. + */ + if (test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state)) + return BLK_EH_DONE; + trace_scsi_dispatch_cmd_timeout(scmd); scsi_log_completion(scmd, TIMEOUT_ERROR); @@ -341,20 +349,6 @@ enum blk_eh_timer_return scsi_times_out(struct request *req) rtn = host->hostt->eh_timed_out(scmd); if (rtn == BLK_EH_DONE) { - /* - * Set the command to complete first in order to prevent a real - * completion from releasing the command while error handling - * is using it. If the command was already completed, then the - * lower level driver beat the timeout handler, and it is safe - * to return without escalating error recovery. - * - * If timeout handling lost the race to a real completion, the - * block layer may ignore that due to a fake timeout injection, - * so return RESET_TIMER to allow error handling another shot - * at this command. - */ - if (test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state)) - return BLK_EH_RESET_TIMER; if (scsi_abort_command(scmd) != SUCCESS) { set_host_byte(scmd, DID_TIME_OUT); scsi_eh_scmd_add(scmd); From patchwork Tue Nov 30 23:33:10 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: 518634 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 CAEF4C433EF for ; Tue, 30 Nov 2021 23:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241159AbhK3XhI (ORCPT ); Tue, 30 Nov 2021 18:37:08 -0500 Received: from mail-pl1-f171.google.com ([209.85.214.171]:36849 "EHLO mail-pl1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241095AbhK3XhB (ORCPT ); Tue, 30 Nov 2021 18:37:01 -0500 Received: by mail-pl1-f171.google.com with SMTP id u11so16210012plf.3 for ; Tue, 30 Nov 2021 15:33: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=rrrrLIqTiCPIc2x/fw9rWnKpd2BAH4hDd4xjJM9vM+0=; b=rQxQGGPGyEKwOUDPdgaG0aBK260sBWsr9NFCAvDQ5pZDZkbaG8yqjYIdTOJ487Ac03 4RHDoTDg3DmNPQgX97+e/qcKD+nPB4IpTg0asCMdATHBrbAjDZ8rlsxcBNpukZVQ01Va EB4WANWTcyjm9VBbo4GKA5UWoHIxp5ylGruxRBdMqc8GcMnqK3XS8NzQxN+audZtlc+m VMtWSvcaXERSo0n+NVV9OJTCYCEv1f3dUbRdJlkAgQCj49NiVR68CayAY4OFQUVhzwwV iJu66DgtQsl2LJGRmfeGLDo2TbNCMiDDR2mIZUI8h67suJlN4224/J/GdEWvfJ3yvKe/ 7PFQ== X-Gm-Message-State: AOAM531aCSxMVlW+pXA6mEnGxWdVL3HiQ8ytca5y8naNemUy0LxiTJpl RIX43q8hvuvOfyStW+iMIbw= X-Google-Smtp-Source: ABdhPJxnodbDOlUjs8r3gJtIFVGJZV2PAP+mKAJrCJVEMEF0RcJUAyQXAWZXT3OVi606PA5QbILUbw== X-Received: by 2002:a17:90b:2245:: with SMTP id hk5mr2821936pjb.6.1638315221576; Tue, 30 Nov 2021 15:33:41 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:33:41 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Chanho Park , Alim Akhtar , Keoseong Park , Bean Huo , "James E.J. Bottomley" , Krzysztof Kozlowski , Kiwoong Kim , Yue Hu , Stanley Chu , Avri Altman , Can Guo , Adrian Hunter , Asutosh Das Subject: [PATCH v3 03/17] scsi: ufs: Rename a function argument Date: Tue, 30 Nov 2021 15:33:10 -0800 Message-Id: <20211130233324.1402448-4-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The new name makes it clear what the meaning of the function argument is. Reviewed-by: Chanho Park Acked-by: Alim Akhtar Reviewed-by: Keoseong Park Reviewed-by: Bean Huo Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufs-exynos.c | 4 ++-- drivers/scsi/ufs/ufshcd.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufs-exynos.c b/drivers/scsi/ufs/ufs-exynos.c index cd26bc82462e..474a4a064a68 100644 --- a/drivers/scsi/ufs/ufs-exynos.c +++ b/drivers/scsi/ufs/ufs-exynos.c @@ -853,14 +853,14 @@ static int exynos_ufs_post_pwr_mode(struct ufs_hba *hba, } static void exynos_ufs_specify_nexus_t_xfer_req(struct ufs_hba *hba, - int tag, bool op) + int tag, bool is_scsi_cmd) { struct exynos_ufs *ufs = ufshcd_get_variant(hba); u32 type; type = hci_readl(ufs, HCI_UTRL_NEXUS_TYPE); - if (op) + if (is_scsi_cmd) hci_writel(ufs, type | (1 << tag), HCI_UTRL_NEXUS_TYPE); else hci_writel(ufs, type & ~(1 << tag), HCI_UTRL_NEXUS_TYPE); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 6103e98e9a08..28c1bbe9fa7d 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -338,7 +338,8 @@ struct ufs_hba_variant_ops { enum ufs_notify_change_status status, struct ufs_pa_layer_attr *, struct ufs_pa_layer_attr *); - void (*setup_xfer_req)(struct ufs_hba *, int, bool); + void (*setup_xfer_req)(struct ufs_hba *hba, int tag, + bool is_scsi_cmd); void (*setup_task_mgmt)(struct ufs_hba *, int, u8); void (*hibern8_notify)(struct ufs_hba *, enum uic_cmd_dme, enum ufs_notify_change_status); From patchwork Tue Nov 30 23:33:11 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: 520137 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 6DFEEC433F5 for ; Tue, 30 Nov 2021 23:33:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230386AbhK3XhN (ORCPT ); Tue, 30 Nov 2021 18:37:13 -0500 Received: from mail-pj1-f46.google.com ([209.85.216.46]:56192 "EHLO mail-pj1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236283AbhK3XhG (ORCPT ); Tue, 30 Nov 2021 18:37:06 -0500 Received: by mail-pj1-f46.google.com with SMTP id v23so16500403pjr.5 for ; Tue, 30 Nov 2021 15:33: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=RBVvpH8dg3y7bfs6Vgy2geJPP0x7Fiiw2uEdgKD9aAM=; b=wN0w3Vq+L9XpVAQTq4sUJ/1Tjb/gPLG1liEqn/wQ0hRuIUOviEbh9YkBZNpiWfMgP/ pDq6HqIMiSN4In4P+3bFDz+zPMMGdVDkQwzvxyTS2HTHdI6yD/BjCRjRi7bzetE83fSy 3voTt2emI7xjOHUsMBFZZTKdnTuLLzmrI2Ck/qOtPwZTaL2CAXj79hRH2aT5E6gRPMwE 3dWSKk5hNwA+tYGpqfTFqgPmezxQNQxE7wIqRmgNH2yEkZytj/zpG2/+4JFsol71TfQC Tosx83EBaD//A0dH/3lLcBNSwTYIYuSb8SJtUQUeDYnrWs+yrpeUc5LB9KIf+KW2/IEz kO9g== X-Gm-Message-State: AOAM533LpBXvo8SqGZa7oOC+Usnla1tkJvitvN10ZwBxwzDxDFDd4ICU oiSe4mbT0R2L/4kGEmic2EY= X-Google-Smtp-Source: ABdhPJzELzrgnfZ9zVytqfvGpUOBD00KqQZUtcelmjH0D+52lDHu040NBoYDcO8DdCfTnJpATPbl7Q== X-Received: by 2002:a17:90b:380a:: with SMTP id mq10mr2679500pjb.61.1638315226622; Tue, 30 Nov 2021 15:33:46 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:33:46 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , 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 , Adrian Hunter , Stanley Chu Subject: [PATCH v3 04/17] scsi: ufs: Remove is_rpmb_wlun() Date: Tue, 30 Nov 2021 15:33:11 -0800 Message-Id: <20211130233324.1402448-5-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-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 024f6d958341..4821ad9912bb 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 Tue Nov 30 23:33:12 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: 518633 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 6678AC433EF for ; Tue, 30 Nov 2021 23:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231616AbhK3XhP (ORCPT ); Tue, 30 Nov 2021 18:37:15 -0500 Received: from mail-pg1-f178.google.com ([209.85.215.178]:41508 "EHLO mail-pg1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236283AbhK3XhO (ORCPT ); Tue, 30 Nov 2021 18:37:14 -0500 Received: by mail-pg1-f178.google.com with SMTP id k4so11402759pgb.8 for ; Tue, 30 Nov 2021 15:33:55 -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=qp6OgTSeGaLaP7FXJm6cQqjf4ONa+6UL3Ui5n6wvjR0=; b=wdy/BUWxZh1gt9T5j4izEasAu6FzTK0nd9iNrN33YeIaXbsIgmxThYvktydOTdKWjp sTLUU1wFEM3zvI17r/b+nA3QOREZK0Ph48EDwLcPNDYWrAJXPMkcI6e6rDCeyUdE4/4R TAnEGqo1XTuxi0BJsRXkIzDhGu0OVAUjc1vaNE4u+D0gmWC5XyVvyTHyWUB8ChlrAWp6 IUJKruSY/UnL0AQPsU3X9MCqtQbHw+9+/saeiPE0PHZVIAd9tpZRQoX855/GF08vMm3R aALMgBuZB4fSFpyf72uiVUnMKte6EuR7WAr/rMjqXOtPCdLYIlB6S/F53eYMDdOx3+CE HuAw== X-Gm-Message-State: AOAM532Bf6oWITR1cage6UrUkOCfYWP5H2cdN9Hz559az+EVTXw3MXal zALsuzZb5jEc7yR76SUAJCg= X-Google-Smtp-Source: ABdhPJyrQNVMoM01Id7uxc2vcThGq7jfSb2X+fPK01QvN7FQbYKIpM7bn0kmcoxXOcTny23zCQsc2Q== X-Received: by 2002:a63:8849:: with SMTP id l70mr1859869pgd.257.1638315234788; Tue, 30 Nov 2021 15:33:54 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.33.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:33:54 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Asutosh Das , Alim Akhtar , "James E.J. Bottomley" , Bean Huo , Avri Altman , Can Guo , Adrian Hunter , Stanley Chu , Keoseong Park Subject: [PATCH v3 05/17] scsi: ufs: Remove the sdev_rpmb member Date: Tue, 30 Nov 2021 15:33:12 -0800 Message-Id: <20211130233324.1402448-6-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Since the sdev_rpmb member of struct ufs_hba is only used inside ufshcd_scsi_add_wlus(), convert it into a local variable. Reviewed-by: Asutosh Das Reviewed-by: Alim Akhtar Suggested-by: Jaegeuk Kim Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 12 ++++++------ drivers/scsi/ufs/ufshcd.h | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 4821ad9912bb..973b7b083dbe 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7412,7 +7412,7 @@ static inline void ufshcd_blk_pm_runtime_init(struct scsi_device *sdev) static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) { int ret = 0; - struct scsi_device *sdev_boot; + struct scsi_device *sdev_boot, *sdev_rpmb; hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0, ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_UFS_DEVICE_WLUN), NULL); @@ -7423,14 +7423,14 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) } scsi_device_put(hba->sdev_ufs_device); - hba->sdev_rpmb = __scsi_add_device(hba->host, 0, 0, + sdev_rpmb = __scsi_add_device(hba->host, 0, 0, ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL); - if (IS_ERR(hba->sdev_rpmb)) { - ret = PTR_ERR(hba->sdev_rpmb); + if (IS_ERR(sdev_rpmb)) { + ret = PTR_ERR(sdev_rpmb); goto remove_sdev_ufs_device; } - ufshcd_blk_pm_runtime_init(hba->sdev_rpmb); - scsi_device_put(hba->sdev_rpmb); + ufshcd_blk_pm_runtime_init(sdev_rpmb); + scsi_device_put(sdev_rpmb); sdev_boot = __scsi_add_device(hba->host, 0, 0, ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 28c1bbe9fa7d..ecc6c545a19d 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -809,7 +809,6 @@ struct ufs_hba { * "UFS device" W-LU. */ struct scsi_device *sdev_ufs_device; - struct scsi_device *sdev_rpmb; #ifdef CONFIG_SCSI_UFS_HWMON struct device *hwmon_device; From patchwork Tue Nov 30 23:33:13 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: 520136 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 64B85C433F5 for ; Tue, 30 Nov 2021 23:34:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240900AbhK3Xhc (ORCPT ); Tue, 30 Nov 2021 18:37:32 -0500 Received: from mail-pl1-f177.google.com ([209.85.214.177]:35587 "EHLO mail-pl1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241065AbhK3XhU (ORCPT ); Tue, 30 Nov 2021 18:37:20 -0500 Received: by mail-pl1-f177.google.com with SMTP id b13so16220824plg.2 for ; Tue, 30 Nov 2021 15:34:00 -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=2NcKKuNFXDrVoNqJibcOxzYNgtrcA0XwNPYkrUXSc+8=; b=bgB8rMnH++ln5qChWQT77mzTXTT8tB4KuUblUCVv2AR/W+lROMuhSjJ3hqkDWlMNji Kr65n1ksp9UDzlD5aPLe5gw0VL1f0wRjxcWsWJMu3Jnp4ljcxLwP+G4Dzbbg9RUTvAAb XIi9J2AfFVs+ih3ZbXmeO2OkRKG4/lNkBF21sM6/RvD3g6uhJDAhaL1/vfXlIWb6KXta omDYmzkIZc/SGU8uANDqTxDWCREOM5Og0qiWtoMc7szCprAQmwJcu4etTuqb0iYs0JJC 1XTHB7F54mzNwrKFmEPKNxsx2ZAevqB1AIoR2NrR3r8vUHV3XDRGUEfufSlH/7aa8RcG gohA== X-Gm-Message-State: AOAM533lFzI/J7sBTvdHtjBdcOmYcsC1ou9grqa6mIAkNr/CER0VjsCD xhwyaOG1XJM0yrVIEZAflbk= X-Google-Smtp-Source: ABdhPJxVDvum3oCTIBYHML/nvLksNERCX/QiYwN6y6tsZ4SnHzStUXCRyeYz/clD+6/r4TKHGj4Kxg== X-Received: by 2002:a17:90b:4b90:: with SMTP id lr16mr2751323pjb.57.1638315239764; Tue, 30 Nov 2021 15:33:59 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:33:59 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Avri Altman , Bean Huo , "James E.J. Bottomley" , Can Guo , Adrian Hunter , Stanley Chu , Asutosh Das Subject: [PATCH v3 06/17] scsi: ufs: Remove dead code Date: Tue, 30 Nov 2021 15:33:13 -0800 Message-Id: <20211130233324.1402448-7-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-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, 1 insertion(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 973b7b083dbe..d4996ada55b6 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,8 @@ 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 Tue Nov 30 23:33:14 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: 518632 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 192CCC433EF for ; Tue, 30 Nov 2021 23:34:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241065AbhK3Xhd (ORCPT ); Tue, 30 Nov 2021 18:37:33 -0500 Received: from mail-pj1-f43.google.com ([209.85.216.43]:54036 "EHLO mail-pj1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232973AbhK3Xhb (ORCPT ); Tue, 30 Nov 2021 18:37:31 -0500 Received: by mail-pj1-f43.google.com with SMTP id iq11so16525238pjb.3 for ; Tue, 30 Nov 2021 15:34:11 -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=MiKRALvhWmW8Or+0S/sRoVq0CehcMvWWtso+YlMRmbk=; b=38UhosVm5LKN+SW860A/PluHTJg7uXEgY3Q0JDEBzwZko7AnUsFcubVwn2BCH5AeEL hxLzBwGTz4ReRpGzE5TaTwNGjrT9+fZjYQdORZ9WkrVL1N+ezSefhiCU7STnLxcze5qH n/2WM8GnitcBuUguGfU9yX9hv00177+C8ZSvz4SUQUelzPdMSE33KNZBeqeUcEeRxJxg n9bH0ak1fjNi7xCE9OJzkmjMdsia1CvduUxnWC5QaLnNc0W8Ujj+18o9bsYQ2TGZ0r++ b2S+XGTPe/15RkP9WMAqyl/bgoHJX9YJ4Pock423zbC020P5ydeNcFNhZkH+Xzd5Gjm9 ssHg== X-Gm-Message-State: AOAM5337l8zAYOgIrhalQg+v+rvtNhKx1ku6ngCS2Uv4xUcLW+Dlu3Cy rRY4xz0PGcfeIhyPe9u1IYE= X-Google-Smtp-Source: ABdhPJz3oxVeXU0xcSNvSZVe3xxxxDhJJTR5HTFNMXXMu92G0rPu71fF0fJyTpetthUw3l7cxQQHoQ== X-Received: by 2002:a17:90b:4a50:: with SMTP id lb16mr2769427pjb.37.1638315251257; Tue, 30 Nov 2021 15:34:11 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:10 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Alexey Dobriyan , "James E.J. Bottomley" , Adrian Hunter , Avri Altman , Asutosh Das , Stanley Chu , Bean Huo , Can Guo , Yue Hu , Sergey Shtylyov , Srinivas Kandagatla , Vinayak Holikatti , James Bottomley , Namjae Jeon , Santosh Yaraganavi Subject: [PATCH v3 07/17] scsi: ufs: Fix race conditions related to driver data Date: Tue, 30 Nov 2021 15:33:14 -0800 Message-Id: <20211130233324.1402448-8-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The driver data pointer must be set before any callbacks are registered that use that pointer. Hence move the initialization of that pointer from after the ufshcd_init() call to inside ufshcd_init(). Fixes: 3b1d05807a9a ("[SCSI] ufs: Segregate PCI Specific Code") 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 d4996ada55b6..04a19b826837 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -9481,6 +9481,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"); From patchwork Tue Nov 30 23:33:15 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: 520135 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 9C94BC433EF for ; Tue, 30 Nov 2021 23:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237120AbhK3Xhg (ORCPT ); Tue, 30 Nov 2021 18:37:36 -0500 Received: from mail-pl1-f179.google.com ([209.85.214.179]:34540 "EHLO mail-pl1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232973AbhK3Xhg (ORCPT ); Tue, 30 Nov 2021 18:37:36 -0500 Received: by mail-pl1-f179.google.com with SMTP id y8so16209371plg.1 for ; Tue, 30 Nov 2021 15:34: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=eT49CTrfMRMjuYQ3To+zFxQOc/h8/decsQS961Sdj0c=; b=F8dy/i4H4IirlvoCALIJK+YjXTMARUX5a9dZ1G8W+WnIwXr5aOwDyFDgJZSxdg7CcI zc8SIWEQXHkHGWzhchgx7VJ1T+61t2+oOfk267MhPJM1GnCPXnZedPysBzJG5WSnNNZd fJbmlBMGvK7g+HGfxyQFg21ztU/Gw9QJhULFQzO8IWhs/PtN000A5LOtT5/4JI+K3Euu VlR4PvPcDcuVuk50/9ycwKjYdlU1rs31rUMa1P1f2+xL4POPdmEnvC+/3W4qEIlbfZh1 0MSLPtzsEr8ZFEEAAq8bFIDFYmaQom8/NcUTZEWl4+I7vnwQ0Mz1KxCRVzyZ05IAMqMN 6ubA== X-Gm-Message-State: AOAM5305S3OjeLJiQl6Imx9YSCg6TXO5III6oMv+Rkh2MUJR0TfgiQm0 4T0C3HirsjmzxQ3dyL+OOAw= X-Google-Smtp-Source: ABdhPJwscVy78eqanp+5h2FfaqKCQ9LlH7nwKJ/+ybRj3qyDoHbYvrtmdtKvLKJu86vZMdqWUN4abQ== X-Received: by 2002:a17:90a:bb03:: with SMTP id u3mr2752707pjr.85.1638315256306; Tue, 30 Nov 2021 15:34:16 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:15 -0800 (PST) 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 , Can Guo , Adrian Hunter , Stanley Chu , Asutosh Das Subject: [PATCH v3 08/17] scsi: ufs: Remove ufshcd_any_tag_in_use() Date: Tue, 30 Nov 2021 15:33:15 -0800 Message-Id: <20211130233324.1402448-9-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use hba->outstanding_reqs instead of ufshcd_any_tag_in_use(). This patch prepares for removal of the blk_mq_start_request() call from ufshcd_wait_for_dev_cmd(). blk_mq_tagset_busy_iter() only iterates over started requests. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 04a19b826837..974bf47e733c 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1352,25 +1352,6 @@ static int ufshcd_devfreq_target(struct device *dev, return ret; } -static bool ufshcd_is_busy(struct request *req, void *priv, bool reserved) -{ - int *busy = priv; - - WARN_ON_ONCE(reserved); - (*busy)++; - return false; -} - -/* Whether or not any tag is in use by a request that is in progress. */ -static bool ufshcd_any_tag_in_use(struct ufs_hba *hba) -{ - struct request_queue *q = hba->cmd_queue; - int busy = 0; - - blk_mq_tagset_busy_iter(q->tag_set, ufshcd_is_busy, &busy); - return busy; -} - static int ufshcd_devfreq_get_dev_status(struct device *dev, struct devfreq_dev_status *stat) { @@ -1769,7 +1750,7 @@ static void ufshcd_gate_work(struct work_struct *work) if (hba->clk_gating.active_reqs || hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL - || ufshcd_any_tag_in_use(hba) || hba->outstanding_tasks + || hba->outstanding_reqs || hba->outstanding_tasks || hba->active_uic_cmd || hba->uic_async_done) goto rel_lock; From patchwork Tue Nov 30 23:33:16 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: 518631 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 13F5AC433F5 for ; Tue, 30 Nov 2021 23:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241089AbhK3Xhm (ORCPT ); Tue, 30 Nov 2021 18:37:42 -0500 Received: from mail-pj1-f44.google.com ([209.85.216.44]:52978 "EHLO mail-pj1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232973AbhK3Xhl (ORCPT ); Tue, 30 Nov 2021 18:37:41 -0500 Received: by mail-pj1-f44.google.com with SMTP id h24so16541343pjq.2 for ; Tue, 30 Nov 2021 15:34:21 -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=FBFqasEVEbZC/f3NjejIS6eAMihsN/cQol/s0a+pFy0=; b=DA7tzpVGJOZOXii5x22SpYWU74AFaU5s9h89+btZDvzBNfOOOiXy4WCeh9uH4AaBuL mIqIfgWNJu8YG0romizbwnR/1/qAjxHC3YRkxrj74gvuz9oljioQVCMaZcYMT5FKUvk+ zc+LjM8WDrJ7uC8eUcDhm9kqXPwmydScAV+jFZKW1Oubp5ArPFHcJO1AXvJugGbK1LIZ s+hOnzG7meuRfBjYYgDnCx0YZxZ1lMsOqRvWeQvyleq2W980rjXuHO7pNAmWAkoOXx4G kZly9TIaOHOTTcdzJZ5Hq2yJeXob1oT2z0PQg3mLmYH00fbmyJdo8pFGgjklQh12G5yP Aw5w== X-Gm-Message-State: AOAM531xJ+FkZkTzkAPCfJcHMrFoTznBNrE5ddT4x2L3rpSHCA+LyWbI Aml6/i4gSxPnxuKdNs/WgtU= X-Google-Smtp-Source: ABdhPJwAhv7gjI1UeuhTW8NEDaVIhjgjlfOvl5I+HZx4Li/z/BvS3ERnsorwW7TBHZoOJUg1zTFr2A== X-Received: by 2002:a17:90b:1bc4:: with SMTP id oa4mr2687369pjb.179.1638315261306; Tue, 30 Nov 2021 15:34:21 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:20 -0800 (PST) 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 , Can Guo , Avri Altman , Adrian Hunter , Stanley Chu , Asutosh Das Subject: [PATCH v3 09/17] scsi: ufs: Rework ufshcd_change_queue_depth() Date: Tue, 30 Nov 2021 15:33:16 -0800 Message-Id: <20211130233324.1402448-10-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-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 974bf47e733c..2d0f59424b00 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4936,11 +4936,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 Tue Nov 30 23:33:17 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: 520134 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 AC085C433F5 for ; Tue, 30 Nov 2021 23:34:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241095AbhK3Xhu (ORCPT ); Tue, 30 Nov 2021 18:37:50 -0500 Received: from mail-pg1-f181.google.com ([209.85.215.181]:39566 "EHLO mail-pg1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232973AbhK3Xht (ORCPT ); Tue, 30 Nov 2021 18:37:49 -0500 Received: by mail-pg1-f181.google.com with SMTP id r5so21486521pgi.6 for ; Tue, 30 Nov 2021 15:34:30 -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=WtZRiMZiXejpaLTrbZn8XfgRNYsyVCWYUCazi6KKYBM=; b=XSarRX3Ai3x5qa5meInd74JygnoSf5knIbJryxtig8Zq7MhEbkTlJYQRTGgrvSBx2I +RfbMTFHJMNfmMBczQZpa9YtzVYc8vV7FdRL2rAySAmVEcPoxr5TBhqZwcbUFqTruXvc LRe9iogMHzuEKb+fQZ5akPwj6tzvMGNfFVrsCG7a1+aZTsiCsOSkDnzMETdYVHALIrNW NYEq0QbGDK9MS7fo78Mfw4IsJuzec2/1cII95R9jsgZjCApOJkcYN9ZqYYGY2LtV5gbC 3lw++JALM2N6PhoG9RHFBy8RXpxcH6JcBGsSDd/c6oF/7UbjhouDPKzIgMkhZULh/GJw SyXg== X-Gm-Message-State: AOAM5307CwAXm+vKBwWH7X2Dmxrg2LTkVrbnfQkFqKeR5UEOre7bNZi0 hCN/ShS8gxo7BYCEGiJC4Es= X-Google-Smtp-Source: ABdhPJxluhLseoBwqtUZPS/tm03gQMfYMuQahhtHJy7XhrWxCw++jOpkTlDk4ygSkLgkxmfUSmwNRw== X-Received: by 2002:a63:9:: with SMTP id 9mr1861652pga.91.1638315269600; Tue, 30 Nov 2021 15:34:29 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:29 -0800 (PST) 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 , Can Guo , Adrian Hunter , Stanley Chu , Asutosh Das , Keoseong Park Subject: [PATCH v3 10/17] scsi: ufs: Fix a deadlock in the error handler Date: Tue, 30 Nov 2021 15:33:17 -0800 Message-Id: <20211130233324.1402448-11-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-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 Signed-off-by: Bart Van Assche Reviewed-by: Adrian Hunter --- drivers/scsi/ufs/ufshcd.c | 53 +++++++++++---------------------------- drivers/scsi/ufs/ufshcd.h | 2 ++ 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 2d0f59424b00..da4714aaa850 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[] = { @@ -2170,6 +2171,7 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba) hba->nutrs = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS) + 1; hba->nutmrs = ((hba->capabilities & MASK_TASK_MANAGEMENT_REQUEST_SLOTS) >> 16) + 1; + hba->reserved_slot = hba->nutrs - 1; /* Read crypto capabilities */ err = ufshcd_hba_init_crypto_capabilities(hba); @@ -2912,30 +2914,15 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, enum dev_cmd_type cmd_type, int timeout) { - struct request_queue *q = hba->cmd_queue; DECLARE_COMPLETION_ONSTACK(wait); - struct request *req; + const u32 tag = hba->reserved_slot; struct ufshcd_lrb *lrbp; int err; - int tag; - down_read(&hba->clk_scaling_lock); + /* Protects use of hba->reserved_slot. */ + lockdep_assert_held(&hba->dev_cmd.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. - */ - req = blk_mq_alloc_request(q, REQ_OP_DRV_OUT, 0); - if (IS_ERR(req)) { - err = PTR_ERR(req); - goto out_unlock; - } - tag = req->tag; - WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); - /* Set the timeout such that the SCSI error handler is not activated. */ - req->timeout = msecs_to_jiffies(2 * timeout); - blk_mq_start_request(req); + down_read(&hba->clk_scaling_lock); lrbp = &hba->lrb[tag]; WARN_ON(lrbp->cmd); @@ -2953,8 +2940,6 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); out: - blk_mq_free_request(req); -out_unlock: up_read(&hba->clk_scaling_lock); return err; } @@ -6689,23 +6674,16 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, enum dev_cmd_type cmd_type, enum query_opcode desc_op) { - struct request_queue *q = hba->cmd_queue; DECLARE_COMPLETION_ONSTACK(wait); - struct request *req; + const u32 tag = hba->reserved_slot; struct ufshcd_lrb *lrbp; int err = 0; - int tag; u8 upiu_flags; - down_read(&hba->clk_scaling_lock); + /* Protects use of hba->reserved_slot. */ + lockdep_assert_held(&hba->dev_cmd.lock); - req = blk_mq_alloc_request(q, REQ_OP_DRV_OUT, 0); - if (IS_ERR(req)) { - err = PTR_ERR(req); - goto out_unlock; - } - tag = req->tag; - WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); + down_read(&hba->clk_scaling_lock); lrbp = &hba->lrb[tag]; WARN_ON(lrbp->cmd); @@ -6774,9 +6752,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); - blk_mq_free_request(req); - -out_unlock: up_read(&hba->clk_scaling_lock); return err; } @@ -9507,8 +9482,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; diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index ecc6c545a19d..c3c2792f309f 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -745,6 +745,7 @@ struct ufs_hba_monitor { * @capabilities: UFS Controller Capabilities * @nutrs: Transfer Request Queue depth supported by controller * @nutmrs: Task Management Queue depth supported by controller + * @reserved_slot: Used to submit device commands. Protected by @dev_cmd.lock. * @ufs_version: UFS Version to which controller complies * @vops: pointer to variant specific operations * @priv: pointer to variant specific private data @@ -836,6 +837,7 @@ struct ufs_hba { u32 capabilities; int nutrs; int nutmrs; + u32 reserved_slot; u32 ufs_version; const struct ufs_hba_variant_ops *vops; struct ufs_hba_variant_params *vps; From patchwork Tue Nov 30 23:33:18 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: 518630 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 26C87C433F5 for ; Tue, 30 Nov 2021 23:34:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241216AbhK3Xh5 (ORCPT ); Tue, 30 Nov 2021 18:37:57 -0500 Received: from mail-pj1-f50.google.com ([209.85.216.50]:40896 "EHLO mail-pj1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240977AbhK3Xhz (ORCPT ); Tue, 30 Nov 2021 18:37:55 -0500 Received: by mail-pj1-f50.google.com with SMTP id gf14-20020a17090ac7ce00b001a7a2a0b5c3so19500576pjb.5 for ; Tue, 30 Nov 2021 15:34:36 -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=lk9NkVJVVSBBrCi1eWz7MQANLjx7ZaJC7Rk/B06iL8o=; b=cLmKHVTZpGGsujO5GLSYCyCfAT2og5hJcEsp39xeraC0cJWWj9PIAPxe+aEo/h7shO qPqTHQcH05ApFeMynvIVKttsdF5zqRWX7cmVs46di6tq38Ba/hCuPqmcw3dnut59XE6d C+TT14E2ZBDPPf0u3K6SHrFUd2ockr/6fFodTsxaQZLAtDbRycxPDSvY2w3kQG8jXBxw RO8/bI67k22RBosuosUJA3AAa+YsQg0VNGANjnDAyddKupyBMRiV8aYerhMujqmydBOY J77tIBuk8phHaCpoboLS49NTCX0DQQnVSmsXeChMC2Qxi9oGdqPBNf3RpOAhSUgFKIn1 louQ== X-Gm-Message-State: AOAM533o3dE32kgxQ0lRQ/R/SeeoOL7P1/4OhYLlyBqEhybuVQrriZ1I bOyYcqoA9Hzs0q/YCwUNOcw+BVOZ8wk= X-Google-Smtp-Source: ABdhPJw1adiC17j/OXJIEfWAkA5DCFtaFZU5UQvo0Pya7eXpqBtc8XCQGaZ3u/vRZEFH1YjWc2Y3fA== X-Received: by 2002:a17:90b:380a:: with SMTP id mq10mr2684005pjb.61.1638315274673; Tue, 30 Nov 2021 15:34:34 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:34 -0800 (PST) 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 , Can Guo , Adrian Hunter , Stanley Chu , Asutosh Das Subject: [PATCH v3 11/17] scsi: ufs: Remove the 'update_scaling' local variable Date: Tue, 30 Nov 2021 15:33:18 -0800 Message-Id: <20211130233324.1402448-12-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch does not change any functionality but makes the next patch in this series easier to read. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index da4714aaa850..4e9755c060af 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -5225,7 +5225,6 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, struct scsi_cmnd *cmd; int result; int index; - bool update_scaling = false; for_each_set_bit(index, &completed_reqs, hba->nutrs) { lrbp = &hba->lrb[index]; @@ -5243,18 +5242,16 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, /* Do not touch lrbp after scsi done */ scsi_done(cmd); ufshcd_release(hba); - update_scaling = true; + ufshcd_clk_scaling_update_busy(hba); } else if (lrbp->command_type == UTP_CMD_TYPE_DEV_MANAGE || lrbp->command_type == UTP_CMD_TYPE_UFS_STORAGE) { if (hba->dev_cmd.complete) { ufshcd_add_command_trace(hba, index, UFS_DEV_COMP); complete(hba->dev_cmd.complete); - update_scaling = true; + ufshcd_clk_scaling_update_busy(hba); } } - if (update_scaling) - ufshcd_clk_scaling_update_busy(hba); } } From patchwork Tue Nov 30 23:33:19 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: 520133 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 3525DC433EF for ; Tue, 30 Nov 2021 23:34:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241264AbhK3XiB (ORCPT ); Tue, 30 Nov 2021 18:38:01 -0500 Received: from mail-pj1-f53.google.com ([209.85.216.53]:34462 "EHLO mail-pj1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240990AbhK3Xh7 (ORCPT ); Tue, 30 Nov 2021 18:37:59 -0500 Received: by mail-pj1-f53.google.com with SMTP id j5-20020a17090a318500b001a6c749e697so14760837pjb.1 for ; Tue, 30 Nov 2021 15:34:40 -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=vDeLtFp+3z7D62tVexY/RvJu1DgY2LTjCyBZ7zIvdqI=; b=ypsK3NiXrZuSrtWLdtRtqvZPwdxHZTFxUSSJq4yjEVH9NnezFEHJwr2SPkS5utYgCP 6pbovGOGQst3gGOxLKx2G/iExBW0tcJP4DTWfOztVcF5s/0jJTmAvqsj2OaepsRdtWiy bBVg/0aCVF5XLkH743TYMhTX781MX+n0Eizm9Sow4dJzIAKjqztmIQGhS5hyHQHY7cs2 bzGTXJROc82bhq+he6NRIwFIPznB8VhktT5zW9jfLn7lYsR/aSySaWDVcU6l9oxCbOHf 8TzUb+yn/DyC+xwXi6yjc9zp8NueTw1gh2xEsdOjHhI1Fa8TUuS+Sif5+UfidWzuilL0 Olwg== X-Gm-Message-State: AOAM530pGfmZM2jXIjNL1L84Zh1ulVURLqlrJnF5jRQpTN9QgSaLsu6g xHTq09cFCXT0MUrR/ZTVtCY= X-Google-Smtp-Source: ABdhPJxUgdJ4HywbujqMKvQJS/BSSoyKUF0O9MXHBRro2XkEbgmPYCFuM/uTNzx5myh7keEood3m+A== X-Received: by 2002:a17:90a:c58d:: with SMTP id l13mr2715902pjt.189.1638315279882; Tue, 30 Nov 2021 15:34:39 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:39 -0800 (PST) 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 , Can Guo , Adrian Hunter , Stanley Chu , Asutosh Das Subject: [PATCH v3 12/17] scsi: ufs: Introduce ufshcd_release_scsi_cmd() Date: Tue, 30 Nov 2021 15:33:19 -0800 Message-Id: <20211130233324.1402448-13-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The only functional change in this patch is that scsi_done() is now called after ufshcd_release() and ufshcd_clk_scaling_update_busy() instead of before. The next patch in this series will introduce a call to ufshcd_release_scsi_cmd() in the abort handler. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 4e9755c060af..8703e4a70256 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -5213,6 +5213,18 @@ static irqreturn_t ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status) return retval; } +/* Release the resources allocated for processing a SCSI command. */ +static void ufshcd_release_scsi_cmd(struct ufs_hba *hba, + struct ufshcd_lrb *lrbp) +{ + struct scsi_cmnd *cmd = lrbp->cmd; + + scsi_dma_unmap(cmd); + lrbp->cmd = NULL; /* Mark the command as completed. */ + ufshcd_release(hba); + ufshcd_clk_scaling_update_busy(hba); +} + /** * __ufshcd_transfer_req_compl - handle SCSI and query command completion * @hba: per adapter instance @@ -5223,7 +5235,6 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, { struct ufshcd_lrb *lrbp; struct scsi_cmnd *cmd; - int result; int index; for_each_set_bit(index, &completed_reqs, hba->nutrs) { @@ -5234,15 +5245,10 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, if (unlikely(ufshcd_should_inform_monitor(hba, lrbp))) ufshcd_update_monitor(hba, lrbp); ufshcd_add_command_trace(hba, index, UFS_CMD_COMP); - result = ufshcd_transfer_rsp_status(hba, lrbp); - scsi_dma_unmap(cmd); - cmd->result = result; - /* Mark completed command as NULL in LRB */ - lrbp->cmd = NULL; + cmd->result = ufshcd_transfer_rsp_status(hba, lrbp); + ufshcd_release_scsi_cmd(hba, lrbp); /* Do not touch lrbp after scsi done */ scsi_done(cmd); - ufshcd_release(hba); - ufshcd_clk_scaling_update_busy(hba); } else if (lrbp->command_type == UTP_CMD_TYPE_DEV_MANAGE || lrbp->command_type == UTP_CMD_TYPE_UFS_STORAGE) { if (hba->dev_cmd.complete) { From patchwork Tue Nov 30 23:33:20 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: 518629 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 7C7A9C433F5 for ; Tue, 30 Nov 2021 23:34:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345034AbhK3XiJ (ORCPT ); Tue, 30 Nov 2021 18:38:09 -0500 Received: from mail-pg1-f176.google.com ([209.85.215.176]:40958 "EHLO mail-pg1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241396AbhK3XiF (ORCPT ); Tue, 30 Nov 2021 18:38:05 -0500 Received: by mail-pg1-f176.google.com with SMTP id l190so21542877pge.7 for ; Tue, 30 Nov 2021 15:34:45 -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=wfQuYA0v5AGpeWacISPDNlA0H6jLiK+GpLahmP0hicc=; b=mR1oJO2DnT2yqsMJHxfsf1KzpsuBRPbZByYHM7afY6ZzcdGJtEyK97PsFfeORQcezo llPk8vSgom7sDuknNTTv5EmyDXu7Bj0D7X2g0EyPsBsVii7XOZ/pK7dcjS8nfCrfuvO4 uxk9JaJdWJ3vrWlzHvgKzPWqchFBtgvwMyIgsXrNqoiYLOqL3HLN0ElIkgjMiL3cUqd1 OubnMBCoflQmqa1AAynWsuQc04KAna+CMnvKmsCm7zCej2JQFGjSKh/0HOISuOXNKHpN ihn4UI3DAXaDt9/TPdSW+fwF5ZYdECGCPiPDflovs3VLj3iDqEzDUDd8ON4ngf+A8w7O 5EIQ== X-Gm-Message-State: AOAM531njAYkoPNBhWIiEsJYSbA4ZOz2j6fwEVxvkSsz5bmC77BQjaTH ihZg9qoT21OvbllBpekMJ/0= X-Google-Smtp-Source: ABdhPJzwub6gcqu76uzUEJnqMYDcyKBOaJA98G1XtZSB0yRrVQjIxJ57XPN1wn8yoqakQZlxUIJnsg== X-Received: by 2002:a63:ef58:: with SMTP id c24mr1929421pgk.94.1638315284965; Tue, 30 Nov 2021 15:34:44 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:44 -0800 (PST) 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 , Can Guo , Avri Altman , Adrian Hunter , Stanley Chu , Asutosh Das , Santosh Yaraganavi , Vishak G , Vinayak Holikatti , Namjae Jeon Subject: [PATCH v3 13/17] scsi: ufs: Improve SCSI abort handling further Date: Tue, 30 Nov 2021 15:33:20 -0800 Message-Id: <20211130233324.1402448-14-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Release resources when aborting a command. Make sure that aborted commands are completed once by clearing the corresponding tag bit from hba->outstanding_reqs. This patch is an improved version of commit 3ff1f6b6ba6f ("scsi: ufs: core: Improve SCSI abort handling"). Fixes: 7a3e97b0dc4b ("[SCSI] ufshcd: UFS Host controller driver") Signed-off-by: Bart Van Assche Reviewed-by: Adrian Hunter --- drivers/scsi/ufs/ufshcd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 8703e4a70256..1a4f2ebf955e 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6984,6 +6984,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) struct ufshcd_lrb *lrbp = &hba->lrb[tag]; unsigned long flags; int err = FAILED; + bool outstanding; u32 reg; WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); @@ -7061,6 +7062,17 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) goto release; } + /* + * Clear the corresponding bit from outstanding_reqs since the command + * has been aborted successfully. + */ + spin_lock_irqsave(&hba->outstanding_lock, flags); + outstanding = __test_and_clear_bit(tag, &hba->outstanding_reqs); + spin_unlock_irqrestore(&hba->outstanding_lock, flags); + + if (outstanding) + ufshcd_release_scsi_cmd(hba, lrbp); + err = SUCCESS; release: From patchwork Tue Nov 30 23:33:21 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: 520132 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 953B8C433EF for ; Tue, 30 Nov 2021 23:34:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240512AbhK3XiM (ORCPT ); Tue, 30 Nov 2021 18:38:12 -0500 Received: from mail-pf1-f172.google.com ([209.85.210.172]:43544 "EHLO mail-pf1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241126AbhK3XiK (ORCPT ); Tue, 30 Nov 2021 18:38:10 -0500 Received: by mail-pf1-f172.google.com with SMTP id n85so22242928pfd.10 for ; Tue, 30 Nov 2021 15:34:50 -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=qr0lteHE2MHHWadRe8v5OkBA+Kt4SnjvEPdPF2o6ReY=; b=y7rrYt85cnnv8K3d7LAjIabSe0VcuULD/vzwx6ByQizApgkuFJ6Msav+cZUgw35GFS QsNrsVjyKqWSF2WSx58iuYjg/NoK5wz/rF0fs0cPNnamF2jkkOvBGWGdltL3tgq9RXKg bK763TWdqBhTtu3YlPKASXhvoftkebfP1KmThRmB2aikPGUJIJPq4oHcJqt80O5Y4e5J JrslJMmivgVvWbzhz1U1YjKzNxKIUc2sqTphK2vZAmqwd2vs5XTrOozBxtjuADUBv+tJ 5MYn/fixQUBT/9dsepxClrtJ6jtZLwuEcqQ/vTM866r6ud3wBhVcj9153IWUSc3z1xng izAg== X-Gm-Message-State: AOAM532RozMAoDpThrpx3KZ7H2TKy9mlFGZ+dnXRF2QxijKM9tVU09N7 CBespsRLfby+pUXs/1k2olk= X-Google-Smtp-Source: ABdhPJzQeT9WoAnm93cDSeUg0dmSVBUWTCFS6HYD/wt7cNfMYpSnndb/CT7+0hfYZP5M0Kw8l1PrLQ== X-Received: by 2002:aa7:9586:0:b0:4a2:78b4:a402 with SMTP id z6-20020aa79586000000b004a278b4a402mr2534069pfj.21.1638315290000; Tue, 30 Nov 2021 15:34:50 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:49 -0800 (PST) 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 , Can Guo , Avri Altman , Adrian Hunter , Stanley Chu , Asutosh Das Subject: [PATCH v3 14/17] scsi: ufs: Fix a kernel crash during shutdown Date: Tue, 30 Nov 2021 15:33:21 -0800 Message-Id: <20211130233324.1402448-15-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Fix the following kernel crash: Unable to handle kernel paging request at virtual address ffffffc91e735000 Call trace: __queue_work+0x26c/0x624 queue_work_on+0x6c/0xf0 ufshcd_hold+0x12c/0x210 __ufshcd_wl_suspend+0xc0/0x400 ufshcd_wl_shutdown+0xb8/0xcc device_shutdown+0x184/0x224 kernel_restart+0x4c/0x124 __arm64_sys_reboot+0x194/0x264 el0_svc_common+0xc8/0x1d4 do_el0_svc+0x30/0x8c el0_svc+0x20/0x30 el0_sync_handler+0x84/0xe4 el0_sync+0x1bc/0x1c0 Fix this crash by ungating the clock before destroying the work queue on which clock gating work is queued. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 1a4f2ebf955e..074ea9ae54e0 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1648,7 +1648,8 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) bool flush_result; unsigned long flags; - if (!ufshcd_is_clkgating_allowed(hba)) + if (!ufshcd_is_clkgating_allowed(hba) || + !hba->clk_gating.is_initialized) goto out; spin_lock_irqsave(hba->host->host_lock, flags); hba->clk_gating.active_reqs++; @@ -1808,7 +1809,7 @@ static void __ufshcd_release(struct ufs_hba *hba) if (hba->clk_gating.active_reqs || hba->clk_gating.is_suspended || hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL || - hba->outstanding_tasks || + hba->outstanding_tasks || !hba->clk_gating.is_initialized || hba->active_uic_cmd || hba->uic_async_done || hba->clk_gating.state == CLKS_OFF) return; @@ -1943,11 +1944,15 @@ static void ufshcd_exit_clk_gating(struct ufs_hba *hba) { if (!hba->clk_gating.is_initialized) return; + ufshcd_remove_clk_gating_sysfs(hba); - cancel_work_sync(&hba->clk_gating.ungate_work); - cancel_delayed_work_sync(&hba->clk_gating.gate_work); - destroy_workqueue(hba->clk_gating.clk_gating_workq); + + /* Ungate the clock if necessary. */ + ufshcd_hold(hba, false); hba->clk_gating.is_initialized = false; + ufshcd_release(hba); + + destroy_workqueue(hba->clk_gating.clk_gating_workq); } /* Must be called with host lock acquired */ From patchwork Tue Nov 30 23:33:22 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: 518628 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 B3895C433EF for ; Tue, 30 Nov 2021 23:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241111AbhK3XiQ (ORCPT ); Tue, 30 Nov 2021 18:38:16 -0500 Received: from mail-pg1-f178.google.com ([209.85.215.178]:39594 "EHLO mail-pg1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240977AbhK3XiP (ORCPT ); Tue, 30 Nov 2021 18:38:15 -0500 Received: by mail-pg1-f178.google.com with SMTP id r5so21487334pgi.6 for ; Tue, 30 Nov 2021 15:34:55 -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=73edNt+G3LODt3CyOK2nQJJ1/G55cmNYSyUMKsGK9xo=; b=zeQq6CjaAW6E1FhMov9ziSovAKy0com4lbHWIrBIwnuukNiDOFQJq2W/5nPSADhACS oOEpMLI9NCBUToa61JyE9vTiCzRHy41fWMSnB4xr+hGqMmIBqf99e0cRpz8C5ZUIZtIV 30xwFvgo9Na9RqcUck+9jIuKABV/XQaMAY9ux/dAngPU9EfMuLYw0sAjD5CKXXRlZVki JiW2etW5/eqIyQ0XwgQVYlcucHlilsmhkQepoWr8mViNeNXN9t8qM7UTGqZc+5gc12qT MUGoSZjLo+Gr861NfcLd4GVSmpOFF6lW4GguWbE5kq5LxuXil30fs9yBRo3N+T4Ra6vS XTCw== X-Gm-Message-State: AOAM532VirRxU/piiWq5ulWzj8+pzz5Ss47wrPn3DazALfetHTU7xU+E rtfgqLTwIPu25J+tTtpClUIrSm8ch5I= X-Google-Smtp-Source: ABdhPJxmkSuGW+aGybYktDPDNYw57ZslOKA/bNMxInNHsuRkcAIfIAzCIakS9vA493wLQn0cvQCtKQ== X-Received: by 2002:a63:bf45:: with SMTP id i5mr1919152pgo.161.1638315294952; Tue, 30 Nov 2021 15:34:54 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:34:54 -0800 (PST) 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 , Can Guo , Avri Altman , Adrian Hunter , Stanley Chu , Asutosh Das Subject: [PATCH v3 15/17] scsi: ufs: Stop using the clock scaling lock in the error handler Date: Tue, 30 Nov 2021 15:33:22 -0800 Message-Id: <20211130233324.1402448-16-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-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 Reviewed-by: Adrian Hunter --- 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 074ea9ae54e0..c4cf5c4b4893 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2684,6 +2684,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; @@ -2762,7 +2768,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()) { @@ -5951,8 +5960,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 Tue Nov 30 23:33:23 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: 520131 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 D977DC433EF for ; Tue, 30 Nov 2021 23:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345217AbhK3Xi0 (ORCPT ); Tue, 30 Nov 2021 18:38:26 -0500 Received: from mail-pf1-f177.google.com ([209.85.210.177]:39834 "EHLO mail-pf1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345130AbhK3XiX (ORCPT ); Tue, 30 Nov 2021 18:38:23 -0500 Received: by mail-pf1-f177.google.com with SMTP id i12so22269897pfd.6 for ; Tue, 30 Nov 2021 15:35:03 -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=CnZqmy35APeBK43FDLtAn48H00//bAqCefvaRW8D3WU=; b=XQMvtC3GC/52bW3nY8Q7Xqdu9qymJtI4w+uYdQO3szE3x6StH0m3UTm2vrR7Rs8Hk4 4nRn0KC6rF7MmI6i9odLTXp5tMgKU7U/Ymfkypzz8Sx1zJQBjh5slYX5o0j9tn2Bf3hM 1s+5ApmAa0qKkZaeP1bAGIKJqKT+kFBZmtP1c5hL9po6cGksbsewk+yJ8SvdHT5JjxMB Eaofn8+e9tm7aNEAva0osTUBCjjFhohKb3aH/I0/7/4uXaQV32x53FCIh6kn5ccDr4Dw WwOfVCnDamF36VPD8MZbs/j9LuzjmcOJFX5FLQR7Vg04XwG75HlBUrCoEx4N8mb1vujk HdkQ== X-Gm-Message-State: AOAM532raD52EqHZ0ZcZixXmpGd1+VO0f6qhS+MkCwxDpnRqQJN3qt1Z vgpXpx6v1nL4Vaz+/LIJgYuAPAXRGec= X-Google-Smtp-Source: ABdhPJwIdqafhnckBJbw/zfEo2ssqd/JzpZuXProVRI/dIMO0MZGvMGpMnyqULpL9n0ImJqeErmlDg== X-Received: by 2002:a63:24c4:: with SMTP id k187mr1877766pgk.554.1638315303274; Tue, 30 Nov 2021 15:35:03 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:35:02 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Asutosh Das , "James E.J. Bottomley" , Bean Huo , Avri Altman , Can Guo , Adrian Hunter , Stanley Chu , Keoseong Park Subject: [PATCH v3 16/17] scsi: ufs: Optimize the command queueing code Date: Tue, 30 Nov 2021 15:33:23 -0800 Message-Id: <20211130233324.1402448-17-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-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. Instead, use synchronize_rcu_expedited() to wait for ongoing ufshcd_queuecommand() calls. Cc: Asutosh Das (asd) Signed-off-by: Bart Van Assche Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 12 +++++++----- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index c4cf5c4b4893..3e4c62c6f9d2 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1196,6 +1196,13 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) /* let's not get into low power until clock scaling is completed */ ufshcd_hold(hba, false); + /* + * Wait for ongoing ufshcd_queuecommand() calls. Calling + * synchronize_rcu_expedited() instead of synchronize_rcu() reduces the + * waiting time from milliseconds to microseconds. + */ + synchronize_rcu_expedited(); + out: return ret; } @@ -2681,9 +2688,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. @@ -2772,8 +2776,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 c3c2792f309f..411c6015bbfe 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -779,6 +779,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 Tue Nov 30 23:33:24 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: 518627 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 115F0C433EF for ; Tue, 30 Nov 2021 23:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345280AbhK3Xif (ORCPT ); Tue, 30 Nov 2021 18:38:35 -0500 Received: from mail-pl1-f179.google.com ([209.85.214.179]:43617 "EHLO mail-pl1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240977AbhK3Xi2 (ORCPT ); Tue, 30 Nov 2021 18:38:28 -0500 Received: by mail-pl1-f179.google.com with SMTP id m24so16195915pls.10 for ; Tue, 30 Nov 2021 15:35:09 -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=LOwNxUGaXRXYkzQoj4hoWe0WWsfF8s4evhhcNvlzf3k=; b=ibnEuFmYScAumJ4MwSBcRUua8AFf1k0bmlW+HHWxKFmr1Knh5n4xgJXVhvUc79oHzK joOGYWpjuPA5kUKLASxouw7dRLclFz/nDx50szRZHSyN3dxGUlexei+9Oyajw2RADwdP X7w8gqBLxr3Fz1hmTJnvQRDM8rAGbDkuDHLo9FkYyWRCb6o3Mvv9pVLwBPgDU2jptbNa KKar/36rWZccGr9KLo70d3lvSsAkz6C7PgaUHXRci7DWwYNYC4BEClmWKsbhogM3zd4x ICJxX4O/nTBkn06OfMJJY0eWyFRbMigxK2/pTKG7Q0dDAmM0SjU7YfjwMuYwmDzYYb9+ CvLQ== X-Gm-Message-State: AOAM530pWMshC5c4dC1kQQaq1rkpQMlA/hu1v2Ka9FxJgpr8PL7vnJ/t qosnqOtExoWasrCK/Lzc9Ug= X-Google-Smtp-Source: ABdhPJzKG+xNHSa3QCLsZMXcJMGeufhO2YRZOOVsOMzabhaYAoITGQa3BjRmmqGPnuwXm/fFijBvow== X-Received: by 2002:a17:902:d50e:b0:142:1b2a:144 with SMTP id b14-20020a170902d50e00b001421b2a0144mr2651712plg.51.1638315308587; Tue, 30 Nov 2021 15:35:08 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ef1f:f086:d1ba:8190]) by smtp.gmail.com with ESMTPSA id mu4sm4127187pjb.8.2021.11.30.15.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 15:35:07 -0800 (PST) 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 , Can Guo , Avri Altman , Adrian Hunter , Stanley Chu , Asutosh Das Subject: [PATCH v3 17/17] scsi: ufs: Implement polling support Date: Tue, 30 Nov 2021 15:33:24 -0800 Message-Id: <20211130233324.1402448-18-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130233324.1402448-1-bvanassche@acm.org> References: <20211130233324.1402448-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The time spent in io_schedule() and also the interrupt latency are significant when submitting direct I/O to a UFS device. Hence this patch that implements polling support. User space software can enable polling by passing the RWF_HIPRI flag to the preadv2() system call or the IORING_SETUP_IOPOLL flag to the io_uring interface. Although the block layer supports to partition the tag space for interrupt-based completions (HCTX_TYPE_DEFAULT) purposes and polling (HCTX_TYPE_POLL), the choice has been made to use the same hardware queue for both hctx types because partitioning the tag space would negatively affect performance. On my test setup this patch increases IOPS from 2736 to 22000 (8x) for the following test: for hipri in 0 1; do fio --ioengine=io_uring --iodepth=1 --rw=randread \ --runtime=60 --time_based=1 --direct=1 --name=qd1 \ --filename=/dev/block/sda --ioscheduler=none --gtod_reduce=1 \ --norandommap --hipri=$hipri done Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 85 ++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 3e4c62c6f9d2..5b3efc880246 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2651,6 +2651,36 @@ static inline bool is_device_wlun(struct scsi_device *sdev) ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_UFS_DEVICE_WLUN); } +/* + * Associate the UFS controller queue with the default and poll HCTX types. + * Initialize the mq_map[] arrays. + */ +static int ufshcd_map_queues(struct Scsi_Host *shost) +{ + int i, ret; + + for (i = 0; i < shost->nr_maps; i++) { + struct blk_mq_queue_map *map = &shost->tag_set.map[i]; + + switch (i) { + case HCTX_TYPE_DEFAULT: + case HCTX_TYPE_POLL: + map->nr_queues = 1; + break; + case HCTX_TYPE_READ: + map->nr_queues = 0; + break; + default: + WARN_ON_ONCE(true); + } + map->queue_offset = 0; + ret = blk_mq_map_queues(map); + WARN_ON_ONCE(ret); + } + + return 0; +} + static void ufshcd_init_lrb(struct ufs_hba *hba, struct ufshcd_lrb *lrb, int i) { struct utp_transfer_cmd_desc *cmd_descp = hba->ucdl_base_addr; @@ -2686,7 +2716,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) struct ufshcd_lrb *lrbp; int err = 0; - WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); + WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag); /* * Allows the UFS error handler to wait for prior ufshcd_queuecommand() @@ -5277,6 +5307,31 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, } } +/* + * Returns > 0 if one or more commands have been completed or 0 if no + * requests have been completed. + */ +static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) +{ + struct ufs_hba *hba = shost_priv(shost); + unsigned long completed_reqs, flags; + u32 tr_doorbell; + + spin_lock_irqsave(&hba->outstanding_lock, flags); + tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); + completed_reqs = ~tr_doorbell & hba->outstanding_reqs; + WARN_ONCE(completed_reqs & ~hba->outstanding_reqs, + "completed: %#lx; outstanding: %#lx\n", completed_reqs, + hba->outstanding_reqs); + hba->outstanding_reqs &= ~completed_reqs; + spin_unlock_irqrestore(&hba->outstanding_lock, flags); + + if (completed_reqs) + __ufshcd_transfer_req_compl(hba, completed_reqs); + + return completed_reqs; +} + /** * ufshcd_transfer_req_compl - handle SCSI and query command completion * @hba: per adapter instance @@ -5287,9 +5342,6 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, */ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba) { - unsigned long completed_reqs, flags; - u32 tr_doorbell; - /* Resetting interrupt aggregation counters first and reading the * DOOR_BELL afterward allows us to handle all the completed requests. * In order to prevent other interrupts starvation the DB is read once @@ -5304,21 +5356,13 @@ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba) if (ufs_fail_completion()) return IRQ_HANDLED; - spin_lock_irqsave(&hba->outstanding_lock, flags); - tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); - completed_reqs = ~tr_doorbell & hba->outstanding_reqs; - WARN_ONCE(completed_reqs & ~hba->outstanding_reqs, - "completed: %#lx; outstanding: %#lx\n", completed_reqs, - hba->outstanding_reqs); - hba->outstanding_reqs &= ~completed_reqs; - spin_unlock_irqrestore(&hba->outstanding_lock, flags); + /* + * Ignore the ufshcd_poll() return value and return IRQ_HANDLED since we + * do not want polling to trigger spurious interrupt complaints. + */ + ufshcd_poll(hba->host, 0); - if (completed_reqs) { - __ufshcd_transfer_req_compl(hba, completed_reqs); - return IRQ_HANDLED; - } else { - return IRQ_NONE; - } + return IRQ_HANDLED; } int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask) @@ -6570,6 +6614,8 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba, spin_lock_irqsave(host->host_lock, flags); task_tag = req->tag; + WARN_ONCE(task_tag < 0 || task_tag >= hba->nutmrs, "Invalid tag %d\n", + task_tag); hba->tmf_rqs[req->tag] = req; treq->upiu_req.req_header.dword_0 |= cpu_to_be32(task_tag); @@ -8133,7 +8179,9 @@ static struct scsi_host_template ufshcd_driver_template = { .module = THIS_MODULE, .name = UFSHCD, .proc_name = UFSHCD, + .map_queues = ufshcd_map_queues, .queuecommand = ufshcd_queuecommand, + .mq_poll = ufshcd_poll, .slave_alloc = ufshcd_slave_alloc, .slave_configure = ufshcd_slave_configure, .slave_destroy = ufshcd_slave_destroy, @@ -9422,6 +9470,7 @@ int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle) err = -ENOMEM; goto out_error; } + host->nr_maps = HCTX_TYPE_POLL + 1; hba = shost_priv(host); hba->host = host; hba->dev = dev;