From nobody Fri Sep 25 02:02:24 2026 Received: from mta0.migadu.com (out-88.mta0.migadu.com [91.218.175.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 611CA3AA4E8 for ; Thu, 17 Sep 2026 23:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.88 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789686594; cv=none; b=W1fefJqmVoVaRdPNUtk0Vg9FR2QMXS3peNMDx03TIfltuTbDuUCc0wralckCgfVlqIXO8OiLHoIgI6mm+La5m6q443Im3+Una7UXlM/4Z0n5MwLLNCGJqYwJjEJPS4rVjzZ/hYrZIA37fyLY0QT6vmlttlGaC6Z6qaKs+ms/fUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789686594; c=relaxed/simple; bh=qALapTuiw4QCIJOOpOKBx6DcORu290NfVxg/ccqwXE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Newnq/TLPtdzcCiVwyn/sKsgKvnSm0oJp0yyrsZgzPgGno+7wo8Rggd5g69LhkwUwspTe/FfF1VlJDbHT7LrafCgGaV57ur5MZlzmmQcyvEU8ofrcBKyTciqEqOnfVBMmmsy82UFva0wMue5Xg7JDaZ49QoMTjqa5iIiKj7cRQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=vzOvP8ZA; arc=none smtp.client-ip=91.218.175.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="vzOvP8ZA" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=qALapTuiw4QCIJOOpOKBx6DcORu290NfVxg/ccqwXE8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789686584; v=1; x=1790291384; b=vzOvP8ZAluKYEus63Ngh1rsH9IkimYNiPRI+ZskYjsPMefDCq23tNBEkAzuzkbASwwXM4xjh pKSCuox7uH0wTwnOdH30aJddPBcu8Fg5fJPjcpKup9IZn96n73l0sGGorFn4PVT8hkQrFn161zU MDWzimnhbbRdFIEH9XB6X0Eg= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id a750deb8ffe1ae15; Thu, 17 Sep 2026 23:09:44 +0000 X-Mizu-Trace-ID: a750deb8ffe1ae15 X-Migadu-Flow: FLOW_OUT From: Matthew Schwartz To: Xin Li , hpa@zytor.com Cc: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Paul Gofman , Lionel Landwerlin , Shuah Khan , Matthew Schwartz Subject: [PATCH 1/2] x86/fred: Reconstruct the #GP context for rejected INT instructions Date: Thu, 17 Sep 2026 16:09:06 -0700 Message-ID: <20260917230907.2080792-2-matthew.schwartz@linux.dev> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917230907.2080792-1-matthew.schwartz@linux.dev> References: <20260917230907.2080792-1-matthew.schwartz@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" FRED event delivery does not use the IDT, so the gate DPL check that rejects a user INT n falls to software (Intel FRED specification [1], section 8.3). fred_intx() rejects the same vectors as IDT delivery, but reports a zero error code and the IP after the INT. This breaks the signal ABI. Wine uses the error code to recognize INT 0x2d, so the changed context turns a handled breakpoint into an access violation in Elden Ring. Rewind IP using the instruction length in the augmented SS and synthesize the IDT selector error code, (vector << 3) | 2. Set RF in the saved flags, as the CPU does for a #GP fault. Section 5.2.1 defines the saved vector, instruction length and RF state. The supplied length handles prefixes without reading user memory. Limit the changes to already-rejected software interrupts, preserving the accepted INT3, INT4 and enabled INT80 paths and hardware exceptions. With IA32 emulation disabled, INT 0x80 now reports the same #GP as the DPL 0 gate IDT installs there. The rewound IP also stops fixup_iopl_exception() from inspecting the byte after the INT. Also clear the software event flag. Section 6.2.3 specifies that ERETU with this flag and TF set traps before executing any user instruction. A tracer that suppresses SIGSEGV and resumes with TF set expects the next instruction to run first, as after IRET. The sigreturn path clears the same flag for this reason in prevent_single_step_upon_eretu(). [1] Intel Flexible Return and Event Delivery (FRED) Specification, revision 9.0 (346446-009US), sections 5.2.1, 6.2.3 and 8.3. Fixes: 14619d912b65 ("x86/fred: FRED entry/exit and dispatch code") Reported-by: Paul Gofman Closes: https://gitlab.freedesktop.org/mesa/mesa/-/work_items/15745 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/work_items/16132 Signed-off-by: Matthew Schwartz Link: https://cdrdv2.intel.com/v1/dl/getContent/678938 # [1] Reviewed-by: H. Peter Anvin --- arch/x86/entry/entry_fred.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/entry_fred.c b/arch/x86/entry/entry_fred.c index fb3594ddf731..854899bfec5d 100644 --- a/arch/x86/entry/entry_fred.c +++ b/arch/x86/entry/entry_fred.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -71,7 +72,15 @@ static noinstr void fred_intx(struct pt_regs *regs) #endif =20 default: - return exc_general_protection(regs, 0); + /* + * Reconstruct the #GP fault state that IDT delivery would produce. + * Clear the software event flag so ERETU with TF set does not trap + * before the resumed instruction. See prevent_single_step_upon_eretu(). + */ + regs->ip -=3D regs->fred_ss.insnlen; + regs->flags |=3D X86_EFLAGS_RF; + regs->fred_ss.swevent =3D 0; + return exc_general_protection(regs, (regs->fred_ss.vector << 3) | 2); } } =20 --=20 2.55.0 From nobody Fri Sep 25 02:02:24 2026 Received: from mta0.migadu.com (out-105.mta0.migadu.com [91.218.175.105]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57C774BCAA9 for ; Thu, 17 Sep 2026 23:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.105 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789686601; cv=none; b=CKXGBxi4i0JRJ7/z4L45TcFS+XUOg/xxRgYuXh/qYegMJbEmwj5AUxQa7MVxl7tTKMD5pVAUj7luNK9Gc2Yv96NLUqwwajvJcSyxRtFOnczpSX18Y4GVRqJ6iVDOGErMh5tSY5z897UgklKAdHuHV1UO+EUEPnRO64UTiLb+44s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789686601; c=relaxed/simple; bh=oFNZnroysglcMzj8u+xfoACOnRUzQ/KsuJn2dxzUMR8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LHW55NIs48mqvQBfJeZ6brXbi0Ej7clsoyjIW6ikSVX/6/P9GsxuX2HTVQ+xr/CPjnymuLl8iijzoQOH5bBVn5hi9AK5YJSY6dVcQ0KRqFh052pPOgfB+Dpeh7MsoWCA0w5pwvVoVPAJSEw93JqrOFGxZqVUmWf/yA0XTOl6nYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=VoeaAR//; arc=none smtp.client-ip=91.218.175.105 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="VoeaAR//" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=oFNZnroysglcMzj8u+xfoACOnRUzQ/KsuJn2dxzUMR8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789686588; v=1; x=1790291388; b=VoeaAR//fQudthjcqsK2u1hnV4AdsPfcodFmkNJIjgE9h7g0Tb99MxAA4H3+oxk5ZzZ9f8h2 OPsYnJ7SwimMoWTcH5clgDLXPbyB48l+HUW7rjb65VWkXWhyRDWrZcXKIqwSotyCihA30QLwgxF AV0SSZ6wAQHdAKq+FEy0AycE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id f227167076898fad; Thu, 17 Sep 2026 23:09:48 +0000 X-Mizu-Trace-ID: f227167076898fad X-Migadu-Flow: FLOW_OUT From: Matthew Schwartz To: Xin Li , hpa@zytor.com Cc: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Paul Gofman , Lionel Landwerlin , Shuah Khan , Matthew Schwartz Subject: [PATCH 2/2] selftests/x86: Check signal state for rejected software interrupts Date: Thu, 17 Sep 2026 16:09:07 -0700 Message-ID: <20260917230907.2080792-3-matthew.schwartz@linux.dev> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917230907.2080792-1-matthew.schwartz@linux.dev> References: <20260917230907.2080792-1-matthew.schwartz@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a test of the signal ABI for INT instructions in both 32-bit and 64-bit processes. Check the signal number, trap number, error code, si_code, si_addr, instruction pointer and RF/TF state against legacy IDT behavior. Include a 15-byte prefixed INT to check that IP uses the hardware instruction length. Exercise both INT3 encodings, INT4, UD2 and HLT to cover the unchanged trap and fault paths. Run each instruction with TF clear and set. Resume at a known NOP after handling the signal and check that single-stepping traps after the NOP. Also drive INT 0x2d under ptrace, which resumes through the fault frame rather than sigreturn and so exposes a stale FRED software event flag. Start from an INT3 stop, whose FRED frame has no software event flag, instead of the syscall frame of raise(SIGSTOP). Single-step into the INT and check that the fault reports its address. Then suppress SIGSEGV and resume at the NOP, once with PTRACE_SINGLESTEP and once with PTRACE_CONT and TF set. Section 6.2.3 of the Intel FRED specification [1] specifies the immediate single-step trap caused by returning with both that flag and TF set. Check that each trap occurs after the NOP, rather than at its address. Report whether the CPU supports FRED, since a pass looks the same on either entry path. INT 0x80 with IA32 emulation disabled and a 64-bit tracer of a 32-bit tracee are not covered. Both variants pass all 29 checks on a non-FRED AMD host and on Panther Lake with FRED enabled and the fix applied. With the same binaries on unpatched Panther Lake, 16 signal-context checks fail and the first ptrace check reports the IP after the INT. The two dependent ptrace resume checks are not reached. [1] Intel Flexible Return and Event Delivery (FRED) Specification, revision 9.0 (346446-009US), section 6.2.3. Signed-off-by: Matthew Schwartz Link: https://cdrdv2.intel.com/v1/dl/getContent/678938 # [1] --- tools/testing/selftests/x86/Makefile | 2 +- tools/testing/selftests/x86/int_signal.c | 311 +++++++++++++++++++++++ 2 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/x86/int_signal.c diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests= /x86/Makefile index 434065215d12..d478b13cc8d5 100644 --- a/tools/testing/selftests/x86/Makefile +++ b/tools/testing/selftests/x86/Makefile @@ -13,7 +13,7 @@ CAN_BUILD_WITH_NOPIE :=3D $(shell ./check_cc.sh "$(CC)" t= rivial_program.c -no-pie) TARGETS_C_BOTHBITS :=3D single_step_syscall sysret_ss_attrs syscall_nt tes= t_mremap_vdso \ check_initial_reg_state sigreturn iopl ioperm \ test_vsyscall mov_ss_trap sigtrap_loop \ - syscall_arg_fault fsgsbase_restore sigaltstack + syscall_arg_fault fsgsbase_restore sigaltstack int_signal TARGETS_C_BOTHBITS +=3D nx_stack TARGETS_C_32BIT_ONLY :=3D entry_from_vm86 test_syscall_vdso unwind_vdso \ test_FCMOV test_FCOMI test_FISTTP \ diff --git a/tools/testing/selftests/x86/int_signal.c b/tools/testing/selft= ests/x86/int_signal.c new file mode 100644 index 000000000000..22676dac72b5 --- /dev/null +++ b/tools/testing/selftests/x86/int_signal.c @@ -0,0 +1,311 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Check the signal context for INT instructions with IDT and FRED entry. = */ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "helpers.h" + +#ifdef __x86_64__ +#define REG_IP REG_RIP +#define USER_IP rip +#define STACK_PTR "%rsp" +#else +#define REG_IP REG_EIP +#define USER_IP eip +#define STACK_PTR "%esp" +#endif + +/* + * Each instruction has normal and single-step entry points. Resume at the + * NOP after handling its signal, then expect a trace trap after that NOP + * when TF is set. Explicit labels avoid assuming the kernel's saved IP. + */ +#define PROBE(name, insn) \ + extern void name(void); \ + extern void name##_tf(void); \ + extern const char name##_end[], name##_step[]; \ + asm(".pushsection .text\n" \ + ".globl " #name "_tf\n" \ + ".type " #name "_tf, @function\n" \ + #name "_tf:\n" \ + "pushf\n" \ + "orl $0x100, (" STACK_PTR ")\n" \ + "popf\n" \ + ".globl " #name "\n" \ + ".type " #name ", @function\n" \ + #name ":\n" insn "\n" \ + ".globl " #name "_end\n" \ + #name "_end:\nnop\n" \ + ".globl " #name "_step\n" \ + #name "_step:\nret\n" \ + ".size " #name ", .-" #name "\n" \ + ".size " #name "_tf, .-" #name "_tf\n" \ + ".popsection\n") + +PROBE(int1, ".byte 0xcd, 0x01"); +PROBE(int29, ".byte 0xcd, 0x29"); +PROBE(int2c, ".byte 0xcd, 0x2c"); +PROBE(int2d, ".byte 0xcd, 0x2d"); +PROBE(prefixed_int2d, ".byte 0x66, 0xcd, 0x2d"); +PROBE(long_int2d, ".fill 13, 1, 0x2e\n.byte 0xcd, 0x2d"); +PROBE(int81, ".byte 0xcd, 0x81"); +PROBE(intff, ".byte 0xcd, 0xff"); +PROBE(short_int3, ".byte 0xcc"); +PROBE(long_int3, ".byte 0xcd, 0x03"); +PROBE(int4, ".byte 0xcd, 0x04"); +PROBE(ud2, ".byte 0x0f, 0x0b"); +PROBE(hlt, ".byte 0xf4"); + +struct test { + const char *name; + void (*run)(void); + void (*run_tf)(void); + const char *end, *step; + int signo, trap, error, ip_offset, flags, code; +}; + +#define TEST(name, sig, trap, error, offset, flags, code) \ + { #name, name, name##_tf, name##_end, name##_step, \ + sig, trap, error, offset, flags, code } + +#define GP(name, error) \ + TEST(name, SIGSEGV, 13, error, 0, X86_EFLAGS_RF, SI_KERNEL) + +static const struct test tests[] =3D { + GP(int1, 0x00a), + GP(int29, 0x14a), + GP(int2c, 0x162), + GP(int2d, 0x16a), + GP(prefixed_int2d, 0x16a), + GP(long_int2d, 0x16a), + GP(int81, 0x40a), + GP(intff, 0x7fa), + GP(hlt, 0), + TEST(short_int3, SIGTRAP, 3, 0, 1, 0, SI_KERNEL), + TEST(long_int3, SIGTRAP, 3, 0, 2, 0, SI_KERNEL), + TEST(int4, SIGSEGV, 4, 0, 2, 0, SI_KERNEL), + TEST(ud2, SIGILL, 6, 0, 0, X86_EFLAGS_RF, ILL_ILLOPN), +}; + +static const struct test *active; +static volatile sig_atomic_t seen, signo, trap, error, ip_offset, flags; +static volatile sig_atomic_t code, addr_ok, single_step, stepped, step_ok; + +static void handler(int sig, siginfo_t *info, void *context) +{ + ucontext_t *uc =3D context; + uintptr_t ip =3D uc->uc_mcontext.gregs[REG_IP]; + uintptr_t start =3D (uintptr_t)active->run; + uintptr_t end =3D (uintptr_t)active->end; + + if (seen && single_step && sig =3D=3D SIGTRAP) { + if (stepped++) { + ksft_print_msg("%s: second trace trap at %#lx\n", + active->name, (unsigned long)ip); + _exit(KSFT_FAIL); + } + step_ok =3D ip =3D=3D (uintptr_t)active->step && + uc->uc_mcontext.gregs[REG_TRAPNO] =3D=3D 1 && + info->si_code =3D=3D TRAP_TRACE; + uc->uc_mcontext.gregs[REG_EFL] &=3D ~X86_EFLAGS_TF; + return; + } + + if (seen || ip < start || ip > end) { + ksft_print_msg("%s: unexpected signal %d at %#lx\n", + active->name, sig, (unsigned long)ip); + _exit(KSFT_FAIL); + } + + signo =3D sig; + trap =3D uc->uc_mcontext.gregs[REG_TRAPNO]; + error =3D uc->uc_mcontext.gregs[REG_ERR]; + ip_offset =3D ip - start; + flags =3D uc->uc_mcontext.gregs[REG_EFL] & (X86_EFLAGS_RF | X86_EFLAGS_TF= ); + code =3D info->si_code; + /* force_sig() reports no address, force_sig_fault() reports the IP. */ + addr_ok =3D info->si_addr =3D=3D (code =3D=3D SI_KERNEL ? NULL : (void *)= ip); + seen =3D 1; + uc->uc_mcontext.gregs[REG_IP] =3D end; +} + +static void wait_for_child(pid_t child, int *status) +{ + pid_t ret; + + do { + ret =3D waitpid(child, status, 0); + } while (ret < 0 && errno =3D=3D EINTR); + if (ret !=3D child) + ksft_exit_fail_perror("waitpid"); +} + +/* Resume the tracee and check where the next stop lands. */ +static bool resume_to(pid_t child, int *status, int request, int sig, + const void *ip, const char *what) +{ + struct user_regs_struct regs; + + if (ptrace(request, child, 0, 0)) + return false; + wait_for_child(child, status); + if (!WIFSTOPPED(*status)) { + ksft_print_msg("%s: tracee did not stop\n", what); + return false; + } + if (WSTOPSIG(*status) !=3D sig) { + ksft_print_msg("%s: stopped with signal %d, expected %d\n", + what, WSTOPSIG(*status), sig); + return false; + } + if (ptrace(PTRACE_GETREGS, child, 0, ®s)) + return false; + if ((unsigned long)regs.USER_IP !=3D (unsigned long)ip) { + ksft_print_msg("%s: stopped at %#lx, expected %#lx\n", what, + (unsigned long)regs.USER_IP, (unsigned long)ip); + return false; + } + return true; +} + +static bool set_ip(pid_t child, const void *ip, bool tf) +{ + struct user_regs_struct regs; + + if (ptrace(PTRACE_GETREGS, child, 0, ®s)) + return false; + regs.USER_IP =3D (unsigned long)ip; + if (tf) + regs.eflags |=3D X86_EFLAGS_TF; + return !ptrace(PTRACE_SETREGS, child, 0, ®s); +} + +/* + * Exercise the tracer paths that resume through the fault frame rather th= an + * sigreturn. A stale FRED software event flag on that frame traps before = the + * NOP executes instead of after it. + */ +static void test_ptrace(void) +{ + bool into =3D false, step =3D false, cont =3D false; + pid_t child; + int status; + + child =3D fork(); + if (child < 0) + ksft_exit_fail_perror("fork"); + if (!child) { + if (ptrace(PTRACE_TRACEME, 0, 0, 0)) + _exit(KSFT_FAIL); + /* Start from a breakpoint frame, not the syscall frame of raise(). */ + asm volatile("int3"); + _exit(KSFT_FAIL); + } + + wait_for_child(child, &status); + if (!WIFSTOPPED(status) || WSTOPSIG(status) !=3D SIGTRAP) + goto out; + if (ptrace(PTRACE_SETOPTIONS, child, 0, PTRACE_O_EXITKILL)) + goto out; + + /* Single-step into the INT. The fault must report the INT's address. */ + if (!set_ip(child, int2d, false)) + goto out; + into =3D resume_to(child, &status, PTRACE_SINGLESTEP, SIGSEGV, int2d, + "single-step into INT"); + if (!into) + goto out; + + /* Suppress SIGSEGV and single-step the NOP. */ + if (!set_ip(child, int2d_end, false)) + goto out; + step =3D resume_to(child, &status, PTRACE_SINGLESTEP, SIGTRAP, int2d_step, + "single-step after INT"); + if (!step) + goto out; + + /* Fault again, then suppress SIGSEGV and continue with TF set. */ + if (!set_ip(child, int2d, false)) + goto out; + if (!resume_to(child, &status, PTRACE_CONT, SIGSEGV, int2d, + "continue to INT")) + goto out; + if (!set_ip(child, int2d_end, true)) + goto out; + cont =3D resume_to(child, &status, PTRACE_CONT, SIGTRAP, int2d_step, + "continue with TF after INT"); +out: + if (WIFSTOPPED(status)) { + kill(child, SIGKILL); + wait_for_child(child, &status); + } + ksft_test_result(into, "ptrace single-step into INT faults at the INT\n"); + ksft_test_result(step, "ptrace single-step after suppressing SIGSEGV\n"); + ksft_test_result(cont, "ptrace continue with TF after suppressing SIGSEGV= \n"); +} + +static bool cpu_has_fred(void) +{ + unsigned int eax, ebx, ecx, edx; + + if (__get_cpuid_max(0, NULL) < 7) + return false; + __cpuid_count(7, 1, eax, ebx, ecx, edx); + return eax & (1 << 17); +} + +int main(void) +{ + unsigned int i, tf; + int expected_flags, ok; + + ksft_print_header(); + ksft_set_plan(2 * ARRAY_SIZE(tests) + 3); + ksft_print_msg("CPU %s FRED\n", cpu_has_fred() ? "supports" : "lacks"); + sethandler(SIGSEGV, handler, 0); + sethandler(SIGTRAP, handler, 0); + sethandler(SIGILL, handler, 0); + + for (tf =3D 0; tf < 2; tf++) { + for (i =3D 0; i < ARRAY_SIZE(tests); i++) { + active =3D &tests[i]; + single_step =3D tf; + seen =3D signo =3D trap =3D error =3D ip_offset =3D flags =3D 0; + code =3D addr_ok =3D stepped =3D step_ok =3D 0; + expected_flags =3D active->flags | (tf ? X86_EFLAGS_TF : 0); + if (tf) + active->run_tf(); + else + active->run(); + + ok =3D seen && signo =3D=3D active->signo && trap =3D=3D active->trap && + error =3D=3D active->error && ip_offset =3D=3D active->ip_offset && + flags =3D=3D expected_flags && code =3D=3D active->code && addr_ok && + (!tf || (stepped && step_ok)); + ksft_test_result(ok, "%s%s\n", active->name, tf ? " with TF" : ""); + if (!ok) { + ksft_print_msg("got signal=3D%d trap=3D%d error=3D%#x ip=3D%d\n", + signo, trap, error, ip_offset); + ksft_print_msg("got flags=3D%#x code=3D%d addr_ok=3D%d step_ok=3D%d\n", + flags, code, addr_ok, step_ok); + ksft_print_msg("expected signal=3D%d trap=3D%d error=3D%#x ip=3D%d\n", + active->signo, active->trap, active->error, + active->ip_offset); + ksft_print_msg("expected flags=3D%#x code=3D%d\n", + expected_flags, active->code); + } + } + } + test_ptrace(); + ksft_finished(); +} --=20 2.55.0