Commit f4ac7b5e authored by Benjamin Herrenschmidt's avatar Benjamin Herrenschmidt Committed by Paul Mackerras

[POWERPC] Fix device-tree locking vs. interrupts

Lockdep found out that we can occasionally take the device-tree
lock for reading from softirq time (from rtas_token called
by the rtas real time clock code called by the NTP code),
while we take it occasionally for writing without masking
interrupts. The combination of those two can thus deadlock.

While some of those cases of interrupt read lock could be fixed
(such as caching the RTAS tokens) I figured that taking the
lock for writing is so rare (device-tree modification) that we
may as well penalize that case and allow reading from interrupts.

Thus, this turns all the writers to take the lock with irqs
masked to avoid the situation.
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent f13f4ca8
...@@ -1332,12 +1332,14 @@ EXPORT_SYMBOL(of_node_put); ...@@ -1332,12 +1332,14 @@ EXPORT_SYMBOL(of_node_put);
*/ */
void of_attach_node(struct device_node *np) void of_attach_node(struct device_node *np)
{ {
write_lock(&devtree_lock); unsigned long flags;
write_lock_irqsave(&devtree_lock, flags);
np->sibling = np->parent->child; np->sibling = np->parent->child;
np->allnext = allnodes; np->allnext = allnodes;
np->parent->child = np; np->parent->child = np;
allnodes = np; allnodes = np;
write_unlock(&devtree_lock); write_unlock_irqrestore(&devtree_lock, flags);
} }
/* /*
...@@ -1348,8 +1350,9 @@ void of_attach_node(struct device_node *np) ...@@ -1348,8 +1350,9 @@ void of_attach_node(struct device_node *np)
void of_detach_node(struct device_node *np) void of_detach_node(struct device_node *np)
{ {
struct device_node *parent; struct device_node *parent;
unsigned long flags;
write_lock(&devtree_lock); write_lock_irqsave(&devtree_lock, flags);
parent = np->parent; parent = np->parent;
if (!parent) if (!parent)
...@@ -1380,7 +1383,7 @@ void of_detach_node(struct device_node *np) ...@@ -1380,7 +1383,7 @@ void of_detach_node(struct device_node *np)
of_node_set_flag(np, OF_DETACHED); of_node_set_flag(np, OF_DETACHED);
out_unlock: out_unlock:
write_unlock(&devtree_lock); write_unlock_irqrestore(&devtree_lock, flags);
} }
#ifdef CONFIG_PPC_PSERIES #ifdef CONFIG_PPC_PSERIES
...@@ -1461,20 +1464,21 @@ __initcall(prom_reconfig_setup); ...@@ -1461,20 +1464,21 @@ __initcall(prom_reconfig_setup);
int prom_add_property(struct device_node* np, struct property* prop) int prom_add_property(struct device_node* np, struct property* prop)
{ {
struct property **next; struct property **next;
unsigned long flags;
prop->next = NULL; prop->next = NULL;
write_lock(&devtree_lock); write_lock_irqsave(&devtree_lock, flags);
next = &np->properties; next = &np->properties;
while (*next) { while (*next) {
if (strcmp(prop->name, (*next)->name) == 0) { if (strcmp(prop->name, (*next)->name) == 0) {
/* duplicate ! don't insert it */ /* duplicate ! don't insert it */
write_unlock(&devtree_lock); write_unlock_irqrestore(&devtree_lock, flags);
return -1; return -1;
} }
next = &(*next)->next; next = &(*next)->next;
} }
*next = prop; *next = prop;
write_unlock(&devtree_lock); write_unlock_irqrestore(&devtree_lock, flags);
#ifdef CONFIG_PROC_DEVICETREE #ifdef CONFIG_PROC_DEVICETREE
/* try to add to proc as well if it was initialized */ /* try to add to proc as well if it was initialized */
...@@ -1494,9 +1498,10 @@ int prom_add_property(struct device_node* np, struct property* prop) ...@@ -1494,9 +1498,10 @@ int prom_add_property(struct device_node* np, struct property* prop)
int prom_remove_property(struct device_node *np, struct property *prop) int prom_remove_property(struct device_node *np, struct property *prop)
{ {
struct property **next; struct property **next;
unsigned long flags;
int found = 0; int found = 0;
write_lock(&devtree_lock); write_lock_irqsave(&devtree_lock, flags);
next = &np->properties; next = &np->properties;
while (*next) { while (*next) {
if (*next == prop) { if (*next == prop) {
...@@ -1509,7 +1514,7 @@ int prom_remove_property(struct device_node *np, struct property *prop) ...@@ -1509,7 +1514,7 @@ int prom_remove_property(struct device_node *np, struct property *prop)
} }
next = &(*next)->next; next = &(*next)->next;
} }
write_unlock(&devtree_lock); write_unlock_irqrestore(&devtree_lock, flags);
if (!found) if (!found)
return -ENODEV; return -ENODEV;
...@@ -1535,9 +1540,10 @@ int prom_update_property(struct device_node *np, ...@@ -1535,9 +1540,10 @@ int prom_update_property(struct device_node *np,
struct property *oldprop) struct property *oldprop)
{ {
struct property **next; struct property **next;
unsigned long flags;
int found = 0; int found = 0;
write_lock(&devtree_lock); write_lock_irqsave(&devtree_lock, flags);
next = &np->properties; next = &np->properties;
while (*next) { while (*next) {
if (*next == oldprop) { if (*next == oldprop) {
...@@ -1551,7 +1557,7 @@ int prom_update_property(struct device_node *np, ...@@ -1551,7 +1557,7 @@ int prom_update_property(struct device_node *np,
} }
next = &(*next)->next; next = &(*next)->next;
} }
write_unlock(&devtree_lock); write_unlock_irqrestore(&devtree_lock, flags);
if (!found) if (!found)
return -ENODEV; return -ENODEV;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment