Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp2170388rdb; Sun, 24 Dec 2023 22:13:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmHBGhsZAyBHj0OMPjauqhXhCeEBU8xnG/vwsfWUa9wnDcKYWFE38UrtgH9skaBSaW4y09 X-Received: by 2002:a9d:7d1a:0:b0:6db:a406:d5b7 with SMTP id v26-20020a9d7d1a000000b006dba406d5b7mr3721268otn.61.1703484818655; Sun, 24 Dec 2023 22:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703484818; cv=none; d=google.com; s=arc-20160816; b=OYJ8tFiMiMrPAcayOoDrW6YLfzmRZJbMb5Yen4Nsv9qmUlP1DMSZgQ5L8tZLUoueFl ImBcB6ZA5b1Quh0vdQAzGpdnFk8VBn1PSVSck08srD/qgNnzHKDjcNajuYVpoceJIvFB 1ahtxd2sPqq/TCfoeWOD7aINuwcd1q2WP+XgT6kjTLP/kTknZH2KyX+BumxV1ZVe57z0 I55jN3BKPqgJ69xahmSxC3AiMwHaCMf0KCvqJZ7iGB+5CppEb/KRvYrRCk4Ljtch5bLP XNj1tFE+hLb14hU/gYDzHcz+t6HdJQPBuUsASkwg0xt9AAHBJYbdalNKqCGxtyN61LkK XqtQ== 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:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=N0UEdLDAQUomhdx40Nl1VF0nJCvYxde5CcvFj+y08kQ=; fh=4icPYejiZpSgRLGzqqAwr1YbXR39HKGEitEWin88hYo=; b=b4F/br715wQtcBG8RAiuqSZ5oNQ8TPlM0L0d9wOXKvG1xB9FrsYlkn6eFMZW7GBvIs NV95rFog5c7svepGY7pnRKONvPAfPFWO9kO5YTcBby65u1jyBSILL8dDG/9iQnMOUzuI OUQBHNxs5DRb/1Wu4dMJ2aB9SyhhY7c4paUQiAbPWR2/DvCFp9j4sAL0ajP1NbfObdHE Gh5GrsvJK1UNLFOOwxd3iyGK7z+OSPmyKjnqsajNHdjA8yBMEIma3o6jEGLVrwFWFXcH gMnapx9zv88MnnDj+m4VgLncmieEDXITMZHkbrWI/TFuP18wo67o7AjCGyFHtgq2sm08 w/WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Vhqe498v; spf=pass (google.com: domain of linux-kernel+bounces-10900-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 11-20020aa7924b000000b006d972181bc8si6859876pfp.5.2023.12.24.22.13.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 22:13:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10900-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Vhqe498v; spf=pass (google.com: domain of linux-kernel+bounces-10900-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10900-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 66E072817A2 for ; Mon, 25 Dec 2023 06:13:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ADB4515B0; Mon, 25 Dec 2023 06:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Vhqe498v" 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 7CB451846; Mon, 25 Dec 2023 06:13:27 +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 (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BP5xKoc008073; Mon, 25 Dec 2023 06:13:23 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=N0UEdLDAQUomhdx40Nl1VF0nJCvYxde5CcvFj+y08kQ=; b=Vh qe498vXsr/aOQ5X+JVPd8HqDVPgcXSr5xMvLeKOxQ1r3IZFM8F9KQBecptcIi1ka UGpKz9koyIz34FisDxHudcYkUgt7C5Qb8YoOVcFJ3p66z1NoQQ+9pvArUsGwuyr9 0cjP7z++7zR2i9nNgPQMLE2GeneAF91ckRuCo2Fpp9PFvCUcBI141C7V+KeURw9E NXQZz4303LaQOzGA4SGH3dx/MD8Qhx0OPBM65oFHJG2WkmC4Al4/WIyWmzCVQB1C yVeGJfv2s0wWFBYFn4wRcLoM3ILeVjaeundGj7dF7heEidSgb0aGAe7iOr89qHDj PVdF28u5T+KITqPm4U4g== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3v5raku13w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Dec 2023 06:13:23 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BP6DMkg003579 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Dec 2023 06:13:22 GMT Received: from [10.239.132.150] (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; Sun, 24 Dec 2023 22:13:17 -0800 Message-ID: <52ee95c2-1118-4f44-85e0-862ac5f83257@quicinc.com> Date: Mon, 25 Dec 2023 14:13:14 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] pinctrl: Add lock to ensure the state atomization Content-Language: en-US To: Linus Walleij CC: , , , , References: <20231212090611.950-1-quic_aiquny@quicinc.com> From: "Aiqun Yu (Maria)" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit 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: 4cjNcax0jBjGDfAU6EmVVsuUhFJN9NjC X-Proofpoint-GUID: 4cjNcax0jBjGDfAU6EmVVsuUhFJN9NjC 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 impostorscore=0 spamscore=0 malwarescore=0 bulkscore=0 adultscore=0 mlxlogscore=674 clxscore=1011 phishscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312250044 On 12/20/2023 7:02 PM, Linus Walleij wrote: > Hi Maria, > > On Tue, Dec 12, 2023 at 10:06 AM Maria Yu wrote: > >> Currently pinctrl_select_state is an export symbol and don't have >> effective re-entrance protect design. During async probing of devices >> it's possible to end up in pinctrl_select_state() from multiple >> contexts simultaneously, so make it thread safe. >> More over, when the real racy happened, the system frequently have >> printk message like: >> "not freeing pin xx (xxx) as part of deactivating group xxx - it is >> already used for some other setting". >> Finally the system crashed after the flood log. >> Add per pinctrl lock to ensure the old state and new state transition >> atomization. >> Also move dev error print message outside the region with interrupts >> disabled. >> >> Fixes: 4198a9b57106 ("pinctrl: avoid reload of p state in list iteration") >> Signed-off-by: Maria Yu > > Overall this looks good! > >> @@ -1262,9 +1263,12 @@ static void pinctrl_link_add(struct pinctrl_dev *pctldev, >> static int pinctrl_commit_state(struct pinctrl *p, struct pinctrl_state *state) >> { >> struct pinctrl_setting *setting, *setting2; >> - struct pinctrl_state *old_state = READ_ONCE(p->state); >> + struct pinctrl_state *old_state; >> int ret; >> + unsigned long flags; >> >> + spin_lock_irqsave(&p->lock, flags); > (...) >> + spin_unlock_irqrestore(&p->lock, flags); > (...) >> + spin_unlock_irqrestore(&p->lock, flags); > > Is it possible to use a scoped guard for pinctrl_commit_state()? Good idea. I will address this in next patchset. > > #include > guard(spinlock_irqsave)(&p->lock); > > It saves some code (and no need for flags) and avoid possible > bugs when people add new errorpaths to the code. > > Yours, > Linus Walleij -- Thx and BRs, Aiqun(Maria) Yu