From patchwork Wed Apr 3 15:01:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13616296 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 ED661CD1288 for ; Wed, 3 Apr 2024 15:02:26 +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=4NwtLpgZ9VVD1ujREUW9chKZlRZAy+1o4tJr8AVsu3I=; b=F7KpSwOMkeJT9Q EM7Be+TNTbiZ0r/kkzhdbgT76v1YFkpDKtFAEptAr52ZNXMKVMlWwUHblb9rDIe2etH9sTnTIpVZA nQisLAPB32rr6OHvpsLLfO5CllbHVdtMaCNKGY1WjEC8eZsYS2UXLXZt1RJ5E/afyO58w8OFfSx8x 5t0mMgc7zV+V1onjNVVuJDRlrWecoSgrNLJsNFhUoJGVSiMpfpTMwNaRTd4sC+NN4sY8CkqF1izQG YmpzFS74TTX1Uknygc+I0QM1sFctLxxiax6jAX5pw+qF1W3FbLE0CkWgAtXq9LqkuvG93dQnK/CUQ aCv9Sq/0VW6HuiIaTTMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rs27s-0000000GbAr-1Q1N; Wed, 03 Apr 2024 15:02:08 +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 1rs27p-0000000Gb98-04rE for linux-arm-kernel@lists.infradead.org; Wed, 03 Apr 2024 15:02:06 +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 E6C481007; Wed, 3 Apr 2024 08:02:32 -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 423483F7B4; Wed, 3 Apr 2024 08:02:00 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: anil.s.keshavamurthy@intel.com, aou@eecs.berkeley.edu, catalin.marinas@arm.com, davem@davemloft.net, jarkko@kernel.org, linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, mhiramat@kernel.org, naveen.n.rao@linux.ibm.com, palmer@dabbelt.com, paul.walmsley@sifive.com, will@kernel.org Subject: [PATCH v2 0/4] kprobes: permit use without modules Date: Wed, 3 Apr 2024 16:01:50 +0100 Message-Id: <20240403150154.667649-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-20240403_080205_453598_81029A26 X-CRM114-Status: GOOD ( 15.69 ) 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. Since v1 [1]: * Rebase to v6.9-rc2 (trivial) * Update to Jarkko's v7 cleanups for core kprobes * Fix accidental use of KPROBES_USE_MODULE_ALLOC * Improve commit messages * Update Cc lists [1] https://lore.kernel.org/lkml/20240326163624.3253157-1-mark.rutland@arm.com/ 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 | 68 +++++++++++++++++------------- kernel/trace/trace_kprobe.c | 15 ++++++- 16 files changed, 103 insertions(+), 52 deletions(-)