From patchwork Mon Mar 27 15:06:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 75519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1590660vqo; Mon, 27 Mar 2023 08:21:17 -0700 (PDT) X-Google-Smtp-Source: AKy350ZxgmcCBtUsmd+V0Jj8np2ZZ7ojNPhcUs5LeS6r4wr1jCuBSXjja146AJIMZjWAAn+l+Wz+ X-Received: by 2002:a62:585:0:b0:5e0:a86:a76f with SMTP id 127-20020a620585000000b005e00a86a76fmr11503293pff.0.1679930477295; Mon, 27 Mar 2023 08:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679930477; cv=none; d=google.com; s=arc-20160816; b=0GBKTvh4bFt0N+ZHO/YRKmfzVctdaUJARxakToWTgm3/Gj/pFvLCjfYjHXuyCD8T7r rsEyPtVufsSoHIjRGo24/r3JYZAj94ZHGqe2/K/5uiOgggGx4Q6xijSa7Vd2bzr/z9Xt Pr3vQCd9kKeLfwrPS6DmpcvvH6ZywO18GaRh6uyw8beY9f9cXWinDKyzuF6ICUTdoUqO maVZNmiyQbTP9ORwwHpl3rtLZaWjVfxayAQ9jjdQBwG4GVPZ4E2mjREyS87nBMcxhbA9 mR8HmsE8qER7FhjybXCeGM6QL+K4Cnm3FVlhq3ro4TBQ0lQxZ5JqtKLmht9JhZEt92iM z9Bg== 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=D4LtynCWvRc0UC/GbC/kiRSwfX8IErgGFnov9fH0MI4=; b=tDKlcLoO61kJkSO413guCjABdJNN+XfUDiUJ0auInS7kLO7spR3XtC1Wd/+J368uF0 EK0nrCobEFA/N6qP8uBsSkXsqLFPdqoabIL/W1PdyHvtq4uo9LDDR9Uuvezsbdq3ihGw u42/CaYZVU+iTFNTxkY5bcVW8FBIVKxYvsdZSkXn/2eVyWyx7UDAyJn8qBIl3jU9StEi Vv1Pw2sNo/dZz71wLyJqTRHTfKfQykvQeDEpNLmSQk0WJ5REI9h6Gg8uAUWpWyLSjxAD h20un4g8m7NblRVJDva2qgCvLX07joshllVQ9BBbPvnDcCb6SvkXhUASE6y4cSTgUkYJ Lsxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SeR8XpvJ; 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 x37-20020a056a000be500b0062514cb8b77si24524069pfu.40.2023.03.27.08.21.04; Mon, 27 Mar 2023 08:21:17 -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=SeR8XpvJ; 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 S229733AbjC0PHR (ORCPT + 99 others); Mon, 27 Mar 2023 11:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbjC0PHK (ORCPT ); Mon, 27 Mar 2023 11:07:10 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A57D1FF5 for ; Mon, 27 Mar 2023 08:07:09 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id eg48so37411452edb.13 for ; Mon, 27 Mar 2023 08:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1679929627; 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=D4LtynCWvRc0UC/GbC/kiRSwfX8IErgGFnov9fH0MI4=; b=SeR8XpvJmFC7LdsZqO8PftPdO/WoEdoLnRyq0aSn9RvbLTOVIM0I+Uy/lTlIGFgZP0 QgZOH4KxGsX91xq39mn7GToV2aXvzURLfKScT12mKf8Ud7UUs21OTnHk1uM3pMAppgQh nMnbh2WoNeFYQK8A2bs/7k1d5yB+8KYm0cEP8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679929627; 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=D4LtynCWvRc0UC/GbC/kiRSwfX8IErgGFnov9fH0MI4=; b=WM/KdDyveFTVpxdD4njk+y1eSsnA3UVXK2XPU3FP2ZkTw3wkKi4aeKxcy87LNGmBoe Jl5FwuCOgUoNNBuJ6l5XGjbbwUaPDPq2YxYbmWTnuMm9Z2wtr6HoPB9UFNhFO+0GOlkq vzLbZBPzalopZMib2RsMCn5JMyfrEYO7CJ1sqNB9rH7q85ql/WwwJ6ipYxvLzUab5+md 0JhpcS4kQWCUJbr2Ul+aB6CiNPOE2YGR1dukIemOfmmRBN6o2JiSNN0V0symF+cIfKlL L8S7SPk43i/AZ6xpij9UxSQ7L9Q/ZWGSxgny+jr150jcVbp+j/mhj70T4EYyVK3cLvg8 Lt2A== X-Gm-Message-State: AAQBX9fqr4+2tScQ5aNerQLlg8+cHlc3u6j6CuNQT62Pl+SJFpAF7agd jtL79Rct93d9r1+DmRoprRi0RNDGa8v+5NDtNPJs9Q== X-Received: by 2002:aa7:c54f:0:b0:4fa:4bc4:a911 with SMTP id s15-20020aa7c54f000000b004fa4bc4a911mr12553566edr.13.1679929627312; Mon, 27 Mar 2023 08:07:07 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:ed3c:5e9e:b8e4:8695]) by smtp.gmail.com with ESMTPSA id t9-20020a50c249000000b005021d1ae6adsm5312428edf.28.2023.03.27.08.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 08:07:07 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 27 Mar 2023 17:06:53 +0200 Subject: [PATCH v4 1/2] kexec: Support purgatories with .text.hot sections MIME-Version: 1.0 Message-Id: <20230321-kexec_clang16-v4-1-1340518f98e9@chromium.org> References: <20230321-kexec_clang16-v4-0-1340518f98e9@chromium.org> In-Reply-To: <20230321-kexec_clang16-v4-0-1340518f98e9@chromium.org> To: Eric Biederman Cc: linux-kernel@vger.kernel.org, Baoquan He , stable@vger.kernel.org, Ross Zwisler , Ricardo Ribalda , Philipp Rudo , Steven Rostedt , kexec@lists.infradead.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2330; i=ribalda@chromium.org; h=from:subject:message-id; bh=Ei7yD2n0waFqw7CoS4vSLL1z8Jz5Bb9trLKry0qiinI=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBkIbEWxcy3B0iTPJoJZfWXxHifMkAgvOzFX4C1Aerk unaFyXiJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCZCGxFgAKCRDRN9E+zzrEiPlpD/ 4xdjzkJcT2YBJrKe5K8kUeZunIKRIaZcU1T0vmQaW/gAAnb5Q4nb7q5RN98Kjn7/hfW1GJqG4QmKlQ CHL5TS07IZKvJZJG3R7fgUO+4iEbugW051COhuGNppdWZBbSuqb4loquF5yBWNueEHDoTkAjN9RM4Z t1wWEzEGn5g8DCBC3ppMSBIDsLfA4htdBMsT1cmuxXTkcpundBPg30B0OJoMS3Gl+syPsjaoSPxLCU ldl68qHqp3daJmfAinSvIQMdcO7LRU5L/gH1vb169QVxFlyqBRMRDNG40qxUy+Sthro74tSunoDpwc HvYylBBLyDsBlPy+sJn5bH1NYVHfR4DDgqnAMA3mspPxd7C++A7tHNXwRPMCZh18tZ3ubPspRKQX0t menr++Tglz9sHfiYr5ODn7s7NNYkPl26+DBi8IGVh6TVLlRlEm9nYTb79xiyzQWR0FDQ8eMENitsyj PiQB4wkHjMPfQYJpV2QvyhseHaRpWxpbDT7xZ59QLLniImh+AjzrTMTWXA1za7N59SqZ4b0TzWhdB+ 4eqK5d8m9WPJ7aaFh35lyFudOKRlE7FWToHEsP/od/1Iych5C02gaXTPfhITIp7tlkVspW7j/2O0U/ euo8nzE58m4B7Q/xBSBg9EqfJD8MNV4BkZDq/JGR1om/3a84hAzqEsVaMCMQ== 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761534780350360396?= X-GMAIL-MSGID: =?utf-8?q?1761534780350360396?= Clang16 links the purgatory text in two sections: [ 1] .text PROGBITS 0000000000000000 00000040 00000000000011a1 0000000000000000 AX 0 0 16 [ 2] .rela.text RELA 0000000000000000 00003498 0000000000000648 0000000000000018 I 24 1 8 ... [17] .text.hot. PROGBITS 0000000000000000 00003220 000000000000020b 0000000000000000 AX 0 0 1 [18] .rela.text.hot. RELA 0000000000000000 00004428 0000000000000078 0000000000000018 I 24 17 8 And both of them have their range [sh_addr ... sh_addr+sh_size] on the area pointed by `e_entry`. This causes that image->start is calculated twice, once for .text and another time for .text.hot. The second calculation leaves image->start in a random location. Because of this, the system crashes inmediatly after: kexec_core: Starting new kernel Cc: stable@vger.kernel.org Reviewed-by: Ross Zwisler Signed-off-by: Ricardo Ribalda --- kernel/kexec_file.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f1a0e4e3fb5c..25a37d8f113a 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -901,10 +901,21 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, } offset = ALIGN(offset, align); + + /* + * Check if the segment contains the entry point, if so, + * calculate the value of image->start based on it. + * If the compiler has produced more than one .text sections + * (Eg: .text.hot), they are generally after the main .text + * section, and they shall not be used to calculate + * image->start. So do not re-calculate image->start if it + * is not set to the initial value. + */ if (sechdrs[i].sh_flags & SHF_EXECINSTR && pi->ehdr->e_entry >= sechdrs[i].sh_addr && pi->ehdr->e_entry < (sechdrs[i].sh_addr - + sechdrs[i].sh_size)) { + + sechdrs[i].sh_size) && + kbuf->image->start == pi->ehdr->e_entry) { kbuf->image->start -= sechdrs[i].sh_addr; kbuf->image->start += kbuf->mem + offset; } From patchwork Mon Mar 27 15:06:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 75518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1588916vqo; Mon, 27 Mar 2023 08:18:45 -0700 (PDT) X-Google-Smtp-Source: AKy350a9cZpvyUlaNv7/erhfT7IaN7NPCDFk5hzyofacCcavOMnG1E+IPcOLeO8JHftcdeZwEfoq X-Received: by 2002:a17:907:6c11:b0:92b:e1ff:be30 with SMTP id rl17-20020a1709076c1100b0092be1ffbe30mr12900366ejc.4.1679930325124; Mon, 27 Mar 2023 08:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679930325; cv=none; d=google.com; s=arc-20160816; b=clfkcP+vYAP9ZRmmr/2Vj8BHiJS6F6Y/mJg7vxHTN3jU0R6LNw+hlUlUeWY3to64f/ GbaYh62O7uO8Nz3zdJm0WuJ8kRRR9fgKVcXFNjpLh6kUXF8bOck/dThHo2xf8X2zegRR m6OeU1T4LX1GmdFmGirBWNMRsh46wEingu3J4aROpIxuI/L1X4V1H80lAPX9laMb7gWt ZNWYemuAm19zdf3TSsRwS1knPmVaIh6PDDTVlQybeBYIsCljGhkftMFHm1Ig2E7QUSa6 u6jkNKQzxQ86X4prp2r4wbXXHD7XFiKwvp6iv9OlS+t63aaWdF5oWpglKWngS7VNjHtB 37Xw== 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=4F21eaCjPlHPX0mt5BYCkFL5YU30FB5WE06H9+TgyGM=; b=EsDdK6l2yQSn19AQXt3g2xeasKsZCzaw0lLhRiYn6wDbuQwPWjtXRVRlDu7HjNLS7T FS9NhXGqoFwLApDCuOAwy3Ytcd/6pn+YwcXUW3zgCKyz0OcgzVTi329DsfU0dqSiTLRU V3/3bks7OdbDdbLaP5xNgcqTOhwdXYbqjrZCun0RJZExLOtNBRpEt30eH27N17NpUCcd /kKt2PVaCRHOX2qTPIoNdrq3zGb2P6abgzEPN7TVkOCmROujojuuLAXhCqBnYtesfvyt 94R7tzxrIpB1z7G8WGCpHk9Mlb77QNNv4yLCO4MMIeIGtDUJVCaSRk0z/XOd3Iz+PPfA 4b3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Nk8teTJS; 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 h18-20020a1709063c1200b0093c96e480d1si11378777ejg.437.2023.03.27.08.18.19; Mon, 27 Mar 2023 08:18:45 -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=Nk8teTJS; 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 S232440AbjC0PHU (ORCPT + 99 others); Mon, 27 Mar 2023 11:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232065AbjC0PHL (ORCPT ); Mon, 27 Mar 2023 11:07:11 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198B11B0 for ; Mon, 27 Mar 2023 08:07:10 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id b20so37595427edd.1 for ; Mon, 27 Mar 2023 08:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1679929628; 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=4F21eaCjPlHPX0mt5BYCkFL5YU30FB5WE06H9+TgyGM=; b=Nk8teTJSKpMvzOa2aMHyMoIsxBKdK0bqysKUKWgePW4/z76CuPzpsa2b9Svg7JXOua ls6++OZGzpLGm2yBZC1w3G/FdDMXQutiA7p/DqRBiiqQ/NHmLhrQa/wjG/GOZFyjuTWP eSkjeOLKdDPKy5v835waRLRiQO7MXqQqFQSfM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679929628; 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=4F21eaCjPlHPX0mt5BYCkFL5YU30FB5WE06H9+TgyGM=; b=pp/MNi4RDiUrJtlHcI8adZ8jJvbUYHp5W15HUibWlNgb33tbgkto/gF7pTVVwRIsIp 6prTcahDF8WT0ye78kIBq1+LAeWtK71d5P3jbuwNSFmR1M7uXkzAt8VB273wN//hunpN 8CBEBZjpNlOphQvURlhU6jE0pJLvSU6MVL8RNLlu3PjWe3n3tAzyF/+Zjn67Yj8pCHpD +4YtyAngd8kAHAh50cCFzvyGqJ+ISWJGjhVxkXTpSGxl1D168tK77mDa6+3dmoGytQCX +lGoIJ8x73febup3WlFHSxV5H2TVUOMPEgfnFVKgaDA2IcbG8p6Pd3u36AoryqSvEpf6 v2vA== X-Gm-Message-State: AAQBX9cg6YzuuBWXvndiuiyr6XmwfqC49Q8UyF1XKUsRKc3Pev8B0Wm6 AVq4J+hXKbpJytG0N38e+r4CqyR5ilLfJ9hoISHbIw== X-Received: by 2002:a05:6402:d3:b0:4fa:e1fd:5a30 with SMTP id i19-20020a05640200d300b004fae1fd5a30mr12303438edu.19.1679929628405; Mon, 27 Mar 2023 08:07:08 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:ed3c:5e9e:b8e4:8695]) by smtp.gmail.com with ESMTPSA id t9-20020a50c249000000b005021d1ae6adsm5312428edf.28.2023.03.27.08.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 08:07:08 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 27 Mar 2023 17:06:54 +0200 Subject: [PATCH v4 2/2] x86/purgatory: Add linker script MIME-Version: 1.0 Message-Id: <20230321-kexec_clang16-v4-2-1340518f98e9@chromium.org> References: <20230321-kexec_clang16-v4-0-1340518f98e9@chromium.org> In-Reply-To: <20230321-kexec_clang16-v4-0-1340518f98e9@chromium.org> To: Eric Biederman Cc: linux-kernel@vger.kernel.org, Baoquan He , stable@vger.kernel.org, Ross Zwisler , Ricardo Ribalda , Philipp Rudo , Steven Rostedt , kexec@lists.infradead.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=4062; i=ribalda@chromium.org; h=from:subject:message-id; bh=qY09zbcWDi4omI4cAAqSkSf1QXILb3VpDDT9kkUrd8k=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBkIbEXTTl0yvDRVdkTXHHm+0bOTv2j/hTT7auw+OrA crD/BLWJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCZCGxFwAKCRDRN9E+zzrEiAsbD/ 0UsWhT4KOuvSbykGED1lnG/+pTSa3Xp9DDzRODKaqq2yNEiujiz6N8UcEW7t5GEA1++UUUAZPD8MBd bqegVfBE1QvTudCz7SYGQ34tYg0NRZfYEJRi4GjJ8LWSH3aBVjTdRTOHVf3Ixv5iZXjA5CnD7gij80 CVs0m7tTmWtk/mISLzsXIYvDVvIumbQD9tevfwTFP1gk8TqZk7nE/LFzTyuiDwBzGWQuRFKeBJM7qQ lhCoPJcFrLahBfcmEKsbhcznykvHmhTRHFf5s0uRr7qVWANQd4l+a/2+XOSgEwwheY87nL5H2Z6fXY oc02JXg7tJtKn7W5uqnoyUfJWj5W7QiYwN9KDAdfVBUGaVYwEX75y8EMjdN4vhdgmCuHcMxoC/BQz8 fDl/PO8eCnDXEsg5z+is1bdMXSJ20JCU1GPgldC9eG2QR7kFXgOF5NOLg2ndjXwd5cVDB0aAuzxfAe FTJDe/5ecHdkjIrCSECROJSIAlKKu/5zGsJ0yaTs1aIr02aiU0y2UZQ9HCLdcXHf4erZBypIYNy+QE fOoXFDdNjXCWkQlhBsEsrgIhrSZWbvMjM3KJ9Vvb8q1Er0jFnuvOqclpT0mwW5gLbsvQv2+gPHPHdq M+FO5RVET3Muy4/a+4eTLUi8jn0UyioYEI4LV5esDnAGuRelODSlNgdM6ohQ== 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761534620875594195?= X-GMAIL-MSGID: =?utf-8?q?1761534620875594195?= 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 --- 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 + +OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) + +#undef i386 + +#include +#include + +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*) + } +}