Skip to content

Commit 5ed35b4

Browse files
Marek Vasutbjorn-helgaas
authored andcommitted
PCI: rcar-host: Convert struct rcar_msi mask_lock into raw spinlock
The rcar_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 rcar_msi_irq_unmask(). Since the &desc->lock descriptor lock is a raw spinlock, and the rcar_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: 83ed8d4 ("PCI: rcar: Convert to MSI domains") Reported-by: Duy Nguyen <[email protected]> Reported-by: Thuan Nguyen <[email protected]> Signed-off-by: Marek Vasut <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Acked-by: Marc Zyngier <[email protected]> Cc: [email protected] Link: https://patch.msgid.link/[email protected]
1 parent 0a8f173 commit 5ed35b4

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

drivers/pci/controller/pcie-rcar-host.c

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

1414
#include <linux/bitops.h>
15+
#include <linux/cleanup.h>
1516
#include <linux/clk.h>
1617
#include <linux/clk-provider.h>
1718
#include <linux/delay.h>
@@ -38,7 +39,7 @@ struct rcar_msi {
3839
DECLARE_BITMAP(used, INT_PCI_MSI_NR);
3940
struct irq_domain *domain;
4041
struct mutex map_lock;
41-
spinlock_t mask_lock;
42+
raw_spinlock_t mask_lock;
4243
int irq1;
4344
int irq2;
4445
};
@@ -602,28 +603,26 @@ static void rcar_msi_irq_mask(struct irq_data *d)
602603
{
603604
struct rcar_msi *msi = irq_data_get_irq_chip_data(d);
604605
struct rcar_pcie *pcie = &msi_to_host(msi)->pcie;
605-
unsigned long flags;
606606
u32 value;
607607

608-
spin_lock_irqsave(&msi->mask_lock, flags);
609-
value = rcar_pci_read_reg(pcie, PCIEMSIIER);
610-
value &= ~BIT(d->hwirq);
611-
rcar_pci_write_reg(pcie, value, PCIEMSIIER);
612-
spin_unlock_irqrestore(&msi->mask_lock, flags);
608+
scoped_guard(raw_spinlock_irqsave, &msi->mask_lock) {
609+
value = rcar_pci_read_reg(pcie, PCIEMSIIER);
610+
value &= ~BIT(d->hwirq);
611+
rcar_pci_write_reg(pcie, value, PCIEMSIIER);
612+
}
613613
}
614614

615615
static void rcar_msi_irq_unmask(struct irq_data *d)
616616
{
617617
struct rcar_msi *msi = irq_data_get_irq_chip_data(d);
618618
struct rcar_pcie *pcie = &msi_to_host(msi)->pcie;
619-
unsigned long flags;
620619
u32 value;
621620

622-
spin_lock_irqsave(&msi->mask_lock, flags);
623-
value = rcar_pci_read_reg(pcie, PCIEMSIIER);
624-
value |= BIT(d->hwirq);
625-
rcar_pci_write_reg(pcie, value, PCIEMSIIER);
626-
spin_unlock_irqrestore(&msi->mask_lock, flags);
621+
scoped_guard(raw_spinlock_irqsave, &msi->mask_lock) {
622+
value = rcar_pci_read_reg(pcie, PCIEMSIIER);
623+
value |= BIT(d->hwirq);
624+
rcar_pci_write_reg(pcie, value, PCIEMSIIER);
625+
}
627626
}
628627

629628
static void rcar_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
@@ -736,7 +735,7 @@ static int rcar_pcie_enable_msi(struct rcar_pcie_host *host)
736735
int err;
737736

738737
mutex_init(&msi->map_lock);
739-
spin_lock_init(&msi->mask_lock);
738+
raw_spin_lock_init(&msi->mask_lock);
740739

741740
err = of_address_to_resource(dev->of_node, 0, &res);
742741
if (err)

0 commit comments

Comments
 (0)