From patchwork Wed Jul 26 09:53:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 13327787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A233BC001DE for ; Wed, 26 Jul 2023 09:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OOy83Up1jxoYIx6ynkn9gaHsCV69CdZ3a5Pzwfo6gz0=; b=cTzhYJpd+UNRSo iwfbkSlcgaAnQf4+VHC2oL6y3HqkX5wMY6bkQXYbpts4l5FTDhOufnLmzmY/pVUSB9kwEdBQmaIR1 55Qeaci4anQ9zlMn5h5SyfhnsP+0F0oabwNFX64eX+n5X6sXlQNZnlrYuAWI5jkr+UMWNVDb93A8a Q7eC93DzYaVM+wcOQamKL6O8/z409CtTWtm/JdC5Y3KPAHYP/EqLG5nsZ0OmPCxGN3LkmuyYBUrbp TgpdMXEbu7C2nHIUo4SWLr01p2Po3fH1JIED4dGZkJV+1uMCRiTNaOK+4X8gWJVIrfG4YvuekkmMv mzE32d3jwsI4LrDV7m0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qObEQ-009pFD-1u; Wed, 26 Jul 2023 09:54:58 +0000 Received: from [14.137.139.154] (helo=frasgout12.his.huawei.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qObEM-009pBp-2i; Wed, 26 Jul 2023 09:54:57 +0000 Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4R9pnT1p13z9v7cY; Wed, 26 Jul 2023 17:41:33 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.81.211.226]) by APP1 (Coremail) with SMTP id LxC2BwBHo95C7cBk+WYTBQ--.33492S3; Wed, 26 Jul 2023 10:54:32 +0100 (CET) From: Petr Tesarik To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Li Huafei , Liao Chang , Masahiro Yamada , Kees Cook , Andrew Morton , Heiko Stuebner , Ricardo Ribalda , Alyssa Ross , Li Zhengyu , linux-riscv@lists.infradead.org (open list:RISC-V ARCHITECTURE), kexec@lists.infradead.org, linux-kernel@vger.kernel.org (open list) Cc: Torsten Duwe , Roberto Sassu , petr@tesarici.cz Subject: [PATCH v2 1/3] riscv/kexec: handle R_RISCV_CALL_PLT relocation type Date: Wed, 26 Jul 2023 11:53:59 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: LxC2BwBHo95C7cBk+WYTBQ--.33492S3 X-Coremail-Antispam: 1UD129KBjvJXoW7Cr47uw13tFW5WFWfZF4ruFg_yoW8WFy3pw 17Crn8KrWkGw1Sk3yagr48W348Ga1kurWaqa98GFW0qrsxXry0v3yvg3WUWF1jyrn5K3yS vFySgr1rZa15ArJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI 8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0x kIwI1lc7CjxVAaw2AFwI0_Jw0_GFylc7CjxVAKzI0EY4vE52x082I5MxAIw28IcxkI7VAK I48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7 xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xII jxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04 k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7Cj xVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUU-B_DUUUU X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_025455_164235_07C04636 X-CRM114-Status: UNSURE ( 8.43 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Torsten Duwe R_RISCV_CALL has been deprecated and replaced by R_RISCV_CALL_PLT. See Enum 18-19 in Table 3. Relocation types here: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc It was deprecated in ("Deprecated R_RISCV_CALL, prefer R_RISCV_CALL_PLT"): https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/a0dced85018d7a0ec17023c9389cbd70b1dbc1b0 Recent tools (at least GNU binutils-2.40) already use R_RISCV_CALL_PLT. Kernels built with such binutils fail kexec_load_file(2) with: kexec_image: Unknown rela relocation: 19 kexec_image: Error loading purgatory ret=-8 The binary code at the call site remains the same, so tell arch_kexec_apply_relocations_add() to handle _PLT alike. Fixes: 838b3e28488f ("RISC-V: Load purgatory in kexec_file") Signed-off-by: Torsten Duwe Signed-off-by: Petr Tesarik Cc: Li Zhengyu Cc: stable@vger.kernel.org Reviewed-by: Conor Dooley --- arch/riscv/kernel/elf_kexec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c index 5372b708fae2..38390d3bdcac 100644 --- a/arch/riscv/kernel/elf_kexec.c +++ b/arch/riscv/kernel/elf_kexec.c @@ -425,6 +425,7 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi, * sym, instead of searching the whole relsec. */ case R_RISCV_PCREL_HI20: + case R_RISCV_CALL_PLT: case R_RISCV_CALL: *(u64 *)loc = CLEAN_IMM(UITYPE, *(u64 *)loc) | ENCODE_UJTYPE_IMM(val - addr); From patchwork Wed Jul 26 09:54:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 13327788 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5B70C001DE for ; Wed, 26 Jul 2023 09:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/u5YN7Cgufdo0Yo5y1LeAKpXYbnzNBbr5LF8D+2K6zM=; b=zAzlX4S4drPskD plNnd7C/SBwr3CQSbyQSknk6Er9+5MSvqVVYReYa+6BZHJLuZwRwMn23BtkY5SpWspSbYve7tpq9Q 1PGeMjHb4G34ounpYxlRczpEo7iVPN2jL7UpIqzFsehNnLjlyniI+MCLGJC7gm7X9nC1fHxArTk/q 9EvEUxZOaLCEnGCtVX5tlXdAWWKb/9Z4tQRaq9FloYjKdQ6ux1AE7PeNUd08UqzL1duIKbewR5Ida /zzGFbUSN2Avip4ihLfQu6RMWclHjPQ2YQ6oyvdcGgInMJGuRf9WqZuJRWX+Gfy8e0TTZjAzHzbxS Uzd8e4jFOdE82ZO4gQYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qObEZ-009pLI-17; Wed, 26 Jul 2023 09:55:07 +0000 Received: from [14.137.139.154] (helo=frasgout12.his.huawei.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qObES-009pFw-32; Wed, 26 Jul 2023 09:55:02 +0000 Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4R9png08yTz9xFZZ; Wed, 26 Jul 2023 17:41:43 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.81.211.226]) by APP1 (Coremail) with SMTP id LxC2BwBHo95C7cBk+WYTBQ--.33492S4; Wed, 26 Jul 2023 10:54:43 +0100 (CET) From: Petr Tesarik To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Li Huafei , Liao Chang , Masahiro Yamada , Kees Cook , Andrew Morton , Heiko Stuebner , Ricardo Ribalda , Alyssa Ross , Li Zhengyu , linux-riscv@lists.infradead.org (open list:RISC-V ARCHITECTURE), kexec@lists.infradead.org, linux-kernel@vger.kernel.org (open list) Cc: Torsten Duwe , Roberto Sassu , petr@tesarici.cz Subject: [PATCH v2 2/3] riscv/purgatory: do not link with string.o and its dependencies Date: Wed, 26 Jul 2023 11:54:00 +0200 Message-Id: <2832b3e5ac781a0c0ade9d77b15a80e7f2fb4ab2.1690365011.git.petr.tesarik.ext@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: LxC2BwBHo95C7cBk+WYTBQ--.33492S4 X-Coremail-Antispam: 1UD129KBjvJXoWxAF47uFy3CF13tF15tr43Jrb_yoWrWF1fpa yxG34kK3yUAwn7Krn2y3WUWw45AayUKryFgF4j93y5CF45AF9Ikr93W3yqyFyUJryIk348 CryFgFy5ta1FkwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI 8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0x kIwI1lc7CjxVAaw2AFwI0_Jw0_GFylc7CjxVAKzI0EY4vE52x082I5MxAIw28IcxkI7VAK I48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7 xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xII jxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04 k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7Cj xVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUnxhLUUUUU X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_025501_260038_DD76D0AD X-CRM114-Status: GOOD ( 12.72 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Petr Tesarik Linking with this object file makes kexec_file_load(2) fail because of multiple unknown relocation types: - R_RISCV_ADD16, R_RISCV_SUB16: used by alternatives in strcmp() - R_RISCV_GOT_HI20: used to resolve _ctype in strcasecmp() All this hassle is needed for one single call to memcmp() from verify_sha256_digest() to compare 32 bytes of SHA256 checksum. Simply replace this memcmp() call with an explicit loop over those 32 bytes and remove the need to link with string.o and all the other object files that provide undefined symbols from that object file. Fixes: 838b3e28488f ("RISC-V: Load purgatory in kexec_file") Signed-off-by: Petr Tesarik Cc: Li Zhengyu Cc: stable@vger.kernel.org Acked-by: Conor Dooley --- arch/riscv/purgatory/Makefile | 26 +------------------------- arch/riscv/purgatory/purgatory.c | 6 ++++-- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/arch/riscv/purgatory/Makefile b/arch/riscv/purgatory/Makefile index dc20e166983e..00f50cd29310 100644 --- a/arch/riscv/purgatory/Makefile +++ b/arch/riscv/purgatory/Makefile @@ -1,39 +1,21 @@ # SPDX-License-Identifier: GPL-2.0 OBJECT_FILES_NON_STANDARD := y -purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o -purgatory-y += strcmp.o strlen.o strncmp.o +purgatory-y := purgatory.o sha256.o entry.o memcpy.o memset.o targets += $(purgatory-y) PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) -$(obj)/string.o: $(srctree)/lib/string.c FORCE - $(call if_changed_rule,cc_o_c) - -$(obj)/ctype.o: $(srctree)/lib/ctype.c FORCE - $(call if_changed_rule,cc_o_c) - $(obj)/memcpy.o: $(srctree)/arch/riscv/lib/memcpy.S FORCE $(call if_changed_rule,as_o_S) $(obj)/memset.o: $(srctree)/arch/riscv/lib/memset.S FORCE $(call if_changed_rule,as_o_S) -$(obj)/strcmp.o: $(srctree)/arch/riscv/lib/strcmp.S FORCE - $(call if_changed_rule,as_o_S) - -$(obj)/strlen.o: $(srctree)/arch/riscv/lib/strlen.S FORCE - $(call if_changed_rule,as_o_S) - -$(obj)/strncmp.o: $(srctree)/arch/riscv/lib/strncmp.S FORCE - $(call if_changed_rule,as_o_S) - $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE $(call if_changed_rule,cc_o_c) CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY -CFLAGS_string.o := -D__DISABLE_EXPORTS -CFLAGS_ctype.o := -D__DISABLE_EXPORTS # When profile-guided optimization is enabled, llvm emits two different # overlapping text sections, which is not supported by kexec. Remove profile @@ -83,12 +65,6 @@ CFLAGS_purgatory.o += $(PURGATORY_CFLAGS) CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) CFLAGS_sha256.o += $(PURGATORY_CFLAGS) -CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) -CFLAGS_string.o += $(PURGATORY_CFLAGS) - -CFLAGS_REMOVE_ctype.o += $(PURGATORY_CFLAGS_REMOVE) -CFLAGS_ctype.o += $(PURGATORY_CFLAGS) - asflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x)) $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE diff --git a/arch/riscv/purgatory/purgatory.c b/arch/riscv/purgatory/purgatory.c index 80596ab5fb62..1d30103d2047 100644 --- a/arch/riscv/purgatory/purgatory.c +++ b/arch/riscv/purgatory/purgatory.c @@ -22,14 +22,16 @@ static int verify_sha256_digest(void) struct kexec_sha_region *ptr, *end; struct sha256_state ss; u8 digest[SHA256_DIGEST_SIZE]; + int i; sha256_init(&ss); end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions); for (ptr = purgatory_sha_regions; ptr < end; ptr++) sha256_update(&ss, (uint8_t *)(ptr->start), ptr->len); sha256_final(&ss, digest); - if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)) != 0) - return 1; + for (i = 0; i < SHA256_DIGEST_SIZE; ++i) + if (digest[i] != purgatory_sha256_digest[i]) + return 1; return 0; } From patchwork Wed Jul 26 09:54:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 13327789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79959C001DE for ; Wed, 26 Jul 2023 09:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0Aix5rItSojwdDVL0tUcnUEtw5s2+bFdcHwkwGrwe9E=; b=Zllg8uSGeAukTv TFwE8wQqo8f/o3I07Y9Nlu4wnAyxD3w4M/Ir6rVqITH5WV08uNc017avOWxK1x8M+Slsh6BjNqusq m8fMRxfptcU+IYV6NoJp6TTDqiTFVByW0UN0YF1rMUEyxf12iF+dKxufgzvRFFxQHJd5SzlpJmvNX QZysX2tyPcX3vOM4kWbKLl0UglveuNBk/nVUJ3Y98soaAif6ROlsbojTWmBlQDqjyf66kNlnROP4d sylX8BXcHPWkC+gsNa7miJTEun7672G+ckEioR9BkecUAq4tWsId03YqJpjxbju4h7SG2xEEwtIJ4 cruwgRXzxb4Z+21uOZOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qObEh-009pQD-0h; Wed, 26 Jul 2023 09:55:15 +0000 Received: from [14.137.139.154] (helo=frasgout12.his.huawei.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qObEc-009pMv-2n; Wed, 26 Jul 2023 09:55:12 +0000 Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4R9pnr6DVKz9v7cX; Wed, 26 Jul 2023 17:41:52 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.81.211.226]) by APP1 (Coremail) with SMTP id LxC2BwBHo95C7cBk+WYTBQ--.33492S5; Wed, 26 Jul 2023 10:54:52 +0100 (CET) From: Petr Tesarik To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Li Huafei , Liao Chang , Masahiro Yamada , Kees Cook , Andrew Morton , Heiko Stuebner , Ricardo Ribalda , Alyssa Ross , Li Zhengyu , linux-riscv@lists.infradead.org (open list:RISC-V ARCHITECTURE), kexec@lists.infradead.org, linux-kernel@vger.kernel.org (open list) Cc: Torsten Duwe , Roberto Sassu , petr@tesarici.cz Subject: [PATCH v2 3/3] riscv/kexec: load initrd high in available memory Date: Wed, 26 Jul 2023 11:54:01 +0200 Message-Id: <67c8eb9eea25717c2c8208d9bfbfaa39e6e2a1c6.1690365011.git.petr.tesarik.ext@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: LxC2BwBHo95C7cBk+WYTBQ--.33492S5 X-Coremail-Antispam: 1UD129KBjvJXoWxJr13KrWrXFWfuw4kArW7XFb_yoW8Gr1Dpw sxCF4UGrWUuwsrC34j93Wxua48Aa95Wr1aga1DCayrJrs8XrW5Z3yqq342vF4vkr1agF9Y vFyY9r1S93WkA3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQq14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxkF7I0En4kS14v26r1q6r43MxkF7I0Ew4C26cxK6c8Ij28IcwCF04k20xvY0x0E wIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E74 80Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0 I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42 xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF 7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUjmFAJUUUUU== X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_025511_185973_0A65B4BF X-CRM114-Status: GOOD ( 13.02 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Torsten Duwe When initrd is loaded low, the secondary kernel fails like this: INITRD: 0xdc581000+0x00eef000 overlaps in-use memory region This initrd load address corresponds to the _end symbol, but the reservation is aligned on PMD_SIZE, as explained by a comment in setup_bootmem(). It is technically possible to align the initrd load address accordingly, leaving a hole between the end of kernel and the initrd, but it is much simpler to allocate the initrd top-down. Fixes: 838b3e28488f ("RISC-V: Load purgatory in kexec_file") Signed-off-by: Torsten Duwe Signed-off-by: Petr Tesarik Cc: stable@vger.kernel.org Reviewed-by: Conor Dooley --- arch/riscv/kernel/elf_kexec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c index 38390d3bdcac..c08bb5c3b385 100644 --- a/arch/riscv/kernel/elf_kexec.c +++ b/arch/riscv/kernel/elf_kexec.c @@ -281,7 +281,7 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf, kbuf.buffer = initrd; kbuf.bufsz = kbuf.memsz = initrd_len; kbuf.buf_align = PAGE_SIZE; - kbuf.top_down = false; + kbuf.top_down = true; kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; ret = kexec_add_buffer(&kbuf); if (ret)