Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp204276pxb; Thu, 30 Sep 2021 04:28:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmfD8CgGH4yO/kN8M53wg5V2TlG+ym+/8Va693MeVrb9iOelq8VcRqLtTfHgBPRIUDbg06 X-Received: by 2002:aa7:8434:0:b0:43c:222b:1d3d with SMTP id q20-20020aa78434000000b0043c222b1d3dmr3929959pfn.84.1633001333791; Thu, 30 Sep 2021 04:28:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633001333; cv=none; d=google.com; s=arc-20160816; b=w7rcjqHHSBE03WUUb9KRQK/LNrI+johJCase9mZrYMufom/6Uo4RMBW89MjRr+JQDb 1pnHqZ6FJZdpu7pR6DJYCCmDk8+DsbRfvdjpnmbailbn7YWHUh5jHnnAhQiWLTJ/bMla 1Ud8+JXMxfN4UhBYdReXZuG2tjZxgnztXSkLoutiGz+BARfZWo50g/gggEVW98kq28mH cJc2dV/7L1ZQ9/8bc59GFzfXCfsHVb+EmqtO5R/jjdcVsjeqeh4cff8gk6ZKNdqL9JGM 6UJrG9WjiV3oeglbHV5HYCmluIDe+iMJcvQN9KzZTFaTISzN9Y4jHQb6Fs2svLQOSn1r 2wdw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5bGDFgmt+1hFHtK2vzHdSmYuAEs19WkqDE5hrcZM36c=; b=dNDjj1J6N8XkNzxOpkpTh3fpBCAR/I3alhfy0nEk2AVTehtibQFASfIY5I9CIbRwE3 pgAaQ6Wj01jDz0C9fObt0niWYBngQIHY8eglDy7ODCjzajYx0o0u1y38PyF7h4vkJC+1 IC4t7T7Ad+1cLw76EGwok7btYd5jpxj3qJoCtybC0EMtJnoRpBm47Sle00LNPJAkQvVu JC6h/tZi5VJSZsvDJaPseGT8+72SqibBC6Bu+LBJCkdP71XIxejcqXLg1V7LEHkuO4Z+ 1vU1F0ypp+BHKWCrHMlxUAjZUTc4FZQkYJyDV0AsNZaWkCfvj4+tmtQVKiH8xX2IsDNm TBQQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v9si3411787plp.24.2021.09.30.04.28.40; Thu, 30 Sep 2021 04:28:53 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350494AbhI3L1i (ORCPT + 99 others); Thu, 30 Sep 2021 07:27:38 -0400 Received: from pegase2.c-s.fr ([93.17.235.10]:40245 "EHLO pegase2.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350458AbhI3L1g (ORCPT ); Thu, 30 Sep 2021 07:27:36 -0400 Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4HKrX70rlzz9sX9; Thu, 30 Sep 2021 13:25:43 +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 TpLfoGdbZD5Q; Thu, 30 Sep 2021 13:25:43 +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 4HKrX61Ytcz9sX5; Thu, 30 Sep 2021 13:25:42 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1F8EA8B773; Thu, 30 Sep 2021 13:25:42 +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 KWkHm5QCjSZ6; Thu, 30 Sep 2021 13:25:42 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.149]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C3DA58B763; Thu, 30 Sep 2021 13:25:41 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.16.1/8.16.1) with ESMTPS id 18UBO9ws1558822 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 30 Sep 2021 13:24:09 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.16.1/8.16.1/Submit) id 18UBO9i81558821; Thu, 30 Sep 2021 13:24:09 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: 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 , Kefeng Wang Subject: [PATCH v3 2/4] mm: Make generic arch_is_kernel_initmem_freed() do what it says Date: Thu, 30 Sep 2021 13:23:44 +0200 Message-Id: <1d40783e676e07858be97d881f449ee7ea8adfb1.1633001016.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <9ecfdee7dd4d741d172cb93ff1d87f1c58127c9a.1633001016.git.christophe.leroy@csgroup.eu> References: <9ecfdee7dd4d741d172cb93ff1d87f1c58127c9a.1633001016.git.christophe.leroy@csgroup.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. To ease the use of system_state, move it out of line into its only caller which is lockdep.c Cc: Gerald Schaefer Cc: Kefeng Wang Signed-off-by: Christophe Leroy --- v3: Move it out of sections.h into lockdep.c and fix the comment. v2: Change to using the new SYSTEM_FREEING_INITMEM state Signed-off-by: Christophe Leroy --- include/asm-generic/sections.h | 14 -------------- kernel/locking/lockdep.c | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index d16302d3eb59..596ab2092289 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -80,20 +80,6 @@ static inline int arch_is_kernel_data(unsigned long addr) } #endif -/* - * 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) -{ - return 0; -} -#endif - /** * memory_contains - checks if an object is contained within a memory region * @begin: virtual address of the beginning of the memory region diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index bf1c00c881e4..8e118caf835e 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -788,6 +788,21 @@ static int very_verbose(struct lock_class *class) * Is this the address of a static object: */ #ifdef __KERNEL__ +/* + * Check if an address is part of freed initmem. 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 int arch_is_kernel_initmem_freed(unsigned long addr) +{ + if (system_state < SYSTEM_FREEING_INITMEM) + return 0; + + return init_section_contains((void *)addr, 1); +} +#endif + static int static_obj(const void *obj) { unsigned long start = (unsigned long) &_stext, -- 2.31.1