Skip to contentSkip to conversation

pinctrl: protect pinctrl_list add

PATCH Superseded Stanislaw Gruszka 3 participants 6 messages Feb 3, 2014 – Feb 4, 2014 Pin control

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: protect pinctrl_list add

We have few fedora bug reports about list corruption on pinctrl, for example:
https://bugzilla.redhat.com/show_bug.cgi?id=1051918

Most likely corruption happen due lack of protection of pinctrl_list when adding new nodes to it. Patch corrects that.

Fixes 57b676f9c1b ("pinctrl: fix and simplify locking")

---
I only compile tested patch, also did not get test results from bug reporters yet. But I'm pretty confident that patch fixes the problem and does not cause any other deadlock.

 drivers/pinctrl/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pinctrl/core.c +2 -0
index 5ee61a4..cab020a 100644
@@ -851,7 +851,9 @@ static struct pinctrl *create_pinctrl(struct device *dev)
 	kref_init(&p->users);
 
 	/* Add the pinctrl handle to the global list */
+	mutex_lock(&pinctrl_list_mutex);
 	list_add_tail(&p->node, &pinctrl_list);
+	mutex_unlock(&pinctrl_list_mutex);
 
 	return p;
 }
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 8 lines · Stanislaw Gruszka

We have few fedora bug reports about list corruption on pinctrl, for example:
https://bugzilla.redhat.com/show_bug.cgi?id=1051918

Most likely corruption happen due lack of protection of pinctrl_list when adding new nodes to it. Patch corrects that.

Fixes 57b676f9c1b ("pinctrl: fix and simplify locking")

After that patch ...

drivers/pinctrl/core.c static struct pinctrl *create_pinctrl(struct device *dev) · line 854

Quoted 7 lines
drivers/pinctrl/core.c +1 -0
@@ -851,7 +851,9 @@ static struct pinctrl *create_pinctrl(struct device *dev)
 	kref_init(&p->users);
 
 	/* Add the pinctrl handle to the global list */
+	mutex_lock(&pinctrl_list_mutex);

That variable doesn't exist; it got replaced with the "global" pinctrl_mutex. Also, since that patch, IIRC some other changes have been made to the locking structure, so this patch might need adjustments not to conflict with those changes?

Quoted 2 lines
drivers/pinctrl/core.c +1 -0
 	list_add_tail(&p->node, &pinctrl_list);
+	mutex_unlock(&pinctrl_list_mutex);
#2 lore raw
Quoted 17 lines · Stephen Warren
Quoted 8 lines · Stanislaw Gruszka

We have few fedora bug reports about list corruption on pinctrl, for example:
https://bugzilla.redhat.com/show_bug.cgi?id=1051918

Most likely corruption happen due lack of protection of pinctrl_list when adding new nodes to it. Patch corrects that.

Fixes 57b676f9c1b ("pinctrl: fix and simplify locking")

After that patch ...

Quoted 5 lines
drivers/pinctrl/core.c +0 -0
@@ -851,7 +851,9 @@ static struct pinctrl *create_pinctrl(struct device *dev)
 	kref_init(&p->users);
 
Quoted 7 lines

drivers/pinctrl/core.c static struct pinctrl *create_pinctrl(struct device *dev) · line 854

Quoted 2 lines
drivers/pinctrl/core.c +1 -0
 	/* Add the pinctrl handle to the global list */
+	mutex_lock(&pinctrl_list_mutex);

That variable doesn't exist; it got replaced with the "global" pinctrl_mutex. Also, since that patch, IIRC some other changes have been made to the locking structure, so this patch might need adjustments not to conflict with those changes?

I missed that, I just quicky looked at git blame. This mutex was added again by commit 42fed7ba44e4e8c1fb27b28ad14490cb1daff3c7 "pinctrl: move subsystem mutex to pinctrl_dev struct"
and actually this is the commit that introduce the bug. Before it, list_add_tail() was called inside pinctrl_get_locked() and was protected by global pinctrl_mutex.

I'll post patch with fixed "Fixes:" shortly.

Thanks
Stanislaw

#3 lore raw

PATCH v2 1/1 pinctrl: protect pinctrl_list add

We have few fedora bug reports about list corruption on pinctrl, for example:
https://bugzilla.redhat.com/show_bug.cgi?id=1051918

Most likely corruption happen due lack of protection of pinctrl_list when adding new nodes to it. Patch corrects that.

Fixes 42fed7ba44e ("pinctrl: move subsystem mutex to pinctrl_dev struct")

---
I only compile tested patch, also did not get test results from bug reporters yet. But I'm pretty confident that patch fixes the problem and does not cause any other deadlock.

v1 -> v2: point correct first bad commit.

 drivers/pinctrl/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pinctrl/core.c +2 -0
index 5ee61a4..cab020a 100644
@@ -851,7 +851,9 @@ static struct pinctrl *create_pinctrl(struct device *dev)
 	kref_init(&p->users);
 
 	/* Add the pinctrl handle to the global list */
+	mutex_lock(&pinctrl_list_mutex);
 	list_add_tail(&p->node, &pinctrl_list);
+	mutex_unlock(&pinctrl_list_mutex);
 
 	return p;
 }
Signature · 1 line
1.7.11.7
Acked-by Stephen Warren on v2 1/1
#4 lore raw
Quoted 10 lines · Stanislaw Gruszka

We have few fedora bug reports about list corruption on pinctrl, for example:
https://bugzilla.redhat.com/show_bug.cgi?id=1051918

Most likely corruption happen due lack of protection of pinctrl_list when adding new nodes to it. Patch corrects that.

Fixes 42fed7ba44e ("pinctrl: move subsystem mutex to pinctrl_dev struct")

(but not tested)

#5 lore raw
In reply to Stanislaw Gruszka
Quoted 10 lines · Stanislaw Gruszka

We have few fedora bug reports about list corruption on pinctrl, for example:
https://bugzilla.redhat.com/show_bug.cgi?id=1051918

Most likely corruption happen due lack of protection of pinctrl_list when adding new nodes to it. Patch corrects that.

Fixes 42fed7ba44e ("pinctrl: move subsystem mutex to pinctrl_dev struct")
Quoted 6 lines

---
I only compile tested patch, also did not get test results from bug reporters yet. But I'm pretty confident that patch fixes the problem and does not cause any other deadlock.

v1 -> v2: point correct first bad commit.

Patch applied. Thanks for bringing this to our attention!

Yours,
Linus Walleij