On Fri, May 3, 2019 at 10:08 PM Linus Torvalds torvalds@linux-foundation.org wrote:
I'll look at it tomorrow, but I think this actually makes unnecessary changes.
In particular, I think we could keep the existing entry code almost unchanged with this whole approach.
So here's what I *think* should work. Note that I also removed your test-case code, because it really didn't have a chance in hell of working. Doing that
int3_emulate_call(regs, (unsigned long)&int3_magic);
inside of int3_exception_notify() could not possibly be valid, since int3_emulate_call() returns the new pt_regs that need to be used, and throwing it away is clearly wrong.
So you can't use a register_die_notifier() to try to intercept the 'int3' error and then do it manually, it needs to be done by the ftrace_int3_handler() code that actually returns the new regs, and where do_kernel_int3() will then return it to the low-level handler.
End result: I haven't actually tested this code, but I've looked through the patch something like ten times without finding any new errors.
I've also tried *very* hard to make the patch minimal, with the exception of the comments, which I tried to make extensive for any of the subtle cases.
But without testing, it's probably still buggy.
I have to say, I finally like the end result here. Maybe it's because I got to make my mark and pee in the snow, but I will say that
(a) the actual entry code modifications really are minimal now
(b) the instruction emulation really is very simple and straightforward
(c) yes, we play some stack tricks (and yes, we play them differently on x86-64 and x86-32), but the tricks are again at least straightforward, and we never really change the layout of any stack.
So on the whole, I think this is about as good as it gets. Did I get all the details actually right, and it _works_? I guess we'll see.
Linus