From: Mark Rutland <mark.rutland@arm.com>
To: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Jonathan Corbet <corbet@lwn.net>, Marc Zyngier <maz@kernel.org>,
Oliver Upton <oliver.upton@linux.dev>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Mark Brown <broonie@kernel.org>,
kvmarm@lists.linux.dev
Subject: Re: [PATCH 3/3] arm64/hw_breakpoint: Enable FEAT_Debugv8p9
Date: Tue, 29 Oct 2024 16:20:56 +0000 [thread overview]
Message-ID: <ZyELaIMQVRTULKXi@J2N7QTR9R3.cambridge.arm.com> (raw)
In-Reply-To: <f65af1fe-b500-499e-84dd-954700583475@arm.com>
On Tue, Oct 29, 2024 at 01:06:38PM +0530, Anshuman Khandual wrote:
> On 10/28/24 18:17, Mark Rutland wrote:
> > On Wed, Oct 23, 2024 at 01:01:52PM +0530, Anshuman Khandual wrote:
> >> On 10/22/24 21:04, Mark Rutland wrote:
> >>> I assume this is intended to protect the bank in sequences like:
> >>>
> >>> MSR MDSELR, <...>
> >>> ISB
> >>> MRS <..._, BANKED_REGISTER
> >>
> >> Correct, it is protecting the above sequence.
> >>
> >>> ... but is theat suffucient for mutual exclusion against
> >>> exception handlers, or does that come from somewhere else?
> >>
> >> Looking at all existing use cases for breakpoint/watchpoints, it should
> >> be sufficient to protect against mutual exclusion. But thinking, do you
> >> have a particular exception handler scenario in mind where this might
> >> still be problematic ? Will keep looking into it.
> >
> > Where does the mutual exclusion come from for the existing sequences?
>
> Bank selection followed by indexed read/write, inherently requires mutual
> exclusion (ensuring that both these steps executed together) in order to
> prevent read/write into wrong registers. That being said, HW breakpoints
> get used in multiple different places such as perf, ptrace, debug monitor
> based single stepping etc calling platform functions which operate on the
> HW breakpoint registers here.
Yes; that's *why* I'm asking.
> preempt_disable()/enable() sequence in the very last leaf level helpers
> such as [read|write]_wb_reg(), will ensure required mutual exclusion.
I do not believe that this assertion is correct.
I specifically gave the example of mutual exclusion against exception
handlers, and preempt_disable() ... preempt_disable() does not prevent
exceptions being taken, so disabling preemption *cannot* be sufficient
to provide mutual exclusion against exception handlers.
What prevents a race with an exception handler? e.g.
* Does the structure of the code prevent that somehow?
* What context(s) does this code execute in?
- Are debug exceptions always masked?
- Do we disable breakpoints/watchpoints around (some) manipulation of
the relevant registers?
> > We should be able to descrive should be able to describe that in the
> > commit message or in a comment somewhere (or better, with some
> > assertions that get tested).
>
> Planning to add a comment - something like this both for read and write
> helpers.
> /*
> * Bank selection in MDSELR_EL1, followed by indexed read from
> * [break|watch]point registers cannot be interrupted, as that
> * might cause misread from wrong targets. Hence this requires
> * mutual exclusion via preventing any preemption.
> */
As above, I do not believe this is correct. At minimum, disabling
preemption is not the full story here.
> But regarding adding assertions, could you give some more details and
> it will be great to have some relevant examples as well.
I've given some suggestions above. Please go and read the code and
figure this out.
> > For example, what prevents watchpoint_handler() from firing in the
> > middle of arch_install_hw_breakpoint() or
> > arch_uninstall_hw_breakpoint()?
>
> If perf is the only user, watchpoint_handler() will not get triggered
> without watchpoints being installed via arch_install_hw_breakpoint().
> Similarly once they get uninstalled via arch_uninstall_hw_breakpoint()
> there will not be active watchpoints to trigger the handler. Although
> there are other users (ptrace, debug monitor etc) besides perf which
> could also be active simultaneously and race with each other ? TBH, I
> am not sure.
Please go and read the code and figure this out.
> > Is the existing code correct?
>
> I have not tested the concurrency aspects of the HW breakpoints enough
> to be able to answer that question. But if there is a particular concern
> here, happy to look into that.
>
> But wondering how does this new bank indexed read/write mechanism (after
> taking care of the mutual exclusion in the leaf level helpers such as
> [read| write]_wb_reg()) still makes the existing concurrency situation
> worse off than earlier ?
Please go and read the code and figure this out.
Mark.
next prev parent reply other threads:[~2024-10-29 16:21 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 4:35 [PATCH 0/3] " Anshuman Khandual
2024-10-01 4:36 ` [PATCH 1/3] arm64/cpufeature: Add field details for ID_AA64DFR1_EL1 register Anshuman Khandual
2024-10-22 15:56 ` Mark Rutland
2024-10-23 5:48 ` Anshuman Khandual
2024-10-28 12:33 ` Mark Rutland
2024-10-28 13:38 ` Anshuman Khandual
2024-10-01 4:36 ` [PATCH 2/3] arm64/boot: Enable EL2 requirements for FEAT_Debugv8p9 Anshuman Khandual
2024-10-02 23:25 ` kernel test robot
2024-10-02 23:25 ` kernel test robot
2024-10-22 16:10 ` Mark Rutland
2024-10-23 6:12 ` Anshuman Khandual
2024-10-28 12:35 ` Mark Rutland
2024-10-28 13:43 ` Anshuman Khandual
2024-10-01 4:36 ` [PATCH 3/3] arm64/hw_breakpoint: Enable FEAT_Debugv8p9 Anshuman Khandual
2024-10-02 23:36 ` kernel test robot
2024-10-03 3:40 ` Anshuman Khandual
2024-10-22 15:34 ` Mark Rutland
2024-10-23 7:31 ` Anshuman Khandual
2024-10-28 12:47 ` Mark Rutland
2024-10-29 7:36 ` Anshuman Khandual
2024-10-29 16:20 ` Mark Rutland [this message]
2024-10-21 4:09 ` [PATCH 0/3] " Anshuman Khandual
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=ZyELaIMQVRTULKXi@J2N7QTR9R3.cambridge.arm.com \
--to=mark.rutland@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=james.morse@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.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
all inboxes | Powered by JetHome®