Re: [PATCH] binfmt_elf: Introduce KUnit test
From: Daniel Latypov
Date: Tue Mar 01 2022 - 01:43:12 EST
On Mon, Feb 28, 2022 at 8:21 PM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> On Mon, 28 Feb 2022 17:48:27 -0800
> Daniel Latypov <dlatypov@xxxxxxxxxx> wrote:
>
> > He also prototyped a more intrusive alternative to using ftrace and
> > kernel livepatch since they don't work on all arches, like UML.
>
> Perhaps instead of working on a intrusive alternative on archs that do
> not support live kernel patching, implement live kernel patching on
> those archs! ;-)
>
> It's probably the same amount of work. Well, really, you only need to
> implement the klp_arch_set_pc(fregs, new_function); part.
Yeah, that's the only bit we'd need to get working.
I called this out in "Open questions:" bit on
https://kunit-review.googlesource.com/c/linux/+/5109
As for the amount of work, I know how to do KUnit-y things, I have no
idea how to do livepatch things :)
Also, we're not aiming for something as "magic" as the ftrace one.
David's patch is here: https://kunit-review.googlesource.com/c/linux/+/5129
Here's a snippet from the example in that one:
static int add_one(int i)
{
/* This will trigger the stub if active. */
KUNIT_TRIGGER_STATIC_STUB(add_one, i);
return i + 1;
}
i.e. users just add this one macro in with <func> and <args>.
It internally expands to roughly
if (<check if current test has registered a replacement>)
<invoke replacement with <args>
So it's all quite simple.
But it'd definitely be interesting to try and get klp_arch_set_pc()
working on UML if that's a possibility!
Speaking from ignorance, I can see this either being somewhat simple
or very painful.
>
> -- Steve