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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A453AC4332F for ; Mon, 27 Sep 2021 13:51:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 23EFA61074 for ; Mon, 27 Sep 2021 13:51:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 23EFA61074 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=csgroup.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 37780900002; Mon, 27 Sep 2021 09:51:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 326236B0072; Mon, 27 Sep 2021 09:51:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F0A7900002; Mon, 27 Sep 2021 09:51:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id 11D506B0071 for ; Mon, 27 Sep 2021 09:51:13 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BA5DA180025D9 for ; Mon, 27 Sep 2021 13:51:12 +0000 (UTC) X-FDA: 78633489984.01.8D281EF Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf08.hostedemail.com (Postfix) with ESMTP id 4700430000AC for ; Mon, 27 Sep 2021 13:51:12 +0000 (UTC) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4HJ3vL1zTlz9sXy; Mon, 27 Sep 2021 15:51:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UxKXWkRZpdci; Mon, 27 Sep 2021 15:51:10 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4HJ3vL0qqRz9sXw; Mon, 27 Sep 2021 15:51:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 074478B76E; Mon, 27 Sep 2021 15:51:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id nsEoLaYG6VnV; Mon, 27 Sep 2021 15:51:09 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [172.25.230.103]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CA6948B763; Mon, 27 Sep 2021 15:51:09 +0200 (CEST) Subject: Re: [PATCH 1/3] mm: Make generic arch_is_kernel_initmem_freed() do what it says To: Michael Ellerman , Andrew Morton , arnd@arndb.de Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, Gerald Schaefer References: <0b55650058a5bf64f7d74781871a1ada2298c8b4.1632491308.git.christophe.leroy@csgroup.eu> <87h7e6kvs3.fsf@mpe.ellerman.id.au> From: Christophe Leroy Message-ID: Date: Mon, 27 Sep 2021 15:51:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <87h7e6kvs3.fsf@mpe.ellerman.id.au> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr-FR X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4700430000AC X-Stat-Signature: rixu387g53r6pahbsq5gfeaxtg98d3p9 Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1632750672-566992 Content-Transfer-Encoding: quoted-printable 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: Le 27/09/2021 =C3=A0 15:11, Michael Ellerman a =C3=A9crit=C2=A0: > Christophe Leroy writes: >> Commit 7a5da02de8d6 ("locking/lockdep: check for freed initmem in >> static_obj()") added arch_is_kernel_initmem_freed() which is supposed >> to report whether an object is part of already freed init memory. >> >> For the time being, the generic version of arch_is_kernel_initmem_free= d() >> always reports 'false', allthough free_initmem() is generically called >> on all architectures. >> >> Therefore, change the generic version of arch_is_kernel_initmem_freed(= ) >> to check whether free_initmem() has been called. If so, then check >> if a given address falls into init memory. >> >> In order to use function init_section_contains(), the fonction is >> moved at the end of asm-generic/section.h >> >> Cc: Gerald Schaefer >> Signed-off-by: Christophe Leroy >> --- >> include/asm-generic/sections.h | 31 +++++++++++++++++-------------- >> 1 file changed, 17 insertions(+), 14 deletions(-) >> >> diff --git a/include/asm-generic/sections.h b/include/asm-generic/sect= ions.h >> index d16302d3eb59..d1e5bb2c6b72 100644 >> --- a/include/asm-generic/sections.h >> +++ b/include/asm-generic/sections.h >> @@ -172,4 +158,21 @@ static inline bool is_kernel_rodata(unsigned long= addr) >> addr < (unsigned long)__end_rodata; >> } >> =20 >> +/* >> + * Check if an address is part of freed initmem. This is needed on ar= chitectures >> + * with virt =3D=3D phys kernel mapping, for code that wants to check= if an address >> + * is part of a static object within [_stext, _end]. After initmem is= freed, >> + * memory can be allocated from it, and such allocations would then h= ave >> + * addresses within the range [_stext, _end]. >> + */ >> +#ifndef arch_is_kernel_initmem_freed >> +static inline int arch_is_kernel_initmem_freed(unsigned long addr) >> +{ >> + if (system_state < SYSTEM_RUNNING) >> + return 0; >> + >> + return init_section_contains((void *)addr, 1); >> +} >> +#endif >=20 > This will return an incorrect result for a short period during boot > won't it? >=20 > See init/main.c: >=20 > static int __ref kernel_init(void *unused) > { > ... > free_initmem(); <- memory is freed here > mark_readonly(); >=20 > /* > * Kernel mappings are now finalized - update the userspace page-table > * to finalize PTI. > */ > pti_finalize(); >=20 > system_state =3D SYSTEM_RUNNING; >=20 >=20 > After free_initmem() we have address ranges that are now freed initmem, > but arch_is_kernel_initmem_freed() continues to return 0 (false) for al= l > addresses, until we update system_state. >=20 > Possibly that doesn't matter for any of the current callers, but it > seems pretty dicey to me. >=20 Yes I saw it but as function core_kernel_text() uses that criteria for=20 deciding whether a given init text address is valid or not, I thought it=20 was just ok. Should we add an intermediate state called for exemple=20 SYSTEM_FREEING_INIT just before SYSTEM_RUNNING ? Christophe