From: Xin Li <xin@zytor.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
Dave Hansen <dave.hansen@intel.com>,
linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
peterz@infradead.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 1/1] x86/fred/signal: Prevent single-step upon ERETU completion
Date: Thu, 22 May 2025 17:57:31 -0700 [thread overview]
Message-ID: <97a86550-844d-41c8-bc5e-b3b7b20ef6c9@zytor.com> (raw)
In-Reply-To: <ad8d3a12-25f3-4d57-8f34-950b7967f92b@citrix.com>
On 5/22/2025 10:53 AM, Andrew Cooper wrote:
> This was a behaviour intentionally changed in FRED so traps wouldn't get
> lost if an exception where to occur.
>
> What precise case is triggering this?
Following is the test code:
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2025 Intel Corporation
*/
#define _GNU_SOURCE
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ucontext.h>
static void sethandler(int sig, void (*handler)(int, siginfo_t *, void
*), int flags)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = handler;
sa.sa_flags = SA_SIGINFO | flags;
sigemptyset(&sa.sa_mask);
if (sigaction(sig, &sa, 0))
err(1, "sigaction");
return;
}
static void sigtrap(int sig, siginfo_t *info, void *ctx_void)
{
ucontext_t *ctx = (ucontext_t *)ctx_void;
static unsigned long last_trap_ip;
static unsigned int loop_count_on_same_ip;
if (last_trap_ip == ctx->uc_mcontext.gregs[REG_RIP]) {
printf("trapped on %016lx\n", last_trap_ip);
if (++loop_count_on_same_ip > 10) {
printf("trap loop detected, test failed\n");
exit(2);
}
return;
}
loop_count_on_same_ip = 0;
last_trap_ip = ctx->uc_mcontext.gregs[REG_RIP];
printf("trapped on %016lx\n", last_trap_ip);
}
int main(int argc, char *argv[])
{
sethandler(SIGTRAP, sigtrap, 0);
asm volatile("push $0x302\n\t"
"popf\n\t"
"nop\n\t"
"nop\n\t"
"push $0x202\n\t"
"popf\n\t");
printf("test passed\n");
}
W/o the fix when FRED enabled, I get:
xin@fred-ubt:~$ ./lass_test
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trapped on 00000000004012fe
trap loop detected, test failed
W/ the fix when FRED enabled:
[xin@dev ~]$ ./lass_test
trapped on 00000000004012fe
trapped on 00000000004012ff
trapped on 0000000000401304
trapped on 0000000000401305
test passed
Obviously the test passes on IDT.
As Dave asked, I will integrate this test into selftests.
Thanks!
Xin
next prev parent reply other threads:[~2025-05-23 0:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 17:17 Xin Li (Intel)
2025-05-22 17:22 ` Dave Hansen
2025-05-22 17:26 ` Xin Li
2025-05-22 17:53 ` Andrew Cooper
2025-05-22 21:28 ` H. Peter Anvin
2025-05-23 0:10 ` Andrew Cooper
2025-05-23 3:48 ` H. Peter Anvin
2025-05-23 0:57 ` Xin Li [this message]
2025-05-23 7:42 ` H. Peter Anvin
2025-05-23 17:21 ` Xin Li
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=97a86550-844d-41c8-bc5e-b3b7b20ef6c9@zytor.com \
--to=xin@zytor.com \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.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
all inboxes | Powered by JetHome®