[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231102114422.GB3818@noisy.programming.kicks-ass.net>
Date: Thu, 2 Nov 2023 12:44:22 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Uros Bizjak <ubizjak@...il.com>
Cc: x86@...nel.org, linux-kernel@...r.kernel.org,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...nel.org>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH 2/3] x86/callthunks: Handle %rip-relative relocations in
call thunk template
On Thu, Nov 02, 2023 at 12:25:47PM +0100, Uros Bizjak wrote:
> @@ -166,13 +168,51 @@ static const u8 nops[] = {
> 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
> };
>
> +#define apply_reloc_n(n_, p_, d_) \
> + do { \
> + s32 v = *(s##n_ *)(p_); \
> + v += (d_); \
> + BUG_ON((v >> 31) != (v >> (n_-1))); \
> + *(s##n_ *)(p_) = (s##n_)v; \
> + } while (0)
> +
> +static __always_inline
> +void apply_reloc(int n, void *ptr, uintptr_t diff)
> +{
> + switch (n) {
> + case 4: apply_reloc_n(32, ptr, diff); break;
> + default: BUG();
> + }
> +}
> +
> +static void apply_relocation(u8 *buf, size_t len, u8 *dest, u8 *src)
> +{
> + for (int next, i = 0; i < len; i = next) {
> + struct insn insn;
> +
> + if (WARN_ON_ONCE(insn_decode_kernel(&insn, &buf[i])))
> + return;
> +
> + next = i + insn.length;
> +
> + if (insn_rip_relative(&insn))
> + apply_reloc(insn.displacement.nbytes,
> + buf + i + insn_offset_displacement(&insn),
> + src - dest);
> + }
> +}
Isn't it simpler to use apply_relocation() from alternative.c?
Remove static, add decl, stuff like that?
Powered by blists - more mailing lists