On May 22, 2025 5:57:31 PM PDT, Xin Li xin@zytor.com wrote:
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
Btw, make the test work on 32 bits as well (just a matter of using a different ucontext.)