From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43C851BBBC6; Mon, 14 Oct 2024 15:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728919787; cv=none; b=raHi2go8LpJCivLFZYWlho97gE18gIuYXyjQPMnYPnjGmZT2xkHu2llrCBwc0aQAkSMXgBsd6zJOS2tmVzSz3GrCyf6dQXMggJGLCA6IZPb0EOwc3kgTbad/vr2yrdMXfFaOyiakIlz/QtLUHE9sXMiI709d3wYCBXaWgr6hQ8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728919787; c=relaxed/simple; bh=tbWXi7V7jHmQi6a8+pEBJiAp0zSdCWcumXja8D8mKMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m6qjIzpKA7Ud4eEAg3DSS99d28CVTyDKbfO2L+j4hFH2dvV5Uy0Vmcz0f7eI93SGIzYrtvZdt0Co4+KM/EvEDRnneuuBa1F0ic2d59p4M4K1sYKCkF48ZCK+kxRpYvheaqleNstQeVGYPyEvbE89muZ3eY2AFMx7gd68eve434Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0xsvKeNH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="0xsvKeNH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68363C4CEC3; Mon, 14 Oct 2024 15:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728919786; bh=tbWXi7V7jHmQi6a8+pEBJiAp0zSdCWcumXja8D8mKMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0xsvKeNH90v1sPj3fQPMowKQrwromKpIzVrT3FYvvzWoeLKphexPMvxOkC2RZlFfy oAn1WbCz3gDgofmk+1toALs4xb9ai1VO2EGZamukIinI+a5M2ZOwk25zvDOgEVYfq6 T7Eyh3Ayv7JDkHb+Q4CJjq+xyn2O5X9GpKyuDt3I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Petr Tesarik , Ying Sun , Andrew Jones , Palmer Dabbelt , Sasha Levin Subject: [PATCH 6.1 707/798] riscv/kexec_file: Fix relocation type R_RISCV_ADD16 and R_RISCV_SUB16 unknown Date: Mon, 14 Oct 2024 16:21:01 +0200 Message-ID: <20241014141245.844833607@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241014141217.941104064@linuxfoundation.org> References: <20241014141217.941104064@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ying Sun [ Upstream commit c6ebf2c528470a09be77d0d9df2c6617ea037ac5 ] Runs on the kernel with CONFIG_RISCV_ALTERNATIVE enabled: kexec -sl vmlinux Error: kexec_image: Unknown rela relocation: 34 kexec_image: Error loading purgatory ret=-8 and kexec_image: Unknown rela relocation: 38 kexec_image: Error loading purgatory ret=-8 The purgatory code uses the 16-bit addition and subtraction relocation type, but not handled, resulting in kexec_file_load failure. So add handle to arch_kexec_apply_relocations_add(). Tested on RISC-V64 Qemu-virt, issue fixed. Co-developed-by: Petr Tesarik Signed-off-by: Petr Tesarik Signed-off-by: Ying Sun Reviewed-by: Andrew Jones Link: https://lore.kernel.org/r/20240711083236.2859632-1-sunying@isrc.iscas.ac.cn Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/kernel/elf_kexec.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c index b3b96ff46d193..88721bea81fcd 100644 --- a/arch/riscv/kernel/elf_kexec.c +++ b/arch/riscv/kernel/elf_kexec.c @@ -444,6 +444,12 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi, *(u32 *)loc = CLEAN_IMM(CJTYPE, *(u32 *)loc) | ENCODE_CJTYPE_IMM(val - addr); break; + case R_RISCV_ADD16: + *(u16 *)loc += val; + break; + case R_RISCV_SUB16: + *(u16 *)loc -= val; + break; case R_RISCV_ADD32: *(u32 *)loc += val; break; -- 2.43.0