From: Guangbo Cui <jckeep.cuiguangbo@gmail.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Bjorn Helgaas <bhelgaas@google.com>
Cc: Waiman Long <longman@redhat.com>,
linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org,
Guangbo Cui <jckeep.cuiguangbo@gmail.com>
Subject: [PATCH v4 2/2] PCI/aer_inject: Convert inject_lock to raw_spinlock_t
Date: Sun, 2 Nov 2025 10:57:06 +0000 [thread overview]
Message-ID: <20251102105706.7259-3-jckeep.cuiguangbo@gmail.com> (raw)
In-Reply-To: <20251102105706.7259-1-jckeep.cuiguangbo@gmail.com>
The AER injection path may run in interrupt-disabled context while
holding inject_lock. On PREEMPT_RT kernels, spinlock_t becomes a
sleeping lock, so it must not be taken while a raw_spinlock_t is held.
Doing so violates lock ordering rules and trigger lockdep reports
such as “Invalid wait context”.
Convert inject_lock to raw_spinlock_t to ensure non-sleeping locking
semantics. The protected list is bounded and used only for debugging,
so raw locking will not cause latency issues.
Acked-by: Waiman Long <longman@redhat.com>
Signed-off-by: Guangbo Cui <jckeep.cuiguangbo@gmail.com>
---
drivers/pci/pcie/aer_inject.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/pci/pcie/aer_inject.c b/drivers/pci/pcie/aer_inject.c
index d0cabfc04d48..a064fa2acb94 100644
--- a/drivers/pci/pcie/aer_inject.c
+++ b/drivers/pci/pcie/aer_inject.c
@@ -72,7 +72,7 @@ static LIST_HEAD(einjected);
static LIST_HEAD(pci_bus_ops_list);
/* Protect einjected and pci_bus_ops_list */
-static DEFINE_SPINLOCK(inject_lock);
+static DEFINE_RAW_SPINLOCK(inject_lock);
static void aer_error_init(struct aer_error *err, u32 domain,
unsigned int bus, unsigned int devfn,
@@ -126,12 +126,12 @@ static struct pci_bus_ops *pci_bus_ops_pop(void)
unsigned long flags;
struct pci_bus_ops *bus_ops;
- spin_lock_irqsave(&inject_lock, flags);
+ raw_spin_lock_irqsave(&inject_lock, flags);
bus_ops = list_first_entry_or_null(&pci_bus_ops_list,
struct pci_bus_ops, list);
if (bus_ops)
list_del(&bus_ops->list);
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
return bus_ops;
}
@@ -223,7 +223,7 @@ static int aer_inj_read_config(struct pci_bus *bus, unsigned int devfn,
int domain;
int rv;
- spin_lock_irqsave(&inject_lock, flags);
+ raw_spin_lock_irqsave(&inject_lock, flags);
if (size != sizeof(u32))
goto out;
domain = pci_domain_nr(bus);
@@ -236,12 +236,12 @@ static int aer_inj_read_config(struct pci_bus *bus, unsigned int devfn,
sim = find_pci_config_dword(err, where, NULL);
if (sim) {
*val = *sim;
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
return 0;
}
out:
rv = aer_inj_read(bus, devfn, where, size, val);
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
return rv;
}
@@ -255,7 +255,7 @@ static int aer_inj_write_config(struct pci_bus *bus, unsigned int devfn,
int domain;
int rv;
- spin_lock_irqsave(&inject_lock, flags);
+ raw_spin_lock_irqsave(&inject_lock, flags);
if (size != sizeof(u32))
goto out;
domain = pci_domain_nr(bus);
@@ -271,12 +271,12 @@ static int aer_inj_write_config(struct pci_bus *bus, unsigned int devfn,
*sim ^= val;
else
*sim = val;
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
return 0;
}
out:
rv = aer_inj_write(bus, devfn, where, size, val);
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
return rv;
}
@@ -304,14 +304,14 @@ static int pci_bus_set_aer_ops(struct pci_bus *bus)
if (!bus_ops)
return -ENOMEM;
ops = pci_bus_set_ops(bus, &aer_inj_pci_ops);
- spin_lock_irqsave(&inject_lock, flags);
+ raw_spin_lock_irqsave(&inject_lock, flags);
if (ops == &aer_inj_pci_ops)
goto out;
pci_bus_ops_init(bus_ops, bus, ops);
list_add(&bus_ops->list, &pci_bus_ops_list);
bus_ops = NULL;
out:
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
kfree(bus_ops);
return 0;
}
@@ -383,7 +383,7 @@ static int aer_inject(struct aer_error_inj *einj)
uncor_mask);
}
- spin_lock_irqsave(&inject_lock, flags);
+ raw_spin_lock_irqsave(&inject_lock, flags);
err = __find_aer_error_by_dev(dev);
if (!err) {
@@ -404,14 +404,14 @@ static int aer_inject(struct aer_error_inj *einj)
!(einj->cor_status & ~cor_mask)) {
ret = -EINVAL;
pci_warn(dev, "The correctable error(s) is masked by device\n");
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
goto out_put;
}
if (!aer_mask_override && einj->uncor_status &&
!(einj->uncor_status & ~uncor_mask)) {
ret = -EINVAL;
pci_warn(dev, "The uncorrectable error(s) is masked by device\n");
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
goto out_put;
}
@@ -445,7 +445,7 @@ static int aer_inject(struct aer_error_inj *einj)
rperr->source_id &= 0x0000ffff;
rperr->source_id |= PCI_DEVID(einj->bus, devfn) << 16;
}
- spin_unlock_irqrestore(&inject_lock, flags);
+ raw_spin_unlock_irqrestore(&inject_lock, flags);
if (aer_mask_override) {
pci_write_config_dword(dev, pos_cap_err + PCI_ERR_COR_MASK,
--
2.43.0
next prev parent reply other threads:[~2025-11-02 10:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-02 10:57 [PATCH v4 0/2] PCI/aer_inject: Adjust locking for PREEMPT_RT Guangbo Cui
2025-11-02 10:57 ` [PATCH v4 1/2] PCI/aer_inject: Remove unnecessary lock in aer_inject_exit Guangbo Cui
2025-11-02 10:57 ` Guangbo Cui [this message]
2025-11-03 19:21 ` [PATCH v4 2/2] PCI/aer_inject: Convert inject_lock to raw_spinlock_t Peter Zijlstra
2025-11-03 19:27 ` Peter Zijlstra
2025-11-06 13:08 ` Guangbo Cui
2025-11-06 14:05 ` Peter Zijlstra
2025-11-11 14:39 ` Sebastian Andrzej Siewior
2025-11-03 20:02 ` Sebastian Andrzej Siewior
2025-11-03 20:29 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251102105706.7259-3-jckeep.cuiguangbo@gmail.com \
--to=jckeep.cuiguangbo@gmail.com \
--cc=bhelgaas@google.com \
--cc=bigeasy@linutronix.de \
--cc=boqun.feng@gmail.com \
--cc=clrkwllms@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).