Re: [PATCH] x86/alternatives: gracefully skip unrecognized indirect call instructions

From: H. Peter Anvin

Date: Wed Aug 12 2026 - 07:28:54 EST


On August 12, 2026 4:00:23 AM PDT, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>On Wed, Aug 12, 2026 at 05:22:14PM +0800, 李则良 wrote:
>> From cd58bd112a6178593c6bc9c0f9b307d6897ae3d0 Mon Sep 17 00:00:00 2001
>> From: Zeliang Li <lizeliang.linux@xxxxxxxxx>
>> Date: Tue, 11 Aug 2026 19:09:09 +0800
>> Subject: [PATCH v2] x86/alternative: WARN and skip unrecognized indirect call
>> only for non-O2 builds
>>
>> When the kernel is compiled at a non-default optimization level
>> (e.g., KCFLAGS=-O1 or -O0), the compiler may emit call instruction
>> patterns that differ from the expected 6-byte sequence
>> (opcodes 0xff 0x15 followed by a 32-bit displacement) checked
>> by alt_replace_call().
>
>I don't think we want to cater for this. But what actual instruction
>sequences is it emitting?

I'm kind of surprised the kernel compiles with -O0 at all; it certainly didn't used to. -Og was created for a reason.

That being said, if it helps someone debug a problem as long as the kernel also screams "bloody murder don't use me in production" it might be useful.

Honestly, thinking about it, an "unsafe_debug=..." or similar kernel command line option might be justified for things like this; by requiring an active user step to enable the unsafe behavior it should make it much harder for something to sneak into production.

-hpa