Message ID | ZQC5jS/Kc/JiBEOa@p100 |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp632329vqx; Tue, 12 Sep 2023 12:26:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOHrOCNzB+DmN4J+3vHR0NNqs3eloex8jpp8kjP0/XHWsd7XfZ280H46EB1aDHC4IPJUU6 X-Received: by 2002:a05:6a00:1407:b0:67a:9208:87a with SMTP id l7-20020a056a00140700b0067a9208087amr646761pfu.23.1694546805848; Tue, 12 Sep 2023 12:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694546805; cv=none; d=google.com; s=arc-20160816; b=BEZkhWKlkdkEg/XotLui2dBac1MoO1QO4Hc9SvremXbO4HXPLR+tAViSEYwroycq/o Se66gdzxsIbBV/JwtvYuET7V29f9DczZ/zXK5xSD4MAsX+rK9WlL4e+k+0y+vFd4iRW4 zWT7yl/LiMDctsl6EGPitrvFofgbHcuZ1nIvhH1nU/Hi0f6gXaEqPkoKZwIeRvt5C/Yo 5oM9cBk58RQM4snNax60f7SQG5qoBduvN91WigbsmwROoivIYv21HaoGuUScwtb7CUGC zcFSGzt8WVTF3L6X43opn5J+uU0d/rNb+c6sqdGl52tLLhmUN4/B1bh7l7J6JPYqyIHC aTkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=rIQvBZu9KcNTUibAJpvMDUrHoEWYVjguzWOhZfbdZoo=; fh=7RgR9kjqmu2liFG1SSAK7W74bENpkdzpuN7j/jwMF9U=; b=iJ7C8OD/FVbYQrUxfwfvgfxiCeKzCwLe/7k/PSihBLJk6mnHOhU6cNrrQNACLldZl4 8AyPaCQE3sbksxPVzkoLzgVO9t0EDlBeppStas6UmsrpU+jUzCk2262bws3OAlk7ans4 +xDbzJhDJ1bbpE9Lp3DdNcnLq7Sm3MRg/YsdC8Nxko+souoNint41BbR7uR7km234PaY B1dGMl8wLfF77qLjgcTs9Ms7E7KpFjZx+xdvmG2+ORPnCbQ0d9h6v/c9gRsLDNlnihnz o1OYnnHHYYbhLgof4i2Sk/Yg6dHx1AgUBmBoa5vxU4o/9StrzJaHDgVZMkfuuNPubKUL w+FA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id k79-20020a628452000000b0068fce0c7193si3163329pfd.282.2023.09.12.12.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 12:26:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D026C80AFE8E; Tue, 12 Sep 2023 12:19:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231381AbjILTSs (ORCPT <rfc822;pwkd43@gmail.com> + 36 others); Tue, 12 Sep 2023 15:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbjILTSr (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 12 Sep 2023 15:18:47 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45841C1 for <linux-kernel@vger.kernel.org>; Tue, 12 Sep 2023 12:18:43 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F4046C433C7; Tue, 12 Sep 2023 19:18:40 +0000 (UTC) Date: Tue, 12 Sep 2023 21:18:37 +0200 From: Helge Deller <deller@gmx.de> To: Huacai Chen <chenhuacai@kernel.org>, WANG Xuerui <kernel@xen0n.name>, loongarch@lists.linux.dev, Guenter Roeck <linux@roeck-us.net>, Linus Torvalds <torvalds@linux-foundation.org>, Geert Uytterhoeven <geert@linux-m68k.org>, linux-kernel@vger.kernel.org Subject: [PATCH] LoongArch: Fix lockdep static memory detection Message-ID: <ZQC5jS/Kc/JiBEOa@p100> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 12:19:02 -0700 (PDT) X-Spam-Status: No, score=-0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776861111692522219 X-GMAIL-MSGID: 1776861111692522219 |
Series |
LoongArch: Fix lockdep static memory detection
|
|
Commit Message
Helge Deller
Sept. 12, 2023, 7:18 p.m. UTC
Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection even
more") the lockdep code uses is_kernel_core_data(), is_kernel_rodata()
and init_section_contains() to verify if a lock is located inside a
kernel static data section.
This change triggers a failure on LoongArch, for which the vmlinux.lds.S
script misses to put the locks (as part of in the .data.rel symbols)
into the Linux data section.
This patch fixes the lockdep problem by moving *(.data.rel*) symbols
into the kernel data section (from _sdata to _edata).
Additionally, move other wrongly assigned symbols too:
- altinstructions into the _initdata section,
- PLT symbols behind the read-only section, and
- *(.la_abs) into the data section.
Signed-off-by: Helge Deller <deller@gmx.de>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Fixes: 0a6b58c5cd0d ("lockdep: fix static memory detection even more")
Cc: stable <stable@kernel.org> # v6.4+
Comments
On Tue, Sep 12, 2023 at 09:18:37PM +0200, Helge Deller wrote: > Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection even > more") the lockdep code uses is_kernel_core_data(), is_kernel_rodata() > and init_section_contains() to verify if a lock is located inside a > kernel static data section. > > This change triggers a failure on LoongArch, for which the vmlinux.lds.S > script misses to put the locks (as part of in the .data.rel symbols) > into the Linux data section. > This patch fixes the lockdep problem by moving *(.data.rel*) symbols > into the kernel data section (from _sdata to _edata). > > Additionally, move other wrongly assigned symbols too: > - altinstructions into the _initdata section, > - PLT symbols behind the read-only section, and > - *(.la_abs) into the data section. > > Signed-off-by: Helge Deller <deller@gmx.de> > Reported-by: Guenter Roeck <linux@roeck-us.net> > Fixes: 0a6b58c5cd0d ("lockdep: fix static memory detection even more") > Cc: stable <stable@kernel.org> # v6.4+ Tested-by: Guenter Roeck <linux@roeck-us.net> > > diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S > index b1686afcf876..bb2ec86f37a8 100644 > --- a/arch/loongarch/kernel/vmlinux.lds.S > +++ b/arch/loongarch/kernel/vmlinux.lds.S > @@ -53,33 +53,6 @@ SECTIONS > . = ALIGN(PECOFF_SEGMENT_ALIGN); > _etext = .; > > - /* > - * struct alt_inst entries. From the header (alternative.h): > - * "Alternative instructions for different CPU types or capabilities" > - * Think locking instructions on spinlocks. > - */ > - . = ALIGN(4); > - .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { > - __alt_instructions = .; > - *(.altinstructions) > - __alt_instructions_end = .; > - } > - > -#ifdef CONFIG_RELOCATABLE > - . = ALIGN(8); > - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { > - __la_abs_begin = .; > - *(.la_abs) > - __la_abs_end = .; > - } > -#endif > - > - .got : ALIGN(16) { *(.got) } > - .plt : ALIGN(16) { *(.plt) } > - .got.plt : ALIGN(16) { *(.got.plt) } > - > - .data.rel : { *(.data.rel*) } > - > . = ALIGN(PECOFF_SEGMENT_ALIGN); > __init_begin = .; > __inittext_begin = .; > @@ -94,6 +67,18 @@ SECTIONS > > __initdata_begin = .; > > + /* > + * struct alt_inst entries. From the header (alternative.h): > + * "Alternative instructions for different CPU types or capabilities" > + * Think locking instructions on spinlocks. > + */ > + . = ALIGN(4); > + .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { > + __alt_instructions = .; > + *(.altinstructions) > + __alt_instructions_end = .; > + } > + > INIT_DATA_SECTION(16) > .exit.data : { > EXIT_DATA > @@ -113,6 +98,11 @@ SECTIONS > > _sdata = .; > RO_DATA(4096) > + > + .got : ALIGN(16) { *(.got) } > + .plt : ALIGN(16) { *(.plt) } > + .got.plt : ALIGN(16) { *(.got.plt) } > + > RW_DATA(1 << CONFIG_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE) > > .rela.dyn : ALIGN(8) { > @@ -121,6 +111,17 @@ SECTIONS > __rela_dyn_end = .; > } > > + .data.rel : { *(.data.rel*) } > + > +#ifdef CONFIG_RELOCATABLE > + . = ALIGN(8); > + .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { > + __la_abs_begin = .; > + *(.la_abs) > + __la_abs_end = .; > + } > +#endif > + > .sdata : { > *(.sdata) > }
PING to Loongarch maintainers! Without this patch, lockdep is broken on LoongArch on kernel v6.1 and above. (patch below wrongly mentions kernel 6.4, but actually it needs backport to v6.1 too). Helge On 9/12/23 22:31, Guenter Roeck wrote: > On Tue, Sep 12, 2023 at 09:18:37PM +0200, Helge Deller wrote: >> Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection even >> more") the lockdep code uses is_kernel_core_data(), is_kernel_rodata() >> and init_section_contains() to verify if a lock is located inside a >> kernel static data section. >> >> This change triggers a failure on LoongArch, for which the vmlinux.lds.S >> script misses to put the locks (as part of in the .data.rel symbols) >> into the Linux data section. >> This patch fixes the lockdep problem by moving *(.data.rel*) symbols >> into the kernel data section (from _sdata to _edata). >> >> Additionally, move other wrongly assigned symbols too: >> - altinstructions into the _initdata section, >> - PLT symbols behind the read-only section, and >> - *(.la_abs) into the data section. >> >> Signed-off-by: Helge Deller <deller@gmx.de> >> Reported-by: Guenter Roeck <linux@roeck-us.net> >> Fixes: 0a6b58c5cd0d ("lockdep: fix static memory detection even more") >> Cc: stable <stable@kernel.org> # v6.4+ > > Tested-by: Guenter Roeck <linux@roeck-us.net> > >> >> diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S >> index b1686afcf876..bb2ec86f37a8 100644 >> --- a/arch/loongarch/kernel/vmlinux.lds.S >> +++ b/arch/loongarch/kernel/vmlinux.lds.S >> @@ -53,33 +53,6 @@ SECTIONS >> . = ALIGN(PECOFF_SEGMENT_ALIGN); >> _etext = .; >> >> - /* >> - * struct alt_inst entries. From the header (alternative.h): >> - * "Alternative instructions for different CPU types or capabilities" >> - * Think locking instructions on spinlocks. >> - */ >> - . = ALIGN(4); >> - .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { >> - __alt_instructions = .; >> - *(.altinstructions) >> - __alt_instructions_end = .; >> - } >> - >> -#ifdef CONFIG_RELOCATABLE >> - . = ALIGN(8); >> - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { >> - __la_abs_begin = .; >> - *(.la_abs) >> - __la_abs_end = .; >> - } >> -#endif >> - >> - .got : ALIGN(16) { *(.got) } >> - .plt : ALIGN(16) { *(.plt) } >> - .got.plt : ALIGN(16) { *(.got.plt) } >> - >> - .data.rel : { *(.data.rel*) } >> - >> . = ALIGN(PECOFF_SEGMENT_ALIGN); >> __init_begin = .; >> __inittext_begin = .; >> @@ -94,6 +67,18 @@ SECTIONS >> >> __initdata_begin = .; >> >> + /* >> + * struct alt_inst entries. From the header (alternative.h): >> + * "Alternative instructions for different CPU types or capabilities" >> + * Think locking instructions on spinlocks. >> + */ >> + . = ALIGN(4); >> + .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { >> + __alt_instructions = .; >> + *(.altinstructions) >> + __alt_instructions_end = .; >> + } >> + >> INIT_DATA_SECTION(16) >> .exit.data : { >> EXIT_DATA >> @@ -113,6 +98,11 @@ SECTIONS >> >> _sdata = .; >> RO_DATA(4096) >> + >> + .got : ALIGN(16) { *(.got) } >> + .plt : ALIGN(16) { *(.plt) } >> + .got.plt : ALIGN(16) { *(.got.plt) } >> + >> RW_DATA(1 << CONFIG_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE) >> >> .rela.dyn : ALIGN(8) { >> @@ -121,6 +111,17 @@ SECTIONS >> __rela_dyn_end = .; >> } >> >> + .data.rel : { *(.data.rel*) } >> + >> +#ifdef CONFIG_RELOCATABLE >> + . = ALIGN(8); >> + .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { >> + __la_abs_begin = .; >> + *(.la_abs) >> + __la_abs_end = .; >> + } >> +#endif >> + >> .sdata : { >> *(.sdata) >> }
Hi Helge, On Wed, Sep 13, 2023 at 3:18 AM Helge Deller <deller@gmx.de> wrote: > > Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection even > more") the lockdep code uses is_kernel_core_data(), is_kernel_rodata() > and init_section_contains() to verify if a lock is located inside a > kernel static data section. > > This change triggers a failure on LoongArch, for which the vmlinux.lds.S > script misses to put the locks (as part of in the .data.rel symbols) > into the Linux data section. > This patch fixes the lockdep problem by moving *(.data.rel*) symbols > into the kernel data section (from _sdata to _edata). > > Additionally, move other wrongly assigned symbols too: > - altinstructions into the _initdata section, I think altinstructions cannot be put into _initdata because it will be used by modules. Huacai > - PLT symbols behind the read-only section, and > - *(.la_abs) into the data section. > > Signed-off-by: Helge Deller <deller@gmx.de> > Reported-by: Guenter Roeck <linux@roeck-us.net> > Fixes: 0a6b58c5cd0d ("lockdep: fix static memory detection even more") > Cc: stable <stable@kernel.org> # v6.4+ > > diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S > index b1686afcf876..bb2ec86f37a8 100644 > --- a/arch/loongarch/kernel/vmlinux.lds.S > +++ b/arch/loongarch/kernel/vmlinux.lds.S > @@ -53,33 +53,6 @@ SECTIONS > . = ALIGN(PECOFF_SEGMENT_ALIGN); > _etext = .; > > - /* > - * struct alt_inst entries. From the header (alternative.h): > - * "Alternative instructions for different CPU types or capabilities" > - * Think locking instructions on spinlocks. > - */ > - . = ALIGN(4); > - .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { > - __alt_instructions = .; > - *(.altinstructions) > - __alt_instructions_end = .; > - } > - > -#ifdef CONFIG_RELOCATABLE > - . = ALIGN(8); > - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { > - __la_abs_begin = .; > - *(.la_abs) > - __la_abs_end = .; > - } > -#endif > - > - .got : ALIGN(16) { *(.got) } > - .plt : ALIGN(16) { *(.plt) } > - .got.plt : ALIGN(16) { *(.got.plt) } > - > - .data.rel : { *(.data.rel*) } > - > . = ALIGN(PECOFF_SEGMENT_ALIGN); > __init_begin = .; > __inittext_begin = .; > @@ -94,6 +67,18 @@ SECTIONS > > __initdata_begin = .; > > + /* > + * struct alt_inst entries. From the header (alternative.h): > + * "Alternative instructions for different CPU types or capabilities" > + * Think locking instructions on spinlocks. > + */ > + . = ALIGN(4); > + .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { > + __alt_instructions = .; > + *(.altinstructions) > + __alt_instructions_end = .; > + } > + > INIT_DATA_SECTION(16) > .exit.data : { > EXIT_DATA > @@ -113,6 +98,11 @@ SECTIONS > > _sdata = .; > RO_DATA(4096) > + > + .got : ALIGN(16) { *(.got) } > + .plt : ALIGN(16) { *(.plt) } > + .got.plt : ALIGN(16) { *(.got.plt) } > + > RW_DATA(1 << CONFIG_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE) > > .rela.dyn : ALIGN(8) { > @@ -121,6 +111,17 @@ SECTIONS > __rela_dyn_end = .; > } > > + .data.rel : { *(.data.rel*) } > + > +#ifdef CONFIG_RELOCATABLE > + . = ALIGN(8); > + .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { > + __la_abs_begin = .; > + *(.la_abs) > + __la_abs_end = .; > + } > +#endif > + > .sdata : { > *(.sdata) > }
On 9/15/23 05:22, Huacai Chen wrote: > Hi Helge, > > On Wed, Sep 13, 2023 at 3:18 AM Helge Deller <deller@gmx.de> wrote: >> >> Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection even >> more") the lockdep code uses is_kernel_core_data(), is_kernel_rodata() >> and init_section_contains() to verify if a lock is located inside a >> kernel static data section. >> >> This change triggers a failure on LoongArch, for which the vmlinux.lds.S >> script misses to put the locks (as part of in the .data.rel symbols) >> into the Linux data section. >> This patch fixes the lockdep problem by moving *(.data.rel*) symbols >> into the kernel data section (from _sdata to _edata). >> >> Additionally, move other wrongly assigned symbols too: >> - altinstructions into the _initdata section, > I think altinstructions cannot be put into _initdata because it will > be used by modules. No. arch/loongarch/kernel/vmlinux.lds.S is used for the static parts of the kernel and altinstructions are replaced before modules are loaded. For altinstructions in modules the linker script scripts/module.lds.S is used. Helge >> - PLT symbols behind the read-only section, and >> - *(.la_abs) into the data section. >> >> Signed-off-by: Helge Deller <deller@gmx.de> >> Reported-by: Guenter Roeck <linux@roeck-us.net> >> Fixes: 0a6b58c5cd0d ("lockdep: fix static memory detection even more") >> Cc: stable <stable@kernel.org> # v6.4+ >> >> diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S >> index b1686afcf876..bb2ec86f37a8 100644 >> --- a/arch/loongarch/kernel/vmlinux.lds.S >> +++ b/arch/loongarch/kernel/vmlinux.lds.S >> @@ -53,33 +53,6 @@ SECTIONS >> . = ALIGN(PECOFF_SEGMENT_ALIGN); >> _etext = .; >> >> - /* >> - * struct alt_inst entries. From the header (alternative.h): >> - * "Alternative instructions for different CPU types or capabilities" >> - * Think locking instructions on spinlocks. >> - */ >> - . = ALIGN(4); >> - .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { >> - __alt_instructions = .; >> - *(.altinstructions) >> - __alt_instructions_end = .; >> - } >> - >> -#ifdef CONFIG_RELOCATABLE >> - . = ALIGN(8); >> - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { >> - __la_abs_begin = .; >> - *(.la_abs) >> - __la_abs_end = .; >> - } >> -#endif >> - >> - .got : ALIGN(16) { *(.got) } >> - .plt : ALIGN(16) { *(.plt) } >> - .got.plt : ALIGN(16) { *(.got.plt) } >> - >> - .data.rel : { *(.data.rel*) } >> - >> . = ALIGN(PECOFF_SEGMENT_ALIGN); >> __init_begin = .; >> __inittext_begin = .; >> @@ -94,6 +67,18 @@ SECTIONS >> >> __initdata_begin = .; >> >> + /* >> + * struct alt_inst entries. From the header (alternative.h): >> + * "Alternative instructions for different CPU types or capabilities" >> + * Think locking instructions on spinlocks. >> + */ >> + . = ALIGN(4); >> + .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { >> + __alt_instructions = .; >> + *(.altinstructions) >> + __alt_instructions_end = .; >> + } >> + >> INIT_DATA_SECTION(16) >> .exit.data : { >> EXIT_DATA >> @@ -113,6 +98,11 @@ SECTIONS >> >> _sdata = .; >> RO_DATA(4096) >> + >> + .got : ALIGN(16) { *(.got) } >> + .plt : ALIGN(16) { *(.plt) } >> + .got.plt : ALIGN(16) { *(.got.plt) } >> + >> RW_DATA(1 << CONFIG_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE) >> >> .rela.dyn : ALIGN(8) { >> @@ -121,6 +111,17 @@ SECTIONS >> __rela_dyn_end = .; >> } >> >> + .data.rel : { *(.data.rel*) } >> + >> +#ifdef CONFIG_RELOCATABLE >> + . = ALIGN(8); >> + .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { >> + __la_abs_begin = .; >> + *(.la_abs) >> + __la_abs_end = .; >> + } >> +#endif >> + >> .sdata : { >> *(.sdata) >> }
On Fri, Sep 15, 2023 at 4:16 PM Helge Deller <deller@gmx.de> wrote: > > On 9/15/23 05:22, Huacai Chen wrote: > > Hi Helge, > > > > On Wed, Sep 13, 2023 at 3:18 AM Helge Deller <deller@gmx.de> wrote: > >> > >> Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection even > >> more") the lockdep code uses is_kernel_core_data(), is_kernel_rodata() > >> and init_section_contains() to verify if a lock is located inside a > >> kernel static data section. > >> > >> This change triggers a failure on LoongArch, for which the vmlinux.lds.S > >> script misses to put the locks (as part of in the .data.rel symbols) > >> into the Linux data section. > >> This patch fixes the lockdep problem by moving *(.data.rel*) symbols > >> into the kernel data section (from _sdata to _edata). > >> > >> Additionally, move other wrongly assigned symbols too: > >> - altinstructions into the _initdata section, > > > I think altinstructions cannot be put into _initdata because it will > > be used by modules. > > No. > arch/loongarch/kernel/vmlinux.lds.S is used for the static parts of the kernel > and altinstructions are replaced before modules are loaded. > For altinstructions in modules the linker script scripts/module.lds.S is used. OK, then what about .got/.plt? It seems arm64 also doesn't put them in the data section. Huacai > > Helge > > > >> - PLT symbols behind the read-only section, and > >> - *(.la_abs) into the data section. > >> > >> Signed-off-by: Helge Deller <deller@gmx.de> > >> Reported-by: Guenter Roeck <linux@roeck-us.net> > >> Fixes: 0a6b58c5cd0d ("lockdep: fix static memory detection even more") > >> Cc: stable <stable@kernel.org> # v6.4+ > >> > >> diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S > >> index b1686afcf876..bb2ec86f37a8 100644 > >> --- a/arch/loongarch/kernel/vmlinux.lds.S > >> +++ b/arch/loongarch/kernel/vmlinux.lds.S > >> @@ -53,33 +53,6 @@ SECTIONS > >> . = ALIGN(PECOFF_SEGMENT_ALIGN); > >> _etext = .; > >> > >> - /* > >> - * struct alt_inst entries. From the header (alternative.h): > >> - * "Alternative instructions for different CPU types or capabilities" > >> - * Think locking instructions on spinlocks. > >> - */ > >> - . = ALIGN(4); > >> - .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { > >> - __alt_instructions = .; > >> - *(.altinstructions) > >> - __alt_instructions_end = .; > >> - } > >> - > >> -#ifdef CONFIG_RELOCATABLE > >> - . = ALIGN(8); > >> - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { > >> - __la_abs_begin = .; > >> - *(.la_abs) > >> - __la_abs_end = .; > >> - } > >> -#endif > >> - > >> - .got : ALIGN(16) { *(.got) } > >> - .plt : ALIGN(16) { *(.plt) } > >> - .got.plt : ALIGN(16) { *(.got.plt) } > >> - > >> - .data.rel : { *(.data.rel*) } > >> - > >> . = ALIGN(PECOFF_SEGMENT_ALIGN); > >> __init_begin = .; > >> __inittext_begin = .; > >> @@ -94,6 +67,18 @@ SECTIONS > >> > >> __initdata_begin = .; > >> > >> + /* > >> + * struct alt_inst entries. From the header (alternative.h): > >> + * "Alternative instructions for different CPU types or capabilities" > >> + * Think locking instructions on spinlocks. > >> + */ > >> + . = ALIGN(4); > >> + .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { > >> + __alt_instructions = .; > >> + *(.altinstructions) > >> + __alt_instructions_end = .; > >> + } > >> + > >> INIT_DATA_SECTION(16) > >> .exit.data : { > >> EXIT_DATA > >> @@ -113,6 +98,11 @@ SECTIONS > >> > >> _sdata = .; > >> RO_DATA(4096) > >> + > >> + .got : ALIGN(16) { *(.got) } > >> + .plt : ALIGN(16) { *(.plt) } > >> + .got.plt : ALIGN(16) { *(.got.plt) } > >> + > >> RW_DATA(1 << CONFIG_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE) > >> > >> .rela.dyn : ALIGN(8) { > >> @@ -121,6 +111,17 @@ SECTIONS > >> __rela_dyn_end = .; > >> } > >> > >> + .data.rel : { *(.data.rel*) } > >> + > >> +#ifdef CONFIG_RELOCATABLE > >> + . = ALIGN(8); > >> + .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { > >> + __la_abs_begin = .; > >> + *(.la_abs) > >> + __la_abs_end = .; > >> + } > >> +#endif > >> + > >> .sdata : { > >> *(.sdata) > >> } >
On 9/15/23 11:23, Huacai Chen wrote: > On Fri, Sep 15, 2023 at 4:16 PM Helge Deller <deller@gmx.de> wrote: >> >> On 9/15/23 05:22, Huacai Chen wrote: >>> Hi Helge, >>> >>> On Wed, Sep 13, 2023 at 3:18 AM Helge Deller <deller@gmx.de> wrote: >>>> >>>> Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection even >>>> more") the lockdep code uses is_kernel_core_data(), is_kernel_rodata() >>>> and init_section_contains() to verify if a lock is located inside a >>>> kernel static data section. >>>> >>>> This change triggers a failure on LoongArch, for which the vmlinux.lds.S >>>> script misses to put the locks (as part of in the .data.rel symbols) >>>> into the Linux data section. >>>> This patch fixes the lockdep problem by moving *(.data.rel*) symbols >>>> into the kernel data section (from _sdata to _edata). >>>> >>>> Additionally, move other wrongly assigned symbols too: >>>> - altinstructions into the _initdata section, >> >>> I think altinstructions cannot be put into _initdata because it will >>> be used by modules. >> >> No. >> arch/loongarch/kernel/vmlinux.lds.S is used for the static parts of the kernel >> and altinstructions are replaced before modules are loaded. >> For altinstructions in modules the linker script scripts/module.lds.S is used. > OK, then what about .got/.plt? It seems arm64 also doesn't put them in > the data section. arm64 seems to throw away all plt entries already at link time (and just keeps the got.plt in the read-only data section). It even checks at link time, that there are no plt entries in the binary: ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") I don't know for loongarch, but if you need the plt entries for loongarch, it's safest & best to put them into the read-only data section too, which is what my patch does. Up to now, you have them completely outside of code & data sections. In the end you need to decide for your platform. My patch is a suggestion, which I think is correct (untested by me, but Guenter replied he tested it). But to fix the lockdep problem at minimum the move of the .data.rel section is needed. Helge >> >>>> - PLT symbols behind the read-only section, and >>>> - *(.la_abs) into the data section. >>>> >>>> Signed-off-by: Helge Deller <deller@gmx.de> >>>> Reported-by: Guenter Roeck <linux@roeck-us.net> >>>> Fixes: 0a6b58c5cd0d ("lockdep: fix static memory detection even more") >>>> Cc: stable <stable@kernel.org> # v6.4+ >>>> >>>> diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S >>>> index b1686afcf876..bb2ec86f37a8 100644 >>>> --- a/arch/loongarch/kernel/vmlinux.lds.S >>>> +++ b/arch/loongarch/kernel/vmlinux.lds.S >>>> @@ -53,33 +53,6 @@ SECTIONS >>>> . = ALIGN(PECOFF_SEGMENT_ALIGN); >>>> _etext = .; >>>> >>>> - /* >>>> - * struct alt_inst entries. From the header (alternative.h): >>>> - * "Alternative instructions for different CPU types or capabilities" >>>> - * Think locking instructions on spinlocks. >>>> - */ >>>> - . = ALIGN(4); >>>> - .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { >>>> - __alt_instructions = .; >>>> - *(.altinstructions) >>>> - __alt_instructions_end = .; >>>> - } >>>> - >>>> -#ifdef CONFIG_RELOCATABLE >>>> - . = ALIGN(8); >>>> - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { >>>> - __la_abs_begin = .; >>>> - *(.la_abs) >>>> - __la_abs_end = .; >>>> - } >>>> -#endif >>>> - >>>> - .got : ALIGN(16) { *(.got) } >>>> - .plt : ALIGN(16) { *(.plt) } >>>> - .got.plt : ALIGN(16) { *(.got.plt) } >>>> - >>>> - .data.rel : { *(.data.rel*) } >>>> - >>>> . = ALIGN(PECOFF_SEGMENT_ALIGN); >>>> __init_begin = .; >>>> __inittext_begin = .; >>>> @@ -94,6 +67,18 @@ SECTIONS >>>> >>>> __initdata_begin = .; >>>> >>>> + /* >>>> + * struct alt_inst entries. From the header (alternative.h): >>>> + * "Alternative instructions for different CPU types or capabilities" >>>> + * Think locking instructions on spinlocks. >>>> + */ >>>> + . = ALIGN(4); >>>> + .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { >>>> + __alt_instructions = .; >>>> + *(.altinstructions) >>>> + __alt_instructions_end = .; >>>> + } >>>> + >>>> INIT_DATA_SECTION(16) >>>> .exit.data : { >>>> EXIT_DATA >>>> @@ -113,6 +98,11 @@ SECTIONS >>>> >>>> _sdata = .; >>>> RO_DATA(4096) >>>> + >>>> + .got : ALIGN(16) { *(.got) } >>>> + .plt : ALIGN(16) { *(.plt) } >>>> + .got.plt : ALIGN(16) { *(.got.plt) } >>>> + >>>> RW_DATA(1 << CONFIG_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE) >>>> >>>> .rela.dyn : ALIGN(8) { >>>> @@ -121,6 +111,17 @@ SECTIONS >>>> __rela_dyn_end = .; >>>> } >>>> >>>> + .data.rel : { *(.data.rel*) } >>>> + >>>> +#ifdef CONFIG_RELOCATABLE >>>> + . = ALIGN(8); >>>> + .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { >>>> + __la_abs_begin = .; >>>> + *(.la_abs) >>>> + __la_abs_end = .; >>>> + } >>>> +#endif >>>> + >>>> .sdata : { >>>> *(.sdata) >>>> } >>
Hi Helge, On 9/15/23 03:10, Helge Deller wrote: > On 9/15/23 11:23, Huacai Chen wrote: >> On Fri, Sep 15, 2023 at 4:16 PM Helge Deller <deller@gmx.de> wrote: >>> >>> On 9/15/23 05:22, Huacai Chen wrote: >>>> Hi Helge, >>>> >>>> On Wed, Sep 13, 2023 at 3:18 AM Helge Deller <deller@gmx.de> wrote: >>>>> >>>>> Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection even >>>>> more") the lockdep code uses is_kernel_core_data(), is_kernel_rodata() >>>>> and init_section_contains() to verify if a lock is located inside a >>>>> kernel static data section. >>>>> >>>>> This change triggers a failure on LoongArch, for which the vmlinux.lds.S >>>>> script misses to put the locks (as part of in the .data.rel symbols) >>>>> into the Linux data section. >>>>> This patch fixes the lockdep problem by moving *(.data.rel*) symbols >>>>> into the kernel data section (from _sdata to _edata). >>>>> >>>>> Additionally, move other wrongly assigned symbols too: >>>>> - altinstructions into the _initdata section, >>> >>>> I think altinstructions cannot be put into _initdata because it will >>>> be used by modules. >>> >>> No. >>> arch/loongarch/kernel/vmlinux.lds.S is used for the static parts of the kernel >>> and altinstructions are replaced before modules are loaded. >>> For altinstructions in modules the linker script scripts/module.lds.S is used. > >> OK, then what about .got/.plt? It seems arm64 also doesn't put them in >> the data section. > > arm64 seems to throw away all plt entries already at link time (and just keeps > the got.plt in the read-only data section). > It even checks at link time, that there are no plt entries in the binary: > ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") > > I don't know for loongarch, but if you need the plt entries for loongarch, it's > safest & best to put them into the read-only data section too, which is what my patch does. > Up to now, you have them completely outside of code & data sections. > > In the end you need to decide for your platform. My patch is a suggestion, which I think > is correct (untested by me, but Guenter replied he tested it). > But to fix the lockdep problem at minimum the move of the .data.rel section > is needed. > Just my $0.02 .. it might make sense to concentrate on the minimum to get the immediate problem fixed. Loongarch maintainers can then decide at their own pace if they want to apply any of the other changes you suggested. After all, unless I am missing something, those additional changes are not really needed in stable releases. Thanks, Guenter
Hi, On 9/15/23 22:07, Guenter Roeck wrote: > Hi Helge, > > On 9/15/23 03:10, Helge Deller wrote: >> On 9/15/23 11:23, Huacai Chen wrote: >>> On Fri, Sep 15, 2023 at 4:16 PM Helge Deller <deller@gmx.de> wrote: >>>> >>>> On 9/15/23 05:22, Huacai Chen wrote: >>>>> Hi Helge, >>>>> >>>>> On Wed, Sep 13, 2023 at 3:18 AM Helge Deller <deller@gmx.de> wrote: >>>>>> >>>>>> Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection >>>>>> even >>>>>> more") the lockdep code uses is_kernel_core_data(), >>>>>> is_kernel_rodata() >>>>>> and init_section_contains() to verify if a lock is located inside a >>>>>> kernel static data section. >>>>>> >>>>>> This change triggers a failure on LoongArch, for which the >>>>>> vmlinux.lds.S >>>>>> script misses to put the locks (as part of in the .data.rel symbols) >>>>>> into the Linux data section. >>>>>> This patch fixes the lockdep problem by moving *(.data.rel*) symbols >>>>>> into the kernel data section (from _sdata to _edata). >>>>>> >>>>>> Additionally, move other wrongly assigned symbols too: >>>>>> - altinstructions into the _initdata section, >>>> >>>>> I think altinstructions cannot be put into _initdata because it will >>>>> be used by modules. >>>> >>>> No. >>>> arch/loongarch/kernel/vmlinux.lds.S is used for the static parts of >>>> the kernel >>>> and altinstructions are replaced before modules are loaded. >>>> For altinstructions in modules the linker script >>>> scripts/module.lds.S is used. >> >>> OK, then what about .got/.plt? It seems arm64 also doesn't put them in >>> the data section. >> >> arm64 seems to throw away all plt entries already at link time (and >> just keeps >> the got.plt in the read-only data section). >> It even checks at link time, that there are no plt entries in the >> binary: >> ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure >> linkages detected!") >> >> I don't know for loongarch, but if you need the plt entries for >> loongarch, it's >> safest & best to put them into the read-only data section too, which >> is what my patch does. >> Up to now, you have them completely outside of code & data sections. >> >> In the end you need to decide for your platform. My patch is a >> suggestion, which I think >> is correct (untested by me, but Guenter replied he tested it). >> But to fix the lockdep problem at minimum the move of the .data.rel >> section >> is needed. >> > > Just my $0.02 .. it might make sense to concentrate on the minimum to > get the immediate > problem fixed. Loongarch maintainers can then decide at their own pace > if they want > to apply any of the other changes you suggested. After all, unless I > am missing > something, those additional changes are not really needed in stable > releases. Sorry for coming late, but as reviewer of arch/loongarch, I'd agree with Guenter and Helge here: let's fix the immediate problem and investigate the rest later -- it's not like the problems are *definitely* orthogonal in this case, and at least *some* progress would be appreciated. I'll try to reproduce the problem and test the fix during the weekend, so hopefully Huacai can get the fix in before -rc2 or -rc3. Thanks for the attention and fix.
On Fri, Sep 15, 2023 at 10:19 PM WANG Xuerui <kernel@xen0n.name> wrote: > > Hi, > > On 9/15/23 22:07, Guenter Roeck wrote: > > Hi Helge, > > > > On 9/15/23 03:10, Helge Deller wrote: > >> On 9/15/23 11:23, Huacai Chen wrote: > >>> On Fri, Sep 15, 2023 at 4:16 PM Helge Deller <deller@gmx.de> wrote: > >>>> > >>>> On 9/15/23 05:22, Huacai Chen wrote: > >>>>> Hi Helge, > >>>>> > >>>>> On Wed, Sep 13, 2023 at 3:18 AM Helge Deller <deller@gmx.de> wrote: > >>>>>> > >>>>>> Since commit 0a6b58c5cd0d ("lockdep: fix static memory detection > >>>>>> even > >>>>>> more") the lockdep code uses is_kernel_core_data(), > >>>>>> is_kernel_rodata() > >>>>>> and init_section_contains() to verify if a lock is located inside a > >>>>>> kernel static data section. > >>>>>> > >>>>>> This change triggers a failure on LoongArch, for which the > >>>>>> vmlinux.lds.S > >>>>>> script misses to put the locks (as part of in the .data.rel symbols) > >>>>>> into the Linux data section. > >>>>>> This patch fixes the lockdep problem by moving *(.data.rel*) symbols > >>>>>> into the kernel data section (from _sdata to _edata). > >>>>>> > >>>>>> Additionally, move other wrongly assigned symbols too: > >>>>>> - altinstructions into the _initdata section, > >>>> > >>>>> I think altinstructions cannot be put into _initdata because it will > >>>>> be used by modules. > >>>> > >>>> No. > >>>> arch/loongarch/kernel/vmlinux.lds.S is used for the static parts of > >>>> the kernel > >>>> and altinstructions are replaced before modules are loaded. > >>>> For altinstructions in modules the linker script > >>>> scripts/module.lds.S is used. > >> > >>> OK, then what about .got/.plt? It seems arm64 also doesn't put them in > >>> the data section. > >> > >> arm64 seems to throw away all plt entries already at link time (and > >> just keeps > >> the got.plt in the read-only data section). > >> It even checks at link time, that there are no plt entries in the > >> binary: > >> ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure > >> linkages detected!") > >> > >> I don't know for loongarch, but if you need the plt entries for > >> loongarch, it's > >> safest & best to put them into the read-only data section too, which > >> is what my patch does. > >> Up to now, you have them completely outside of code & data sections. > >> > >> In the end you need to decide for your platform. My patch is a > >> suggestion, which I think > >> is correct (untested by me, but Guenter replied he tested it). > >> But to fix the lockdep problem at minimum the move of the .data.rel > >> section > >> is needed. > >> > > > > Just my $0.02 .. it might make sense to concentrate on the minimum to > > get the immediate > > problem fixed. Loongarch maintainers can then decide at their own pace > > if they want > > to apply any of the other changes you suggested. After all, unless I > > am missing > > something, those additional changes are not really needed in stable > > releases. > > Sorry for coming late, but as reviewer of arch/loongarch, I'd agree with > Guenter and Helge here: let's fix the immediate problem and investigate > the rest later -- it's not like the problems are *definitely* orthogonal > in this case, and at least *some* progress would be appreciated. > > I'll try to reproduce the problem and test the fix during the weekend, > so hopefully Huacai can get the fix in before -rc2 or -rc3. Thanks for > the attention and fix. If all changes are OK, I have no objection to putting them in a single patch. Huacai > > -- > WANG "xen0n" Xuerui > > Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/ > >
diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S index b1686afcf876..bb2ec86f37a8 100644 --- a/arch/loongarch/kernel/vmlinux.lds.S +++ b/arch/loongarch/kernel/vmlinux.lds.S @@ -53,33 +53,6 @@ SECTIONS . = ALIGN(PECOFF_SEGMENT_ALIGN); _etext = .; - /* - * struct alt_inst entries. From the header (alternative.h): - * "Alternative instructions for different CPU types or capabilities" - * Think locking instructions on spinlocks. - */ - . = ALIGN(4); - .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { - __alt_instructions = .; - *(.altinstructions) - __alt_instructions_end = .; - } - -#ifdef CONFIG_RELOCATABLE - . = ALIGN(8); - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { - __la_abs_begin = .; - *(.la_abs) - __la_abs_end = .; - } -#endif - - .got : ALIGN(16) { *(.got) } - .plt : ALIGN(16) { *(.plt) } - .got.plt : ALIGN(16) { *(.got.plt) } - - .data.rel : { *(.data.rel*) } - . = ALIGN(PECOFF_SEGMENT_ALIGN); __init_begin = .; __inittext_begin = .; @@ -94,6 +67,18 @@ SECTIONS __initdata_begin = .; + /* + * struct alt_inst entries. From the header (alternative.h): + * "Alternative instructions for different CPU types or capabilities" + * Think locking instructions on spinlocks. + */ + . = ALIGN(4); + .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { + __alt_instructions = .; + *(.altinstructions) + __alt_instructions_end = .; + } + INIT_DATA_SECTION(16) .exit.data : { EXIT_DATA @@ -113,6 +98,11 @@ SECTIONS _sdata = .; RO_DATA(4096) + + .got : ALIGN(16) { *(.got) } + .plt : ALIGN(16) { *(.plt) } + .got.plt : ALIGN(16) { *(.got.plt) } + RW_DATA(1 << CONFIG_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE) .rela.dyn : ALIGN(8) { @@ -121,6 +111,17 @@ SECTIONS __rela_dyn_end = .; } + .data.rel : { *(.data.rel*) } + +#ifdef CONFIG_RELOCATABLE + . = ALIGN(8); + .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { + __la_abs_begin = .; + *(.la_abs) + __la_abs_end = .; + } +#endif + .sdata : { *(.sdata) }