Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp85454rdb; Wed, 29 Nov 2023 21:38:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwkPHqgBwMH51BZ9kTJwrrhdRLBUtVH3b0usX8LGXoWSjBoM3hgM62iJFPl1+6AV44n4Lr X-Received: by 2002:a05:6a00:1888:b0:6cd:daa5:1398 with SMTP id x8-20020a056a00188800b006cddaa51398mr4117380pfh.9.1701322699362; Wed, 29 Nov 2023 21:38:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701322699; cv=none; d=google.com; s=arc-20160816; b=0zyuZqL+odOyLwaLzb1zlRfUdwu04PXjNbQumDrHJOg2U5nsgYugn5aorJj/iis2rP NaeFXlkH8SjDyXGZW3jBbbwz6yrmttmqyAyNVx1mOTa0BnR+KKX2sWPAQT4CTgnmufTV Kb7TLWx3MqRY5E55c/PUZLR1D45GQ+tCClennhDz28s0qyHBzTDXOi1gJwnboVrIU2oS rQXeHucTtkGaEFeFcbjXVsfk6/yJPZMsDsS3USrm+pjuehdMaPdEthhgmMAoh/g0DtyA N4juqvEvl0gz81nlwySQB6xMe5bZVTB9fkreVdZkaMCw1fGIvJCBoFaGnfEtUbDD7UYV C+Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=IQ9Dg6khK07xMiIBzuk7297S9BV6a1vgqK58LceC2J0=; fh=sgXmjX/pgDufeH4EsbD7MI/04N1cfyITlb/HboB1ogY=; b=WQU93sEd7NHZH9PLEw5OUqcaVRcsr8+6rQrYwC8dRXYhpgT17NzfDLGI4E5PVSuC/T jrv0sxv+O3ylw1SpUJyD/VOFVCi/upJpFsXEPV8SKTXSFxOApa55G3M+JlrOIQk7MIjI TsVbwlLObTBOliwqDHLBU2PAYG5QnvS50wTcwrwdw1rTdW+7vW3Swj691cpvqQqJdJDI t4vz9MVjTgiembhpXZmf/pSrwuuqnTZcEvYP018yFW52xXm3ksAg3VWjSNI0Zua6DD0R J9q3lqScvX1gZzOMXlTVlyhLtzgf3cVCUT5ntXbu1GkNvY9DdiWaSNwqDurZlzrYoGac mp7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JuJD0AIy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id q18-20020a635052000000b00577f67a0614si531231pgl.879.2023.11.29.21.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 21:38:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JuJD0AIy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9A62B8077857; Wed, 29 Nov 2023 21:38:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231646AbjK3FiA (ORCPT + 99 others); Thu, 30 Nov 2023 00:38:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjK3Fh7 (ORCPT ); Thu, 30 Nov 2023 00:37:59 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DB1F198; Wed, 29 Nov 2023 21:38:02 -0800 (PST) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AU4rmH0004391; Thu, 30 Nov 2023 05:37:56 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=IQ9Dg6khK07xMiIBzuk7297S9BV6a1vgqK58LceC2J0=; b=JuJD0AIy9kdSpuImpU6k2rr8CK+cbVAyuRRQ/tNs4XOLIE1n334jag0BpMgJ+XRbF4G4 QdczhBW8Hi76mvmq+aqARxHfNVSihOAPiICkl40ayz/dUnwD/q6nEFHUOOxwpjI7q7ay NpRdj7do3XWhXlA7Q1uREhLNQ4Fza6dSex/Hu+3FQ/t3dsnbEC9MuHpYHN20u5H0viTw m1j4QCLwHl/iU13K9K1yK1bwlbuuxS4lank1+hmurht2S4zs/3Peu5udp7XYGUlpvkfL 9tpT/Otu3k0mR1zS6Q0XgqLMVZZjkjhmgm6mD7AratuB65vW63TiIjYuoXDSe0G8UEXp bg== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3up5e8t99b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Nov 2023 05:37:56 +0000 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 3AU5bt4G004641 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Nov 2023 05:37:55 GMT Received: from [10.239.133.73] (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; Wed, 29 Nov 2023 21:37:54 -0800 Message-ID: Date: Thu, 30 Nov 2023 13:37:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [GIT PULL] Pin control fixes for v6.7 To: Linus Walleij , Linus Torvalds CC: "open list:GPIO SUBSYSTEM" , linux-kernel , Charles Keepax , Chester Lin References: From: "Aiqun(Maria) Yu" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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: 3Uv19rQtdR-Dh05KVC5dC-5hsS6i6MBx X-Proofpoint-ORIG-GUID: 3Uv19rQtdR-Dh05KVC5dC-5hsS6i6MBx 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-11-30_03,2023-11-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 clxscore=1011 impostorscore=0 adultscore=0 mlxlogscore=933 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311300041 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 29 Nov 2023 21:38:16 -0800 (PST) On 11/29/2023 11:08 PM, Linus Walleij wrote: > On Wed, Nov 29, 2023 at 3:56 PM Linus Torvalds > wrote: >> On Wed, 29 Nov 2023 at 04:09, Linus Walleij wrote: >>> >>> The most interesting patch is the list iterator fix in the core by Maria >>> Yu, it took a while for me to realize what was going on there. >> >> That commit message still doesn't explain what the problem was. >> >> Why is p->state volatile there? It seems to be a serious locking bug >> if p->state can randomly change there, and the READ_ONCE() looks like >> a "this hides the problem" rather than an actual real fix. This is indeed an interesting issue. Thx for the comment, Linus. **Let me explain how: "p->state becomes volatile in the list iterator", and "why READ_ONCE is suggested". The current critical code is: list_for_each_entry(setting, &p->state->settings, node) after elaborating the define list_for_each_entry, so above critical code will be: for (setting = list_head(&p->state->settings, typeof(*setting), node); \ &setting->node != (&p->state->settings); \ setting = list_next(setting , node)) The asm code(refer result from Clang version 10.0) can cleared explain the step of p->state reload actions: loop: ldr x22,[x22] ; x22=list_next(setting , node)) add x9,x8,#0x18 ; x9=&p->state->setting cmp x22,x9 ; setting,x9 b.eq 0xFFFFFF9B24483530 ldr w9,[x22,#0x10] ; w9,[setting,#16] cmp w9,#0x2 ; w9,#2 b.ne 0xFFFFFF9B24483504 mov x0,x22 ; x0,setting bl 0xFFFFFF9B24486048 ; pinmux_disable_setting ldr x8,[x19,#0x28] ; x19=p, x8=[p->state], *reload p->state* b loop The *reload p->state* inside the loop for checking is not needed and can cause possible infinite loop. So READ_ONCE is highly suggested even if p->state is not randomly changed. And then unnecessary "ldr x8,[x19,#0x28]" can be removed from above loop code. **Comments about the locking bug: currently pinctrl_select_state is an export symbol and don't have effective reentrance protect design. That's why current infinite loop issue was observed with customer's multi thread call with pinctrl_select_state without lock protection. pinctrl_select_state totally rely on driver module user side to ensure the reentrant state. Usually the suggested usage from driver side who are using pinctrl would be: LOCK; pinctrl_select_state(); gpio pulling; udelay(); check state; other hardware behaviors; UNLOCK; So the locking bug fix I have told customer side to fix from their own driver part. Since usually not only a simple pinctrl_select_state call can finish the hardware state transaction. I myself also is fine to have a small per pinctrl lock to only protect the current pinctrl_select_state->pinctrl_commit_state reentrance issues. Pls any pinctrl maintainer help to comment to suggest or not and I can prepare a change as well. > > Thanks for looking into it Linus, Maria can you look closer at this and > try to pinpoint exactly what happens? Sure, I am trying to explain from my end. If there is other thoughts pls feel free to chime in. > > Is the bug never manifesting with GCC for example? > > In the meantime I'll cook a fixes branch without this one commit. > > Yours, > Linus Walleij -- Thx and BRs, Aiqun(Maria) Yu