From: Wei Yongjun weiyongjun1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8VOZQ CVE: NA
---------------------------
Allow vendor modules to attach bonding driver hooks. This patch introduce vendor_bond_check_dev_link hook.
Usage:
static void vendor_foo(void *data, const struct bonding *bond, const struct slave *slave, int *state) { pr_info("%s\n", __func__); }
static int __init vendor_bond_init(void) { return register_trace_vendor_bond_check_dev_link(&vendor_foo, NULL); }
static void __exit vendor_bond_exit(void) { unregister_trace_vendor_bond_check_dev_link(&vendor_foo, NULL); }
module_init(vendor_bond_init); module_exit(vendor_bond_exit);
Signed-off-by: Wei Yongjun weiyongjun1@huawei.com Signed-off-by: Zhengchao Shao shaozhengchao@huawei.com --- arch/arm64/configs/openeuler_defconfig | 1 + arch/x86/configs/openeuler_defconfig | 1 + drivers/hooks/Kconfig | 10 +++++++++ drivers/hooks/vendor_hooks.c | 4 ++++ drivers/net/bonding/bond_main.c | 5 +++++ include/trace/hooks/bonding.h | 29 ++++++++++++++++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 include/trace/hooks/bonding.h
diff --git a/arch/arm64/configs/openeuler_defconfig b/arch/arm64/configs/openeuler_defconfig index 703fe5bc2535..268550234d30 100644 --- a/arch/arm64/configs/openeuler_defconfig +++ b/arch/arm64/configs/openeuler_defconfig @@ -6736,6 +6736,7 @@ CONFIG_USB4=m # Vendor Hooks # CONFIG_VENDOR_HOOKS=y +CONFIG_VENDOR_BOND_HOOKS=y # end of Vendor Hooks
CONFIG_LIBNVDIMM=m diff --git a/arch/x86/configs/openeuler_defconfig b/arch/x86/configs/openeuler_defconfig index c9e816e54003..43574cee0160 100644 --- a/arch/x86/configs/openeuler_defconfig +++ b/arch/x86/configs/openeuler_defconfig @@ -7939,6 +7939,7 @@ CONFIG_USB4=m # Vendor Hooks # CONFIG_VENDOR_HOOKS=y +CONFIG_VENDOR_BOND_HOOKS=y # end of Vendor Hooks
CONFIG_LIBNVDIMM=m diff --git a/drivers/hooks/Kconfig b/drivers/hooks/Kconfig index 1c0e33ef9a56..6a00168e67ad 100644 --- a/drivers/hooks/Kconfig +++ b/drivers/hooks/Kconfig @@ -10,4 +10,14 @@ config VENDOR_HOOKS Allow vendor modules to attach to tracepoint "hooks" defined via DECLARE_HOOK or DECLARE_RESTRICTED_HOOK.
+config VENDOR_BOND_HOOKS + bool "Ethernet Bonding driver Vendor Hooks" + depends on VENDOR_HOOKS && BONDING + default n + help + Enable ethernet bonding driver vendor hooks + + Allow vendor modules to attach bonding driver hooks defined via + DECLARE_HOOK or DECLARE_RESTRICTED_HOOK. + endmenu diff --git a/drivers/hooks/vendor_hooks.c b/drivers/hooks/vendor_hooks.c index 359989d1bb32..85bda58159f6 100644 --- a/drivers/hooks/vendor_hooks.c +++ b/drivers/hooks/vendor_hooks.c @@ -8,9 +8,13 @@
#define CREATE_TRACE_POINTS #include <trace/hooks/vendor_hooks.h> +#include <trace/hooks/bonding.h>
/* * Export tracepoints that act as a bare tracehook (ie: have no trace event * associated with them) to allow external modules to probe them. */
+#ifdef CONFIG_VENDOR_BOND_HOOKS +EXPORT_TRACEPOINT_SYMBOL_GPL(vendor_bond_check_dev_link); +#endif diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 80ebf3fbc88e..0fd7263b1dd7 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -91,6 +91,7 @@ #endif #include <net/ip6_route.h> #include <net/xdp.h> +#include <trace/hooks/bonding.h>
#include "bonding_priv.h"
@@ -2601,6 +2602,10 @@ static int bond_miimon_inspect(struct bonding *bond)
link_state = bond_check_dev_link(bond, slave->dev, 0);
+#ifdef CONFIG_VENDOR_BOND_HOOKS + trace_vendor_bond_check_dev_link(bond, slave, &link_state); +#endif + switch (slave->link) { case BOND_LINK_UP: if (link_state) diff --git a/include/trace/hooks/bonding.h b/include/trace/hooks/bonding.h new file mode 100644 index 000000000000..fc77d6da3a19 --- /dev/null +++ b/include/trace/hooks/bonding.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Ethernet Bonding driver Vendor Hooks + * + * Copyright (c) 2022, Huawei Tech. Co., Ltd. + */ + +#ifdef CONFIG_VENDOR_BOND_HOOKS + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM bonding + +#define TRACE_INCLUDE_PATH trace/hooks +#if !defined(_TRACE_HOOK_BONDING_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_BONDING_H +#include <linux/tracepoint.h> +#include <trace/hooks/vendor_hooks.h> + +struct bonding; +struct slave; +DECLARE_HOOK(vendor_bond_check_dev_link, + TP_PROTO(const struct bonding *bond, const struct slave *slave, int *state), + TP_ARGS(bond, slave, state)); + +#endif +/* This part must be outside protection */ +#include <trace/define_trace.h> + +#endif