Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

static_call: Add function to query current function

Some users of paravirtualized functions need to query which function
has been specified in a pv_ops vector element. In order to be able to
switch such paravirtualized functions to static_calls instead, there
needs to be a function to query the function which will be called via
static_call().

Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210311142319.4723-4-jgross@suse.com

authored by

Juergen Gross and committed by
Borislav Petkov
6ea312d9 b0466648

+8
+8
include/linux/static_call.h
··· 20 20 * static_call(name)(args...); 21 21 * static_call_cond(name)(args...); 22 22 * static_call_update(name, func); 23 + * static_call_query(name); 23 24 * 24 25 * Usage example: 25 26 * ··· 92 91 * 93 92 * which will include the required value tests to avoid NULL-pointer 94 93 * dereferences. 94 + * 95 + * To query which function is currently set to be called, use: 96 + * 97 + * func = static_call_query(name); 95 98 */ 96 99 97 100 #include <linux/types.h> ··· 122 117 __static_call_update(&STATIC_CALL_KEY(name), \ 123 118 STATIC_CALL_TRAMP_ADDR(name), func); \ 124 119 }) 120 + 121 + #define static_call_query(name) (READ_ONCE(STATIC_CALL_KEY(name).func)) 125 122 126 123 #ifdef CONFIG_HAVE_STATIC_CALL_INLINE 127 124 ··· 197 190 .func = NULL, \ 198 191 }; \ 199 192 ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) 193 + 200 194 201 195 #define static_call_cond(name) (void)__static_call(name) 202 196