Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3714352imu; Mon, 28 Jan 2019 09:30:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN4KOiidc7Dwrg43EkfhZr4WyHyf3nX1oQNJY7fL2fOIp3+ELyRWGraJQAN5IhLO5EnFoxRY X-Received: by 2002:a62:53c5:: with SMTP id h188mr22327959pfb.190.1548696610914; Mon, 28 Jan 2019 09:30:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548696610; cv=none; d=google.com; s=arc-20160816; b=v/AzzP1LWiqcb99TXy8CJXzNm4D7bXgB+7rrv7GB+4+AzBTzQiwlXUzih2Rx3t+E0Z AaL2xXk8p7EPiLnt+6EYl+sBOUnMJHgr68eSEWLzqMpMF3SYt2y+bNvavCsDof7v3loX l82iMIIIZQ4B8RszeYN29a6Eel/rK7bZ79EOfr7yrSAVCR52vFnKnFGPC/54vyN/EweF nYh5p5oQAPUdyXJIvy8kljLtsLfpJZnodsOZOlkwkT+GvZNtZwJ8GS2lZSAGAlC/ynzp SYrG02YCXoUK94Eg29suknn3PWpxj/ynK4G6c8vkaEPNzYQ5jMXLH3JAv0AepEl8oB6q A1QA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+ZVtU239rTevaNaTZOA+ZoUnCMP4rLxEa0nquP6pjS8=; b=pu3SoLBT3Qe+kYD3QEaM4Suev2lzvz5bECA/5Rx9k3bd6Q76CgH6QlRXjdI4pDumGN zor18ybKBaLzDlWM7f8y0I4bQAcSHlfCqrsVBErdX8Y4ZngtKWcxBOy8Oqh/f0SF+yQG mikRRaURFXlS/MlR0YWf2fiy1vztedwSqwK5DB10OZS7VB1tVmLHKiEMAKmm/VCBqEF/ y8vT6pgxVfbgytSXPAvmtqQMRaU934TdQAELXGCHNn9ulL2woD3Yhtc/YfTYPioPpQ16 EKIRAN8T2wURh2GJS4irycNi4rsKzxkI3HuhLgVWXm9nvqLSWLVsEU6Ozx2vn35/lkyQ AM0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fXiLuv8K; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12si3261996plg.250.2019.01.28.09.29.55; Mon, 28 Jan 2019 09:30:10 -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=fXiLuv8K; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730599AbfA1P7m (ORCPT + 99 others); Mon, 28 Jan 2019 10:59:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:44918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727158AbfA1P7l (ORCPT ); Mon, 28 Jan 2019 10:59:41 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5AC642175B; Mon, 28 Jan 2019 15:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691180; bh=cu9oaL5Qh4oRfgsQ43pu620QNt3zV7o3X9rv5QO/njw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fXiLuv8KakTsQeoNw2G9gzCeCzy7IytG6FfmqizKI4vvsn81VUbVGHX4DGitcQ7U5 iglIQUhr3YI2q79EsMpZw1xxf1E6OTf2GjzKi9yIxFfhLknfEQy/OE7LglYzRV6PTd +a5nt852pOyJGP4pKGFP+B2zrukFKc9H4rTdSXPU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lukas Wunner , Mathias Duckeck , Linus Walleij , Sasha Levin , linux-gpio@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 004/258] pinctrl: bcm2835: Use raw spinlock for RT compatibility Date: Mon, 28 Jan 2019 10:55:10 -0500 Message-Id: <20190128155924.51521-4-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner [ 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