mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: "Xin Li (Intel)" <xin@zytor.com>, linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org,
	peterz@infradead.org, andrew.cooper3@citrix.com,
	stable@vger.kernel.org
Subject: Re: [PATCH v1 1/1] x86/fred/signal: Prevent single-step upon ERETU completion
Date: Thu, 22 May 2025 00:20:13 -0700	[thread overview]
Message-ID: <e32dc7de-9f97-4857-8e07-0905a94acfad@zytor.com> (raw)
In-Reply-To: <20250522060549.2882444-1-xin@zytor.com>

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


  reply	other threads:[~2025-05-22  7:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-22  6:05 Xin Li (Intel)
2025-05-22  7:20 ` H. Peter Anvin [this message]
2025-05-22 17:10   ` Xin Li
2025-05-22 17:20 ` kernel test robot
2025-05-22 17:33   ` Xin Li
2025-05-22 17:51     ` Andrew Cooper
2025-05-23  6:23       ` Xin Li
2025-05-22 17:54     ` Dave Hansen
2025-05-23  6:24       ` 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=e32dc7de-9f97-4857-8e07-0905a94acfad@zytor.com \
    --to=hpa@zytor.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.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 \
    --cc=xin@zytor.com \
    /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®