[RFC PATCH 7/7] static_call: add generic support for non-exported keys

From: Ard Biesheuvel
Date: Tue Nov 09 2021 - 11:46:38 EST


The static_call feature where only the static call target is exposed to
modules while access to the key is withheld is only implemented for the
inline and out-of-line varieties, but not for the generic indirect call
based variety.

Let's use static_call_query() to obtain the call target address if the
key is not exported. Note that this means we can do the converse as
well, i.e., implement static_call_query() in terms of the key struct if
the key is exported, so we only need to export one of the two.

Note that this adds an additional load and potentially a direct call to
the instantiations of static_call residing in module code.

Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
---
include/linux/static_call.h | 4 ++--
include/linux/static_call_types.h | 3 +--
tools/include/linux/static_call_types.h | 3 +--
3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/include/linux/static_call.h b/include/linux/static_call.h
index 21929147879a..d88fd613f06d 100644
--- a/include/linux/static_call.h
+++ b/include/linux/static_call.h
@@ -302,8 +302,8 @@ static inline int static_call_text_reserved(void *start, void *end)
return 0;
}

-#define EXPORT_STATIC_CALL(name) EXPORT_SYMBOL(STATIC_CALL_KEY(name))
-#define EXPORT_STATIC_CALL_GPL(name) EXPORT_SYMBOL_GPL(STATIC_CALL_KEY(name))
+#define EXPORT_STATIC_CALL(name) EXPORT_STATIC_CALL_QUERY(name,)
+#define EXPORT_STATIC_CALL_GPL(name) EXPORT_STATIC_CALL_QUERY(name, _GPL)

#define EXPORT_STATIC_CALL_FOR_UPDATE(name) EXPORT_SYMBOL(STATIC_CALL_KEY(name))
#define EXPORT_STATIC_CALL_FOR_UPDATE_GPL(name) EXPORT_SYMBOL_GPL(STATIC_CALL_KEY(name))
diff --git a/include/linux/static_call_types.h b/include/linux/static_call_types.h
index eae11c5b015d..920828ad1d69 100644
--- a/include/linux/static_call_types.h
+++ b/include/linux/static_call_types.h
@@ -106,8 +106,7 @@ struct static_call_key {
void *func;
};

-#define static_call(name) \
- ((typeof(STATIC_CALL_QUERY(name)()))(STATIC_CALL_KEY(name).func))
+#define static_call(name) static_call_query(name)

#endif /* CONFIG_HAVE_STATIC_CALL */

diff --git a/tools/include/linux/static_call_types.h b/tools/include/linux/static_call_types.h
index eae11c5b015d..920828ad1d69 100644
--- a/tools/include/linux/static_call_types.h
+++ b/tools/include/linux/static_call_types.h
@@ -106,8 +106,7 @@ struct static_call_key {
void *func;
};

-#define static_call(name) \
- ((typeof(STATIC_CALL_QUERY(name)()))(STATIC_CALL_KEY(name).func))
+#define static_call(name) static_call_query(name)

#endif /* CONFIG_HAVE_STATIC_CALL */

--
2.30.2