On 5/21/25 23:05, Xin Li (Intel) wrote:
+/*
- To prevent infinite SIGTRAP handler loop if TF is used without an external
- debugger, clear the software event flag in the augmented SS, ensuring no
- single-step trap is pending upon ERETU completion.
- Note, this function should be called in sigreturn() before the original state
- is restored to make sure the TF is read from the entry frame.
- */
+static __always_inline void prevent_single_step_upon_eretu(struct pt_regs *regs) +{
- /*
* If the trap flag (TF) is set, i.e., the sigreturn() SYSCALL instruction
* is being single-stepped, do not clear the software event flag in the
* augmented SS, thus a debugger won't skip over the following instruction.
*/
- if (IS_ENABLED(CONFIG_X86_FRED) && cpu_feature_enabled(X86_FEATURE_FRED) &&
!(regs->flags & X86_EFLAGS_TF))
regs->fred_ss.swevent = 0;
+}
Minor nit (and I should have caught this when I saw your patch earlier):
cpu_feature_enabled(X86_FEATURE_FRED) is unnecessary here, because when FRED is not enabled, regs->fred_ss.swevent will always be 0, and this bit has no function, so there is no point in making that extra test.
The only reason for IS_ENABLED(CONFIG_X86_FRED) (which is implied in cpu_feature_enabled() anyway via !CONFIG_X86_DISABLED_FEATURE_FRED) is to eliminate the code entirely if FRED is not compiled in.
Although the way it goes, it sounds like CONFIG_X86_FRED might go away soon anyway, since KVM wants to use some of the FRED code unconditionally (and Xen might follow, too.)
-hpa