Skip to contentSkip to conversation

livepatch: introduce klp_func called interface

PATCH In review Wardenjohn 6 participants 26 messages May 20, 2024 – Jun 20, 2024

Subsystems (2)
lore
Share & tools
lore

Wardenjohn

author
#0 lore raw

PATCH 1/1 livepatch: introduce klp_func called interface

Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash.

This is a kobject attribute of klp_func. Sysfs interface named
"called" is introduced to livepatch which will be set as true
if the patched function is called.

/sys/kernel/livepatch/<patch>/<object>/<function,sympos>/called

This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called.
Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.

---
 include/linux/livepatch.h |  2 ++
 kernel/livepatch/core.c   | 18 ++++++++++++++++++
 kernel/livepatch/patch.c  |  2 ++
 3 files changed, 22 insertions(+)
include/linux/livepatch.h +2 -0
index 51a258c24ff5..026431825593 100644
@@ -37,6 +37,7 @@
  * @nop:        temporary patch to use the original code again; dyn. allocated
  * @patched:	the func has been added to the klp_ops list
  * @transition:	the func is currently being applied or reverted
+ * @called:		the func is called
  *
  * The patched and transition variables define the func's patching state.  When
  * patching, a func is always in one of the following states:
@@ -75,6 +76,7 @@ struct klp_func {
 	bool nop;
 	bool patched;
 	bool transition;
+	bool called;
 };
 
 struct klp_object;
kernel/livepatch/core.c +18 -0
index 52426665eecc..a840ddd41d00 100644
@@ -470,6 +470,22 @@ static struct attribute *klp_object_attrs[] = {
 };
 ATTRIBUTE_GROUPS(klp_object);
 
