Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2648824imj; Mon, 11 Feb 2019 06:27:14 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaf5jERjjt9aG2HiReZO1qm5fDBhoTm4zAJfCZ1M6a/JHXy8jH5w/yHJ/Z+dHBSpBA4R8RK X-Received: by 2002:a62:f598:: with SMTP id b24mr14796704pfm.72.1549895234458; Mon, 11 Feb 2019 06:27:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895234; cv=none; d=google.com; s=arc-20160816; b=Tito3AGSQ3OyPtzZHa5yR0y+GXT14bqJmqxcuK/qOHw3HUkSlzFUHxpm+AoZf42Go6 T8wk7OJLRZ/XX0vu3Ryfx8Dcsw0u57I7LRQs3wclyEXOhDTHLqf+S7zQ4fzIVnVogY1o AhD+x65D0ZmMD63lzG1ms73AoKbFjlDn7eattiiKLHewlBcT3wV6qrqy49mze8SG9g1/ J+DkcAS0d/RShENqwP+mHmuQsgqssy3n4ymMdv430RfpaBNh5e05DJdwVbga7yaARBMR nnJqSskCANqI5IcoYRb05lSRgKlh+QRriA0vm8HmryGdf6iuvV8Z1xOpj5VFuf6T5Wiq Tb8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=t4J/PYr+kDr0iNvupGawVuhBdJfmLEuL870kWYbwwSY=; b=eJK9z7pJNxdEDhZgJ5HrmOP7ZOWm+pEg8nXQZwWIw/IIFQkyxHWMpZ2nEGbLSRnwNa 0oEnVMsTUYXVKOgnfH84jxZwtgAaN9HXzOu89vrAn5gbv30qRzYElm3e6MATZ7rrGwMC r3qOrIRyp/2g5mq+D0W5EeXSV2ZNzw6LkwaSNHGsTerna8VJJO25uL03sAijFI0LT9P1 KDrvmqXvo4oQJPpgZn2mBCEOIkk1uO3gOSa0/+WwN6Zifd9mCGf6z2TBJWrQIlqC9R8U WqyLrwrJkI2JGKTj+zarGNK19rnAw3Gcl/yG2zT+/JwfxeDS8bLytZGYcq5cRxxixyT2 RJdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xwVNhnO5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si10661597pld.249.2019.02.11.06.26.58; Mon, 11 Feb 2019 06:27:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xwVNhnO5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728460AbfBKOVG (ORCPT + 99 others); Mon, 11 Feb 2019 09:21:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:53880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728445AbfBKOVE (ORCPT ); Mon, 11 Feb 2019 09:21:04 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AF06D2073F; Mon, 11 Feb 2019 14:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549894863; bh=TanTB0KDQgZmcOBWT9B5gklZK3YP6POwLDT6GE68Mmo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xwVNhnO53UYaYZ6yJKIkseENTTvOwZnB0yzuEEKiHSJiPRqDmMeAxL9Gy1b5K39vM dwB5jmVepYNcHizNq56rVQgLyh3iw5YiPm5rNxYYlGtO6cQe42QQO9pFxRuL4A+ZPB vu53K3/4B+KhwycOmJZ4Swtht8nHgLtDYGU+HunY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Duckeck , Lukas Wunner , Julia Cartwright , Linus Walleij , Sasha Levin Subject: [PATCH 4.20 005/352] pinctrl: bcm2835: Use raw spinlock for RT compatibility Date: Mon, 11 Feb 2019 15:13:52 +0100 Message-Id: <20190211141846.834956258@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 3c7b30f704b6f5e53eed6bf89cf2c8d1b38b02c0 ] The BCM2835 pinctrl driver acquires a spinlock in its ->irq_enable, ->irq_disable and ->irq_set_type callbacks. Spinlocks become sleeping locks with CONFIG_PREEMPT_RT_FULL=y, therefore invocation of one of the callbacks in atomic context may cause a hard lockup if at least two GPIO pins in the same bank are used as interrupts. The issue doesn't occur with just a single interrupt pin per bank because the lock is never contended. I'm experiencing such lockups with GPIO 8 and 28 used as level-triggered interrupts, i.e. with ->irq_disable being invoked on reception of every IRQ. The critical section protected by the spinlock is very small (one bitop and one RMW of an MMIO register), hence converting to a raw spinlock seems a better trade-off than converting the driver to threaded IRQ handling (which would increase latency to handle an interrupt). Cc: Mathias Duckeck Signed-off-by: Lukas Wunner Acked-by: Julia Cartwright Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/bcm/pinctrl-bcm2835.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c index fa530913a2c8..08925d24180b 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c @@ -90,7 +90,7 @@ struct bcm2835_pinctrl { struct gpio_chip gpio_chip; struct pinctrl_gpio_range gpio_range; - spinlock_t irq_lock[BCM2835_NUM_BANKS]; + raw_spinlock_t irq_lock[BCM2835_NUM_BANKS]; }; /* pins are just named GPIO0..GPIO53 */ @@ -461,10 +461,10 @@ static void bcm2835_gpio_irq_enable(struct irq_data *data) unsigned bank = GPIO_REG_OFFSET(gpio); unsigned long flags; - spin_lock_irqsave(&pc->irq_lock[bank], flags); + raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); set_bit(offset, &pc->enabled_irq_map[bank]); bcm2835_gpio_irq_config(pc, gpio, true); - spin_unlock_irqrestore(&pc->irq_lock[bank], flags); + raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); } static void bcm2835_gpio_irq_disable(struct irq_data *data) @@ -476,12 +476,12 @@ static void bcm2835_gpio_irq_disable(struct irq_data *data) unsigned bank = GPIO_REG_OFFSET(gpio); unsigned long flags; - spin_lock_irqsave(&pc->irq_lock[bank], flags); + raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); bcm2835_gpio_irq_config(pc, gpio, false); /* Clear events that were latched prior to clearing event sources */ bcm2835_gpio_set_bit(pc, GPEDS0, gpio); clear_bit(offset, &pc->enabled_irq_map[bank]); - spin_unlock_irqrestore(&pc->irq_lock[bank], flags); + raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); } static int __bcm2835_gpio_irq_set_type_disabled(struct bcm2835_pinctrl *pc, @@ -584,7 +584,7 @@ static int bcm2835_gpio_irq_set_type(struct irq_data *data, unsigned int type) unsigned long flags; int ret; - spin_lock_irqsave(&pc->irq_lock[bank], flags); + raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); if (test_bit(offset, &pc->enabled_irq_map[bank])) ret = __bcm2835_gpio_irq_set_type_enabled(pc, gpio, type); @@ -596,7 +596,7 @@ static int bcm2835_gpio_irq_set_type(struct irq_data *data, unsigned int type) else irq_set_handler_locked(data, handle_level_irq); - spin_unlock_irqrestore(&pc->irq_lock[bank], flags); + raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); return ret; } @@ -1047,7 +1047,7 @@ static int bcm2835_pinctrl_probe(struct platform_device *pdev) for_each_set_bit(offset, &events, 32) bcm2835_gpio_wr(pc, GPEDS0 + i * 4, BIT(offset)); - spin_lock_init(&pc->irq_lock[i]); + raw_spin_lock_init(&pc->irq_lock[i]); } err = gpiochip_add_data(&pc->gpio_chip, pc); -- 2.19.1