Skip to content

Commit 7503861

Browse files
Marek Vasutgregkh
authored andcommitted
PCI: rcar-host: Convert struct rcar_msi mask_lock into raw spinlock
commit 5ed35b4 upstream. 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 <duy.nguyen.rh@renesas.com> Reported-by: Thuan Nguyen <thuan.nguyen-hong@banvien.com.vn> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Acked-by: Marc Zyngier <maz@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20250909162707.13927-2-marek.vasut+renesas@mailbox.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8f79f82 commit 7503861

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>
@@ -37,7 +38,7 @@ struct rcar_msi {
3738
DECLARE_BITMAP(used, INT_PCI_MSI_NR);
3839
struct irq_domain *domain;
3940
struct mutex map_lock;
40-
spinlock_t mask_lock;
41+
raw_spinlock_t mask_lock;
4142
int irq1;
4243
int irq2;
4344
};
@@ -625,28 +626,26 @@ static void rcar_msi_irq_mask(struct irq_data *d)
625626
{
626627
struct rcar_msi *msi = irq_data_get_irq_chip_data(d);
627628
struct rcar_pcie *pcie = &msi_to_host(msi)->pcie;
628-
unsigned long flags;
629629
u32 value;
630630

631-
spin_lock_irqsave(&msi->mask_lock, flags);
632-
value = rcar_pci_read_reg(pcie, PCIEMSIIER);
633-
value &= ~BIT(d->hwirq);
634-
rcar_pci_write_reg(pcie, value, PCIEMSIIER);
635-
spin_unlock_irqrestore(&msi->mask_lock, flags);
631+
scoped_guard(raw_spinlock_irqsave, &msi->mask_lock) {
632+
value = rcar_pci_read_reg(pcie, PCIEMSIIER);
633+
value &= ~BIT(d->hwirq);
634+
rcar_pci_write_reg(pcie, value, PCIEMSIIER);
635+
}
636636
}
637637

638638
static void rcar_msi_irq_unmask(struct irq_data *d)
639639
{
640640
struct rcar_msi *msi = irq_data_get_irq_chip_data(d);
641641
struct rcar_pcie *pcie = &msi_to_host(msi)->pcie;
642-
unsigned long flags;
643642
u32 value;
644643

645-
spin_lock_irqsave(&msi->mask_lock, flags);
646-
value = rcar_pci_read_reg(pcie, PCIEMSIIER);
647-
value |= BIT(d->hwirq);
648-
rcar_pci_write_reg(pcie, value, PCIEMSIIER);
649-
spin_unlock_irqrestore(&msi->mask_lock, flags);
644+
scoped_guard(raw_spinlock_irqsave, &msi->mask_lock) {
645+
value = rcar_pci_read_reg(pcie, PCIEMSIIER);
646+
value |= BIT(d->hwirq);
647+
rcar_pci_write_reg(pcie, value, PCIEMSIIER);
648+
}
650649
}
651650

652651
static void rcar_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
@@ -756,7 +755,7 @@ static int rcar_pcie_enable_msi(struct rcar_pcie_host *host)
756755
int err;
757756

758757
mutex_init(&msi->map_lock);
759-
spin_lock_init(&msi->mask_lock);
758+
raw_spin_lock_init(&msi->mask_lock);
760759

761760
err = of_address_to_resource(dev->of_node, 0, &res);
762761
if (err)

0 commit comments

Comments
 (0)