Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp580334ybi; Wed, 19 Jun 2019 04:35:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDPbFtWTR13ugM9Htjg1fGXj25M5yn9U9sByOwPaIXBdBZ+lw9yj0bdS5uYRJY7xx7XdTr X-Received: by 2002:a63:dc50:: with SMTP id f16mr7467916pgj.447.1560944110116; Wed, 19 Jun 2019 04:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560944110; cv=none; d=google.com; s=arc-20160816; b=zt+5fGJKNx5EdAR6cTSZNWePhm89vjFKh6uscTssOTqO/SB/Slp0MXuQXFJx7B8FoH uPSUaKGehGcgyNfeEm5yrSgAqECRM1bZQ2ZbNkyD0a0+682XU0TFgDL77C8ia8a+cDa1 0gHqcpBCQNsf94mRwwd8efI0DMaPYIANzzfdY5ReWapnWXrIovX2HoNo4rDbHLXG1aQm QxMNn9siS4h2zE1KMsehBlQpqA7AXMo/XT/ixbiDFGvv0TS1Alc+qZE5+tnF88Qp2+Ow 6nZ6p7RBGHs8J7Ebd+pJgmJKKGSXVsqB+33H6e3XvJWKCBOKCVHYjCVdcomi/jRaPsnf liPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=nd4eBypmiHuJCd/nOCanYfdJy+o2wCHZjp7YtMP41+k=; b=EGpwd55mAliaGJzWn1Nige45xhfq194AtjTIFcFlqKOXq4GFuD2zUAtp1gQYREk4fs dilx2Baa83zIREM2Qy6tYSt4wGzGXFERrzvaaKGPeTC5XCctZURMH1fKZ0i+XP05YPNB prr3XP4whu6V0njPdTYf8EiqZocErwGGIdr/u64iiJvJiDJE9Md+2x+LMqd98hC55azf EdfcEtMci1g9PPnXl+SDDOPvjPTfHUz8iNKAOa3eeIQhxtmr6So2CknULlMfS0n2a5yQ HenGka7wQYrNIbmqyNlaf5ULUi0OXv47V8Co94+B+E9aT+/XKKxSAkWvXRKJBJs8DDXa N0wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=ACiBKSsZ; 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 ay6si10568323plb.203.2019.06.19.04.34.54; Wed, 19 Jun 2019 04:35:10 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=ACiBKSsZ; 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 S1727250AbfFSLeG (ORCPT + 99 others); Wed, 19 Jun 2019 07:34:06 -0400 Received: from merlin.infradead.org ([205.233.59.134]:58642 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726826AbfFSLeG (ORCPT ); Wed, 19 Jun 2019 07:34:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=nd4eBypmiHuJCd/nOCanYfdJy+o2wCHZjp7YtMP41+k=; b=ACiBKSsZLenlmf66IBzI6HcsA rGodTH9ItcUy1dkQK0itc7TxiyYyuGFsygW6DXRa1Fw3WJKiYd1cadEsdp85cgwuoIrC5ocKQ81Ha lnslaIQVgdLqhkrC4hTGF1uTT+gRx+HEOGjhhsChQ9FuTIRnPwLbVU4zs6BXlAz1tytBBei7oiGY4 rftRAKzQakus+hSwL5hD6HBnM8gOmZdnBah3xAx+tfxbMYfGYX0+D77I5NcK6tsjw/jKjcQe5zxlu MbkAzZ8qISSJkKRCtLZDEnJ3KLrd5l6WpUVzuzk1KMyfaBlKu7kow7401QwQ6kKSsu//xlsPnQOVJ 0af4bzi9A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hdYqD-0006hO-UC; Wed, 19 Jun 2019 11:33:26 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B643F20796503; Wed, 19 Jun 2019 13:33:24 +0200 (CEST) Date: Wed, 19 Jun 2019 13:33:24 +0200 From: Peter Zijlstra To: Miroslav Benes 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 Message-ID: <20190619113324.GO3463@hirez.programming.kicks-ass.net> References: <20190617090335.GX3436@hirez.programming.kicks-ass.net> <20190619112350.GN3419@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190619112350.GN3419@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 19, 2019 at 01:23:50PM +0200, Peter Zijlstra wrote: > On Wed, Jun 19, 2019 at 01:12:12PM +0200, Miroslav Benes wrote: > > > @@ -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. > > Bah, I did look at that but failed to spot it :/ > > > So it calls for more fine-grained error handling. > > Another approach that I considered was trying to re-iterate the notifier > list up until the point we got, but that was fairly non-trivial and > needed changes to the notifier crud itself. > > I'll try again. 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) + 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,