Re: [PATCH 2/5] of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock
From: Rob Herring
Date: Thu Aug 03 2023 - 13:37:22 EST
On Wed, Aug 2, 2023 at 3:33 PM Rob Herring <robh@xxxxxxxxxx> wrote:
>
> On Tue, Aug 1, 2023 at 9:35 PM Andy Shevchenko
> <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> >
> > On Wed, Aug 02, 2023 at 06:28:48AM +0300, Andy Shevchenko wrote:
> > > On Tue, Aug 01, 2023 at 03:54:45PM -0600, Rob Herring wrote:
> > > > While originally it was fine to format strings using "%pOF" while
> > > > holding devtree_lock, this now causes a deadlock. Lockdep reports:
> > > >
> > > > of_get_parent from of_fwnode_get_parent+0x18/0x24
> > > > ^^^^^^^^^^^^^
> > > > of_fwnode_get_parent from fwnode_count_parents+0xc/0x28
> > > > fwnode_count_parents from fwnode_full_name_string+0x18/0xac
> > > > fwnode_full_name_string from device_node_string+0x1a0/0x404
> > > > device_node_string from pointer+0x3c0/0x534
> > > > pointer from vsnprintf+0x248/0x36c
> > > > vsnprintf from vprintk_store+0x130/0x3b4
> > > >
> > > > To fix this, move the printing in __of_changeset_entry_apply() outside the
> > > > lock. As there's already similar printing of the same changeset actions,
> > > > refactor all of them to use a common action print function. This has the
> > > > side benefit of getting rid of some ifdefs.
> >
> > ...
> >
> > > > v3:
> > > > - Add missing 'static' reported by 0-day
> > >
> > > It reported two issues (at least what I see).
>
> Indeed. I missed the 2nd one.
>
> > ...
> >
> > > > + if (pr_debug("notify "))
> > >
> > > This is weird. How did you compile it?
>
> I agree it's a weird pattern...
>
> > Urgh, you need to fix dynamic debug macros to return an error code.
>
> Or adding a 'pr_debug_cont' macro would do it. I'm inclined to wrap it
> in an "#ifdef DEBUG" and be done with it.
Here's what I've come up with instead:
#define _do_print(func, prefix, action, node, prop, ...) ({ \
if (prop) \
func(prefix "%-15s %pOF:%s\n", ##__VA_ARGS__,
action_names[action], node, prop); \
else \
func(prefix "%-15s %pOF\n", ##__VA_ARGS__, action_names[action], node);\
})
#define of_changeset_action_err(...) _do_print(pr_err, __VA_ARGS__)
#define of_changeset_action_debug(...) _do_print(pr_debug, __VA_ARGS__)
Rob