Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp706003ybz; Wed, 15 Apr 2020 17:08:34 -0700 (PDT) X-Google-Smtp-Source: APiQypJLrXv7VLgKhQRdbMDAQlvGMTjgTCJSuC8KLv9pG4Bx67fIXE/XPguMJ+EOJK+hNzmMCBAi X-Received: by 2002:a17:906:130e:: with SMTP id w14mr7508823ejb.155.1586995714267; Wed, 15 Apr 2020 17:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586995714; cv=none; d=google.com; s=arc-20160816; b=igXf/9XZX8n+Oul5rck7nZ2VErIKoFiAheOf9N69PgkMxkt+Mo08qEO+3/4thtlC6k 6tbbHIg6YzzBM0W3t5OpZFLtHvaPoGZ6udItYz8wo68+P/yLqBMGl/QAicxU7rv4OuNA qNw5thqB5lQv+wJQCJ0QVobUZIXxDBRuXdelMwXOgwK2qoVQ0fI3NhzgnHzxVcvszqtU FtSv+s+Rz5uaVtsPuURX6OXIPZhmrJqqc5RAeVFQLksgByxjO0ZKpaH8xyK2+rwgaPZ8 Ljir8wAhIHcGJwYLoBiyOXAzwaRDreWi8lAjeiWqdFmz7M5xXsmpuk2MLLzywZAOhJ+7 nhTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=k70JX9dGb5HJevGuiLeyAfGQdNacrtEnoRjysTqq8Jc=; b=qx/vk4Y1XSWcEsABEwxF9hGhWjBpEox7MspNGE8oHzMiEDkBbIX+DzMvYM4P8dQQgV vFrBDSfuLRZmPqxFTd9044XordmVr9ZtvvoWHED4x8B3rHOj1snZ+k2e00uh9Zrnz6xU 7v3wjtMg3D2Qu0Zu+SrvtpmgKUsSJw2Do0J2kcv9H8u852xjEnbHPmyLEKdbpv9YpX7z vweNdy0OR81YiYjK6VlS7VeU0FGHFSi19iuk6DvNWA5O93f/RvONTJqXzsKHuwlWm0Fs MHsLFLab5P0SqTEUgBvdWZi5e/yuyFS5fYc03GFQ7yRZSnnUWajnBFb2CAB0pRgKhEev Ol8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=FDikE0Gg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di15si1823811edb.423.2020.04.15.17.08.11; Wed, 15 Apr 2020 17:08:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=FDikE0Gg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391965AbgDOOYl (ORCPT + 99 others); Wed, 15 Apr 2020 10:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2387746AbgDOOYg (ORCPT ); Wed, 15 Apr 2020 10:24:36 -0400 X-Greylist: delayed 74408 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 15 Apr 2020 07:24:36 PDT Received: from merlin.infradead.org (unknown [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A021C061A0C; Wed, 15 Apr 2020 07:24:36 -0700 (PDT) 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; bh=k70JX9dGb5HJevGuiLeyAfGQdNacrtEnoRjysTqq8Jc=; b=FDikE0Ggh/CSVMyB2amhONlMRw pj/k9Wpy0t5hXqbTH8Fk3U1RIh8AM3QVcmZevBbPeUy7Qq0YvY+Wx9Id2QdbwxS6vBcNtnAP6vtD2 B85Y3yamN+NbhZ6Sa/Z6Wy1ILjyRn2i4cVsqJb1G10+Xa5+Sv604cMMxMdE0WMWSyQagUTheSl2xy 0RhDHbYgCXUHHX6Ye34Uc8IVvRUr1veavNPhUc79lU9r/K9mlSuBRGHt0peSl5Xsxq51EoBioTM19 hq6SWjBTNp+uBqsH91U7QklfQDGtevz7ymQoRpurVnzDawDpcs5wezfs8/jODWyrZ2fWzajkUgOLS lT+dIG5Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jOixe-0006JI-Df; Wed, 15 Apr 2020 14:24:18 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B8016304D58; Wed, 15 Apr 2020 16:24:15 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A45712BC703E8; Wed, 15 Apr 2020 16:24:15 +0200 (CEST) Date: Wed, 15 Apr 2020 16:24:15 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Jessica Yu Subject: Re: [PATCH 0/7] livepatch,module: Remove .klp.arch and module_disable_ro() Message-ID: <20200415142415.GH20730@hirez.programming.kicks-ass.net> References: <20200414182726.GF2483@worktop.programming.kicks-ass.net> <20200414190814.glra2gceqgy34iyx@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200414190814.glra2gceqgy34iyx@treble> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 14, 2020 at 02:08:14PM -0500, Josh Poimboeuf wrote: > On Tue, Apr 14, 2020 at 08:27:26PM +0200, Peter Zijlstra wrote: > > On Tue, Apr 14, 2020 at 11:28:36AM -0500, Josh Poimboeuf wrote: > > > Better late than never, these patches add simplifications and > > > improvements for some issues Peter found six months ago, as part of his > > > non-writable text code (W^X) cleanups. > > > > Excellent stuff, thanks!! > > > > I'll go brush up these two patches then: > > > > https://lkml.kernel.org/r/20191018074634.801435443@infradead.org > > https://lkml.kernel.org/r/20191018074634.858645375@infradead.org > > Ah right, I meant to bring that up. I actually played around with those > patches. While it would be nice to figure out a way to converge the > ftrace module init, I didn't really like the first patch. ftrace only needs it done after ftrace_module_enable(), which is before the notifier chain happens, so we can simply do something like so instead: diff --git a/kernel/module.c b/kernel/module.c index a3a8f6d0e144..89f8d02c3c3e 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3700,6 +3700,10 @@ static int prepare_coming_module(struct module *mod) if (err) return err; + module_enable_ro(mod, false); + module_enable_nx(mod); + module_enable_x(mod); + err = blocking_notifier_call_chain_robust(&module_notify_list, MODULE_STATE_COMING, MODULE_STATE_GOING, mod); err = notifier_to_errno(err); @@ -3845,10 +3849,6 @@ static int load_module(struct load_info *info, const char __user *uargs, if (err) goto bug_cleanup; - module_enable_ro(mod, false); - module_enable_nx(mod); - module_enable_x(mod); - /* Module is ready to execute: parsing args may do that. */ after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, -32768, 32767, mod, > It bothers me that both the notifiers and the module init() both see the > same MODULE_STATE_COMING state, but only in the former case is the text > writable. > > I think it's cognitively simpler if MODULE_STATE_COMING always means the > same thing, like the comments imply, "fully formed" and thus > not-writable: > > enum module_state { > MODULE_STATE_LIVE, /* Normal state. */ > MODULE_STATE_COMING, /* Full formed, running module_init. */ > MODULE_STATE_GOING, /* Going away. */ > MODULE_STATE_UNFORMED, /* Still setting it up. */ > }; > > And, it keeps tighter constraints on what a notifier can do, which is a > good thing if we can get away with it. Moo! -- but jump_label and static_call are on the notifier chain and I was hoping to make it cheaper for them. Should we perhaps weane them off the notifier and, like ftrace/klp put in explicit calls? It'd make the error handling in prepare_coming_module() a bigger mess, but it should work.