From: Ilya Mamay <mmamayka01@gmail.com>
To: Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
alex@ghiti.fr, shuah@kernel.org
Subject: Re: [PATCH v3 1/2] riscv: Introduce support for hardware break/watchpoints
Date: Thu, 19 Mar 2026 13:36:29 +0300 [thread overview]
Message-ID: <20260319103629.by3bw3qeev26jvqq@imamay-pc> (raw)
In-Reply-To: <20260223044918.1359983-2-himanshu.chauhan@oss.qualcomm.com>
Hi, Himanshu
I have been using your previous HBP implementation for some time and have
encountered some of its shortcomings, which this implementation has also
inherited.
On Mon, Feb 23, 2026 at 10:19:17AM +0530, Himanshu Chauhan wrote:
> +/*
> + * HW Breakpoint/watchpoint handler
> + */
> +static int hw_breakpoint_handler(struct die_args *args)
> +{
> + int ret = NOTIFY_DONE;
> + struct arch_hw_breakpoint *bp;
> + struct perf_event *event;
> + int i;
> +
> + for (i = 0; i < dbtr_total_num; i++) {
> + event = this_cpu_read(pcpu_hw_bp_events[i]);
> + if (!event)
> + continue;
> +
> + bp = counter_arch_bp(event);
> + switch (bp->type) {
> + /* Breakpoint */
> + case RV_DBTR_BP:
> + if (bp->address == args->regs->epc) {
> + perf_bp_event(event, args->regs);
> + ret = NOTIFY_STOP;
> + }
> + break;
> +
> + /* Watchpoint */
> + case RV_DBTR_WP:
> + if (bp->address == csr_read(CSR_STVAL)) {
Sdtrig spec (5.7.11 and 5.7.12 in the tdata1.select field description) states that:
"There is at least (!) one compare value and it contains the lowest virtual
address of the access. In addition, it is recommended that there are additional
compare values for the other accessed virtual addresses match. (E.g. on a 32-bit
read from 0x4000, the lowest address is 0x4000 and the other addresses are
0x4001, 0x4002, and 0x4003".
A 32-bit read from 0x4000 will definitely have compare value 0x4000 (the lowest
virtual address), but may also have compare values at 0x4001, 0x4002, and 0x4003.
This means that a 16-bit watchpoint at 0x4002 will fire on this 32-bit read, yet
stval will be 0x4000, and the current hw_breakpoint_handler implementation will
not detect it.
Therefore, it is important to check tdata1.hit bit (which indicates that the
trigger condition was definitely met) and only use the comparison between
bp->address and CSR_STVAL as a fallback (if tdata1.hit is not supported by the
hardware).
> +/* atomic: counter->ctx->lock is held */
> +int arch_install_hw_breakpoint(struct perf_event *event)
> +{
> + struct arch_hw_breakpoint *bp = counter_arch_bp(event);
> + union sbi_dbtr_shmem_entry *shmem = this_cpu_ptr(sbi_dbtr_shmem);
> + struct sbi_dbtr_data_msg *xmit;
> + struct sbi_dbtr_id_msg *recv;
> + struct perf_event **slot;
> + unsigned long idx;
> + struct sbiret ret;
> + int err = 0;
> +
> + raw_spin_lock_irqsave(this_cpu_ptr(&ecall_lock),
> + *this_cpu_ptr(&ecall_lock_flags));
> +
> + xmit = &shmem->data;
> + recv = &shmem->id;
> + xmit->tdata1 = cpu_to_le(bp->tdata1);
> + xmit->tdata2 = cpu_to_le(bp->tdata2);
> + xmit->tdata3 = cpu_to_le(bp->tdata3);
> +
> + ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_INSTALL,
> + 1, 0, 0, 0, 0, 0);
perf installs breakpoints (via the call chain pmu.add->arch_install_hw_breakpoint)
during context rotation after a perf_event_open or ptrace call finishes.
So, if the hardware does not support the given tdata1, tdata2 and tdata3
configuration and OpenSBI fails to set up the trigger, the kernel will still
report that the breakpoint was successfully installed.
A probing stage is therefore needed before or during perf event
registration to ensure that all breakpoints can be installed
successfully during context rotation.
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-03-19 10:36 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 4:49 [PATCH v3 0/2] " Himanshu Chauhan
2026-02-23 4:49 ` [PATCH v3 1/2] " Himanshu Chauhan
2026-02-23 10:24 ` Conor Dooley
2026-02-24 4:00 ` Himanshu Chauhan
2026-02-24 8:03 ` Conor Dooley
2026-02-25 5:03 ` Himanshu Chauhan
2026-02-25 9:00 ` Conor Dooley
2026-02-26 2:47 ` Himanshu Chauhan
2026-02-26 8:48 ` Conor Dooley
2026-02-26 5:35 ` Anup Patel
2026-02-26 8:44 ` Conor Dooley
2026-02-26 11:40 ` Anup Patel
2026-02-26 12:35 ` Conor Dooley
2026-02-26 13:03 ` Anup Patel
2026-02-26 8:52 ` Conor Dooley
2026-03-18 12:00 ` Ilya Mamay
2026-04-06 4:51 ` Himanshu Chauhan
2026-04-07 10:29 ` Ilya Mamay
2026-04-07 15:22 ` Himanshu Chauhan
2026-03-19 10:36 ` Ilya Mamay [this message]
2026-04-06 4:49 ` Himanshu Chauhan
2026-04-07 11:34 ` Ilya Mamay
2026-04-07 15:29 ` Himanshu Chauhan
2026-04-03 7:37 ` liangzhen
2026-04-06 4:48 ` Himanshu Chauhan
2026-04-07 1:47 ` liangzhen
2026-04-07 4:53 ` Himanshu Chauhan
2026-04-07 10:32 ` liangzhen
2026-02-23 4:49 ` [PATCH v3 2/2] riscv: Add breakpoint and watchpoint test for riscv Himanshu Chauhan
2026-04-21 12:00 ` Ilya Mamay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260319103629.by3bw3qeev26jvqq@imamay-pc \
--to=mmamayka01@gmail.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=himanshu.chauhan@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®