Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1446771pxb; Wed, 4 Nov 2020 09:07:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFMioh6SvsEecUU5pc20rcH19hKO1gGRkuq8NCRoH6w/omxIva1W+mfu7FY+GB9y1rk5IA X-Received: by 2002:a17:906:3ed0:: with SMTP id d16mr26906056ejj.477.1604509646707; Wed, 04 Nov 2020 09:07:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604509646; cv=none; d=google.com; s=arc-20160816; b=yg1uRfgIggZCYZ55oCJYz/jo7ieZ5AbOvZh2PgAIgBPwJYZ5Z/SVuwSeq88HpNlxIJ Uhr4vP+cB8CiUZWxrfExhLa/tmFE84paCJfWCwwvdS2J8e9WTdCp2Wz+7p9oKZzsv/Wv GwVvgjWdIw3RJjYbur8wZ8tg7nUpkgdYXMgGSmL1Xp+IDgLtITLUnlCAmk5B2zPMLRGs jDMwuWgaK2ZI9v0hE9uIdqqpKbFG5SU3WQ8dyFSyC8Rl/RCDpOtG5hNdEllqRhfuDv7d PfTPGmob3JizQ+2esKVzUydK4C6+a1tfFoZ/xmyxAC8gEjhmkQYgWR1YQ/2PmI/w9Zma OQ3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/ipN2OHWhaQxheYdOXhTrFFEC6RbsQ7nc8F7dXSQxjM=; b=0JW0T8skPsVfu0tB3ROwVjoQRtiZdtLOCNri35DaP+QFxuTaCwfw7wGiRyHYjTc+to N7hQ69okhMcQuDfmv+G5oN3aMSBBQK4ohhTjok+bxecsqAy2CIsORD23NY8Yfq5PHm/6 Cgb1dXkV69HYcFq5hxRHKmp4hiFU5lULzcE2v0SSWa6B4OAFZ2sOPNkp0ksL0w/kgjMa G4QvBknbCJ/NQfZ4XrErlx5b25YEUWsHXEDi7N0SVCMOE0CjIQoHRrySSkDmGw3+W1QC ASU+80ethgrImutM4USYavD/zF+jmv7m2mpFyCaLLDMgYJlK64Xw5cxfdGZMEHaMsCjn Lebw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=APvuMiLr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a19si1310388edb.410.2020.11.04.09.07.01; Wed, 04 Nov 2020 09:07:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=APvuMiLr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731909AbgKDREx (ORCPT + 99 others); Wed, 4 Nov 2020 12:04:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729679AbgKDREw (ORCPT ); Wed, 4 Nov 2020 12:04:52 -0500 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7CBEC0613D3; Wed, 4 Nov 2020 09:04:51 -0800 (PST) Received: by mail-lj1-x242.google.com with SMTP id y16so23782689ljk.1; Wed, 04 Nov 2020 09:04:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/ipN2OHWhaQxheYdOXhTrFFEC6RbsQ7nc8F7dXSQxjM=; b=APvuMiLrs0T8g4v1aieiR0rHJlTVC9HNP01vRsacddx8uHEIMuZdXVzVj/gX5fKOL7 Fi4oYz2YMfcMI8Q1l/nGMRvN6HwVA+c4geJFzjSoi0I8Ebgy3N5y3c5KAf2xg6Q0JGTi 4BA+2BYDcGttqqZU9fkEZTtjJbk23+eLArZOthzAWCZFPiIZplks5h6BLWdLoOM6K40Z 7A/IMKiWFsRvz7G2kbPA43qfVI8rRK38NQS5NGLuwqadNquPdg84++UEBzxxuMj1MuXv Ysc6v+K8tzXyB0LMVxyt+nBjNGWVg48XY4ivnOEkf1ACv6E6QbbOYzXPpiMR5REUdykZ w6GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/ipN2OHWhaQxheYdOXhTrFFEC6RbsQ7nc8F7dXSQxjM=; b=pFDEJCYJgby3HEW4LExR2fpMu1Jp3AnNcdWOfjg4L1ugUgqghwBwUwGj8cpv+/0oBQ tBFzlRbocGf4N2lYTSPxo02I5/88QBCokDSnLTPOLJd3MBn/uLrOeYuR5RKFGsLLO5GP uSx3BaZkjcq+gYHtJq7xdpTTDaTe9ZaoIOyCOl9ccYQ2EyFkJ7eo2f4LN+jNHlNRgNlF eVk7+CKlFPGcLBUbGbgs8YAGbhWNxXg7r537QgmliqbhxCbIJofB6bDc/Rphs2kCAA7A PsYHExY/AuNoCeGEtuhdmTs63Y2fSxN3tpIIS/D6w5wpAigtxGq3yHCuvi9yLk5QgB+i ov3A== X-Gm-Message-State: AOAM530NFHFYmp1Wr12Xoc9MSasiMgndhxStnCbE+ipHy6Hf7yOaN2WY jtuE3G3PQlNS9fONS3Y+KOw= X-Received: by 2002:a05:651c:506:: with SMTP id o6mr10281844ljp.249.1604509490384; Wed, 04 Nov 2020 09:04:50 -0800 (PST) Received: from localhost.localdomain (109-252-192-83.dynamic.spd-mgts.ru. [109.252.192.83]) by smtp.gmail.com with ESMTPSA id c4sm457931lfh.60.2020.11.04.09.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:04:49 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Bartosz Golaszewski , Linus Walleij , Andy Shevchenko , Peter Geis Cc: linux-tegra@vger.kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] gpio: tegra: Use raw_spinlock Date: Wed, 4 Nov 2020 20:04:23 +0300 Message-Id: <20201104170423.23436-2-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201104170423.23436-1-digetx@gmail.com> References: <20201104170423.23436-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use raw_spinlock in order to fix spurious messages about invalid context when spinlock debugging is enabled. This happens because there is a legit nested raw_spinlock->spinlock locking usage within IRQ-related code. IRQ core uses raw spinlock and then Tegra GPIO driver uses a nested spinlock. The debug code can't recognize and handle this case, hence we need to use raw spinlock in the GPIO driver. [ BUG: Invalid wait context ] ... (dump_stack) from (__lock_acquire) (__lock_acquire) from (lock_acquire) (lock_acquire) from (_raw_spin_lock_irqsave) (_raw_spin_lock_irqsave) from (tegra_gpio_irq_set_type) (tegra_gpio_irq_set_type) from (__irq_set_trigger) (__irq_set_trigger) from (__setup_irq) (__setup_irq) from (request_threaded_irq) (request_threaded_irq) from (devm_request_threaded_irq) (devm_request_threaded_irq) from (elants_i2c_probe) (elants_i2c_probe) from (i2c_device_probe) ... Tested-by: Peter Geis Signed-off-by: Dmitry Osipenko --- Changelog: v2: - Only lvl_lock is converted to raw_spinlock. The dbc_lock doesn't relate to IRQ and doesn't need the conversion. - Improved commit message by clarifying that IRQ core uses raw spinlock. - Added clarifying comment to the code for the lvl_lock. drivers/gpio/gpio-tegra.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c index 98fc78739ebf..e19ebff6018c 100644 --- a/drivers/gpio/gpio-tegra.c +++ b/drivers/gpio/gpio-tegra.c @@ -61,8 +61,16 @@ struct tegra_gpio_info; struct tegra_gpio_bank { unsigned int bank; unsigned int irq; - spinlock_t lvl_lock[4]; - spinlock_t dbc_lock[4]; /* Lock for updating debounce count register */ + + /* + * IRQ-core code uses raw locking, and thus, nested locking also + * should be raw in order not to trip spinlock debug warnings. + */ + raw_spinlock_t lvl_lock[4]; + + /* Lock for updating debounce count register */ + spinlock_t dbc_lock[4]; + #ifdef CONFIG_PM_SLEEP u32 cnf[4]; u32 out[4]; @@ -334,14 +342,14 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) return -EINVAL; } - spin_lock_irqsave(&bank->lvl_lock[port], flags); + raw_spin_lock_irqsave(&bank->lvl_lock[port], flags); val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio)); val &= ~(GPIO_INT_LVL_MASK << GPIO_BIT(gpio)); val |= lvl_type << GPIO_BIT(gpio); tegra_gpio_writel(tgi, val, GPIO_INT_LVL(tgi, gpio)); - spin_unlock_irqrestore(&bank->lvl_lock[port], flags); + raw_spin_unlock_irqrestore(&bank->lvl_lock[port], flags); tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0); tegra_gpio_enable(tgi, gpio); @@ -675,7 +683,7 @@ static int tegra_gpio_probe(struct platform_device *pdev) tegra_gpio_irq_handler, bank); for (j = 0; j < 4; j++) { - spin_lock_init(&bank->lvl_lock[j]); + raw_spin_lock_init(&bank->lvl_lock[j]); spin_lock_init(&bank->dbc_lock[j]); } } -- 2.27.0