History

Merge branch 'netconsole-stop-charging-netpoll-users-for-netconsole-only-data'

Breno Leitao says: ==================== netconsole: stop charging netpoll users for netconsole-only data This work continue to untangle netconsole and netpoll, improving memory usage for netpoll users that are not netconsole. struct netpoll is shared by every netpoll consumer in the tree: bonding, bridge, team, vlan, macvlan, dsa and netconsole. The non- netconsole users only need a per-port handle that lets them transmit SKBs. Yet struct netpoll has accumulated a pile of fields that exist only to serve netconsole's printk path: - skb_pool / refill_wq: the fallback skb pool find_skb() falls back on when alloc_skb() returns NULL, plus the workqueue that refills it. - local_port / remote_port / remote_mac: the source and destination UDP ports and the destination ethernet address used to build outgoing log packets. Every netpoll user that allocates a struct netpoll pays for all of these fields, even though it never queues a single skb on the pool, never sends a UDP frame and never looks at any of the addressing. Move this netconsole-only state out of the shared struct into struct netconsole_target, where its only consumer already lives. After the series every passive netpoll consumer drops sizeof(sk_buff_head) + sizeof(work_struct) + 2 * sizeof(u16) + ETH_ALEN bytes per port (plus padding), and struct netpoll keeps only what belongs to the generic poll/transmit abstraction or what netpoll core still reads itself. Follow-ups ---------- local_ip, remote_ip and ipv6 are still in struct netpoll. Moving the addressing additionally requires relocating netpoll_setup() -- whose only caller is netconsole -- and its IPv4/IPv6 helpers, so it is left for a follow-up to keep this series focused on a single responsibility transfer. This is pure code motion with no functional change. The pre-existing target/device teardown races reported against v1 have since been fixed independently (as suggested by Jakub) and are already in the tree, so, re-posting this one. ====================

Paolo Abeni committed 4 months ago

Commit 5c655df2 parents f6f3b36 49e03ca3 files · +152 −116Browse files

Unified · Split

3 files
  1. drivers/net/netconsole.c +151 −48
  2. include/linux/netpoll.h +0 −18
  3. net/core/netpoll.c +1 −50
