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 82332C433EF for ; Mon, 27 Sep 2021 13:12:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 75D8B6103B for ; Mon, 27 Sep 2021 13:12:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 75D8B6103B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id DBC866B0071; Mon, 27 Sep 2021 09:12:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6B1B900003; Mon, 27 Sep 2021 09:12:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5A45900002; Mon, 27 Sep 2021 09:12:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id AEB366B0071 for ; Mon, 27 Sep 2021 09:12:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 49A54181CC1B9 for ; Mon, 27 Sep 2021 13:12:06 +0000 (UTC) X-FDA: 78633391452.06.3267956 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by imf08.hostedemail.com (Postfix) with ESMTP id 7E36330000A8 for ; Mon, 27 Sep 2021 13:12:05 +0000 (UTC) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4HJ3286WM8z4xZJ; Mon, 27 Sep 2021 23:12:00 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1632748321; bh=/6NGyTxf3yZzS/6VpTsWCSMws0EAQCWdVr1eBk3RItQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=bCCOJ57PVuxKBr/+8rzursr0M58poo2U8UYU8FmOa4Ve+xeh2oVXaK/weC5cayqC8 0wfzCG3XkzUK6Cq3uln4S1u7XiI8Y5zls2oXnDdU8s8sTYlXG0ip+mYiZXMrDsr0Ms rgvGcz2IfqStO+q38lKNaAq/EqUyLMic0uWxcIB0J9CzMKYaZF+8ecEHf3d0bQmkvS aHG/dFXj/TlPCuEGMseSTg3CjjKQ3HmJ7K6YllqzxrwuI16j2tZXrTHkJAF1Jps4OY umzjNyJWrNKJ+gqjI+Y3AiPuqS0/WkO+2lgBODADFgP+K/n+6PQi6QF0+aN0U1U7KW vJ+X8XhJSUtPA== From: Michael Ellerman To: Christophe Leroy , Andrew Morton , arnd@arndb.de Cc: Christophe Leroy , 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 Subject: Re: [PATCH 1/3] mm: Make generic arch_is_kernel_initmem_freed() do what it says In-Reply-To: <0b55650058a5bf64f7d74781871a1ada2298c8b4.1632491308.git.christophe.leroy@csgroup.eu> References: <0b55650058a5bf64f7d74781871a1ada2298c8b4.1632491308.git.christophe.leroy@csgroup.eu> Date: Mon, 27 Sep 2021 23:11:56 +1000 Message-ID: <87h7e6kvs3.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7E36330000A8 X-Stat-Signature: fpwujnr3doapzi33778miiteyhcntnks Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=bCCOJ57P; dmarc=none; spf=pass (imf08.hostedemail.com: domain of mpe@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=mpe@ellerman.id.au X-HE-Tag: 1632748325-763826 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: 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_freed() > 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/sections.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; > } > > +/* > + * Check if an address is part of freed initmem. This is needed on architectures > + * with virt == 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 have > + * 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 This will return an incorrect result for a short period during boot won't it? See init/main.c: static int __ref kernel_init(void *unused) { ... free_initmem(); <- memory is freed here mark_readonly(); /* * Kernel mappings are now finalized - update the userspace page-table * to finalize PTI. */ pti_finalize(); system_state = SYSTEM_RUNNING; After free_initmem() we have address ranges that are now freed initmem, but arch_is_kernel_initmem_freed() continues to return 0 (false) for all addresses, until we update system_state. Possibly that doesn't matter for any of the current callers, but it seems pretty dicey to me. cheers