From patchwork Mon Oct 16 17:36:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13423883 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BB50CDB465 for ; Mon, 16 Oct 2023 17:36:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B45BD8E000C; Mon, 16 Oct 2023 13:36:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF6868D0001; Mon, 16 Oct 2023 13:36:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BEB28E000C; Mon, 16 Oct 2023 13:36:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8A40F8D0001 for ; Mon, 16 Oct 2023 13:36:20 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 68687160AC3 for ; Mon, 16 Oct 2023 17:36:20 +0000 (UTC) X-FDA: 81352028520.24.7EFE73B Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46]) by imf17.hostedemail.com (Postfix) with ESMTP id 800DE40004 for ; Mon, 16 Oct 2023 17:36:18 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=2IXiHPXI; dmarc=none; spf=pass (imf17.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.160.46 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697477778; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=wPqNuOKCfINBcA4JkEYIZMV2tOMunrhVNGKlfAdiW0k=; b=vBIYc+rqiou7tb1gbIsRmQXXQiy1j7POKf07nGGmdqyyT2o3SlIntPRVIyL4B6GhFrqSNA TiiJ8MaNpPrwhIrPbgnXkrDG7Zc8r30Xl1XvTXeyPba3vgNVc4817QL2IkziLRyBG2Uimq 7wKBLEM9UpWNr5wnkF3U+jb6/q2T4Nk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=2IXiHPXI; dmarc=none; spf=pass (imf17.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.160.46 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697477778; a=rsa-sha256; cv=none; b=B47sP/Z476mYJneXfoJcLJG8txmRGf83ZJSe14GgaQXsZBs3i6kOgb4HmB5S1xBMxzAXQz 4dmR0meIjs5DCYvQxgDm9HmN7VPkcoBWmcs893tZyTDtGKIpYkkJljpuffViWwuLc5qDzF fIJdOtjrdE5R4dSmIyCEdb53t1bmNWs= Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-1e9bb3a0bfeso2674632fac.3 for ; Mon, 16 Oct 2023 10:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697477777; x=1698082577; darn=kvack.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=wPqNuOKCfINBcA4JkEYIZMV2tOMunrhVNGKlfAdiW0k=; b=2IXiHPXI9NREsBXD//5MaQpBy6bfaSzboxuVHyLXyjg06jB7LYTGZPzKjh9NV7+bUG J1OTZ9N84YBuWF1VF7R7TNkK/pg+UUSX7cEYghQLKZYV681i+ud81JN1ppTpXDVEi0hM Dx10aH1PcdMcgkHRDJdXL+utuo0x47bBZVGGVfOMIffzJKTKciMzYXDmZaJSuR1HonYh AosLG1NeHSU0GYIeFhDeebLLAxwhY7Hg0BvxmUDAR5TYdSTHdYbFuZF646lkekYq4+4V ELQtvQhx+Yc4C+vR8rysUrAz5gS7UBk5yLRCAy7bQ2NUf38S9EYrjFnMW1iegK4DIjPE 1x1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697477777; x=1698082577; 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=wPqNuOKCfINBcA4JkEYIZMV2tOMunrhVNGKlfAdiW0k=; b=oWuga9fXDOP9/YEuuNT0jADQC09ubkY5eCxpJsUvaNFmnyljiZ264FApY7BFlFj5Q1 6Vdd9+HPphmVY4ARfFPr1QL4yQiVLOWtjmG0WkiYiZ4ewm6du/vqzt27Ak9Ekh/8oCoV ela9bT5Zhl43xuIGbcVfo8v+5ZYcLqNps8tph84KFJU/5G0G0LsZS5VwoZ0iHaHpvDro 9O/zU6xkX/rsBcKdB/ZzZcCxhjnRurMzmzeImUL3PDcOgE+u0Exw1uXb52PftFFUzQM4 VdtfqKQLXw2j39EVWcbmZL3dvy8xFHaWxil+LYm5vsACISCpHw6GBfhgo+tdYjb2HVOh M/kg== X-Gm-Message-State: AOJu0YxPfa9ZoOz/B7ly5mPyCuHAvvY1RpWTrPUfGcx8J/9HipYkd9GF M4IKAjeaB16+jjW+CZPlBGXZAw== X-Google-Smtp-Source: AGHT+IFjy7wWtg4cLzRfrDjTXhyzIN/arrlQSsc1LKoPaM1CIh1aS1d1idcXizO/mGXqU+9/QHsVCQ== X-Received: by 2002:a05:6871:5319:b0:1e9:9469:a858 with SMTP id hx25-20020a056871531900b001e99469a858mr16940767oac.39.1697477777557; Mon, 16 Oct 2023 10:36:17 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id lv15-20020a056871318f00b001e0fd4c9b9asm2092936oac.6.2023.10.16.10.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 10:36:17 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH v3 0/2] riscv: Add remaining module relocations and tests Date: Mon, 16 Oct 2023 10:36:08 -0700 Message-Id: <20231016-module_relocations-v3-0-a667fd6071e9@rivosinc.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAIh0LWUC/23NSw6CMBCA4auQrq3pA1pw5T2MMdAOMglQ02KjI dzdQowLw/KfzHwzkwAeIZBTNhMPEQO6MYU8ZMR09XgHijY1EUxIVrGSDs4+e7h56J2pp7QdaKu kAasK3lhN0uHDQ4uvDb1cU3cYJuff24/I1+mX43KPi5wy2jTSlrnSoCt59hhdwNEcjRvIKkbxU zhjalcRScl1oVReyBas+VOWZfkALPixp/0AAAA= 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 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 800DE40004 X-Stat-Signature: i3fkkj15nxijcwyae9x9m6pdsiutekj1 X-Rspam-User: X-HE-Tag: 1697477778-609387 X-HE-Meta: U2FsdGVkX1/aC0XkJk573yDqlUDFEqhxnbSVafxGxB4d0URRpkWPOqC8WOGeO2YaLS5buwsYbEWZ7PuV1QQL4duFcCs5IQBHPobGpzBi1f0uRyPEzcsgV1tvjNQWdBCaZEMh47VjVl9RTyq9sr/Ww/fx3RKv/8N/6vyD01lCt0rk+s3KjUC2msDs6zeA8e00n2o26Um5hIDDglUta0V+F3golg4gOBY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d9NywfP+/uRmF6MzY5JJAy7oApjyYbEMU3g+vpzf1s8ZObsOUoxGhbOQuITKwe84GhrQFsokWcrR8xIZ9oFQXtk9r75bt/ALPBuPL7uDkfH5/fezY/qfMGuTXpnA44sO1yMMnuck/7TjlkZwQ8WCAXYJqy/Xzb9zaHaQK8OLScQbyGr2f9mssc6gz+dEm+Vrmk0rimURjBqYOb4X8gyfQNZhJffoPL69SCiyrAnNWISs X-Bogosity: Ham, tests=bogofilter, spamicity=0.059136, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 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 arch/riscv/Kconfig.debug | 1 + arch/riscv/include/uapi/asm/elf.h | 6 +- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/module.c | 207 ++++++++++++++++++--- 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 | 78 ++++++++ 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, 539 insertions(+), 26 deletions(-) --- base-commit: 4d320c2d9a2b22f53523a1b012cda17a50220965 change-id: 20230908-module_relocations-f63ced651bd7