From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 B7C171FC5 for ; Wed, 16 Feb 2022 04:26:39 +0000 (UTC) Received: by mail-oo1-f49.google.com with SMTP id 189-20020a4a03c6000000b003179d7b30d8so1184011ooi.2 for ; Tue, 15 Feb 2022 20:26:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=LT0nFgfu58iECyaHltrzdhXTd+LwZiIDPIbmP9t/t9o=; b=ivR6LRRUrRUqhges/nGaYsw1UOA96T1jPn1qxGbWmBPiz2uW/K2qljiopqaeCrzZPT WSsOHbQ+SOSlLhRIzELZ4OZq2QAsJT9PT43jnwOselJD7nQsOOU8NwVwOMCt3ME66/F7 p/3Ho5xc66S811J1YoQTrtpBVUFZU8ervzUD5OEaG5IquwxDJtUYqREJDJvwBM3deNAC y5r665Qyb43YPPP4EEgOzK6/vBseYOmDPm256syo1R5i6brs0GEdcOsG34cO1Y82fmPo n857J+spdkvVmcyAAMq4KdouteiMJvFMQ/w6FcJZ5kOHPl7ucgdENTT5HxNy1A9ElgDH MzzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=LT0nFgfu58iECyaHltrzdhXTd+LwZiIDPIbmP9t/t9o=; b=xDjZxkI561xWy6QWnAbLLqzlWoKQzmm9kKUQhRThXm/HKRMnXtZz9JMN0ts8brmcBa IjGPL56zC8O26wGze4fae/LLVH3SQ5yCG+CHWqALOi9EPvf6hY8esgSGnzv4xgvG1bGS wTntnE2sJdfy36j5RRKpKc1vllPTGpe/9o7VVPOeVnhkc8A0jUzOCfgJTHsc20xxPpJ4 IIWQc0A4y9m/QGAgxsybiflHmvFyBneiKaPKwGYiGg146i9l4Z+tzrK8YN2MSkLZY2pQ GnBu5a2fwqqn22Rj/O1RX0EnsQWH+3pB3pstKo0bG6EWyZr7mBDMhqF9N7JQbR2v2D2K B4QA== X-Gm-Message-State: AOAM530E+/mF1wNz19kG9JjVMGEb9B7MRgbWVCIU/BMwV/k8ppKsZ/sV sk9HaLVndprnBqzHgdQVCJ0= X-Google-Smtp-Source: ABdhPJzyD3GOhI4bv3I4PQ2oQYbNvToBTGMJaqoncptwGkOgDGQeU3ShnblQe7wT9dXLowkD1EX7TA== X-Received: by 2002:a05:6870:c21e:b0:d1:4378:7c14 with SMTP id z30-20020a056870c21e00b000d143787c14mr2544337oae.268.1644985598931; Tue, 15 Feb 2022 20:26:38 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d7sm14264348otf.66.2022.02.15.20.26.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 20:26:38 -0800 (PST) Sender: Guenter Roeck Date: Tue, 15 Feb 2022 20:26:37 -0800 From: Guenter Roeck To: Samuel Holland Cc: Linus Walleij , Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , linux-sunxi@lists.linux.dev, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] pinctrl: sunxi: Use unique lockdep classes for IRQs Message-ID: <20220216042637.GB63304@roeck-us.net> References: <20220216040037.22730-1-samuel@sholland.org> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220216040037.22730-1-samuel@sholland.org> On Tue, Feb 15, 2022 at 10:00:36PM -0600, Samuel Holland wrote: > This driver, like several others, uses a chained IRQ for each GPIO bank, > and forwards .irq_set_wake to the GPIO bank's upstream IRQ. As a result, > a call to irq_set_irq_wake() needs to lock both the upstream and > downstream irq_desc's. Lockdep considers this to be a possible deadlock > when the irq_desc's share lockdep classes, which they do by default: > > ============================================ > WARNING: possible recursive locking detected > 5.17.0-rc3-00394-gc849047c2473 #1 Not tainted > -------------------------------------------- > init/307 is trying to acquire lock: > c2dfe27c (&irq_desc_lock_class){-.-.}-{2:2}, at: __irq_get_desc_lock+0x58/0xa0 > > but task is already holding lock: > c3c0ac7c (&irq_desc_lock_class){-.-.}-{2:2}, at: __irq_get_desc_lock+0x58/0xa0 > > other info that might help us debug this: > Possible unsafe locking scenario: > > CPU0 > ---- > lock(&irq_desc_lock_class); > lock(&irq_desc_lock_class); > > *** DEADLOCK *** > > May be due to missing lock nesting notation > > 4 locks held by init/307: > #0: c1f29f18 (system_transition_mutex){+.+.}-{3:3}, at: __do_sys_reboot+0x90/0x23c > #1: c20f7760 (&dev->mutex){....}-{3:3}, at: device_shutdown+0xf4/0x224 > #2: c2e804d8 (&dev->mutex){....}-{3:3}, at: device_shutdown+0x104/0x224 > #3: c3c0ac7c (&irq_desc_lock_class){-.-.}-{2:2}, at: __irq_get_desc_lock+0x58/0xa0 > > stack backtrace: > CPU: 0 PID: 307 Comm: init Not tainted 5.17.0-rc3-00394-gc849047c2473 #1 > Hardware name: Allwinner sun8i Family > unwind_backtrace from show_stack+0x10/0x14 > show_stack from dump_stack_lvl+0x68/0x90 > dump_stack_lvl from __lock_acquire+0x1680/0x31a0 > __lock_acquire from lock_acquire+0x148/0x3dc > lock_acquire from _raw_spin_lock_irqsave+0x50/0x6c > _raw_spin_lock_irqsave from __irq_get_desc_lock+0x58/0xa0 > __irq_get_desc_lock from irq_set_irq_wake+0x2c/0x19c > irq_set_irq_wake from irq_set_irq_wake+0x13c/0x19c > [tail call from sunxi_pinctrl_irq_set_wake] > irq_set_irq_wake from gpio_keys_suspend+0x80/0x1a4 > gpio_keys_suspend from gpio_keys_shutdown+0x10/0x2c > gpio_keys_shutdown from device_shutdown+0x180/0x224 > device_shutdown from __do_sys_reboot+0x134/0x23c > __do_sys_reboot from ret_fast_syscall+0x0/0x1c > > However, this can never deadlock because the upstream and downstream > IRQs are never the same (nor do they even involve the same irqchip). > > Silence this erroneous lockdep splat by applying what appears to be the > usual fix of moving the GPIO IRQs to separate lockdep classes. > > Fixes: a59c99d9eaf9 ("pinctrl: sunxi: Forward calls to irq_set_irq_wake") > Reported-by: Guenter Roeck > Signed-off-by: Samuel Holland Tested-by: Guenter Roeck Guenter > --- > > drivers/pinctrl/sunxi/pinctrl-sunxi.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c > index 80d6750c74a6..9e6ed1175db3 100644 > --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c > +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c > @@ -36,6 +36,13 @@ > #include "../core.h" > #include "pinctrl-sunxi.h" > > +/* > + * These lock classes tell lockdep that GPIO IRQs are in a different > + * category than their parents, so it won't report false recursion. > + */ > +static struct lock_class_key sunxi_pinctrl_irq_lock_class; > +static struct lock_class_key sunxi_pinctrl_irq_request_class; > + > static struct irq_chip sunxi_pinctrl_edge_irq_chip; > static struct irq_chip sunxi_pinctrl_level_irq_chip; > > @@ -1555,6 +1562,8 @@ int sunxi_pinctrl_init_with_variant(struct platform_device *pdev, > for (i = 0; i < (pctl->desc->irq_banks * IRQ_PER_BANK); i++) { > int irqno = irq_create_mapping(pctl->domain, i); > > + irq_set_lockdep_class(irqno, &sunxi_pinctrl_irq_lock_class, > + &sunxi_pinctrl_irq_request_class); > irq_set_chip_and_handler(irqno, &sunxi_pinctrl_edge_irq_chip, > handle_edge_irq); > irq_set_chip_data(irqno, pctl); > -- > 2.33.1 >