Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2051317rwb; Thu, 17 Nov 2022 06:02:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf5CJOaqLR6EXj6d/9n8mHNODHxg+I4Hay5GmJU4dtWllmamr+AWlSdCjpF/ePUxU/GfYtkm X-Received: by 2002:a17:906:cedc:b0:7ad:e8dd:837c with SMTP id si28-20020a170906cedc00b007ade8dd837cmr2418603ejb.264.1668693744693; Thu, 17 Nov 2022 06:02:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668693744; cv=none; d=google.com; s=arc-20160816; b=uRxNcxSsO13FSscDJrUb6no+x+pHmukeNwZCASGrpXHpLno3vs+ECPc/xdv7M+9F86 mgcaSNebSO7cmvfkelrs627lXWs6aamhlku9Br6rwr/oreBObTTJWlYl4HWOZo7e+1hk t9N/aa+qsgdEmbwQ1Wy8MkBrdbKvxJ9TGyN9ttTRn/QBh3clLJsoIaozYHf5TZ5pt+3D demqTUCI0BCcaxI0qPscKijO1AOnwR2q7Nag0nqo2Y2RVVZQjEDXnaigXG2cPUOzwEMj KezxMjDCvoNrTPJ5TejF4lWNW3sRMflXLZ6EGazUDpIreHjNYq1nuwRE8ol6olbN3SaI BovA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature:dkim-signature; bh=eHZtzoLmgWNyYNUouVIRCZY0sUahEygITlmSolT078s=; b=Oh29fv4XkFuI1YYAW20eRMeLK2SXdcrTCQZPTqmtM+XaxKUlu7wu1WroLaQcGwxglE PUHYHJoqc2EIDPqSVo2r1Mab/T7XTA5hgRrHJDt+DGXOvWIu9cUL2syP9/bdSvpu/5kU Uco/Gl/VIBOh1Xa6NNcRTlY8y7hRF9DEi94QH0KPoBB4muBWfwEmKXlZ8pJyqWNN3rDN MIThagtkTmc2lPh5ijY/c3cEq+GD2puNJB+BbI7RZ8MfqBmq8IS3PK5Y/anYwaqflWdT O+wBsDeRba9GLT8pvhHaNb4fOP2RP+hF3p9yPBhV1WarDWue9OWyYui7/LhjZowrC/hG rwnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=pejazUta; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m9-20020a170906848900b00783645da4e5si535813ejx.582.2022.11.17.06.02.01; Thu, 17 Nov 2022 06:02:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=pejazUta; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240238AbiKQNzN (ORCPT + 92 others); Thu, 17 Nov 2022 08:55:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240235AbiKQNzL (ORCPT ); Thu, 17 Nov 2022 08:55:11 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38D1F11805 for ; Thu, 17 Nov 2022 05:55:10 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D1CDF2277E; Thu, 17 Nov 2022 13:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1668693308; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eHZtzoLmgWNyYNUouVIRCZY0sUahEygITlmSolT078s=; b=pejazUta8vOTgr0YDbBTFzGQQUQoIj10cp0lp9HCyhgpq5MCkaD6y87OOJNl9t3Bmz26nw 6sLgURDwKQTG/hQvAVFTQgeOHrHLlN/hEdOgzO8lVWVelcXRC31tFgh7zmHTuTCLH3HG3i ripbNbtt9T2Sx1h+RdKTYhw4vH724LM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1668693308; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eHZtzoLmgWNyYNUouVIRCZY0sUahEygITlmSolT078s=; b=vsnrAzA1JIFC1BdEOnH/2y/mURbqgxpqnIyFDYwpAwTgYbQrEiKi3saGIvrh1wOxtDJrmz Q7KtexlcOZn0XBBg== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id EE0072C141; Thu, 17 Nov 2022 13:55:07 +0000 (UTC) Date: Thu, 17 Nov 2022 13:55:07 +0000 (UTC) From: Richard Biener To: Ard Biesheuvel cc: Peter Zijlstra , "Jiri Slaby (SUSE)" , linux-kernel@vger.kernel.org, Alexander Potapenko , Alexander Shishkin , Alexei Starovoitov , Alexey Makhalov , Andrew Morton , Andrey Konovalov , Andrey Ryabinin , Andrii Nakryiko , Andy Lutomirski , Arnaldo Carvalho de Melo , Ben Segall , Borislav Petkov , Daniel Borkmann , Daniel Bristot de Oliveira , Dave Hansen , Dietmar Eggemann , Dmitry Vyukov , Don Zickus , Hao Luo , "H . J . Lu" , "H. Peter Anvin" , Huang Rui , Ingo Molnar , Jan Hubicka , Jason Baron , Jiri Kosina , Jiri Olsa , Joe Lawrence , John Fastabend , Josh Poimboeuf , Juergen Gross , Juri Lelli , KP Singh , Mark Rutland , Martin KaFai Lau , Martin Liska , Masahiro Yamada , Mel Gorman , Miguel Ojeda , Michal Marek , Miroslav Benes , Namhyung Kim , Nick Desaulniers , Oleksandr Tyshchenko , Petr Mladek , "Rafael J. Wysocki" , Sedat Dilek , Song Liu , Stanislav Fomichev , Stefano Stabellini , Steven Rostedt , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vincenzo Frascino , Viresh Kumar , VMware PV-Drivers Reviewers , Yonghong Song Subject: Re: [PATCH 00/46] gcc-LTO support for the kernel In-Reply-To: Message-ID: References: <20221114114344.18650-1-jirislaby@kernel.org> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Nov 2022, Ard Biesheuvel wrote: > On Thu, 17 Nov 2022 at 12:43, Peter Zijlstra wrote: > > > > On Thu, Nov 17, 2022 at 08:50:59AM +0000, Richard Biener wrote: > > > On Thu, 17 Nov 2022, Peter Zijlstra wrote: > > > > > > > On Mon, Nov 14, 2022 at 08:40:50PM +0100, Ard Biesheuvel wrote: > > > > > On Mon, 14 Nov 2022 at 12:44, Jiri Slaby (SUSE) wrote: > > > > > > > > > > > > Hi, > > > > > > > > > > > > this is the first call for comments (and kbuild complaints) for this > > > > > > support of gcc (full) LTO in the kernel. Most of the patches come from > > > > > > Andi. Me and Martin rebased them to new kernels and fixed the to-use > > > > > > known issues. Also I updated most of the commit logs and reordered the > > > > > > patches to groups of patches with similar intent. > > > > > > > > > > > > The very first patch comes from Alexander and is pending on some x86 > > > > > > queue already (I believe). I am attaching it only for completeness. > > > > > > Without that, the kernel does not boot (LTO reorders a lot). > > > > > > > > > > > > In our measurements, the performance differences are negligible. > > > > > > > > > > > > The kernel is bigger with gcc LTO due to more inlining. > > > > > > > > > > OK, so if I understand this correctly: > > > > > - the performance is the same > > > > > - the resulting image is bigger > > > > > - we need a whole lot of ugly hacks to placate the linker. > > > > > > > > > > Pardon my cynicism, but this cover letter does not mention any > > > > > advantages of LTO, so what is the point of all of this? > > > > > > > > Seconded; I really hate all the ugly required for the GCC-LTO > > > > 'solution'. There not actually being any benefit just makes it a very > > > > simple decision to drop all these patches on the floor. > > > > > > I'd say that instead a prerequesite for the series would be to actually > > > enforce hidden visibility for everything not part of the kernel module > > > API so the compiler can throw away unused functions. Currently it has > > > to keep everything because with a shared object there might be external > > > references to everything exported from individual TUs. > > > > I'm not sure what you're on about; only symbols annotated with > > EXPORT_SYMBOL*() are accessible from modules (aka DSOs) and those will > > have their address taken. You can feely eliminate any unused symbol. But IIRC that's not reflected on the ELF level by making EXPORT_SYMBOL*() symbols public and the rest hidden - instead all symbols global in the C TUs will become public and the module dynamic loader details are hidden from GCCs view of the kernel image as ELF relocatable object. > > > There was a size benefit mentioned for module-less monolithic kernels > > > as likely used in embedded setups, not sure if that's enough motivation > > > to properly annotate symbols with visibility - and as far as I understand > > > all these 'required' are actually such fixes. > > > > I'm not seeing how littering __visible is useful or desired, doubly so > > for that static hack, that's just a crude work around for GCC LTO being > > inferior for not being able to read inline asm. > > We have an __ADDRESSABLE() macro and asmlinkage modifier to annotate > symbols that may appear to the compiler as though they are never > referenced. > > Would it be possible to repurpose those so that the LTO code knows > which symbols it must not remove? I find /* * Force the compiler to emit 'sym' as a symbol, so that we can reference * it from inline assembler. Necessary in case 'sym' could be inlined * otherwise, or eliminated entirely due to lack of references that are * visible to the compiler. */ #define ___ADDRESSABLE(sym, __attrs) \ static void * __used __attrs \ __UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)&sym; #define __ADDRESSABLE(sym) \ ___ADDRESSABLE(sym, __section(".discard.addressable")) that should be enough to force LTO keeping 'sym' - unless there's a linker script that discards .discard.addressable which I fear LTO will notice, losing the effect. A more direct way would be to attach __used to 'sym' directly. __ADDRESSABLE doesn't seem to be used directly but instead I see cases like #define __define_initcall_stub(__stub, fn) \ int __init __stub(void); \ int __init __stub(void) \ { \ return fn(); \ } \ __ADDRESSABLE(__stub) where one could have added __used to the __stub prototypes instead? The folks who worked on LTO enablement of the kernel should know the real issue better - I understand asm()s are a pain because GCC refuses to parse the assembler string heuristically for used symbols (but it can never be more than heuristics). The issue with asm()s is not so much elimination (__used solves that) but that GCC can end up moving the asm() and the refered to symbols to different link-time units causing unresolved symbols for non-global symbols. -fno-toplevel-reorder should fix that at some cost. Richard. -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)