Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Chen Pei <cp0613@linux.alibaba.com>
To: Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>,
	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
Subject: Re: [PATCH v6 1/5] riscv: Introduce support for hardware break/watchpoints
Date: Wed,  5 Aug 2026 21:20:54 +0800	[thread overview]
Message-ID: <20260805132058.884-1-cp0613@linux.alibaba.com> (raw)
In-Reply-To: <20260803134913.2013674-2-himanshu.chauhan@oss.qualcomm.com>

Hi Himanshu,

Thanks for the series. Two small observations on the tdata1.hit
handling, based on my reading of the Sdtrig spec.

> +			/*
> +			 * Prefer tdata1.hit from SBI trigger readout whenever
> +			 * possible. Fall back to address-based matching if HIT
> +			 * isn't observed/supported.
> +			 */
> +			raw_spin_lock_irqsave(this_cpu_ptr(&ecall_lock),
> +					      *this_cpu_ptr(&ecall_lock_flags));
> +			shmem = this_cpu_ptr(sbi_dbtr_shmem);
> +			sret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_READ,
> +					 i, 1, 0, 0, 0, 0);
> +			if (!sret.error) {
> +				tdata1 = le_to_cpu(shmem->data.tdata1);
> +
> +				if (dbtr_type == RISCV_DBTR_TRIG_MCONTROL)
> +					hit = !!(tdata1 & RISCV_DBTR_MC_HIT_BIT_MASK);
> +				else if (dbtr_type == RISCV_DBTR_TRIG_MCONTROL6)
> +					hit = !!(tdata1 & RISCV_DBTR_MC6_HIT_BIT_MASK);
> +			}

It looks like the hit bit is read here but not cleared afterwards.
The debug spec describes mcontrol.hit as:

  "If this bit is implemented then it must become set when this
   trigger fires and may become set when this trigger matches.
   The trigger's user can set or clear it at any time."

and for mcontrol6 hit0/hit1:

  "The TM updates this field when the trigger fires. After the
   debugger has seen the update, it will normally write 0 to this
   field so it can see future changes."

So the hardware only sets hit, and clearing seems to be left to the
trigger's user. Without a clear, a trigger that fired once would keep
hit=1 and might be reported as matching on later unrelated traps on
the same hart. Would it make sense to write tdata1 back with the hit
bit(s) cleared (e.g. via TRIG_UPDATE) once a hit has been observed?

A related minor point: for mcontrol6 with tinfo.version > 0, hit1 and
hit0 combine into a 2-bit field (0=false, 1=before, 2=after). If only
hit0 is tested, the "after" encoding (hit1=1, hit0=0) might be missed
and would then rely on the address-based fallback. Checking (and
clearing) both bits could make the hit detection a bit more robust.

Best regards,
Pei

-- 
Chen Pei <cp0613@linux.alibaba.com>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2026-08-05 13:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 13:49 [PATCH v6 0/5] riscv: Introduce support for hardware break/watchpoints Himanshu Chauhan
2026-08-03 13:49 ` [PATCH v6 1/5] " Himanshu Chauhan
2026-08-05 13:20   ` Chen Pei [this message]
2026-08-03 13:49 ` [PATCH v6 2/5] riscv: Add breakpoint and watchpoint test for riscv Himanshu Chauhan
2026-08-03 13:49 ` [PATCH v6 3/5] riscv: ptrace support for hardware break/watchpoints Himanshu Chauhan
2026-08-05 13:22   ` Chen Pei
2026-08-03 13:49 ` [PATCH v6 4/5] selftests/breakpoints: extend riscv test for ptrace hw break/watchpoints Himanshu Chauhan
2026-08-03 13:49 ` [PATCH v6 5/5] MAINTAINERS: Add entry for RISC-V Debugging Himanshu Chauhan
2026-08-04 17:10 ` [PATCH v6 0/5] riscv: Introduce support for hardware break/watchpoints Jesse Taube

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=20260805132058.884-1-cp0613@linux.alibaba.com \
    --to=cp0613@linux.alibaba.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=himanshu.chauhan@oss.qualcomm.com \
    --cc=jtaubepe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=qingfang.deng@linux.dev \
    --cc=shuah@kernel.org \
    --cc=thecharlesjenkins@gmail.com \
    /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