From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B31EC433E3 for ; Thu, 25 Mar 2021 11:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D259D61A43 for ; Thu, 25 Mar 2021 11:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231643AbhCYL2j (ORCPT ); Thu, 25 Mar 2021 07:28:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:34218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230350AbhCYLZw (ORCPT ); Thu, 25 Mar 2021 07:25:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DF00F61A2E; Thu, 25 Mar 2021 11:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616671551; bh=hr/+gkGBj/uQZNi8ZyyGs/rsPjt2/D6F9uCb8FTE3Wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ce/tEGIEv2slSbfhKbql7ea3B0tVbcV+H3rul5NiwLw4b/9ZUd2j3FGWSTiBm2Jqa liw6jrnZigO5QG90TpwNj2KTtzpJ9atAPMbe1jxcFpZrY6etyNVOR3zKDXo0SbZq2v FZxyzu5ohNRlND1GFsuGMoUirRfDADkNwjpfXG5B6MWda2RlMo0vZ1FL7zF4E10NRa WA86P6uFJ6gtEiLiEAJ6Eo+l8IzHblHjOMwLLybqMuUySNtY1X7r1Q5jfdq7aNK5WG wemvCOLyNPk+owPZSG55u9Kpt/9CLId2qwSSV3GFOJ7OcO4R2kFBbvs/j3ArE3xT6o 3QboqGuJO4Amg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Zijlstra , Jarkko Sakkinen , Sumit Garg , Sasha Levin Subject: [PATCH AUTOSEL 5.11 40/44] static_call: Align static_call_is_init() patching condition Date: Thu, 25 Mar 2021 07:24:55 -0400 Message-Id: <20210325112459.1926846-40-sashal@kernel.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210325112459.1926846-1-sashal@kernel.org> References: <20210325112459.1926846-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra [ Upstream commit 698bacefe993ad2922c9d3b1380591ad489355e9 ] 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 Signed-off-by: Sasha Levin --- 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 84565c2a41b8..781ff0fd031d 100644 --- a/kernel/static_call.c +++ b/kernel/static_call.c @@ -144,6 +144,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) { @@ -163,6 +164,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 @@ -170,16 +172,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", -- 2.30.1