Received: by 2002:a05:7412:d024:b0:f9:90c9:de9f with SMTP id bd36csp79062rdb; Wed, 20 Dec 2023 06:51:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsKa1S/6v2fLuC2WiJchhNfs5gJrRa6dRlsagG/NNl87o9KMk2kZ57IVHONNXY9P4gTO75 X-Received: by 2002:a17:906:890d:b0:a26:9c11:3cc5 with SMTP id fr13-20020a170906890d00b00a269c113cc5mr143457ejc.84.1703083859849; Wed, 20 Dec 2023 06:50:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703083859; cv=none; d=google.com; s=arc-20160816; b=HCN9Vz9FU9wQthrXirfF3qGfrf8BeRj6J151T9D8qC4+mxKgiWF8QpOEPGcRtzAf6n Cw3zOISQdP7IRo5R7TlqQH08yqVGT+flQQP7HXfpmA3CKQjWaV4eggRNLjDDBpjZx8mv 8bYwRf43T4Mzidfp6wMwcXSZ/UJbLmwNDmzt4j7xvGtjrmZDVt2Nk31zS5S9l71WI0HA w/O2ikG9ay75CydM5MpKhA2U41ZuEIrJuWzCqi12Vc6hP4CphmJMQfgrGhD3+D/g8pPB MOsY0DMDsiDFcZRmq0Nq9jPh++5zoX9KERy+ugsjuX1H2+/HmkXvZCIiWZc5WhT0hweq J8vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dB0LYa5JmRW+h8N4OVzWagjxfGqKR43GCuW9ZDjLPq4=; fh=Yy+UdRsQCnzRJJyWZwz9OhWAvvalTRG1MtAcI4W/LLQ=; b=SJsLYFVL1s2IInlA2bBBmoOh1reYq7J66kqnMuXTHssxeuMBp+Fv9F3LDVwd2uosAz Qgugk/nhDMgaEe+PKYz0Ao68Ci4YiX3cZkz2DQoXPGCBzImUPC60Ev00s5H47X+JD/TQ MIFyXZhLF4np2OelDnLpHOr/oMSrJENnoxYIczmgDZu1IZ7kd0s5RXb8ggwon6GVsp3a fJPaz2i/bBzOfB8rZVPJIUzhZy2U60q8FLq8TH4sEo2/t9hcdSmy/cEriFmXkrsH3VWX VsT7Zgb0NSSq/8H7uY8HQE/2C2f4s4GFz7baB6K7jR/mVZDg6szYzr0NHa7Rs1yY8Pcg TCEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z3nCfqbl; spf=pass (google.com: domain of linux-kernel+bounces-7087-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q12-20020a170906b28c00b00a2356f4c943si2774158ejz.866.2023.12.20.06.50.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:50:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7087-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z3nCfqbl; spf=pass (google.com: domain of linux-kernel+bounces-7087-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CCD801F234F2 for ; Wed, 20 Dec 2023 14:50:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46BB93D995; Wed, 20 Dec 2023 14:50:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z3nCfqbl" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6BFC33D96F; Wed, 20 Dec 2023 14:50:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F9D8C433C7; Wed, 20 Dec 2023 14:50:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703083848; bh=RbnKwhHVCMmtzs/gnnNR6IeXwTlPNVrUWe2V3JfuahE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Z3nCfqbl6K1XjAuARXoTPBFJ4X57GygwJAsgp5Bhqh5TElE38LXeIuE3xiwom6FuV sj+Gks9N0DocsTEKOFN0cVX81Fw+LmZE2hSp61o93gh17Z5U35bJAaSxdpFqF02vG+ mTU+I2qLqsUjjO0HsEaHEtJsxGeCWAaP5PDq9qHt2N2gnvBCjlHC08RgKQ5YBbqEIo vDpgk8VKOfm8jEYaWL1LTvPwzRS+YsuglKONF+ng0QclXwr8wPhOFuytfWhrlrSjYd RIFHJu8uTDCMkHuU7R3kSR/s9epcDw7Z9+QMQ+19oovFil/EYNtW71p7mEa/tWYKN/ Eui6fDFNUu+Sg== Date: Wed, 20 Dec 2023 20:20:31 +0530 From: Manivannan Sadhasivam To: Can Guo Cc: bvanassche@acm.org, adrian.hunter@intel.com, beanhuo@micron.com, avri.altman@wdc.com, junwoo80.lee@samsung.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, linux-arm-msm@vger.kernel.org, Alim Akhtar , "James E.J. Bottomley" , Stanley Chu , Asutosh Das , Peter Wang , "Bao D. Nguyen" , Arthur Simchaev , open list Subject: Re: [PATCH] scsi: ufs: core: Let the sq_lock protect sq_tail_slot access Message-ID: <20231220145031.GI3544@thinkpad> References: <1702913550-20631-1-git-send-email-quic_cang@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1702913550-20631-1-git-send-email-quic_cang@quicinc.com> On Mon, Dec 18, 2023 at 07:32:17AM -0800, Can Guo wrote: > If access sq_tail_slot without the protection from the sq_lock, race > condition can have multiple SQEs copied to duplicate SQE slot(s), which can > lead to multiple incredible stability issues. Fix it by moving the *dest > initialization, in ufshcd_send_command(), back under protection from the > sq_lock. > > Fixes: 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()") Cc: stable@vger.kernel.org > Signed-off-by: Can Guo Reviewed-by: Manivannan Sadhasivam - Mani > > diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c > index ae9936f..2994aac 100644 > --- a/drivers/ufs/core/ufshcd.c > +++ b/drivers/ufs/core/ufshcd.c > @@ -2274,9 +2274,10 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag, > if (is_mcq_enabled(hba)) { > int utrd_size = sizeof(struct utp_transfer_req_desc); > struct utp_transfer_req_desc *src = lrbp->utr_descriptor_ptr; > - struct utp_transfer_req_desc *dest = hwq->sqe_base_addr + hwq->sq_tail_slot; > + struct utp_transfer_req_desc *dest; > > spin_lock(&hwq->sq_lock); > + dest = hwq->sqe_base_addr + hwq->sq_tail_slot; > memcpy(dest, src, utrd_size); > ufshcd_inc_sq_tail(hwq); > spin_unlock(&hwq->sq_lock); > -- > 2.7.4 > -- மணிவண்ணன் சதாசிவம்