Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4189527rwo; Tue, 25 Jul 2023 01:58:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlFiFZkC9YhjEuMqiwRi7dELYWZciqYhVgIrAFD20KdRRYiiIJusZVvvSBykvx/XxcX6gO+w X-Received: by 2002:a17:903:2309:b0:1b8:9ba6:b221 with SMTP id d9-20020a170903230900b001b89ba6b221mr12027955plh.21.1690275504107; Tue, 25 Jul 2023 01:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690275504; cv=none; d=google.com; s=arc-20160816; b=an6PQFoVPVkzZnuVEV4+OrVHQwFXkcoWH5FqNQ06qjWdoLuk/5/5de2H7+0xO4EJpu 0ciSCY2ICraQWJ80ClB+W7lW4FUTGJAz3kAO792eX6hXC2SYU51Tpdd7MEM4QHKsEomc ptk2oXjyj9D9e6z8opBxVhV8LCYIhaEYA3Xqz+k5B0Ox7lfpr4kCuJYH+84j9ea7Q52z s2AeNYpvqLMZDT8ui5g1torzSV8264ibkSQF1Gl7K7QZWXmWJQahkaq09unJp3thQNR3 k0vox8KPb+5TY/7YAa07KevXaoJ2zYx85DdHco00kY9F0KFWcmfHwtLCgDIQk+DyIUyi yvYA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wty8JCtBL/p096nX7fvX9PTA1CKlYqvtvBS6jxkzxZI=; fh=lcXKo0NRrUXZg/5xK5FQthl2JcV2SVZShbwn9PnLCCI=; b=MVvTA2amTMgsx0dYZ7SdztC8bcP+V91TpgTPCfHzIqdmzfkLv8dQNaa0z7JmOnnzRJ BFsOZLNAG+3O8uIlrs2dmp6LCfWLc8/lXn/pPdIkbOc8CyQO8tNd4oAR5RFcpvNA0OV+ Yuc1Ny9D2W1sa10eKQpJtgA5YJyfmfawYS23MUfPikA6TrCdNrwwgJ3IhUvauOYA/r6U TpyOaTbhensaScjJ8zA97+NUfH1oHxAOAKIad2dbc8x70JU3qnoP5o7F/nX4q9G/JMdI VIH0u0FcQCda9mokQ+IM4C1dh+U/AEmLF5cYy4tD83awyaCR2cA1zpTVKj6JOYyV01gL dFAg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij22-20020a170902ab5600b001bba53994acsi3804495plb.243.2023.07.25.01.58.10; Tue, 25 Jul 2023 01:58:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231349AbjGYItT (ORCPT + 99 others); Tue, 25 Jul 2023 04:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232306AbjGYIrn (ORCPT ); Tue, 25 Jul 2023 04:47:43 -0400 Received: from frasgout12.his.huawei.com (unknown [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C82030E9 for ; Tue, 25 Jul 2023 01:46:13 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.229]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4R99J06vRWz9xtSP for ; Tue, 25 Jul 2023 16:32:16 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.48.128.235]) by APP2 (Coremail) with SMTP id GxC2BwB3Ijlwi79kXB38BA--.63760S4; Tue, 25 Jul 2023 09:45:05 +0100 (CET) From: Petr Tesarik To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Li Huafei , Liao Chang , Masahiro Yamada , Alyssa Ross , Nick Desaulniers , Ricardo Ribalda , Kees Cook , Heiko Stuebner , Li Zhengyu , linux-riscv@lists.infradead.org (open list:RISC-V ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Cc: Roberto Sassu , petr@tesarici.cz Subject: [PATCH v1 2/3] riscv/kexec: handle R_RISCV_ADD16 and R_RISCV_SUB16 relocation types Date: Tue, 25 Jul 2023 10:44:26 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GxC2BwB3Ijlwi79kXB38BA--.63760S4 X-Coremail-Antispam: 1UD129KBjvJXoW7tFy7AF1rGw1DKr1rWr18Grg_yoW8GrW8pw 4xGr48GFWDGr1Ik34xZaykC34rG3WDu3y3ta9Fy3W5Arn8JFy7CrZ2g3WUXF1jqr1FgFWS vFyIgr1rt3W8A3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI 8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0x kIwI1lc7CjxVAKzI0EY4vE52x082I5MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnI WIevJa73UjIFyTuYvjfUn3kuUUUUU X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_L3,RDNS_DYNAMIC, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Petr Tesarik 16-bit add and subtract relocation types are used by the purgatory code when the kernel is built with CONFIG_RISCV_ALTERNATIVES. If they are not handled, kexec_file_load(2) fails with: Unknown rela relocation: 34 kexec_image: Error loading purgatory ret=-8 or later with: Unknown rela relocation: 38 kexec_image: Error loading purgatory ret=-8 Note that alternatives are not yet handled in purgatory code; this patch merely allows to load it. Fixes: 838b3e28488f ("RISC-V: Load purgatory in kexec_file") Signed-off-by: Petr Tesarik Cc: Li Zhengyu Cc: stable@vger.kernel.org --- 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 38390d3bdcac..f23fd419c402 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, case R_RISCV_SUB32: *(u32 *)loc -= val; break; + case R_RISCV_ADD16: + *(u16 *)loc += val; + break; + case R_RISCV_SUB16: + *(u16 *)loc -= val; + break; /* It has been applied by R_RISCV_PCREL_HI20 sym */ case R_RISCV_PCREL_LO12_I: case R_RISCV_ALIGN: -- 2.25.1