From patchwork Fri Nov 5 20:40:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12605593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84199C433FE for ; Fri, 5 Nov 2021 20:40:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 29EE56126A for ; Fri, 5 Nov 2021 20:40:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 29EE56126A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BFBEF94006F; Fri, 5 Nov 2021 16:40:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAF06940049; Fri, 5 Nov 2021 16:40:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9C4594006F; Fri, 5 Nov 2021 16:40:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id 9AE36940049 for ; Fri, 5 Nov 2021 16:40:42 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 60D461856B121 for ; Fri, 5 Nov 2021 20:40:42 +0000 (UTC) X-FDA: 78776045124.26.AC2B96C Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf27.hostedemail.com (Postfix) with ESMTP id 0690F70000B0 for ; Fri, 5 Nov 2021 20:40:41 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id DF383611C0; Fri, 5 Nov 2021 20:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1636144841; bh=f0pmK+QffkqWkpYdf0i/C/k78iRf3FkcX2CSByEiaMk=; h=Date:From:To:Subject:In-Reply-To:From; b=N52eVlPPc1wg3mSPA4w8V8K4QX1JuNyvlWmyK2ySGjw5Qd8XjAf15uqeiRC+ENimm sVDkyK9/F7iAf5SmpUK1Xro5uxqqftn5SsZeasUpDow0Mj8h6EmED/JRc/nxAUGvJG Svr3En7Q9E19ySz8mq67xKNPngk/18+PWTEpuQmc= Date: Fri, 05 Nov 2021 13:40:40 -0700 From: Andrew Morton To: akpm@linux-foundation.org, benh@kernel.crashing.org, christophe.leroy@csgroup.eu, gerald.schaefer@linux.ibm.com, hca@linux.ibm.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, paulus@ozlabs.org, torvalds@linux-foundation.org, wangkefeng.wang@huawei.com Subject: [patch 115/262] mm: create a new system state and fix core_kernel_text() Message-ID: <20211105204040.TmGWbPVoa%akpm@linux-foundation.org> In-Reply-To: <20211105133408.cccbb98b71a77d5e8430aba1@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=N52eVlPP; dmarc=none; spf=pass (imf27.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0690F70000B0 X-Stat-Signature: 1nxj14md5ypwn5fi3r3fiqaruczg9kbr X-HE-Tag: 1636144841-917601 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Christophe Leroy Subject: mm: create a new system state and fix core_kernel_text() core_kernel_text() considers that until system_state in at least SYSTEM_RUNNING, init memory is valid. But init memory is freed a few lines before setting SYSTEM_RUNNING, so we have a small period of time when core_kernel_text() is wrong. Create an intermediate system state called SYSTEM_FREEING_INIT that is set before starting freeing init memory, and use it in core_kernel_text() to report init memory invalid earlier. Link: https://lkml.kernel.org/r/9ecfdee7dd4d741d172cb93ff1d87f1c58127c9a.1633001016.git.christophe.leroy@csgroup.eu Signed-off-by: Christophe Leroy Cc: Gerald Schaefer Cc: Kefeng Wang Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Heiko Carstens Signed-off-by: Andrew Morton --- include/linux/kernel.h | 1 + init/main.c | 2 ++ kernel/extable.c | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) --- a/include/linux/kernel.h~mm-create-a-new-system-state-and-fix-core_kernel_text +++ a/include/linux/kernel.h @@ -248,6 +248,7 @@ extern bool early_boot_irqs_disabled; extern enum system_states { SYSTEM_BOOTING, SYSTEM_SCHEDULING, + SYSTEM_FREEING_INITMEM, SYSTEM_RUNNING, SYSTEM_HALT, SYSTEM_POWER_OFF, --- a/init/main.c~mm-create-a-new-system-state-and-fix-core_kernel_text +++ a/init/main.c @@ -1506,6 +1506,8 @@ static int __ref kernel_init(void *unuse kernel_init_freeable(); /* need to finish all async __init code before freeing the memory */ async_synchronize_full(); + + system_state = SYSTEM_FREEING_INITMEM; kprobe_free_init_mem(); ftrace_free_init_mem(); kgdb_free_init_mem(); --- a/kernel/extable.c~mm-create-a-new-system-state-and-fix-core_kernel_text +++ a/kernel/extable.c @@ -76,7 +76,7 @@ int notrace core_kernel_text(unsigned lo addr < (unsigned long)_etext) return 1; - if (system_state < SYSTEM_RUNNING && + if (system_state < SYSTEM_FREEING_INITMEM && init_kernel_text(addr)) return 1; return 0;