From patchwork Wed Oct 18 22:51:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13428067 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 28F48CDB483 for ; Wed, 18 Oct 2023 22:51: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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:MIME-Version:Message-Id:Date:Subject :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=m0zXfDROJYhTGP73sufXSpDH/B3N1TJUJCwjXUaCudY=; b=fIaxlQ+2Bkf7SN F496plm5Olsv6Ko2TFBk8+1QvNSrzktR03ls5C0nGAD+wPc8xgwoJuiZruBn7ai3dnJivekYwx1hc /hNssvIP16u+QIaV9ltXKhS1L/wcwgBUYEGMRDIWlhBNJ3B5Em2yMtu4q0sbI43E6vPidad1YRQNP JCdAgdU2glbkm+20O6yWcQ/TuNeQbBwKHcEg6DLBhL5Gn6hJYoBRHnBAJHN060Hlu3b9zOxU7n9Or oZo3NtRKb0R9eg5iGFhQ/Nh0EZ93oyq/5PpGt61PkAS112t26BJwQKl2rqNngO9Ci4O3sch9fBb9O 9QtL67lmHSV03COzGo8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtFNc-00Fr5q-1P; Wed, 18 Oct 2023 22:51:08 +0000 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtFNZ-00Fr53-0V for linux-riscv@lists.infradead.org; Wed, 18 Oct 2023 22:51:07 +0000 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6cd09f51fe0so562968a34.1 for ; Wed, 18 Oct 2023 15:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697669464; x=1698274264; darn=lists.infradead.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=9/6gRB6PKN0zKg0UrM+QY05Z/ZteQMJLVCSifjerBXY=; b=ACgdAr5bUDcbgcbg/VTLpnQeoHbvm1siSPBKTMXt++Cd/RAD/y8ZaJTNnu8ZpuFNyY vRgIlervaDjM53N4KvKRrFN3j5qlxJUN+slYSoDDvqxmG17sF8MszO+k0ae2EvWNQs/L sI1Mh7f2Dzd/E6lI7tO+tgDC17FsN/7yxM692h0n7v2FAMieAgh5f4uKBgrJDkaUWzbI dUEdlsdnKnm19weGi3jJj0IAoeVVXr06m8nv4V60E87Y9slnIEzr1dXpwbQqThfLgqPB McGFgA9hvpnXcCKBRe+peySGPCrXBGylgP/u4UFLeS3cQS5jonzG2j+gPyZJdgYSLCzx swXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697669464; x=1698274264; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9/6gRB6PKN0zKg0UrM+QY05Z/ZteQMJLVCSifjerBXY=; b=cW0qTGKyyi1PxEZhOWXm3V8kn0Lpr7UJYbf8oprZepULMF7A4jwXF9baAeM4hpLcnA DV1nCtyVXiX8RmHyTS47k3vM/HPp4lH486jfXuQ/+uGFAvR221d+BNXKKDW57OrAixWz JcXvtUb6bOP6xkZN6zW8tmnWCPgbymyNmE4mSDgnP72GdwP65RnZCDWeSM3IeLq7M8dD bkbgwstbkWUDsGOYoqpCUIn4ScTlVDrUjEC6L6DuXtJCL8Z/KA38Vp3yAa9fORWj+7NF 1JGe933EhBzlpsZtdS5x8aSLTnZV7ljRTA9Ix4SpqJ6/5pdGqPyDYQvg8oh04cN3i4Qg Q4QA== X-Gm-Message-State: AOJu0YyZ9lIU/4PkxBgkfiXGZa5ZJTPTCjexar6BD7t7d1BtWWKAeK+M PmZ3wQ4OBT5KpKgpNSzUuzxeKQ== X-Google-Smtp-Source: AGHT+IHPM5SEb3p3yXI6+cmxTQEe9iGrXUotAOK1ZPi+82laCIzaDi0NMhLemTRTVTsPi8QNYprGKw== X-Received: by 2002:a9d:7398:0:b0:6ce:21c:28a9 with SMTP id j24-20020a9d7398000000b006ce021c28a9mr634585otk.34.1697669463891; Wed, 18 Oct 2023 15:51:03 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id r195-20020a4a37cc000000b00581e7506f2fsm641134oor.9.2023.10.18.15.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 15:51:03 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH v5 0/3] riscv: Add remaining module relocations and tests Date: Wed, 18 Oct 2023 15:51:00 -0700 Message-Id: <20231018-module_relocations-v5-0-dfee32d4dfc3@rivosinc.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAFRhMGUC/23NwWoDIRCA4VcJnmvQHR2zPeU9Qii7OjZCshZNJ CHsu9ddQgnF4z/MfPNkmVKgzD43T5aohBziVEN/bJg9DdM38eBqs050IHqx45fobmf6SnSOdrj W7cw9giWHWo7OsHr4k8iH+4oejrVPIV9jeqw/ilymL05CiyuSCz6O4HYKDZke9imUmMNktzZe2 CKW7k+RQmBT6aqijEZUGjw521DgTZFtBaoyIBrvUBhJfUNR74ppKqoqPRivyYNEL/4p8zz/Ai9 cJJSJAQAA To: linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231018_155105_211523_74952D55 X-CRM114-Status: GOOD ( 11.37 ) 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: , Cc: Albert Ou , Kees Cook , Charlie Jenkins , Andreas Schwab , Eric Biederman , Paul Walmsley , Palmer Dabbelt , Emil Renner Berthing , Emil Renner Berthing Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org A handful of module relocations were missing, this patch includes the remaining ones. I also wrote some test cases to ensure that module loading works properly. Some relocations cannot be supported in the kernel, these include the ones that rely on thread local storage and dynamic linking. ULEB128 handling is a bit special because SET and SUB relocations must happen together, and SET must happen before SUB. A psABI proposal [1] mandates that the first SET_ULEB128 that appears before a SUB_ULEB128 is the associated SET_ULEB128. This can be tested by enabling KUNIT, RUNTIME_KERNEL_TESTING_MENU, and RISCV_MODULE_LINKING_KUNIT. [1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/403 Signed-off-by: Charlie Jenkins --- Changes in v5: - Brought in patch by Emil and fixed it up to force little endian - Fixed up issues with apply_r_riscv_32_pcrel_rela and apply_r_riscv_plt32_rela (Samuel) - Added u8 cast in apply_r_riscv_sub6_rela (Andreas) - Link to v4: https://lore.kernel.org/r/20231017-module_relocations-v4-0-937f5ef316f0@rivosinc.com Changes in v4: - Complete removal of R_RISCV_RVC_LUI - Fix bug in R_RISCV_SUB6 linking - Only build ULEB128 tests if supported by toolchain - Link to v3: https://lore.kernel.org/r/20231016-module_relocations-v3-0-a667fd6071e9@rivosinc.com Changes in v3: - Add prototypes to test_module_linking_main as recommended by intel zero day bot - Improve efficiency of ULEB128 pair matching - Link to v2: https://lore.kernel.org/r/20231006-module_relocations-v2-0-47566453fedc@rivosinc.com Changes in v2: - Added ULEB128 relocations - Link to v1: https://lore.kernel.org/r/20230913-module_relocations-v1-0-bb3d8467e793@rivosinc.com --- Charlie Jenkins (2): riscv: Add remaining module relocations riscv: Add tests for riscv module loading Emil Renner Berthing (1): riscv: Avoid unaligned access when relocating modules arch/riscv/Kconfig.debug | 1 + arch/riscv/include/uapi/asm/elf.h | 5 +- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/module.c | 371 +++++++++++++++------ arch/riscv/kernel/tests/Kconfig.debug | 35 ++ arch/riscv/kernel/tests/Makefile | 1 + arch/riscv/kernel/tests/module_test/Makefile | 15 + .../tests/module_test/test_module_linking_main.c | 85 +++++ arch/riscv/kernel/tests/module_test/test_set16.S | 23 ++ arch/riscv/kernel/tests/module_test/test_set32.S | 20 ++ arch/riscv/kernel/tests/module_test/test_set6.S | 23 ++ arch/riscv/kernel/tests/module_test/test_set8.S | 23 ++ arch/riscv/kernel/tests/module_test/test_sub16.S | 22 ++ arch/riscv/kernel/tests/module_test/test_sub32.S | 22 ++ arch/riscv/kernel/tests/module_test/test_sub6.S | 22 ++ arch/riscv/kernel/tests/module_test/test_sub64.S | 27 ++ arch/riscv/kernel/tests/module_test/test_sub8.S | 22 ++ arch/riscv/kernel/tests/module_test/test_uleb128.S | 20 ++ 18 files changed, 637 insertions(+), 101 deletions(-) --- base-commit: 4d320c2d9a2b22f53523a1b012cda17a50220965 change-id: 20230908-module_relocations-f63ced651bd7