Re: [RFC][PATCH] module: Propagate MODULE_STATE_COMING notifier errors

From: Peter Zijlstra
Date: Wed Jun 19 2019 - 08:07:12 EST


On Wed, Jun 19, 2019 at 01:35:08PM +0200, Peter Zijlstra wrote:
> On Wed, Jun 19, 2019 at 01:33:24PM +0200, Peter Zijlstra wrote:
> > How's something like so:
> >
> > diff --git a/kernel/module.c b/kernel/module.c
> > index 80c7c09584cf..eba6560c89da 100644
> > --- a/kernel/module.c
> > +++ b/kernel/module.c
> > @@ -3631,16 +3631,28 @@ static int complete_formation(struct module *mod, struct load_info *info)
> >
> > static int prepare_coming_module(struct module *mod)
> > {
> > - int err;
> > + struct blocking_notifier_head *nh = &module_notify_list;
> > + int err, nr;
> >
> > ftrace_module_enable(mod);
> > err = klp_module_coming(mod);
> > if (err)
> > return err;
> >
> > - blocking_notifier_call_chain(&module_notify_list,
> > - MODULE_STATE_COMING, mod);
> > - return 0;
> > + if (!rcu_access_pointer(nh->head))
> > + return 0;
> > +
> > + down_read(&nh->rwsem);
> > + ret = notifier_call_chain(&nh->head, MODULE_STATE_COMING, mod, -1, &nr);
> > + if (ret & NOTIFIER_STOP_MASK)
>
> It compiles _lots_ better with s/ret/err/ on.
>
> > + notifier_call_chain(&nh->head, MODULE_STATE_GOING, mod, nr, NULL);
> > + up_read(&nh->rwsem);
> > +
> > + err = notifier_to_err(err);
> > + if (err)
> > + klp_module_going(mod);
> > +
> > + return err;
> > }
> >
> > static int unknown_module_param_cb(char *param, char *val, const char *modname,

Rafael, how is kernel/power/user.c snapshot_open() not broken (any any
other __pm_notifier_call_chain() user)?

afaict the __pm_notifier_call_chain() thing is broken in two ways:

- there can be a change to the notifier list between the PREPARE and
POST iteration

- the error value isn't put through notifier_to_errno().