1 // SPDX-License-Identifier: GPL-2.0-only
3 * Monitoring code for network dropped packet alerts
5 * Copyright (C) 2009 Neil Horman <nhorman@tuxdriver.com>
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/netdevice.h>
11 #include <linux/etherdevice.h>
12 #include <linux/string.h>
13 #include <linux/if_arp.h>
14 #include <linux/inetdevice.h>
15 #include <linux/inet.h>
16 #include <linux/interrupt.h>
17 #include <linux/netpoll.h>
18 #include <linux/sched.h>
19 #include <linux/delay.h>
20 #include <linux/types.h>
21 #include <linux/workqueue.h>
22 #include <linux/netlink.h>
23 #include <linux/net_dropmon.h>
24 #include <linux/percpu.h>
25 #include <linux/timer.h>
26 #include <linux/bitops.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <net/genetlink.h>
30 #include <net/netevent.h>
31 #include <net/flow_offload.h>
32 #include <net/devlink.h>
34 #include <trace/events/skb.h>
35 #include <trace/events/napi.h>
36 #include <trace/events/devlink.h>
38 #include <asm/unaligned.h>
44 * Globals, our netlink socket pointer
45 * and the work handle that will send up
48 static int trace_state = TRACE_OFF;
49 static bool monitor_hw;
53 * An overall lock guarding every operation coming from userspace.
54 * It also guards the global 'hw_stats_list' list.
56 static DEFINE_MUTEX(net_dm_mutex);
60 struct u64_stats_sync syncp;
63 #define NET_DM_MAX_HW_TRAP_NAME_LEN 40
65 struct net_dm_hw_entry {
66 char trap_name[NET_DM_MAX_HW_TRAP_NAME_LEN];
70 struct net_dm_hw_entries {
72 struct net_dm_hw_entry entries[];
75 struct per_cpu_dm_data {
76 spinlock_t lock; /* Protects 'skb', 'hw_entries' and
81 struct net_dm_hw_entries *hw_entries;
83 struct sk_buff_head drop_queue;
84 struct work_struct dm_alert_work;
85 struct timer_list send_timer;
86 struct net_dm_stats stats;
89 struct dm_hw_stat_delta {
90 struct net_device *dev;
91 unsigned long last_rx;
92 struct list_head list;
94 unsigned long last_drop_val;
97 static struct genl_family net_drop_monitor_family;
99 static DEFINE_PER_CPU(struct per_cpu_dm_data, dm_cpu_data);
100 static DEFINE_PER_CPU(struct per_cpu_dm_data, dm_hw_cpu_data);
102 static int dm_hit_limit = 64;
103 static int dm_delay = 1;
104 static unsigned long dm_hw_check_delta = 2*HZ;
105 static LIST_HEAD(hw_stats_list);
107 static enum net_dm_alert_mode net_dm_alert_mode = NET_DM_ALERT_MODE_SUMMARY;
108 static u32 net_dm_trunc_len;
109 static u32 net_dm_queue_len = 1000;
111 struct net_dm_alert_ops {
112 void (*kfree_skb_probe)(void *ignore, struct sk_buff *skb,
114 void (*napi_poll_probe)(void *ignore, struct napi_struct *napi,
115 int work, int budget);
116 void (*work_item_func)(struct work_struct *work);
117 void (*hw_work_item_func)(struct work_struct *work);
118 void (*hw_trap_probe)(void *ignore, const struct devlink *devlink,
120 const struct devlink_trap_metadata *metadata);
123 struct net_dm_skb_cb {
125 struct devlink_trap_metadata *hw_metadata;
130 #define NET_DM_SKB_CB(__skb) ((struct net_dm_skb_cb *)&((__skb)->cb[0]))
132 static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
135 struct net_dm_alert_msg *msg;
141 al = sizeof(struct net_dm_alert_msg);
142 al += dm_hit_limit * sizeof(struct net_dm_drop_point);
143 al += sizeof(struct nlattr);
145 skb = genlmsg_new(al, GFP_KERNEL);
150 msg_header = genlmsg_put(skb, 0, 0, &net_drop_monitor_family,
151 0, NET_DM_CMD_ALERT);
157 nla = nla_reserve(skb, NLA_UNSPEC,
158 sizeof(struct net_dm_alert_msg));
169 mod_timer(&data->send_timer, jiffies + HZ / 10);
171 spin_lock_irqsave(&data->lock, flags);
172 swap(data->skb, skb);
173 spin_unlock_irqrestore(&data->lock, flags);
176 struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data;
177 struct genlmsghdr *gnlh = (struct genlmsghdr *)nlmsg_data(nlh);
179 genlmsg_end(skb, genlmsg_data(gnlh));
185 static const struct genl_multicast_group dropmon_mcgrps[] = {
186 { .name = "events", .cap_sys_admin = 1 },
189 static void send_dm_alert(struct work_struct *work)
192 struct per_cpu_dm_data *data;
194 data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
196 skb = reset_per_cpu_data(data);
199 genlmsg_multicast(&net_drop_monitor_family, skb, 0,
204 * This is the timer function to delay the sending of an alert
205 * in the event that more drops will arrive during the
208 static void sched_send_work(struct timer_list *t)
210 struct per_cpu_dm_data *data = from_timer(data, t, send_timer);
212 schedule_work(&data->dm_alert_work);
215 static void trace_drop_common(struct sk_buff *skb, void *location)
217 struct net_dm_alert_msg *msg;
218 struct net_dm_drop_point *point;
219 struct nlmsghdr *nlh;
222 struct sk_buff *dskb;
223 struct per_cpu_dm_data *data;
226 local_irq_save(flags);
227 data = this_cpu_ptr(&dm_cpu_data);
228 spin_lock(&data->lock);
234 nlh = (struct nlmsghdr *)dskb->data;
235 nla = genlmsg_data(nlmsg_data(nlh));
238 for (i = 0; i < msg->entries; i++) {
239 if (!memcmp(&location, &point->pc, sizeof(void *))) {
245 if (msg->entries == dm_hit_limit)
248 * We need to create a new entry
250 __nla_reserve_nohdr(dskb, sizeof(struct net_dm_drop_point));
251 nla->nla_len += NLA_ALIGN(sizeof(struct net_dm_drop_point));
252 memcpy(point->pc, &location, sizeof(void *));
256 if (!timer_pending(&data->send_timer)) {
257 data->send_timer.expires = jiffies + dm_delay * HZ;
258 add_timer(&data->send_timer);
262 spin_unlock_irqrestore(&data->lock, flags);
265 static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb, void *location)
267 trace_drop_common(skb, location);
270 static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi,
271 int work, int budget)
273 struct dm_hw_stat_delta *new_stat;
276 * Don't check napi structures with no associated device
282 list_for_each_entry_rcu(new_stat, &hw_stats_list, list) {
283 struct net_device *dev;
286 * only add a note to our monitor buffer if:
287 * 1) this is the dev we received on
288 * 2) its after the last_rx delta
289 * 3) our rx_dropped count has gone up
291 /* Paired with WRITE_ONCE() in dropmon_net_event() */
292 dev = READ_ONCE(new_stat->dev);
293 if ((dev == napi->dev) &&
294 (time_after(jiffies, new_stat->last_rx + dm_hw_check_delta)) &&
295 (napi->dev->stats.rx_dropped != new_stat->last_drop_val)) {
296 trace_drop_common(NULL, NULL);
297 new_stat->last_drop_val = napi->dev->stats.rx_dropped;
298 new_stat->last_rx = jiffies;
305 static struct net_dm_hw_entries *
306 net_dm_hw_reset_per_cpu_data(struct per_cpu_dm_data *hw_data)
308 struct net_dm_hw_entries *hw_entries;
311 hw_entries = kzalloc(struct_size(hw_entries, entries, dm_hit_limit),
314 /* If the memory allocation failed, we try to perform another
315 * allocation in 1/10 second. Otherwise, the probe function
316 * will constantly bail out.
318 mod_timer(&hw_data->send_timer, jiffies + HZ / 10);
321 spin_lock_irqsave(&hw_data->lock, flags);
322 swap(hw_data->hw_entries, hw_entries);
323 spin_unlock_irqrestore(&hw_data->lock, flags);
328 static int net_dm_hw_entry_put(struct sk_buff *msg,
329 const struct net_dm_hw_entry *hw_entry)
333 attr = nla_nest_start(msg, NET_DM_ATTR_HW_ENTRY);
337 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_NAME, hw_entry->trap_name))
338 goto nla_put_failure;
340 if (nla_put_u32(msg, NET_DM_ATTR_HW_TRAP_COUNT, hw_entry->count))
341 goto nla_put_failure;
343 nla_nest_end(msg, attr);
348 nla_nest_cancel(msg, attr);
352 static int net_dm_hw_entries_put(struct sk_buff *msg,
353 const struct net_dm_hw_entries *hw_entries)
358 attr = nla_nest_start(msg, NET_DM_ATTR_HW_ENTRIES);
362 for (i = 0; i < hw_entries->num_entries; i++) {
365 rc = net_dm_hw_entry_put(msg, &hw_entries->entries[i]);
367 goto nla_put_failure;
370 nla_nest_end(msg, attr);
375 nla_nest_cancel(msg, attr);
380 net_dm_hw_summary_report_fill(struct sk_buff *msg,
381 const struct net_dm_hw_entries *hw_entries)
383 struct net_dm_alert_msg anc_hdr = { 0 };
387 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
392 /* We need to put the ancillary header in order not to break user
395 if (nla_put(msg, NLA_UNSPEC, sizeof(anc_hdr), &anc_hdr))
396 goto nla_put_failure;
398 rc = net_dm_hw_entries_put(msg, hw_entries);
400 goto nla_put_failure;
402 genlmsg_end(msg, hdr);
407 genlmsg_cancel(msg, hdr);
411 static void net_dm_hw_summary_work(struct work_struct *work)
413 struct net_dm_hw_entries *hw_entries;
414 struct per_cpu_dm_data *hw_data;
418 hw_data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
420 hw_entries = net_dm_hw_reset_per_cpu_data(hw_data);
424 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
428 rc = net_dm_hw_summary_report_fill(msg, hw_entries);
434 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
441 net_dm_hw_trap_summary_probe(void *ignore, const struct devlink *devlink,
443 const struct devlink_trap_metadata *metadata)
445 struct net_dm_hw_entries *hw_entries;
446 struct net_dm_hw_entry *hw_entry;
447 struct per_cpu_dm_data *hw_data;
451 if (metadata->trap_type == DEVLINK_TRAP_TYPE_CONTROL)
454 hw_data = this_cpu_ptr(&dm_hw_cpu_data);
455 spin_lock_irqsave(&hw_data->lock, flags);
456 hw_entries = hw_data->hw_entries;
461 for (i = 0; i < hw_entries->num_entries; i++) {
462 hw_entry = &hw_entries->entries[i];
463 if (!strncmp(hw_entry->trap_name, metadata->trap_name,
464 NET_DM_MAX_HW_TRAP_NAME_LEN - 1)) {
469 if (WARN_ON_ONCE(hw_entries->num_entries == dm_hit_limit))
472 hw_entry = &hw_entries->entries[hw_entries->num_entries];
473 strlcpy(hw_entry->trap_name, metadata->trap_name,
474 NET_DM_MAX_HW_TRAP_NAME_LEN - 1);
476 hw_entries->num_entries++;
478 if (!timer_pending(&hw_data->send_timer)) {
479 hw_data->send_timer.expires = jiffies + dm_delay * HZ;
480 add_timer(&hw_data->send_timer);
484 spin_unlock_irqrestore(&hw_data->lock, flags);
487 static const struct net_dm_alert_ops net_dm_alert_summary_ops = {
488 .kfree_skb_probe = trace_kfree_skb_hit,
489 .napi_poll_probe = trace_napi_poll_hit,
490 .work_item_func = send_dm_alert,
491 .hw_work_item_func = net_dm_hw_summary_work,
492 .hw_trap_probe = net_dm_hw_trap_summary_probe,
495 static void net_dm_packet_trace_kfree_skb_hit(void *ignore,
499 ktime_t tstamp = ktime_get_real();
500 struct per_cpu_dm_data *data;
501 struct sk_buff *nskb;
504 if (!skb_mac_header_was_set(skb))
507 nskb = skb_clone(skb, GFP_ATOMIC);
511 NET_DM_SKB_CB(nskb)->pc = location;
512 /* Override the timestamp because we care about the time when the
513 * packet was dropped.
515 nskb->tstamp = tstamp;
517 data = this_cpu_ptr(&dm_cpu_data);
519 spin_lock_irqsave(&data->drop_queue.lock, flags);
520 if (skb_queue_len(&data->drop_queue) < net_dm_queue_len)
521 __skb_queue_tail(&data->drop_queue, nskb);
524 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
526 schedule_work(&data->dm_alert_work);
531 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
532 u64_stats_update_begin(&data->stats.syncp);
533 data->stats.dropped++;
534 u64_stats_update_end(&data->stats.syncp);
538 static void net_dm_packet_trace_napi_poll_hit(void *ignore,
539 struct napi_struct *napi,
540 int work, int budget)
544 static size_t net_dm_in_port_size(void)
546 /* NET_DM_ATTR_IN_PORT nest */
547 return nla_total_size(0) +
548 /* NET_DM_ATTR_PORT_NETDEV_IFINDEX */
549 nla_total_size(sizeof(u32)) +
550 /* NET_DM_ATTR_PORT_NETDEV_NAME */
551 nla_total_size(IFNAMSIZ + 1);
554 #define NET_DM_MAX_SYMBOL_LEN 40
556 static size_t net_dm_packet_report_size(size_t payload_len)
560 size = nlmsg_msg_size(GENL_HDRLEN + net_drop_monitor_family.hdrsize);
562 return NLMSG_ALIGN(size) +
563 /* NET_DM_ATTR_ORIGIN */
564 nla_total_size(sizeof(u16)) +
566 nla_total_size(sizeof(u64)) +
567 /* NET_DM_ATTR_SYMBOL */
568 nla_total_size(NET_DM_MAX_SYMBOL_LEN + 1) +
569 /* NET_DM_ATTR_IN_PORT */
570 net_dm_in_port_size() +
571 /* NET_DM_ATTR_TIMESTAMP */
572 nla_total_size(sizeof(u64)) +
573 /* NET_DM_ATTR_ORIG_LEN */
574 nla_total_size(sizeof(u32)) +
575 /* NET_DM_ATTR_PROTO */
576 nla_total_size(sizeof(u16)) +
577 /* NET_DM_ATTR_PAYLOAD */
578 nla_total_size(payload_len);
581 static int net_dm_packet_report_in_port_put(struct sk_buff *msg, int ifindex,
586 attr = nla_nest_start(msg, NET_DM_ATTR_IN_PORT);
591 nla_put_u32(msg, NET_DM_ATTR_PORT_NETDEV_IFINDEX, ifindex))
592 goto nla_put_failure;
594 if (name && nla_put_string(msg, NET_DM_ATTR_PORT_NETDEV_NAME, name))
595 goto nla_put_failure;
597 nla_nest_end(msg, attr);
602 nla_nest_cancel(msg, attr);
606 static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb,
609 u64 pc = (u64)(uintptr_t) NET_DM_SKB_CB(skb)->pc;
610 char buf[NET_DM_MAX_SYMBOL_LEN];
615 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
616 NET_DM_CMD_PACKET_ALERT);
620 if (nla_put_u16(msg, NET_DM_ATTR_ORIGIN, NET_DM_ORIGIN_SW))
621 goto nla_put_failure;
623 if (nla_put_u64_64bit(msg, NET_DM_ATTR_PC, pc, NET_DM_ATTR_PAD))
624 goto nla_put_failure;
626 snprintf(buf, sizeof(buf), "%pS", NET_DM_SKB_CB(skb)->pc);
627 if (nla_put_string(msg, NET_DM_ATTR_SYMBOL, buf))
628 goto nla_put_failure;
630 rc = net_dm_packet_report_in_port_put(msg, skb->skb_iif, NULL);
632 goto nla_put_failure;
634 if (nla_put_u64_64bit(msg, NET_DM_ATTR_TIMESTAMP,
635 ktime_to_ns(skb->tstamp), NET_DM_ATTR_PAD))
636 goto nla_put_failure;
638 if (nla_put_u32(msg, NET_DM_ATTR_ORIG_LEN, skb->len))
639 goto nla_put_failure;
644 if (nla_put_u16(msg, NET_DM_ATTR_PROTO, be16_to_cpu(skb->protocol)))
645 goto nla_put_failure;
647 attr = skb_put(msg, nla_total_size(payload_len));
648 attr->nla_type = NET_DM_ATTR_PAYLOAD;
649 attr->nla_len = nla_attr_size(payload_len);
650 if (skb_copy_bits(skb, 0, nla_data(attr), payload_len))
651 goto nla_put_failure;
654 genlmsg_end(msg, hdr);
659 genlmsg_cancel(msg, hdr);
663 #define NET_DM_MAX_PACKET_SIZE (0xffff - NLA_HDRLEN - NLA_ALIGNTO)
665 static void net_dm_packet_report(struct sk_buff *skb)
671 /* Make sure we start copying the packet from the MAC header */
672 if (skb->data > skb_mac_header(skb))
673 skb_push(skb, skb->data - skb_mac_header(skb));
675 skb_pull(skb, skb_mac_header(skb) - skb->data);
677 /* Ensure packet fits inside a single netlink attribute */
678 payload_len = min_t(size_t, skb->len, NET_DM_MAX_PACKET_SIZE);
679 if (net_dm_trunc_len)
680 payload_len = min_t(size_t, net_dm_trunc_len, payload_len);
682 msg = nlmsg_new(net_dm_packet_report_size(payload_len), GFP_KERNEL);
686 rc = net_dm_packet_report_fill(msg, skb, payload_len);
692 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
698 static void net_dm_packet_work(struct work_struct *work)
700 struct per_cpu_dm_data *data;
701 struct sk_buff_head list;
705 data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
707 __skb_queue_head_init(&list);
709 spin_lock_irqsave(&data->drop_queue.lock, flags);
710 skb_queue_splice_tail_init(&data->drop_queue, &list);
711 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
713 while ((skb = __skb_dequeue(&list)))
714 net_dm_packet_report(skb);
718 net_dm_flow_action_cookie_size(const struct devlink_trap_metadata *hw_metadata)
720 return hw_metadata->fa_cookie ?
721 nla_total_size(hw_metadata->fa_cookie->cookie_len) : 0;
725 net_dm_hw_packet_report_size(size_t payload_len,
726 const struct devlink_trap_metadata *hw_metadata)
730 size = nlmsg_msg_size(GENL_HDRLEN + net_drop_monitor_family.hdrsize);
732 return NLMSG_ALIGN(size) +
733 /* NET_DM_ATTR_ORIGIN */
734 nla_total_size(sizeof(u16)) +
735 /* NET_DM_ATTR_HW_TRAP_GROUP_NAME */
736 nla_total_size(strlen(hw_metadata->trap_group_name) + 1) +
737 /* NET_DM_ATTR_HW_TRAP_NAME */
738 nla_total_size(strlen(hw_metadata->trap_name) + 1) +
739 /* NET_DM_ATTR_IN_PORT */
740 net_dm_in_port_size() +
741 /* NET_DM_ATTR_FLOW_ACTION_COOKIE */
742 net_dm_flow_action_cookie_size(hw_metadata) +
743 /* NET_DM_ATTR_TIMESTAMP */
744 nla_total_size(sizeof(u64)) +
745 /* NET_DM_ATTR_ORIG_LEN */
746 nla_total_size(sizeof(u32)) +
747 /* NET_DM_ATTR_PROTO */
748 nla_total_size(sizeof(u16)) +
749 /* NET_DM_ATTR_PAYLOAD */
750 nla_total_size(payload_len);
753 static int net_dm_hw_packet_report_fill(struct sk_buff *msg,
754 struct sk_buff *skb, size_t payload_len)
756 struct devlink_trap_metadata *hw_metadata;
760 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
762 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
763 NET_DM_CMD_PACKET_ALERT);
767 if (nla_put_u16(msg, NET_DM_ATTR_ORIGIN, NET_DM_ORIGIN_HW))
768 goto nla_put_failure;
770 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_GROUP_NAME,
771 hw_metadata->trap_group_name))
772 goto nla_put_failure;
774 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_NAME,
775 hw_metadata->trap_name))
776 goto nla_put_failure;
778 if (hw_metadata->input_dev) {
779 struct net_device *dev = hw_metadata->input_dev;
782 rc = net_dm_packet_report_in_port_put(msg, dev->ifindex,
785 goto nla_put_failure;
788 if (hw_metadata->fa_cookie &&
789 nla_put(msg, NET_DM_ATTR_FLOW_ACTION_COOKIE,
790 hw_metadata->fa_cookie->cookie_len,
791 hw_metadata->fa_cookie->cookie))
792 goto nla_put_failure;
794 if (nla_put_u64_64bit(msg, NET_DM_ATTR_TIMESTAMP,
795 ktime_to_ns(skb->tstamp), NET_DM_ATTR_PAD))
796 goto nla_put_failure;
798 if (nla_put_u32(msg, NET_DM_ATTR_ORIG_LEN, skb->len))
799 goto nla_put_failure;
804 if (nla_put_u16(msg, NET_DM_ATTR_PROTO, be16_to_cpu(skb->protocol)))
805 goto nla_put_failure;
807 attr = skb_put(msg, nla_total_size(payload_len));
808 attr->nla_type = NET_DM_ATTR_PAYLOAD;
809 attr->nla_len = nla_attr_size(payload_len);
810 if (skb_copy_bits(skb, 0, nla_data(attr), payload_len))
811 goto nla_put_failure;
814 genlmsg_end(msg, hdr);
819 genlmsg_cancel(msg, hdr);
823 static struct devlink_trap_metadata *
824 net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata)
826 const struct flow_action_cookie *fa_cookie;
827 struct devlink_trap_metadata *hw_metadata;
828 const char *trap_group_name;
829 const char *trap_name;
831 hw_metadata = kzalloc(sizeof(*hw_metadata), GFP_ATOMIC);
835 trap_group_name = kstrdup(metadata->trap_group_name, GFP_ATOMIC);
836 if (!trap_group_name)
837 goto free_hw_metadata;
838 hw_metadata->trap_group_name = trap_group_name;
840 trap_name = kstrdup(metadata->trap_name, GFP_ATOMIC);
842 goto free_trap_group;
843 hw_metadata->trap_name = trap_name;
845 if (metadata->fa_cookie) {
846 size_t cookie_size = sizeof(*fa_cookie) +
847 metadata->fa_cookie->cookie_len;
849 fa_cookie = kmemdup(metadata->fa_cookie, cookie_size,
853 hw_metadata->fa_cookie = fa_cookie;
856 hw_metadata->input_dev = metadata->input_dev;
857 if (hw_metadata->input_dev)
858 dev_hold(hw_metadata->input_dev);
865 kfree(trap_group_name);
872 net_dm_hw_metadata_free(const struct devlink_trap_metadata *hw_metadata)
874 if (hw_metadata->input_dev)
875 dev_put(hw_metadata->input_dev);
876 kfree(hw_metadata->fa_cookie);
877 kfree(hw_metadata->trap_name);
878 kfree(hw_metadata->trap_group_name);
882 static void net_dm_hw_packet_report(struct sk_buff *skb)
884 struct devlink_trap_metadata *hw_metadata;
889 if (skb->data > skb_mac_header(skb))
890 skb_push(skb, skb->data - skb_mac_header(skb));
892 skb_pull(skb, skb_mac_header(skb) - skb->data);
894 payload_len = min_t(size_t, skb->len, NET_DM_MAX_PACKET_SIZE);
895 if (net_dm_trunc_len)
896 payload_len = min_t(size_t, net_dm_trunc_len, payload_len);
898 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
899 msg = nlmsg_new(net_dm_hw_packet_report_size(payload_len, hw_metadata),
904 rc = net_dm_hw_packet_report_fill(msg, skb, payload_len);
910 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
913 net_dm_hw_metadata_free(NET_DM_SKB_CB(skb)->hw_metadata);
917 static void net_dm_hw_packet_work(struct work_struct *work)
919 struct per_cpu_dm_data *hw_data;
920 struct sk_buff_head list;
924 hw_data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
926 __skb_queue_head_init(&list);
928 spin_lock_irqsave(&hw_data->drop_queue.lock, flags);
929 skb_queue_splice_tail_init(&hw_data->drop_queue, &list);
930 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
932 while ((skb = __skb_dequeue(&list)))
933 net_dm_hw_packet_report(skb);
937 net_dm_hw_trap_packet_probe(void *ignore, const struct devlink *devlink,
939 const struct devlink_trap_metadata *metadata)
941 struct devlink_trap_metadata *n_hw_metadata;
942 ktime_t tstamp = ktime_get_real();
943 struct per_cpu_dm_data *hw_data;
944 struct sk_buff *nskb;
947 if (metadata->trap_type == DEVLINK_TRAP_TYPE_CONTROL)
950 if (!skb_mac_header_was_set(skb))
953 nskb = skb_clone(skb, GFP_ATOMIC);
957 n_hw_metadata = net_dm_hw_metadata_copy(metadata);
961 NET_DM_SKB_CB(nskb)->hw_metadata = n_hw_metadata;
962 nskb->tstamp = tstamp;
964 hw_data = this_cpu_ptr(&dm_hw_cpu_data);
966 spin_lock_irqsave(&hw_data->drop_queue.lock, flags);
967 if (skb_queue_len(&hw_data->drop_queue) < net_dm_queue_len)
968 __skb_queue_tail(&hw_data->drop_queue, nskb);
971 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
973 schedule_work(&hw_data->dm_alert_work);
978 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
979 u64_stats_update_begin(&hw_data->stats.syncp);
980 hw_data->stats.dropped++;
981 u64_stats_update_end(&hw_data->stats.syncp);
982 net_dm_hw_metadata_free(n_hw_metadata);
987 static const struct net_dm_alert_ops net_dm_alert_packet_ops = {
988 .kfree_skb_probe = net_dm_packet_trace_kfree_skb_hit,
989 .napi_poll_probe = net_dm_packet_trace_napi_poll_hit,
990 .work_item_func = net_dm_packet_work,
991 .hw_work_item_func = net_dm_hw_packet_work,
992 .hw_trap_probe = net_dm_hw_trap_packet_probe,
995 static const struct net_dm_alert_ops *net_dm_alert_ops_arr[] = {
996 [NET_DM_ALERT_MODE_SUMMARY] = &net_dm_alert_summary_ops,
997 [NET_DM_ALERT_MODE_PACKET] = &net_dm_alert_packet_ops,
1000 #if IS_ENABLED(CONFIG_NET_DEVLINK)
1001 static int net_dm_hw_probe_register(const struct net_dm_alert_ops *ops)
1003 return register_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
1006 static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
1008 unregister_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
1009 tracepoint_synchronize_unregister();
1012 static int net_dm_hw_probe_register(const struct net_dm_alert_ops *ops)
1017 static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
1022 static int net_dm_hw_monitor_start(struct netlink_ext_ack *extack)
1024 const struct net_dm_alert_ops *ops;
1028 NL_SET_ERR_MSG_MOD(extack, "Hardware monitoring already enabled");
1032 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1034 if (!try_module_get(THIS_MODULE)) {
1035 NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");
1039 for_each_possible_cpu(cpu) {
1040 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1041 struct net_dm_hw_entries *hw_entries;
1043 INIT_WORK(&hw_data->dm_alert_work, ops->hw_work_item_func);
1044 timer_setup(&hw_data->send_timer, sched_send_work, 0);
1045 hw_entries = net_dm_hw_reset_per_cpu_data(hw_data);
1049 rc = net_dm_hw_probe_register(ops);
1051 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to devlink_trap_probe() tracepoint");
1052 goto err_module_put;
1060 for_each_possible_cpu(cpu) {
1061 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1062 struct sk_buff *skb;
1064 del_timer_sync(&hw_data->send_timer);
1065 cancel_work_sync(&hw_data->dm_alert_work);
1066 while ((skb = __skb_dequeue(&hw_data->drop_queue))) {
1067 struct devlink_trap_metadata *hw_metadata;
1069 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
1070 net_dm_hw_metadata_free(hw_metadata);
1074 module_put(THIS_MODULE);
1078 static void net_dm_hw_monitor_stop(struct netlink_ext_ack *extack)
1080 const struct net_dm_alert_ops *ops;
1084 NL_SET_ERR_MSG_MOD(extack, "Hardware monitoring already disabled");
1088 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1092 net_dm_hw_probe_unregister(ops);
1094 for_each_possible_cpu(cpu) {
1095 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1096 struct sk_buff *skb;
1098 del_timer_sync(&hw_data->send_timer);
1099 cancel_work_sync(&hw_data->dm_alert_work);
1100 while ((skb = __skb_dequeue(&hw_data->drop_queue))) {
1101 struct devlink_trap_metadata *hw_metadata;
1103 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
1104 net_dm_hw_metadata_free(hw_metadata);
1109 module_put(THIS_MODULE);
1112 static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
1114 const struct net_dm_alert_ops *ops;
1117 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1119 if (!try_module_get(THIS_MODULE)) {
1120 NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");
1124 for_each_possible_cpu(cpu) {
1125 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1126 struct sk_buff *skb;
1128 INIT_WORK(&data->dm_alert_work, ops->work_item_func);
1129 timer_setup(&data->send_timer, sched_send_work, 0);
1130 /* Allocate a new per-CPU skb for the summary alert message and
1131 * free the old one which might contain stale data from
1134 skb = reset_per_cpu_data(data);
1138 rc = register_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1140 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to kfree_skb() tracepoint");
1141 goto err_module_put;
1144 rc = register_trace_napi_poll(ops->napi_poll_probe, NULL);
1146 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to napi_poll() tracepoint");
1147 goto err_unregister_trace;
1152 err_unregister_trace:
1153 unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1155 for_each_possible_cpu(cpu) {
1156 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1157 struct sk_buff *skb;
1159 del_timer_sync(&data->send_timer);
1160 cancel_work_sync(&data->dm_alert_work);
1161 while ((skb = __skb_dequeue(&data->drop_queue)))
1164 module_put(THIS_MODULE);
1168 static void net_dm_trace_off_set(void)
1170 struct dm_hw_stat_delta *new_stat, *temp;
1171 const struct net_dm_alert_ops *ops;
1174 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1176 unregister_trace_napi_poll(ops->napi_poll_probe, NULL);
1177 unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1179 tracepoint_synchronize_unregister();
1181 /* Make sure we do not send notifications to user space after request
1182 * to stop tracing returns.
1184 for_each_possible_cpu(cpu) {
1185 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1186 struct sk_buff *skb;
1188 del_timer_sync(&data->send_timer);
1189 cancel_work_sync(&data->dm_alert_work);
1190 while ((skb = __skb_dequeue(&data->drop_queue)))
1194 list_for_each_entry_safe(new_stat, temp, &hw_stats_list, list) {
1195 if (new_stat->dev == NULL) {
1196 list_del_rcu(&new_stat->list);
1197 kfree_rcu(new_stat, rcu);
1201 module_put(THIS_MODULE);
1204 static int set_all_monitor_traces(int state, struct netlink_ext_ack *extack)
1208 if (state == trace_state) {
1209 NL_SET_ERR_MSG_MOD(extack, "Trace state already set to requested state");
1215 rc = net_dm_trace_on_set(extack);
1218 net_dm_trace_off_set();
1226 trace_state = state;
1233 static bool net_dm_is_monitoring(void)
1235 return trace_state == TRACE_ON || monitor_hw;
1238 static int net_dm_alert_mode_get_from_info(struct genl_info *info,
1239 enum net_dm_alert_mode *p_alert_mode)
1243 val = nla_get_u8(info->attrs[NET_DM_ATTR_ALERT_MODE]);
1246 case NET_DM_ALERT_MODE_SUMMARY:
1247 case NET_DM_ALERT_MODE_PACKET:
1248 *p_alert_mode = val;
1257 static int net_dm_alert_mode_set(struct genl_info *info)
1259 struct netlink_ext_ack *extack = info->extack;
1260 enum net_dm_alert_mode alert_mode;
1263 if (!info->attrs[NET_DM_ATTR_ALERT_MODE])
1266 rc = net_dm_alert_mode_get_from_info(info, &alert_mode);
1268 NL_SET_ERR_MSG_MOD(extack, "Invalid alert mode");
1272 net_dm_alert_mode = alert_mode;
1277 static void net_dm_trunc_len_set(struct genl_info *info)
1279 if (!info->attrs[NET_DM_ATTR_TRUNC_LEN])
1282 net_dm_trunc_len = nla_get_u32(info->attrs[NET_DM_ATTR_TRUNC_LEN]);
1285 static void net_dm_queue_len_set(struct genl_info *info)
1287 if (!info->attrs[NET_DM_ATTR_QUEUE_LEN])
1290 net_dm_queue_len = nla_get_u32(info->attrs[NET_DM_ATTR_QUEUE_LEN]);
1293 static int net_dm_cmd_config(struct sk_buff *skb,
1294 struct genl_info *info)
1296 struct netlink_ext_ack *extack = info->extack;
1299 if (net_dm_is_monitoring()) {
1300 NL_SET_ERR_MSG_MOD(extack, "Cannot configure drop monitor during monitoring");
1304 rc = net_dm_alert_mode_set(info);
1308 net_dm_trunc_len_set(info);
1310 net_dm_queue_len_set(info);
1315 static int net_dm_monitor_start(bool set_sw, bool set_hw,
1316 struct netlink_ext_ack *extack)
1318 bool sw_set = false;
1322 rc = set_all_monitor_traces(TRACE_ON, extack);
1329 rc = net_dm_hw_monitor_start(extack);
1331 goto err_monitor_hw;
1338 set_all_monitor_traces(TRACE_OFF, extack);
1342 static void net_dm_monitor_stop(bool set_sw, bool set_hw,
1343 struct netlink_ext_ack *extack)
1346 net_dm_hw_monitor_stop(extack);
1348 set_all_monitor_traces(TRACE_OFF, extack);
1351 static int net_dm_cmd_trace(struct sk_buff *skb,
1352 struct genl_info *info)
1354 bool set_sw = !!info->attrs[NET_DM_ATTR_SW_DROPS];
1355 bool set_hw = !!info->attrs[NET_DM_ATTR_HW_DROPS];
1356 struct netlink_ext_ack *extack = info->extack;
1358 /* To maintain backward compatibility, we start / stop monitoring of
1359 * software drops if no flag is specified.
1361 if (!set_sw && !set_hw)
1364 switch (info->genlhdr->cmd) {
1365 case NET_DM_CMD_START:
1366 return net_dm_monitor_start(set_sw, set_hw, extack);
1367 case NET_DM_CMD_STOP:
1368 net_dm_monitor_stop(set_sw, set_hw, extack);
1375 static int net_dm_config_fill(struct sk_buff *msg, struct genl_info *info)
1379 hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
1380 &net_drop_monitor_family, 0, NET_DM_CMD_CONFIG_NEW);
1384 if (nla_put_u8(msg, NET_DM_ATTR_ALERT_MODE, net_dm_alert_mode))
1385 goto nla_put_failure;
1387 if (nla_put_u32(msg, NET_DM_ATTR_TRUNC_LEN, net_dm_trunc_len))
1388 goto nla_put_failure;
1390 if (nla_put_u32(msg, NET_DM_ATTR_QUEUE_LEN, net_dm_queue_len))
1391 goto nla_put_failure;
1393 genlmsg_end(msg, hdr);
1398 genlmsg_cancel(msg, hdr);
1402 static int net_dm_cmd_config_get(struct sk_buff *skb, struct genl_info *info)
1404 struct sk_buff *msg;
1407 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1411 rc = net_dm_config_fill(msg, info);
1415 return genlmsg_reply(msg, info);
1422 static void net_dm_stats_read(struct net_dm_stats *stats)
1426 memset(stats, 0, sizeof(*stats));
1427 for_each_possible_cpu(cpu) {
1428 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1429 struct net_dm_stats *cpu_stats = &data->stats;
1434 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
1435 dropped = cpu_stats->dropped;
1436 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
1438 stats->dropped += dropped;
1442 static int net_dm_stats_put(struct sk_buff *msg)
1444 struct net_dm_stats stats;
1445 struct nlattr *attr;
1447 net_dm_stats_read(&stats);
1449 attr = nla_nest_start(msg, NET_DM_ATTR_STATS);
1453 if (nla_put_u64_64bit(msg, NET_DM_ATTR_STATS_DROPPED,
1454 stats.dropped, NET_DM_ATTR_PAD))
1455 goto nla_put_failure;
1457 nla_nest_end(msg, attr);
1462 nla_nest_cancel(msg, attr);
1466 static void net_dm_hw_stats_read(struct net_dm_stats *stats)
1470 memset(stats, 0, sizeof(*stats));
1471 for_each_possible_cpu(cpu) {
1472 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1473 struct net_dm_stats *cpu_stats = &hw_data->stats;
1478 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
1479 dropped = cpu_stats->dropped;
1480 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
1482 stats->dropped += dropped;
1486 static int net_dm_hw_stats_put(struct sk_buff *msg)
1488 struct net_dm_stats stats;
1489 struct nlattr *attr;
1491 net_dm_hw_stats_read(&stats);
1493 attr = nla_nest_start(msg, NET_DM_ATTR_HW_STATS);
1497 if (nla_put_u64_64bit(msg, NET_DM_ATTR_STATS_DROPPED,
1498 stats.dropped, NET_DM_ATTR_PAD))
1499 goto nla_put_failure;
1501 nla_nest_end(msg, attr);
1506 nla_nest_cancel(msg, attr);
1510 static int net_dm_stats_fill(struct sk_buff *msg, struct genl_info *info)
1515 hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
1516 &net_drop_monitor_family, 0, NET_DM_CMD_STATS_NEW);
1520 rc = net_dm_stats_put(msg);
1522 goto nla_put_failure;
1524 rc = net_dm_hw_stats_put(msg);
1526 goto nla_put_failure;
1528 genlmsg_end(msg, hdr);
1533 genlmsg_cancel(msg, hdr);
1537 static int net_dm_cmd_stats_get(struct sk_buff *skb, struct genl_info *info)
1539 struct sk_buff *msg;
1542 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1546 rc = net_dm_stats_fill(msg, info);
1550 return genlmsg_reply(msg, info);
1557 static int dropmon_net_event(struct notifier_block *ev_block,
1558 unsigned long event, void *ptr)
1560 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1561 struct dm_hw_stat_delta *new_stat = NULL;
1562 struct dm_hw_stat_delta *tmp;
1565 case NETDEV_REGISTER:
1566 new_stat = kzalloc(sizeof(struct dm_hw_stat_delta), GFP_KERNEL);
1571 new_stat->dev = dev;
1572 new_stat->last_rx = jiffies;
1573 mutex_lock(&net_dm_mutex);
1574 list_add_rcu(&new_stat->list, &hw_stats_list);
1575 mutex_unlock(&net_dm_mutex);
1577 case NETDEV_UNREGISTER:
1578 mutex_lock(&net_dm_mutex);
1579 list_for_each_entry_safe(new_stat, tmp, &hw_stats_list, list) {
1580 if (new_stat->dev == dev) {
1582 /* Paired with READ_ONCE() in trace_napi_poll_hit() */
1583 WRITE_ONCE(new_stat->dev, NULL);
1585 if (trace_state == TRACE_OFF) {
1586 list_del_rcu(&new_stat->list);
1587 kfree_rcu(new_stat, rcu);
1592 mutex_unlock(&net_dm_mutex);
1599 static const struct nla_policy net_dm_nl_policy[NET_DM_ATTR_MAX + 1] = {
1600 [NET_DM_ATTR_UNSPEC] = { .strict_start_type = NET_DM_ATTR_UNSPEC + 1 },
1601 [NET_DM_ATTR_ALERT_MODE] = { .type = NLA_U8 },
1602 [NET_DM_ATTR_TRUNC_LEN] = { .type = NLA_U32 },
1603 [NET_DM_ATTR_QUEUE_LEN] = { .type = NLA_U32 },
1604 [NET_DM_ATTR_SW_DROPS] = {. type = NLA_FLAG },
1605 [NET_DM_ATTR_HW_DROPS] = {. type = NLA_FLAG },
1608 static const struct genl_small_ops dropmon_ops[] = {
1610 .cmd = NET_DM_CMD_CONFIG,
1611 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1612 .doit = net_dm_cmd_config,
1613 .flags = GENL_ADMIN_PERM,
1616 .cmd = NET_DM_CMD_START,
1617 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1618 .doit = net_dm_cmd_trace,
1619 .flags = GENL_ADMIN_PERM,
1622 .cmd = NET_DM_CMD_STOP,
1623 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1624 .doit = net_dm_cmd_trace,
1625 .flags = GENL_ADMIN_PERM,
1628 .cmd = NET_DM_CMD_CONFIG_GET,
1629 .doit = net_dm_cmd_config_get,
1632 .cmd = NET_DM_CMD_STATS_GET,
1633 .doit = net_dm_cmd_stats_get,
1637 static int net_dm_nl_pre_doit(const struct genl_ops *ops,
1638 struct sk_buff *skb, struct genl_info *info)
1640 mutex_lock(&net_dm_mutex);
1645 static void net_dm_nl_post_doit(const struct genl_ops *ops,
1646 struct sk_buff *skb, struct genl_info *info)
1648 mutex_unlock(&net_dm_mutex);
1651 static struct genl_family net_drop_monitor_family __ro_after_init = {
1655 .maxattr = NET_DM_ATTR_MAX,
1656 .policy = net_dm_nl_policy,
1657 .pre_doit = net_dm_nl_pre_doit,
1658 .post_doit = net_dm_nl_post_doit,
1659 .module = THIS_MODULE,
1660 .small_ops = dropmon_ops,
1661 .n_small_ops = ARRAY_SIZE(dropmon_ops),
1662 .mcgrps = dropmon_mcgrps,
1663 .n_mcgrps = ARRAY_SIZE(dropmon_mcgrps),
1666 static struct notifier_block dropmon_net_notifier = {
1667 .notifier_call = dropmon_net_event
1670 static void __net_dm_cpu_data_init(struct per_cpu_dm_data *data)
1672 spin_lock_init(&data->lock);
1673 skb_queue_head_init(&data->drop_queue);
1674 u64_stats_init(&data->stats.syncp);
1677 static void __net_dm_cpu_data_fini(struct per_cpu_dm_data *data)
1679 WARN_ON(!skb_queue_empty(&data->drop_queue));
1682 static void net_dm_cpu_data_init(int cpu)
1684 struct per_cpu_dm_data *data;
1686 data = &per_cpu(dm_cpu_data, cpu);
1687 __net_dm_cpu_data_init(data);
1690 static void net_dm_cpu_data_fini(int cpu)
1692 struct per_cpu_dm_data *data;
1694 data = &per_cpu(dm_cpu_data, cpu);
1695 /* At this point, we should have exclusive access
1696 * to this struct and can free the skb inside it.
1698 consume_skb(data->skb);
1699 __net_dm_cpu_data_fini(data);
1702 static void net_dm_hw_cpu_data_init(int cpu)
1704 struct per_cpu_dm_data *hw_data;
1706 hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1707 __net_dm_cpu_data_init(hw_data);
1710 static void net_dm_hw_cpu_data_fini(int cpu)
1712 struct per_cpu_dm_data *hw_data;
1714 hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1715 kfree(hw_data->hw_entries);
1716 __net_dm_cpu_data_fini(hw_data);
1719 static int __init init_net_drop_monitor(void)
1723 pr_info("Initializing network drop monitor service\n");
1725 if (sizeof(void *) > 8) {
1726 pr_err("Unable to store program counters on this arch, Drop monitor failed\n");
1730 rc = genl_register_family(&net_drop_monitor_family);
1732 pr_err("Could not create drop monitor netlink family\n");
1735 WARN_ON(net_drop_monitor_family.mcgrp_offset != NET_DM_GRP_ALERT);
1737 rc = register_netdevice_notifier(&dropmon_net_notifier);
1739 pr_crit("Failed to register netdevice notifier\n");
1745 for_each_possible_cpu(cpu) {
1746 net_dm_cpu_data_init(cpu);
1747 net_dm_hw_cpu_data_init(cpu);
1753 genl_unregister_family(&net_drop_monitor_family);
1758 static void exit_net_drop_monitor(void)
1762 BUG_ON(unregister_netdevice_notifier(&dropmon_net_notifier));
1765 * Because of the module_get/put we do in the trace state change path
1766 * we are guarnateed not to have any current users when we get here
1769 for_each_possible_cpu(cpu) {
1770 net_dm_hw_cpu_data_fini(cpu);
1771 net_dm_cpu_data_fini(cpu);
1774 BUG_ON(genl_unregister_family(&net_drop_monitor_family));
1777 module_init(init_net_drop_monitor);
1778 module_exit(exit_net_drop_monitor);
1780 MODULE_LICENSE("GPL v2");
1781 MODULE_AUTHOR("Neil Horman <nhorman@tuxdriver.com>");
1782 MODULE_ALIAS_GENL_FAMILY("NET_DM");
1783 MODULE_DESCRIPTION("Monitoring code for network dropped packet alerts");