Re: [RFC][PATCH 1/2] x86: Allow breakpoints to emulate call functions

From: Linus Torvalds
Date: Mon May 06 2019 - 12:18:22 EST


On Mon, May 6, 2019 at 6:56 AM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> I can test this too. I was hoping to get this in by this merge window.
> I spent 3 hours yesterday trying to get Linus's version working on
> i386 with no success. Not sure how much time Linus will have to look at
> this, as he just opened the merge window.

I acvtually just tested it in qemu, and it worked fine.

Ok, so my test was admittedly really simple and stupid, in that al I did was

printk("Before int3\n");
asm("int3; nop; nop; nop; nop" : : :"ax","dx","cx");
printk("After int3\n");

and then I hacked up do_kernel_int3() to just unconditionally do

return int3_emulate_call(regs, (unsigned long)test_int3);

with a stupid test-function:

void test_int3(void)
{
printk("In int3 handler");
}

instead fo anything fancy.

But it did exactly the expected thing, and resulted in

Before int3
In int3 handler
After int3

on the screen.

So what is it that doesn't actually work? I've looked at the patch
even more, and I can't for the life of me see how it wouldn't work.

Of course, I didn't test any of the actual ftrace parts, since I
short-circuited them intentionally with the above test function hack.
I have no idea what the semantics for those
ftrace_location(ip)/is_ftrace_caller(ip) cases are supposed to be, I
only tested that yes, the infrastructure clearly emulates a call
instruction.

Linus