lkml.org 
[lkml]   [2021]   [Oct]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 4/9] x86/alternative: Implement .retpoline_sites support
On Wed, Oct 13, 2021 at 02:22:21PM +0200, Peter Zijlstra wrote:
> +static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)
> +{
> + void (*target)(void);
> + int reg, i = 0;
> +
> + if (cpu_feature_enabled(X86_FEATURE_RETPOLINE))
> + return -1;

Better to do this check further up the call stack in apply_retpolines()
before looping through all the call sites?

> +
> + target = addr + insn->length + insn->immediate.value;
> + reg = (target - &__x86_indirect_thunk_rax) /
> + (&__x86_indirect_thunk_rcx - &__x86_indirect_thunk_rax);
> +
> + if (WARN_ON_ONCE(reg & ~0xf))
> + return -1;

It would be more robust and less magical to just have a basic lookup
table array which converts a thunk address to a reg. Then you can just
avoid all the safety checks because it's no longer insane ;-)

--
Josh

\
 
 \ /
  Last update: 2021-10-13 22:40    [W:0.252 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site