From: Thomas Gleixner <tglx@linutronix.de>
To: Florian Rommel <mail@florommel.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>,
Jason Wessel <jason.wessel@windriver.com>,
Daniel Thompson <daniel.thompson@linaro.org>,
Douglas Anderson <dianders@chromium.org>,
Lorena Kretzschmar <qy15sije@cip.cs.fau.de>,
Stefan Saecherl <stefan.saecherl@fau.de>,
Peter Zijlstra <peterz@infradead.org>,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Randy Dunlap <rdunlap@infradead.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Geert Uytterhoeven <geert+renesas@glider.be>,
kgdb-bugreport@lists.sourceforge.net, x86@kernel.org,
linux-kernel@vger.kernel.org
Cc: Florian Rommel <mail@florommel.de>
Subject: Re: [PATCH v2 2/2] x86/kgdb: fix hang on failed breakpoint removal
Date: Mon, 12 Aug 2024 23:04:13 +0200 [thread overview]
Message-ID: <871q2tsbaq.ffs@tglx> (raw)
In-Reply-To: <20240812174338.363838-3-mail@florommel.de>
Florian!
On Mon, Aug 12 2024 at 19:43, Florian Rommel wrote:
> On x86, occasionally, the removal of a breakpoint (i.e., removal of
> the int3 instruction) fails because the text_mutex is taken by another
> CPU (mainly due to the static_key mechanism, I think).
Either you know it or not. Speculation is reserved for CPUs.
> The function kgdb_skipexception catches exceptions from these spurious
> int3 instructions, bails out of KGDB, and continues execution from the
> previous PC address.
>
> However, this led to an endless loop between the int3 instruction and
> kgdb_skipexception since the int3 instruction (being still present)
> triggered again. This effectively caused the system to hang.
>
> With this patch, we try to remove the concerned spurious int3
> instruction in kgdb_skipexception before continuing execution. This
> may take a few attempts until the concurrent holders of the text_mutex
> have released it, but eventually succeeds and the kernel can continue.
What guarantees the release of text mutex?
> Signed-off-by: Florian Rommel <mail@florommel.de>
> ---
> arch/x86/kernel/kgdb.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
> index 64c332151af7..585a7a72af74 100644
> --- a/arch/x86/kernel/kgdb.c
> +++ b/arch/x86/kernel/kgdb.c
> @@ -723,7 +723,31 @@ void kgdb_arch_exit(void)
> int kgdb_skipexception(int exception, struct pt_regs *regs)
Btw, kgdb_skipexception() is a gross nisnomer because it rewinds the
instruction pointer to the exception address and does not skip anything,
but that's an orthogonal issue though it could be cleaned up along the
way...
> {
> if (exception == 3 && kgdb_isremovedbreak(regs->ip - 1)) {
> + struct kgdb_bkpt *bpt;
> + int i, error;
> +
> regs->ip -= 1;
> +
> + /*
> + * Try to remove the spurious int3 instruction.
> + * These int3s can result from failed breakpoint removals
> + * in kgdb_arch_remove_breakpoint.
> + */
> + for (bpt = NULL, i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
> + if (kgdb_break[i].bpt_addr == regs->ip &&
> + kgdb_break[i].state == BP_REMOVED &&
> + (kgdb_break[i].type == BP_BREAKPOINT ||
> + kgdb_break[i].type == BP_POKE_BREAKPOINT)) {
> + bpt = &kgdb_break[i];
> + break;
> + }
> + }
Seriously? The KGBD core already walked that array in
kgdb_isremovedbreak() just so you can walk it again here.
struct kkgdb_bkpt *kgdb_get_removed_breakpoint(unsigned long addr)
{
struct kgdb_bkpt *bp = kgdb_break;
for (int i = 0; i < KGDB_MAX_BREAKPOINTS; i++, bp++) {
if (bp>.state == BP_REMOVED && bp->kgdb_bpt_addr == addr)
return bp;
}
return NULL;
}
bool kgdb_isremovedbreak(unsigned long addr)
{
return !!kgdb_get_removed_breakpoint(addr);
}
bool kgdb_rewind_exception(int exception, struct pt_regs *regs)
{
struct kgdb_bkpt *bp;
if (exception != 3)
return false;
bp = kgdb_get_removed_breakpoint(--regs->ip);
if (!bp || !bp->type == BP_BREAKPOINT)
return false;
Hmm?
> + error = kgdb_arch_remove_breakpoint(bpt);
> + if (error)
> + pr_err("skipexception: breakpoint remove failed: %lx\n",
> + bpt->bpt_addr);
Lacks curly brackets. See Documentation.
return !error;
Aside of that the same problem exists on PowerPC. So you can move the
attempt to remove the breakpoint into the generic code, no?
Thanks,
tglx
next prev parent reply other threads:[~2024-08-12 21:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 17:43 [PATCH v2 0/2] kgdb: x86: fix breakpoint removal problems Florian Rommel
2024-08-12 17:43 ` [PATCH v2 1/2] x86/kgdb: convert early breakpoints to poke breakpoints Florian Rommel
2024-08-12 18:54 ` Thomas Gleixner
2024-08-12 17:43 ` [PATCH v2 2/2] x86/kgdb: fix hang on failed breakpoint removal Florian Rommel
2024-08-12 21:04 ` Thomas Gleixner [this message]
2024-08-13 11:31 ` Daniel Thompson
2024-08-13 15:06 ` Florian Rommel
2024-08-13 16:21 ` Thomas Gleixner
2024-08-14 8:51 ` [PATCH WIP] x86/kgdb: trampolines for shadowed instructions Florian Rommel
2024-08-14 10:29 ` Daniel Thompson
2024-08-14 13:52 ` Thomas Gleixner
2024-08-15 19:51 ` kernel test robot
2024-08-16 11:12 ` kernel test robot
2024-08-13 15:05 ` [PATCH v2 2/2] x86/kgdb: fix hang on failed breakpoint removal Florian Rommel
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=871q2tsbaq.ffs@tglx \
--to=tglx@linutronix.de \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=christophe.jaillet@wanadoo.fr \
--cc=christophe.leroy@csgroup.eu \
--cc=daniel.thompson@linaro.org \
--cc=dave.hansen@linux.intel.com \
--cc=dianders@chromium.org \
--cc=geert+renesas@glider.be \
--cc=hpa@zytor.com \
--cc=jason.wessel@windriver.com \
--cc=kgdb-bugreport@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@florommel.de \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=qy15sije@cip.cs.fau.de \
--cc=rdunlap@infradead.org \
--cc=stefan.saecherl@fau.de \
--cc=x86@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