Message ID | 20230321-kexec_clang16-v5-2-5563bf7c4173@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1005833vqo; Thu, 30 Mar 2023 02:55:04 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1t+WA8E8uiMRM1yXUM2dvIEhbLnA3B+c/IdJaXNNhAbUvayffOfIHTL5HKrt99NnRXSaN X-Received: by 2002:a05:6402:2032:b0:4ac:bd84:43d8 with SMTP id ay18-20020a056402203200b004acbd8443d8mr22135692edb.8.1680170104103; Thu, 30 Mar 2023 02:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680170104; cv=none; d=google.com; s=arc-20160816; b=aNPx+tt9XjM2P6CAcpzobbOryyZpSoIZpZ3LVgSCXDDSFk0VWf70gqPcGkg1A9bBqS Pj6N6jAdLyAwe8KfF44XKXsjyPnZTSTGLUJMbVUHCEOiM8ug8qrmpZLB3u30T4+ap1PE iNattaOpw0kScqdab+ZuqrBqpZ0+ydb5GkzqYjT115INwPt6tv781tJg4QzAhhklB4rf NPwAiIFHXZS7HyRBSAk3e3DiW1TMTQ+FTL0a1AhYIf3P+2VSefNDabtg2PWdw06mA/tU zVdmBAyaUDeRnHkuuE53EvMjriJxkU+WPYORBIJraip7wgSOyh3fSy8gvzE/yMiacoah 0z7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=RP2whGHxY9E5x0G60FkplpO6Msu4rnrvVDst1YhxnH4=; b=vxAm13LoJH1oy31JhAz5jaNPO46tZO1hHBWBTi5WmtLWKgyjJsp2TXOQeFnDeZkHG/ 380oVZtuBfNpzbXLVoiroAAgazI3h+n9b0jeTMZRMbsapvS7Qm1LMeEnxJHKy0pKAmIm pLu6Z04+p9LnH3qraVcdc49AzDBkVByAyp+UlkSHN0c1Pdg8iitgC7CSGyXQ7t/sKKS/ ZNg8VqgA0aD32c32lO58BoAiGiawQLrzOoPVI6XrVwQkqPWeq+bdBJy2C/229XJ+Qohr j020bEAMf3WxttBSlhNG3nc9ondlQO7/XeIQa4zi4MsONitrq8y1+VqOr3TkimlgcvEV Nrgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="IjQBd/+y"; 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=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xf14-20020a17090731ce00b008d17b125784si46658640ejb.30.2023.03.30.02.54.39; Thu, 30 Mar 2023 02:55:04 -0700 (PDT) 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=@chromium.org header.s=google header.b="IjQBd/+y"; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230393AbjC3JqI (ORCPT <rfc822;rua109.linux@gmail.com> + 99 others); Thu, 30 Mar 2023 05:46:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbjC3Jpm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 30 Mar 2023 05:45:42 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AC078A52 for <linux-kernel@vger.kernel.org>; Thu, 30 Mar 2023 02:45:18 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id y4so74166353edo.2 for <linux-kernel@vger.kernel.org>; Thu, 30 Mar 2023 02:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1680169515; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RP2whGHxY9E5x0G60FkplpO6Msu4rnrvVDst1YhxnH4=; b=IjQBd/+yqDgfC6l8l+UQ4SJFT3mv4DXq/ugkc8lAzKIy9GkkF/9pE1Mh0myFCSFUvf AgvtdkStMT3ma/7pbgLI2yp6RMAjeUgIw65Sb/ItJhK5mO2KlA1iv5423UNNCP1uAmpQ 3fg4rgiYgRyj9PGIrJ6n28XC6bc5KgfMh70K8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680169515; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RP2whGHxY9E5x0G60FkplpO6Msu4rnrvVDst1YhxnH4=; b=us3CcyLMtQwvCuzUEbfHaBd2KFZzCPfF46KaEqS8I8YOAdvRUU/9QUZphWH+3cawNC 62CFN0pQFaNElHOs87+HN7QcIbpnsLw2Uze03LvJ8VdzNyINTSljrwpUpm5Ub3G/Rz/c LFprr534bP7qQ+C8/sQKSifA847po3M11XqwVK3ORrGyou0IGLzARbVSFEgJFnfdRpbh /Z3SJtALZ0xVdnqOTUZ9WDOnlIl22OpNtGssJG6I6HkQPJzQ2wjym/EYQIMsP0Q+JRPY lQUeUdqcPQdZ9V2RkdbwE2g7+PEiIdEO/FwyebkKwc3q/RJajW6WqXkPdGwOgbfQJNpS cItw== X-Gm-Message-State: AAQBX9frIv02r36U8EVwxa8nPZl6h/w2NOy/2fsnELK8MrK+LdjOzr6v 6PCKxqEYMydTAkEO93cXlvCtiQ== X-Received: by 2002:a17:906:8392:b0:92c:5f1:8288 with SMTP id p18-20020a170906839200b0092c05f18288mr24186052ejx.13.1680169515396; Thu, 30 Mar 2023 02:45:15 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:1396:ff5d:6e2a:df6d]) by smtp.gmail.com with ESMTPSA id k9-20020a17090666c900b0092b606cb803sm17683616ejp.140.2023.03.30.02.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 02:45:15 -0700 (PDT) From: Ricardo Ribalda <ribalda@chromium.org> Date: Thu, 30 Mar 2023 11:44:48 +0200 Subject: [PATCH v5 2/2] x86/purgatory: Add linker script MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230321-kexec_clang16-v5-2-5563bf7c4173@chromium.org> References: <20230321-kexec_clang16-v5-0-5563bf7c4173@chromium.org> In-Reply-To: <20230321-kexec_clang16-v5-0-5563bf7c4173@chromium.org> To: Eric Biederman <ebiederm@xmission.com> Cc: Baoquan He <bhe@redhat.com>, Philipp Rudo <prudo@redhat.com>, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Ross Zwisler <zwisler@google.com>, Steven Rostedt <rostedt@goodmis.org>, Simon Horman <horms@kernel.org>, Ricardo Ribalda <ribalda@chromium.org> X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4042; i=ribalda@chromium.org; h=from:subject:message-id; bh=sl6K1VSwL+1LyYrdz/oxSd3LOsvL2UCVP6pzeLWPy1Q=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBkJVok98RKwyzQtMEXTvDv5OfJerWqnGMS2NKs2 DJr6RojE4+JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCZCVaJAAKCRDRN9E+zzrE iHOqD/4szxWo11qcXn44Q+uzXQtETg3pZ52c8iQ3lFFyc+7YegOCvOXUXAkZv+wSL4uHyJRNzJT nSiJeEc29WUlnRoTBrW2VEwG2ojXcrfo92B7FJTR8putcifU63Dby0pWa2r/JdlYEdEC8H+dMnk ds2lqGOx6O/KEkprhp90mAzm1/SmsImuOcLF1IOT0tQwHT/8ESuTuXfsbpodSFtgM/IHEA6BWoW 8jPhxkxvACuZxbEvp3j65I+VIUAjbd7zIodTy+cSv2+/JLPDRVE9Lq5g2NNg1gGLQS7E7tbxWLD lED6W0GuMSqOrQyzt71I5v62Z3qmeEUweOwr5dRWl/sePzuD7sDzSvU434mbT46UaZXnsvTZIl5 vmNXhHLgqy2nQRDKMzyDV7MO7FXloVzIuvM6c+oEkrJ0EDxDC+b9PAmYbkHmMNMmuViLY/cysvz hgP38Z4fDMZGlBZZibGLWOHR65aXPHKNuE2pxgQ3juv7zhyiyBoS4zBQUMz37jgmZXRAOH3zVnB BU7l8TMuegLfJL8N2kW53iSp9vOTfLrS1fvKYtrqKiNykUUFM4S+6dH0nClgc0HoCGawEGa4+rb H50Yv5+iQssPhEbNs6Dg14f+dmwfzCVauUcYBO097k6eLUrSd9TajkZGetSul9+gxGK07KvCVZh rmjrfJTxyjszHWw== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761786047102076582?= X-GMAIL-MSGID: =?utf-8?q?1761786047102076582?= |
Series |
kexec: Fix kexec_file_load for llvm16
|
|
Commit Message
Ricardo Ribalda
March 30, 2023, 9:44 a.m. UTC
Make sure that the .text section is not divided in multiple overlapping
sections. This is not supported by kexec_file.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
arch/x86/purgatory/.gitignore | 2 ++
arch/x86/purgatory/Makefile | 20 +++++++++----
arch/x86/purgatory/kexec-purgatory.S | 2 +-
arch/x86/purgatory/purgatory.lds.S | 57 ++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 7 deletions(-)
Comments
Hmm, this patch may need some more eyes. At least from the x86 maintainers. -- Steve On Thu, 30 Mar 2023 11:44:48 +0200 Ricardo Ribalda <ribalda@chromium.org> wrote: > Make sure that the .text section is not divided in multiple overlapping > sections. This is not supported by kexec_file. > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> > --- > arch/x86/purgatory/.gitignore | 2 ++ > arch/x86/purgatory/Makefile | 20 +++++++++---- > arch/x86/purgatory/kexec-purgatory.S | 2 +- > arch/x86/purgatory/purgatory.lds.S | 57 ++++++++++++++++++++++++++++++++++++ > 4 files changed, 74 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/purgatory/.gitignore b/arch/x86/purgatory/.gitignore > index d2be1500671d..1fe71fe5945d 100644 > --- a/arch/x86/purgatory/.gitignore > +++ b/arch/x86/purgatory/.gitignore > @@ -1 +1,3 @@ > purgatory.chk > +purgatory.lds > +purgatory > diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile > index 17f09dc26381..4dc96d409bec 100644 > --- a/arch/x86/purgatory/Makefile > +++ b/arch/x86/purgatory/Makefile > @@ -16,10 +16,11 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS > > # 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 > -LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS) > -LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS) > -targets += purgatory.ro purgatory.chk > +PURGATORY_LDFLAGS := -nostdlib -z nodefaultlib > +LDFLAGS_purgatory := -r $(PURGATORY_LDFLAGS) -T > +LDFLAGS_purgatory.chk := -e purgatory_start $(PURGATORY_LDFLAGS) > + > +targets += purgatory.lds purgatory.ro purgatory.chk > > # Sanitizer, etc. runtimes are unavailable and cannot be linked here. > GCOV_PROFILE := n > @@ -72,10 +73,17 @@ CFLAGS_string.o += $(PURGATORY_CFLAGS) > AFLAGS_REMOVE_setup-x86_$(BITS).o += -Wa,-gdwarf-2 > AFLAGS_REMOVE_entry64.o += -Wa,-gdwarf-2 > > -$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE > +OBJCOPYFLAGS_purgatory.ro := -O elf64-x86-64 > +OBJCOPYFLAGS_purgatory.ro += --remove-section='*debug*' > +OBJCOPYFLAGS_purgatory.ro += --remove-section='.comment' > +OBJCOPYFLAGS_purgatory.ro += --remove-section='.note.*' > +$(obj)/purgatory.ro: $(obj)/purgatory FORCE > + $(call if_changed,objcopy) > + > +$(obj)/purgatory.chk: $(obj)/purgatory FORCE > $(call if_changed,ld) > > -$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE > +$(obj)/purgatory: $(obj)/purgatory.lds $(PURGATORY_OBJS) FORCE > $(call if_changed,ld) > > $(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk > diff --git a/arch/x86/purgatory/kexec-purgatory.S b/arch/x86/purgatory/kexec-purgatory.S > index 8530fe93b718..54b0d0b4dc42 100644 > --- a/arch/x86/purgatory/kexec-purgatory.S > +++ b/arch/x86/purgatory/kexec-purgatory.S > @@ -5,7 +5,7 @@ > .align 8 > kexec_purgatory: > .globl kexec_purgatory > - .incbin "arch/x86/purgatory/purgatory.ro" > + .incbin "arch/x86/purgatory/purgatory" > .Lkexec_purgatory_end: > > .align 8 > diff --git a/arch/x86/purgatory/purgatory.lds.S b/arch/x86/purgatory/purgatory.lds.S > new file mode 100644 > index 000000000000..610da88aafa0 > --- /dev/null > +++ b/arch/x86/purgatory/purgatory.lds.S > @@ -0,0 +1,57 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#include <asm-generic/vmlinux.lds.h> > + > +OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) > + > +#undef i386 > + > +#include <asm/cache.h> > +#include <asm/page_types.h> > + > +ENTRY(purgatory_start) > + > +SECTIONS > +{ > + . = 0; > + .head.text : { > + _head = . ; > + HEAD_TEXT > + _ehead = . ; > + } > + .rodata : { > + _rodata = . ; > + *(.rodata) /* read-only data */ > + *(.rodata.*) > + _erodata = . ; > + } > + .text : { > + _text = .; /* Text */ > + *(.text) > + *(.text.*) > + *(.noinstr.text) > + _etext = . ; > + } > + .data : { > + _data = . ; > + *(.data) > + *(.data.*) > + *(.bss.efistub) > + _edata = . ; > + } > + . = ALIGN(L1_CACHE_BYTES); > + .bss : { > + _bss = . ; > + *(.bss) > + *(.bss.*) > + *(COMMON) > + . = ALIGN(8); /* For convenience during zeroing */ > + _ebss = .; > + } > + > + /* Sections to be discarded */ > + /DISCARD/ : { > + *(.eh_frame) > + *(*__ksymtab*) > + *(___kcrctab*) > + } > +} >
On Thu, Mar 30, 2023 at 11:15:23AM -0400, Steven Rostedt wrote: > > Make sure that the .text section is not divided in multiple overlapping > > sections. This is not supported by kexec_file. And? What is the failure scenario? Why are you fixing it? Why do we care? This is way too laconic.
On Thu, 30 Mar 2023 17:18:26 +0200 Borislav Petkov <bp@alien8.de> wrote: > On Thu, Mar 30, 2023 at 11:15:23AM -0400, Steven Rostedt wrote: > > > Make sure that the .text section is not divided in multiple overlapping > > > sections. This is not supported by kexec_file. > > And? > > What is the failure scenario? Why are you fixing it? Why do we care? > > This is way too laconic. > Yeah, I think the change log in patch 1 needs to be in this patch too, which gives better context. -- Steve
On Thu, Mar 30, 2023 at 11:31:27AM -0400, Steven Rostedt wrote: > On Thu, 30 Mar 2023 17:18:26 +0200 > Borislav Petkov <bp@alien8.de> wrote: > > > On Thu, Mar 30, 2023 at 11:15:23AM -0400, Steven Rostedt wrote: > > > > Make sure that the .text section is not divided in multiple overlapping > > > > sections. This is not supported by kexec_file. > > > > And? > > > > What is the failure scenario? Why are you fixing it? Why do we care? > > > > This is way too laconic. > > > > Yeah, I think the change log in patch 1 needs to be in this patch too, > which gives better context. Just read it. Why did it work with clang version < 16? + toolchains ML.
On Thu, Mar 30, 2023 at 3:45 AM Ricardo Ribalda <ribalda@chromium.org> wrote: > Make sure that the .text section is not divided in multiple overlapping > sections. This is not supported by kexec_file. How does this interact with patch #1 from this series, which IIUC allows us to handle the case where the .text section is split between .text and .text.hot? Do we still need that patch, but only for non-x86 platforms? Or do we need both, and this patch will need to be replicated for other arches?
Hi Ross On Fri, 31 Mar 2023 at 21:14, Ross Zwisler <zwisler@kernel.org> wrote: > > On Thu, Mar 30, 2023 at 3:45 AM Ricardo Ribalda <ribalda@chromium.org> wrote: > > Make sure that the .text section is not divided in multiple overlapping > > sections. This is not supported by kexec_file. > > How does this interact with patch #1 from this series, which IIUC > allows us to handle the case where the .text section is split between > .text and .text.hot? Do we still need that patch, but only for > non-x86 platforms? Or do we need both, and this patch will need to be > replicated for other arches? Patch 1/2 is a must. Patch 2/2 is a nice_to_have and would be great to have a similar patch for every arch... but I do not feel confident enough to send it for every arch :) If we have linker scripts for all the arches do we need 1/2? I think so, because the user might want to load a kernel <6.4 built with clang > 16. Regards!
Hi Ricardo, Thanks for the patch! Please make sure to cc our mailing list <llvm@lists.linux.dev> for llvm specific issues. scripts/get_maintainer.pl should recommend it, or you can find it from clangbuiltlinux.github.io. You can also ping me internally for toolchain related issues. Start of thread. https://lore.kernel.org/lkml/20230321-kexec_clang16-v5-0-5563bf7c4173@chromium.org/ On Thu, Mar 30, 2023 at 9:00 AM Borislav Petkov <bp@alien8.de> wrote: > > On Thu, Mar 30, 2023 at 11:31:27AM -0400, Steven Rostedt wrote: > > On Thu, 30 Mar 2023 17:18:26 +0200 > > Borislav Petkov <bp@alien8.de> wrote: > > > > > On Thu, Mar 30, 2023 at 11:15:23AM -0400, Steven Rostedt wrote: > > > > > Make sure that the .text section is not divided in multiple overlapping > > > > > sections. This is not supported by kexec_file. Perhaps this is related to CrOS' use of AutoFDO creating .text.hot? If so, it's probably more straightforward to straight up disable PGO for kexec. See also: commit bde971a83bbf ("KVM: arm64: nvhe: Fix build with profile optimization") > > > > > > And? > > > > > > What is the failure scenario? Why are you fixing it? Why do we care? > > > > > > This is way too laconic. > > > > > > > Yeah, I think the change log in patch 1 needs to be in this patch too, > > which gives better context. > > Just read it. > > Why did it work with clang version < 16? I'll bet if we bisect llvm, we can spot what might have changed, which may give us a clue on how to get the old behavior back; maybe without the need for a linker script. Ricardo, how did you verify that your fix was correct? Surely we can check using command line utilities without needing a full blown kexec setup? If you can share more info, I can bisect llvm quickly. If it requires profile data, you'll need to share it, since CrOS engineers still have not posted public documentation on AutoFDO as I have repeatedly asked for. > > + toolchains ML. > > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette
Hi Nick On Sat, 8 Apr 2023 at 01:22, Nick Desaulniers <ndesaulniers@google.com> wrote: > > Hi Ricardo, > Thanks for the patch! Please make sure to cc our mailing list > <llvm@lists.linux.dev> for llvm specific issues. > scripts/get_maintainer.pl should recommend it, or you can find it from > clangbuiltlinux.github.io. You can also ping me internally for > toolchain related issues. > > Start of thread. > https://lore.kernel.org/lkml/20230321-kexec_clang16-v5-0-5563bf7c4173@chromium.org/ > > On Thu, Mar 30, 2023 at 9:00 AM Borislav Petkov <bp@alien8.de> wrote: > > > > On Thu, Mar 30, 2023 at 11:31:27AM -0400, Steven Rostedt wrote: > > > On Thu, 30 Mar 2023 17:18:26 +0200 > > > Borislav Petkov <bp@alien8.de> wrote: > > > > > > > On Thu, Mar 30, 2023 at 11:15:23AM -0400, Steven Rostedt wrote: > > > > > > Make sure that the .text section is not divided in multiple overlapping > > > > > > sections. This is not supported by kexec_file. > > Perhaps this is related to CrOS' use of AutoFDO creating .text.hot? > If so, it's probably more straightforward to straight up disable PGO > for kexec. See also: > > commit bde971a83bbf ("KVM: arm64: nvhe: Fix build with profile optimization") It was indeed due to the AutoFDO, adding KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, $(KBUILD_CFLAGS)) to arch/x86/purgatory/Makefile It is definitely simpler than adding a linker script, but I am not sure if it is the correct way to fix this... Seems like splitting .text in multiple sections is an implementation detail of the compiler and the only way to force it is with a linker script... Or am I missing something? Shall I send a new version with the KBUILD_CFLAGS ? Thanks! > > > > > > > > > And? > > > > > > > > What is the failure scenario? Why are you fixing it? Why do we care? > > > > > > > > This is way too laconic. > > > > > > > > > > Yeah, I think the change log in patch 1 needs to be in this patch too, > > > which gives better context. > > > > Just read it. > > > > Why did it work with clang version < 16? > > I'll bet if we bisect llvm, we can spot what might have changed, which > may give us a clue on how to get the old behavior back; maybe without > the need for a linker script. > > Ricardo, how did you verify that your fix was correct? Surely we can > check using command line utilities without needing a full blown kexec > setup? If you can share more info, I can bisect llvm quickly. If it > requires profile data, you'll need to share it, since CrOS engineers > still have not posted public documentation on AutoFDO as I have > repeatedly asked for. The simplest test is to run: $readelf -S arch/x86/purgatory/purgatory.ro | grep "] \.text" [ 3] .text PROGBITS 0000000000000000 000002a0 If there is only one .text section then that kernel will be load properly via kexec_file(). > > > > > + toolchains ML. > > > > -- > > Regards/Gruss, > > Boris. > > > > https://people.kernel.org/tglx/notes-about-netiquette > > > > -- > Thanks, > ~Nick Desaulniers -- Ricardo Ribalda
On Tue, Apr 11, 2023 at 2:46 PM Ricardo Ribalda <ribalda@chromium.org> wrote: > > Hi Nick > > On Sat, 8 Apr 2023 at 01:22, Nick Desaulniers <ndesaulniers@google.com> wrote: > > > > Hi Ricardo, > > Thanks for the patch! Please make sure to cc our mailing list > > <llvm@lists.linux.dev> for llvm specific issues. > > scripts/get_maintainer.pl should recommend it, or you can find it from > > clangbuiltlinux.github.io. You can also ping me internally for > > toolchain related issues. > > > > Start of thread. > > https://lore.kernel.org/lkml/20230321-kexec_clang16-v5-0-5563bf7c4173@chromium.org/ > > > > On Thu, Mar 30, 2023 at 9:00 AM Borislav Petkov <bp@alien8.de> wrote: > > > > > > On Thu, Mar 30, 2023 at 11:31:27AM -0400, Steven Rostedt wrote: > > > > On Thu, 30 Mar 2023 17:18:26 +0200 > > > > Borislav Petkov <bp@alien8.de> wrote: > > > > > > > > > On Thu, Mar 30, 2023 at 11:15:23AM -0400, Steven Rostedt wrote: > > > > > > > Make sure that the .text section is not divided in multiple overlapping > > > > > > > sections. This is not supported by kexec_file. > > > > Perhaps this is related to CrOS' use of AutoFDO creating .text.hot? > > If so, it's probably more straightforward to straight up disable PGO > > for kexec. See also: > > > > commit bde971a83bbf ("KVM: arm64: nvhe: Fix build with profile optimization") > > It was indeed due to the AutoFDO, adding > > KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, > $(KBUILD_CFLAGS)) > > to arch/x86/purgatory/Makefile > > It is definitely simpler than adding a linker script, but I am not > sure if it is the correct way to fix this... Seems like splitting > .text in multiple sections is an implementation detail of the compiler > and the only way to force it is with a linker script... Or am I > missing something? I think with the use of `unlikely` GCC will put code in .text.cold, so it is possible to trigger this using simpler means, but... > > Shall I send a new version with the KBUILD_CFLAGS ? I still think the cflags approach is way simpler. If someone tries to use unlikely in purgatory: "don't do that." Same for PGO. > > Thanks! > > > > > > > > > > > > > And? > > > > > > > > > > What is the failure scenario? Why are you fixing it? Why do we care? > > > > > > > > > > This is way too laconic. > > > > > > > > > > > > > Yeah, I think the change log in patch 1 needs to be in this patch too, > > > > which gives better context. > > > > > > Just read it. > > > > > > Why did it work with clang version < 16? > > > > I'll bet if we bisect llvm, we can spot what might have changed, which > > may give us a clue on how to get the old behavior back; maybe without > > the need for a linker script. > > > > Ricardo, how did you verify that your fix was correct? Surely we can > > check using command line utilities without needing a full blown kexec > > setup? If you can share more info, I can bisect llvm quickly. If it > > requires profile data, you'll need to share it, since CrOS engineers > > still have not posted public documentation on AutoFDO as I have > > repeatedly asked for. > > The simplest test is to run: > > $readelf -S arch/x86/purgatory/purgatory.ro | grep "] \.text" > [ 3] .text PROGBITS 0000000000000000 000002a0 > > If there is only one .text section then that kernel will be load > properly via kexec_file(). Got it, profile data will be required to reproduce then. If you can share.
diff --git a/arch/x86/purgatory/.gitignore b/arch/x86/purgatory/.gitignore index d2be1500671d..1fe71fe5945d 100644 --- a/arch/x86/purgatory/.gitignore +++ b/arch/x86/purgatory/.gitignore @@ -1 +1,3 @@ purgatory.chk +purgatory.lds +purgatory diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 17f09dc26381..4dc96d409bec 100644 --- a/arch/x86/purgatory/Makefile +++ b/arch/x86/purgatory/Makefile @@ -16,10 +16,11 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS # 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 -LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS) -LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS) -targets += purgatory.ro purgatory.chk +PURGATORY_LDFLAGS := -nostdlib -z nodefaultlib +LDFLAGS_purgatory := -r $(PURGATORY_LDFLAGS) -T +LDFLAGS_purgatory.chk := -e purgatory_start $(PURGATORY_LDFLAGS) + +targets += purgatory.lds purgatory.ro purgatory.chk # Sanitizer, etc. runtimes are unavailable and cannot be linked here. GCOV_PROFILE := n @@ -72,10 +73,17 @@ CFLAGS_string.o += $(PURGATORY_CFLAGS) AFLAGS_REMOVE_setup-x86_$(BITS).o += -Wa,-gdwarf-2 AFLAGS_REMOVE_entry64.o += -Wa,-gdwarf-2 -$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE +OBJCOPYFLAGS_purgatory.ro := -O elf64-x86-64 +OBJCOPYFLAGS_purgatory.ro += --remove-section='*debug*' +OBJCOPYFLAGS_purgatory.ro += --remove-section='.comment' +OBJCOPYFLAGS_purgatory.ro += --remove-section='.note.*' +$(obj)/purgatory.ro: $(obj)/purgatory FORCE + $(call if_changed,objcopy) + +$(obj)/purgatory.chk: $(obj)/purgatory FORCE $(call if_changed,ld) -$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE +$(obj)/purgatory: $(obj)/purgatory.lds $(PURGATORY_OBJS) FORCE $(call if_changed,ld) $(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk diff --git a/arch/x86/purgatory/kexec-purgatory.S b/arch/x86/purgatory/kexec-purgatory.S index 8530fe93b718..54b0d0b4dc42 100644 --- a/arch/x86/purgatory/kexec-purgatory.S +++ b/arch/x86/purgatory/kexec-purgatory.S @@ -5,7 +5,7 @@ .align 8 kexec_purgatory: .globl kexec_purgatory - .incbin "arch/x86/purgatory/purgatory.ro" + .incbin "arch/x86/purgatory/purgatory" .Lkexec_purgatory_end: .align 8 diff --git a/arch/x86/purgatory/purgatory.lds.S b/arch/x86/purgatory/purgatory.lds.S new file mode 100644 index 000000000000..610da88aafa0 --- /dev/null +++ b/arch/x86/purgatory/purgatory.lds.S @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <asm-generic/vmlinux.lds.h> + +OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) + +#undef i386 + +#include <asm/cache.h> +#include <asm/page_types.h> + +ENTRY(purgatory_start) + +SECTIONS +{ + . = 0; + .head.text : { + _head = . ; + HEAD_TEXT + _ehead = . ; + } + .rodata : { + _rodata = . ; + *(.rodata) /* read-only data */ + *(.rodata.*) + _erodata = . ; + } + .text : { + _text = .; /* Text */ + *(.text) + *(.text.*) + *(.noinstr.text) + _etext = . ; + } + .data : { + _data = . ; + *(.data) + *(.data.*) + *(.bss.efistub) + _edata = . ; + } + . = ALIGN(L1_CACHE_BYTES); + .bss : { + _bss = . ; + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN(8); /* For convenience during zeroing */ + _ebss = .; + } + + /* Sections to be discarded */ + /DISCARD/ : { + *(.eh_frame) + *(*__ksymtab*) + *(___kcrctab*) + } +}