From patchwork Fri Apr 12 00:02:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 788928 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BF6015B7 for ; Fri, 12 Apr 2024 00:03:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712880184; cv=none; b=JNKNEsQXAkVtRmI1vvmNKUwZUa7CUzcqEsTlRVvv8KcytAnAAqUVM5/KDSsYsJix2QfmFQTs2VfkhHISb+atgOvm04t3NFdHJxB5R2pvQ2m8aq0QuaBpVog6NXNv+eJsrMXmUYBhTyWEhpnqG8SP0Of08wPZlpt6Yjp6o8Mowb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712880184; c=relaxed/simple; bh=T9WrfpuBDHAe4xeZm3YN8pMCpcrsE0CX5iaqAirKMB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ClHUhNE1KCJec1pX5RMTlaY/d55ihKLGELi2vFLY6MTBT6HOaOUlVPp4SftjcsTIh2niG1zQloCyOiz23l+nn/Yl+LEJr07jWZ64t3sCO4pLgzBQb31xFGfuzvqOJQXz46fClqooiuVMk6amVEXQ+yKZeGZbI9h+H8BHMivcDjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=QVDJL7O1; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="QVDJL7O1" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VFxbV301gz6Cnk8y; Fri, 12 Apr 2024 00:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1712880178; x=1715472179; bh=0gyQs VhGa672wbZSWf6EJ1bspdIdFZwvR0VKtj2LVjM=; b=QVDJL7O16K5+o0E93kU/3 ovnCsBamBlHobQf+31lIAx0L+IhGhvOVRH6jNoMNZfnaV+5YFfbMk5PuNM6B1s3u 5am5nYbRZZzqRGVNTO85ZLptngCToegzQjFyhMrBHD4oTIIGI4+4yxFD92/mrvwI vgKPi8tptwKsrK9l38MCi+enjKfzzDs2UE9D4Ax952lPW4826rYCQs/DwJr1Kmrb emaL6s7Sv6frSsjlHQtBPiF8p7IfYckV6M+pl0Y2XEKbqVR8+IHx+lmwJe52tHqS UPxuxOagjd0nDfTL6qNvnQ4nbsX383YEy2Xrc/09HWaDs5qV+D8XeA7myTCCHu04 w== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id L5fT2N8GLn8i; Fri, 12 Apr 2024 00:02:58 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VFxbN1j6Zz6Cnk8m; Fri, 12 Apr 2024 00:02:56 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Stanley Jhu , Can Guo , "Bao D. Nguyen" , Keoseong Park , Po-Wen Kao , Avri Altman , zhanghui Subject: [PATCH 1/4] scsi: ufs: Declare ufshcd_mcq_poll_cqe_lock() once Date: Thu, 11 Apr 2024 17:02:21 -0700 Message-ID: <20240412000246.1167600-2-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240412000246.1167600-1-bvanassche@acm.org> References: <20240412000246.1167600-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ufshcd_mcq_poll_cqe_lock() is declared in include/ufs/ufshcd.h and also in drivers/ufs/core/ufshcd-priv.h. Remove the declaration from the latter file. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd-priv.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index a1add22205db..fb4457a84d11 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -72,8 +72,6 @@ u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i); void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i); struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba, struct request *req); -unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, - struct ufs_hw_queue *hwq); void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, struct ufs_hw_queue *hwq); bool ufshcd_cmd_inflight(struct scsi_cmnd *cmd); From patchwork Fri Apr 12 00:02:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 788192 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDCD428E7 for ; Fri, 12 Apr 2024 00:03:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712880189; cv=none; b=DpqDCOPhpPRfhCN2zEdUrrvHW721GsLKzeJaIjOGLxdhUWA+hkX30ab8QiLh2ASBD9tLZ7D8v5cgGXpx4AcaUfdRRSH13w46+RzeXoFj0vOWU9jqcS57hPoAZt/BVnu6rs7CNVwxy5cTxbMxhnGYJgSJb9P1lwRsV4cBwKGgQ3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712880189; c=relaxed/simple; bh=tVSFqs4M+dZdosEXmcx7d0wioApvxbkm4QJMEGyKg7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DofrCZA2w3PC6wb7ON5Rfnl5OTXZuEoVHAPojuOP5GM6rT0ZXwPecQH1Fnbl29s9RmB+bSKhs4rrobS8a5XJs4rCXbb9YDSbJCcAMIK8d11/Lf5G5Bo9f9MLjQKppN/ie2ROkhgiSas24ZtoX1ApqwQxplO66/jZwZOZQk0LBU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=dq4pPuMw; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="dq4pPuMw" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VFxbb4JRcz6Cnk8m; Fri, 12 Apr 2024 00:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1712880183; x=1715472184; bh=pVq15 uAKoGgM8Aqrh+JwHv5Y1sBgqhp+mELSsza3CB8=; b=dq4pPuMwjllyfFH+bdV9b HIlTq/pxPwKMZk4NNic2hgCI7A8otI1IuXsx48F7+YLCixSWndHiGpjLue00SKBr qM9mF3O9Qk336Ef/MZI79kjD1nOcTrjD0hW3mwtnGmvmg5u8S8s8jeGtjHmRzSgp jelmdYBBllqmVdNHpFHKZWkvTRCwz/8iz1EZRgyrPh3rzfdamTLiiVuYIHF/4qEt juTU7T9o1GVFKosOrK3urO+zHn2OHTNAuveGZz34PEnoMT6hxNkw+6XWYXsXEj2T N8vtoqyzZLa6qxRHjBDuedNnTltHvKeSTTZXxThZmtpPfwUn3ibFAro70u9EYGEQ g== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id XO5xLE3P75XW; Fri, 12 Apr 2024 00:03:03 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VFxbT6pVSz6Cnk8t; Fri, 12 Apr 2024 00:03:01 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Stanley Jhu , Avri Altman , Can Guo , Peter Wang , "Bao D. Nguyen" , Bean Huo , Manivannan Sadhasivam Subject: [PATCH 2/4] scsi: ufs: Make ufshcd_poll() complain about unsupported arguments Date: Thu, 11 Apr 2024 17:02:22 -0700 Message-ID: <20240412000246.1167600-3-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240412000246.1167600-1-bvanassche@acm.org> References: <20240412000246.1167600-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The ufshcd_poll() implementation does not support queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT in MCQ mode. Hence complain if queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT in MCQ mode. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 62c8575f2c67..66198eee51b0 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5617,6 +5617,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) struct ufs_hw_queue *hwq; if (is_mcq_enabled(hba)) { + WARN_ON_ONCE(queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT); hwq = &hba->uhq[queue_num]; return ufshcd_mcq_poll_cqe_lock(hba, hwq); From patchwork Fri Apr 12 00:02:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 788191 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9EA66AA7 for ; Fri, 12 Apr 2024 00:03:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712880226; cv=none; b=Zn+5qG7ZaknsTxgkuKa6h8a0pQlsEL7Lsd57plrpQvBCxhFtGz1bUtweAsRyens19VIQGsiFjWaMigOYpq7ycr0deJgvQY8kVO0BRyS6ZpIT8xxLplHMsXIzO4t54yTiaZjJyXEVRzZeefoqtDP8faKVViDmmK2uJJeS5qOHkQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712880226; c=relaxed/simple; bh=eQ/qhs1ik29keoE15NCTXV32HbfcEnrHkpRhCTgMh1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KKV7AXlAOOV4LquTEYGUIvozxKmTXI+oIOSiMBxmiU0HjqtbAcvgbUEBn9qSbseqWrolRsIUWfQ+Nz4FHHRa64hCjBdgvO6psJWvhJN6vBBTuvMfNnrMaeHiZmrPbsoWkF2YeVqxvOdzN2p9lB9wDG/UzplKxHVzq/tMd1zm1RA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=B42RdYrm; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="B42RdYrm" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VFxcJ2t7Rz6Cnk8t; Fri, 12 Apr 2024 00:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1712880199; x=1715472200; bh=3zKPl niePqLPgrhgP09Zb8NAsJ/pSjX7dV9ryrPihLI=; b=B42RdYrmJrKFXRHr25X3/ FTX1MBhYczYQ19GfG35ZBOZocUqnrvl9/P0PdSpSyNUbY/chtEj4Bek7Yb7Yut9R 9QMGR6B3ylBXRYMLy3OQZ1YdNIiEoIz+4VZwvMUdpSTMGCALXW0PJMviSheNmlqd LOWp97C/Jw7SCuOVIu/+CZqEcbRLCiWKHo2uTURWZYaYASqNDIb+B4e4ev7lZr77 VMtOmDZvyFkGdYn45o+texT17ImeXtCQIjhYh2aYt9MkWsLw4dHlU3Oaz88fz5xB fTlU3I9wM18o+7RzdtkQBMrzJCMNJ6QHsrXDssD71NpEcyQBcloDiDWsaNHhilIN g== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 8Cz9c1E4F2P9; Fri, 12 Apr 2024 00:03:19 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VFxbm2cLVz6Cnk8m; Fri, 12 Apr 2024 00:03:16 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Manivannan Sadhasivam , Bjorn Andersson , Konrad Dybcio , Stanley Jhu , Po-Wen Kao , Can Guo , "Bao D. Nguyen" , ChanWoo Lee , Yang Li , zhanghui , Keoseong Park , Avri Altman , Peter Wang , Bean Huo , Maramaina Naresh , Akinobu Mita Subject: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed Date: Thu, 11 Apr 2024 17:02:23 -0700 Message-ID: <20240412000246.1167600-4-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240412000246.1167600-1-bvanassche@acm.org> References: <20240412000246.1167600-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Prepare for introducing a new __ufshcd_poll() caller that will need to know whether or not a specific command has been completed. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufs-mcq.c | 23 +++++++++++++------- drivers/ufs/core/ufshcd-priv.h | 4 ++-- drivers/ufs/core/ufshcd.c | 39 +++++++++++++++++++++++----------- drivers/ufs/host/ufs-qcom.c | 2 +- include/ufs/ufshcd.h | 3 ++- 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c index 228975caf68e..5a02e1b3b3a5 100644 --- a/drivers/ufs/core/ufs-mcq.c +++ b/drivers/ufs/core/ufs-mcq.c @@ -268,17 +268,20 @@ static int ufshcd_mcq_get_tag(struct ufs_hba *hba, struct cq_entry *cqe) return div_u64(addr, ufshcd_get_ucd_size(hba)); } -static void ufshcd_mcq_process_cqe(struct ufs_hba *hba, - struct ufs_hw_queue *hwq) +/* Returns true if and only if @compl_cmd has been completed. */ +static bool ufshcd_mcq_process_cqe(struct ufs_hba *hba, + struct ufs_hw_queue *hwq, + struct scsi_cmnd *compl_cmd) { struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq); - int tag = ufshcd_mcq_get_tag(hba, cqe); if (cqe->command_desc_base_addr) { - ufshcd_compl_one_cqe(hba, tag, cqe); - /* After processed the cqe, mark it empty (invalid) entry */ + const int tag = ufshcd_mcq_get_tag(hba, cqe); + /* Mark the CQE as invalid. */ cqe->command_desc_base_addr = 0; + return ufshcd_compl_one_cqe(hba, tag, cqe, compl_cmd); } + return false; } void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, @@ -289,7 +292,7 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, spin_lock_irqsave(&hwq->cq_lock, flags); while (entries > 0) { - ufshcd_mcq_process_cqe(hba, hwq); + ufshcd_mcq_process_cqe(hba, hwq, NULL); ufshcd_mcq_inc_cq_head_slot(hwq); entries--; } @@ -299,8 +302,10 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, spin_unlock_irqrestore(&hwq->cq_lock, flags); } +/* Clears *@compl_cmd if and only if *@compl_cmd has been completed. */ unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, - struct ufs_hw_queue *hwq) + struct ufs_hw_queue *hwq, + struct scsi_cmnd **compl_cmd) { unsigned long completed_reqs = 0; unsigned long flags; @@ -308,7 +313,9 @@ unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, spin_lock_irqsave(&hwq->cq_lock, flags); ufshcd_mcq_update_cq_tail_slot(hwq); while (!ufshcd_mcq_is_cq_empty(hwq)) { - ufshcd_mcq_process_cqe(hba, hwq); + if (ufshcd_mcq_process_cqe(hba, hwq, + compl_cmd ? *compl_cmd : NULL)) + *compl_cmd = NULL; ufshcd_mcq_inc_cq_head_slot(hwq); completed_reqs++; } diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index fb4457a84d11..42802fd689fb 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -61,8 +61,8 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, enum flag_idn idn, u8 index, bool *flag_res); void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit); -void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, - struct cq_entry *cqe); +bool ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, + struct cq_entry *cqe, struct scsi_cmnd *compl_cmd); int ufshcd_mcq_init(struct ufs_hba *hba); int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba); int ufshcd_mcq_memory_alloc(struct ufs_hba *hba); diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 66198eee51b0..08abdd763c51 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5540,9 +5540,12 @@ void ufshcd_release_scsi_cmd(struct ufs_hba *hba, * @hba: per adapter instance * @task_tag: the task tag of the request to be completed * @cqe: pointer to the completion queue entry + * @compl_cmd: if not NULL, check whether this command has been completed + * + * Returns: true if and only if @compl_cmd has been completed. */ -void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, - struct cq_entry *cqe) +bool ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, + struct cq_entry *cqe, struct scsi_cmnd *compl_cmd) { struct ufshcd_lrb *lrbp; struct scsi_cmnd *cmd; @@ -5559,6 +5562,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, ufshcd_release_scsi_cmd(hba, lrbp); /* Do not touch lrbp after scsi done */ scsi_done(cmd); + return cmd == compl_cmd; } else if (lrbp->command_type == UTP_CMD_TYPE_DEV_MANAGE || lrbp->command_type == UTP_CMD_TYPE_UFS_STORAGE) { if (hba->dev_cmd.complete) { @@ -5569,6 +5573,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, complete(hba->dev_cmd.complete); } } + return false; } /** @@ -5577,12 +5582,15 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, * @completed_reqs: bitmask that indicates which requests to complete */ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, - unsigned long completed_reqs) + unsigned long completed_reqs, + struct scsi_cmnd **compl_cmd) { int tag; for_each_set_bit(tag, &completed_reqs, hba->nutrs) - ufshcd_compl_one_cqe(hba, tag, NULL); + if (ufshcd_compl_one_cqe(hba, tag, NULL, + compl_cmd ? *compl_cmd : NULL)) + *compl_cmd = NULL; } /* Any value that is not an existing queue number is fine for this constant. */ @@ -5609,7 +5617,8 @@ static void ufshcd_clear_polled(struct ufs_hba *hba, * Return: > 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) +static int __ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num, + struct scsi_cmnd **compl_cmd) { struct ufs_hba *hba = shost_priv(shost); unsigned long completed_reqs, flags; @@ -5620,7 +5629,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) WARN_ON_ONCE(queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT); hwq = &hba->uhq[queue_num]; - return ufshcd_mcq_poll_cqe_lock(hba, hwq); + return ufshcd_mcq_poll_cqe_lock(hba, hwq, compl_cmd); } spin_lock_irqsave(&hba->outstanding_lock, flags); @@ -5637,11 +5646,16 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) spin_unlock_irqrestore(&hba->outstanding_lock, flags); if (completed_reqs) - __ufshcd_transfer_req_compl(hba, completed_reqs); + __ufshcd_transfer_req_compl(hba, completed_reqs, compl_cmd); return completed_reqs != 0; } +static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) +{ + return __ufshcd_poll(shost, queue_num, NULL); +} + /** * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is * invoked from the error handler context or ufshcd_host_reset_and_restore() @@ -5685,7 +5699,7 @@ static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, } spin_unlock_irqrestore(&hwq->cq_lock, flags); } else { - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); } } } @@ -6960,7 +6974,7 @@ static irqreturn_t ufshcd_handle_mcq_cq_events(struct ufs_hba *hba) ufshcd_mcq_write_cqis(hba, events, i); if (events & UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS) - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); } return IRQ_HANDLED; @@ -7453,7 +7467,7 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) lrbp->lun == lun) { ufshcd_clear_cmd(hba, pos); hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(lrbp->cmd)); - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); } } err = 0; @@ -7481,7 +7495,8 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) __func__, pos); } } - __ufshcd_transfer_req_compl(hba, pending_reqs & ~not_cleared_mask); + __ufshcd_transfer_req_compl(hba, pending_reqs & ~not_cleared_mask, + NULL); out: hba->req_abort_count = 0; @@ -7658,7 +7673,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) dev_err(hba->dev, "%s: cmd was completed, but without a notifying intr, tag = %d", __func__, tag); - __ufshcd_transfer_req_compl(hba, 1UL << tag); + __ufshcd_transfer_req_compl(hba, 1UL << tag, NULL); goto release; } diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index b3ca9b3bf94b..0598cd8f53dd 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -1704,7 +1704,7 @@ static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data) struct ufs_hw_queue *hwq = &hba->uhq[id]; ufshcd_mcq_write_cqis(hba, 0x1, id); - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); return IRQ_HANDLED; } diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 4ba826fe7b62..8fac282e0476 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1263,7 +1263,8 @@ void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds); u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i); void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i); unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, - struct ufs_hw_queue *hwq); + struct ufs_hw_queue *hwq, + struct scsi_cmnd **compl_cmd); void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba); void ufshcd_mcq_enable_esi(struct ufs_hba *hba); void ufshcd_mcq_enable(struct ufs_hba *hba); From patchwork Fri Apr 12 00:02:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 788927 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F11F4C70 for ; Fri, 12 Apr 2024 00:03:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712880213; cv=none; b=McTPNu+jCJaFTYbh2gYav/JHsGicc6CT2edncy8cgcbGat4JX7/fq/xBu8oCCYYtL/ejtPX3oKxA+XqySqhLA33rVo9e8YhWM0NXxwnm2YoFQp9tjUP6OojN2WaT2LdOeiQ7sC8kGddty4jIlelVdf3xVLZrV0zaBTOMaOlH9eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712880213; c=relaxed/simple; bh=WcxWPMo00MFwO8E8aZ3yGjE2YafWMvZBn2w2oAY2Pok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TzUGm21i+7+H8okSBcr1wb0ctvbsg/KgOhuv1sHpkZoU6NCFg/Eie5ZYyi1E+4mnAE0uIvAxBWryzSwiXu2hISJ8cnDbn7QZQ3VU6kfcd6tQAX70C5/bgwB70m2dAi/xxE7rwme0pmIJtZNrDtUazLzbS8MXd1cQP3FPmw6RmK4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=rnkW8AXA; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="rnkW8AXA" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VFxc25hZ4z6Cnk8y; Fri, 12 Apr 2024 00:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received; s=mr01; t=1712880204; x= 1715472205; bh=9IuSH1YaIUPTgPJI7q/c41AePG3xK0BVVdglZ64w0p8=; b=r nkW8AXAklTBYpcpvLaW8Rir2SU2Hpi/xzY+4n/FcKFlXqrFk7GAjLsSCoPkZ5mZQ j785fXJBwi+Yli1VMuLRRGor97OtE2TXNzTGFZ1p8rHyEH4UsWQf8pI+KH7Vf9T7 LzgA6ZXZrIGJq3q7xoHixc+77PVg3OF5rTLpt9PqwNWeIqfoini4tg3ypnFPW0D7 UIN09i7Qjc1gnPRut1iEsZ3Gk3VAWWmfKmbJtXt/mKlKkNpmlpZImyrt4N24qD3L jAmHrvuSV06PsCeHlaVs8rSi/SBjEQgwXTsGYv/YRjekcUgOffbCN1M50kNTAHuQ wd2Fr5823r5S5ynm41umw== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id dNN9Cy6wdJyp; Fri, 12 Apr 2024 00:03:24 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VFxbv0Xqrz6Cnk8t; Fri, 12 Apr 2024 00:03:22 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Stanley Jhu , Avri Altman , Can Guo , Peter Wang , "Bao D. Nguyen" , Manivannan Sadhasivam , Bean Huo Subject: [PATCH 4/4] scsi: ufs: Check for completion from the timeout handler Date: Thu, 11 Apr 2024 17:02:24 -0700 Message-ID: <20240412000246.1167600-5-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240412000246.1167600-1-bvanassche@acm.org> References: <20240412000246.1167600-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If ufshcd_abort() returns SUCCESS for an already completed command then that command is completed twice. This results in a crash. Prevent this by checking whether a command has completed without completion interrupt from the timeout handler. This CL fixes the following kernel crash: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 Call trace:  dma_direct_map_sg+0x70/0x274  scsi_dma_map+0x84/0x124  ufshcd_queuecommand+0x3fc/0x880  scsi_queue_rq+0x7d0/0x111c  blk_mq_dispatch_rq_list+0x440/0xebc  blk_mq_do_dispatch_sched+0x5a4/0x6b8  __blk_mq_sched_dispatch_requests+0x150/0x220  __blk_mq_run_hw_queue+0xf0/0x218  __blk_mq_delay_run_hw_queue+0x8c/0x18c  blk_mq_run_hw_queue+0x1a4/0x360  blk_mq_sched_insert_requests+0x130/0x334  blk_mq_flush_plug_list+0x138/0x234  blk_flush_plug_list+0x118/0x164  blk_finish_plug()  read_pages+0x38c/0x408  page_cache_ra_unbounded+0x230/0x2f8  do_sync_mmap_readahead+0x1a4/0x208  filemap_fault+0x27c/0x8f4  f2fs_filemap_fault+0x28/0xfc  __do_fault+0xc4/0x208  handle_pte_fault+0x290/0xe04  do_handle_mm_fault+0x52c/0x858  do_page_fault+0x5dc/0x798  do_translation_fault+0x40/0x54  do_mem_abort+0x60/0x134  el0_da+0x40/0xb8  el0t_64_sync_handler+0xc4/0xe4  el0t_64_sync+0x1b4/0x1b8 Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 08abdd763c51..98b14623317f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -9022,6 +9022,25 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd) { struct ufs_hba *hba = shost_priv(scmd->device->host); + struct scsi_cmnd *cmd2 = scmd; + + WARN_ON_ONCE(!scmd); + + if (is_mcq_enabled(hba)) { + struct ufs_hw_queue *hwq = + ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(scmd)); + + ufshcd_mcq_poll_cqe_lock(hba, hwq, &cmd2); + } else { + __ufshcd_poll(hba->host, UFSHCD_POLL_FROM_INTERRUPT_CONTEXT, + &cmd2); + } + if (cmd2 == NULL) { + sdev_printk(KERN_INFO, scmd->device, + "%s: cmd with tag %#x has already been completed\n", + __func__, blk_mq_unique_tag(scsi_cmd_to_rq(scmd))); + return SCSI_EH_DONE; + } if (!hba->system_suspending) { /* Activate the error handler in the SCSI core. */