Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1349989pxf; Fri, 19 Mar 2021 05:26:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznG1ne83++I+WIaajhXOYNUX5XR+KjTkjzHTFF6AmYne6+9/SqxUImit4EhK3HoCbrJakR X-Received: by 2002:a17:906:f296:: with SMTP id gu22mr3964706ejb.20.1616156811665; Fri, 19 Mar 2021 05:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616156811; cv=none; d=google.com; s=arc-20160816; b=llkp5RReLVouvGYCKAiTxwCfvLPI72TCS0aHm9xQYVlcyT5J7wlZJuFBUnJ8MT3i9n 5YB86sHgB099SaMJq8oerR1/76oW431ElrO5wtDxrj4qflVNIJcRDrxPeAgUtHMB3WXk 9jpba9hY4jMIZ26crQ7K59RJfJ6jkUVIDCJEl01b59bjjM3AwSaZW+qNNjCAdaPoewhC XiAcjTDS7LYEibhleky58CG5YnX10OLvR/nZinIc5rFQbfndmkOW2mvBwQFnsDgHihiF w9r4O4K8KiEBQwnHPFkH3HgFUPFXD/JBk3JLjUGeKEYCda5qNQTWAr5g3QouXsJRxbpd hEwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=EuFN8GZSBvQdVGnuFOlfzsjSkAhg+4MNcecV7My0xNU=; b=RFJoAw9G5jQpzdMOckKUbsnf97piptapzr8p4Re1VUqi7YF8h9ptzarw/TA/I/qTis EiQCcVkseSPE820ElrTvs8OlMirnq2KdEIyb4B3rAjTOf0A1fqSWaKIor2EOXahN+wnb ClEM5m7SImcVmhD4ttgD6m0uGG0sPcJRE7GVEN+mQkOWGnZIhORlhgeY5LfSf1TLREhm ObJyoSTzFJ2qgEnV1UMA8IW14te9QYnPXoG3gW7HQfHwj8Jenhg6mScOHRAHEqz7ew/w 9pIjBpBbG1L7G8v2LS/fbAE59wBf6p4TloBgVJOLjtR07A1WzApdqY9F0b2CQ2goKckQ NlgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Cm2r9omR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=8lE0d5xz; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v25si3994267eju.48.2021.03.19.05.26.28; Fri, 19 Mar 2021 05:26:51 -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=@linutronix.de header.s=2020 header.b=Cm2r9omR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=8lE0d5xz; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbhCSMZf (ORCPT + 99 others); Fri, 19 Mar 2021 08:25:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbhCSMZM (ORCPT ); Fri, 19 Mar 2021 08:25:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18469C06175F; Fri, 19 Mar 2021 05:25:10 -0700 (PDT) Date: Fri, 19 Mar 2021 12:25:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1616156708; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EuFN8GZSBvQdVGnuFOlfzsjSkAhg+4MNcecV7My0xNU=; b=Cm2r9omRdA2sy/IXNJ0vDXrkMMdSooH3GrDevAvIdmZ5Wo8zzGcQuJVza5B0iprA9WLKGW KTndrFy45V5o1bdyYxgr4uwlTVCZyGYU40mwjNrzG+lRp9FWXtKZ2hl4iptJcbr8D0U5El M9Spo1lEsvq8DgSNyIxpTnyyH16kHPkt5TJ0Pv/pTrM7JqZhQU+/JCiMICQqE64WMXyPZH 5p6leFa5VVRt7MGEWnZJ/F8LEeqGZy0zUZCIz8wooIvvkQdgzLVoYXnqhtV+t72gWIttWP bzHbDk8gXRBhJOcuZMoeee/wFzpp07VrsvXQsrMIYGd0RHxsuoIm1k/qHPg4TQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1616156708; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EuFN8GZSBvQdVGnuFOlfzsjSkAhg+4MNcecV7My0xNU=; b=8lE0d5xzlUgOFrnPypq0KrZbefZDooYBTgKLbsKNjrL9bK7ZP/ARhpL0T/wPzFxzXYrMT2 bYhTuwqHu53K8jCQ== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/urgent] static_call: Align static_call_is_init() patching condition Cc: "Peter Zijlstra (Intel)" , Jarkko Sakkinen , Sumit Garg , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210318113610.636651340@infradead.org> References: <20210318113610.636651340@infradead.org> MIME-Version: 1.0 Message-ID: <161615670801.398.11880263831906331601.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/urgent branch of tip: Commit-ID: 698bacefe993ad2922c9d3b1380591ad489355e9 Gitweb: https://git.kernel.org/tip/698bacefe993ad2922c9d3b1380591ad489355e9 Author: Peter Zijlstra AuthorDate: Thu, 18 Mar 2021 11:29:56 +01:00 Committer: Peter Zijlstra CommitterDate: Fri, 19 Mar 2021 13:16:44 +01:00 static_call: Align static_call_is_init() patching condition 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) Acked-by: Jarkko Sakkinen Tested-by: Sumit Garg Link: https://lkml.kernel.org/r/20210318113610.636651340@infradead.org --- kernel/static_call.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/kernel/static_call.c b/kernel/static_call.c index 080c8a9..fc22590 100644 --- a/kernel/static_call.c +++ b/kernel/static_call.c @@ -149,6 +149,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func) }; for (site_mod = &first; site_mod; site_mod = site_mod->next) { + bool init = system_state < SYSTEM_RUNNING; struct module *mod = site_mod->mod; if (!site_mod->sites) { @@ -168,6 +169,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func) if (mod) { stop = mod->static_call_sites + mod->num_static_call_sites; + init = mod->state == MODULE_STATE_COMING; } #endif @@ -175,16 +177,8 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func) site < stop && static_call_key(site) == key; site++) { void *site_addr = static_call_addr(site); - if (static_call_is_init(site)) { - /* - * Don't write to call sites which were in - * initmem and have since been freed. - */ - if (!mod && system_state >= SYSTEM_RUNNING) - continue; - if (mod && !within_module_init((unsigned long)site_addr, mod)) - continue; - } + if (!init && static_call_is_init(site)) + continue; if (!kernel_text_address((unsigned long)site_addr)) { WARN_ONCE(1, "can't patch static call site at %pS",