drivers/net/netconsole.c+151−48
@@ -61,6 +61,19 @@ MODULE_IMPORT_NS("NETDEV_INTERNAL"); · 60 unmodified lines
6161 #define MAX_USERDATA_ITEMS 256
6262 #define MAX_PRINT_CHUNK 1000
6363
64+/*
65+ * Sizing for the per-target fallback skb pool consulted by find_skb()
66+ * when its GFP_ATOMIC allocation fails so messages still get out under
67+ * memory pressure.
68+ */
69+#define MAX_UDP_CHUNK 1460
70+#define MAX_SKBS 32
71+#define MAX_SKB_SIZE \
72+ (sizeof(struct ethhdr) + \
73+ sizeof(struct iphdr) + \
74+ sizeof(struct udphdr) + \
75+ MAX_UDP_CHUNK)
76+
6477 static char config[MAX_PARAM_LENGTH];
6578 module_param_string(netconsole, config, MAX_PARAM_LENGTH, 0);
6679 MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]");
@@ -162,14 +175,19 @@ enum target_state { · 95 unmodified lines
162175 * @np: The netpoll structure for this target.
163176 * Contains the other userspace visible parameters:
164177 * dev_name (read-write)
165− * local_port (read-write)
166− * remote_port (read-write)
167178 * local_ip (read-write)
168179 * remote_ip (read-write)
169180 * local_mac (read-only)
170− * remote_mac (read-write)
181+ * @local_port: Source UDP port of the target (read-write).
182+ * @remote_port: Destination UDP port of the target (read-write).
183+ * @remote_mac: Destination ethernet address of the target (read-write).
171184 * @buf: The buffer used to send the full msg to the network stack
172185 * @resume_wq: Workqueue to resume deactivated target
186+ * @skb_pool: Per-target fallback skb pool consulted by find_skb() when
187+ * its GFP_ATOMIC allocation fails. Lifetime brackets a
188+ * successful netpoll_setup() / netpoll_cleanup() pair on @np.
189+ * @refill_wq: Work item that asynchronously tops @skb_pool back up to
190+ * MAX_SKBS after find_skb() drains an entry.
173191 */
174192 struct netconsole_target {
175193 struct list_head list;
@@ -190,11 +208,15 @@ struct netconsole_target { · 14 unmodified lines
190208 bool extended;
191209 bool release;
192210 struct netpoll np;
211+ u16 local_port, remote_port;
212+ u8 remote_mac[ETH_ALEN];
193213 /* protected by target_list_lock; +1 gives scnprintf() room for its
194214 * NUL terminator so a full MAX_PRINT_CHUNK payload is not truncated
195215 */
196216 char buf[MAX_PRINT_CHUNK + 1];
197217 struct work_struct resume_wq;
218+ struct sk_buff_head skb_pool;
219+ struct work_struct refill_wq;
198220 };
199221
200222 #ifdef CONFIG_NETCONSOLE_DYNAMIC
@@ -292,11 +314,56 @@ static void netcons_release_dev(struct netconsole_target *nt) · 91 unmodified lines
292314 memset(&nt->np.dev_name, 0, IFNAMSIZ);
293315 }
294316
317+static void refill_skbs(struct netconsole_target *nt)
318+{
319+ struct sk_buff_head *skb_pool = &nt->skb_pool;
320+ struct sk_buff *skb;
321+
322+ while (READ_ONCE(skb_pool->qlen) < MAX_SKBS) {
323+ skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC | __GFP_NOWARN);
324+ if (!skb)
325+ break;
326+
327+ skb_queue_tail(skb_pool, skb);
328+ }
329+}
330+
331+static void refill_skbs_work_handler(struct work_struct *work)
332+{
333+ struct netconsole_target *nt =
334+ container_of(work, struct netconsole_target, refill_wq);
335+
336+ refill_skbs(nt);
337+}
338+
339+/* Seed the per-target skb pool that find_skb() falls back to. The queue
340+ * head and refill work are set up once in alloc_and_init(); this only
341+ * (re)fills the pool. Pair with netconsole_skb_pool_flush().
342+ */
343+static void netconsole_skb_pool_init(struct netconsole_target *nt)
344+{
345+ refill_skbs(nt);
346+}
347+
348+static void netconsole_skb_pool_flush(struct netconsole_target *nt)
349+{
350+ cancel_work_sync(&nt->refill_wq);
351+ skb_queue_purge_reason(&nt->skb_pool, SKB_CONSUMED);
352+}
353+
295354 /* Attempts to resume logging to a deactivated target. */
296355 static void resume_target(struct netconsole_target *nt)
297356 {
357+ /* Initialise the skb pool before netpoll_setup() makes nt->np.dev
358+ * visible to target_list walkers (e.g. netconsole_netdev_event),
359+ * which otherwise may move the target to the cleanup list and
360+ * call netconsole_skb_pool_flush() on uninitialised state.
361+ */
362+ netconsole_skb_pool_init(nt);
363+
298364 if (netpoll_setup(&nt->np)) {
299365 /* netpoll fails setup once, do not try again. */
366+ netconsole_skb_pool_flush(nt);
300367 nt->state = STATE_DISABLED;
301368 return;
302369 }
@@ -358,6 +425,7 @@ static void process_resume_target(struct work_struct *work) · 55 unmodified lines
358425 rtnl_lock();
359426 if (nt->state == STATE_ENABLED && nt->np.dev &&
360427 nt->np.dev->reg_state != NETREG_REGISTERED) {
428+ netconsole_skb_pool_flush(nt);
361429 netcons_release_dev(nt);
362430 nt->state = STATE_DISABLED;
363431 }
@@ -393,11 +461,14 @@ static struct netconsole_target *alloc_and_init(void) · 29 unmodified lines
393461
394462 nt->np.name = "netconsole";
395463 strscpy(nt->np.dev_name, "eth0", IFNAMSIZ);
396− nt->np.local_port = 6665;
397− nt->np.remote_port = 6666;
398− eth_broadcast_addr(nt->np.remote_mac);
464+ nt->local_port = 6665;
465+ nt->remote_port = 6666;
466+ eth_broadcast_addr(nt->remote_mac);
399467 nt->state = STATE_DISABLED;
400468 INIT_WORK(&nt->resume_wq, process_resume_target);
469+ /* Set up the skb pool primitives once; enabling only refills it. */
470+ skb_queue_head_init(&nt->skb_pool);
471+ INIT_WORK(&nt->refill_wq, refill_skbs_work_handler);
401472
402473 return nt;
403474 }
@@ -417,6 +488,7 @@ static void netconsole_process_cleanups_core(void) · 13 unmodified lines
417488 list_for_each_entry_safe(nt, tmp, &target_cleanup_list, list) {
418489 /* all entries in the cleanup_list needs to be disabled */
419490 WARN_ON_ONCE(nt->state == STATE_ENABLED);
491+ netconsole_skb_pool_flush(nt);
420492 netcons_release_dev(nt);
421493 /* moved the cleaned target to target_list. Need to hold both
422494 * locks
@@ -429,21 +501,23 @@ static void netconsole_process_cleanups_core(void) · 6 unmodified lines
429501 mutex_unlock(&target_cleanup_list_lock);
430502 }
431503
432−static void netconsole_print_banner(struct netpoll *np)
504+static void netconsole_print_banner(struct netconsole_target *nt)
433505 {
434− np_info(np, "local port %d\n", np->local_port);
506+ struct netpoll *np = &nt->np;
507+
508+ np_info(np, "local port %d\n", nt->local_port);
435509 if (np->ipv6)
436510 np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.in6);
437511 else
438512 np_info(np, "local IPv4 address %pI4\n", &np->local_ip.ip);
439513 np_info(np, "interface name '%s'\n", np->dev_name);
440514 np_info(np, "local ethernet address '%pM'\n", np->dev_mac);
441− np_info(np, "remote port %d\n", np->remote_port);
515+ np_info(np, "remote port %d\n", nt->remote_port);
442516 if (np->ipv6)
443517 np_info(np, "remote IPv6 address %pI6c\n", &np->remote_ip.in6);
444518 else
445519 np_info(np, "remote IPv4 address %pI4\n", &np->remote_ip.ip);
446− np_info(np, "remote ethernet address %pM\n", np->remote_mac);
520+ np_info(np, "remote ethernet address %pM\n", nt->remote_mac);
447521 }
448522
449523 /* Parse the string and populate the `inet_addr` union. Return 0 if IPv4 is
@@ -561,12 +635,12 @@ static ssize_t dev_name_show(struct config_item *item, char *buf) · 111 unmodified lines
561635
562636 static ssize_t local_port_show(struct config_item *item, char *buf)
563637 {
564− return sysfs_emit(buf, "%d\n", to_target(item)->np.local_port);
638+ return sysfs_emit(buf, "%d\n", to_target(item)->local_port);
565639 }
566640
567641 static ssize_t remote_port_show(struct config_item *item, char *buf)
568642 {
569− return sysfs_emit(buf, "%d\n", to_target(item)->np.remote_port);
643+ return sysfs_emit(buf, "%d\n", to_target(item)->remote_port);
570644 }
571645
572646 static ssize_t local_ip_show(struct config_item *item, char *buf)
@@ -599,7 +673,7 @@ static ssize_t local_mac_show(struct config_item *item, char *buf) · 26 unmodified lines
599673
600674 static ssize_t remote_mac_show(struct config_item *item, char *buf)
601675 {
602− return sysfs_emit(buf, "%pM\n", to_target(item)->np.remote_mac);
676+ return sysfs_emit(buf, "%pM\n", to_target(item)->remote_mac);
603677 }
604678
605679 static ssize_t transmit_errors_show(struct config_item *item, char *buf)
@@ -756,11 +830,21 @@ static ssize_t enabled_store(struct config_item *item, · 150 unmodified lines
756830 * Skip netconsole_parser_cmdline() -- all the attributes are
757831 * already configured via configfs. Just print them out.
758832 */
759− netconsole_print_banner(&nt->np);
833+ netconsole_print_banner(nt);
834+
835+ /* Initialise the skb pool before netpoll_setup() so the pool
836+ * is valid as soon as nt->np.dev becomes visible to
837+ * target_list walkers (netconsole_netdev_event), which would
838+ * otherwise call netconsole_skb_pool_flush() on uninitialised
839+ * state.
840+ */
841+ netconsole_skb_pool_init(nt);
760842
761843 ret = netpoll_setup(&nt->np);
762− if (ret)
844+ if (ret) {
845+ netconsole_skb_pool_flush(nt);
763846 goto out_unlock;
847+ }
764848
765849 nt->state = STATE_ENABLED;
766850 pr_info("network logging started\n");
@@ -885,7 +969,7 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, · 118 unmodified lines
885969 goto out_unlock;
886970 }
887971
888− ret = kstrtou16(buf, 10, &nt->np.local_port);
972+ ret = kstrtou16(buf, 10, &nt->local_port);
889973 if (ret < 0)
890974 goto out_unlock;
891975 ret = count;
@@ -907,7 +991,7 @@ static ssize_t remote_port_store(struct config_item *item, · 15 unmodified lines
907991 goto out_unlock;
908992 }
909993
910− ret = kstrtou16(buf, 10, &nt->np.remote_port);
994+ ret = kstrtou16(buf, 10, &nt->remote_port);
911995 if (ret < 0)
912996 goto out_unlock;
913997 ret = count;
@@ -994,7 +1078,7 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf, · 80 unmodified lines
9941078 goto out_unlock;
9951079 if (buf[MAC_ADDR_STR_LEN] && buf[MAC_ADDR_STR_LEN] != '\n')
9961080 goto out_unlock;
997− memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN);
1081+ memcpy(nt->remote_mac, remote_mac, ETH_ALEN);
9981082
9991083 ret = count;
10001084 out_unlock:
@@ -1481,15 +1565,15 @@ static void drop_netconsole_target(struct config_group *group, · 480 unmodified lines
14811565
14821566 mutex_lock(&target_cleanup_list_lock);
14831567 spin_lock_irqsave(&target_list_lock, flags);
1484− /* A STATE_DEACTIVATED target may have been moved to
1485− * target_cleanup_list by netconsole_netdev_event() but not yet
1486− * processed by netconsole_process_cleanups_core(). Unlinking it below
1487− * hides it from the cleanup worker, so this path has to clean it up
1488− * itself. Record that the target still owns a netpoll before the
1489− * state is downgraded.
1568+ /* A target moved to target_cleanup_list by netconsole_netdev_event()
1569+ * but not yet processed still owns a netpoll; unlinking it below hides
1570+ * it from the cleanup worker, so this path must tear it down itself.
1571+ * This covers NETDEV_UNREGISTER (STATE_DEACTIVATED) and
1572+ * NETDEV_RELEASE / NETDEV_JOIN (STATE_DISABLED); key off nt->np.dev,
1573+ * which stays set until the netpoll is cleaned up.
14901574 */
14911575 needs_cleanup = nt->state == STATE_ENABLED ||
1492− nt->state == STATE_DEACTIVATED;
1576+ nt->state == STATE_DEACTIVATED || nt->np.dev;
14931577 /* Disable deactivated target to prevent races between resume attempt
14941578 * and target removal.
14951579 */
@@ -1514,8 +1598,10 @@ static void drop_netconsole_target(struct config_group *group, · 18 unmodified lines
15141598 * netpoll_cleanup() is idempotent (it skips when np->dev is NULL), so
15151599 * it is safe even if the cleanup worker already tore the netpoll down.
15161600 */
1517− if (needs_cleanup)
1601+ if (needs_cleanup) {
1602+ netconsole_skb_pool_flush(nt);
15181603 netpoll_cleanup(&nt->np);
1604+ }
15191605
15201606 config_item_put(&nt->group.cg_item);
15211607 }
@@ -1706,7 +1792,7 @@ static struct notifier_block netconsole_netdev_notifier = { · 184 unmodified lines
17061792 * pool locks and is therefore not NMI-safe. Skip the refill when called
17071793 * from NMI context; the next non-NMI caller will top the pool back up.
17081794 */
1709−static struct sk_buff *netcons_skb_pop(struct netpoll *np, int len)
1795+static struct sk_buff *netcons_skb_pop(struct netconsole_target *nt, int len)
17101796 {
17111797 struct sk_buff *skb;
17121798
@@ -1718,19 +1804,21 @@ static struct sk_buff *netcons_skb_pop(struct netpoll *np, int len) · 5 unmodified lines
17181804 if (!in_nmi())
17191805 net_warn_ratelimited("netconsole: dropping message, requested skb len %d exceeds pool buffer size %zu on %s\n",
17201806 len, (size_t)MAX_SKB_SIZE,
1721− np->dev->name);
1807+ nt->np.dev->name);
17221808 return NULL;
17231809 }
17241810
1725− skb = skb_dequeue(&np->skb_pool);
1811+ skb = skb_dequeue(&nt->skb_pool);
17261812 if (!in_nmi())
1727− schedule_work(&np->refill_wq);
1813+ schedule_work(&nt->refill_wq);
17281814
17291815 return skb;
17301816 }
17311817
1732−static struct sk_buff *find_skb(struct netpoll *np, int len, int reserve)
1818+static struct sk_buff *find_skb(struct netconsole_target *nt, int len,
1819+ int reserve)
17331820 {
1821+ struct netpoll *np = &nt->np;
17341822 int count = 0;
17351823 struct sk_buff *skb;
17361824
@@ -1739,7 +1827,7 @@ repeat: · 2 unmodified lines
17391827
17401828 skb = alloc_skb(len, GFP_ATOMIC | __GFP_NOWARN);
17411829 if (!skb)
1742− skb = netcons_skb_pop(np, len);
1830+ skb = netcons_skb_pop(nt, len);
17431831
17441832 if (!skb) {
17451833 if (++count < 10) {
@@ -1779,8 +1867,9 @@ static void netpoll_udp_checksum(struct netpoll *np, struct sk_buff *skb, · 33 unmodified lines
17791867 udph->check = CSUM_MANGLED_0;
17801868 }
17811869
1782−static void push_udp(struct netpoll *np, struct sk_buff *skb, int len)
1870+static void push_udp(struct netconsole_target *nt, struct sk_buff *skb, int len)
17831871 {
1872+ struct netpoll *np = &nt->np;
17841873 struct udphdr *udph;
17851874 int udp_len;
17861875
@@ -1790,21 +1879,22 @@ static void push_udp(struct netpoll *np, struct sk_buff *skb, int len) · 3 unmodified lines
17901879 skb_reset_transport_header(skb);
17911880
17921881 udph = udp_hdr(skb);
1793− udph->source = htons(np->local_port);
1794− udph->dest = htons(np->remote_port);
1882+ udph->source = htons(nt->local_port);
1883+ udph->dest = htons(nt->remote_port);
17951884 udph->len = htons(udp_len);
17961885
17971886 netpoll_udp_checksum(np, skb, len);
17981887 }
17991888
1800−static void push_eth(struct netpoll *np, struct sk_buff *skb)
1889+static void push_eth(struct netconsole_target *nt, struct sk_buff *skb)
18011890 {
1891+ struct netpoll *np = &nt->np;
18021892 struct ethhdr *eth;
18031893
18041894 eth = skb_push(skb, ETH_HLEN);
18051895 skb_reset_mac_header(skb);
18061896 ether_addr_copy(eth->h_source, np->dev->dev_addr);
1807− ether_addr_copy(eth->h_dest, np->remote_mac);
1897+ ether_addr_copy(eth->h_dest, nt->remote_mac);
18081898 if (np->ipv6)
18091899 eth->h_proto = htons(ETH_P_IPV6);
18101900 else
@@ -1861,8 +1951,10 @@ static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len) · 50 unmodified lines
18611951 skb->protocol = htons(ETH_P_IPV6);
18621952 }
18631953
1864−static int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
1954+static int netpoll_send_udp(struct netconsole_target *nt, const char *msg,
1955+ int len)
18651956 {
1957+ struct netpoll *np = &nt->np;
18661958 int total_len, ip_len, udp_len;
18671959 struct sk_buff *skb;
18681960
@@ -1877,7 +1969,7 @@ static int netpoll_send_udp(struct netpoll *np, const char *msg, int len) · 8 unmodified lines
18771969
18781970 total_len = ip_len + LL_RESERVED_SPACE(np->dev);
18791971
1880− skb = find_skb(np, total_len + np->dev->needed_tailroom,
1972+ skb = find_skb(nt, total_len + np->dev->needed_tailroom,
18811973 total_len - len);
18821974 if (!skb)
18831975 return -ENOMEM;
@@ -1885,12 +1977,12 @@ static int netpoll_send_udp(struct netpoll *np, const char *msg, int len) · 1 unmodified line
18851977 skb_copy_to_linear_data(skb, msg, len);
18861978 skb_put(skb, len);
18871979
1888− push_udp(np, skb, len);
1980+ push_udp(nt, skb, len);
18891981 if (np->ipv6)
18901982 push_ipv6(np, skb, len);
18911983 else
18921984 push_ipv4(np, skb, len);
1893− push_eth(np, skb);
1985+ push_eth(nt, skb);
18941986 skb->dev = np->dev;
18951987
18961988 return (int)netpoll_send_skb(np, skb);
@@ -1908,7 +2000,7 @@ static int netpoll_send_udp(struct netpoll *np, const char *msg, int len) · 11 unmodified lines
19082000 */
19092001 static void send_udp(struct netconsole_target *nt, const char *msg, int len)
19102002 {
1911− int result = netpoll_send_udp(&nt->np, msg, len);
2003+ int result = netpoll_send_udp(nt, msg, len);
19122004
19132005 if (IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC)) {
19142006 if (result == NET_XMIT_DROP) {
@@ -2203,8 +2295,9 @@ __releases(&target_list_lock) · 288 unmodified lines
22032295 spin_unlock_irqrestore(&target_list_lock, flags);
22042296 }
22052297
2206−static int netconsole_parser_cmdline(struct netpoll *np, char *opt)
2298+static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt)
22072299 {
2300+ struct netpoll *np = &nt->np;
22082301 bool ipversion_set = false;
22092302 char *cur = opt;
22102303 char *delim;
@@ -2215,7 +2308,7 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt) · 4 unmodified lines
22152308 if (!delim)
22162309 goto parse_failed;
22172310 *delim = 0;
2218− if (kstrtou16(cur, 10, &np->local_port))
2311+ if (kstrtou16(cur, 10, &nt->local_port))
22192312 goto parse_failed;
22202313 cur = delim;
22212314 }
@@ -2262,7 +2355,7 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt) · 40 unmodified lines
22622355 *delim = 0;
22632356 if (*cur == ' ' || *cur == '\t')
22642357 np_info(np, "warning: whitespace is not allowed\n");
2265− if (kstrtou16(cur, 10, &np->remote_port))
2358+ if (kstrtou16(cur, 10, &nt->remote_port))
22662359 goto parse_failed;
22672360 cur = delim;
22682361 }
@@ -2284,11 +2377,11 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt) · 15 unmodified lines
22842377
22852378 if (*cur != 0) {
22862379 /* MAC address */
2287− if (!mac_pton(cur, np->remote_mac))
2380+ if (!mac_pton(cur, nt->remote_mac))
22882381 goto parse_failed;
22892382 }
22902383
2291− netconsole_print_banner(np);
2384+ netconsole_print_banner(nt);
22922385
22932386 return 0;
22942387
@@ -2326,14 +2419,22 @@ static struct netconsole_target *alloc_param_target(char *target_config, · 31 unmodified lines
23262419 }
23272420
23282421 /* Parse parameters and setup netpoll */
2329− err = netconsole_parser_cmdline(&nt->np, target_config);
2422+ err = netconsole_parser_cmdline(nt, target_config);
23302423 if (err)
23312424 goto fail;
23322425
2426+ /* Initialise the skb pool before netpoll_setup() so the pool is
2427+ * valid as soon as nt->np.dev becomes visible. The target is not
2428+ * yet on target_list, so a netdev event cannot reach it here, but
2429+ * mirror the configfs path for symmetry.
2430+ */
2431+ netconsole_skb_pool_init(nt);
2432+
23332433 err = netpoll_setup(&nt->np);
23342434 if (err) {
23352435 pr_err("Not enabling netconsole for %s%d. Netpoll setup failed\n",
23362436 NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count);
2437+ netconsole_skb_pool_flush(nt);
23372438 if (!IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC))
23382439 /* only fail if dynamic reconfiguration is set,
23392440 * otherwise, keep the target in the list, but disabled.
@@ -2355,6 +2456,8 @@ fail: · 15 unmodified lines
23552456 static void free_param_target(struct netconsole_target *nt)
23562457 {
23572458 cancel_work_sync(&nt->resume_wq);
2459+ if (nt->state == STATE_ENABLED)
2460+ netconsole_skb_pool_flush(nt);
23582461 netpoll_cleanup(&nt->np);
23592462 #ifdef CONFIG_NETCONSOLE_DYNAMIC
23602463 kfree(nt->userdata);
include/linux/netpoll.h+0−18
@@ -21,20 +21,6 @@ union inet_addr { · 20 unmodified lines
2121 struct in6_addr in6;
2222 };
2323
24−/*
25− * Maximum payload netpoll's preallocated skb pool can carry. Keep this in
26− * sync with the buffer size used by refill_skbs() in net/core/netpoll.c;
27− * callers (e.g. netconsole) use it to detect requests the pool can never
28− * satisfy and avoid dequeuing a pooled skb that would later trip
29− * skb_over_panic() in skb_put().
30− */
31−#define MAX_UDP_CHUNK 1460
32−#define MAX_SKB_SIZE \
33− (sizeof(struct ethhdr) + \
34− sizeof(struct iphdr) + \
35− sizeof(struct udphdr) + \
36− MAX_UDP_CHUNK)
37−
3824 struct netpoll {
3925 struct net_device *dev;
4026 netdevice_tracker dev_tracker;
@@ -49,10 +35,6 @@ struct netpoll { · 8 unmodified lines
4935
5036 union inet_addr local_ip, remote_ip;
5137 bool ipv6;
52− u16 local_port, remote_port;
53− u8 remote_mac[ETH_ALEN];
54− struct sk_buff_head skb_pool;
55− struct work_struct refill_wq;
5638 };
5739
5840 #define np_info(np, fmt, ...) \
net/core/netpoll.c+1−50
@@ -36,12 +36,6 @@ · 35 unmodified lines
3636 #include <trace/events/napi.h>
3737 #include <linux/kconfig.h>
3838
39−/*
40− * We maintain a small pool of fully-sized skbs, to make sure the
41− * message gets out even in extreme OOM situations.
42− */
43−
44−#define MAX_SKBS 32
4539 #define USEC_PER_POLL 50
4640
4741 static unsigned int carrier_timeout = 4;
@@ -213,22 +207,6 @@ void netpoll_poll_enable(struct net_device *dev) · 165 unmodified lines
213207 up(&ni->dev_lock);
214208 }
215209
216−static void refill_skbs(struct netpoll *np)
217−{
218− struct sk_buff_head *skb_pool;
219− struct sk_buff *skb;
220−
221− skb_pool = &np->skb_pool;
222−
223− while (READ_ONCE(skb_pool->qlen) < MAX_SKBS) {
224− skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC | __GFP_NOWARN);
225− if (!skb)
226− break;
227−
228− skb_queue_tail(skb_pool, skb);
229− }
230−}
231−
232210 void netpoll_zap_completion_queue(void)
233211 {
234212 unsigned long flags;
@@ -351,32 +329,12 @@ netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb) · 116 unmodified lines
351329 }
352330 EXPORT_SYMBOL(netpoll_send_skb);
353331
354−static void skb_pool_flush(struct netpoll *np)
355−{
356− struct sk_buff_head *skb_pool;
357−
358− cancel_work_sync(&np->refill_wq);
359− skb_pool = &np->skb_pool;
360− skb_queue_purge_reason(skb_pool, SKB_CONSUMED);
361−}
362−
363−static void refill_skbs_work_handler(struct work_struct *work)
364−{
365− struct netpoll *np =
366− container_of(work, struct netpoll, refill_wq);
367−
368− refill_skbs(np);
369−}
370−
371332 int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
372333 {
373334 struct netpoll_info *npinfo;
374335 const struct net_device_ops *ops;
375336 int err;
376337
377− skb_queue_head_init(&np->skb_pool);
378− INIT_WORK(&np->refill_wq, refill_skbs_work_handler);
379−
380338 if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
381339 np_err(np, "%s doesn't support polling, aborting\n",
382340 ndev->name);
@@ -411,9 +369,6 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) · 28 unmodified lines
411369 np->dev = ndev;
412370 strscpy(np->dev_name, ndev->name, IFNAMSIZ);
413371
414− /* fill up the skb queue */
415− refill_skbs(np);
416−
417372 /* last thing to do is link it to the net device structure */
418373 rcu_assign_pointer(ndev->npinfo, npinfo);
419374
@@ -603,7 +558,7 @@ int netpoll_setup(struct netpoll *np) · 183 unmodified lines
603558
604559 err = __netpoll_setup(np, ndev);
605560 if (err)
606− goto flush;
561+ goto put;
607562 rtnl_unlock();
608563
609564 /* Make sure all NAPI polls which started before dev->npinfo
@@ -614,8 +569,6 @@ int netpoll_setup(struct netpoll *np) · 4 unmodified lines
614569
615570 return 0;
616571
617−flush:
618− skb_pool_flush(np);
619572 put:
620573 DEBUG_NET_WARN_ON_ONCE(np->dev);
621574 if (ip_overwritten)
@@ -659,8 +612,6 @@ static void __netpoll_cleanup(struct netpoll *np) · 37 unmodified lines
659612 disable_delayed_work_sync(&npinfo->tx_work);
660613 call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
661614 }
662−
663− skb_pool_flush(np);
664615 }
665616
666617 void __netpoll_free(struct netpoll *np)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t