Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp559211ybi; Wed, 19 Jun 2019 04:12:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5aytlzXmzZJTmvnw54yxrYWghAZgZb2XHJ/PxbznxZNdOTCZCbTQTMCJBO0Gj9eT5f1wM X-Received: by 2002:a63:2c43:: with SMTP id s64mr7252607pgs.50.1560942773241; Wed, 19 Jun 2019 04:12:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560942773; cv=none; d=google.com; s=arc-20160816; b=MZQ/3Qsbu9fLa8YMsCCU5fVDCt4Twx2O0C/9Rm2GDMDph0RxAsOyFHzSdXQigP758d 9YRSKLbDUMWCu3Tw5hXWIF5QLSXU+8MRrLnH/4dwssj/uA00AzK4ijW8AoILzOvq5WSZ OJXzzP5PDbg191QdsjIEVC0snczG0ZegbWTZPBS7FKfKSDEzVn/8GlJXVL/2LLQopO9F Odd1I/buFcb5GekZPrAkh6q7jdpB+1ir8L0HEYDZUTwgu7fmJebquHhh8FoB11x90HvA 6Cvuc21Rs9H1LDr17e58ENQOJiZhOyx9XAectw7mLzEPPoSuWOGEZnWeL+CyvGwOGWyw ceMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=RcZ3dcWI7y/RURv56j9Da9keknq9R7KwTM8Zd8qWrL8=; b=AkCTRaDPj91BfTSr1aNqYCpdAX/DOs1PzUgSO6ww/GFAp/FI1zXqQwlIaemUokJJuG wfRZ1NN0qQ5ijteXj+gI3/I6Ep6TARoMfAEXjin4choFEon44GENmn6n8YQ8UgZr3cTR 9TM0hI5SkW46JF3InJVMggVZg764Nz8G2bE/DRN7nV1eRzrn6weVJiMLxaPhmDOvwKrY VvUfKkuIgt+6v8U/6aIKhnWD7Z1xnGjTnrpZJXNaPn/1X/bH+sXOobNJ8OxrdCZvLHQw /57FenX3C7UwsL3COF6QJxgT7a54bNFyMZPVts0XX9F6O81UJQEUZieTbX58/DOaCSsx LDig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si1160067pju.64.2019.06.19.04.12.36; Wed, 19 Jun 2019 04:12:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731625AbfFSLMP (ORCPT + 99 others); Wed, 19 Jun 2019 07:12:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:60606 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727076AbfFSLMP (ORCPT ); Wed, 19 Jun 2019 07:12:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 15634AE74; Wed, 19 Jun 2019 11:12:14 +0000 (UTC) Date: Wed, 19 Jun 2019 13:12:12 +0200 (CEST) From: Miroslav Benes To: Peter Zijlstra cc: Jessica Yu , linux-kernel@vger.kernel.org, jpoimboe@redhat.com, jikos@kernel.org, pmladek@suse.com, rostedt@goodmis.org, ast@kernel.org, daniel@iogearbox.net Subject: Re: [RFC][PATCH] module: Propagate MODULE_STATE_COMING notifier errors In-Reply-To: <20190617090335.GX3436@hirez.programming.kicks-ass.net> Message-ID: References: <20190617090335.GX3436@hirez.programming.kicks-ass.net> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 Jun 2019, Peter Zijlstra wrote: > > Some module notifiers; such as jump_label_module_notifier(), > tracepoint_module_notify(); can fail the MODULE_STATE_COMING callback > (due to -ENOMEM for example). However module.c:prepare_coming_module() > ignores all such errors, even though this function can already fail due > to klp_module_coming(). It does, but there is no change from the pre-prepare_coming_module() times. Coming notifiers were called in complete_formation(), their return values happily ignored and going notifiers not called to clean up even before. > Therefore, propagate the notifier error and ensure we call the GOING > notifier when we do fail, to ensure cleanup for all notifiers that > didn't fail. Auditing all notifiers to make sure calling GOING without > COMING first is OK found no obvious problems with that, but it did find > a whole bunch of issues with return values, so clean those up too. Jessica, do you know why coming notifiers do not return errors without this patch (or to be precise, blocking_notifier_call_chain() return value is not taken into the account)? We have come across the issue couple of times already and I think there was a reason, but I cannot remember anything and the code does not help either. Also the situation around the return values themselves is not completely clear. If there is no NOTIFY_STOP_MASK set, only the return value of the last notifier called is returned, so good that you checked, Peter. > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -3638,9 +3638,10 @@ static int prepare_coming_module(struct module *mod) > if (err) > return err; > > - blocking_notifier_call_chain(&module_notify_list, > - MODULE_STATE_COMING, mod); > - return 0; > + ret = blocking_notifier_call_chain(&module_notify_list, > + MODULE_STATE_COMING, mod); > + ret = notifier_to_errno(ret); > + return ret; > } > > static int unknown_module_param_cb(char *param, char *val, const char *modname, > @@ -3780,7 +3781,7 @@ static int load_module(struct load_info *info, const char __user *uargs, > > err = prepare_coming_module(mod); > if (err) > - goto bug_cleanup; > + goto coming_cleanup; Not good. klp_module_going() is not prepared to be called without klp_module_coming() succeeding. "Funny" things might happen. Also destroy_params() might be called without parse_args() first now. So it calls for more fine-grained error handling. Miroslav