From patchwork Tue Mar 26 16:36:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13604664 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 583E9C6FD1F for ; Tue, 26 Mar 2024 16:36:58 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To: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=7CG3FsIU5ORI8ORxISPX9N3HITPH/MNi7CPCjihtnX4=; b=ZvScObM3hviy5J GnXhA+ofEhRH85QqO0t/FWeWWz9B/LFkgfVMIRTBbHN/evSCAXTL7r5f01oWcPNHq/qlZWww7fbI9 +vTQdYpS7ZjWh0PqMJNUKEy6bSL4gY36HH6bQ3cwI3VSc2dM4crYNovuvnzWZJTD08dVsWFSwSOmZ 8QJScuTrClduzKWBJZWAeELcnS6usYsmkPCbCJNhxP59/WGSFCey/9Y0OEtBmqLM7Bj7b45b7TGQQ K6KsvWmURZUsLGU/gO+KCQAgMbsW/GgTSIfAAQPkQqcmRbuJ6vPHxTVONamFM3o+cAvPVSpuSuDEW NdTkYhpleqziYUZc+Otw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp9n0-00000005V95-2sm3; Tue, 26 Mar 2024 16:36:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp9mv-00000005V6m-34lN for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2024 16:36:39 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 007332F4; Tue, 26 Mar 2024 09:37:07 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B057C3F694; Tue, 26 Mar 2024 09:36:30 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: agordeev@linux.ibm.com, anil.s.keshavamurthy@intel.com, aou@eecs.berkeley.edu, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, davem@davemloft.net, gor@linux.ibm.com, hca@linux.ibm.com, jarkko@kernel.org, jcalvinowens@gmail.com, linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, mhiramat@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, palmer@dabbelt.com, paul.walmsley@sifive.com, tglx@linutronix.de, will@kernel.org Subject: [PATCH 0/4] kprobes: permit use without modules Date: Tue, 26 Mar 2024 16:36:20 +0000 Message-Id: <20240326163624.3253157-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240326_093638_070048_9FD3B567 X-CRM114-Status: GOOD ( 14.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently KPROBES depends on MODULES and cannot be built when support for modules is not enabled. This is largely an artifact of the default/generic code for allocating insn pages using module_alloc(), though several architectures do not use this and have no strict dependency on MODULES. It would be nice to allow KPROBES to be used without MODULES, as this can be useful for testing and/or in certain constrained environments. This series (based on v6.9-rc1) removes the artificial dependency on MODULES. This permits (but does not require) that architectures which don't use module_alloc() to allocate kprobe insn pages can support kprobes when module support is not enabled. The series deliberately avoids adding a common text allocator, as the requirements for allocating kprobe memory van vary by architecture, and can differ from other text allocations. However, architectures can easily call a common allocator if they wish, and this series does not preclude using common allocators immediately or in future. The key change is in patch 3. This requires that architectures which provide their own alloc function must provide the corresponding free function and select HAVE_KPROBES_ALLOC with any appropriate dependencies for their implementation. Architectures which use the generic functions are left as-is with a dependency on MODULES. The final patch allows the core kprobes code to be built without MODULES, and removes the explicit dependency from Kconfig. This is derived from Jarkko's recent v6 attempt: https://lore.kernel.org/lkml/20240326012102.27438-1-jarkko@kernel.org/ With the series applied, arm64 and riscv can enable KPROBES without MODULES, while powerpc/s390/x86 are still depend on MODULES as their alloc functions currently use module_alloc(), and all other architectures with KPROBES uses the generic implementation that depends on MODULES. I believe it should be relatively easy to enable powerpc/s390/x86 to not depend on MODULES. Mark. Jarkko Sakkinen (1): kprobes: Remove core dependency on modules Mark Rutland (3): arm64: patching: always use fixmap kprobes/treewide: Add kprobes_ prefix to insn alloc/free functions kprobes/treewide: Explicitly override alloc/free functions arch/Kconfig | 5 ++++- arch/arm64/Kconfig | 1 + arch/arm64/kernel/patching.c | 10 +++------ arch/arm64/kernel/probes/kprobes.c | 7 +++++- arch/powerpc/Kconfig | 3 ++- arch/powerpc/kernel/kprobes.c | 7 +++++- arch/powerpc/kernel/optprobes.c | 4 ++-- arch/riscv/Kconfig | 1 + arch/riscv/kernel/probes/kprobes.c | 7 +++++- arch/s390/Kconfig | 3 ++- arch/s390/kernel/kprobes.c | 7 +++++- arch/x86/Kconfig | 3 ++- arch/x86/kernel/kprobes/core.c | 7 +++++- include/linux/kprobes.h | 7 +++--- kernel/kprobes.c | 34 ++++++++++++++++++++---------- kernel/trace/trace_kprobe.c | 15 +++++++++++-- 16 files changed, 87 insertions(+), 34 deletions(-)