Skip to contentSkip to conversation

riscv: Introduce support for hardware break/watchpoints

PATCH In review Himanshu Chauhan 3 participants 8 messages Jul 10, 2025 – Nov 27, 2025 RISC-V

lore
Share & tools
lore
#0 lore raw

cover riscv: Introduce support for hardware break/watchpoints

This patchset adds support of hardware breakpoints and watchpoints in RISC-V architecture. The framework is built on top of perf subsystem and SBI debug trigger extension.

Currently following features are not supported and are in works:
- Ptrace support
- Single stepping
- Virtualization of debug triggers

The SBI debug trigger extension proposal can be found in Chapter-19 of SBI specification:
https://github.com/riscv-non-isa/riscv-sbi-doc/releases/download/v3.0-rc8/riscv-sbi.pdf

The Sdtrig ISA is part of RISC-V debug specification which can be found at:
https://github.com/riscv/riscv-debug-spec

Himanshu Chauhan (2):
riscv: Add SBI debug trigger extension and function ids
riscv: Introduce support for hardware break/watchpoints

 arch/riscv/Kconfig                     |   1 +
 arch/riscv/include/asm/hw_breakpoint.h | 320 ++++++++++++
 arch/riscv/include/asm/kdebug.h        |   3 +-
 arch/riscv/include/asm/sbi.h           |  29 ++
 arch/riscv/kernel/Makefile             |   1 +
 arch/riscv/kernel/hw_breakpoint.c      | 657 +++++++++++++++++++++++++
 arch/riscv/kernel/traps.c              |   6 +
 7 files changed, 1016 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/include/asm/hw_breakpoint.h
 create mode 100644 arch/riscv/kernel/hw_breakpoint.c
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/2 riscv: Add SBI debug trigger extension and function ids

Debug trigger extension is an SBI extension to support native debugging in S-mode and VS-mode. This patch adds the extension and the function IDs defined by the extension.

---
 arch/riscv/include/asm/sbi.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
