From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98E484119E3 for ; Mon, 3 Aug 2026 13:49:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785764971; cv=none; b=MUOrpGvL6d+O4Jr6oSWy+DXdWaRMR6unTH30yavG0N9AMNprR3fL66jFH7ay3qgad06bo/CJ+vlYVwSpvIrilRzWmJ2hKHEL9Ebgd5HpJmcKfSMwMM8p/z87SNdPhSQHB5/tFZYh70ag8aVEkS6jb9t+ZzvYE7qqkX6wvDhOQMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785764971; c=relaxed/simple; bh=2O9xuPa7M9Wg/JUzHTAGgtC+Z2fTnqo72pkpX/N1ms4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=D04q/tCDkthrS2L6jLkGfFnUPpI0ba6/TeIvlEOc76ixyWBmFegeD5GhagOkB0YhmPZjzE2vY6psrqsh4WuMfWTaox467C8qyJF0F2ILluwjQyzLW/NwHTdc1/BEpeQaPzOoxfuGTuMK2IT+67592/Z6pn0Fmh6PFpCDBS19sE0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=ObQnEI3P; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=OhdBUCQ+; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="ObQnEI3P"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="OhdBUCQ+" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 673DRgPL1030704 for ; Mon, 3 Aug 2026 13:49:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=LaA81qaNbrY1YLttx6AnIVlkjw/iQrLtgmE 4RYoHXf4=; b=ObQnEI3PvkDz2oiZxJnfMlhG1B3de4QrfSXH7hxnu1Wf2gHlOj+ yf+l8zzLuVbJjPJt6vg858Cu6TWTx9h5Rr0bzLoRpq7OeJcYJyX6cJJLu6ODYryu upv7oqoozu8jzm4O+QwNQWMZok2KuQvxChAdBUh+Cpy2m1MF5IKURZ5p4qn3tX7F tKZwdHqBwwSou0q5blBfI6xpmUqQMvEuGtcRtcVBiYN1L10bc4HTzUzrBgufWTOK 9nd1g7ZUnbQOHF9zsp0MsFK9XqUdVuETyvAJLCGnX9EY7PuBtDfJn9w2TYkTaME6 Yc1kKgFRWHRDDLv4shR2HSR0BNCufmOClig== Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ftnj79tgf-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 03 Aug 2026 13:49:28 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-38e22137fb3so5501165a91.0 for ; Mon, 03 Aug 2026 06:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1785764967; x=1786369767; 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:content-type; bh=LaA81qaNbrY1YLttx6AnIVlkjw/iQrLtgmE4RYoHXf4=; b=OhdBUCQ+ztzxwH6WLNjLJxjpKxItRdiHwtUXXC0ccS5evoCSwCvFm9cBNzoELDof/T sc5kTsXcMCqKbrRg+K0hfkRxN/PuZ3XmKn2afXTv/ezObNrMNwg/CYqOuLbqhY1sOZ3T hui1TEItYBfCYVTVssfIBx0APyA+ivP6bsoIxcFTsSrnl5pjzaXq/vUqPJCRMeP25GTs 3e1zx+q9Vzf9XcGF3IHsI3/5BtC9KoA1L9pxDjqgF5OHEBVK2Uvy1fFiXkiKp2XuNfr/ Tgwbh55E9W63VOcQmB++ClOplm9Zr9/1/IuQdDx9AzsfBkaObDfYob3P5W5d2diCmEuq XKyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785764967; x=1786369767; 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:content-type; bh=LaA81qaNbrY1YLttx6AnIVlkjw/iQrLtgmE4RYoHXf4=; b=UjTP6X2oBezUHluLeHV+ulGawPDVZYsX6hijMQnxuocAiUu0v0eJ/g0UByu+wsZzMs LXxca3RWnOtTNPbUo040mpCAEAmobqabSLyC3gS4d8MRvxFFEi1A0FEvS13jPwbeRBUy NSbva0yg164uveUDo2Blk4w/aiPE8B4prq7JJODb8PwPr3MfFviDuDmRi9Y//N0kwZsK WobgXOVhwWFyVqn0Tm1Rccn/6xWLJxTqVKCbEO38NaFP9DMMF57VVVLlDOl/+Cie4H0X a0FtfaQdefNcy2fG1c0jP3jTD2EfREC44s5stlFNge/iJkx+7dJq9XNWCqiD/YTUFmff nUJQ== X-Forwarded-Encrypted: i=1; AHgh+RoQvPthCUq3ssFsLz5gU25sNUtyNKezdSegcBlNu+pfU71L/LpdOn0aBxIenrM3Cf50uiYKj0l5QtCfVFg=@vger.kernel.org X-Gm-Message-State: AOJu0YwritEGrKb1rSstuPiQHHAU8rnUnEpryJkcml0UaIgRfwY1VqiD LqDsNnX5q+7H1GJzyg1pgAH0i83wW2Qj2m0DIuKUNa7bHLkmgnWNLDegTgrRGCpMiJpk4bEtyQ5 ZZt9en2SYOxp5SDzIVXG6hJR5GLHMBMumzIvkMD+WOoUoNkesMfPWWn2slbjMYyZBgW4NOzMKtL c= X-Gm-Gg: AR+sD102ZxZ89NpX4SsKhUO1ynfVZgACspgXJRCyeywT/c0/e3D2zF+KVs4nkw7c8KT Nyn2+gcbVx1J9l1xgatJSnSDA8OFjzVjNYgUl1XvnkCCRth84Uz3tMuLm2Er8rd/oF8283gnsI6 1i9is5rK4JH3kK7X/xoxG7ehp1FFWRs7Iw40znPPUOxdVT+BHLPzsGuqX3+jD7pHziyg1bnKXnz Rm5k/Zl2y0tx/WtsiOnqSe8A0rIM4rKWcEyh8WWM2iP6aG9DLVJ49HoS1tXdHpo+amG2s36scX+ qVogCk3Wasbwss1dlSTCikXWVc1z6FzvDvnRRtx0kU9o39w8w2iC+2NsxRMmi82T/S/zdmAtFGx +E6gXC30flexeswkfrrSk/2CqOQJOfRWce9qbMXb/DD5T6zA/9+opU+r5RAycUoML0TT7NousnC PjK2lOkydkwd0+tila8pA904mq X-Received: by 2002:a17:90b:4c51:b0:38d:c0f9:30be with SMTP id 98e67ed59e1d1-38fbc5bd83bmr9000690a91.38.1785764967112; Mon, 03 Aug 2026 06:49:27 -0700 (PDT) X-Received: by 2002:a17:90b:4c51:b0:38d:c0f9:30be with SMTP id 98e67ed59e1d1-38fbc5bd83bmr9000649a91.38.1785764966565; Mon, 03 Aug 2026 06:49:26 -0700 (PDT) Received: from hu-himchau-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153e18d9c6sm39278870eec.30.2026.08.03.06.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 06:49:26 -0700 (PDT) From: Himanshu Chauhan To: linux-riscv@lists.infradead.org Cc: qingfang.deng@linux.dev, alex@ghiti.fr, aou@eecs.berkeley.edu, palmer@dabbelt.com, pjw@kernel.org, shuah@kernel.org, linux-kernel@vger.kernel.org, thecharlesjenkins@gmail.com, jtaubepe@redhat.com, Himanshu Chauhan Subject: [PATCH v6 0/5] riscv: Introduce support for hardware break/watchpoints Date: Mon, 3 Aug 2026 19:19:08 +0530 Message-ID: <20260803134913.2013674-1-himanshu.chauhan@oss.qualcomm.com> X-Mailer: git-send-email 2.43.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 X-Proofpoint-ORIG-GUID: BjldxnrF_eCj86h54Unqp7qCicDxlRMF X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODAzMDEyNCBTYWx0ZWRfXycG2jvfsm/Hl 3JKbVvryec0kCNMcR7NznX7k92l5k9QUZiFZ6065kUZ7oEC34ovYTm+25v2Hjb1LW6e9NJn9QWW NYuKm2opK6GbvDNZUfX6ZXqw7i2xVEi22UWWFv0vG5bOlFMI18/eFpu8g8Ffv5bQhXMg7C2C6Rm NpQbsmBvowk8zutKT60eCrgcu5qqGqIXfjfuvyFEoSzJaRJ8jQM2MZrf8iMaPm455txJWb7KLSt 6GNLcDbHLkrMGXdw7OwXMgijGv06uzPFUPYpPBagh5lynpGG2uGIiiC6CYmFeKf0ir6MwpINbDN 0Dlhr56zosv6IIm4TNRzCBYaxhvfPR/IwZDcKMw4SqBJevmhqik0jOkgU0a2lDggywuQeG0tGtC Zm0fUJhrGDtHSVw+hSUMqwMACOZJr3J/rogpNhJyg0FBz5ml919b4SFb3GPLFOgeksMXVfdYMly WdiM18rT1muc0D+wT6g== X-Proofpoint-GUID: BjldxnrF_eCj86h54Unqp7qCicDxlRMF X-Authority-Analysis: v=2.4 cv=PqSjqQM3 c=1 sm=1 tr=0 ts=6a709c68 cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=V1jnuoLLAAAA:20 a=NEAV23lmAAAA:8 a=Gr54bvSM7lryjJAaCBAA:9 a=rl5im9kqc5Lf4LNbBjHf:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-Spam-Info: AW1haW4tMjYwODAzMDEyNCBTYWx0ZWRfX6NqzLiu9nV6E u2Rzyz0crEn0XSlisT13zExNU/CqALFxaEDRY4gm7hQHPV89fvYDxOM2RUEGUGSrizaCh2ZlfuZ y5QBPEzBv3qwOwb0FE4p3xCSeJ61H8A= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-03_03,2026-08-03_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 spamscore=0 priorityscore=1501 adultscore=0 clxscore=1015 impostorscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608030124 This patchset adds support for hardware breakpoints and watchpoints in the RISC-V architecture. The framework is built on top of the perf subsystem and the SBI debug trigger extension (Sdtrig). v6 extends v5 with two new patches: - ptrace support: debuggers can now set and query hardware debug triggers through the standard PTRACE_GETREGSET/SETREGSET interface using new NT_RISCV_HW_BREAK/WATCH note types. A simpler PTRACE_GETHBPREGS/SETHBPREGS request pair is also provided for direct single-trigger access without going through the regset machinery. Thread flush/copy hooks are wired up so per-task breakpoints are cleaned up across fork/exec. - Extended selftest: the existing perf_event-based selftest is extended to also exercise the new ptrace GETREGSET/SETREGSET regset path and the raw PTRACE_GETHBPREGS/SETHBPREGS interface. Single stepping is ready and test but to follow this patch set. Virtualization of debug triggers are pending The SBI debug trigger extension is specified in Chapter 19 of the SBI specification: https://github.com/riscv-non-isa/riscv-sbi-doc/releases/download/v3.0/riscv-sbi.pdf The Sdtrig ISA is part of the RISC-V debug specification: https://github.com/riscv/riscv-debug-spec Changes from v5: - Rebased to v7.2-rc6 - Simplified Macros in hw_breakpoint.h - Took care of the review comments - Added ptrace support for hardware break/watchpoints (new patch) - PTRACE_GETREGSET/SETREGSET via NT_RISCV_HW_BREAK / NT_RISCV_HW_WATCH - PTRACE_GETHBPREGS / SETHBPREGS for direct single-trigger access - HAVE_MIXED_BREAKPOINTS_REGS selected (break/watch share trigger pool) - flush_ptrace_hw_breakpoint / ptrace_hw_copy_thread wired up - Extended selftest to cover ptrace-based hw break/watchpoint paths (new patch) Changes from v4: - Rebased to v7.2-rc4 - Fixed rv32 build error - Added pr_fmt to print KBUILD_MODNAME - Changed type of shmem_pa to phys_addr_t - Use per_cpu_ptr_to_phys instead of __pa for per-cpu allocated memory - Print successful registration/unregistration message when no error - Added RISC-V DEBUGGING section in MAINTAINERS and added myself as maintainer - Fixed warnings from checkpatch.pl --strict run Changes from v3: - Rebased to v7.1-rc3 - For watchpoints, check tdata1.hit via SBI_EXT_DBTR_TRIG_READ and keep STVAL-based matching as fallback - Improved watchpoint matching when STVAL reports the lowest accessed address for wider memory accesses - Program execute breakpoints with SIZE=0 (match any size) to avoid misses with 16-bit/compressed instruction addresses - Updated selftest to avoid deadlock by replacing unbounded sem_wait() with sem_timedwait() timeout handling - Updated selftest breakpoint function so it cannot be inlined or optimized away Changes from v2: - Rebased to v7.0-rc1 - Fixed warnings from checkpatch.pl --strict run Changes from v1: - The patch adding the SBI extension and function IDs is already merged; this series builds on top of that - Added breakpoint selftest in tools/testing/selftests/breakpoints/ How to use: ~~~~~~~~~~~ OpenSBI: https://github.com/riscv-software-src/opensbi.git QEMU: https://github.com/qemu/qemu.git Linux Kernel: Apply these patches on top of v7.2-rc6. How to test: ~~~~~~~~~~~ >From the Linux kernel directory, first install the UAPI headers (required on a fresh tree so the compiler can locate and the new NT_RISCV_HW_BREAK/WATCH definitions via KHDR_INCLUDES): make headers Then build the selftest: make -C tools/testing/selftests/breakpoints/ This produces breakpoint_test_riscv under the same directory. Load it on the target and run. Sample output: # /apps/breakpoint_test_riscv # [perf_event]: Breakpoint test passed! # [perf_event]: Watchpoint test passed! # [ptrace]: Breakpoint test passed! # ptrace(PTRACE_GETREGSET): Number of watchpoints: 2 # ptrace(PTRACE_GETREGSet): addr: 0x82888 control: 0x8080 # [ptrace]: Watchpoint test passed! # [hbpregs] breakpoint readback: addr=0x10472 type=4 len=4 ctrl=0 # [hbpregs]: Breakpoint test passed! # [hbpregs] watchpoint readback: addr=0x82888 type=2 len=8 ctrl=0 # [hbpregs]: Watchpoint test passed! Himanshu Chauhan (5): riscv: Introduce support for hardware break/watchpoints riscv: Add breakpoint and watchpoint test for riscv riscv: ptrace support for hardware break/watchpoints selftests/breakpoints: extend riscv test for ptrace hw break/watchpoints MAINTAINERS: Add entry for RISC-V Debugging MAINTAINERS | 9 + arch/riscv/Kconfig | 2 + arch/riscv/include/asm/hw_breakpoint.h | 299 +++++++ arch/riscv/include/asm/kdebug.h | 3 +- arch/riscv/include/asm/processor.h | 18 + arch/riscv/include/uapi/asm/ptrace.h | 53 ++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/hw_breakpoint.c | 677 ++++++++++++++++ arch/riscv/kernel/process.c | 5 + arch/riscv/kernel/ptrace.c | 507 ++++++++++++ arch/riscv/kernel/traps.c | 6 + include/uapi/linux/elf.h | 4 + tools/include/uapi/linux/elf.h | 2 + tools/testing/selftests/breakpoints/Makefile | 5 + .../breakpoints/breakpoint_test_riscv.c | 765 ++++++++++++++++++ 15 files changed, 2355 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/include/asm/hw_breakpoint.h create mode 100644 arch/riscv/kernel/hw_breakpoint.c create mode 100644 tools/testing/selftests/breakpoints/breakpoint_test_riscv.c -- 2.43.0