From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CB27EB64D8 for ; Wed, 21 Jun 2023 09:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:CC:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ze55HOL16RtuAqRDbLlc2qkB9BvtdU8DQ6PoEl4IJvI=; b=nZyalVfi+OUjxJ mhE111DXwfIdTIOSKaEqWGOK+RE3l8zxE92Syd4R5YYiRyslelLgxmLf4hxKj9Ml1hQXfpOcxUMLv rrADDpRLUtmahqP9whISCXIC/Eo5PUrq/xPtgi3/EuEYoWrJ1KMk6/aOrsd+u4f49VLFinAG/JPNL RAf25F8/1IiU9NMkyhWffSmSyzYS07xjIIdAheiAeretbiEvThXlUcPH1lkAQDWH/pTEkN6pweHvt t1c9VHOggGGLm8xf30VVKSSLefWoGfLJn1F8TM99bcErO9JVKufz5r2TbSMxfw8ZAmjGsFkjdUNEm 0aF27rM4BhKUEdDrYBRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBtzp-00Dpgb-2p; Wed, 21 Jun 2023 09:19:25 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qBtzm-00Dpff-1f for linux-arm-kernel@lists.infradead.org; Wed, 21 Jun 2023 09:19:24 +0000 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35L6S9jI014635; Wed, 21 Jun 2023 09:19:06 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=vAU1Ys21VigpVm04YN3UwYN6qhXIfFW/h2O0LO0OSkQ=; b=W8tHjkD+x3IpP0NQZ+x4link8tgA1je6GgNR3qMxzb1G8Q7mLZEIwAy0h/b/c2EuG9rH mqRyByOkozGtH9vCl3WD3EwmTyWiYoNeIaftkyqIE88WxCff+0gWXxpNPAQYsyTto3At QAtQK2WTVDvbGFw4M57+1zbeJmaDfxYo0ulSbSEJZXY3j0r+3jppKqV/Qaf9G4TWi4h2 RnIW7nzhe+bSebmKvDxd2lwUMmTS92w4/N7IVoFbZHX2BLjR86mN7WJisU8qlpMBCw/V 0dP4sVYu1incJa6al3MHYlJ2t2Q9BtJ8yZzyCT2Udpt37FA3tbW8jkh7TAFGpKyrBNrD Bg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rbqkh0rwc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 09:19:06 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 35L9IsJE015739 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 09:18:54 GMT Received: from [10.50.7.175] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Wed, 21 Jun 2023 02:18:49 -0700 Message-ID: <31cb09ae-dbb8-8ba0-08dc-fcc2af63ca30@quicinc.com> Date: Wed, 21 Jun 2023 14:48:23 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH V23 2/3] misc: dcc: Add driver support for Data Capture and Compare unit(DCC) To: Greg Kroah-Hartman CC: Andy Gross , Konrad Dybcio , Krzysztof Kozlowski , Bjorn Andersson , Rob Herring , Alex Elder , Arnd Bergmann , , , , , Sibi Sankar , "Rajendra Nayak" References: <2259ab0348282349e88905ea99bcb4aa815d941f.1683265984.git.quic_schowdhu@quicinc.com> <2023061542-reformed-unholy-10a3@gregkh> <2023061515-unbuckled-consonant-e207@gregkh> <5d9ab90f-4fc3-26c6-141e-e9388ac2f0cf@quicinc.com> <2023061548-subtly-cackle-8be2@gregkh> Content-Language: en-US From: Souradeep Chowdhury In-Reply-To: <2023061548-subtly-cackle-8be2@gregkh> X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: QQgPXKIzyOTwBP_LMUYqItkgCave8iml X-Proofpoint-GUID: QQgPXKIzyOTwBP_LMUYqItkgCave8iml X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_07,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=869 priorityscore=1501 bulkscore=0 clxscore=1011 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210079 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230621_021922_565275_552A0F3E X-CRM114-Status: GOOD ( 26.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 6/15/2023 7:36 PM, Greg Kroah-Hartman wrote: > On Thu, Jun 15, 2023 at 07:17:34PM +0530, Souradeep Chowdhury wrote: >>>>>> +static ssize_t ready_read(struct file *filp, char __user *userbuf, >>>>>> + size_t count, loff_t *ppos) >>>>>> +{ >>>>>> + int ret = 0; >>>>>> + char *buf; >>>>>> + struct dcc_drvdata *drvdata = filp->private_data; >>>>>> + >>>>>> + mutex_lock(&drvdata->mutex); >>>>>> + >>>>>> + if (!is_dcc_enabled(drvdata)) { >>>>>> + ret = -EINVAL; >>>>>> + goto out_unlock; >>>>>> + } >>>>>> + >>>>>> + if (!FIELD_GET(BIT(1), readl(drvdata->base + dcc_status(drvdata->mem_map_ver)))) >>>>>> + buf = "Y\n"; >>>>>> + else >>>>>> + buf = "N\n"; >>>>>> +out_unlock: >>>>>> + mutex_unlock(&drvdata->mutex); >>>>>> + >>>>>> + if (ret < 0) >>>>>> + return -EINVAL; >>>>>> + else >>>>> >>>>> You do the "lock, get a value, unlock, do something with the value" >>>>> thing a bunch, but what prevents the value from changing after the lock >>>>> happens? So why is the lock needed at all? >>>> >>>> The lock is used to prevent concurrent accesses of the drv_data when >>>> scripts are being run from userspace. >>> >>> How would that matter? The state can change instantly after the lock is >>> given up, and then the returned value is now incorrect. So no need for >>> a lock at all as you really aren't "protecting" anything, or am I >>> missing something else? >> >> This lock is needed to protect the access to the global instance of drv_data >> structure instantiated at probe time within each individual callbacks of >> debugfs. > > What exactly are you "protecting" here that could change in a way that > cause a problem? > > You aren't returning a value that is ever guaranteed to be "correct" > except that it happened sometime in the past, it might be right anymore. Hi Greg, The lock doesn't add any value in this particular case and I will be dropping it from here but in other cases it is being used to protect the concurrent access of the data-structures used inside the drv_data mainly the list which is being used to append register configurations, write the configuration to the dcc_sram and also delete it while doing a config reset. The lock is also used in case of software trigger to read the bitmap of the lists to set register values. Thanks, Souradeep > > thanks, > > greg k-h _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel