public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH 2/3] x86/callthunks: Handle %rip-relative relocations in call thunk template
Date: Thu, 2 Nov 2023 12:44:22 +0100	[thread overview]
Message-ID: <20231102114422.GB3818@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20231102112850.3448745-3-ubizjak@gmail.com>

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?

  reply	other threads:[~2023-11-02 11:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02 11:25 [PATCH 0/3] Fix and unify call thunks assembly snippets Uros Bizjak
2023-11-02 11:25 ` [PATCH 1/3] x86/callthunks: Move call thunk template to .S file Uros Bizjak
2023-11-02 11:25 ` [PATCH 2/3] x86/callthunks: Handle %rip-relative relocations in call thunk template Uros Bizjak
2023-11-02 11:44   ` Peter Zijlstra [this message]
2023-11-02 11:50     ` Uros Bizjak
2023-11-02 11:56       ` Peter Zijlstra
2023-11-02 12:34         ` Uros Bizjak
2023-11-02 11:25 ` [PATCH 3/3] x86/callthunks: Fix and unify call thunks assembly snippets Uros Bizjak
2023-11-05  8:23   ` kernel test robot

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=20231102114422.GB3818@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=ubizjak@gmail.com \
    --cc=x86@kernel.org \
    /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