Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6765338rdb; Tue, 2 Jan 2024 12:34:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIXw3Xyok575T8mI6P4CeGsXDbu18tAcBFMKrMtHlS37sYDHHWod1HMpRQj2yebk5cVhXW X-Received: by 2002:a50:8758:0:b0:555:e614:1d95 with SMTP id 24-20020a508758000000b00555e6141d95mr1584105edv.71.1704227661890; Tue, 02 Jan 2024 12:34:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704227661; cv=none; d=google.com; s=arc-20160816; b=vrtfBKLDLjCyUtVSxBVFp/UU+z1Fmh8ueFfXZjxWPyU/+uMlEKz4dbwy/FifdDECIw Va3bv/W5vRK2RRKHVNaBAICxyYZcrFOxTas1aLFKZ6Js8guFucsxOdp/C4F1NWNXq/vK Nu8Se0DUrk9pGWrOTOb1dIupU8ggQSjLjzPHKCJyArVa4Npqo7YKJC5wsGXFaHqj9RQY teujDubsmzJJsGd+jS6R8XmMfqvX/9KVjS7ydHC0fxPNCf+xzG5f3JaH7T7hJDu9byoI 6huufhXzEBdfbuB9A7YiNGkWf2CL5RRkkLQ5n0+pbju0aL9xdq6xGJMkagq0U42Uwt8h 9qhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=vmjxe9XwHidyB+gjEeLkZQFfIRNKZJrOImocyOmQabs=; fh=nELA03QUU9CHL4T9zUeMpoIvqy4Nvsem/7hcIpt00YE=; b=BPIHZZkTWQbPlR1Qwpimu00dwhQK6GaxGedBpoFKaU2miouHOXS+cil5yCc1Osc+t7 ZDBkdYjUAgkkrTQGKrZalr/8lPnSHr+5oCo9l3zRoH+WVcsITPgUh1fQJqEF1foKBBQ7 SksoDwt1sYRxBDfxPZv1SbOWQb8ycRYdzczYIatfjslypfsBtv8MoKsn/NNQCgiwOQCw LjYNxE8hE6baxfvG83rJWtMXdnuHObM9nQareOho8bxEUY79LRyDtLCb96O7+pTZXTtt 6WmNvEOQ4sw7VuGu8GtrLOO/MyNtvN7ds0FyQTOKhxhNHv+covA3tn7luEeUV2pBydk1 mBXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=USUEz1at; spf=pass (google.com: domain of linux-kernel+bounces-14805-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14805-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ee39-20020a056402292700b005561833cb84si2711352edb.383.2024.01.02.12.34.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 12:34:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14805-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=USUEz1at; spf=pass (google.com: domain of linux-kernel+bounces-14805-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14805-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com 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 A14291F235BA for ; Tue, 2 Jan 2024 20:34:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8108D16408; Tue, 2 Jan 2024 20:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="USUEz1at" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 5377616410; Tue, 2 Jan 2024 20:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 402KTbF2012670; Tue, 2 Jan 2024 20:33:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=vmjxe9XwHidyB+gjEeLkZQFfIRNKZJrOImocyOmQabs=; b=US UEz1atSMTOHCJVCNjWRj6XFMwUr1Xn2oojZJOQWwTOCFODutx3yhJ3cZQeclRQMF tcb5HTUxlYnD3JmhB0fbrdH1cK0jiKJU1naZ4Ng5mplMmPt2sI/L5UKQrb0MTzOr eEwzT6M5H5VSe+3QidqTqumS8OSY3GffDJzMUKy2OtDmvRjzpwPKXQDot61r8bOC 9JFUCTyNxUIjIrX66btJop71g4xaOIUJo+Un03suTF9ntL6d7rb54gf7y+RQVwEC 8Bu5ee2D/GdqtSVOnEoYfnO+V2qfBEndcjRtna47Z+KUVsJmaE3rmNf0dPjlV4Yb 88hdjoThs2xADwFD9ZFg== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vcg41977q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 20:33:22 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 402KXLl2028048 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 2 Jan 2024 20:33:21 GMT Received: from [192.168.143.77] (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 2 Jan 2024 12:33:20 -0800 Message-ID: <76fb76cc-70d6-7a5f-7fcd-e8161ae72299@quicinc.com> Date: Tue, 2 Jan 2024 12:33:20 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] scsi: ufs: core: Let the sq_lock protect sq_tail_slot access To: Can Guo , , , , , , , CC: , , Alim Akhtar , "James E.J. Bottomley" , Stanley Chu , Asutosh Das , Peter Wang , "Arthur Simchaev" , open list References: <1702913550-20631-1-git-send-email-quic_cang@quicinc.com> Content-Language: en-US From: "Bao D. Nguyen" In-Reply-To: <1702913550-20631-1-git-send-email-quic_cang@quicinc.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: wsIyvjIJr7V944lrYzvcDlEk0rKbpo45 X-Proofpoint-ORIG-GUID: wsIyvjIJr7V944lrYzvcDlEk0rKbpo45 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 mlxscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401020153 On 12/18/2023 7:32 AM, 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()") > Signed-off-by: Can Guo > > 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); Reviewed and Tested-by: Bao D. Nguyen