Re: [PATCH v7 7/8] [DO NOT MERGE] x86/kexec: Add int3 in kexec path for testing

From: David Woodhouse
Date: Thu Mar 13 2025 - 07:10:18 EST


On 13 March 2025 11:44:41 CET, Ingo Molnar <mingo@xxxxxxxxxx> wrote:
>
>* David Woodhouse <dwmw2@xxxxxxxxxxxxx> wrote:
>
>> From: David Woodhouse <dwmw@xxxxxxxxxxxx>
>>
>> Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
>> ---
>> arch/x86/kernel/relocate_kernel_64.S | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
>> index 17d41e6e1a4b..2b7fc59af373 100644
>> --- a/arch/x86/kernel/relocate_kernel_64.S
>> +++ b/arch/x86/kernel/relocate_kernel_64.S
>> @@ -158,7 +158,7 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
>> lidt (%rsp)
>> addq $10, %rsp
>>
>> - //int3
>> + int3
>
>So this is all boot-serialized functionality with no SMP concerns
>whatsoever, right?
>
>If yes then we could use something like this:
>
> static int exception_selftest = 1;
>
>and add the INT3 point:
>
> int3
>.globl after_int3
>after_int3:
>
>And do this in the early exception handler:
>
> ...
>
> if (exception_selftest) {
> exception_selftest = 0;
>
> print_something_warm_and_fuzzy();
>
> IRET-to-after_int3;
> }
>
> ...
>
> ... regular exception path ...
>
>... but all in assembly or so ;-)
>
>This would make it reasonably certain that the most complex bits of
>this new debuging code are in working order, all the time.
>
>Thanks,
>
> Ingo

The exception handler already returns if the exception was int3, but not for anything else. Less so the "print something warm and fuzzy" part; it just does the same register dump. But we could change that.

I'm less keen on making it unconditional though. Kexec is a performance-critical path when every millisecond is perceived as guest steal time, and the serial output should only happen in production if something goes *wrong*.

And besides, most kexec users don't have early_printk enabled anyway so if we break them, this idea doesn't help.