[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240912075714.GT4723@noisy.programming.kicks-ass.net>
Date: Thu, 12 Sep 2024 09:57:14 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: "Xin Li (Intel)" <xin@...or.com>
Cc: linux-kernel@...r.kernel.org, tglx@...utronix.de, mingo@...hat.com,
bp@...en8.de, dave.hansen@...ux.intel.com, x86@...nel.org,
hpa@...or.com, andrew.cooper3@...rix.com
Subject: Re: [PATCH v1 1/1] x86/fred: Clear the WFE bit in missing-ENDBRANCH
#CP
On Wed, Sep 11, 2024 at 04:19:29PM -0700, Xin Li (Intel) wrote:
> +static void ibt_clear_fred_wfe(struct pt_regs *regs)
> +{
> + if (cpu_feature_enabled(X86_FEATURE_FRED))
> + regs->fred_cs.wfe = 0;
> +}
> +
> static void do_kernel_cp_fault(struct pt_regs *regs, unsigned long error_code)
> {
> if ((error_code & CP_EC) != CP_ENDBR) {
> @@ -90,6 +107,7 @@ static void do_kernel_cp_fault(struct pt_regs *regs, unsigned long error_code)
>
> if (unlikely(regs->ip == (unsigned long)&ibt_selftest_noendbr)) {
> regs->ax = 0;
> + ibt_clear_fred_wfe(regs);
> return;
> }
>
> @@ -97,6 +115,7 @@ static void do_kernel_cp_fault(struct pt_regs *regs, unsigned long error_code)
> if (!ibt_fatal) {
> printk(KERN_DEFAULT CUT_HERE);
> __warn(__FILE__, __LINE__, (void *)regs->ip, TAINT_WARN, regs, NULL);
> + ibt_clear_fred_wfe(regs);
> return;
> }
> BUG();
So, why not clear the bit the moment we know this is CP_ENDBR?
In the fatal case, we'll hit that BUG and die anyway, nobody cares about
the tracker state in that case.
diff --git a/arch/x86/kernel/cet.c b/arch/x86/kernel/cet.c
index d2c732a34e5d..fde4bdd25a73 100644
--- a/arch/x86/kernel/cet.c
+++ b/arch/x86/kernel/cet.c
@@ -88,6 +88,8 @@ static void do_kernel_cp_fault(struct pt_regs *regs, unsigned long error_code)
return;
}
+ ibt_clear_fred_wfe(regs);
+
if (unlikely(regs->ip == (unsigned long)&ibt_selftest_noendbr)) {
regs->ax = 0;
return;
Powered by blists - more mailing lists