Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp614755rwd; Thu, 1 Jun 2023 04:41:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Nnam1Xu6FZ3tQlQH4WKarix76fbe5U5XUfeGmjlsJdj7f7/E2XmuaJem2k/dNw7xHTjho X-Received: by 2002:a17:902:e54e:b0:1b1:8ca9:10ca with SMTP id n14-20020a170902e54e00b001b18ca910camr1719167plf.33.1685619667931; Thu, 01 Jun 2023 04:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685619667; cv=none; d=google.com; s=arc-20160816; b=Lr11M856mOzuDnmz/93XcU7t40BfFqylzCIgQ+pf2PFFKEImen2jj5cCxtOF78k7Y1 qNEyUD0vKiVoEMxrIcYeBWraOJv7Hw0ZL4Do0xHs8Mga8yVQm+hisqQ6m80OE6BXFr28 zyYKgynjhAf4fWrJsd24sTAm2vXTpcUnLt0gL6yO8j8Wy/JLTxZpVPgRTHC5Whbt0K89 TD4aagctKUsiT65522zoukSNbl8wlZgLLzeHEquYMKwv/OiywWy39o3Lt14WWsEHbd+V o5CnFxhhLuzBOKsvpTt9QkwhgcGFy7Yh7jWYEfFeBhYmyzaNyeJbsNr29JA8QbdBHuvi kWcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cfMQqCdL/Z44EbSVXa1lxsAa6Ha3jxDNZTaevoUb3Fs=; b=Pjv/uA5SCYu+EfKH5QR2ugZib72fHTAn8LzAtZe7j/VjaOnJxK8vPi4s/DAWzjrgft 7H84HerMk3c1n3yuwrsTzZmqlAm4f0Z7ex8wd6N43kx1620QpByR03PFiccQ3muc1g0A QPUa0cKPvhuVwj/8fLwNo2tXezgfpfNDecWg4A7FBYBE7USlFsaU7YT4JlDpIoPtlmiT Ze6BKkDizeY4qT5rARywhApXVom9rAl2OL8OwFn9/ZPQe6VWa36bLGZ/uOHW331MQCoO Frf05QJJ8nbl52r5xUqieD1D5smd83arJioKBaoSHa76RSGYA2phknMX3fYRMRwPgMfb XvYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=pQnPSYB5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p6-20020a170902eac600b001a6565a16c4si1608523pld.493.2023.06.01.04.40.53; Thu, 01 Jun 2023 04:41:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=pQnPSYB5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232848AbjFAL2Y (ORCPT + 99 others); Thu, 1 Jun 2023 07:28:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232332AbjFAL2U (ORCPT ); Thu, 1 Jun 2023 07:28:20 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1F0124; Thu, 1 Jun 2023 04:28:19 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35157EpB004438; Thu, 1 Jun 2023 11:27:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=cfMQqCdL/Z44EbSVXa1lxsAa6Ha3jxDNZTaevoUb3Fs=; b=pQnPSYB5UQSTmMiF6FwPNUmI7mlWPGPGBSVLhzGzT7cDgOmu++W4eeX8jtYgTFWn2u1l USS7BygZ6pv8+3ohuQdH/xRH0KPTaCaMedsK26XgFs/EKu20FxtHYYPHpvIvu7V4+q16 D06IvqP+Fo9G9XukDST7t5QMyZuyZG685BTZaYekFnhJpVPs89pRbHBRmWuoF5eLVbT3 vo+Kr12Ax1MxY8QGPwWhRtauV/lrp0AcgQPjb5rIX4/f/5JUax7SRIvaQdT9gmjzIvOz qmcA0pCi7RkwVqY54oFKwGbH9uQLiEhotZbuPlvazp50Ivsi9HH6xrAebNSWXyRinurn uw== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qxdr99jsh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Jun 2023 11:27:53 +0000 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 351BRqhY021128 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 1 Jun 2023 11:27:52 GMT Received: from stor-berry.qualcomm.com (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.986.42; Thu, 1 Jun 2023 04:27:52 -0700 From: "Bao D. Nguyen" To: , , , , , , , , CC: , "Bao D. Nguyen" , Alim Akhtar , "James E.J. Bottomley" , Alice Chao , open list Subject: [PATCH v1 1/1] ufs: mcq: Fix the variable wraparound logic Date: Thu, 1 Jun 2023 04:27:01 -0700 Message-ID: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] 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-ORIG-GUID: mJ528_cE8svJtbdhtniCiM-9-Rkc5UZf X-Proofpoint-GUID: mJ528_cE8svJtbdhtniCiM-9-Rkc5UZf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-01_07,2023-05-31_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 impostorscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 phishscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2306010101 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the hwq's queue depth is not a multiple of 4s, the logic used for wrapping around the increase-by-1 sq_head_slot variable in ufshcd_mcq_sqe_search() will give an incorrect result because the binary expression of the mask is not a uniform of all 1s. Signed-off-by: Bao D. Nguyen --- drivers/ufs/core/ufs-mcq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c index 66ac02e..8e5bc88 100644 --- a/drivers/ufs/core/ufs-mcq.c +++ b/drivers/ufs/core/ufs-mcq.c @@ -585,7 +585,6 @@ static bool ufshcd_mcq_sqe_search(struct ufs_hba *hba, { struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; struct utp_transfer_req_desc *utrd; - u32 mask = hwq->max_entries - 1; __le64 cmd_desc_base_addr; bool ret = false; u64 addr, match; @@ -610,7 +609,10 @@ static bool ufshcd_mcq_sqe_search(struct ufs_hba *hba, ret = true; goto out; } - sq_head_slot = (sq_head_slot + 1) & mask; + + sq_head_slot++; + if (sq_head_slot == hwq->max_entries) + sq_head_slot = 0; } out: -- 2.7.4