[PATCH 3/3] static_call: Fix static_call_update() sanity check

From: Peter Zijlstra
Date: Thu Mar 18 2021 - 07:39:22 EST


Sites that match init_section_contains() get marked as INIT. For
built-in code init_sections contains both __init and __exit text. OTOH
kernel_text_address() only explicitly includes __init text (and there
are no __exit text markers).

Match what jump_label already does and ignore the warning for INIT
sites. Also see the excellent changelog for commit: 8f35eaa5f2de
("jump_label: Don't warn on __exit jump entries")

Fixes: 9183c3f9ed710 ("static_call: Add inline static call infrastructure")
Reported-by: Sumit Garg <sumit.garg@xxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
kernel/jump_label.c | 8 ++++++++
kernel/static_call.c | 11 ++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)

--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -407,6 +407,14 @@ static bool jump_label_can_update(struct
return false;

if (!kernel_text_address(jump_entry_code(entry))) {
+ /*
+ * This skips patching __exit, which is part of
+ * init_section_contains() but is not part of
+ * kernel_text_address().
+ *
+ * Skipping __exit is fine since it will never
+ * be executed.
+ */
WARN_ONCE(!jump_entry_is_init(entry),
"can't patch jump_label at %pS",
(void *)jump_entry_code(entry));
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -181,7 +181,16 @@ void __static_call_update(struct static_
continue;

if (!kernel_text_address((unsigned long)site_addr)) {
- WARN_ONCE(1, "can't patch static call site at %pS",
+ /*
+ * This skips patching __exit, which is part of
+ * init_section_contains() but is not part of
+ * kernel_text_address().
+ *
+ * Skipping __exit is fine since it will never
+ * be executed.
+ */
+ WARN_ONCE(!static_call_is_init(site),
+ "can't patch static call site at %pS",
site_addr);
continue;
}