mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] genirq: add mutex and rcu locking to irq_desc_tree
@ 2017-10-31  2:28 Masahiro Yamada
  2017-10-31 22:29 ` Thomas Gleixner
  0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2017-10-31  2:28 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Peter Zijlstra, Ingo Molnar, Paul E . McKenney, Masahiro Yamada,
	linux-kernel

Add a mutex to prevent concurrency on the updater side of the
irq_desc radix tree.

Add rcu_read_lock/unlock to the reader side so that lifetimes of
leaf pointers of the radix tree are correctly managed.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 kernel/irq/irqdesc.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 82afb7e..928c896 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -12,6 +12,7 @@
 #include <linux/export.h>
 #include <linux/interrupt.h>
 #include <linux/kernel_stat.h>
+#include <linux/mutex.h>
 #include <linux/radix-tree.h>
 #include <linux/bitmap.h>
 #include <linux/irqdomain.h>
@@ -312,21 +313,32 @@ static void irq_sysfs_add(int irq, struct irq_desc *desc) {}
 #endif /* CONFIG_SYSFS */
 
 static RADIX_TREE(irq_desc_tree, GFP_KERNEL);
+static DEFINE_MUTEX(irq_desc_tree_mutex);
 
 static void irq_insert_desc(unsigned int irq, struct irq_desc *desc)
 {
+	mutex_lock(&irq_desc_tree_mutex);
 	radix_tree_insert(&irq_desc_tree, irq, desc);
+	mutex_unlock(&irq_desc_tree_mutex);
 }
 
 struct irq_desc *irq_to_desc(unsigned int irq)
 {
-	return radix_tree_lookup(&irq_desc_tree, irq);
+	struct irq_desc *desc;
+
+	rcu_read_lock();
+	desc = radix_tree_lookup(&irq_desc_tree, irq);
+	rcu_read_unlock();
+
+	return desc;
 }
 EXPORT_SYMBOL(irq_to_desc);
 
 static void delete_irq_desc(unsigned int irq)
 {
+	mutex_lock(&irq_desc_tree_mutex);
 	radix_tree_delete(&irq_desc_tree, irq);
+	mutex_unlock(&irq_desc_tree_mutex);
 }
 
 #ifdef CONFIG_SMP
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-31 22:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-31  2:28 [PATCH] genirq: add mutex and rcu locking to irq_desc_tree Masahiro Yamada
2017-10-31 22:29 ` Thomas Gleixner

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®