Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp71055rdb; Tue, 31 Oct 2023 00:26:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXHXNIAa0Bv9qQ1/4kAplSZ5GMrcVVUgeCrfDam2tR8MOlfYofVzGYp+w79Z/NUrUFV4H+ X-Received: by 2002:a17:902:e544:b0:1cc:5899:112c with SMTP id n4-20020a170902e54400b001cc5899112cmr4033618plf.23.1698737166607; Tue, 31 Oct 2023 00:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698737166; cv=none; d=google.com; s=arc-20160816; b=GnCRuTmMVJoDkn4VEcD80W2MaSc5KAw8PcFx2u9nwlu6IflSfGE+YlXzkG/hy21pMs 5SGu18RziE1qX4qvGrzW5MhJ3cbNt3uxQBUnRlrgdij/MBdYvnC6uygkq7cBkwC4GM3G Vgs7+CSOS2CygqGa3b+1Lik89PcHZB9+94g1x1GJ+8WPx0raV1v1jQpuaQj2d5VvInpG aG6gicXwFf2ovqV2tAlpblI3iOOhaegQ2PWcrQtvttntxW1XmucLXPGu2Q5+4QG85Cl3 qJDmzHgf8ovhhOnY7QGfhY0oAd2ygvEwzFeP9+B4lupmI+Mbb1o0fNBahZ6DzI7FLr1t 0lJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:content-transfer-encoding:mime-version :message-id:date:subject:from:dkim-signature; bh=vhAhMlUaphHl5V7P6XcsEBHb1Aahpw8dSDQur0cX8zw=; fh=3JJYoT2qrR3RU+rWlb6yoFBgRHYOWCMcUv6lOGhOtBk=; b=Ii86clLiNDGlRciJGEpephs7NZlhEpvr52y4mm+5XADVjdKI8dBx9P8qt9s6UxS4MJ NSjGPhfhzv63Bpx8Vyb6WIOP+iX3HCtNBX4XPTZZOr77pGOURBtqNUPU+fP0JQHzRL3Q 2Qq/qaoFMBHmyBpXSuiOIrFpluQORzYD056exPX4kECFTwRKLKyNaqfm25OOfaxt0WcB 1br0oIl2HEqzZ8y1LiK+Fiv79sw7rkz91FYR0upAeYbXmZPyetDUi9m6CESEn2tlWZps FdZ4EO+BmqqQPOrShM3sBMruDPcecErsExTf6TQQu/lFmLEnk9cLhZu3+L4DiqlJz86s MoSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=1Zj2xfsE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id lb7-20020a170902fa4700b001cc3e45ac2esi611600plb.19.2023.10.31.00.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 00:26:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=1Zj2xfsE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C137D80A49B9; Tue, 31 Oct 2023 00:25:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343674AbjJaHZE (ORCPT + 99 others); Tue, 31 Oct 2023 03:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343611AbjJaHZB (ORCPT ); Tue, 31 Oct 2023 03:25:01 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1C16C1 for ; Tue, 31 Oct 2023 00:24:58 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1cc2575dfc7so26332305ad.1 for ; Tue, 31 Oct 2023 00:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698737098; x=1699341898; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=vhAhMlUaphHl5V7P6XcsEBHb1Aahpw8dSDQur0cX8zw=; b=1Zj2xfsEM8yuLQ0p1aVRsOU7MIt+b4pHcVfkRmKwEWYgmiVJHpGww412QxfyPJUV6v ayKIrkWFCaSaQGn5642AVp3wFeO0AEpetk3d6HKHF7eYUYSNg0yQF6F+MTckoUBmttpO XeI5JiODH+myEdYo332VByjZhEv4EPvaaUKK9ngeMtTNPJ0tUTkN9txVDJLqLRsacxVn UTuLUiosys3ZwNPySgUn1Dc69t/LJmfLpNkiz02keVqzc6cvPDHhN6Au5D5jHp40EyzR h/lPsOYSTDMdMZyn6giE2ZYTsG55/Q5W0Bzhr8voh/Ljt3iRRx6B5WswfeF+lI+N1pn9 o/Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698737098; x=1699341898; 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=vhAhMlUaphHl5V7P6XcsEBHb1Aahpw8dSDQur0cX8zw=; b=g13X72W5wb7UA08Oap2NziQPK5uiHk07t6JXWhKULyl8JOw3Nul27/gou95EOc4qlr mDt3UNmW1UjS0JVvCA9kAMWz6rYk1Uzt5yCmbqoj39oTE1D95f7L3qYbZGalKlePNhsk u31NftETc6QCy7RHYT+TAR/5A3MxASsf5+KZ5Hs35ZKHWxu4MNGpVVYLXNoj0dVKfEFT CiXdN5qr/cj3M/seSeVC+rEq9pYV6RUJ+3HfSBPAzjDQCNaTu8FKetft8n0ZoJx+B4Sg ecSKLu0yQwBmq/DI9h2+ha6V9zgsiDLYHrRHM0ZdeosLLHg1J1jKXGjlGAPWZQhs3S3W txEQ== X-Gm-Message-State: AOJu0Ywm7k/Lhf8xgWVkbjdq9I4AqMZhZNMJHLP5n3dkbBcBJBXA7Sg5 QNm/30wk41FURi5d7JYin/pNHQ== X-Received: by 2002:a17:902:ce8e:b0:1cc:636f:f38a with SMTP id f14-20020a170902ce8e00b001cc636ff38amr1759360plg.57.1698737098025; Tue, 31 Oct 2023 00:24:58 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id c4-20020a170902d90400b001c74876f018sm652575plz.18.2023.10.31.00.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 00:24:57 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH v7 0/3] riscv: Add remaining module relocations and tests Date: Tue, 31 Oct 2023 00:24:49 -0700 Message-Id: <20231031-module_relocations-v7-0-6f4719b64bf7@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAMGrQGUC/23QwWoEIQwG4FdZPNeiRuPaU9+jlDKjsSvsjkW30 rLMu9dZShmKxz8kX0JurFJJVNnT4cYKtVRTXnqwDwfmT9PyTjyFnpkSCoQTR37J4fNMb4XO2U/ X3l15RPAU0Mg5WNYHPwrF9HVHX157PqV6zeX7vqPJrfrLSRhxTXLB5xnCUaMl6+C5pJZrWvyjz xe2iU39KVIIHCqqK9oaRG0gUvADBXaKHCvQlQnRxoDCSnIDRe8VO1R0VxzYaCiCxCgGitkrwzc 305UQiUAFHaIf/QX3ihsquN2irUJCrUHJf8q6rj/THr9CFQIAAA== To: linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Eric Biederman , Kees Cook , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andreas Schwab , Emil Renner Berthing , Samuel Holland , Nelson Chu , Charlie Jenkins , Emil Renner Berthing X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 31 Oct 2023 00:25:30 -0700 (PDT) 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. This patch also overhauls the implementation of ADD/SUB/SET/ULEB128 relocations to handle overflow. "Overflow" is different for ULEB128 since it is a variable-length encoding that the compiler can be expected to generate enough space for. Instead of overflowing, ULEB128 will expand into the next 8-bit segment of the location. A psABI proposal [1] was merged that mandates that SET_ULEB128 and SUB_ULEB128 are paired, however the discussion following the merging of the pull request revealed that while the pull request was valid, it would be better for linkers to properly handle this overflow. This patch proactively implements this methodology for future compatibility. 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 v7: - Overhaul ADD/SUB/SET/ULEB128 relocations - Fix ULEB128 so it produces correct values when more than 1 byte is needed - Link to v6: https://lore.kernel.org/r/20231019-module_relocations-v6-0-94726e644321@rivosinc.com Changes in v6: - Use (void *) instead of (u32 *) for handler type - Constrain ULEB128 to be consecutive relocations - Link to v5: https://lore.kernel.org/r/20231018-module_relocations-v5-0-dfee32d4dfc3@rivosinc.com 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 | 685 ++++++++++++++++++--- 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 | 88 +++ 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 | 31 + 18 files changed, 963 insertions(+), 103 deletions(-) --- base-commit: 3bcce01fcbcd868b8cf3a5632fde283e122d7213 change-id: 20230908-module_relocations-f63ced651bd7 -- - Charlie