From: Bill Tsui <b10902118@ntu.edu.tw>
To: Will Deacon <will@kernel.org>
Cc: oleg@redhat.com, catalin.marinas@arm.com, nathan@kernel.org,
nick.desaulniers+lkml@gmail.com, morbo@google.com,
justinstitt@google.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH v4 1/1] arm64: ptrace: fix hw_break_set() to set addr and ctrl together
Date: Sat, 15 Nov 2025 11:44:36 +0800 [thread overview]
Message-ID: <617369509d2fa1948b8851e070dd441e@ntu.edu.tw> (raw)
In-Reply-To: <aRdVZmeOHYbm24NJ@willie-the-truck>
On 2025-11-15 00:14, Will Deacon wrote:
> ... but you only implement this for the native (64-bit) case, so I
> don't
> understand how it helps with the problem above.
Yes it is only for 64-bit tracer to debug 32-bit processes because
64-bit tracer always use 64-bit ptrace API (PTRACE_SETREGSET) regardless
of tracee, so only 64-bit code were changed.
>> @@ -524,9 +506,6 @@ static int hw_break_set(struct task_struct
>> *target,
>> return -EINVAL;
>> ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &addr,
>> offset, offset + PTRACE_HBP_ADDR_SZ);
>> - if (ret)
>> - return ret;
>> - ret = ptrace_hbp_set_addr(note_type, target, idx, addr);
>> if (ret)
>> return ret;
>> offset += PTRACE_HBP_ADDR_SZ;
>> @@ -537,10 +516,11 @@ static int hw_break_set(struct task_struct
>> *target,
>> offset, offset + PTRACE_HBP_CTRL_SZ);
>> if (ret)
>> return ret;
>> - ret = ptrace_hbp_set_ctrl(note_type, target, idx, ctrl);
>> + offset += PTRACE_HBP_CTRL_SZ;
>> +
>> + ret = ptrace_hbp_set(note_type, target, idx, addr, ctrl);
>
> Doesn't this break the case where userspace tries only to set the
> address?
> The loop will break out when !count without updating anything.
>
The case doesn't exist for normal use. I saw that as a validation
rather than an intended stop point. If in doubt, I can remove it.
The signature from man ptrace(2)
ptrace(PTRACE_SETREGSET, pid, NT_foo, &iov)
requires all registers' values to be specified in iov in order. And the
unit of debug registers is the inline structure in user_hwdebug_state:
struct {
__u64 addr;
__u32 ctrl;
__u32 pad;
} dbg_regs[16];
and userspace uses by:
struct user_hwdebug_state dreg_state;
ioVec.iov_base = &dreg_state;
ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad)
+ (sizeof(dreg_state.dbg_regs[0]) * m_max_hwp_supported);
for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
dreg_state.dbg_regs[i].addr = m_hwp_regs[i].address;
dreg_state.dbg_regs[i].ctrl = m_hwp_regs[i].control;
}
The only case of setting only address is to have iov length only reach
the first register's .addr, but I don't think that memory layout should
be relied on.
> As I mentioned before, I'd prefer to leave this code as-is short of
> removing the indirection through perf entirely.
I am working on that, the side effects are hard to trace, and I think
this patch can make removing perf easier by reducing calls to it and
make clearer what hardware API ptrace needs. This recurs to me and I
think it can be a separated patch.
Here is my progress on removing perf:
I tried to directly set by hw_breakpoint_control, which perf finally
use, but we also relied on perf event handling cpu interrupts when
breakpoints get triggered. This is the hardest part and I am learning
how the kernel handles it across so many others. I feel that the use
of perf has its reasons but definitely there is space to improve.
Anyway, I respect maintainer's decision. I just felt that you thought
this is complicated so I simplifed it. Now I explains the correctness
and how it relates to your final goal. If there are still concerns,
please directly reject me, then I can also stop holding on it.
Thanks,
Bill
prev parent reply other threads:[~2025-11-15 3:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-24 12:43 [PATCH 0/3] ARM/arm64: ptrace: fix unaligned hardware breakpoint validation for 32bit b10902118
2025-08-24 12:43 ` [PATCH 1/3] arm64: ptrace: fix hw_break_set() by setting addr and ctrl together b10902118
2025-08-24 12:43 ` [PATCH 2/3] arm64: ptrace: minimize default bp_len for hw breakpoints to pass check b10902118
2025-08-24 12:43 ` [PATCH 3/3] ARM: " b10902118
2025-08-26 19:37 ` [PATCH 0/3] ARM/arm64: ptrace: fix unaligned hardware breakpoint validation for 32bit Catalin Marinas
2025-08-27 1:41 ` [PATCH v2 " Bill Tsui
2025-08-27 1:41 ` [PATCH v2 1/3] arm64: ptrace: fix hw_break_set() by setting addr and ctrl together Bill Tsui
2025-09-08 15:14 ` Will Deacon
2025-09-09 1:50 ` b10902118
2025-09-09 1:57 ` Bill Tsui
2025-09-17 14:23 ` Bill Tsui
2025-08-27 1:41 ` [PATCH v2 2/3] arm64: ptrace: minimize default bp_len for hw breakpoints to pass check Bill Tsui
2025-08-27 1:41 ` [PATCH v2 3/3] ARM: " Bill Tsui
2025-10-16 15:44 ` [PATCH v3 0/1] arm64: ptrace: fix hw_break_set() to set addr and ctrl together Bill Tsui
2025-10-16 15:44 ` [PATCH v3 1/1] " Bill Tsui
2025-10-18 8:24 ` kernel test robot
2025-10-18 13:37 ` [PATCH v4 0/1] " Bill Tsui
2025-10-18 13:37 ` [PATCH v4 1/1] " Bill Tsui
2025-11-14 16:14 ` Will Deacon
2025-11-15 3:44 ` Bill Tsui [this message]
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=617369509d2fa1948b8851e070dd441e@ntu.edu.tw \
--to=b10902118@ntu.edu.tw \
--cc=catalin.marinas@arm.com \
--cc=justinstitt@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=oleg@redhat.com \
--cc=will@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