From patchwork Mon Mar 29 17:53:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kardell X-Patchwork-Id: 12171209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62AD4C433C1 for ; Mon, 29 Mar 2021 23:59:17 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F381B6191B for ; Mon, 29 Mar 2021 23:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F381B6191B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=telliq.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=xEDqFxqKRse2F0UnJnc5emeSdW++G9mWj4e4je+E3eE=; b=dWkDx8BDpOrAFWn1vELFWyKIuu aJyPPA+MIH3phW+6WiTxt6gUHzG7GuYqMkpkjXLTAxD1cu5yKxDaRDwI1ZN2YBu8nGQ2MDc/tDau/ Sxj+FEqu9YhQevMs5qUSq8BkOOJgIF0WMHgYDxLJTqymURPK7Jz4qIznhGFg6vhMYcEchsDGrAbB3 di45ig46wCbc0etngP6XBRHsrhUSJe8w20wVT25mt68J6QOxRfJ0/Sua/5SKX+0jWFI6cdV2z9ogQ t8aw86MZaeMSYsRvsecf+jeeIdDDNNEDEpD1Xt4LCcOHQTbGWIzsLurul5pusfQq8REodxn2iEdS/ UIL1YqHw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lR1lQ-0024xI-Vp; Mon, 29 Mar 2021 23:57:45 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lQw4n-000wrM-Md for linux-arm-kernel@lists.infradead.org; Mon, 29 Mar 2021 17:53:29 +0000 Received: by mail-wm1-x332.google.com with SMTP id d191so7041366wmd.2 for ; Mon, 29 Mar 2021 10:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telliq.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=N6EnRd/MY7h8IstQCaZRWpBwbfFtnJv4s7DJ21C8TVU=; b=CAYs0tgpe8vK037DR+QKaY/dFao1NgmTdZvmoJDVBWeLeSuPcF3sVB1RqBALma6L8e 60P2lVgiHv00myzkjExiWiTZHHsP7a/koD0WhGQ+zNK1slD/vjgM6DrhEZVhmH2+Tnmu Z/mI+39OQ3DTCUwCqMrlnG5aMbvmKzhNwdyUvJ44OPCCWxE0MdElOpdyvE7VNhXccv/5 HebYIbIELrPYac0N9mRrcLivnzbn51nOkbB2tL/qlB5Q0pwMejygyEGxzUBbSykJ3YuR LLyWHvkBLRHBMbVOTCYKZhA1cUYOPBjFs2k3h6OlZiJnMiAZoytiL8wzI5xn/HtZmzbW zm+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=N6EnRd/MY7h8IstQCaZRWpBwbfFtnJv4s7DJ21C8TVU=; b=s+h1dL/k+QP65mEyk/EUpiRZ+ta7I3iek46YuDb/gwhELgKpP6XKM2F8GdyR/B0Uxb f3kuxnkPmMnoilNp5eToDLUqsrE3Ct4cjFqbHK2wHlGcEA0H36JMK+TRUvLOulrUpfJQ JyjHik+S87xFzmQMWQrmyUgBOoKfGbSaLFyouUquSlAQIknMorrXsWI4Imube6LtIz/L 2oi2pTDZs4xAtOVvuMAmeGm272OCQD4ekbKbJrks7xj9cpqFzTNdOyIaj5iDWQGU8XAN Jv1tJ6edmPle2ZQwchnMNdP95EuHPiFc7CPlKG1mQL/CzPEPWEZRK5gWDDTYmBnQAj72 Q3Lg== X-Gm-Message-State: AOAM531bWYDq+hpLtKMPdShzt+KsaXxQXqe8z9cdPUt93ESDSszDPm7W X58B22gNax0I81u30JkH3SVgH+oWbI7ofJke X-Google-Smtp-Source: ABdhPJzNvL5rgMlYeb3DLyMYlNh0fTGWd7RQJVVnvzJUaoumN5K/evaFhoN2SSC65l7mRBlLfxAODg== X-Received: by 2002:a7b:c841:: with SMTP id c1mr232796wml.123.1617040399629; Mon, 29 Mar 2021 10:53:19 -0700 (PDT) Received: from emu.mida (static-212-247-121-18.cust.tele2.se. [212.247.121.18]) by smtp.gmail.com with ESMTPSA id q4sm154209wma.20.2021.03.29.10.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 10:53:19 -0700 (PDT) From: Jan Kardell To: Linux ARM Cc: linux-kernel@vger.kernel.org, Russell King , linux-omap@vger.kernel.org, Andrew Morton , linux-mm@kvack.org Subject: [PATCH] arm: Define arch_is_kernel_initmem_freed() for lockdep Date: Mon, 29 Mar 2021 19:53:18 +0200 Message-Id: <20210329175318.21393-1-jan.kardell@telliq.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210329_185325_484698_15C6A515 X-CRM114-Status: GOOD ( 15.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This fixes the warning: WARNING: CPU: 0 PID: 1994 at kernel/locking/lockdep.c:1119 alloc_netdev_mqs+0xb4/0x3b0 This warning is because the check in static_obj() assumes that all memory within [_stext, _end] belongs to static objects. The init section is also part of this range, and freeing it allows the buddy allocator to allocate memory from it. To fix this, define arch_is_kernel_initmem_freed() for arm, it will return 1 if initmem has been freed and the address is in the range [__init_begin, __init_end], and this function is called by the static_obj() function in lockdep. Tested on TI am3352 (Cortex A8). This change is modelled after commit 7a5da02de8d6eafba995 ("locking/lockdep: check for freed initmem in static_obj()") for s390 by Gerald Schaefer Signed-off-by: Jan Kardell --- arch/arm/include/asm/sections.h | 13 +++++++++++++ arch/arm/mm/init.c | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/sections.h b/arch/arm/include/asm/sections.h index 700b8bcdf9bd..1dd64c90c1ac 100644 --- a/arch/arm/include/asm/sections.h +++ b/arch/arm/include/asm/sections.h @@ -2,6 +2,8 @@ #ifndef _ASM_ARM_SECTIONS_H #define _ASM_ARM_SECTIONS_H +#define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed + #include extern char _exiprom[]; @@ -11,6 +13,17 @@ extern char __idmap_text_end[]; extern char __entry_text_start[]; extern char __entry_text_end[]; +extern bool initmem_freed; + +static inline int arch_is_kernel_initmem_freed(unsigned long addr) +{ + if (!initmem_freed) + return 0; + return addr >= (unsigned long)__init_begin && + addr < (unsigned long)__init_end; +} + + static inline bool in_entry_text(unsigned long addr) { return memory_contains(__entry_text_start, __entry_text_end, diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 828a2561b229..cd7a4273797a 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -41,6 +41,8 @@ #include "mm.h" +bool initmem_freed; + #ifdef CONFIG_CPU_CP15_MMU unsigned long __init __clear_cr(unsigned long mask) { @@ -523,8 +525,10 @@ void free_initmem(void) fix_kernmem_perms(); poison_init_mem(__init_begin, __init_end - __init_begin); - if (!machine_is_integrator() && !machine_is_cintegrator()) + if (!machine_is_integrator() && !machine_is_cintegrator()) { + initmem_freed = true; free_initmem_default(-1); + } } #ifdef CONFIG_BLK_DEV_INITRD