Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp874437pxu; Wed, 7 Oct 2020 19:35:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo8lSbTtcpt689kt29++/tKkWztwLRueCPpUL+wgaqzbzVd5xo+5s7GvZjrr0RCfvlVc7O X-Received: by 2002:a50:e799:: with SMTP id b25mr6626218edn.225.1602124502319; Wed, 07 Oct 2020 19:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602124502; cv=none; d=google.com; s=arc-20160816; b=wRjjAmQictXXE7E02JmXtdEWp3KmjrjHlAAV6zJxCq6mbyyDrD65AebHRPf3QG6djt XZxtLr0UEr8Hm0cKTzlUAMVWRZESU1ReK+8Mgcz1IMgbYnAK1N0uue6YHEBBpZlMNFCU C4/2JuxYu4NSoe9U2zsZ1lXcrwqZi4S6DxuS+szZ2/cI1je6+ARZtLz+uAQ6JPGGBWtc uS7b0m4bhvqh8YwtJU9fMwGk1I5CjGFYVZ7ZH2jUzOWJQARkjvkgUbxPgN6PtFhsJyNo ccABJSKoIQYu5DTLFqtIv0XerNuHuSPupRsJmz6qowObMPfmgeOAP9lYVyGQSp2OSpxX tg6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=eKO8+3RcYquKGrdUdbJ5WjclAeNT1IaQ0rPn9htBY2M=; b=pzsbG+n1r1qZGpUPvoiJ6tefMBFlKELMRcqvmhVI78aMo7rcO5kzkzJ3bdasR5dC9l SsLzRedJvdqNi+tUPJYJUch3SU1bBhGjD5fAOVENH0nt1y6LEMvvVXJU0QBWojwTuDrX PHkxphehVuWn6sfvn32XpRohoApdvULXtU4TdPH6vnPYfuR51q1npn5v0Zm7M95bcdhy fXEAQ65FmSdQnyd27toMjc5ee5Zew8OojSCvec8DBZ2i/drhMpp79lXaImUwDwSI1+OG 7YizNUofRbozutzN9z7JvSf1C91kye6l4W93XAJMm4PLAOy6qfgYJ4z+zhHH8xo9L6BV hLAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="N/CoW0GN"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si3452248edi.602.2020.10.07.19.34.37; Wed, 07 Oct 2020 19:35:02 -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; dkim=pass header.i=@kernel.org header.s=default header.b="N/CoW0GN"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727707AbgJHCak (ORCPT + 99 others); Wed, 7 Oct 2020 22:30:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:34254 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727253AbgJHCak (ORCPT ); Wed, 7 Oct 2020 22:30:40 -0400 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0B9CF2145D for ; Thu, 8 Oct 2020 02:30:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602124239; bh=tHJb3mueFHF3ie2tCZCZmBSRR7A+YvcAIjejINpLILc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=N/CoW0GNNxVUUHpGA0WvFml8+Sp0+8lA8m6NZIAakDLBFkPqIQ3PzcUHYCX6TA4M9 QcmsYeMhOxB0Yse31e0UiN1f06s8RpUd4MngaGawsG1qfxR6wwvjKdbqvMlHi7XCxK JqXVEwkrgasBpyZmROYTLKapb42jhVtSiXBHoXHw= Received: by mail-lj1-f174.google.com with SMTP id d24so1104008ljg.10 for ; Wed, 07 Oct 2020 19:30:38 -0700 (PDT) X-Gm-Message-State: AOAM530K+0OS5uUG0+wNLVLQTLVSIZWQl3u1fcZ9Eidc0Q9rXqgoDsYD J83Buwl84ZdvAJNlkvYtGSebrq7/UYj27gTRkMk= X-Received: by 2002:a2e:6c08:: with SMTP id h8mr2128760ljc.66.1602124237280; Wed, 07 Oct 2020 19:30:37 -0700 (PDT) MIME-Version: 1.0 References: <1602083313-19239-1-git-send-email-guoren@kernel.org> <1602083313-19239-2-git-send-email-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Thu, 8 Oct 2020 10:30:25 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] riscv: Fixup static_obj() fail v2 To: Atish Patra Cc: Palmer Dabbelt , linux-riscv , "linux-kernel@vger.kernel.org List" , Andreas Schwab , aurelien@aurel32.net, Guo Ren Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 8, 2020 at 3:46 AM Atish Patra wrote: > > On Wed, Oct 7, 2020 at 8:09 AM wrote: > > > > From: Guo Ren > > > > v1 is commit: 6184358da0004c8fd940afda6c0a0fa4027dc911 which has > > been reverted. > > > > When enable LOCKDEP, static_obj() will cause error: > > > > [ 0.067192] INFO: trying to register non-static key. > > [ 0.067325] the code is fine but needs lockdep annotation. > > [ 0.067449] turning off the locking correctness validator. > > [ 0.067718] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.7.0-rc7-dirty #44 > > [ 0.067945] Call Trace: > > [ 0.068369] [] walk_stackframe+0x0/0xa4 > > [ 0.068506] [] show_stack+0x2a/0x34 > > [ 0.068631] [] dump_stack+0x94/0xca > > [ 0.068757] [] register_lock_class+0x5b8/0x5bc > > [ 0.068969] [] __lock_acquire+0x6c/0x1d5c > > [ 0.069101] [] lock_acquire+0xae/0x312 > > [ 0.069228] [] _raw_spin_lock_irqsave+0x40/0x5a > > [ 0.069357] [] complete+0x1e/0x50 > > [ 0.069479] [] rest_init+0x1b0/0x28a > > [ 0.069660] [] 0xffffffe0000016a2 > > [ 0.069779] [] 0xffffffe000001b84 > > [ 0.069953] [] 0xffffffe000001092 > > > > Because some __initdata static variables is before _stext: > > > > static int static_obj(const void *obj) > > { > > unsigned long start = (unsigned long) &_stext, > > end = (unsigned long) &_end, > > addr = (unsigned long) obj; > > > > /* > > * static variable? > > */ > > if ((addr >= start) && (addr < end)) > > return 1; > > > > if (arch_is_kernel_data(addr)) > > return 1; > > > > We could implement arch_is_kernel_data to fixup it. > > > > Link: https://lore.kernel.org/linux-riscv/1593266228-61125-1-git-send-email-guoren@kernel.org/T/#t > > Signed-off-by: Guo Ren > > Reported-by: Aurelien Jarno > > Cc: Palmer Dabbelt > > Cc: Atish Patra > > Cc: Andreas Schwab > > Cc: Aurelien Jarno > > --- > > arch/riscv/include/asm/sections.h | 20 ++++++++++++++++++++ > > arch/riscv/kernel/setup.c | 9 +++++++++ > > 2 files changed, 29 insertions(+) > > create mode 100644 arch/riscv/include/asm/sections.h > > > > diff --git a/arch/riscv/include/asm/sections.h b/arch/riscv/include/asm/sections.h > > new file mode 100644 > > index 00000000..2317b9e > > --- /dev/null > > +++ b/arch/riscv/include/asm/sections.h > > You may want to rebase it on top of for-next as UEFI series also adds this file. ok > . > > > @@ -0,0 +1,20 @@ > > +/* SPDX-License-Identifier: GPL-2.0-only */ > > + > > +#ifndef _ASM_RISCV_SECTIONS_H > > +#define _ASM_RISCV_SECTIONS_H > > + > > +#define arch_is_kernel_data arch_is_kernel_data > > + > > +#include > > + > > +extern bool init_mem_is_free; > > + > > +static inline int arch_is_kernel_data(unsigned long addr) > > +{ > > + if (init_mem_is_free) > > + return 0; > > + > > + return addr >= (unsigned long)__init_begin && > > + addr < (unsigned long)__init_end; > > +} > > +#endif /* _ASM_RISCV_SECTIONS_H */ > > diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c > > index 2c6dd32..9ebd5eb4 100644 > > --- a/arch/riscv/kernel/setup.c > > +++ b/arch/riscv/kernel/setup.c > > @@ -17,6 +17,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > #include > > @@ -112,3 +113,11 @@ static int __init topology_init(void) > > return 0; > > } > > subsys_initcall(topology_init); > > + > > +bool init_mem_is_free = false; > > + > > +void free_initmem(void) > > +{ > > + free_initmem_default(POISON_FREE_INITMEM); > > + init_mem_is_free = true; > > +} > > -- > > 2.7.4 > > > > Looks good. Much cleaner than the first approach. > FYI: I am still looking into separating __init text & data so that > different permissions can be applied to them. > With this patch, we can just separate it on top of _stext. > > > Reviewed-by: Atish Patra > > -- > Regards, > Atish -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/