From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 248AA25A321 for ; Tue, 7 Apr 2026 18:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775588294; cv=none; b=QVUTu5lnhKM1PGrljEijt6inok0f+Uktkl/0aHMKKTrHpKqi00UOiRRSl4LpdHEX5Di+2Eepyw+pF6Wu7PIb6MkxT/nDbcgxH9AhBlqhOrnNN5x5gIHWayV+00Piw6cPZkDkG3DaBYpS8pTYiiX00Pk9hvqvkhHp2eu6jF8J2N4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775588294; c=relaxed/simple; bh=GR45AI0o78Ytejg5IdSf+fIb6OLzz6uoIIPfDIjeIWQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=qMG/2pVEn5QB2GkesXM/Kfge9eF/sJLIpyC/gBQGDjJk7ZuUz/kd9MDPguHwvVDscopIDRzTDNn8yrSGyT6TbQIwT64Egb/kSLVeVwj8QLS1jaU8kjfL4I2fZJDNsCRXKnLWGK+bMnzQsLx0X2FXEooLtsENithQgsyI5d0ihyM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TqzCghp1; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TqzCghp1" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2ad617d5b80so29110395ad.1 for ; Tue, 07 Apr 2026 11:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775588291; x=1776193091; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=55j8IddnRN/mRx9o2IbvUofVTQLK3O2pOkhg4YsKhUY=; b=TqzCghp1D07Nx9ZaCp8ExzNn+ctR7LJEXe0LvE82b5XZkCOvFt7Q+ioGY82mDH/wWD Zd3/aJu9CSCKQ5AbDWkbROC2/I7xNnmZHVeTdGu3DL3gITuDiB0BgFyJkDnTLvy8jYG/ e/0FDW93NOC8Qjo8jvlBu69oDUGRFSfrq4nZVBaVAe85UnCYsCtgtYKdeP6CkJ79rn0U lRCOHny/o2ZqtoEbuss8SlGVxHWym9o/VQfG1Hh1Rq7R9Ix12tHlDYQdkAGqaikPpDCP q/XpYe4z7SEcYFQb67VDjNGU1DIffnqA7Hc3ICEc+/oMTv5rjYL+efaF3CxWeOCL8VUi p09g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775588291; x=1776193091; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=55j8IddnRN/mRx9o2IbvUofVTQLK3O2pOkhg4YsKhUY=; b=qn87QIDeR5wU6FMWx7rWJipeoIOpcBOR4ihaXRm8ZmPYFpZS41OJXVDL7Q/L07nQZ+ Rs61v8qlLPNDRhl09wAVri1b5JBjCj0+ZpTUeitIxlBkFEhVvjXQeqwy5wXj+KZgOwSn 8b946Yx31VDgR1HvYSUtm1L7mwp25UIjKWn3UmmE5vsyJoI7kYChp/XGo1hxvwcfYVO1 21eJuWBjGlOukvcg4dZDjAKIEizJGi9jvasQEigJYghUrIzagXB8UCygpBxXLT6WSUnN XwazyGUHw3PxMg88UEOSn4nTwvm89NWj+RcZAd3Eny43MUo34QnEWbk36FuWw6CSGapU O2Lw== X-Forwarded-Encrypted: i=1; AJvYcCVMOqD0QK3oAH2OSM0lzpKAwgSD/f59BUTn6O6iYwvTvPYY3NS1OkS2wtX+gm73cCnqeg3zW4Ech48BnuA=@vger.kernel.org X-Gm-Message-State: AOJu0YzPUMqVuxuAudQe9vwSIxOVX5Z928SnZX/m3TdbD4WS2OTQWw8P U5GXl7WI2c4uykJpU3Mo2IT8L+AeeW/F5yjf30ik7nn1zhVaW51gbFsNnkZl8Hx9 X-Gm-Gg: AeBDietiC2VGLqUKitrAI4t/000La0+imYiuyviPntYEx+uwmZ/5IHQBVottLJR8k2R G6XB5pvx0yvnuvyI9WiuG+J9xycqDmcgC4jnwY8UHqLM1zg0/4wfe6q30DNGmFjgmgYKruU77nZ zR+KdJXvvMvcu+X7gMraBh1FsbARgrlsW+uSzpBgTZGoOBdsf7j+ny0Qr11cvdge7EJ2HKrtMUD pLLwAk3TLWMAUew1avBLHDKKRGQ3P9/g/yT6+jI2I5WC+NKirjkbxHPTrCdV5/6Y/UwM68Nyxm8 Sai/VYezUlXQhlv5Je5emhVe2+lGlndaixQ7UcgIVDf9r8TmYmdpGwnMZ8Ai3NpTEQ3JlHwCBKV mgsDE74JxAzeXfPtugtGvJm+6BP+IfnEELFSt5HUS1OWXz1jhgVYxYHldfDD3utJizo7mdft2kI CRatYVi2m+niaID13ekaJHkbg+SA2ORQI= X-Received: by 2002:a17:903:22c5:b0:2b2:a6a2:c8ca with SMTP id d9443c01a7336-2b2a6a2ca50mr73961255ad.13.1775588291250; Tue, 07 Apr 2026 11:58:11 -0700 (PDT) Received: from valdaarhun.localdomain ([2401:4900:1c45:a41c:c2d5:268a:232e:d07e]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b2749ce29esm193486145ad.81.2026.04.07.11.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 11:58:10 -0700 (PDT) From: Sahil Siddiq To: jonas@southpole.se, stefan.kristiansson@saunalahti.fi, shorne@gmail.com, naveen@kernel.org, davem@davemloft.net, mhiramat@kernel.org Cc: peterz@infradead.org, jpoimboe@kernel.org, jbaron@akamai.com, rostedt@goodmis.org, ardb@kernel.org, chenmiao.ku@gmail.com, johannes@sipsolutions.net, nsc@kernel.org, masahiroy@kernel.org, tytso@mit.edu, linux-openrisc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Sahil Siddiq Subject: [RFC 0/2] openrisc: Add support for KProbes Date: Wed, 8 Apr 2026 00:26:48 +0530 Message-ID: <20260407185650.79816-1-sahilcdq0@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi, This series adds basic support for KProbes on OpenRISC. There are a few changes that I would still like to add and test before this can be considered for merging. I was hoping to get some feedback on the changes made so far. The implementation in this series is based on KProbes for LoongArch, MIPS and RISC-V. The current state of the series allows traps to be inserted dynamically in the kernel. A KProbe can be inserted via a kernel module whose init/exit functions are used to register/unregister a KProbe. A pre- handler and post-handler can also be provisioned in the module, which are associated with the KProbe and triggered when the probe is hit. See the documentation on KProbes for a detailed explanation [1]. The following are yet to be implemented for OpenRISC: 1. kretprobes 2. kprobe-based event tracing 3. ftrace, and kprobe features that depend on ftrace (particularly, dynamic tracing) I hope to submit a patch for kretprobes soon (possibly in a revision of this series). I wrote a couple of kernel modules to test these changes. They can be found here [2]. I also ran test_kprobes located at ./lib/tests/ against these changes [3]. The results are as shown below: /home # insmod test_kprobes.ko KTAP version 1 1..1 KTAP version 1 # Subtest: kprobes_test # module: test_kprobes 1..3 ok 1 test_kprobe ok 2 test_kprobes ok 3 test_kprobe_missed # kprobes_test: pass:3 fail:0 skip:0 total:3 # Totals: pass:3 fail:0 skip:0 total:3 ok 1 kprobes_test /home # When compiling the kernel, the following options should be enabled: 1. CONFIG_HAVE_KPROBES=y 2. CONFIG_KPROBES=y Also ensure that CONFIG_KPROBE_EVENTS is disabled. To compile /lib/tests/test_kprobes.c, add the following to .config: 1. CONFIG_KUNIT=y 2. CONFIG_DEBUG_KERNEL=y 3. CONFIG_KPROBES_SANITY_TEST=m The first commit cleans up and reorganizes existing functions, fixes a few issues with instruction simulation, and introduces new structures and macros that will be used by KProbes and other tracing facilities in the future. The second commit adds support for KProbes. Currently, I have implemented this in such a way that KProbes can't be used to probe a few "blacklisted" instructions. Probes can't be inserted in a delay slot either (similar to MIPS). I have also added a few asm functions to the blacklist that I think should not be probed. For e.g., "memset" and "_trap_handler" have been blacklisted because probing them causes the kernel to hang. However, I am not sure if other functions in "entry.S" need to be added as well to the blacklist. Thanks, Sahil [1] https://www.kernel.org/doc/html/latest/trace/kprobes.html [2] https://github.com/valdaarhun/or-dev/tree/main/home [3] https://github.com/openrisc/linux/blob/for-next/lib/tests/test_kprobes.c Sahil Siddiq (2): openrisc: Add utilities and clean up simulation of instructions openrisc: Add KProbes arch/openrisc/Kconfig | 1 + arch/openrisc/configs/or1ksim_defconfig | 2 + arch/openrisc/configs/virt_defconfig | 2 + arch/openrisc/include/asm/asm.h | 22 ++ arch/openrisc/include/asm/break.h | 19 ++ arch/openrisc/include/asm/insn-def.h | 61 +++- arch/openrisc/include/asm/kprobes.h | 76 +++++ arch/openrisc/include/asm/spr_defs.h | 1 + arch/openrisc/kernel/Makefile | 3 +- arch/openrisc/kernel/entry.S | 16 + arch/openrisc/kernel/insn.c | 74 +++++ arch/openrisc/kernel/jump_label.c | 2 +- arch/openrisc/kernel/kprobes.c | 381 ++++++++++++++++++++++++ arch/openrisc/kernel/traps.c | 67 ++--- arch/openrisc/lib/memcpy.c | 2 + arch/openrisc/lib/memset.S | 4 + arch/openrisc/mm/fault.c | 5 + samples/kprobes/kprobe_example.c | 8 + 18 files changed, 701 insertions(+), 45 deletions(-) create mode 100644 arch/openrisc/include/asm/asm.h create mode 100644 arch/openrisc/include/asm/break.h create mode 100644 arch/openrisc/include/asm/kprobes.h create mode 100644 arch/openrisc/kernel/insn.c create mode 100644 arch/openrisc/kernel/kprobes.c -- 2.53.0