Skip to content

Commit 8ee2267

Browse files
idoschdavem330
authored andcommitted
drop_monitor: Convert to using devlink tracepoint
Convert drop monitor to use the recently introduced 'devlink_trap_report' tracepoint instead of having devlink call into drop monitor. This is both consistent with software originated drops ('kfree_skb' tracepoint) and also allows drop monitor to be built as a module and still report hardware originated drops. Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5855357 commit 8ee2267

File tree

5 files changed

+40
-78
lines changed

5 files changed

+40
-78
lines changed

MAINTAINERS

-1
Original file line numberDiff line numberDiff line change
@@ -12065,7 +12065,6 @@ M: Neil Horman <[email protected]>
1206512065
1206612066
S: Maintained
1206712067
W: https://fedorahosted.org/dropwatch/
12068-
F: include/net/drop_monitor.h
1206912068
F: include/uapi/linux/net_dropmon.h
1207012069
F: net/core/drop_monitor.c
1207112070

include/net/drop_monitor.h

-36
This file was deleted.

net/Kconfig

-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ config NET_SOCK_MSG
434434
config NET_DEVLINK
435435
bool
436436
default n
437-
imply NET_DROP_MONITOR
438437

439438
config PAGE_POOL
440439
bool

net/core/devlink.c

-24
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <net/net_namespace.h>
2828
#include <net/sock.h>
2929
#include <net/devlink.h>
30-
#include <net/drop_monitor.h>
3130
#define CREATE_TRACE_POINTS
3231
#include <trace/events/devlink.h>
3332

@@ -9261,24 +9260,6 @@ devlink_trap_stats_update(struct devlink_stats __percpu *trap_stats,
92619260
u64_stats_update_end(&stats->syncp);
92629261
}
92639262

