Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4541806rdb; Fri, 15 Sep 2023 05:38:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGa6vKvLGHkowS1kmIZxrj3joDYRQmvM++TTueZivLwXbl+XrUajRcxdMk8RS/dmuPY/q/u X-Received: by 2002:a17:902:f68f:b0:1c0:bf60:ba4f with SMTP id l15-20020a170902f68f00b001c0bf60ba4fmr1505390plg.4.1694781500383; Fri, 15 Sep 2023 05:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694781500; cv=none; d=google.com; s=arc-20160816; b=pobOhs14KswRS3kzh49v3XdXq3S+Tmod6pGr7M21DUKzt/oL1K4hXaAP/Ic3t5FrSg kEu3z1k4O1+EfRHAd5x/DH9DfsR4WXiGAuZ2SlGK7fw2ZzAJofuPGvJF3msoeDLgT64J MBc+pHppr9wHdccZgPOhEsDPDm95CGFz+4aSCxZwSWsjhKoRurQsjmU0j+spOl/oNEJc /2JS17/nzp/oGyR6gGiQLkIL9c+1Suh4K9WzVB/eDvz/+tlam+bBzyJV76DfEupM03pH OSS+23IS5rsq7X3cQm4vi0a6kfLbn0FITkaY7nJilrrZNUNjsQs5AZsXFnIoxKD5OF6u de0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=dBI0GHCIO0w0C40HYlEZTuICoG4ceYkjH1PsoYeOgzo=; fh=7SJtlliP3OzuXG16h5ln31ejVxMXJ7V/hh1hbEwyLy4=; b=KyMQkimFQO3YUzwCVyRxYrmBMGP+5R2ArLQF+vINBXFc15HZEi+XsxbOsOPQyETqiE oafNk/2GkSUfk/DNPtwFVvHvFOoDutiDUEcallBD1tVEuBO909gmSEJlHyjztk0nQZFs rI6sWT+9d+CPzM/M0ah3XwPXRpwGG/tP+ZXhbqANVfN1+dW8jiSpzhUdJiyZibehY6BB ET2zaRzAKCBT/Hy7uLYfKt/zXAV7nURHyD9EGJsAP4Ws65GLZIn2qms9ycYn3FYD2xc6 F7DskAZWqrWqf0W3nMMFV8K7pq6ePC5jWU307tDicZSxA43ru/u3/XA2No8QT/6wOnRD yVVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=q32zpqsc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q5-20020a170902a3c500b001b9e2ce5723si3371437plb.495.2023.09.15.05.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:38:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=q32zpqsc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id A876383C3ADB; Fri, 15 Sep 2023 03:11:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234360AbjIOKLZ (ORCPT + 99 others); Fri, 15 Sep 2023 06:11:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234260AbjIOKLS (ORCPT ); Fri, 15 Sep 2023 06:11:18 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D102C268A for ; Fri, 15 Sep 2023 03:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1694772626; x=1695377426; i=deller@gmx.de; bh=QOexfBkrKFx5QSiaUReqgS/OH3j3yFKpWiQNhjqiWWE=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=q32zpqscIkzRgTflTuNTFu6fE8UZksUh55pxj2vc5cxgKAKAaz9TLPw616maYfZFCP4qriTQnEN OPIGgOV4E2b/yO4a6+ZoqGIJfg+BPw6pM1npT8WA95nfyr4Uyt6j8M4Ncda46Ic3VRot54qwVU7gA k5a+QiyzNeOv1/Dssu8yocUpdydZ9LYTogwZJs3qPtzClZrl1FuDs7VAKh1d6XQZ0ZraXmD37X6Gk auv/hekZuvav7HuW7aMubT2nZWKxLQ9434+Si9Gsl0V/nSXd0GkVa0/LJhyjrgl4jKvnmRzfQ6kXl iVS5YwWEIcMTZM32YcZTlX4hdLeGBwhJMMZw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.20.60] ([94.134.157.117]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MS3mt-1rAXhh0CgF-00TYeT; Fri, 15 Sep 2023 12:10:26 +0200 Message-ID: <1160d063-8396-b126-15ca-a46807ec4258@gmx.de> Date: Fri, 15 Sep 2023 12:10:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] LoongArch: Fix lockdep static memory detection Content-Language: en-US To: Huacai Chen Cc: WANG Xuerui , loongarch@lists.linux.dev, Guenter Roeck , Linus Torvalds , Geert Uytterhoeven , linux-kernel@vger.kernel.org References: From: Helge Deller In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:NHjKD4A+g/FJQYtBwxwcgIaDkB6As5B0qp12+9vpsXTY9lxbU6x +tudTSZscur1kvyzkaO3RdDEnPtIyvvv2z+Dvmhvk8knj5JYfILh84yLxORoPtlyJdeFPGs HNxVMV5IlbUDcxNz67cgeclcchyfed6cKAAtDdZYiTzgVPdT4WtCSxWVdkCc761yXPXfUOt E/GarWXt/GsOk9fKC2xzA== UI-OutboundReport: notjunk:1;M01:P0:jwSKsw9udR8=;isZiHDrDsLZ+ghtLWD50WoaAMiq MIFFEm3WzN/wzycBvj7khuNe4Qf76G7XCkmGXDy2VzJ9jGJLfR7HsHpq3uDd9ftWfjT7pIX7j 1fj3jAwenj0BsADeERrVWq/zb9m9/H8SNgujWzjbEOgSOK0JGxHUGD6azHxw/QAHlbjgmLdzx 2gfkqnVQMkk/ygfX0gyGYKMX9Q9u1k0upi54GrCkOHi5WETiMrpgc7oiT9/a9n29BDX5Rd41r MzLKuyTJmkTPhdWPIbEKWCwzKv1k+FdZkifM0wuSgXZRW+/m5fPs1AWD8oyG+IoBVVIEXmt9S XK/F+7iwQ06JG6KUX+rl+OsK5anNvZ6DvTZyLDcFL9NeG9AywkEsumLS2cRyEzXWBvaCv9Heg iNWqRZn9DxP44GJsaBM0plV60JMe7jU6nX3AFCRXEVQ/WSL/XFRS78ex/Jpl/UB8RWDaWwGRg Xpw/ozcyrTHszc2vpbfDIE1YhoYFZrRs4oyRB3ji/oH46LAqJZhZQH63YEcFnXgBaiNSfBsQ2 Xj7u4K9YCgAcT8bQuKkr98hJniHeCPz9VNpZ+mZChzU5jQzise9WRIxRL+PltTUFajiYE6g0W piQTc4STxlRGES7mrzQZLSC61LDaT7UWdszcBNxgaZA/wd5QugTHK4JEDBp+VV71yvyiedMe7 D3e5Fmu9TdgmEFQhqr5rm0ky3Vhr8nS9U2WLjeke3z6VtL9SRP/ZvfzM6emwQ7rFnpz9jSOwN JxfmnKMbpC9UZ9sFRzPhLiwq8g1vU+mS16h12Gl2JLE+F7whouS8hFKcquOpL2vYvazUMhHZf P6jkVhf4j5KN5NXpDiVZHyWWARVhkyyY8ttHL7yy+ftxo8cKvEbJc56H6YhGi68Acc1j2OEmP W5ZIXawASJ2PdDzjDqBM3/mxxSTwPUSaKVyk1wbC52dgC8p6vE+YSQHgSsPuDeaIKrKq6MhG1 QNRWzw== X-Spam-Status: No, score=-2.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, 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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 15 Sep 2023 03:11:25 -0700 (PDT) On 9/15/23 11:23, Huacai Chen wrote: > On Fri, Sep 15, 2023 at 4:16=E2=80=AFPM Helge Deller wro= te: >> >> On 9/15/23 05:22, Huacai Chen wrote: >>> Hi Helge, >>> >>> On Wed, Sep 13, 2023 at 3:18=E2=80=AFAM Helge Deller w= rote: >>>> >>>> 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.ld= s.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 i= s 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 k= eeps 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) =3D=3D 0, "Unexpected run-time procedure link= ages 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 wh= at 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 sectio= n is needed. Helge >> >>>> - PLT symbols behind the read-only section, and >>>> - *(.la_abs) into the data section. >>>> >>>> Signed-off-by: Helge Deller >>>> Reported-by: Guenter Roeck >>>> Fixes: 0a6b58c5cd0d ("lockdep: fix static memory detection even more"= ) >>>> Cc: stable # v6.4+ >>>> >>>> diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/ker= nel/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 >>>> . =3D ALIGN(PECOFF_SEGMENT_ALIGN); >>>> _etext =3D .; >>>> >>>> - /* >>>> - * struct alt_inst entries. From the header (alternative.h): >>>> - * "Alternative instructions for different CPU types or capab= ilities" >>>> - * Think locking instructions on spinlocks. >>>> - */ >>>> - . =3D ALIGN(4); >>>> - .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { >>>> - __alt_instructions =3D .; >>>> - *(.altinstructions) >>>> - __alt_instructions_end =3D .; >>>> - } >>>> - >>>> -#ifdef CONFIG_RELOCATABLE >>>> - . =3D ALIGN(8); >>>> - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { >>>> - __la_abs_begin =3D .; >>>> - *(.la_abs) >>>> - __la_abs_end =3D .; >>>> - } >>>> -#endif >>>> - >>>> - .got : ALIGN(16) { *(.got) } >>>> - .plt : ALIGN(16) { *(.plt) } >>>> - .got.plt : ALIGN(16) { *(.got.plt) } >>>> - >>>> - .data.rel : { *(.data.rel*) } >>>> - >>>> . =3D ALIGN(PECOFF_SEGMENT_ALIGN); >>>> __init_begin =3D .; >>>> __inittext_begin =3D .; >>>> @@ -94,6 +67,18 @@ SECTIONS >>>> >>>> __initdata_begin =3D .; >>>> >>>> + /* >>>> + * struct alt_inst entries. From the header (alternative.h): >>>> + * "Alternative instructions for different CPU types or capab= ilities" >>>> + * Think locking instructions on spinlocks. >>>> + */ >>>> + . =3D ALIGN(4); >>>> + .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { >>>> + __alt_instructions =3D .; >>>> + *(.altinstructions) >>>> + __alt_instructions_end =3D .; >>>> + } >>>> + >>>> INIT_DATA_SECTION(16) >>>> .exit.data : { >>>> EXIT_DATA >>>> @@ -113,6 +98,11 @@ SECTIONS >>>> >>>> _sdata =3D .; >>>> 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 =3D .; >>>> } >>>> >>>> + .data.rel : { *(.data.rel*) } >>>> + >>>> +#ifdef CONFIG_RELOCATABLE >>>> + . =3D ALIGN(8); >>>> + .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { >>>> + __la_abs_begin =3D .; >>>> + *(.la_abs) >>>> + __la_abs_end =3D .; >>>> + } >>>> +#endif >>>> + >>>> .sdata : { >>>> *(.sdata) >>>> } >>