From: Bart Van Assche <bvanassche@acm.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org,
Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH 2/5] irqdesc: Use dynamic lockdep keys for interrupt descriptors
Date: Mon, 3 Feb 2025 09:59:36 -0800 [thread overview]
Message-ID: <20250203175939.3133477-3-bvanassche@acm.org> (raw)
In-Reply-To: <20250203175939.3133477-1-bvanassche@acm.org>
Having to call irq_set_lockdep_class() if nested locking is expected is
cumbersome. Hence, prepare for removing irq_set_lockdep_class() by
associating a dynamic key with the synchronization objects in interrupt
descriptors.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
include/linux/irqdesc.h | 4 ++++
kernel/irq/irqdesc.c | 22 +++++++++-------------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index fd091c35d572..5f4bd476fcc8 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -46,6 +46,7 @@ struct irqstat {
* @threads_handled: stats field for deferred spurious detection of threaded handlers
* @threads_handled_last: comparator field for deferred spurious detection of threaded handlers
* @lock: locking for SMP
+ * @lock_key: Lockdep class for @lock
* @affinity_hint: hint to user space for preferred irq affinity
* @affinity_notify: context for notification of affinity changes
* @pending_mask: pending rebalanced interrupts
@@ -60,6 +61,7 @@ struct irqstat {
* @rcu: rcu head for delayed free
* @kobj: kobject used to represent this struct in sysfs
* @request_mutex: mutex to protect request/free before locking desc->lock
+ * @request_key: Lockdep class for @request_mutex
* @dir: /proc/irq/ procfs entry
* @debugfs_file: dentry for the debugfs file
* @name: flow handler name for /proc/interrupts output
@@ -81,6 +83,7 @@ struct irq_desc {
atomic_t threads_handled;
int threads_handled_last;
raw_spinlock_t lock;
+ struct lock_class_key lock_key;
struct cpumask *percpu_enabled;
const struct cpumask *percpu_affinity;
#ifdef CONFIG_SMP
@@ -111,6 +114,7 @@ struct irq_desc {
struct kobject kobj;
#endif
struct mutex request_mutex;
+ struct lock_class_key request_key;
int parent_irq;
struct module *owner;
const char *name;
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 287830739783..261305a213fd 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -19,11 +19,6 @@
#include "internals.h"
-/*
- * lockdep: we want to handle all irq_desc locks as a single lock-class:
- */
-static struct lock_class_key irq_desc_lock_class;
-
#if defined(CONFIG_SMP)
static int __init irq_affinity_setup(char *str)
{
@@ -222,8 +217,11 @@ static int init_desc(struct irq_desc *desc, int irq, int node,
}
raw_spin_lock_init(&desc->lock);
- lockdep_set_class(&desc->lock, &irq_desc_lock_class);
+ lockdep_register_key(&desc->lock_key);
+ lockdep_set_class(&desc->lock, &desc->lock_key);
mutex_init(&desc->request_mutex);
+ lockdep_register_key(&desc->request_key);
+ lockdep_set_class(&desc->lock, &desc->request_key);
init_waitqueue_head(&desc->wait_for_threads);
desc_set_defaults(irq, desc, node, affinity, owner);
irqd_set(&desc->irq_data, flags);
@@ -484,13 +482,17 @@ static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags,
return desc;
}
+/* Called from RCU context. Hence, must not sleep. */
static void irq_kobj_release(struct kobject *kobj)
{
struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
free_masks(desc);
free_percpu(desc->kstat_irqs);
- kfree(desc);
+ lockdep_unregister_key_nosync(&desc->request_key);
+ lockdep_unregister_key_nosync(&desc->lock_key);
+ init_rcu_head(&desc->rcu);
+ kfree_rcu(desc, rcu);
}
static void delayed_free_desc(struct rcu_head *rhp)
@@ -1064,12 +1066,6 @@ unsigned int kstat_irqs_usr(unsigned int irq)
void __irq_set_lockdep_class(unsigned int irq, struct lock_class_key *lock_class,
struct lock_class_key *request_class)
{
- struct irq_desc *desc = irq_to_desc(irq);
-
- if (desc) {
- lockdep_set_class(&desc->lock, lock_class);
- lockdep_set_class(&desc->request_mutex, request_class);
- }
}
EXPORT_SYMBOL_GPL(__irq_set_lockdep_class);
#endif
next prev parent reply other threads:[~2025-02-03 18:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-03 17:59 [PATCH 0/5] Make it easier to use nested locking " Bart Van Assche
2025-02-03 17:59 ` [PATCH 1/5] lockdep: Introduce lockdep_unregister_key_nosync() Bart Van Assche
2025-02-03 17:59 ` Bart Van Assche [this message]
2025-02-03 17:59 ` [PATCH 3/5] irq: Remove irq_set_lockdep_class() and __irq_set_lockdep_class() Bart Van Assche
2025-02-03 17:59 ` [PATCH 4/5] irq: Remove the IRQ_GC_INIT_NESTED_LOCK flag Bart Van Assche
2025-02-03 17:59 ` [PATCH 5/5] irq: Simplify gpiochip_add_data() Bart Van Assche
2025-02-03 19:40 ` [PATCH 0/5] Make it easier to use nested locking for interrupt descriptors Thomas Gleixner
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=20250203175939.3133477-3-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®