9264-
static void
9265-
devlink_trap_report_metadata_fill(struct net_dm_hw_metadata *hw_metadata,
9266-
const struct devlink_trap_item *trap_item,
9267-
struct devlink_port *in_devlink_port,
9268-
const struct flow_action_cookie *fa_cookie)
9269-
{
9270-
struct devlink_trap_group_item *group_item = trap_item->group_item;
9271-
9272-
hw_metadata->trap_group_name = group_item->group->name;
9273-
hw_metadata->trap_name = trap_item->trap->name;
9274-
hw_metadata->fa_cookie = fa_cookie;
9275-
9276-
spin_lock(&in_devlink_port->type_lock);
9277-
if (in_devlink_port->type == DEVLINK_PORT_TYPE_ETH)
9278-
hw_metadata->input_dev = in_devlink_port->type_dev;
9279-
spin_unlock(&in_devlink_port->type_lock);
9280-
}
9281-
92829263
static void
92839264
devlink_trap_report_metadata_set(struct devlink_trap_metadata *metadata,
92849265
const struct devlink_trap_item *trap_item,
@@ -9309,7 +9290,6 @@ void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
93099290

93109291
{
93119292
struct devlink_trap_item *trap_item = trap_ctx;
9312-
struct net_dm_hw_metadata hw_metadata = {};
93139293

93149294
devlink_trap_stats_update(trap_item->stats, skb->len);
93159295
devlink_trap_stats_update(trap_item->group_item->stats, skb->len);
@@ -9321,10 +9301,6 @@ void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
93219301
if (trap_item->trap->type == DEVLINK_TRAP_TYPE_CONTROL)
93229302
return;
93239303

9324-
devlink_trap_report_metadata_fill(&hw_metadata, trap_item,
9325-
in_devlink_port, fa_cookie);
9326-
net_dm_hw_report(skb, &hw_metadata);
9327-
93289304
if (trace_devlink_trap_report_enabled()) {
93299305
struct devlink_trap_metadata metadata = {};
93309306

net/core/drop_monitor.c

+40-16
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
#include <linux/bitops.h>
2727
#include <linux/slab.h>
2828
#include <linux/module.h>
29-
#include <net/drop_monitor.h>
3029
#include <net/genetlink.h>
3130
#include <net/netevent.h>
3231
#include <net/flow_offload.h>
3332
#include <net/devlink.h>
3433

3534
#include <trace/events/skb.h>
3635
#include <trace/events/napi.h>
36+
#include <trace/events/devlink.h>
3737

3838
#include <asm/unaligned.h>
3939

@@ -108,6 +108,13 @@ static enum net_dm_alert_mode net_dm_alert_mode = NET_DM_ALERT_MODE_SUMMARY;
108108
static u32 net_dm_trunc_len;
109109
static u32 net_dm_queue_len = 1000;
110110

111+
struct net_dm_hw_metadata {
112+
const char *trap_group_name;
113+
const char *trap_name;
114+
struct net_device *input_dev;
115+
const struct flow_action_cookie *fa_cookie;
116+
};
117+
111118
struct net_dm_alert_ops {
112119
void (*kfree_skb_probe)(void *ignore, struct sk_buff *skb,
113120
void *location);
@@ -1129,25 +1136,32 @@ static const struct net_dm_alert_ops *net_dm_alert_ops_arr[] = {
11291136
[NET_DM_ALERT_MODE_PACKET] = &net_dm_alert_packet_ops,
11301137
};
11311138

1132-
void net_dm_hw_report(struct sk_buff *skb,
1133-
const struct net_dm_hw_metadata *hw_metadata)
1139+
#if IS_ENABLED(CONFIG_NET_DEVLINK)
1140+
static int net_dm_hw_probe_register(const struct net_dm_alert_ops *ops)
11341141
{
1135-
rcu_read_lock();
1136-
1137-
if (!monitor_hw)
1138-
goto out;
1142+
return register_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
1143+
}
11391144

1140-
net_dm_alert_ops_arr[net_dm_alert_mode]->hw_probe(skb, hw_metadata);
1145+
static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
1146+
{
1147+
unregister_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
1148+
tracepoint_synchronize_unregister();
1149+
}
1150+
#else
1151+
static int net_dm_hw_probe_register(const struct net_dm_alert_ops *ops)
1152+
{
1153+
return -EOPNOTSUPP;
1154+
}
11411155

1142-
out:
1143-
rcu_read_unlock();
1156+
static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
1157+
{
11441158
}
1145-
EXPORT_SYMBOL_GPL(net_dm_hw_report);
1159+
#endif
11461160

11471161
static int net_dm_hw_monitor_start(struct netlink_ext_ack *extack)
11481162
{
11491163
const struct net_dm_alert_ops *ops;
1150-
int cpu;
1164+
int cpu, rc;
11511165

11521166
if (monitor_hw) {
11531167
NL_SET_ERR_MSG_MOD(extack, "Hardware monitoring already enabled");
@@ -1171,26 +1185,36 @@ static int net_dm_hw_monitor_start(struct netlink_ext_ack *extack)
11711185
kfree(hw_entries);
11721186
}
11731187

1188+
rc = net_dm_hw_probe_register(ops);
1189+
if (rc) {
1190+
NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to devlink_trap_probe() tracepoint");
1191+
goto err_module_put;
1192+
}
1193+
11741194
monitor_hw = true;
11751195

11761196
return 0;
1197+
1198+
err_module_put:
1199+
module_put(THIS_MODULE);
1200+
return rc;
11771201
}
11781202

11791203
static void net_dm_hw_monitor_stop(struct netlink_ext_ack *extack)
11801204
{
1205+
const struct net_dm_alert_ops *ops;
11811206
int cpu;
11821207

11831208
if (!monitor_hw) {
11841209
NL_SET_ERR_MSG_MOD(extack, "Hardware monitoring already disabled");
11851210
return;
11861211
}
11871212

1213+
ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1214+
11881215
monitor_hw = false;
11891216

1190-
/* After this call returns we are guaranteed that no CPU is processing
1191-
* any hardware drops.
1192-
*/
1193-
synchronize_rcu();
1217+
net_dm_hw_probe_unregister(ops);
11941218

11951219
for_each_possible_cpu(cpu) {
11961220
struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);

0 commit comments

Comments
 (0)