[PATCH] altcall: fix __alt_call_maybe_initdata so it's safe for livepatch

Roger Pau Monne posted 1 patch 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20240411155314.73811-1-roger.pau@citrix.com
There is a newer version of this series
xen/include/xen/alternative-call.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] altcall: fix __alt_call_maybe_initdata so it's safe for livepatch
Posted by Roger Pau Monne 3 weeks ago
Setting alternative call variables as __init is not safe for use with
livepatch, as livepatches can rightfully introduce new alternative calls to
structures marked as __alt_call_maybe_initdata (possibly just indirectly due to
replacing existing functions that use those).  Attempting to resolve those
alternative calls then results in page faults as the variable that holds the
function pointer address has been freed.

When livepatch is supported use the __ro_after_init attribute instead of
__initdata for __alt_call_maybe_initdata.

Fixes: f26bb285949b ('xen: Implement xen/alternative-call.h for use in common code')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/include/xen/alternative-call.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/xen/include/xen/alternative-call.h b/xen/include/xen/alternative-call.h
index 5c6b9a562b92..1896063e5da5 100644
--- a/xen/include/xen/alternative-call.h
+++ b/xen/include/xen/alternative-call.h
@@ -50,7 +50,12 @@
 
 #include <asm/alternative.h>
 
-#define __alt_call_maybe_initdata __initdata
+#ifndef CONFIG_LIVEPATCH
+# define __alt_call_maybe_initdata __initdata
+#else
+/* Must keep for livepatches to resolve alternative calls against them. */
+# define __alt_call_maybe_initdata __ro_after_init
+#endif
 
 #else
 
-- 
2.44.0