Received: by 2002:a05:7412:d002:b0:f9:9049:d2ea with SMTP id bd2csp28552rdb; Wed, 20 Dec 2023 03:02:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAHSwyJkg9GEjbA8Ckoxy05QjBmNjRUNrwZ6YuzNUr+rkxzmjgrP7yRdJkHLSLmOB+hl4y X-Received: by 2002:a05:6a00:a0f:b0:6ce:6246:2a17 with SMTP id p15-20020a056a000a0f00b006ce62462a17mr12392117pfh.3.1703070171721; Wed, 20 Dec 2023 03:02:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703070171; cv=none; d=google.com; s=arc-20160816; b=iw5/YOkO8xYeXcDxLVTDEYVvG/0oheyF50FVBI0znAgkCwTz8wy2YumcfoJ2/6M5pB 61Rebu8CqVXBholw09dL1N6Ij71a7pawTMxaeI8M9/oBuLM95u7cjSVdynK+/DNDzvb/ 4pIfC/G+TNK4y0/wk7KrRX1bzsCGJEPS/NEKNv5BQYiF5A4f/rPkw0Cx5BEkSYEkoRIA gnSpuiPPhVyd5CgLiIHJx9mQ7WbBXgqx/FJiALfdgFRGIwba9Q7jcSIUIQLYAqG5/AOR dHYSDFXGW4HPHAQeJ8ikxDIG2LrTQDVe5eWsEsNG5HTSwatqd6QwclV/E484mQn78jIq /Ghw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=nWZSCVRWyRcXn4WJEnxmsNNdBu46mpN/PeFPjmLZcSo=; fh=/nrZ34yELqFBE60xUCVMsf5Xs0i2i1k46RuDfRNlqEY=; b=hTKqsOZzLRZ7kRmFo3awU0NLfvjzQY6YS/jzNwIcuR6bN9qrRYsWV2wdTAkOJb/ZxO Q5klu+0bdPmu3khVz0MIVPYd2/GRFrmOn88ouJdgyz1FQBuS1jTxeVG9KhZ0/4+rIqRL urn3oPkYLHTonbr+g0t9AC5zByTWYRDZ1sqAx6M1IOmugWTwgi20EgVMSMY/RUXxl/sp tc7bOa92MAwOCjs8TmBkfwCTtHhnaGLlr2ZadSKKHzW7Ttj03eEh4cHvfIQvRTrH4iTv /xe234FQ0DNQFtAK7jSILhVY00HkaVXTzh5tq7YpEBss0qqiUxfLEEeh7b1VvlMLhaqM EdXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dc1lT+rN; spf=pass (google.com: domain of linux-kernel+bounces-6785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6785-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i17-20020aa78d91000000b006d7d080b926si4921135pfr.179.2023.12.20.03.02.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 03:02:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6785-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=@linaro.org header.s=google header.b=dc1lT+rN; spf=pass (google.com: domain of linux-kernel+bounces-6785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6785-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 5C628287802 for ; Wed, 20 Dec 2023 11:02:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6B2321351; Wed, 20 Dec 2023 11:02:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dc1lT+rN" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 336E7210EF for ; Wed, 20 Dec 2023 11:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-5d33574f64eso45387907b3.3 for ; Wed, 20 Dec 2023 03:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703070148; x=1703674948; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nWZSCVRWyRcXn4WJEnxmsNNdBu46mpN/PeFPjmLZcSo=; b=dc1lT+rN4Jk1cfhR9kpv3m6Eokb0zL1DeRVZZFb8FpS+LSLEY8OMDzET4PmijmLtT2 O7QKXk4qQ3Jy5nnA3nLM5mR9Jjvh/m9GWCQYPWm8HLpMxqTEcT35Si55MWb6/IoNGswR pTPVVvXcerCAqo0ODQ9iYkQVgwRgo2fJHz5xiHbQFeyvCyPIiJwGcP2TLQJ1EVqkzx6I uZ6mNHj+1s+/uddVt6CzJ7fJfXJxIiDSXJZbFtfFstXzsonly6GuGx05UnTczE/ZVBg+ GT0h9puyl/ll1mn6Agb31cAHynel0HrCuVSsMRsfqeuGrTLkmWO/nFCL8bZQWpJ+Ut+7 9qxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703070148; x=1703674948; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nWZSCVRWyRcXn4WJEnxmsNNdBu46mpN/PeFPjmLZcSo=; b=R17ro7MdD+BP88IJx5tSkTkuVF1U+YYQ5ZaTal9Dij45AmRW7YuP7Z7CZHKjJhH1zt aSe/QumW+UBaeudz0rZ3EUDCrYab90ouZJZul0sp26IJyAAEsELXLbf0jFZhHGG2+5jk Gs5pJpFGMyWYfDYPY7sEWjShA1v7Wv4lTnY5bfj2b3eY3AOYOqGePOMDXl5/9GOOaJIv tTm8B5dHpm1wwIrT4p/lmNQrj1toMoyWiAm7qYo/YAgFblLWqejtRzUnvIkXITSnGqMJ XY5MvoT61KWgl0ac7spFWiuxIitV+7OKoEuKbEEb1cPxGU6MKN1ZhU5x+M2sC3KpdxOB Q+ZQ== X-Gm-Message-State: AOJu0YyqWS8WdLyNeKyzF2T6GvRYyFHJiy0lrUv2B19HCeSaDHozXnXb +SPjw/9I3zI/Ww/33LWwR6zoZbJvniDi8nYmDBBScA== X-Received: by 2002:a0d:ea11:0:b0:5e7:ebc6:984 with SMTP id t17-20020a0dea11000000b005e7ebc60984mr2065348ywe.84.1703070148183; Wed, 20 Dec 2023 03:02:28 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231212090611.950-1-quic_aiquny@quicinc.com> In-Reply-To: <20231212090611.950-1-quic_aiquny@quicinc.com> From: Linus Walleij Date: Wed, 20 Dec 2023 12:02:17 +0100 Message-ID: Subject: Re: [PATCH v2] pinctrl: Add lock to ensure the state atomization To: Maria Yu Cc: andersson@kernel.org, kernel@quicinc.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Maria, On Tue, Dec 12, 2023 at 10:06=E2=80=AFAM 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 *p= ctldev, > static int pinctrl_commit_state(struct pinctrl *p, struct pinctrl_state = *state) > { > struct pinctrl_setting *setting, *setting2; > - struct pinctrl_state *old_state =3D 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()? #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