Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1440428pxf; Fri, 19 Mar 2021 07:18:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIkSOdZyaXy/TCLls4dcMLTLMNmddKSYcD4noVWMHie93WY9CuerjTx3qoEpTWEu/FmKhg X-Received: by 2002:aa7:c346:: with SMTP id j6mr9773287edr.386.1616163485309; Fri, 19 Mar 2021 07:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616163485; cv=none; d=google.com; s=arc-20160816; b=N0u6N3u7MrMRDW3R/61v09UT7QCrLdsygYYoL235d11uchLbk3cp7fLZsTnWOTncLv 2bpd9cs9K3vU8TCHYgb0rjtwBhOIWWTKaXLf2sJQx7LcGwufisQG+uLEueL1aI40Ami5 ZvGilQofMv8AwlZ6GM+ldAmAFDmn5V+52NuQI2PrMAfiZYdr7Nw0UHoklC2nz38j4njy Yd5odj6+SunjUTq0rHttJzpYWlORRb1UCpXjsd49t4hGyDd8OUOZO3JchZKuouhFsN9+ UB2N1Aw77vobhrU8UvmvC9mMYZFeUwpz6g+LOceNsQ+iiJ2Cxa7kP4/33aPi9DOM0Xfr aNMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QHmsNWz5erj7LZSGlBMXaH8wQMGk/AE3dcxSEMqyrnE=; b=g7jS7ueouO9aoYMRXGUkHokIgUeba9aWdFv8cw4YZdVbgMvrF8VisKWerap1js9FDy fnB3Vf2qDh1S2sG0uPVpatxnXWrjrIfMMJGKAsCts8kFHkuooJOtrylwvonfoamfDig/ deVhSEIHjfm9BfLdE3v6fZhR49P5PUdlPVgpeSe9ZyFXroHAuNLmkS7IVnadFCtwv3+Q Uq9Mf7OelSMM2fc3s+bj3awgLNFG1hJnzBbPQTgSSHiGrR3KWNPYcSntM2K9w5/IUllh +fo/NXvdAVKejVFkuU6pqPhoVZaZD3LHH5s+D3lc6x3EO5FqegkTAfwQ1lj849od4cf6 rS8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=DpI7zKfW; 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 f7si4114777ejw.650.2021.03.19.07.17.41; Fri, 19 Mar 2021 07:18:05 -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=pass header.i=@infradead.org header.s=desiato.20200630 header.b=DpI7zKfW; 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 S229951AbhCSOOd (ORCPT + 99 others); Fri, 19 Mar 2021 10:14:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbhCSOOL (ORCPT ); Fri, 19 Mar 2021 10:14:11 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39E1C06174A for ; Fri, 19 Mar 2021 07:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=QHmsNWz5erj7LZSGlBMXaH8wQMGk/AE3dcxSEMqyrnE=; b=DpI7zKfWzFNb9DfteSYNkmk8G4 ZpQqWZzYzJOR0G64GSTjVNUwxPndWcYq4tAPRh92BJ+DtBNdUThV/uoIzis9zvBWhossBby7d/P9J Pgzg3yj3Z8Sy13/y+/uPLVX61u8zLk5biedSd+gHSob7MftTAQtLndethcH1WzXxb5aAh3+ZGbxmc cJhuShFg6eYyQYw9+Yd/2BZmUGwRZFQhSwvSr6eCL2SaWwmXhhwogJJylxY+1sPq71+d28oy6UUo1 CURDlj4/qAagGEqtWWXqZ34ekF5rfR8rnTK6atgH+uUWCaLgSpnfaJm3/8Z0QjZM4g7fKvCnUOE48 0CNrkOjQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lNFsx-007Wbh-Rd; Fri, 19 Mar 2021 14:13:56 +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 E90683006E0; Fri, 19 Mar 2021 15:13:54 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CDD082846DE2B; Fri, 19 Mar 2021 15:13:54 +0100 (CET) Date: Fri, 19 Mar 2021 15:13:54 +0100 From: Peter Zijlstra To: Rasmus Villemoes Cc: x86@kernel.org, jpoimboe@redhat.com, jbaron@akamai.com, rostedt@goodmis.org, ardb@kernel.org, linux-kernel@vger.kernel.org, sumit.garg@linaro.org, oliver.sang@intel.com, jarkko@kernel.org Subject: Re: [PATCH 2/3] static_call: Align static_call_is_init() patching condition Message-ID: References: <20210318113156.407406787@infradead.org> <20210318113610.636651340@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 19, 2021 at 02:31:19PM +0100, Rasmus Villemoes wrote: > On 18/03/2021 12.31, Peter Zijlstra wrote: > > The intent is to avoid writing init code after init (because the text > > might have been freed). The code is needlessly different between > > jump_label and static_call and not obviously correct. > > > > The existing code relies on the fact that the module loader clears the > > init layout, such that within_module_init() always fails, while > > jump_label relies on the module state which is more obvious and > > matches the kernel logic. > > > > Signed-off-by: Peter Zijlstra (Intel) > > --- > > kernel/static_call.c | 14 ++++---------- > > 1 file changed, 4 insertions(+), 10 deletions(-) > > > > --- a/kernel/static_call.c > > +++ b/kernel/static_call.c > > @@ -149,6 +149,7 @@ void __static_call_update(struct static_ > > }; > > > > for (site_mod = &first; site_mod; site_mod = site_mod->next) { > > + bool init = system_state < SYSTEM_RUNNING; > > I recently had occasion to look at whether that would be a suitable > condition for knowing whether __init stuff was gone, but concluded that > it's not. Maybe I'm wrong. init/main.c: Ha, me too: https://lkml.kernel.org/r/YFMToXI/3qjlMur4@hirez.programming.kicks-ass.net and I share your concern. > Dunno, probably overkill, but perhaps we could have an atomic_t (or > refcount, whatever) init_ref inited to 1, with init_ref_get() doing an > inc_unless_zero, and iff you get a ref, you're free to call (/patch) > __init functions and access __initdata, but must do init_ref_put(), with > PID1 dropping its initial ref and waiting for it to drop to 0 before > doing the *free_initmem() calls. I'd as soon simply add another SYSTEM state. That way we don't have to worry about who else looks at RUNNING for what etc..