* [PATCH] livepatch: Move the result-invariant calculation out of the loop
@ 2022-09-30 1:54 Zhen Lei
2022-09-30 7:37 ` Petr Mladek
0 siblings, 1 reply; 3+ messages in thread
From: Zhen Lei @ 2022-09-30 1:54 UTC (permalink / raw)
To: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
Joe Lawrence, live-patching, linux-kernel
Cc: Zhen Lei
The calculation results of the variables 'func_addr' and 'func_size' are
not affected by the for loop and do not change due to the changes of
entries[i]. The performance can be improved by moving it outside the loop.
No functional change.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
kernel/livepatch/transition.c | 54 +++++++++++++++++------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
index 5d03a2ad1066195..da93aa77715a306 100644
--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -196,36 +196,36 @@ static int klp_check_stack_func(struct klp_func *func, unsigned long *entries,
struct klp_ops *ops;
int i;
- for (i = 0; i < nr_entries; i++) {
- address = entries[i];
+ if (klp_target_state == KLP_UNPATCHED) {
+ /*
+ * Check for the to-be-unpatched function
+ * (the func itself).
+ */
+ func_addr = (unsigned long)func->new_func;
+ func_size = func->new_size;
+ } else {
+ /*
+ * Check for the to-be-patched function
+ * (the previous func).
+ */
+ ops = klp_find_ops(func->old_func);
- if (klp_target_state == KLP_UNPATCHED) {
- /*
- * Check for the to-be-unpatched function
- * (the func itself).
- */
- func_addr = (unsigned long)func->new_func;
- func_size = func->new_size;
+ if (list_is_singular(&ops->func_stack)) {
+ /* original function */
+ func_addr = (unsigned long)func->old_func;
+ func_size = func->old_size;
} else {
- /*
- * Check for the to-be-patched function
- * (the previous func).
- */
- ops = klp_find_ops(func->old_func);
-
- if (list_is_singular(&ops->func_stack)) {
- /* original function */
- func_addr = (unsigned long)func->old_func;
- func_size = func->old_size;
- } else {
- /* previously patched function */
- struct klp_func *prev;
-
- prev = list_next_entry(func, stack_node);
- func_addr = (unsigned long)prev->new_func;
- func_size = prev->new_size;
- }
+ /* previously patched function */
+ struct klp_func *prev;
+
+ prev = list_next_entry(func, stack_node);
+ func_addr = (unsigned long)prev->new_func;
+ func_size = prev->new_size;
}
+ }
+
+ for (i = 0; i < nr_entries; i++) {
+ address = entries[i];
if (address >= func_addr && address < func_addr + func_size)
return -EAGAIN;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] livepatch: Move the result-invariant calculation out of the loop
2022-09-30 1:54 [PATCH] livepatch: Move the result-invariant calculation out of the loop Zhen Lei
@ 2022-09-30 7:37 ` Petr Mladek
2022-10-18 13:51 ` Jiri Kosina
0 siblings, 1 reply; 3+ messages in thread
From: Petr Mladek @ 2022-09-30 7:37 UTC (permalink / raw)
To: Zhen Lei
Cc: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Joe Lawrence,
live-patching, linux-kernel
On Fri 2022-09-30 09:54:46, Zhen Lei wrote:
> The calculation results of the variables 'func_addr' and 'func_size' are
> not affected by the for loop and do not change due to the changes of
> entries[i]. The performance can be improved by moving it outside the loop.
>
> No functional change.
>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Makes sense:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] livepatch: Move the result-invariant calculation out of the loop
2022-09-30 7:37 ` Petr Mladek
@ 2022-10-18 13:51 ` Jiri Kosina
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2022-10-18 13:51 UTC (permalink / raw)
To: Petr Mladek
Cc: Zhen Lei, Josh Poimboeuf, Miroslav Benes, Joe Lawrence,
live-patching, linux-kernel
On Fri, 30 Sep 2022, Petr Mladek wrote:
> > The calculation results of the variables 'func_addr' and 'func_size' are
> > not affected by the for loop and do not change due to the changes of
> > entries[i]. The performance can be improved by moving it outside the loop.
> >
> > No functional change.
> >
> > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>
> Makes sense:
>
> Reviewed-by: Petr Mladek <pmladek@suse.com>
Seems like this wasn't picked up by anybody, so I have now pushed it to
livepatching.git#for-6.2/core
Thanks,
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-18 13:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30 1:54 [PATCH] livepatch: Move the result-invariant calculation out of the loop Zhen Lei
2022-09-30 7:37 ` Petr Mladek
2022-10-18 13:51 ` Jiri Kosina
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.