From patchwork Tue Apr 16 17:13:28 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: 789687 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 86357133284 for ; Tue, 16 Apr 2024 17:14:09 +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=1713287651; cv=none; b=PuYRm80e+hQbT5OTIh/raZSbh6EZ8xIq3FCiJN8ApynaSKS8WZT+LIuGrgVUq11yf22JWNi27WiaGWficaCXQjkllykOaCv+ixBgLD2X2gxwMquMD5WEmqptqDFrxTPVv9JisI7+DcJZ178D+N9oTaIGLWyFekvIeru7JA42BmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713287651; c=relaxed/simple; bh=T9WrfpuBDHAe4xeZm3YN8pMCpcrsE0CX5iaqAirKMB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qgRKfiQhpt6dDl+Jgdh/6gzqKYwupjzjrX3EyM6lBuBTbk8jzm+KzLmDeMbMvqYxYhDnuucGLPo+9JJNw3wDzHzO30gPU/c7JEDIHVXVJN/HhWkK7EtqCq6QrG60boN8v1pqm5q2KnrM2ZUH8sGhX7nGuzWbxxp8yr/lP4WwDcU= 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=S1LqRI7M; 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="S1LqRI7M" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VJrHN6cDkz6Cnk8s; Tue, 16 Apr 2024 17:14:08 +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=1713287645; x=1715879646; bh=0gyQs VhGa672wbZSWf6EJ1bspdIdFZwvR0VKtj2LVjM=; b=S1LqRI7McpMTyocVZqQ+7 8gKSY9kiUvsPmjjEGgDRZ0u7TKOhP9LSfk1EDA5Eg8iRkdqjhE4I+jomzK942N8e FteULv73aa1dtej7vIInMF5/2dRQGSNIlkEsRyTCqPrUgfKNf0+zODnwIQ6b4eUB vh2amA2UVrxWv31/Cj6K3TU4xu3CRUwVH7gU3hjGjYCE4Tujj71R0hCPap49wJCk MTCE9JjW9I4wCYA81MQpcDc74CUBAAcPgAlnZ1ykdpfVnAKz3F3VYMN7Jd0b+34u 3dc0FMPQsmkFnaoLw4BAP/w7zNX4iQ8ZPk8T1Sf5axPad/aLuzheYEVXTYh2nTBM 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 eQ8uOF3uhixU; Tue, 16 Apr 2024 17:14:05 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4VJrHJ4VpJz6Cnk8m; Tue, 16 Apr 2024 17:14:04 +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 , "Bao D. Nguyen" , Can Guo , zhanghui , Po-Wen Kao , Keoseong Park Subject: [PATCH v2 1/4] scsi: ufs: Declare ufshcd_mcq_poll_cqe_lock() once Date: Tue, 16 Apr 2024 10:13:28 -0700 Message-ID: <20240416171357.1062583-2-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240416171357.1062583-1-bvanassche@acm.org> References: <20240416171357.1062583-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 Tue Apr 16 17:13:29 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: 790644 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 0CD6A131E21 for ; Tue, 16 Apr 2024 17:14:14 +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=1713287656; cv=none; b=Enk8ntmS+fwQigdaU2nCtus3UMl+ysJXcQ24WIwMzB8q+wSsrmYb7W8MXNajfBJMHToQXFfwWgkglNm+r61Nv/K8CJB96gbnvDCAu3ppXvYsGGysFAPnQbIxJ+Szd4616qxiDQ5nj3hfeXgZkBRsvd1dBqdMOyWbx5w/biQ68Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713287656; c=relaxed/simple; bh=baOxkUWyV5dY0/hGpNjx/6IGGd1S8Le3AQyGgUaqb7g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bpHlf5JM2frxSnz7vaSx+uRiZyJKwIlag0+Gd7W1bo0IrAwWBm2zSjl+L5P/bMvl4+PIrpaycwklWb4+n9j4NSZZm91BM5zAcWzpxE8HtRjVGOHM8o8A0JkGceV3jrJ/v+ahcVA3DRb6cIBumwZ3ky0pB2KSLa36Pz8jK2ZwZYM= 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=vL24pf78; 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="vL24pf78" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VJrHV35Lhz6Cnk8t; Tue, 16 Apr 2024 17:14:14 +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=1713287650; x=1715879651; bh=UQCNz K5G5FpS+9slQUD0ms6yPU100uT00gQm+PolWdI=; b=vL24pf780nUbN7WGN1pqf Ej3ijJ8OzPGsCMhQAQWv6/nMP5Ubqq/0lPnBMQT0RSLqTyWylABytW5/jaiohHyZ mgznZAT5U95Pq7dSZoJcl/YIL4zWunWJFBxo6XYcU8FB2QK83ARy8lveNxzt/Jcl GxCJc8T4VQypbeNT3GqGfq3LYG/GWwUALi9ycMRkF3ss5D3HZRyrkDvi5NXucU2J eJ1rcETR0xJa0gLFzqtmCUMbZSTVzUmQa9kfdkne6xv/7vt4fl2H9vxH0i6FycD3 vXKMUmuwsWNJqqOhh92wnvzThgP3bpjR1LYbTwEHcCEuPuSk3wmvYgFpjSJHz7BF Q== 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 R3GlAkvsjaL5; Tue, 16 Apr 2024 17:14:10 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4VJrHP3CTcz6Cnk8m; Tue, 16 Apr 2024 17:14:09 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Avri Altman , Stanley Jhu , Can Guo , Peter Wang , "Bao D. Nguyen" , Manivannan Sadhasivam , Bean Huo Subject: [PATCH v2 2/4] scsi: ufs: Make ufshcd_poll() complain about unsupported arguments Date: Tue, 16 Apr 2024 10:13:29 -0700 Message-ID: <20240416171357.1062583-3-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240416171357.1062583-1-bvanassche@acm.org> References: <20240416171357.1062583-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 0819ddafe7a6..165557611ae0 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5555,6 +5555,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 Tue Apr 16 17:13:30 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: 790643 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 4949A10A22 for ; Tue, 16 Apr 2024 17:14:57 +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=1713287698; cv=none; b=OzqmmH7CWLV2rTDYyYqjJ0l2qI7mq9+LtqTRxlHZyKdW4M9UVck5UZGvBb95S12qwbN5Xi+jDfgjxgiHbeyZkxYvRgW92Ir4px3eZMlvVSLBSRVeTBeM4d/sNcv3u6Jjc5OLoUh0b1UTlrjEOxfkyWXGZvDRDQ7tascznvsqxoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713287698; c=relaxed/simple; bh=zEqlFXUGDwfLcuPIifvKCDBn6lHlfSEg/QCuHnmvVJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qc0AFPR+lv2sdoRLskj/NgC8Om3UAP4FCidfJejaBaHEpNj6XTAbloXOExeMZrYNSNhGFp/GbEEJJly9ivTJTIxvQYO7mrcQWmMGQ8UeMiE9b17vT4sVFc2dpxDcZBp4mmQsWEBuAGbZiPf26FK4zAGswpgtHD5yayseja/w5LI= 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=WuerQqHc; 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="WuerQqHc" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VJrJJ5rBvz6Cnk8t; Tue, 16 Apr 2024 17:14:56 +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=1713287666; x=1715879667; bh=fUM8l g+QHK/af8HP/lTZyI+9EC9rWmGgEgzN1pGlurM=; b=WuerQqHcNb7z+ZgxKLyaw ZuBG+SAzHvcjc3gNtcuXQOiSIPXS1VtjbkoN7+rEWzE6kIw1hcfJWTPsTOU44bTF 6tmpDV9gc/qzNZE7PPlKKaZ/nnDo7eVkC94mx0SDdEZUEQGZJ6tzotVuxLE0p5G3 Qh0IRcjs4oTkVVmTV4hvDdyxkTXZaGtOt2MEwrUIAW5W2FQkB1Lsx7jyIdNdNvHw D8AYgcWzNECe2eSf1q5ux+Ck/94PihPvVRZqbYXxrmd8mZzD/oZLqOv/48hPU5JH DYupDSUz14qt0qKBo3PA7080xJXKn4Dzc8okZbC9R38IWzlUIYPGYpy3p2sNJ1ad Q== 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 UvJtvpxVMj1p; Tue, 16 Apr 2024 17:14:26 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4VJrHh5y9Tz6Cnk8m; Tue, 16 Apr 2024 17:14:24 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Peter Wang , Bjorn Andersson , Konrad Dybcio , Manivannan Sadhasivam , Matthias Brugger , AngeloGioacchino Del Regno , Stanley Jhu , Can Guo , Po-Wen Kao , "Bao D. Nguyen" , ChanWoo Lee , Yang Li , zhanghui , Keoseong Park , Avri Altman , Bean Huo , Maramaina Naresh , Akinobu Mita Subject: [PATCH v2 3/4] scsi: ufs: Make the polling code report which command has been completed Date: Tue, 16 Apr 2024 10:13:30 -0700 Message-ID: <20240416171357.1062583-4-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240416171357.1062583-1-bvanassche@acm.org> References: <20240416171357.1062583-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 | 25 +++++++++++++------- drivers/ufs/core/ufshcd-priv.h | 4 ++-- drivers/ufs/core/ufshcd.c | 41 +++++++++++++++++++++++---------- drivers/ufs/host/ufs-mediatek.c | 2 +- drivers/ufs/host/ufs-qcom.c | 2 +- include/ufs/ufshcd.h | 3 ++- 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c index 8ffac9f7d07d..fd47ce496138 100644 --- a/drivers/ufs/core/ufs-mcq.c +++ b/drivers/ufs/core/ufs-mcq.c @@ -278,17 +278,22 @@ 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, @@ -299,7 +304,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--; } @@ -309,8 +314,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; @@ -318,7 +325,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 165557611ae0..c552bf391f79 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5481,9 +5481,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; @@ -5500,6 +5503,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 (hba->dev_cmd.complete) { if (cqe) { ocs = le32_to_cpu(cqe->status) & MASK_OCS; @@ -5507,20 +5511,26 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, } complete(hba->dev_cmd.complete); } + return false; } /** * __ufshcd_transfer_req_compl - handle SCSI and query command completion * @hba: per adapter instance * @completed_reqs: bitmask that indicates which requests to complete + * @compl_cmd: if not NULL, check whether *@compl_cmd has been completed. + * Clear *@compl_cmd if it has been completed. */ 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. */ @@ -5547,7 +5557,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; @@ -5558,7 +5569,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); @@ -5575,11 +5586,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() @@ -5623,7 +5639,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); } } } @@ -6898,7 +6914,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; @@ -7391,7 +7407,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; @@ -7419,7 +7435,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; @@ -7596,7 +7613,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-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index c4f997196c57..a89a4106e76d 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -1715,7 +1715,7 @@ static irqreturn_t ufs_mtk_mcq_intr(int irq, void *__intr_info) ufshcd_mcq_write_cqis(hba, events, qid); 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; } diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index 0b02e697ea5b..772e4dd35c12 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -1709,7 +1709,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 4c60c62eddd6..cf2dc8886607 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1266,7 +1266,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 Tue Apr 16 17:13:31 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: 789686 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 7B9DE39ADB for ; Tue, 16 Apr 2024 17:14:38 +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=1713287679; cv=none; b=X5tNcW4egI9ye4fi3patf5afGlMjJvxtTi+KPvOp9p5T2Yh21dJ98VJajgXoc58rW7EI2Q9a7DrL6xoCODe3ZL8ykSyMrvgpUIg/XpVZ3MggXtVZEiKOei96g0TshnnsIPpxsTxVywfoSwqqRuAz7sfnYnDi+pQzM9iVUqNw1B0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713287679; c=relaxed/simple; bh=q4V0l+H+VKbLbn5Gvi+M9UWiRAawqFeoc1Pa/+Tx0ys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IaeqrFgqQnls5kid9S4J0z8NaN5FGRDVV91jMd9Ja/hRY/OW+/K6sB81CQsT2tezTemA387QFy7eE8mBWlp8gKXzOLcMZRLMlWLU+5dk0DhTB0PP5L3QSEam5APjpFcU+iMGeWOEy/AlrmuEoWjb7X4vBLa/v6g3PN6Hs/tyciQ= 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=GihWwyhW; 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="GihWwyhW" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VJrHy1gxrz6Cnk8s; Tue, 16 Apr 2024 17:14:38 +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=1713287671; x= 1715879672; bh=23HYz2m1XT5SSkG1fV63l1pc14rDh/T3Ec+21GcUxd0=; b=G ihWwyhWznT5Ml5mqu/RCG874QZ8R3tI0bkm6xmYZ3Mseq8Xm7pSbR+B3wl0K/7j2 gAZTqNSdP8HeV1TdXaJqJbJSeUlA3SLeT6rPiy3msGtBZLARBgFDd34QAbqJELuO NNls+1wTFPpg0IyhDSjYCPZWl3xqBD/HztPcfGSkITz3cHh76pGWngFIZqDQg8Pe qU3HwpuK3QcUag+n87DWecG8pvYqZjJ6vy56FALRP0Mbg6LGJuveNSZ/y6hOREQn 9VJXu6hUF1b+96cdVOPA+uT62qBv25FFCokkQuNPF6UGvuXbYLtrfQsVMh5hMHJL NCDjAg6vVGpccXMoupfiA== 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 qH751M1jMlXP; Tue, 16 Apr 2024 17:14:31 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4VJrHp5lrbz6Cnk8t; Tue, 16 Apr 2024 17:14:30 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Avri Altman , Stanley Jhu , Can Guo , Peter Wang , "Bao D. Nguyen" , Andrew Halaney , Manivannan Sadhasivam , Bean Huo Subject: [PATCH v2 4/4] scsi: ufs: Check for completion from the timeout handler Date: Tue, 16 Apr 2024 10:13:31 -0700 Message-ID: <20240416171357.1062583-5-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240416171357.1062583-1-bvanassche@acm.org> References: <20240416171357.1062583-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 c552bf391f79..c44515605031 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8880,6 +8880,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 request *rq = scsi_cmd_to_rq(scmd); + struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, rq); + + 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. */