+static ssize_t called_show(struct kobject *kobj,
+				struct kobj_attribute *attr, char *buf)
+{
+	struct klp_func *func;
+
+	func = container_of(kobj, struct klp_func, kobj);
+	return sysfs_emit(buf, "%d\n", func->called);
+}
+
+static struct kobj_attribute called_kobj_attr = __ATTR_RO(called);
+static struct attribute *klp_func_attrs[] = {
+	&called_kobj_attr.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(klp_func);
+
 static void klp_free_object_dynamic(struct klp_object *obj)
 {
 	kfree(obj->name);
@@ -631,6 +647,7 @@ static void klp_kobj_release_func(struct kobject *kobj)
 static const struct kobj_type klp_ktype_func = {
 	.release = klp_kobj_release_func,
 	.sysfs_ops = &kobj_sysfs_ops,
+	.default_groups = klp_func_groups,
 };
 
 static void __klp_free_funcs(struct klp_object *obj, bool nops_only)
@@ -903,6 +920,7 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
 static void klp_init_func_early(struct klp_object *obj,
 				struct klp_func *func)
 {
+	func->called = false;
 	kobject_init(&func->kobj, &klp_ktype_func);
 	list_add_tail(&func->node, &obj->func_list);
 }
kernel/livepatch/patch.c +2 -0
index 90408500e5a3..75b9603a183f 100644
@@ -118,6 +118,8 @@ static void notrace klp_ftrace_handler(unsigned long ip,
 	if (func->nop)
 		goto unlock;
 
+	if (!func->called)
+		func->called = true;
 	ftrace_regs_set_instruction_pointer(fregs, (unsigned long)func->new_func);
 
 unlock:
Signature · 1 line
2.37.3
maintainer
#1 lore raw

Hi,

Quoted 10 lines · Wardenjohn

Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash.

This is a kobject attribute of klp_func. Sysfs interface named
"called" is introduced to livepatch which will be set as true
if the patched function is called.

/sys/kernel/livepatch/<patch>/<object>/<function,sympos>/called

Quoted 7 lines

This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called.
Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.

Even easier is to use the existing tracing infrastructure in the kernel (ftrace for example) to track the new function. You can obtain much more information with that than the new attribute provides.

Regards,
Miroslav

#2 lore raw
Quoted 26 lines · Miroslav Benes

Hi,

Quoted 10 lines · Wardenjohn

Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash.

This is a kobject attribute of klp_func. Sysfs interface named "called" is introduced to livepatch which will be set as true if the patched function is called.

/sys/kernel/livepatch/<patch>/<object>/<function,sympos>/called

Quoted 7 lines

This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called.
Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.

Quoted 6 lines

Even easier is to use the existing tracing infrastructure in the kernel (ftrace for example) to track the new function. You can obtain much more information with that than the new attribute provides.

Regards,
Miroslav

Hi Miroslav

First, in most cases, testing process is should be automated, which make using existing tracing infrastructure inconvenient. Second, livepatch is already use ftrace for functional replacement, I don’t think it is a good choice of using kernel tracing tool to trace a patched function.

At last, this attribute can be thought of as a state of a livepatch function. It is a state, like the "patched" "transition" state of a klp_patch. Adding this state will not break the state consistency of livepatch.

Regards,
Wardenjohn

maintainer
#3 lore raw

Hello,

Quoted 30 lines · zhang warden
Quoted 30 lines · Miroslav Benes

Hi,

Quoted 10 lines · Wardenjohn

Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash.

This is a kobject attribute of klp_func. Sysfs interface named "called" is introduced to livepatch which will be set as true if the patched function is called.

/sys/kernel/livepatch/<patch>/<object>/<function,sympos>/called

Quoted 7 lines

This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called.
Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.

Even easier is to use the existing tracing infrastructure in the kernel (ftrace for example) to track the new function. You can obtain much more information with that than the new attribute provides.

Quoted 6 lines
Quoted 2 lines

Regards,
Miroslav

Hi Miroslav

First, in most cases, testing process is should be automated, which make using existing tracing infrastructure inconvenient.

could you elaborate, please? We use ftrace exactly for this purpose and our testing process is also more or less automated.

Quoted 3 lines

Second, livepatch is
already use ftrace for functional replacement, I don’t think it is a good choice of using kernel tracing tool to trace a patched function.

Why?

Quoted 4 lines

At last, this attribute can be thought of as a state of a livepatch function. It is a state, like the "patched" "transition" state of a klp_patch. Adding this state will not break the state consistency of livepatch.

Yes, but the information you get is limited compared to what is available now. You would obtain the information that a patched function was called but ftrace could also give you the context and more.

It would not hurt to add a new attribute per se but I am wondering about the reason and its usage. Once we have it, the commit message should be improved based on that.

Regards,
Miroslav

maintainer
#4 lore raw
Quoted 50 lines · Miroslav Benes

Hello,

Quoted 30 lines · zhang warden
Quoted 30 lines · Miroslav Benes

Hi,

Quoted 10 lines · Wardenjohn

Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash.

This is a kobject attribute of klp_func. Sysfs interface named "called" is introduced to livepatch which will be set as true if the patched function is called.

/sys/kernel/livepatch/<patch>/<object>/<function,sympos>/called

Quoted 7 lines

This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called.
Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.

Even easier is to use the existing tracing infrastructure in the kernel (ftrace for example) to track the new function. You can obtain much more information with that than the new attribute provides.

Quoted 6 lines
Quoted 2 lines

Regards,
Miroslav

Hi Miroslav

First, in most cases, testing process is should be automated, which make using existing tracing infrastructure inconvenient.

could you elaborate, please? We use ftrace exactly for this purpose and our testing process is also more or less automated.

Quoted 3 lines

Second, livepatch is
already use ftrace for functional replacement, I don’t think it is a good choice of using kernel tracing tool to trace a patched function.

Why?

Quoted 8 lines
Quoted 4 lines

At last, this attribute can be thought of as a state of a livepatch function. It is a state, like the "patched" "transition" state of a klp_patch. Adding this state will not break the state consistency of livepatch.

Yes, but the information you get is limited compared to what is available now. You would obtain the information that a patched function was called but ftrace could also give you the context and more.

Another motivation to use ftrace for testing is that it does not affect the performance in production.

We should keep klp_ftrace_handler() as fast as possible so that we could livepatch also performance sensitive functions.

Best Regards,
Petr

#5 lore raw
Quoted 10 lines · Petr Mladek

Another motivation to use ftrace for testing is that it does not affect the performance in production.

We should keep klp_ftrace_handler() as fast as possible so that we could livepatch also performance sensitive functions.

How about using unlikely() for branch testing? If we use unlikely, maybe there is no negative effect to klp_ftrace_handler() once this function is called.

Regards,
Wardenjohn

#6 lore raw
In reply to Petr Mladek

Hi Bros,

How about my patch? I do think it is a viable feature to show the state of the patched function. If we add an unlikely branch test before we set the 'called' state, once this function is called, there maybe no negative effect to the performance.

Please give me some advice.

Regards,
Wardenjohn

maintainer
#7 lore raw

Hi,

Quoted 7 lines · zhang warden

Hi Bros,

How about my patch? I do think it is a viable feature to show the state of the patched function. If we add an unlikely branch test before we set the 'called' state, once this function is called, there maybe no negative effect to the performance.

you have not replied to my questions/feedback yet.

Also, I do not think that unlikely changes anything here. It is a simple branch after all.

Miroslav

#8 lore raw
Quoted 14 lines · Miroslav Benes

Hi,

On Fri, 31 May 2024, zhang warden wrote:

you have not replied to my questions/feedback yet.

Also, I do not think that unlikely changes anything here. It is a simple branch after all.

Miroslav

Hi Miroslav,

Sorry for my carelessness. I apologise for my ignorance.

Quoted 3 lines

Second, livepatch is
already use ftrace for functional replacement, I don’t think it is a good choice of using kernel tracing tool to trace a patched function.

I admit that ftrace can use for tracing the new patched function. But for some cases, user who what to know the state of this function can easily cat the 'called' interface.

It is more convenient than using ftrace to trace the state.

And for the unlikely branch, isn’t the complier will compile this branch into a cold branch that will do no harm to the function performance?

Regards,
Wardenjohn

maintainer
#9 lore raw
Quoted 2 lines

And for the unlikely branch, isn’t the complier will compile this branch into a cold branch that will do no harm to the function performance?

The test (cmp insn or something like that) still needs to be there. Since there is only a simple assignment in the branch, the compiler may just choose not to have a cold branch in this case. The only difference is in which case you would jump here. You can see for yourself (and prove me wrong if it comes to it).

Miroslav

#10 lore raw
Quoted 7 lines · Miroslav Benes
Quoted 3 lines

And for the unlikely branch, isn’t the complier will compile this branch into a cold branch that will do no harm to the function performance?

Quoted 7 lines

The test (cmp insn or something like that) still needs to be there. Since there is only a simple assignment in the branch, the compiler may just choose not to have a cold branch in this case. The only difference is in which case you would jump here. You can see for yourself (and prove me wrong if it comes to it).

Miroslav

Hi Miroslav,

Yes, more tests should be done in this case according to your opinion.

Regards,
Wardenjohn

maintainer
#11 lore raw
In reply to Petr Mladek

On Tue, May 21, 2024 at 1:04 AM Petr Mladek <[email protected]> wrote:
[...]

Quoted 10 lines
Quoted 4 lines

Yes, but the information you get is limited compared to what is available now. You would obtain the information that a patched function was called but ftrace could also give you the context and more.

Another motivation to use ftrace for testing is that it does not affect the performance in production.

We should keep klp_ftrace_handler() as fast as possible so that we could livepatch also performance sensitive functions.

At LPC last year, we discussed about adding a counter to each klp_func, like:

struct klp_func {
    ...
    u64 __percpu counter;
    ...
};

With some static_key (+ sysctl), this should give us a way to estimate the overhead of livepatch. If we have the counter, this patch is not needed any more. Does this (adding the counter) sound like something we still want to pursue?

Thanks,
Song

maintainer
#12 lore raw

Hi,

Quoted 22 lines · Song Liu

On Tue, May 21, 2024 at 1:04 AM Petr Mladek <[email protected]> wrote:
[...]

Quoted 10 lines
Quoted 4 lines

Yes, but the information you get is limited compared to what is available now. You would obtain the information that a patched function was called but ftrace could also give you the context and more.

Another motivation to use ftrace for testing is that it does not affect the performance in production.

We should keep klp_ftrace_handler() as fast as possible so that we could livepatch also performance sensitive functions.

At LPC last year, we discussed about adding a counter to each klp_func, like:

struct klp_func {
    ...
    u64 __percpu counter;
    ...
};
Quoted 4 lines

With some static_key (+ sysctl), this should give us a way to estimate the overhead of livepatch. If we have the counter, this patch is not needed any more. Does this (adding the counter) sound like something we still want to pursue?

It would be better than this patch but given what was mentioned in the thread I wonder if it is possible to use ftrace even for this. See /sys/kernel/tracing/trace_stat/function*. It already gathers the number of hits.

Would it be sufficient for you? I guess it depends on what the intention is. If there is no time limit, klp_func.counter might be better to provide some kind of overall statistics (but I am not sure if it has any value) and to avoid having ftrace registered on a live patched function for infinite period of time. If the intention is to gather data for some limited period, trace_stat sounds like much better approach to me.

Regards
Miroslav

maintainer
#13 lore raw

Hi Miroslav,

Quoted 32 lines · Miroslav Benes

Hi,

Quoted 22 lines · Song Liu

On Tue, May 21, 2024 at 1:04 AM Petr Mladek <[email protected]> wrote:
[...]

Quoted 10 lines
Quoted 4 lines

Yes, but the information you get is limited compared to what is available now. You would obtain the information that a patched function was called but ftrace could also give you the context and more.

Another motivation to use ftrace for testing is that it does not affect the performance in production.

We should keep klp_ftrace_handler() as fast as possible so that we could livepatch also performance sensitive functions.

At LPC last year, we discussed about adding a counter to each klp_func, like:

struct klp_func {
    ...
    u64 __percpu counter;
    ...
};
Quoted 4 lines

With some static_key (+ sysctl), this should give us a way to estimate the overhead of livepatch. If we have the counter, this patch is not needed any more. Does this (adding the counter) sound like something we still want to pursue?

Quoted 4 lines

It would be better than this patch but given what was mentioned in the thread I wonder if it is possible to use ftrace even for this. See /sys/kernel/tracing/trace_stat/function*. It already gathers the number of hits.

I didn't know about the trace_stat API until today. :) It somehow doesn't exist on some older kernels. (I haven't debugged it.)

Quoted 6 lines

Would it be sufficient for you? I guess it depends on what the intention is. If there is no time limit, klp_func.counter might be better to provide some kind of overall statistics (but I am not sure if it has any value) and to avoid having ftrace registered on a live patched function for infinite period of time. If the intention is to gather data for some limited period, trace_stat sounds like much better approach to me.

We don't have very urgent use for this. As we discussed, various tracing tools are sufficient in most cases. I brought this up in the context of the "called" entry: if we are really adding a new entry, let's do "counter" instead of "called".

Thanks,
Song

#14 lore raw
Quoted 8 lines

We don't have very urgent use for this. As we discussed, various tracing tools are sufficient in most cases. I brought this up in the context of the "called" entry: if we are really adding a new entry, let's do "counter" instead of "called".

Thanks,
Song

Hi, Song

I hope to find a way to optimize "called" will be set once in klp_ftrace_ops function because as Petr said this function should be as fast as possible. But if use "count", this variable will be called every time klp_ftrace_ops run.

Regards,
Wardenjohn

#15 lore raw
In reply to Miroslav Benes
Quoted 9 lines · Miroslav Benes

It would be better than this patch but given what was mentioned in the thread I wonder if it is possible to use ftrace even for this. See /sys/kernel/tracing/trace_stat/function*. It already gathers the number of hits.

Hi, Miroslav

Can ftrace able to trace the function which I added into kernel by livepatching?

Regard
Wardenjohn

maintainer
#16 lore raw

Hi,

Quoted 10 lines · zhang warden
Quoted 9 lines · Miroslav Benes

It would be better than this patch but given what was mentioned in the thread I wonder if it is possible to use ftrace even for this. See /sys/kernel/tracing/trace_stat/function*. It already gathers the number of hits.

Quoted 3 lines

Hi, Miroslav

Can ftrace able to trace the function which I added into kernel by livepatching?

yes, it should also work as is. I just generally recommend to use a different name (prefixed for example) for the new replacement function to avoid issues if you do not already do it.

Miroslav

maintainer
#17 lore raw
In reply to Miroslav Benes
Quoted 55 lines · Miroslav Benes

Hello,

Quoted 30 lines · zhang warden
Quoted 30 lines · Miroslav Benes

Hi,

Quoted 10 lines · Wardenjohn

Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash.

This is a kobject attribute of klp_func. Sysfs interface named "called" is introduced to livepatch which will be set as true if the patched function is called.

/sys/kernel/livepatch/<patch>/<object>/<function,sympos>/called

Quoted 7 lines

This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called.
Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.

Even easier is to use the existing tracing infrastructure in the kernel (ftrace for example) to track the new function. You can obtain much more information with that than the new attribute provides.

Quoted 6 lines
Quoted 2 lines

Regards,
Miroslav

Hi Miroslav

First, in most cases, testing process is should be automated, which make using existing tracing infrastructure inconvenient.

could you elaborate, please? We use ftrace exactly for this purpose and our testing process is also more or less automated.

Quoted 3 lines

Second, livepatch is
already use ftrace for functional replacement, I don’t think it is a good choice of using kernel tracing tool to trace a patched function.

Why?

Quoted 4 lines

At last, this attribute can be thought of as a state of a livepatch function. It is a state, like the "patched" "transition" state of a klp_patch. Adding this state will not break the state consistency of livepatch.

Quoted 8 lines

Yes, but the information you get is limited compared to what is available now. You would obtain the information that a patched function was called but ftrace could also give you the context and more.

It would not hurt to add a new attribute per se but I am wondering about the reason and its usage. Once we have it, the commit message should be improved based on that.

I agree with Miroslav about using ftrace, or Dan in the other thread about using gcov if even more granular coverage is needed.

Admittedly, I would have to go find documentation to remember how to do either, but at least I'd be using well-tested facilities designed for this exact purpose.

Adding these attributes to livepatch sysfs would be expedient and probably easier for us to use, but imposes a recurring burden on us to maintain and test (where is the documentation and kselftest for this new interface?). Or, we could let the other tools handle all of that for us.

Perhaps if someone already has an off-the-shelf script that is using ftrace to monitor livepatched code, it could be donated to Documentation/livepatch/? I can ask our QE folks if they have something like this.

Regards,

--
Joe

#18 lore raw
Quoted 9 lines · Joe Lawrence

Adding these attributes to livepatch sysfs would be expedient and probably easier for us to use, but imposes a recurring burden on us to maintain and test (where is the documentation and kselftest for this new interface?). Or, we could let the other tools handle all of that for us.

How this attribute imposes a recurring burden to maintain and test?

Quoted 4 lines

Perhaps if someone already has an off-the-shelf script that is using ftrace to monitor livepatched code, it could be donated to Documentation/livepatch/? I can ask our QE folks if they have something like this.

My intention to introduce this attitude to sysfs is that user who what to see if this function is called can just need to show this function attribute in the livepatch sysfs interface.

User who have no experience of using ftrace will have problems to get the calling state of the patched function. After all, ftrace is a professional kernel tracing tools.

Adding this attribute will be more easier for us to show if this patched function is called. Actually, I have never try to use ftrace to trace a patched function. Is it OK of using ftrace for a livepatched function?

Regards,
Wardenjohn

#19 lore raw
Quoted 3 lines

My intention to introduce this attitude to sysfs is that user who what to see if this function is called can just need to show this function attribute in the livepatch sysfs interface.

Sorry bros,
There is a typo in my word : attitude -> attribute

Autocomplete make it wrong….lol..

Wardenjohn

maintainer
#20 lore raw
In reply to zhang warden
Quoted 11 lines · zhang warden
Quoted 9 lines · Joe Lawrence

Adding these attributes to livepatch sysfs would be expedient and probably easier for us to use, but imposes a recurring burden on us to maintain and test (where is the documentation and kselftest for this new interface?). Or, we could let the other tools handle all of that for us.

How this attribute imposes a recurring burden to maintain and test?

Perhaps "responsibility" is a better description. This would introduce an attribute that someone's userspace utility is relying on. It should at least have a kselftest to ensure a random patch in 2027 doesn't break it.

Quoted 11 lines
Quoted 4 lines

Perhaps if someone already has an off-the-shelf script that is using ftrace to monitor livepatched code, it could be donated to Documentation/livepatch/? I can ask our QE folks if they have something like this.

My intention to introduce this attitude to sysfs is that user who what to see if this function is called can just need to show this function attribute in the livepatch sysfs interface.

User who have no experience of using ftrace will have problems to get the calling state of the patched function. After all, ftrace is a professional kernel tracing tools.

Adding this attribute will be more easier for us to show if this patched function is called. Actually, I have never try to use ftrace to trace a patched function. Is it OK of using ftrace for a livepatched function?

If you build with CONFIG_SAMPLE_LIVEPATCH=m, you can try it out (or with one of your own livepatches):

# Convenience variable

  $ SYSFS=/sys/kernel/debug/tracing

# Install the livepatch sample demo module

  $ insmod samples/livepatch/livepatch-sample.ko

# Verify that ftrace can filter on our functions

  $ grep cmdline_proc_show $SYSFS/available_filter_functions
  cmdline_proc_show
  livepatch_cmdline_proc_show [livepatch_sample]

# Turn off any existing tracing and filter functions

  $ echo 0 > $SYSFS/tracing_on
  $ echo > $SYSFS/set_ftrace_filter

# Set up the function tracer and add the kernel's cmdline_proc_show()

# and livepatch-sample's livepatch_cmdline_proc_show()
  $ echo function > $SYSFS/current_tracer
  $ echo cmdline_proc_show >> $SYSFS/set_ftrace_filter
  $ echo livepatch_cmdline_proc_show >> $SYSFS/set_ftrace_filter
  $ cat $SYSFS/set_ftrace_filter
  cmdline_proc_show
  livepatch_cmdline_proc_show [livepatch_sample]

# Turn on the ftracing and force execution of the original and

# livepatched functions
  $ echo 1 > $SYSFS/tracing_on
  $ cat /proc/cmdline 
  this has been live patched

# Checkout out the trace file results

  $ cat $SYSFS/trace
  # tracer: function
  #
  # entries-in-buffer/entries-written: 2/2   #P:8
  #
  #                                _-----=> irqs-off/BH-disabled
  #                               / _----=> need-resched
  #                              | / _---=> hardirq/softirq
  #                              || / _--=> preempt-depth
  #                              ||| / _-=> migrate-disable
  #                              |||| /     delay
  #           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
  #              | |         |   |||||     |         |
               cat-254     [002] ...2.   363.043498: cmdline_proc_show <-seq_read_iter
               cat-254     [002] ...1.   363.043501: livepatch_cmdline_proc_show <-seq_read_iter

The kernel docs provide a lot of explanation of the complete ftracing interface. It's pretty power stuff, though you may also go the other direction and look into using the trace-cmd front end to simplify all of the sysfs manipulation. Julia Evans wrote a blog [1] a while back that provides a some more examples.

[1] https://jvns.ca/blog/2017/03/19/getting-started-with-ftrace/

--
Joe

#21 lore raw

Hi Joe,

Quoted 5 lines

Perhaps "responsibility" is a better description. This would introduce an attribute that someone's userspace utility is relying on. It should at least have a kselftest to ensure a random patch in 2027 doesn't break it.

I sent this patch to see the what the community thinks about this attribute (although it think it is necessary and this will be more convenient for users).

If this patch is seems to be good, I will add a kselftest to this attribute.

As Miroslav and Petr said, keeping klp_ftrace_handler() as fast as possible is also important, which I need to find a way to keep it fast (or just setting the state to be true instead of a judgement?).

Quoted 10 lines

The kernel docs provide a lot of explanation of the complete ftracing interface. It's pretty power stuff, though you may also go the other direction and look into using the trace-cmd front end to simplify all of the sysfs manipulation. Julia Evans wrote a blog [1] a while back that provides a some more examples.

[1] https://jvns.ca/blog/2017/03/19/getting-started-with-ftrace/

--
Joe

Nice of you! Thanks! I will learn it!

Regards,
Wardenjohn

maintainer
#22 lore raw

Hi Wardenjohn,

To follow up, Red Hat kpatch QE pointed me toward this test:

https://gitlab.com/redhat/centos-stream/tests/kernel/kernel-tests/-/tree/main/general/kpatch/kpatch-trace?ref_type=heads

which reports a few interesting things via systemd service and ftrace:

- Patched functions
- Traced functions
- Code that was modified, but didn't run
- Other code that ftrace saw, but is not listed in the sysfs directory

The code looks to be built on top of the same basic ftrace commands that I sent the other day. You may be able to reuse/copy/etc bits from the scripts if they are handy.

--
Joe

#23 lore raw
Quoted 17 lines · Joe Lawrence

Hi Wardenjohn,

To follow up, Red Hat kpatch QE pointed me toward this test:

https://gitlab.com/redhat/centos-stream/tests/kernel/kernel-tests/-/tree/main/general/kpatch/kpatch-trace?ref_type=heads

which reports a few interesting things via systemd service and ftrace:

- Patched functions
- Traced functions
- Code that was modified, but didn't run
- Other code that ftrace saw, but is not listed in the sysfs directory

Quoted 7 lines

The code looks to be built on top of the same basic ftrace commands that I sent the other day. You may be able to reuse/copy/etc bits from the scripts if they are handy.

--
Joe

Thank you so much, you really helped me, Joe!

I will try to learn the script and make it suitable for our system.

Again, thank you, Joe!

Regards,
Wardenjohn

#24 lore raw
In reply to Wardenjohn

Please add a version identifier to the message subject.

…

Quoted 2 lines

If the patched function have bug, it may cause serious result such as kernel crash.

Wording suggestion:

If the patched function has a bug, it might cause serious side effects like a kernel crash.

Quoted 2 lines

This is a kobject attribute of klp_func. Sysfs interface named
"called" is introduced to livepatch …

Under which circumstances will imperative wordings be applied for another improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9#n94

…

Quoted 2 lines
---
 include/linux/livepatch.h |  2 ++

…

You may present version descriptions behind the marker line. Would you like to indicate any adjustments according to your change approach (from yesterday)?
https://lore.kernel.org/lkml/[email protected]/

Regards,
Markus

#25 lore raw

OK, I will try to optimize my description after the patch is reviewed. I am sure there are something still need to be fix for that patch.

Quoted 35 lines · Markus Elfring

Please add a version identifier to the message subject.

…

Quoted 2 lines

If the patched function have bug, it may cause serious result such as kernel crash.

Wording suggestion:

If the patched function has a bug, it might cause serious side effects like a kernel crash.

Quoted 2 lines

This is a kobject attribute of klp_func. Sysfs interface named "called" is introduced to livepatch …

Under which circumstances will imperative wordings be applied for another improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9#n94

…

Quoted 2 lines

---
include/linux/livepatch.h | 2 ++

…

You may present version descriptions behind the marker line. Would you like to indicate any adjustments according to your change approach (from yesterday)?
https://lore.kernel.org/lkml/[email protected]/

Regards,
Markus