arch/riscv/include/asm/sbi.h +29 -0
index 341e74238aa0..d1d906bc5365 100644
@@ -36,6 +36,7 @@ enum sbi_ext_id {
 	SBI_EXT_STA = 0x535441,
 	SBI_EXT_NACL = 0x4E41434C,
 	SBI_EXT_FWFT = 0x46574654,
+	SBI_EXT_DBTR = 0x44425452,
 
 	/* Experimentals extensions must lie within this range */
 	SBI_EXT_EXPERIMENTAL_START = 0x08000000,
@@ -430,6 +431,34 @@ enum sbi_fwft_feature_t {
 
 #define SBI_FWFT_SET_FLAG_LOCK			BIT(0)
 
+/* SBI debug triggers function IDs */
+enum sbi_ext_dbtr_fid {
+	SBI_EXT_DBTR_NUM_TRIGGERS = 0,
+	SBI_EXT_DBTR_SETUP_SHMEM,
+	SBI_EXT_DBTR_TRIG_READ,
+	SBI_EXT_DBTR_TRIG_INSTALL,
+	SBI_EXT_DBTR_TRIG_UPDATE,
+	SBI_EXT_DBTR_TRIG_UNINSTALL,
+	SBI_EXT_DBTR_TRIG_ENABLE,
+	SBI_EXT_DBTR_TRIG_DISABLE,
+};
+
+struct sbi_dbtr_data_msg {
+	unsigned long tstate;
+	unsigned long tdata1;
+	unsigned long tdata2;
+	unsigned long tdata3;
+};
+
+struct sbi_dbtr_id_msg {
+	unsigned long idx;
+};
+
+union sbi_dbtr_shmem_entry {
+	struct sbi_dbtr_data_msg data;
+	struct sbi_dbtr_id_msg id;
+};
+
 /* SBI spec version fields */
 #define SBI_SPEC_VERSION_DEFAULT	0x1
 #define SBI_SPEC_VERSION_MAJOR_SHIFT	24
Signature · 1 line
2.45.2
maintainer
#2 lore raw

Re: [PATCH v1 1/2] riscv: Add SBI debug trigger extension and function ids

Quoted 5 lines · Himanshu Chauhan

Debug trigger extension is an SBI extension to support native debugging in S-mode and VS-mode. This patch adds the extension and the function IDs defined by the extension.

Thanks, queued for v6.19.

- Paul

#3 lore raw

PATCH 2/2 riscv: Introduce support for hardware break/watchpoints

In reply to Himanshu Chauhan

RISC-V hardware breakpoint framework is built on top of perf subsystem and uses SBI debug trigger extension to install/uninstall/update/enable/disable hardware triggers as specified in Sdtrig ISA extension.

---
 arch/riscv/Kconfig                     |   1 +
 arch/riscv/include/asm/hw_breakpoint.h | 320 ++++++++++++
 arch/riscv/include/asm/kdebug.h        |   3 +-
 arch/riscv/kernel/Makefile             |   1 +
 arch/riscv/kernel/hw_breakpoint.c      | 657 +++++++++++++++++++++++++
 arch/riscv/kernel/traps.c              |   6 +
 6 files changed, 987 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/include/asm/hw_breakpoint.h
 create mode 100644 arch/riscv/kernel/hw_breakpoint.c
arch/riscv/Kconfig +1 -0
index d71ea0f4466f..741c8765724e 100644
@@ -169,6 +169,7 @@ config RISCV
 	select HAVE_FUNCTION_ERROR_INJECTION
 	select HAVE_GCC_PLUGINS
 	select HAVE_GENERIC_VDSO if MMU && 64BIT
+	select HAVE_HW_BREAKPOINT if PERF_EVENTS
 	select HAVE_IRQ_TIME_ACCOUNTING
 	select HAVE_KERNEL_BZIP2 if !XIP_KERNEL && !EFI_ZBOOT
 	select HAVE_KERNEL_GZIP if !XIP_KERNEL && !EFI_ZBOOT
arch/riscv/include/asm/hw_breakpoint.h new file +320 -0

320 lines not on this page · raw message

arch/riscv/include/asm/kdebug.h +2 -1
index 85ac00411f6e..53e989781aa1 100644
@@ -6,7 +6,8 @@
 enum die_val {
 	DIE_UNUSED,
 	DIE_TRAP,
-	DIE_OOPS
+	DIE_OOPS,
+	DIE_DEBUG
 };
 
 #endif
arch/riscv/kernel/Makefile +1 -0
index c7b542573407..39a3489bd9e2 100644
@@ -98,6 +98,7 @@ obj-$(CONFIG_DYNAMIC_FTRACE)	+= mcount-dyn.o
 
 obj-$(CONFIG_PERF_EVENTS)	+= perf_callchain.o
 obj-$(CONFIG_HAVE_PERF_REGS)	+= perf_regs.o
+obj-$(CONFIG_HAVE_HW_BREAKPOINT)	+= hw_breakpoint.o
 obj-$(CONFIG_RISCV_SBI)		+= sbi.o sbi_ecall.o
 ifeq ($(CONFIG_RISCV_SBI), y)
 obj-$(CONFIG_SMP)		+= sbi-ipi.o
arch/riscv/kernel/hw_breakpoint.c new file +657 -0

657 lines not on this page · raw message

arch/riscv/kernel/traps.c +6 -0
index 9c83848797a7..cc8ef120ff41 100644
@@ -288,6 +288,12 @@ void handle_break(struct pt_regs *regs)
 	if (probe_breakpoint_handler(regs))
 		return;
 
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+	if (notify_die(DIE_DEBUG, "EBREAK", regs, 0, regs->cause, SIGTRAP)
+	    == NOTIFY_STOP)
+		return;
+#endif
+
 	current->thread.bad_cause = regs->cause;
 
 	if (user_mode(regs))
Signature · 1 line
2.45.2
#4 lore raw
kernel test robot noticed the following build warnings:

Hi Himanshu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.16-rc5 next-20250710]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Himanshu-Chauhan/riscv-Add-SBI-debug-trigger-extension-and-function-ids/20250710-205738
base:   linus/master
patch link:    https://lore.kernel.org/r/20250710125231.653967-3-hchauhan%40ventanamicro.com
patch subject: [PATCH v1 2/2] riscv: Introduce support for hardware break/watchpoints
config: riscv-randconfig-r071-20250711 (https://download.01.org/0day-ci/archive/20250711/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250711/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

from ./arch/riscv/include/generated/asm/local64.h:1,
from include/linux/perf_event.h:26,
from include/linux/hw_breakpoint.h:5,
from arch/riscv/kernel/hw_breakpoint.c:6:
arch/riscv/kernel/hw_breakpoint.c: In function 'arch_update_hw_breakpoint':
include/linux/percpu-defs.h:220:52: error: invalid use of undefined type 'union sbi_dbtr_shmem_entry'

     220 |  const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL; \
         |                                                    ^
   include/linux/percpu-defs.h:263:2: note: in expansion of macro '__verify_pcpu_ptr'
     263 |  __verify_pcpu_ptr(ptr);      \
         |  ^~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:267:26: note: in expansion of macro 'per_cpu_ptr'
     267 | #define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
         |                          ^~~~~~~~~~~
   include/linux/percpu-defs.h:268:27: note: in expansion of macro 'raw_cpu_ptr'
     268 | #define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
         |                           ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:536:38: note: in expansion of macro 'this_cpu_ptr'
     536 |  union sbi_dbtr_shmem_entry *shmem = this_cpu_ptr(sbi_dbtr_shmem);
         |                                      ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:539:16: error: storage size of 'ret' isn't known
     539 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c:557:15: error: invalid use of undefined type 'union sbi_dbtr_shmem_entry'
     557 |  xmit = &shmem->data;
         |               ^~
   arch/riscv/kernel/hw_breakpoint.c:558:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     558 |  xmit->tdata1 = cpu_to_le(bp->tdata1);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:559:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     559 |  xmit->tdata2 = cpu_to_le(bp->tdata2);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:560:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     560 |  xmit->tdata3 = cpu_to_le(bp->tdata3);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:562:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     562 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_UPDATE,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:562:32: error: 'SBI_EXT_DBTR_TRIG_UPDATE' undeclared (first use in this function)
     562 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_UPDATE,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:539:16: warning: unused variable 'ret' [-Wunused-variable]
     539 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_disable_hw_breakpoint':
   arch/riscv/kernel/hw_breakpoint.c:574:16: error: storage size of 'ret' isn't known
     574 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c:589:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     589 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_DISABLE,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:589:32: error: 'SBI_EXT_DBTR_TRIG_DISABLE' undeclared (first use in this function)
     589 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_DISABLE,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:574:16: warning: unused variable 'ret' [-Wunused-variable]
     574 |  struct sbiret ret;
         |                ^~~
   In file included from include/linux/percpu.h:5,
                    from include/asm-generic/local64.h:5,
                    from ./arch/riscv/include/generated/asm/local64.h:1,
                    from include/linux/perf_event.h:26,
                    from include/linux/hw_breakpoint.h:5,
                    from arch/riscv/kernel/hw_breakpoint.c:6:
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_hw_breakpoint_init':
   arch/riscv/kernel/hw_breakpoint.c:634:40: error: invalid application of 'sizeof' to incomplete type 'union sbi_dbtr_shmem_entry'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                                        ^
   include/linux/alloc_tag.h:239:9: note: in definition of macro 'alloc_hooks_tag'
     239 |  typeof(_do_alloc) _res;      \
         |         ^~~~~~~~~
   include/linux/percpu.h:142:2: note: in expansion of macro 'alloc_hooks'
     142 |  alloc_hooks(pcpu_alloc_noprof(_size, _align, false, GFP_KERNEL))
         |  ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:634:19: note: in expansion of macro '__alloc_percpu'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                   ^~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:634:40: error: invalid application of 'sizeof' to incomplete type 'union sbi_dbtr_shmem_entry'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                                        ^
   include/linux/alloc_tag.h:243:10: note: in definition of macro 'alloc_hooks_tag'
     243 |   _res = _do_alloc;     \
         |          ^~~~~~~~~
   include/linux/percpu.h:142:2: note: in expansion of macro 'alloc_hooks'
     142 |  alloc_hooks(pcpu_alloc_noprof(_size, _align, false, GFP_KERNEL))
         |  ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:634:19: note: in expansion of macro '__alloc_percpu'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                   ^~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:634:40: error: invalid application of 'sizeof' to incomplete type 'union sbi_dbtr_shmem_entry'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                                        ^
   include/linux/alloc_tag.h:246:10: note: in definition of macro 'alloc_hooks_tag'
     246 |   _res = _do_alloc;     \
         |          ^~~~~~~~~
   include/linux/percpu.h:142:2: note: in expansion of macro 'alloc_hooks'
     142 |  alloc_hooks(pcpu_alloc_noprof(_size, _align, false, GFP_KERNEL))
         |  ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:634:19: note: in expansion of macro '__alloc_percpu'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                   ^~~~~~~~~~~~~~
>> arch/riscv/kernel/hw_breakpoint.c:634:17: warning: assignment to 'union sbi_dbtr_shmem_entry *' from 'int' makes pointer from integer without a cast [-Wint-conversion]

634 | sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
| ^
cc1: some warnings being treated as errors

vim +634 arch/riscv/kernel/hw_breakpoint.c

613
614 static int __init arch_hw_breakpoint_init(void)
615 {
616 unsigned int cpu;
617 int rc = 0;
618
619 for_each_possible_cpu(cpu)
620 raw_spin_lock_init(&per_cpu(ecall_lock, cpu));
621
622 if (!dbtr_init)
623 init_sbi_dbtr();
624
625 if (dbtr_total_num) {
626 pr_info("%s: total number of type %d triggers: %u\n",
627 __func__, dbtr_type, dbtr_total_num);
628 } else {
629 pr_info("%s: No hardware triggers available\n", __func__);
630 goto out;
631 }
632
633 /* Allocate per-cpu shared memory */

 > 634		sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw
In reply to Himanshu Chauhan
kernel test robot noticed the following build errors:

Hi Himanshu,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.16-rc5 next-20250710]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Himanshu-Chauhan/riscv-Add-SBI-debug-trigger-extension-and-function-ids/20250710-205738
base:   linus/master
patch link:    https://lore.kernel.org/r/20250710125231.653967-3-hchauhan%40ventanamicro.com
patch subject: [PATCH v1 2/2] riscv: Introduce support for hardware break/watchpoints
config: riscv-randconfig-r071-20250711 (https://download.01.org/0day-ci/archive/20250711/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250711/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

arch/riscv/kernel/hw_breakpoint.c: In function 'arch_smp_setup_sbi_shmem':
arch/riscv/kernel/hw_breakpoint.c:44:16: error: storage size of 'ret' isn't known

      44 |  struct sbiret ret;
         |                ^~~
   In file included from include/asm-generic/percpu.h:7,
                    from ./arch/riscv/include/generated/asm/percpu.h:1,
                    from include/linux/irqflags.h:19,
                    from arch/riscv/include/asm/bitops.h:14,
                    from include/linux/bitops.h:67,
                    from include/linux/thread_info.h:27,
                    from include/asm-generic/preempt.h:5,
                    from ./arch/riscv/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:79,
                    from include/linux/alloc_tag.h:11,
                    from include/linux/percpu.h:5,
                    from include/asm-generic/local64.h:5,
                    from ./arch/riscv/include/generated/asm/local64.h:1,
                    from include/linux/perf_event.h:26,
                    from include/linux/hw_breakpoint.h:5,
                    from arch/riscv/kernel/hw_breakpoint.c:6:
>> include/linux/percpu-defs.h:220:52: error: invalid use of undefined type 'union sbi_dbtr_shmem_entry'
     220 |  const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL; \
         |                                                    ^
   include/linux/percpu-defs.h:263:2: note: in expansion of macro '__verify_pcpu_ptr'
     263 |  __verify_pcpu_ptr(ptr);      \
         |  ^~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:47:15: note: in expansion of macro 'per_cpu_ptr'
      47 |  dbtr_shmem = per_cpu_ptr(sbi_dbtr_shmem, cpu);
         |               ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:55:8: error: implicit declaration of function 'sbi_ecall' [-Werror=implicit-function-declaration]
      55 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_SETUP_SHMEM,
         |        ^~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:55:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
      55 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_SETUP_SHMEM,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:55:18: note: each undeclared identifier is reported only once for each function it appears in
   arch/riscv/kernel/hw_breakpoint.c:55:32: error: 'SBI_EXT_DBTR_SETUP_SHMEM' undeclared (first use in this function)
      55 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_SETUP_SHMEM,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:60:8: error: 'SBI_ERR_DENIED' undeclared (first use in this function)
      60 |   case SBI_ERR_DENIED:
         |        ^~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:66:8: error: 'SBI_ERR_INVALID_PARAM' undeclared (first use in this function)
      66 |   case SBI_ERR_INVALID_PARAM:
         |        ^~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:67:8: error: 'SBI_ERR_INVALID_ADDRESS' undeclared (first use in this function)
      67 |   case SBI_ERR_INVALID_ADDRESS:
         |        ^~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:73:8: error: 'SBI_ERR_ALREADY_AVAILABLE' undeclared (first use in this function)
      73 |   case SBI_ERR_ALREADY_AVAILABLE:
         |        ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:79:8: error: 'SBI_ERR_FAILURE' undeclared (first use in this function)
      79 |   case SBI_ERR_FAILURE:
         |        ^~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:44:16: warning: unused variable 'ret' [-Wunused-variable]
      44 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_smp_teardown_sbi_shmem':
   arch/riscv/kernel/hw_breakpoint.c:99:16: error: storage size of 'ret' isn't known
      99 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c:102:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     102 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_SETUP_SHMEM,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:102:32: error: 'SBI_EXT_DBTR_SETUP_SHMEM' undeclared (first use in this function)
     102 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_SETUP_SHMEM,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:107:8: error: 'SBI_ERR_DENIED' undeclared (first use in this function)
     107 |   case SBI_ERR_DENIED:
         |        ^~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:112:8: error: 'SBI_ERR_INVALID_PARAM' undeclared (first use in this function)
     112 |   case SBI_ERR_INVALID_PARAM:
         |        ^~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:113:8: error: 'SBI_ERR_INVALID_ADDRESS' undeclared (first use in this function)
     113 |   case SBI_ERR_INVALID_ADDRESS:
         |        ^~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:118:8: error: 'SBI_ERR_ALREADY_AVAILABLE' undeclared (first use in this function)
     118 |   case SBI_ERR_ALREADY_AVAILABLE:
         |        ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:122:8: error: 'SBI_ERR_FAILURE' undeclared (first use in this function)
     122 |   case SBI_ERR_FAILURE:
         |        ^~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:99:16: warning: unused variable 'ret' [-Wunused-variable]
      99 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c: In function 'init_sbi_dbtr':
   arch/riscv/kernel/hw_breakpoint.c:140:16: error: storage size of 'ret' isn't known
     140 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c:142:6: error: implicit declaration of function 'sbi_probe_extension' [-Werror=implicit-function-declaration]
     142 |  if (sbi_probe_extension(SBI_EXT_DBTR) <= 0) {
         |      ^~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:142:26: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     142 |  if (sbi_probe_extension(SBI_EXT_DBTR) <= 0) {
         |                          ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:148:32: error: 'SBI_EXT_DBTR_NUM_TRIGGERS' undeclared (first use in this function)
     148 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_NUM_TRIGGERS,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:140:16: warning: unused variable 'ret' [-Wunused-variable]
     140 |  struct sbiret ret;
         |                ^~~
   In file included from include/asm-generic/percpu.h:7,
                    from ./arch/riscv/include/generated/asm/percpu.h:1,
                    from include/linux/irqflags.h:19,
                    from arch/riscv/include/asm/bitops.h:14,
                    from include/linux/bitops.h:67,
                    from include/linux/thread_info.h:27,
                    from include/asm-generic/preempt.h:5,
                    from ./arch/riscv/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:79,
                    from include/linux/alloc_tag.h:11,
                    from include/linux/percpu.h:5,
                    from include/asm-generic/local64.h:5,
                    from ./arch/riscv/include/generated/asm/local64.h:1,
                    from include/linux/perf_event.h:26,
                    from include/linux/hw_breakpoint.h:5,
                    from arch/riscv/kernel/hw_breakpoint.c:6:
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_install_hw_breakpoint':
>> include/linux/percpu-defs.h:220:52: error: invalid use of undefined type 'union sbi_dbtr_shmem_entry'
     220 |  const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL; \
         |                                                    ^
   include/linux/percpu-defs.h:263:2: note: in expansion of macro '__verify_pcpu_ptr'
     263 |  __verify_pcpu_ptr(ptr);      \
         |  ^~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:267:26: note: in expansion of macro 'per_cpu_ptr'
     267 | #define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
         |                          ^~~~~~~~~~~
   include/linux/percpu-defs.h:268:27: note: in expansion of macro 'raw_cpu_ptr'
     268 | #define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
         |                           ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:428:38: note: in expansion of macro 'this_cpu_ptr'
     428 |  union sbi_dbtr_shmem_entry *shmem = this_cpu_ptr(sbi_dbtr_shmem);
         |                                      ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:433:16: error: storage size of 'ret' isn't known
     433 |  struct sbiret ret;
         |                ^~~
>> arch/riscv/kernel/hw_breakpoint.c:439:15: error: invalid use of undefined type 'union sbi_dbtr_shmem_entry'
     439 |  xmit = &shmem->data;
         |               ^~
   arch/riscv/kernel/hw_breakpoint.c:440:15: error: invalid use of undefined type 'union sbi_dbtr_shmem_entry'
     440 |  recv = &shmem->id;
         |               ^~
   arch/riscv/kernel/hw_breakpoint.c:441:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     441 |  xmit->tdata1 = cpu_to_le(bp->tdata1);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:442:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     442 |  xmit->tdata2 = cpu_to_le(bp->tdata2);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:443:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     443 |  xmit->tdata3 = cpu_to_le(bp->tdata3);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:445:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     445 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_INSTALL,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:445:32: error: 'SBI_EXT_DBTR_TRIG_INSTALL' undeclared (first use in this function)
     445 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_INSTALL,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/byteorder/little_endian.h:5,
                    from arch/riscv/include/uapi/asm/byteorder.h:10,
                    from include/uapi/linux/perf_event.h:20,
                    from include/linux/perf_event.h:17,
                    from include/linux/hw_breakpoint.h:5,
                    from arch/riscv/kernel/hw_breakpoint.c:6:
   arch/riscv/kernel/hw_breakpoint.c:454:22: error: invalid use of undefined type 'struct sbi_dbtr_id_msg'
     454 |  idx = le_to_cpu(recv->idx);
         |                      ^~
   include/uapi/linux/byteorder/little_endian.h:33:51: note: in definition of macro '__le64_to_cpu'
      33 | #define __le64_to_cpu(x) ((__force __u64)(__le64)(x))
         |                                                   ^
   arch/riscv/include/asm/hw_breakpoint.h:17:19: note: in expansion of macro 'le64_to_cpu'
      17 | #define le_to_cpu le64_to_cpu
         |                   ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:454:8: note: in expansion of macro 'le_to_cpu'
     454 |  idx = le_to_cpu(recv->idx);
         |        ^~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:433:16: warning: unused variable 'ret' [-Wunused-variable]
     433 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_uninstall_hw_breakpoint':
   arch/riscv/kernel/hw_breakpoint.c:482:16: error: storage size of 'ret' isn't known
     482 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c:499:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     499 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_UNINSTALL,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:499:32: error: 'SBI_EXT_DBTR_TRIG_UNINSTALL' undeclared (first use in this function)
     499 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_UNINSTALL,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:482:16: warning: unused variable 'ret' [-Wunused-variable]
     482 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_enable_hw_breakpoint':
   arch/riscv/kernel/hw_breakpoint.c:507:16: error: storage size of 'ret' isn't known
     507 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c:523:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     523 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_ENABLE,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:523:32: error: 'SBI_EXT_DBTR_TRIG_ENABLE' undeclared (first use in this function)
     523 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_ENABLE,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:507:16: warning: unused variable 'ret' [-Wunused-variable]
     507 |  struct sbiret ret;
         |                ^~~
   In file included from include/asm-generic/percpu.h:7,
                    from ./arch/riscv/include/generated/asm/percpu.h:1,
                    from include/linux/irqflags.h:19,
                    from arch/riscv/include/asm/bitops.h:14,
                    from include/linux/bitops.h:67,
                    from include/linux/thread_info.h:27,
                    from include/asm-generic/preempt.h:5,
                    from ./arch/riscv/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:79,
                    from include/linux/alloc_tag.h:11,
                    from include/linux/percpu.h:5,
                    from include/asm-generic/local64.h:5,
                    from ./arch/riscv/include/generated/asm/local64.h:1,
                    from include/linux/perf_event.h:26,
                    from include/linux/hw_breakpoint.h:5,
                    from arch/riscv/kernel/hw_breakpoint.c:6:
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_update_hw_breakpoint':
>> include/linux/percpu-defs.h:220:52: error: invalid use of undefined type 'union sbi_dbtr_shmem_entry'
     220 |  const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL; \
         |                                                    ^
   include/linux/percpu-defs.h:263:2: note: in expansion of macro '__verify_pcpu_ptr'
     263 |  __verify_pcpu_ptr(ptr);      \
         |  ^~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:267:26: note: in expansion of macro 'per_cpu_ptr'
     267 | #define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
         |                          ^~~~~~~~~~~
   include/linux/percpu-defs.h:268:27: note: in expansion of macro 'raw_cpu_ptr'
     268 | #define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
         |                           ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:536:38: note: in expansion of macro 'this_cpu_ptr'
     536 |  union sbi_dbtr_shmem_entry *shmem = this_cpu_ptr(sbi_dbtr_shmem);
         |                                      ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:539:16: error: storage size of 'ret' isn't known
     539 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c:557:15: error: invalid use of undefined type 'union sbi_dbtr_shmem_entry'
     557 |  xmit = &shmem->data;
         |               ^~
   arch/riscv/kernel/hw_breakpoint.c:558:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     558 |  xmit->tdata1 = cpu_to_le(bp->tdata1);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:559:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     559 |  xmit->tdata2 = cpu_to_le(bp->tdata2);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:560:6: error: invalid use of undefined type 'struct sbi_dbtr_data_msg'
     560 |  xmit->tdata3 = cpu_to_le(bp->tdata3);
         |      ^~
   arch/riscv/kernel/hw_breakpoint.c:562:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     562 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_UPDATE,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:562:32: error: 'SBI_EXT_DBTR_TRIG_UPDATE' undeclared (first use in this function)
     562 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_UPDATE,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:539:16: warning: unused variable 'ret' [-Wunused-variable]
     539 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_disable_hw_breakpoint':
   arch/riscv/kernel/hw_breakpoint.c:574:16: error: storage size of 'ret' isn't known
     574 |  struct sbiret ret;
         |                ^~~
   arch/riscv/kernel/hw_breakpoint.c:589:18: error: 'SBI_EXT_DBTR' undeclared (first use in this function)
     589 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_DISABLE,
         |                  ^~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:589:32: error: 'SBI_EXT_DBTR_TRIG_DISABLE' undeclared (first use in this function)
     589 |  ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_DISABLE,
         |                                ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:574:16: warning: unused variable 'ret' [-Wunused-variable]
     574 |  struct sbiret ret;
         |                ^~~
   In file included from include/linux/percpu.h:5,
                    from include/asm-generic/local64.h:5,
                    from ./arch/riscv/include/generated/asm/local64.h:1,
                    from include/linux/perf_event.h:26,
                    from include/linux/hw_breakpoint.h:5,
                    from arch/riscv/kernel/hw_breakpoint.c:6:
   arch/riscv/kernel/hw_breakpoint.c: In function 'arch_hw_breakpoint_init':
>> arch/riscv/kernel/hw_breakpoint.c:634:40: error: invalid application of 'sizeof' to incomplete type 'union sbi_dbtr_shmem_entry'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                                        ^
   include/linux/alloc_tag.h:239:9: note: in definition of macro 'alloc_hooks_tag'
     239 |  typeof(_do_alloc) _res;      \
         |         ^~~~~~~~~
   include/linux/percpu.h:142:2: note: in expansion of macro 'alloc_hooks'
     142 |  alloc_hooks(pcpu_alloc_noprof(_size, _align, false, GFP_KERNEL))
         |  ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:634:19: note: in expansion of macro '__alloc_percpu'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                   ^~~~~~~~~~~~~~
>> arch/riscv/kernel/hw_breakpoint.c:634:40: error: invalid application of 'sizeof' to incomplete type 'union sbi_dbtr_shmem_entry'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                                        ^
   include/linux/alloc_tag.h:243:10: note: in definition of macro 'alloc_hooks_tag'
     243 |   _res = _do_alloc;     \
         |          ^~~~~~~~~
   include/linux/percpu.h:142:2: note: in expansion of macro 'alloc_hooks'
     142 |  alloc_hooks(pcpu_alloc_noprof(_size, _align, false, GFP_KERNEL))
         |  ^~~~~~~~~~~
   arch/riscv/kernel/hw_breakpoint.c:634:19: note: in expansion of macro '__alloc_percpu'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                   ^~~~~~~~~~~~~~
>> arch/riscv/kernel/hw_breakpoint.c:634:40: error: invalid application of 'sizeof' to incomplete type 'union sbi_dbtr_shmem_entry'
     634 |  sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
         |                                        ^
   include/linux/alloc_tag.h:246:10: note: in definition of macro 'alloc_hooks_tag'
     246 |   _res = _do_alloc;     \
         |          ^~~~~~~~~
   include/linux/percpu.h:142:2: note: in expansion of macro 'alloc_hooks'
     142 |  alloc_hooks(pcpu_alloc_noprof(_size, _align, false, GFP_KERNEL))
         |  ^~~~~~~~~~~

arch/riscv/kernel/hw_breakpoint.c:634:19: note: in expansion of macro '__alloc_percpu'
634 | sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
| ^~~~~~~~~~~~~~
arch/riscv/kernel/hw_breakpoint.c:634:17: warning: assignment to 'union sbi_dbtr_shmem_entry *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
634 | sbi_dbtr_shmem = __alloc_percpu(sizeof(*sbi_dbtr_shmem) * dbtr_total_num,
| ^
cc1: some warnings being treated as errors

vim +220 include/linux/percpu-defs.h

62fde54123fb64 Tejun Heo 2014-06-17  206  
9c28278a24c01c Tejun Heo 2014-06-17  207  /*
6fbc07bbe2b5a8 Tejun Heo 2014-06-17  208   * __verify_pcpu_ptr() verifies @ptr is a percpu pointer without evaluating
6fbc07bbe2b5a8 Tejun Heo 2014-06-17  209   * @ptr and is invoked once before a percpu area is accessed by all
6fbc07bbe2b5a8 Tejun Heo 2014-06-17  210   * accessors and operations.  This is performed in the generic part of
6fbc07bbe2b5a8 Tejun Heo 2014-06-17  211   * percpu and arch overrides don't need to worry about it; however, if an
6fbc07bbe2b5a8 Tejun Heo 2014-06-17  212   * arch wants to implement an arch-specific percpu accessor or operation,
6fbc07bbe2b5a8 Tejun Heo 2014-06-17  213   * it may use __verify_pcpu_ptr() to verify the parameters.
9c28278a24c01c Tejun Heo 2014-06-17  214   *
9c28278a24c01c Tejun Heo 2014-06-17  215   * + 0 is required in order to convert the pointer type from a
9c28278a24c01c Tejun Heo 2014-06-17  216   * potential array type to a pointer to a single item of the array.
9c28278a24c01c Tejun Heo 2014-06-17  217   */
eba117889ac444 Tejun Heo 2014-06-17  218  #define __verify_pcpu_ptr(ptr)						\
eba117889ac444 Tejun Heo 2014-06-17  219  do {									\
9c28278a24c01c Tejun Heo 2014-06-17 @220  	const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL;	\
9c28278a24c01c Tejun Heo 2014-06-17  221  	(void)__vpp_verify;						\
9c28278a24c01c Tejun Heo 2014-06-17  222  } while (0)

9c28278a24c01c Tejun Heo 2014-06-17 223

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#6 lore raw
In reply to Himanshu Chauhan
Quoted 6 lines · Himanshu Chauhan

RISC-V hardware breakpoint framework is built on top of perf subsystem and uses SBI debug trigger extension to install/uninstall/update/enable/disable hardware triggers as specified in Sdtrig ISA extension.

Talking with Anup, it sounds like you're planning an updated version of this one, so will hold off on it.

- Paul

#7 lore raw

Hi Paul,

Quoted 8 lines · Paul Walmsley
Quoted 5 lines · Himanshu Chauhan

RISC-V hardware breakpoint framework is built on top of perf subsystem and uses SBI debug trigger extension to install/uninstall/update/enable/disable hardware triggers as specified in Sdtrig ISA extension.

Quoted 4 lines
Quoted 1 line

Talking with Anup, it sounds like you're planning an updated version of this one, so will hold off on it.

That's correct. You can hold this version. I will be posting v2 for this series which you can target for 6.20.

Regards
Himanshu

Quoted 3 lines

- Paul