linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: "H. Nikolaus Schaller" <hns@goldelico.com>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	kernel@pyra-handheld.com,
	Discussions about the Letux Kernel <letux-kernel@openphoenux.org>
Subject: Re: [Letux-kernel] BUG: drivers/pinctrl/core: races in pinctrl_groups and deferred probing
Date: Sun, 17 Jun 2018 23:46:51 -0700	[thread overview]
Message-ID: <20180618064651.GL112168@atomide.com> (raw)
In-Reply-To: <4DE2E482-B0D3-4799-9E2D-74E2180B305B@goldelico.com>

* H. Nikolaus Schaller <hns@goldelico.com> [180616 11:10]:
> There is also good news: the selectors are now assigned in strict sequence.
> This is a big improvement:

OK thanks for testing.

> If slots 17 and 18 do not really exist (or are deleted after failed probing), there is
> a NULL return. Which triggers the strcmp(NULL), because the strcmp is not guarded against
> non-existing slots in the radix tree.
> 
> So a simple workaround could be:
> 
> 		if (gname && !strcmp(gname, pin_group)) {
> 
> But I think the fundamental problem is that the same driver assigns multiple slots if
> probing is deferred.
> 
> Therefore, I tried to find out more why this happens. Here are some more observations by
> studying the code and adding a dump_stack() inside pinctrl_generic_add_group():
> 
> 1.  the records stored in the radix tree are allocated through devm_kzalloc() within
>     pinctrl_generic_add_group().
> 2.  I have not found a mechanism that removes them from the radix tree if they are
>     devm freed which IMHO happens if the probe fails (and all devm objects are
>     rewound).
> 3.  I could not observe calls to pinctrl_generic_remove_group()
> 4.  this means a stale pointer to the group_desc is still stored in the radix tree
>     if driver probing fails
> 5.  scanning through the radix tree for a matching gname in pinctrl_get_group_selector()
>     accesses this stale radix tree entry.
>     It has either been overwritten by something else - or contains a dangling pointer for
>     group->name. This explains the randomness of the problem but that it is also repeatable
>     to some extent. For a pure race of some 100 instructions it happens IMHO too often.
> 6.  the pinctrl_generic_add_group() is called from create_pinctrl() through 
>     pinctrl_dt_to_map() and pcs_dt_node_to_map(), i.e. before the pinctrl_maps_mutex
>     is locked in create_pinctrl(). This means that pinctrl_generic_add_group() is
>     not locked in this case.
> 
> I hope this helps to pinpoint and solve the remaining bugs.

Yes sounds like that's where things still go wrong. I'll take a look
if it makes sense to assign the selector from the pin controller
driver instead or just ignoring the holes.

I'll try to debug the devm issue too.

Regards,

Tony

  reply	other threads:[~2018-06-18  6:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-13 12:39 BUG: drivers/pinctrl/core: races in pinctrl_groups and deferred probing H. Nikolaus Schaller
2018-06-14 12:01 ` Tony Lindgren
2018-06-14 12:12   ` H. Nikolaus Schaller
2018-06-15  6:58     ` Tony Lindgren
2018-06-15 11:13       ` Tony Lindgren
2018-06-15 11:18         ` H. Nikolaus Schaller
2018-06-16 11:07           ` [Letux-kernel] " H. Nikolaus Schaller
2018-06-18  6:46             ` Tony Lindgren [this message]
2018-06-18  8:22             ` Andy Shevchenko
2018-06-18  9:14               ` Tony Lindgren
2018-06-18  9:29                 ` H. Nikolaus Schaller
2018-06-18  9:54                   ` Tony Lindgren
2018-06-18  9:59                     ` H. Nikolaus Schaller
     [not found]                     ` <CA+Ot1OxNj30KgHWJHXgWbnXYkNXTNvd_t-b6+uG3u=z8+pZf2Q@mail.gmail.com>
2018-06-18 11:51                       ` Tony Lindgren
2018-06-18 16:43                         ` H. Nikolaus Schaller
2018-06-18 18:17                           ` Tony Lindgren
2018-06-18 18:30                             ` H. Nikolaus Schaller
2018-06-19  4:34                               ` Tony Lindgren
2018-06-19  4:51                                 ` H. Nikolaus Schaller
2018-06-19  6:11                                   ` Tony Lindgren
2018-06-19  6:39                                     ` H. Nikolaus Schaller
2018-06-19  7:15                                       ` Tony Lindgren

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=20180618064651.GL112168@atomide.com \
    --to=tony@atomide.com \
    --cc=hns@goldelico.com \
    --cc=kernel@pyra-handheld.com \
    --cc=letux-kernel@openphoenux.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).