On 11/01/21 17:57, Jason Baron wrote:
+#define DEFINE_KVM_OPS_STATIC_CALL(func) \
+ DEFINE_STATIC_CALL_NULL(kvm_x86_##func, \
+ *(((struct kvm_x86_ops *)0)->func))
+#define DEFINE_KVM_OPS_STATIC_CALLS() \
+ FOREACH_KVM_X86_OPS(DEFINE_KVM_OPS_STATIC_CALL)
Something wrong here?
+#define DECLARE_KVM_OPS_STATIC_CALL(func) \
+ DECLARE_STATIC_CALL(kvm_x86_##func, \
+ *(((struct kvm_x86_ops *)0)->func))
+#define DECLARE_KVM_OPS_STATIC_CALLS() \
+ FOREACH_KVM_X86_OPS(DECLARE_KVM_OPS_STATIC_CALL)
+
+#define KVM_OPS_STATIC_CALL_UPDATE(func) \
+ static_call_update(kvm_x86_##func, kvm_x86_ops.func)
+#define KVM_OPS_STATIC_CALL_UPDATES() \
+ FOREACH_KVM_X86_OPS(KVM_OPS_STATIC_CALL_UPDATE)
+
struct kvm_x86_ops {
int (*hardware_enable)(void);
void (*hardware_disable)(void);
@@ -1326,6 +1385,12 @@ extern u64 __read_mostly host_efer;
extern bool __read_mostly allow_smaller_maxphyaddr;
extern struct kvm_x86_ops kvm_x86_ops;
+DECLARE_KVM_OPS_STATIC_CALLS();
+static inline void kvm_ops_static_call_update(void)
+{
+ KVM_OPS_STATIC_CALL_UPDATES();
+}
This would become
#define KVM_X86_OP(func) \
DECLARE_STATIC_CALL(kvm_x86_##func, \
*(((struct kvm_x86_ops *)0)->func));
#include <asm/kvm-x86-ops.h>
static inline void kvm_ops_static_call_update(void)
{
#define KVM_X86_OP(func) \
static_call_update(kvm_x86_##func, kvm_x86_ops.func)
#include <asm/kvm-x86-ops.h>
}
If you need to choose between DECLARE_STATIC_CALL_NULL and
DECLARE_STATIC_CALL, you can have kvm-x86-ops.h use one of two macros
KVM_X86_OP_NULL and KVM_X86_OP.
#define KVM_X86_OP(func) \
DECLARE_STATIC_CALL(kvm_x86_##func, \
*(((struct kvm_x86_ops *)0)->func));
#define KVM_X86_OP_NULL(func) \
DECLARE_STATIC_CALL_NULL(kvm_x86_##func, \
*(((struct kvm_x86_ops *)0)->func));
#include <asm/kvm-x86-ops.h>
...
#define KVM_X86_OP(func) \
static_call_update(kvm_x86_##func, kvm_x86_ops.func)
#define KVM_X86_OP_NULL(func) \
static_call_update(kvm_x86_##func, kvm_x86_ops.func)
#include <asm/kvm-x86-ops.h>
In that case vmx.c and svm.c could define KVM_X86_OP_NULL to an empty
string and list the optional callbacks manually.
Paolo