Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2058858pxb; Mon, 12 Apr 2021 13:13:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfkP6aSXDAsX07xwR221R5iHW2kdZFnjyCcKyLxfLZz9KmNeZ7o9bdO5E5kTViQ3urhM3p X-Received: by 2002:a17:90a:138b:: with SMTP id i11mr950252pja.220.1618258420257; Mon, 12 Apr 2021 13:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618258420; cv=none; d=google.com; s=arc-20160816; b=N0ZRS1f+MjWMN87ax/15GOGpAfbXRzeMeDpCEkTd1iCSVNUEbGqgn7jBt0Vul1EWwR H6WzTpLgOltXdKRzKhjO7FQues8LuCo5PntjGWZqjPKkUIMOzm+/dnbBEAuj7IoFn8sW hKItST/cGVYvL965e+oRHla//EIs+L1iPmPQ66Fwo9nnZjKN/hXqIajjfIAJ7hoA1mCi Ob8/pIQWdsDPP/0Psx7T3axnUhm7psR22gGGhnAX7gA6fZAyxHeZMISyn+g0cYe3AY2q DOwFCL/17CvqhUQ4yiAGCz95qnETu15KDeiUJkBgLKNQOvN86/vdo5qDw2Dbj3lkKpks LDTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PQmaZ2hSXqFJDhK19E2B3SeGkSFTgrjoizw2eMwRTQQ=; b=yDrxPElxD64Yq5+mS9Hj7E+t1KAw2PbBP7SE9Dcad6Amd+fRS2+xexzBvg4ds1Uk6h U8YhE0WEpIvxxI6PKjgUuwZvn3L59x+LQmk29r6tS/tko09egu3UUpyhu7wF4YHGsLSs phec0ASaJTXUrl6QSfbFR9UMiCBzpASpFWcoy6h1oVlL6SLt3tci2PY6bwJtCiwLlI8M 8mOOT/7JLC8LGYKiI3hEF9X0ewirc5QpeodqVQYF/Y6kNRUc2aGB+8I8j8P59EAwoBw0 +kBQ/UINzYgWOazMHaCRN0WAsOIyiWhN10HF5y+Vxmo2Fo7j4dghzBy+LRvMTnKCDVjL jtDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZlX8WJvn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay5si14493882plb.120.2021.04.12.13.13.27; Mon, 12 Apr 2021 13:13:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZlX8WJvn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238662AbhDLIyU (ORCPT + 99 others); Mon, 12 Apr 2021 04:54:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:39950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238333AbhDLItb (ORCPT ); Mon, 12 Apr 2021 04:49:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D9ADD61367; Mon, 12 Apr 2021 08:48:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618217313; bh=UwComO1wByiYhTby7lt6pteVT4+ngWbBwxiTRSH/wSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZlX8WJvnIOda54edeCOjQHdNuWqBPWfpnBvWVwgqMJlHosICVomeY01Hxt+tbVOP4 Ue9onLsb3aCFqxDITHGkDQBVT58DHuTZbpXaTu2k6E8BbYjZQ8sQLa5EJ9foxB1mzX 6qcDmcxD4JV4eDIYsw2Au1xLLeFEXEwsiaBmGAAc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Can Guo , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.4 080/111] scsi: ufs: core: Fix wrong Task Tag used in task management request UPIUs Date: Mon, 12 Apr 2021 10:40:58 +0200 Message-Id: <20210412084006.930795217@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084004.200986670@linuxfoundation.org> References: <20210412084004.200986670@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Can Guo [ Upstream commit 4b42d557a8add52b9a9924fb31e40a218aab7801 ] In __ufshcd_issue_tm_cmd(), it is not correct to use hba->nutrs + req->tag as the Task Tag in a TMR UPIU. Directly use req->tag as the Task Tag. Fixes: e293313262d3 ("scsi: ufs: Fix broken task management command implementation") Link: https://lore.kernel.org/r/1617262750-4864-3-git-send-email-cang@codeaurora.org Reviewed-by: Bart Van Assche Signed-off-by: Can Guo Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 3f20270f0ca0..b81eebc7e2df 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -5695,35 +5695,31 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba, DECLARE_COMPLETION_ONSTACK(wait); struct request *req; unsigned long flags; - int free_slot, task_tag, err; + int task_tag, err; /* - * Get free slot, sleep if slots are unavailable. - * Even though we use wait_event() which sleeps indefinitely, - * the maximum wait time is bounded by %TM_CMD_TIMEOUT. + * blk_get_request() is used here only to get a free tag. */ req = blk_get_request(q, REQ_OP_DRV_OUT, BLK_MQ_REQ_RESERVED); req->end_io_data = &wait; - free_slot = req->tag; - WARN_ON_ONCE(free_slot < 0 || free_slot >= hba->nutmrs); ufshcd_hold(hba, false); spin_lock_irqsave(host->host_lock, flags); - task_tag = hba->nutrs + free_slot; blk_mq_start_request(req); + task_tag = req->tag; treq->req_header.dword_0 |= cpu_to_be32(task_tag); - memcpy(hba->utmrdl_base_addr + free_slot, treq, sizeof(*treq)); - ufshcd_vops_setup_task_mgmt(hba, free_slot, tm_function); + memcpy(hba->utmrdl_base_addr + task_tag, treq, sizeof(*treq)); + ufshcd_vops_setup_task_mgmt(hba, task_tag, tm_function); /* send command to the controller */ - __set_bit(free_slot, &hba->outstanding_tasks); + __set_bit(task_tag, &hba->outstanding_tasks); /* Make sure descriptors are ready before ringing the task doorbell */ wmb(); - ufshcd_writel(hba, 1 << free_slot, REG_UTP_TASK_REQ_DOOR_BELL); + ufshcd_writel(hba, 1 << task_tag, REG_UTP_TASK_REQ_DOOR_BELL); /* Make sure that doorbell is committed immediately */ wmb(); @@ -5743,24 +5739,24 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba, ufshcd_add_tm_upiu_trace(hba, task_tag, "tm_complete_err"); dev_err(hba->dev, "%s: task management cmd 0x%.2x timed-out\n", __func__, tm_function); - if (ufshcd_clear_tm_cmd(hba, free_slot)) - dev_WARN(hba->dev, "%s: unable clear tm cmd (slot %d) after timeout\n", - __func__, free_slot); + if (ufshcd_clear_tm_cmd(hba, task_tag)) + dev_WARN(hba->dev, "%s: unable to clear tm cmd (slot %d) after timeout\n", + __func__, task_tag); err = -ETIMEDOUT; } else { err = 0; - memcpy(treq, hba->utmrdl_base_addr + free_slot, sizeof(*treq)); + memcpy(treq, hba->utmrdl_base_addr + task_tag, sizeof(*treq)); ufshcd_add_tm_upiu_trace(hba, task_tag, "tm_complete"); } spin_lock_irqsave(hba->host->host_lock, flags); - __clear_bit(free_slot, &hba->outstanding_tasks); + __clear_bit(task_tag, &hba->outstanding_tasks); spin_unlock_irqrestore(hba->host->host_lock, flags); + ufshcd_release(hba); blk_put_request(req); - ufshcd_release(hba); return err; } -- 2.30.2