From patchwork Sat Aug 12 15:48:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 134905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1794257vqi; Sat, 12 Aug 2023 09:26:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+r3lbJZwIERflcrCrG4ihSY8nP3Tm0JizdSBi1w7xRiQ7qJ6QFLE16FCEEG/pGnbaiJ1P X-Received: by 2002:a17:902:7884:b0:1bc:5d0:e8db with SMTP id q4-20020a170902788400b001bc05d0e8dbmr5850457pll.62.1691857605872; Sat, 12 Aug 2023 09:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691857605; cv=none; d=google.com; s=arc-20160816; b=wKw7cGedV9StCAMm+ZCgmvcK4ZooQxiHSOJ/duCawccQGQufjtzihjHsHHzv/jYDok cS6eJMQHURnXO6jpD2lr31Gu89b8Kd3Q9Du5OmLKpyz9d3SEPXBVDWhk3JckiZCTaeiq ixMaaklm5lf5KMXh0jE/O1utbJ8KkVezVGAaGTvLyywqF//cLo2eQcrwD4spyqB/QN8s Z6GMDC22HTnKCH6MFp464vsKQRgxI4kRSPOVuajFaNY5zY4+bc+/vYEI/ly4DmD/hn3a JD8jCHxYlOQ90s1BRNi/XqzWjelxnIMnJDprYSpnDNhkTTyRh3w2er5SJMBUODyYsdJc DkAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:ui-outboundreport :content-disposition:mime-version:message-id:subject:to:from:date :dkim-signature; bh=FyuFJlKNymoV5ox1cKdkhfNhZg4wO+YqE2NMcLmOQ8g=; fh=YCIUZZeGZb5pQ+ktzijle4ggRfhZ6/6cwZScGi3fMjA=; b=IlViBMZIwNvH5aXLxiG0DRVXTUxdPKFgyyTWboOgIix/9rOhRharUyZJnQmRuZxU3E TAwyCx0JWkaZEKTdhL+pOeGTjItgwfqp07kE+1AFSQRaAeTt5bCKtNNFWgeswhIv8+7T 4H+/vYLnqkXvtUegC8kEXouDLdHV/toZ8XiJ5LrgnZSIFjRC3HcIG3Anjh1G0/2IYLSB hmpGTY8yj0KnnfP35jzH6WucXpQNr8GcIyAg8JxOIb5JPJfsvN7tyBsARuhmLSO7dgcR 84jWoIGxm0Rjm4mn1Boym1ThRw43fnz51OZC9Etd+SaLQxy/OvTiEMlgJDu2lhr7QU9U dHrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=qPwxhJR7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c16-20020a170903235000b001b9eb349549si5164781plh.630.2023.08.12.09.26.32; Sat, 12 Aug 2023 09:26:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=qPwxhJR7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbjHLPt0 (ORCPT + 99 others); Sat, 12 Aug 2023 11:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229494AbjHLPtZ (ORCPT ); Sat, 12 Aug 2023 11:49:25 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34F511FC1; Sat, 12 Aug 2023 08:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1691855334; x=1692460134; i=deller@gmx.de; bh=AQBcB+CUsX2eTH/+u9mZCUJr+ijUOKXmaOz8H8saal4=; h=X-UI-Sender-Class:Date:From:To:Subject; b=qPwxhJR79FJL9yRRwISVfZJr9JX1oQFTtt1sOk7MYGg8JyJ0NJpteHMqDRHUa6VKhP7YWGO b62K2CYwt8ZZ7/zssWPu9tFrKj8pRJE801Jt0dmo6hrJPChzgFrk+xlzuYdgGtm60wCwLEUzw ITSkChaJxFIkFjeuHKFmuVaVvJWXp10BPder1HeNCPXOrc4exxq0EF6ygb0fPwVLE4sfMy4fy /xp6oOenmYg7z9hEmlpSZ/baoI6iFmWpnijNqbPk6txQruBcbKc0Ry74hXYXvG4ioWm1SQ5gE zK7UDRdXHtu0ycax5odDpdoX5iot6N0BHC2NQCLD2XNYqKuF5Sjg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100 ([94.134.153.44]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mkpf3-1q4YJd3GMp-00mJHY; Sat, 12 Aug 2023 17:48:54 +0200 Date: Sat, 12 Aug 2023 17:48:52 +0200 From: Helge Deller To: Andrew Morton , Greg Kroah-Hartman , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, Guenter Roeck , Borislav Petkov , Peter Zijlstra Subject: [PATCH] lockdep: Fix static memory detection even more Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Provags-ID: V03:K1:dcEbt/hL0xn2+/fOPVPAwmkoSqwPYd0eThhUGchBAgmMMFlJtPq GJlkPvu/V+fAy2HMh6rrZWAvitZoPyaIjpL79Kt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LGqfc5SgN/KzUbHQUC52RX6n/jOWKpx/2xpaoivS8gV8la5Ma1cvZpel2gE+nWSgT PruKjg== X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774041280770237034 X-GMAIL-MSGID: 1774041280770237034 On the parisc architecture, lockdep reports for all static objects which are in the __initdata section (e.g. "setup_done" in devtmpfs, "kthreadd_done" in init/main.c) this warning: INFO: trying to register non-static key. The warning itself is wrong, because those objects are in the __initdata section, but the section itself is on parisc outside of range from _stext to _end, which is why the static_obj() functions returns a wrong answer. While fixing this issue, I noticed that the whole existing check can be simplified a lot. Instead of checking against the _stext and _end symbols (which include code areas too) just check for the .data and .bss segments (since we check a data object). This can be done with the existing is_kernel_core_data() macro. In addition objects in the __initdata section can be checked with init_section_contains(). This partly reverts and simplifies commit bac59d18c701 ("x86/setup: Fix static memory detection"). Tested on x86-64 and parisc. Signed-off-by: Helge Deller Fixes: bac59d18c701 ("x86/setup: Fix static memory detection") diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h index a6e8373a5170..3fa87e5e11ab 100644 --- a/arch/x86/include/asm/sections.h +++ b/arch/x86/include/asm/sections.h @@ -2,8 +2,6 @@ #ifndef _ASM_X86_SECTIONS_H #define _ASM_X86_SECTIONS_H -#define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed - #include #include @@ -18,20 +16,4 @@ extern char __end_of_kernel_reserve[]; extern unsigned long _brk_start, _brk_end; -static inline bool arch_is_kernel_initmem_freed(unsigned long addr) -{ - /* - * If _brk_start has not been cleared, brk allocation is incomplete, - * and we can not make assumptions about its use. - */ - if (_brk_start) - return 0; - - /* - * After brk allocation is complete, space between _brk_end and _end - * is available for allocation. - */ - return addr >= _brk_end && addr < (unsigned long)&_end; -} - #endif /* _ASM_X86_SECTIONS_H */ diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 111607d91489..957b785d0b59 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -819,34 +819,20 @@ 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, - end = (unsigned long) &_end, - addr = (unsigned long) obj; + unsigned long addr = (unsigned long) obj; - if (arch_is_kernel_initmem_freed(addr)) - return 0; + if (is_kernel_core_data(addr)) + return 1; /* - * static variable? + * in initdata section and used during bootup only? + * NOTE: On some platforms the initdata section is + * outside of the _stext ... _end range. */ - if ((addr >= start) && (addr < end)) + if (system_state < SYSTEM_FREEING_INITMEM && + init_section_contains((void *)addr, 1)) return 1; /*