Skip to content

Commit 3d01eb9

Browse files
Marek Vasutgregkh
authored andcommitted
PCI: tegra: Convert struct tegra_msi mask_lock into raw spinlock
commit 26fda92 upstream. The tegra_msi_irq_unmask() function may be called from a PCI driver request_threaded_irq() function. This triggers kernel/irq/manage.c __setup_irq() which locks raw spinlock &desc->lock descriptor lock and with that descriptor lock held, calls tegra_msi_irq_unmask(). Since the &desc->lock descriptor lock is a raw spinlock, and the tegra_msi .mask_lock is not a raw spinlock, this setup triggers 'BUG: Invalid wait context' with CONFIG_PROVE_RAW_LOCK_NESTING=y. Use scoped_guard() to simplify the locking. Fixes: 2c99e55 ("PCI: tegra: Convert to MSI domains") Reported-by: Geert Uytterhoeven <[email protected]> Closes: https://patchwork.kernel.org/project/linux-pci/patch/[email protected]/#26574451 Signed-off-by: Marek Vasut <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Cc: [email protected] Link: https://patch.msgid.link/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2da2da1 commit 3d01eb9

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

drivers/pci/controller/pci-tegra.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
#include <linux/clk.h>
17+
#include <linux/cleanup.h>
1718
#include <linux/debugfs.h>
1819
#include <linux/delay.h>
1920
#include <linux/export.h>
@@ -270,7 +271,7 @@ struct tegra_msi {
270271
DECLARE_BITMAP(used, INT_PCI_MSI_NR);
271272
struct irq_domain *domain;
272273
struct mutex map_lock;
273-
spinlock_t mask_lock;
274+
raw_spinlock_t mask_lock;
274275
void *virt;
275276
dma_addr_t phys;
276277
int irq;
@@ -1581,29 +1582,27 @@ static void tegra_msi_irq_mask(struct irq_data *d)
15811582
struct tegra_msi *msi = irq_data_get_irq_chip_data(d);
15821583
struct tegra_pcie *pcie = msi_to_pcie(msi);
15831584
unsigned int index = d->hwirq / 32;
1584-
unsigned long flags;
15851585
u32 value;
15861586

1587-
spin_lock_irqsave(&msi->mask_lock, flags);
1588-
value = afi_readl(pcie, AFI_MSI_EN_VEC(index));
1589-
value &= ~BIT(d->hwirq % 32);
1590-
afi_writel(pcie, value, AFI_MSI_EN_VEC(index));
1591-
spin_unlock_irqrestore(&msi->mask_lock, flags);
1587+
scoped_guard(raw_spinlock_irqsave, &msi->mask_lock) {
1588+
value = afi_readl(pcie, AFI_MSI_EN_VEC(index));
1589+
value &= ~BIT(d->hwirq % 32);
1590+
afi_writel(pcie, value, AFI_MSI_EN_VEC(index));
1591+
}
15921592
}
15931593

15941594
static void tegra_msi_irq_unmask(struct irq_data *d)
15951595
{
15961596
struct tegra_msi *msi = irq_data_get_irq_chip_data(d);
15971597
struct tegra_pcie *pcie = msi_to_pcie(msi);
15981598
unsigned int index = d->hwirq / 32;
1599-
unsigned long flags;
16001599
u32 value;
16011600

1602-
spin_lock_irqsave(&msi->mask_lock, flags);
1603-
value = afi_readl(pcie, AFI_MSI_EN_VEC(index));
1604-
value |= BIT(d->hwirq % 32);
1605-
afi_writel(pcie, value, AFI_MSI_EN_VEC(index));
1606-
spin_unlock_irqrestore(&msi->mask_lock, flags);
1601+
scoped_guard(raw_spinlock_irqsave, &msi->mask_lock) {
1602+
value = afi_readl(pcie, AFI_MSI_EN_VEC(index));
1603+
value |= BIT(d->hwirq % 32);
1604+
afi_writel(pcie, value, AFI_MSI_EN_VEC(index));
1605+
}
16071606
}
16081607

16091608
static void tegra_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
@@ -1711,7 +1710,7 @@ static int tegra_pcie_msi_setup(struct tegra_pcie *pcie)
17111710
int err;
17121711

17131712
mutex_init(&msi->map_lock);
1714-
spin_lock_init(&msi->mask_lock);
1713+
raw_spin_lock_init(&msi->mask_lock);
17151714

17161715
if (IS_ENABLED(CONFIG_PCI_MSI)) {
17171716
err = tegra_allocate_domains(msi);

0 commit comments

Comments
 (0)