Message ID | 20230914170138.995606-1-song@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp569332vqi; Thu, 14 Sep 2023 12:16:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEs+Wy0qiXDJSl2/3rPIIp1DEon/qd59fXy1TkJ0u9hOqnEl5MiCmUt8X+pOm/IeWc3mPNg X-Received: by 2002:a05:6a00:803:b0:68a:5cf8:dac5 with SMTP id m3-20020a056a00080300b0068a5cf8dac5mr7223361pfk.22.1694718971011; Thu, 14 Sep 2023 12:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694718970; cv=none; d=google.com; s=arc-20160816; b=OkkaeYog5Mq/O2wyibZzjim/9h2XsQKroy4G+j+DUGwqKMSIphkaIoNZ8yVE+VNZmL sraRqfxzcAsxrqbppvSY27y4WDegLxhCcuaKjo/boub4owxuFWhske4gbNV9zV+Kjt+3 gYkZ3+ugUhQ6esg4cI7OhmnI6p4iwBDglQcuMt/toh2vwK5LSN+TvPDlTgmmveTbYYwB Xmc18LWq/XB0zdzcHr3IeKh2BqsroUIfjq3Ajn/gn2Lc3w5f8tY83RC8d2QS5potdFIx RRg6i1GbXqkWzBe6eWpXmdWQnbj2Qrg+0uKKCY/lNEzSRfkuwrw6izMSs6QsP1LZ1XyD wyPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=1Pr9ZdyWt6mWiPHehO0g6V9+V2ZomF3YdEjlrQ19E5A=; fh=ceDvjZsqNvYnJjBzcj/Tkqp5r9poLxNgb08mgS2xniM=; b=v3vQHTjoEQWg0UgzRDF3O2ZPxHxZF/IaBtxeEvhjui0UaCjY5Oq/xokZXl4/Bh20D0 CcgQnH2eHAK0haCSdQcjXL6a6Wcd714Mo7j521adRBooHzPMfOX+fccPml3JdZzGIAHu j6a5QAw8PWt4lHc20YYdmfxVIk0MjN8Tt7blriN4Qgya+Ql9A+8+Kq1xD6fCJKv4tsGN zAKNx97oOwqmCKV1jhSjG7/gH+ORnQliAzSlzAkYJjy2Nr0E1aZde3jmSRJ8IhRKFtYj NOPnaANQWfPkInvC2Sde5ej99C4/SQjrIc7W9VeOiZB7FqF0yUZdVaafQU7YPpradrns C2yQ== 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:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s22-20020a656456000000b00573fdbc93c0si1909728pgv.892.2023.09.14.12.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 12:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 46D018226AC4; Thu, 14 Sep 2023 10:02:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231588AbjINRCF convert rfc822-to-8bit (ORCPT <rfc822;pwkd43@gmail.com> + 33 others); Thu, 14 Sep 2023 13:02:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjINRCE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 14 Sep 2023 13:02:04 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E460A1BD9 for <linux-kernel@vger.kernel.org>; Thu, 14 Sep 2023 10:01:59 -0700 (PDT) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38EF3xYJ002794 for <linux-kernel@vger.kernel.org>; Thu, 14 Sep 2023 10:01:59 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3t44fu958x-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for <linux-kernel@vger.kernel.org>; Thu, 14 Sep 2023 10:01:59 -0700 Received: from twshared24695.38.frc1.facebook.com (2620:10d:c0a8:1b::2d) by mail.thefacebook.com (2620:10d:c0a8:82::b) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 14 Sep 2023 10:01:55 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id D443F2458D1EB; Thu, 14 Sep 2023 10:01:50 -0700 (PDT) From: Song Liu <song@kernel.org> To: <linux-kernel@vger.kernel.org> CC: <ndesaulniers@google.com>, Song Liu <song@kernel.org>, Ricardo Ribalda <ribalda@chromium.org>, Sami Tolvanen <samitolvanen@google.com>, <kexec@lists.infradead.org>, <x86@kernel.org>, <llvm@lists.linux.dev> Subject: [PATCH v3] x86/purgatory: Remove LTO flags Date: Thu, 14 Sep 2023 10:01:38 -0700 Message-ID: <20230914170138.995606-1-song@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: ifomU8eacBZTOObm3QW3u4GgR1DBcA-U X-Proofpoint-GUID: ifomU8eacBZTOObm3QW3u4GgR1DBcA-U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_09,2023-09-14_01,2023-05-22_02 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 (howler.vger.email [0.0.0.0]); Thu, 14 Sep 2023 10:02:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777040479066943738 X-GMAIL-MSGID: 1777041640022652417 |
Series |
[v3] x86/purgatory: Remove LTO flags
|
|
Commit Message
Song Liu
Sept. 14, 2023, 5:01 p.m. UTC
-flto* implies -ffunction-sections. With LTO enabled, ld.lld generates
multiple .text sections for purgatory.ro:
$ readelf -S purgatory.ro | grep " .text"
[ 1] .text PROGBITS 0000000000000000 00000040
[ 7] .text.purgatory PROGBITS 0000000000000000 000020e0
[ 9] .text.warn PROGBITS 0000000000000000 000021c0
[13] .text.sha256_upda PROGBITS 0000000000000000 000022f0
[15] .text.sha224_upda PROGBITS 0000000000000000 00002be0
[17] .text.sha256_fina PROGBITS 0000000000000000 00002bf0
[19] .text.sha224_fina PROGBITS 0000000000000000 00002cc0
This cause WARNING from kexec_purgatory_setup_sechdrs():
WARNING: CPU: 26 PID: 110894 at kernel/kexec_file.c:919
kexec_load_purgatory+0x37f/0x390
Fix this by disabling LTO for purgatory.
We could also fix this with an explicit linker script to rejoin .text.*
sections back into .text. However, given the benefit of LTOing pugatory
is small, simply disable the production of more .text.* sections for now.
Fixes: b33fff07e3e3 ("x86, build: allow LTO to be selected")
Cc: Ricardo Ribalda <ribalda@chromium.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: kexec@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: x86@kernel.org
Cc: llvm@lists.linux.dev
Signed-off-by: Song Liu <song@kernel.org>
---
AFAICT, x86 is the only arch that supports LTO and purgatory.
Changes in v3:
1. Fix "Fixes" tag. (Nick Desaulniers)
2. Add description of an alternative fix, with linker script.
(Nick Desaulniers)
Changes in v2:
1. Use CC_FLAGS_LTO instead of hardcode -flto. (Nick Desaulniers)
---
arch/x86/purgatory/Makefile | 4 ++++
1 file changed, 4 insertions(+)
Comments
On Thu, Sep 14, 2023 at 10:02 AM Song Liu <song@kernel.org> wrote: > > -flto* implies -ffunction-sections. With LTO enabled, ld.lld generates > multiple .text sections for purgatory.ro: > > $ readelf -S purgatory.ro | grep " .text" > [ 1] .text PROGBITS 0000000000000000 00000040 > [ 7] .text.purgatory PROGBITS 0000000000000000 000020e0 > [ 9] .text.warn PROGBITS 0000000000000000 000021c0 > [13] .text.sha256_upda PROGBITS 0000000000000000 000022f0 > [15] .text.sha224_upda PROGBITS 0000000000000000 00002be0 > [17] .text.sha256_fina PROGBITS 0000000000000000 00002bf0 > [19] .text.sha224_fina PROGBITS 0000000000000000 00002cc0 > > This cause WARNING from kexec_purgatory_setup_sechdrs(): > > WARNING: CPU: 26 PID: 110894 at kernel/kexec_file.c:919 > kexec_load_purgatory+0x37f/0x390 > > Fix this by disabling LTO for purgatory. > > We could also fix this with an explicit linker script to rejoin .text.* > sections back into .text. However, given the benefit of LTOing pugatory > is small, simply disable the production of more .text.* sections for now. > > Fixes: b33fff07e3e3 ("x86, build: allow LTO to be selected") > Cc: Ricardo Ribalda <ribalda@chromium.org> > Cc: Sami Tolvanen <samitolvanen@google.com> > Cc: kexec@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Cc: x86@kernel.org > Cc: llvm@lists.linux.dev > Signed-off-by: Song Liu <song@kernel.org> > > --- > AFAICT, x86 is the only arch that supports LTO and purgatory. > > Changes in v3: > 1. Fix "Fixes" tag. (Nick Desaulniers) > 2. Add description of an alternative fix, with linker script. > (Nick Desaulniers) > > Changes in v2: > 1. Use CC_FLAGS_LTO instead of hardcode -flto. (Nick Desaulniers) > --- > arch/x86/purgatory/Makefile | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile > index c2a29be35c01..08aa0f25f12a 100644 > --- a/arch/x86/purgatory/Makefile > +++ b/arch/x86/purgatory/Makefile > @@ -19,6 +19,10 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY > # optimization flags. > KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS)) > > +# When LTO is enabled, llvm emits many text sections, which is not supported > +# by kexec. Remove -flto=* flags. > +KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS)) > + > # When linking purgatory.ro with -r unresolved symbols are not checked, > # also link a purgatory.chk binary without -r to check for unresolved symbols. > PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib LGTM, thanks for the patch! Reviewed-by: Sami Tolvanen <samitolvanen@google.com> Sami
diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index c2a29be35c01..08aa0f25f12a 100644 --- a/arch/x86/purgatory/Makefile +++ b/arch/x86/purgatory/Makefile @@ -19,6 +19,10 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY # optimization flags. KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS)) +# When LTO is enabled, llvm emits many text sections, which is not supported +# by kexec. Remove -flto=* flags. +KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS)) + # When linking purgatory.ro with -r unresolved symbols are not checked, # also link a purgatory.chk binary without -r to check for unresolved symbols. PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib