Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp769708lqt; Tue, 19 Mar 2024 03:22:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwVwfW7hzy1fMYXpXZl9CGdFArOjF+Xq7dd8eBZ/0H0bRNiTN8Y3OwFNNNVAyqGv9TXLhm8sOBHBbRLBVRxtwG8ejuCG1bPebZsO8GVg== X-Google-Smtp-Source: AGHT+IGJ6N+GDMc6kHjKislLWXXPmvNzsPHFK9yY5j2XVcS22TBECh+GLsERC34JNYtQHJONYMlc X-Received: by 2002:a17:90a:a78a:b0:29b:af61:fb34 with SMTP id f10-20020a17090aa78a00b0029baf61fb34mr2435153pjq.34.1710843764295; Tue, 19 Mar 2024 03:22:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710843764; cv=pass; d=google.com; s=arc-20160816; b=CZ42Lu/RzZu+uRa44l/1+AoIGxegQQ2Y1AXlfDixM4pnWlKOGrahmhPlKHCCF90IuD vGIPS5SPlFguQy2YvDy6BS3LiT7vkTo+hFO0YyY0UZcWiJd2nedyStHUZQDHPbVeWGVo 9ivdyB5bhOA9gg/e5ZW9TcZKKrZuhR4ipxe1qmUhT/bZfP8pF7C3A8TBy/koqP2kXBBf 4IX0xkR+5an7HnxCDxkYRHX/LMkmqxYpVXYzkCg6L59L5oFosP7JtC0QypmrD6fdWoyz FH6TExbC8lEokIHWiJYq6LDq8e1rpCMRjsiyx89PRQRGcvVywC8EPr4XywHVM6h8l1tf tB5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Hn0IAkDGDhCgHfQvbQRjTSXdhr05Qbnhtd+g28g+Bss=; fh=08PZZ8gyBAPuOQ0ubDlPRUv+eaLQpXD0DWNM2kKdaRw=; b=SzRRvxo9ojVGUbeSSg84EnKjtY4kQI9pKH6PfaIOWBrt6fs7UiwYhHYSanagVISTOw Lfw6B7zSyST4vAhLZ4rpvbk1lxrlhXqJ7dfPbneFpHbmMtb/mcQ28fUDoKNzdOb8WidI MGxA6ew/ypBj9bzGPtmOOqK+SbFQYeN8DVoKCXS/uzRcBrv57/xNuK/RC+vzegM/bajV Epg+JpTZeH9MJAMjwXkOYAK1+uZ52LkmF6JKKPl72yyonJeEuszGCbbVtE9NzIJS3YMX prflRfckgRz/GiDpkcKzWOKTdgKxc/TIsFlcvLf9JJLPAhICwlaB8sktUg2ApbqdxG0u 3Z0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="YruXD/2n"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-107380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107380-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k35-20020a17090a3ea600b0029b77c1d3ecsi9955002pjc.16.2024.03.19.03.22.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 03:22:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="YruXD/2n"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-107380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107380-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0C079B21455 for ; Tue, 19 Mar 2024 10:22:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6BDA7D419; Tue, 19 Mar 2024 10:22:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="YruXD/2n" 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 721F97D096; Tue, 19 Mar 2024 10:22:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710843756; cv=none; b=AtHGI0J1p259QcSGoItel3eh8jjk1z1h9Nhbeajggldd+TVSEn4xuv7rupQSMwT9syqD+Op99o91na51FXSMQ9ccE1JNslkNAweEeT9r1mqrBVI4FChjSYCidSZuCarrNxSJCVKh0Bhe0EOSPI3yOtAubkwUm5CRI/57MvtKHbo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710843756; c=relaxed/simple; bh=W3jZVNvJ0NPlQQ3uSaUdcc+IdClJd8FvQrdxHQKRd5Q=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=feHfo5Lzf++KS6RUOGNrF2wsCgEkyDHUbc5IGqh6hk+1puyfkm7r4ScmqJDUNirrH10IzITDK6Sf+Wgr/dMzaW3fYwe+sWSonUAuQa6tvBDkDiVcY8WmeGG0kwnmo+Eg+w5Z5YwpJ2hBsyUSi+wjPOWQToH7SaVKtUc+8ZmTi0M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=YruXD/2n; arc=none smtp.client-ip=205.220.168.131 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 42J8Ql9w013321; Tue, 19 Mar 2024 10:22:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=qcppdkim1; bh=Hn0IAkDGDhCgHfQvbQRjT SXdhr05Qbnhtd+g28g+Bss=; b=YruXD/2nqByMOQAXjS9Wda7tEx4DiUt4HVc9u w4ovBDOP3V1yc8LRUYqUk36RbwD8MHGGb+0vjlSHBtILc5on7tW0rEOrLupftQX7 j/92hPmJRN0xqlX/k2col40z0e5Iki+By5ALSGC34gpKdoM8SLy6rksTywiD30r3 Z6jniOonj6Wfs7CJlJ0m863Xeg79Q6Thw3zPmiy+Ia+WQ+Qb29YL0tQqXag6VFwr weT+d2/tewQgqVpbqT/VYLhIGJmh+SM4V9ifOfD6gqDcj8fAgOpvk78AgJ+sPOsj g4kfKkpQELp6eK3x+V0HaScMbYcyX5sXyrZ4sqPIUY0NE4jJw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wy5pprgmc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Mar 2024 10:22:29 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 42JAMSaa012837 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Mar 2024 10:22:28 GMT Received: from hu-pkondeti-hyd.qualcomm.com (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.1118.40; Tue, 19 Mar 2024 03:22:25 -0700 Date: Tue, 19 Mar 2024 15:52:22 +0530 From: Pavan Kondeti To: Mukesh Ojha CC: Pavan Kondeti , Bjorn Andersson , , , , , Subject: Re: [PATCH v12 7/9] firmware: qcom: scm: Fix __scm->dev assignement Message-ID: <60535d91-3610-4610-ae1a-46b8e3ccd4fa@quicinc.com> References: <20240227155308.18395-1-quic_mojha@quicinc.com> <20240227155308.18395-8-quic_mojha@quicinc.com> <260371ff-da7a-8406-0511-4019f6b860bf@quicinc.com> <03367100-1ad4-4d83-8200-5879550398be@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="us-ascii" Content-Disposition: inline In-Reply-To: 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-GUID: Yq--i3YQ3gsyJFrz-T9yHuwjvWBpIP0X X-Proofpoint-ORIG-GUID: Yq--i3YQ3gsyJFrz-T9yHuwjvWBpIP0X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-18_12,2024-03-18_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 impostorscore=0 malwarescore=0 clxscore=1015 bulkscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2403140001 definitions=main-2403190079 On Tue, Mar 19, 2024 at 03:38:57PM +0530, Mukesh Ojha wrote: > > > On 3/19/2024 6:47 AM, Pavan Kondeti wrote: > > On Mon, Mar 18, 2024 at 06:38:20PM +0530, Mukesh Ojha wrote: > > > > > > > > > On 3/3/2024 12:55 AM, Bjorn Andersson wrote: > > > > On Tue, Feb 27, 2024 at 09:23:06PM +0530, Mukesh Ojha wrote: > > > > > qcom_scm_is_available() gives wrong indication if __scm > > > > > is initialized but __scm->dev is not. > > > > > > > > > > Fix this appropriately by making sure if __scm is > > > > > initialized and then it is associated with its > > > > > device. > > > > > > > > > > > > > This seems like a bug fix, and should as such have a Fixes: tag and > > > > probably Cc: stable@vger.kernel.org > > > > > > > > > Signed-off-by: Mukesh Ojha > > > > > --- > > > > > drivers/firmware/qcom/qcom_scm.c | 2 +- > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c > > > > > index 6c252cddd44e..6f14254c0c10 100644 > > > > > --- a/drivers/firmware/qcom/qcom_scm.c > > > > > +++ b/drivers/firmware/qcom/qcom_scm.c > > > > > @@ -1859,6 +1859,7 @@ static int qcom_scm_probe(struct platform_device *pdev) > > > > > if (!scm) > > > > > return -ENOMEM; > > > > > + scm->dev = &pdev->dev; > > > > > ret = qcom_scm_find_dload_address(&pdev->dev, &scm->dload_mode_addr); > > > > > if (ret < 0) > > > > > return ret; > > > > > @@ -1895,7 +1896,6 @@ static int qcom_scm_probe(struct platform_device *pdev) > > > > > return ret; > > > > > __scm = scm; > > > > > - __scm->dev = &pdev->dev; > > > > > > > > Is it sufficient to just move the line up, or do we need a barrier of > > > > some sort here? > > > > > > Would be good to use, smp_mb() before the assignment > > > __scm = scm > > > along with moving below line > > > __scm->dev = &pdev->dev > > > > > > > Full memory barrier is not needed here. store variant is sufficient. > > WRITE_ONCE() + smp_store_release() will fit here no? > > Thanks for the comment, i again have a look at it and agree we don't > need a full barrier here. > > And we can do either of the below two ways. > > -Mukesh > > > // 1st way > > diff --git a/drivers/firmware/qcom/qcom_scm.c > b/drivers/firmware/qcom/qcom_scm.c > index 49ddbcab0680..b638fb407fc6 100644 > --- a/drivers/firmware/qcom/qcom_scm.c > +++ b/drivers/firmware/qcom/qcom_scm.c > @@ -1741,7 +1741,12 @@ static int qcom_scm_qseecom_init(struct qcom_scm > *scm) > */ > bool qcom_scm_is_available(void) > { > - return !!__scm; > + bool avail; > */ > bool qcom_scm_is_available(void) > { > - return !!__scm; > + bool avail; > + > + avail = !!READ_ONCE(__scm); > + smp_rmb(); > + > + return avail; > } > EXPORT_SYMBOL_GPL(qcom_scm_is_available); > Your original problem statement: qcom_scm_is_available() gives wrong indication if __scm is initialized but __scm->dev is not. This does not require read side barrier as there is an address dependency. If the writer does it *correctly*, the reader would always observe __scm->dev != NULL when __scm != NULL without any barrier. Thanks, Pavan