Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp701297lqz; Sat, 30 Mar 2024 15:33:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIwTkTXhhVHbkqZQ+zCCaki6XOqovSTFgBqGnHUnoGl3bUS1PC9NYTSAlUpcGuWVVu/IEmCV3VnNu/NlhxS/hkaQwOTevDI/+DqQWj8g== X-Google-Smtp-Source: AGHT+IFLbLw0gV0J1YmdFADHR/dezWtNCyTGx1cVxrfRSKD9bNl6Ibg3DQYAMCVnG+EWZrnaVmhw X-Received: by 2002:a50:999e:0:b0:566:7769:11c with SMTP id m30-20020a50999e000000b005667769011cmr7859465edb.19.1711837995860; Sat, 30 Mar 2024 15:33:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711837995; cv=pass; d=google.com; s=arc-20160816; b=K7lVAZqhWKQoGn6o8Ix5xUmzMxSPKWXtGwrqqo9JwVzdhv0mntiWjIX1oWvUbAt0Iy Ehzadoy5I/1eipCOElv1l6werjDlDKUlOpRNFGESGtrROuKGwqFU9oDNiUi0XM1t5zo7 di/8jE5d7BF+MMR+hCNDbYE1Sr8w81+IIkfjWQ7Yg1q1h0T2I/K0unaXRSRgtykelERB TtLBnsS9MxPKDJTgfwig5jcka3ANqCuCagxMQHbd8Et3ZkW3O1hrpQHsf1q/CLCJMk26 ox9mqplMPU0utRGJZq2FKo1k2ThO7wCufYU/XHzqriFYDn3urQND22KmRfNnLyInrhPf rn9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=CjRZqXH4O9NIrKGuArot+5i7bibdSXDsEAYiGs/Hmz8=; fh=ZhkcRBV2GCAetYNRCtrJpTa/leoKQAVhHSCRnenO26Y=; b=d2qsrTCiTRiV2dJYN5WmtDqPSLMChNa9u/skngXZ1h4JR+Qp4B3V/P70z+jyTCQiyE y5iuyIZ4yNtFB56wyNUYdECtLVua4o+UYesXHrsD4IF3TpxY1KqcGodDZPmx82uQAk5b 1rQyLiHJ7JwbkTHcaX62UlaKLx/Kgkjf2qBFDP9iqiRArUAvq/SEemr2FmsXRS1d5D6f t0fz6YO/+/F3Qp5at6Z8GPGvYdroCGzDxd2UGIIbppqc46AO4W6jopDiX34ea1W5PnUW 8auVU667YhBxCAu57vkLfp1Y8wOX0QVAGtSua9HfzC8JpDy/aXW8CHUXEdcsrqsRKHWA qL+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bxcemWO2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-125902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125902-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q26-20020a50aa9a000000b0056c07b4c013si3082908edc.100.2024.03.30.15.33.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 15:33:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-125902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bxcemWO2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-125902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125902-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6B18E1F21989 for ; Sat, 30 Mar 2024 22:33:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA8EB381DF; Sat, 30 Mar 2024 22:33:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bxcemWO2" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF50C28F8; Sat, 30 Mar 2024 22:33:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711837989; cv=none; b=WSn1iK9Ec9mmuxtAYMjNuo01o9xo3uU9jSGU2dzwaCB4OP3A7ZklY+Si9jkGS8mryS17qGqmz6fVSGJay5Ajvs8xZK3/bKWJduQ7TSYo3X1m/kHZI+Tti2GKNOcbA3Xz9Rh1lUGJbFc1xKW684fSgWUeP2XTiOcSfXR/0pHgSyU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711837989; c=relaxed/simple; bh=wWXFZPTscxJeW0asxEFwp355Ey119yMRyA/FK3awRE4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=T9BOU8/JE6UcLwLWYfzIP7Zig9kJRZ6/pTtECcIB/h+IG/9qyLa0bx4mCa70gqzJ9/0cJFLqfoX3YzlsunJpiuDBAFAXbcj5Fm9kmi2RvrVymjrOXaTjGJEnjrYw5onqTazuqQd6x1WKn+rZEUfohMU/2O4vWH/J2//yeuQoH4Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bxcemWO2; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68744C43390; Sat, 30 Mar 2024 22:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711837988; bh=wWXFZPTscxJeW0asxEFwp355Ey119yMRyA/FK3awRE4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bxcemWO2n3VWmOhq4TGNRhMfRNuq41/0lfGpbqmaTpM/ocC1vfviUnTDXFYtKA6hS Vcy/sfQW52fl1zl8d20Dy1cWFq1pAjgAeQjLZz7n7FyCvsFFwbUimR+f3L/5ryss0D kkm54xN3lOOY7/KbwnBOKGmZqvvTEMljed/uQ34gkGS22HY5788r7P/XfWni9LhUvR GXDbH57uZY7GFsDanOWQPknELZsrC0vY4UVJbb5ejJxj7krOBYFaleL4jDNXd/LvCW eBGrSUSnwfPa2voRZmgGpOkikjyUXONhfy8ZQ6t3DRhftOq7+hOr4Ex5dEWZxJsGZ/ yrwR9PLxhiU1Q== Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-515ac73c516so3177173e87.0; Sat, 30 Mar 2024 15:33:08 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXCCERucJ1U44sXj5ev0CbhRNGY3JN3EhDMYNzumMFq+sUSPksYr/N7GaJKASFSr/ml/AJe+QZt4C6pmp1CFpyxs01neVoaUbM8BvhmnhqHvjCm3q120wdoni/WeXntXmLbXVu4uO16l84H X-Gm-Message-State: AOJu0Yz4dLh5r6ZaS3VJ+2SdMolbKc2lwRIJT7jvWuW22ecM28/G8K+9 WWMZnhXmUN8Tmul6MgWzsTC7d9kBaZi1RFoP43cgwgGAXHso6drDoCm9QRWlmiMLWsxI05XF9dz bYE1mYBG0dHMkt+iMZ4thMTqd6es= X-Received: by 2002:ac2:5a4b:0:b0:513:d234:e8c1 with SMTP id r11-20020ac25a4b000000b00513d234e8c1mr2020997lfn.28.1711837987085; Sat, 30 Mar 2024 15:33:07 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <0851a207-7143-417e-be31-8bf2b3afb57d@molgen.mpg.de> <47e032a0-c9a0-4639-867b-cb3d67076eaf@suse.com> <20240326155247.GJZgLvT_AZi3XPPpBM@fat_crate.local> <80582244-8c1c-4eb4-8881-db68a1428817@suse.com> <20240326191211.GKZgMeC21uxi7H16o_@fat_crate.local> <20240326202548.GLZgMvTGpPfQcs2cQ_@fat_crate.local> In-Reply-To: <20240326202548.GLZgMvTGpPfQcs2cQ_@fat_crate.local> From: Masahiro Yamada Date: Sun, 31 Mar 2024 07:32:30 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kbuild: Disable KCSAN for autogenerated *.mod.c intermediaries To: Borislav Petkov Cc: Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, Marco Elver , Nikolay Borisov , Josh Poimboeuf , Paul Menzel , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Dave Hansen , x86@kernel.org, LKML , kasan-dev@googlegroups.com, David Kaplan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 27, 2024 at 5:26=E2=80=AFAM Borislav Petkov wrot= e: > > On Tue, Mar 26, 2024 at 08:33:31PM +0100, Marco Elver wrote: > > I think just removing instrumentation from the mod.c files is very reas= onable. > > Thanks! > > @Masahiro: pls send this to Linus now as the commit which adds the > warning is in 6.9 so we should make sure we release it with all issues > fixed. > > Thx. > > --- > From: "Borislav Petkov (AMD)" > Date: Tue, 26 Mar 2024 21:11:01 +0100 > > When KCSAN and CONSTRUCTORS are enabled, one can trigger the > > "Unpatched return thunk in use. This should not happen!" > > catch-all warning. > > Usually, when objtool runs on the .o objects, it does generate a section > .return_sites which contains all offsets in the objects to the return > thunks of the functions present there. Those return thunks then get > patched at runtime by the alternatives. > > KCSAN and CONSTRUCTORS add this to the the object file's .text.startup > section: > > ------------------- > Disassembly of section .text.startup: > > ... > > 0000000000000010 <_sub_I_00099_0>: > 10: f3 0f 1e fa endbr64 > 14: e8 00 00 00 00 call 19 <_sub_I_00099_0+0x9> > 15: R_X86_64_PLT32 __tsan_init-0x4 > 19: e9 00 00 00 00 jmp 1e <__UNIQUE_ID___addressable_cr= yptd_alloc_aead349+0x6> > 1a: R_X86_64_PLT32 __x86_return_thunk-0x4 > ------------------- > > which, if it is built as a module goes through the intermediary stage of > creating a .mod.c file which, when translated, receives a second > constructor: > > ------------------- > Disassembly of section .text.startup: > > 0000000000000010 <_sub_I_00099_0>: > 10: f3 0f 1e fa endbr64 > 14: e8 00 00 00 00 call 19 <_sub_I_00099_0+0x9> > 15: R_X86_64_PLT32 __tsan_init-0x4 > 19: e9 00 00 00 00 jmp 1e <_sub_I_00099_0+0xe> > 1a: R_X86_64_PLT32 __x86_return_thunk-0x4 > > ... > > 0000000000000030 <_sub_I_00099_0>: > 30: f3 0f 1e fa endbr64 > 34: e8 00 00 00 00 call 39 <_sub_I_00099_0+0x9> > 35: R_X86_64_PLT32 __tsan_init-0x4 > 39: e9 00 00 00 00 jmp 3e <__ksymtab_cryptd_alloc_ahash= +0x2> > 3a: R_X86_64_PLT32 __x86_return_thunk-0x4 > ------------------- > > in the .ko file. > > Objtool has run already so that second constructor's return thunk cannot > be added to the .return_sites section and thus the return thunk remains > unpatched and the warning rightfully fires. > > Drop KCSAN flags from the mod.c generation stage as those constructors > do not contain data races one would be interested about. > > Debugged together with David Kaplan and Nikolay > Borisov . > > Reported-by: Paul Menzel > Signed-off-by: Borislav Petkov (AMD) > Link: https://lore.kernel.org/r/0851a207-7143-417e-be31-8bf2b3afb57d@molg= en.mpg.de > --- > scripts/Makefile.modfinal | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal > index 8568d256d6fb..79fcf2731686 100644 > --- a/scripts/Makefile.modfinal > +++ b/scripts/Makefile.modfinal > @@ -23,7 +23,7 @@ modname =3D $(notdir $(@:.mod.o=3D)) > part-of-module =3D y > > quiet_cmd_cc_o_c =3D CC [M] $@ > - cmd_cc_o_c =3D $(CC) $(filter-out $(CC_FLAGS_CFI) $(CFLAGS_GCOV), = $(c_flags)) -c -o $@ $< > + cmd_cc_o_c =3D $(CC) $(filter-out $(CC_FLAGS_CFI) $(CFLAGS_GCOV) $= (CFLAGS_KCSAN), $(c_flags)) -c -o $@ $< > > %.mod.o: %.mod.c FORCE > $(call if_changed_dep,cc_o_c) > -- > 2.43.0 > > > > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette I applied. I fixed the typo "the the" and replaced Link: with Closes: to address the following checkpatch warnings: WARNING: Possible repeated word: 'the' #18: KCSAN and CONSTRUCTORS add this to the the object file's .text.startup WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report #70: Reported-by: Paul Menzel Signed-off-by: Borislav Petkov (AMD) Instead of filter-out, you could add KCSAN_SANITIZE :=3D n to scripts/Makefile.modfinal because it is the reason why KCSAN_SANITIZE exists. But, that is not a big deal. GCOV flag is also filtered away instead of GCOV_PROFILE :=3D n I will probably use a different approach later. --=20 Best Regards Masahiro Yamada