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 92CA3C43211 for ; Fri, 26 Jun 2026 15:02:10 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date: References:MIME-Version:In-Reply-To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=m/plLMVG5FB7dS1VHSbkkRzjZmO3Qd9qn+nkhoPyF34=; b=CtjLzWF73xd18rME07FCawqWpU aMkS4X+DwZMEbJUn5l171FgYSb+v9sPNHQusfaBDpg4STyiNqfoFu49idg2XEGtlyt5DeaPGTKCdJ pcl871nJm7lGhr26p3nB33zTlfTJv8aRgFCNKAnfHiPzlkScadGVZ52BE+SkPpgwpBjeiJgW0Sb1F 371mon/XGI5C3JD1QVDS1WDHZNUhS/9+VnZvzLzumMXvogkLW5wMTnFMR9+k3wu8kScTIEVQg/+Zf wtUh31Sem6iW0wiCjQ4TEKFjRRilZrzNUlPNJelV+rmgvzK8RcJ+GH/2wggI0UHCxbEXTRvV9odYn lMJLiKmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wd84A-0000000BWAV-1dNf; Fri, 26 Jun 2026 15:02:02 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wd848-0000000BW9v-1v5G for linux-amlogic@lists.infradead.org; Fri, 26 Jun 2026 15:02:00 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id BF829406AF for ; Fri, 26 Jun 2026 15:01:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A39AF1F00A3E for ; Fri, 26 Jun 2026 15:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782486119; bh=2M3/dhcHypRoDMmOlgNYAmiMTmUReoTtADf6M6SzpP4=; h=From:In-Reply-To:References:Date:Subject:To:Cc; b=LGOxQI/OOYjyDQFJ2+bfO91MG6+ldr2pktHxTsGRAyA9V1zCq1Gj3KMYQLiOJCBuq qKYDc+WS4daRh7hU1Gx0dACBHprBNvw4HM+YSCV+qmqpfadTK/v7YvW6/e0vV2gX+g IfoQxno9I/oEF+iIG4jwrcif0X0JXbFH9vw8hQGtBlzpmwjZZVBvkyDRgVLSYktRgQ pwYY/savWCBNKc3H7tU1iMeiopasNQ9g5PLCPhZcKSelwsduHFLx8PRibFW17j2V+X oKcr30zquQYB7oWugAswMKvhvDNgK2XSkRxYiJmABhl/Rru8eD8HaCNtgHhmGu336d ZvOfq9OyEOdaQ== Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5ad4f39064bso665150e87.3 for ; Fri, 26 Jun 2026 08:01:59 -0700 (PDT) X-Forwarded-Encrypted: i=1; AHgh+RopGTysUCYkMR9wFq8mbXLLoZq8lfWgKx8La5KHvNLUgT3i1bhC+xcjNW9JcY0BLgvE4J+IUQnnMIBE9j4R@lists.infradead.org X-Gm-Message-State: AOJu0YwsmXRaLdi39jQR5N0cSI3JXQ08oBPzONz/hiOnHblZeuZHFSg4 cd9E88BVZj68m4Fk4c35gUWqc5WmE2XhKpR3ZJPYF4IEijlRt6IPHZGrDDXn6Evv94IpA2Fb5Tv lvwwOlsTJqjOZV/2DnoFhJ675MjU4N6D6UQ7f3Fstuw== X-Received: by 2002:a05:6512:4408:b0:5aa:6d0e:9d2d with SMTP id 2adb3069b0e04-5aea1f3c218mr2391832e87.20.1782486118352; Fri, 26 Jun 2026 08:01:58 -0700 (PDT) Received: from 969154062570 named unknown by gmailapi.google.com with HTTPREST; Fri, 26 Jun 2026 15:01:57 +0000 Received: from 969154062570 named unknown by gmailapi.google.com with HTTPREST; Fri, 26 Jun 2026 15:01:57 +0000 From: Bartosz Golaszewski In-Reply-To: <20260625115718.1678991-2-v@baodeep.com> MIME-Version: 1.0 References: <20260625115718.1678991-1-v@baodeep.com> <20260625115718.1678991-2-v@baodeep.com> Date: Fri, 26 Jun 2026 15:01:57 +0000 X-Gmail-Original-Message-ID: X-Gm-Features: AVVi8Cc1Kq0gtYMEzpnufw-hx30ivYWpESekEJWXahuAc8z4aeEAOf2sx5m3ETc Message-ID: Subject: Re: [PATCH v2 1/2] gpio: shared-proxy: always serialize with a sleeping mutex To: Viacheslav Bocharov Cc: Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Marek Szyprowski , Robin Murphy , Diederik de Haas , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij , Bartosz Golaszewski X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org On Thu, 25 Jun 2026 13:57:17 +0200, Viacheslav Bocharov said: > The shared GPIO descriptor used either a mutex or a spinlock, chosen at > runtime from the underlying chip's can_sleep: > > shared_desc->can_sleep = gpiod_cansleep(shared_desc->desc); > ... if (can_sleep) mutex_lock(); else spin_lock_irqsave(); > > can_sleep describes only the value path (->get/->set). Under the same > lock, however, the proxy may call gpiod_set_config() and > gpiod_direction_*(), which can reach pinctrl paths that take a mutex > (e.g. gpiod_set_config() -> gpiochip_generic_config() -> > pinctrl_gpio_set_config()), independent of can_sleep. On a controller > with non-sleeping MMIO value ops the descriptor lock was a spinlock, so > the sleeping pinctrl call ran from atomic context. Reproduced on an > Amlogic A113X board with the workaround from commit 28f240683871 > ("pinctrl: meson: mark the GPIO controller as sleeping") reverted; the > original Khadas VIM3 report hit the same path: > > BUG: sleeping function called from invalid context > __mutex_lock > pinctrl_get_device_gpio_range > pinctrl_gpio_set_config > gpiochip_generic_config > gpiod_set_config > gpio_shared_proxy_set_config <- voting spinlock held > ... > mmc_pwrseq_simple_probe > > The spinlock existed to take the value vote from atomic context, but the > vote and the (possibly sleeping) control operations share the same state > and lock, so this scheme cannot serialize config under a mutex and still > offer atomic value access. Always serialize the shared descriptor with a > mutex instead and mark the proxy a sleeping gpiochip, driving the > underlying GPIO through the cansleep value accessors: those are valid > for both sleeping and non-sleeping chips, so value access keeps working > on fast controllers, at the cost of no longer being atomic. > > This is observable: consumers gating on gpiod_cansleep() take their > sleeping branch on a proxied GPIO (mmc-pwrseq-emmc skips its > emergency-restart reset handler; its normal reset is unaffected), and > consumers that reject sleeping GPIOs (pwm-gpio, ps2-gpio, ...) would > fail to probe. Such atomic users do not share a pin through the proxy, > whose purpose is voting on shared reset/enable lines. The same narrowing > already applies on Amlogic since that workaround, and rockchip > addressed the identical splat per-driver in commit 7ca497be0016 ("gpio: > rockchip: Stop calling pinctrl for set_direction"); fixing the proxy > addresses the locking error once, for every controller. > > The lock type was added by commit a060b8c511ab ("gpiolib: implement > low-level, shared GPIO support"); the sleeping call under it arrived with > the proxy driver. > > Fixes: e992d54c6f97 ("gpio: shared-proxy: implement the shared GPIO proxy driver") > Reported-by: Marek Szyprowski > Closes: https://lore.kernel.org/all/00107523-7737-4b92-a785-14ce4e93b8cb@samsung.com/ > Signed-off-by: Viacheslav Bocharov > --- This looks good to me. Linus: do you want me to take patch 2/2 as well? I'll send it for v7.2-rc2. Bart _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic