pinctrl: protect pinctrl_list add
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.
---
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
@@ -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
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=1051918Most likely corruption happen due lack of protection of
pinctrl_listwhen 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
-0list_add_tail (&p->node, &pinctrl_list); +mutex_unlock (&pinctrl_list_mutex);
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=1051918Most likely corruption happen due lack of protection of
pinctrl_listwhen 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
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.
---
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
@@ -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
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=1051918Most likely corruption happen due lack of protection of
pinctrl_listwhen adding new nodes to it. Patch corrects that.Fixes 42fed7ba44e ("pinctrl: move subsystem mutex to pinctrl_dev struct")Signed-off-by Stanislaw Gruszka <[email protected]>
(but not tested)
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=1051918Most likely corruption happen due lack of protection of
pinctrl_listwhen adding new nodes to it. Patch corrects that.Fixes 42fed7ba44e ("pinctrl: move subsystem mutex to pinctrl_dev struct")Signed-off-by Stanislaw Gruszka <[email protected]>
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