Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3351243pxf; Mon, 5 Apr 2021 09:44:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydczBYxRVG36ru/7DmD1TWqaiPzBIVX570ciaSxNeRS/Uk9ME2PA1nk8RulKumkIKLdJ/V X-Received: by 2002:a17:906:288b:: with SMTP id o11mr1079984ejd.151.1617641086166; Mon, 05 Apr 2021 09:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617641086; cv=none; d=google.com; s=arc-20160816; b=iKvFmffScFKrdjqCJBDLkth7pX5poLtovu1/EkOJT7pBu2Aa5UsizGUChdBmp5+vUV wQbSyk58QaYI/ycW/bRVRTbHwmRHZJdFRKdWGCaZ2ocQO+c9Cz1B0Tw8N+MK3GQaBxus yOHC3hA9F/60bSzS2sN8WaxDPeFqum3JdUP2tZMrS2YzLVLWRKDkk6PSJ8Nnflt22ZRt WYZUyG1CHhOsxuizSUj2RvT0WwyCwIZrtrTH0xevMGdI11cvJwypcO9JsUDV5LQLsi/x dqsXt4izFHLeQ/dFIEfG638dvlG8F1TlzMmX+djgVLLJRflkUUhYmy4/d4KddQhcD3xo mPnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Yk6Mhn13kRVAoSL2Cr9DAhbmnHitlevKfgsgGBg69AU=; b=o0bzby06SUj5sVjwXX6yeVJOdSwRvyz9MH+82vI/hTAKDx4MSi8ctQLSqDKz78DEsh BljALYS8FqidJ6wgFivqlhbFpu5vbJFZptHCyqiys4ZnABCp3B6zcGjN6EWYCMZ9Lji7 3wuy+YvlBMEteAJfC5RioWD1FGALIIPsPd2gmUJQ/p9r9SZq4wQFeV7Uya2J+WPFb31D KLEJ48wBwYOdX6kWKL/xoUe3QYDej4CFTaloa8qX1FwGNQe5kfhYU8bbjOPP8VcLrGlm sVkR9mCwKxcdDZr1HS30TOJDCdBftJAG2qVCxQvvaLVXtXca7AV4rqSynySi2vJzElVh tr/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dhER7hNz; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq9si3218795edb.300.2021.04.05.09.44.22; Mon, 05 Apr 2021 09:44:46 -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=@linuxfoundation.org header.s=korg header.b=dhER7hNz; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240750AbhDEJQo (ORCPT + 99 others); Mon, 5 Apr 2021 05:16:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:60310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239346AbhDEJNC (ORCPT ); Mon, 5 Apr 2021 05:13:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 130A461394; Mon, 5 Apr 2021 09:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617613973; bh=jJEBhcO/vA4oZutc7Isaeq+TqEhLLnKnc+/Jmo7DM34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dhER7hNzKVSDSS8hHD9/lq77rcMG3dA5F9MFaAZIhwzLvqGdffFC/RvEpdn3O4/c8 IYzygXKSYwHGO+fJ5FfE5m1ClcXx9prik6RjWuiRA7bJlC9QAU95vwDIunuHqk0yvq g+bk/JUeN5iXfJymeFvI6QTqjDz/w3ItdiSH86Uc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Jarkko Sakkinen , Sumit Garg , Sasha Levin Subject: [PATCH 5.11 037/152] static_call: Align static_call_is_init() patching condition Date: Mon, 5 Apr 2021 10:53:06 +0200 Message-Id: <20210405085035.476176403@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210405085034.233917714@linuxfoundation.org> References: <20210405085034.233917714@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 49efbdc5b480..f59089a12231 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)) { /* -- 2.30.1