Re: [PATCH] x86/static_call: Fix __static_call_fixup()

From: Josh Poimboeuf
Date: Tue Aug 15 2023 - 20:11:26 EST


On Wed, Aug 16, 2023 at 01:08:09AM +0200, Peter Zijlstra wrote:
> bool __static_call_fixup(void *tramp, u8 op, void *dest)
> {
> + /*
> + * Not all .return_sites are a static_call trampoline (most are not).
> + * Check if the next 3 bytes are still kernel text, if not, then this

s/3/7 ?

> + * definitely is not a trampoline and we need not worry further.
> + *
> + * This avoids the memcmp() below tripping over pagefaults etc..
> + */
> + if (!kernel_text_address(tramp+7))
> + return false;
> +
> if (memcmp(tramp+5, tramp_ud, 3)) {
> /* Not a trampoline site, not our problem. */
> return false;

kernel_text_address() can be quite heavyweight to call in a loop during
module loading. Maybe that doesn't matter much. But it would be a lot
faster to only call kernel_text_address() if tramp+7 is on the next
page.

--
Josh