Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp633881rdb; Thu, 19 Oct 2023 14:42:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGq173pRpXmSTijeuLXlILvwycboo0/hR6wRldNGIATCmXAgTq6FpC6QSfuyKMw0LDwqYRb X-Received: by 2002:a17:90a:5b08:b0:27d:54b9:c3c5 with SMTP id o8-20020a17090a5b0800b0027d54b9c3c5mr133525pji.17.1697751724650; Thu, 19 Oct 2023 14:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697751724; cv=none; d=google.com; s=arc-20160816; b=dRYS9M7YW3gDxlJ0t9gIW8alAc42LHQdZhNaHcjbfth5AuG17zc/8r1crcVGdm5fW9 TBMEiYp2GUwulwIkX5O0T59OPECRfJUkulG+Rp7qtfhAUPVDnIozQ6UF+i+xmaACMNwy WDSYHkdxEp1nIuUFvshqqosOHpazkuXYcOjWYv8xwlBlrhNdQuV40q8ZdJsg/0Q3dH1+ gxJsyI+MU1wC3zBQX9YKdtKjhJlTAKiO39mvPwKcMsP/UpS8MvREtPlQ+GWYmYjYoONx YtpkURfdHgsKSDwb6fN4cdrGPA+mV2MQOD4HHXzFK0Hw0WyF2wxpccV0tnnIBAcxmwzE lltg== 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=1PmU2FKsnzb5ZXX3tTX1X2BdGNJX62qrZ4JKEx6OuTU=; fh=p72P/faTatm4zde/2rGY7TVUAfzsmCW1YONXrKkLKtM=; b=MVLAyzmWiRe4icmrzeTlYM7SBO75NxYgJR+LW43jDNO1HGQe05wz2BbEA1O4gBXXHH llWjK6RaXbm2pNB71r7PuXScih0qFTYGu/FKdX1N5myQLQUrwdXjAux6wPBtpD+i9sbC 2kWictypguShmLRFX5xr2xD2+FpL/48MzmmDAa9gaCasEweV39NysuPbXKkAVS83ecDV xK4+tLaXqGP8ozXnLMJZNTSvEsYSfX+gvRaUZguq9M6VQI1JE2hurLjqsLhZSIGlTVou 4sLyMdj9rsx/RI5G/4vVwDd7M+i+rMYfbAD/cnLlMn7vp/i8PoF5eMeRaFOR/J3IrrSD 8b2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=RSQnSbxY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j7-20020a17090ae60700b002772f04f9bfsi2932121pjy.113.2023.10.19.14.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 14:42:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=RSQnSbxY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 9349D80E4B07; Thu, 19 Oct 2023 14:41:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346603AbjJSVla (ORCPT + 99 others); Thu, 19 Oct 2023 17:41:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232759AbjJSVl3 (ORCPT ); Thu, 19 Oct 2023 17:41:29 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9CE7BE for ; Thu, 19 Oct 2023 14:41:27 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6cd09663b1cso108851a34.3 for ; Thu, 19 Oct 2023 14:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697751687; x=1698356487; 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=1PmU2FKsnzb5ZXX3tTX1X2BdGNJX62qrZ4JKEx6OuTU=; b=RSQnSbxYRBuvXaoCQ01q3gCI2eff6kej2TWKpMIVlrXyEq54bGzPhXwaNDmrJrQ1T1 7qTQxDu3kQ3s9a3fg6KEUUjmozjyE15xqzGpTgBUfQSea3d2xdoXDd87ThZGJd3OfuyH VMZL6SJBNIuOMOF3XD03Gmtw8BZ6fEgDemJnfaKE+uwTGRsrN4SbtikCgDaevsvC5Myv 6dcImshVqSTSsNcSoYkn0mA81fucBcY7dwL1xzQcDlP+KkrSZwiAVwXhzuSsovpnpPDa SQ7k4PpzVlEtzgSe/hXF6rv5nKpMzYKUo3iiB6fHJDmW+XJAtinG3TRub+UEaGMZHa8N 3w2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697751687; x=1698356487; 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=1PmU2FKsnzb5ZXX3tTX1X2BdGNJX62qrZ4JKEx6OuTU=; b=UonLR+c2QHSXT9cKwALO9I9U8E5VVblxoBv+7lCiZ6IcCwDYseVxXk+ZKmcvLBPYWV c5Sts94jENYb6I80ILBldf3ktoT1uscAF/QB5vf+fHbrW/RZ5D7RLBsgjhY1V8fry2aK GM0cYmdZP2ecWp9T9kSEknaB5No7TCay8pu+qQHzSoHTtXCXzOJ7KQv40mT+QaAbRjhr IJJRfUiTnHvdnqpmKOcgesXjropxbzi2rDaC2fxbVtUhCGMMAXf01EhJqrYy6vX8u0y4 DpK4DP8nAPEl2FNc8Ki9+4XrbQ7aT7PEF2cbS3dtO6AovZjW7Eo34VYiu9fK1I29bBSh Pjqw== X-Gm-Message-State: AOJu0YxNOvgrQpyb5sngl+Xq6HmNAQaiqq3ayes51d5Mut8YvtAAJewW f0nVIQmjJjL/xeRk7zAgeSUHBA== X-Received: by 2002:a05:6830:25d4:b0:6b8:f588:2c79 with SMTP id d20-20020a05683025d400b006b8f5882c79mr59079otu.1.1697751687063; Thu, 19 Oct 2023 14:41:27 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id x19-20020a9d6293000000b006ce2c785ac7sm81812otk.8.2023.10.19.14.41.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 14:41:26 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH v6 0/3] riscv: Add remaining module relocations and tests Date: Thu, 19 Oct 2023 14:41:23 -0700 Message-Id: <20231019-module_relocations-v6-0-94726e644321@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAIOiMWUC/23Q0WoDIRAF0F8JPneLOjpm+9T/KKHsOmMjJGvRR FrC/ntNKGUpPt5h5gzcmyicIxfxsruJzDWWmJYW8Gkn/HFaPniI1LLQUoMc5X44J7qe+D3zKfn p0rbLEBA8E1o1kxPt8DNziF8P9O3Q8jGWS8rfjx9V3ae/nIIeV9Ugh3kG2ht07EZ4zbGmEhf/7 NNZ3MWq/xQlJXYV3RTjLKKxEJh8R4GNovoKNGVCdIFQOsVjRzFbxXUV05QRXLAcQGGQHcVulW7 N1TaFAjNoMhT8/17Wdf0Bv9/ugM8BAAA= 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 , 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 14:41:55 -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. 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 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 | 368 +++++++++++++++------ 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, 633 insertions(+), 102 deletions(-) --- base-commit: 4d320c2d9a2b22f53523a1b012cda17a50220965 change-id: 20230908-module_relocations-f63ced651bd7 -- - Charlie