Messages in this thread Patch in this message | | | Date | Fri, 25 Feb 2022 15:51:22 -0800 | From | Josh Poimboeuf <> | Subject | Re: [PATCH v2 18/39] x86/ibt: Add IBT feature, MSR and #CP handling |
| |
On Fri, Feb 25, 2022 at 11:51:01AM +0100, Peter Zijlstra wrote: > > > +bool ibt_selftest(void) > > > +{ > > > + unsigned long ret; > > > + > > > + asm ("1: lea 2f(%%rip), %%rax\n\t" > > > + ANNOTATE_RETPOLINE_SAFE > > > + " jmp *%%rax\n\t" > > > + ASM_REACHABLE > > > + ANNOTATE_NOENDBR > > > + "2: nop\n\t" > > > + > > > + /* unsigned ibt_selftest_ip = 2b */ > > > + ".pushsection .rodata,\"a\"\n\t" > > > + ".align 8\n\t" > > > + ".type ibt_selftest_ip, @object\n\t" > > > + ".size ibt_selftest_ip, 8\n\t" > > > + "ibt_selftest_ip:\n\t" > > > + ".quad 2b\n\t" > > > + ".popsection\n\t" > > > > It's still seems silly to make this variable in asm. > > > > Also .rodata isn't going to work for CPU hotplug. > > It's just the IP, that stays invariant. I'm not sure how else to match > regs->ip to 2 in #CP.
Ah, I see what you mean now. Still, it can just reference the code label itself without having to allocate storage:
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 4806fa0adec7..cfaa05ddd1ec 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -225,7 +225,7 @@ static void handle_endbr(struct pt_regs *regs) BUG(); } -extern const unsigned long ibt_selftest_ip; /* defined in asm beow */ +void ibt_selftest_ip(void); /* code label defined in asm below */ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) { @@ -237,7 +237,7 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) if (WARN_ON_ONCE(user_mode(regs) || error_code != 3)) return; - if (unlikely(regs->ip == ibt_selftest_ip)) { + if (unlikely(regs->ip == (unsigned long)ibt_selftest_ip)) { regs->ax = 0; return; } @@ -249,22 +249,12 @@ bool ibt_selftest(void) { unsigned long ret; - asm ("1: lea 2f(%%rip), %%rax\n\t" + asm ("1: lea ibt_selftest_ip(%%rip), %%rax\n\t" ANNOTATE_RETPOLINE_SAFE " jmp *%%rax\n\t" ASM_REACHABLE ANNOTATE_NOENDBR - "2: nop\n\t" - - /* unsigned ibt_selftest_ip = 2b */ - ".pushsection .rodata,\"a\"\n\t" - ".align 8\n\t" - ".type ibt_selftest_ip, @object\n\t" - ".size ibt_selftest_ip, 8\n\t" - "ibt_selftest_ip:\n\t" - ".quad 2b\n\t" - ".popsection\n\t" - + "ibt_selftest_ip: nop\n\t" : "=a" (ret) : : "memory"); return !ret;
| |