From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B625E9413C for ; Sat, 7 Oct 2023 00:41:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233973AbjJGAl1 (ORCPT ); Fri, 6 Oct 2023 20:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233894AbjJGAlY (ORCPT ); Fri, 6 Oct 2023 20:41:24 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E03ABBE for ; Fri, 6 Oct 2023 17:41:18 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c87e55a6baso20686675ad.3 for ; Fri, 06 Oct 2023 17:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1696639278; x=1697244078; 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=0Hp0ECJm0gFf8INn0HiZKpVqg/IUsayxsh+1diajkmI=; b=0snFmb3PiemW40ppTS6XhdS+2Q2BYx3bB5yjqUtuthVDYihbbHjT4n/ZhmtNuDQ3Ot wv1n5sY4TbZHk0RL0/NtPlmSZZF/Gb/HxGPwmOHplmP3eWImzxG1lP9AvVUFBQR132Dt SERJgx2ksaS6ZVM/MhxsjwymIu2RactGqsKWdN06g6p+9hNXH4CyyVjRzw6mnCa0rsaq kHBPS8EYWktLwkSUqLX5MmPPTZEsdfs5eFQHbZEiObnPavb7jMsFGNzkGllRtT8h/GrB tLbcO166lHTlsUurqH76vXIqYVNNCVDMc7V+59BCDTEKvzKgMuhXJ7Kj4oPYwju1enNh S8IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696639278; x=1697244078; 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=0Hp0ECJm0gFf8INn0HiZKpVqg/IUsayxsh+1diajkmI=; b=udW/LGgm9locIHcVC/PtGLMV7+eqMflF/h/K6LTOQd2CMA3rwGx6I6K+5jnjkxcJUt nBAgpn25YLmtL1yZXp3xePbfAXV0/HGmmHa/1gRa/SUGCdbLDOh0gveg5I4rJXFi1x9/ 0whpq1Ih6jRCE0SGp2DGM1W1JLtoPL22xqBBNR62RSzs31cM9DzCd4Cc6x5rmcwPVl0D yC8wym7mI0P411tjhZeSUDAQWCPPjKL9LjME0r2mSEZdjpO7aIu3WWzYxxs7pJJnjk4P /nMx+gWIxqbVBGXkkdDe8kVjsJIVP/0vexf6U8aY273850fgohxnyJ/+yvSO3HhSu+8d pUVw== X-Gm-Message-State: AOJu0Yxb/o1ibziJCWvj6b01uRuxwt2hngQoigaH7ITwz8WrrnkCFkTp hV7x+C0+gyfHN+gi7nZurTucjw== X-Google-Smtp-Source: AGHT+IH9WxpF3kdiS9QaTEtUj5obvaHiYFW9XD6AGPsPbfksFSz9GOfBX62HTFtC8jFHFpfd0gjD2A== X-Received: by 2002:a17:902:c112:b0:1c0:93b6:2e4b with SMTP id 18-20020a170902c11200b001c093b62e4bmr9338829pli.33.1696639278389; Fri, 06 Oct 2023 17:41:18 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id x16-20020a170902ec9000b001c582de968dsm4534540plg.72.2023.10.06.17.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 17:41:17 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH v2 0/2] riscv: Add remaining module relocations and tests Date: Fri, 06 Oct 2023 17:41:05 -0700 Message-Id: <20231006-module_relocations-v2-0-47566453fedc@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIACGpIGUC/22Nyw7CIBREf6W5azFQlD5W/odpTAu39iYtGKhE0 /DvYuPS5ZnMnNkgoCcM0BYbeIwUyNkM5aEAPfX2joxMZih5KXnDa7Y485zx5nF2ul9zO7BRSY1 GncVgKsjDh8eRXrv02mWeKKzOv/ePKL7pTyfkP10UjLNhkKY+qQqrRl48RRfI6qN2C3QppQ8nx buxtwAAAA== 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 , Charlie Jenkins X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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. The module linking ignores a SET unless it is followed by a SUB. In order to find the corresponding SET, module linking starts at the relocation above the SUB and iterates up until it hits the SET. If a SET is not found, module linking fails. This can be tested by enabling KUNIT, RUNTIME_KERNEL_TESTING_MENU, and RISCV_MODULE_LINKING_KUNIT. Signed-off-by: Charlie Jenkins --- 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 arch/riscv/Kconfig.debug | 1 + arch/riscv/include/uapi/asm/elf.h | 6 +- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/module.c | 247 ++++++++++++++++++--- arch/riscv/kernel/tests/Kconfig.debug | 32 +++ arch/riscv/kernel/tests/Makefile | 1 + arch/riscv/kernel/tests/module_test/Makefile | 15 ++ .../tests/module_test/test_module_linking_main.c | 73 ++++++ 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, 574 insertions(+), 26 deletions(-) --- base-commit: 82714078aee4ccbd6ee7579d5a21f8a72155d0fb change-id: 20230908-module_relocations-f63ced651bd7 -- - Charlie