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
61#define MAX_USERDATA_ITEMS 25661#define MAX_USERDATA_ITEMS 256
62#define MAX_PRINT_CHUNK 100062#define MAX_PRINT_CHUNK 1000
63 63
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
64static char config[MAX_PARAM_LENGTH];77static char config[MAX_PARAM_LENGTH];
65module_param_string(netconsole, config, MAX_PARAM_LENGTH, 0);78module_param_string(netconsole, config, MAX_PARAM_LENGTH, 0);
66MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]");79MODULE_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
162 * @np: The netpoll structure for this target.175 * @np: The netpoll structure for this target.
163 * Contains the other userspace visible parameters:176 * Contains the other userspace visible parameters:
164 * dev_name (read-write)177 * dev_name (read-write)
165 * local_port (read-write)
166 * remote_port (read-write)
167 * local_ip (read-write)178 * local_ip (read-write)
168 * remote_ip (read-write)179 * remote_ip (read-write)
169 * local_mac (read-only)180 * 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).
171 * @buf: The buffer used to send the full msg to the network stack184 * @buf: The buffer used to send the full msg to the network stack
172 * @resume_wq: Workqueue to resume deactivated target185 * @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.
173 */191 */
174struct netconsole_target {192struct netconsole_target {
175 struct list_head list;193 struct list_head list;
@@ -190,11 +208,15 @@ struct netconsole_target { · 14 unmodified lines
190 bool extended;208 bool extended;
191 bool release;209 bool release;
192 struct netpoll np;210 struct netpoll np;
211 u16 local_port, remote_port;
212 u8 remote_mac[ETH_ALEN];
193 /* protected by target_list_lock; +1 gives scnprintf() room for its213 /* protected by target_list_lock; +1 gives scnprintf() room for its
194 * NUL terminator so a full MAX_PRINT_CHUNK payload is not truncated214 * NUL terminator so a full MAX_PRINT_CHUNK payload is not truncated
195 */215 */
196 char buf[MAX_PRINT_CHUNK + 1];216 char buf[MAX_PRINT_CHUNK + 1];
197 struct work_struct resume_wq;217 struct work_struct resume_wq;
218 struct sk_buff_head skb_pool;
219 struct work_struct refill_wq;
198};220};
199 221
200#ifdef CONFIG_NETCONSOLE_DYNAMIC222#ifdef CONFIG_NETCONSOLE_DYNAMIC
@@ -292,11 +314,56 @@ static void netcons_release_dev(struct netconsole_target *nt) · 91 unmodified lines
292 memset(&nt->np.dev_name, 0, IFNAMSIZ);314 memset(&nt->np.dev_name, 0, IFNAMSIZ);
293}315}
294 316
317static 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
331static 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 */
343static void netconsole_skb_pool_init(struct netconsole_target *nt)
344{
345 refill_skbs(nt);
346}
347
348static 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
295/* Attempts to resume logging to a deactivated target. */354/* Attempts to resume logging to a deactivated target. */
296static void resume_target(struct netconsole_target *nt)355static void resume_target(struct netconsole_target *nt)
297{356{
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
298 if (netpoll_setup(&nt->np)) {364 if (netpoll_setup(&nt->np)) {
299 /* netpoll fails setup once, do not try again. */365 /* netpoll fails setup once, do not try again. */
366 netconsole_skb_pool_flush(nt);
300 nt->state = STATE_DISABLED;367 nt->state = STATE_DISABLED;
301 return;368 return;
302 }369 }
@@ -358,6 +425,7 @@ static void process_resume_target(struct work_struct *work) · 55 unmodified lines
358 rtnl_lock();425 rtnl_lock();
359 if (nt->state == STATE_ENABLED && nt->np.dev &&426 if (nt->state == STATE_ENABLED && nt->np.dev &&
360 nt->np.dev->reg_state != NETREG_REGISTERED) {427 nt->np.dev->reg_state != NETREG_REGISTERED) {
428 netconsole_skb_pool_flush(nt);
361 netcons_release_dev(nt);429 netcons_release_dev(nt);
362 nt->state = STATE_DISABLED;430 nt->state = STATE_DISABLED;
363 }431 }
@@ -393,11 +461,14 @@ static struct netconsole_target *alloc_and_init(void) · 29 unmodified lines
393 461
394 nt->np.name = "netconsole";462 nt->np.name = "netconsole";
395 strscpy(nt->np.dev_name, "eth0", IFNAMSIZ);463 strscpy(nt->np.dev_name, "eth0", IFNAMSIZ);
396 nt->np.local_port = 6665;464 nt->local_port = 6665;
397 nt->np.remote_port = 6666;465 nt->remote_port = 6666;
398 eth_broadcast_addr(nt->np.remote_mac);466 eth_broadcast_addr(nt->remote_mac);
399 nt->state = STATE_DISABLED;467 nt->state = STATE_DISABLED;
400 INIT_WORK(&nt->resume_wq, process_resume_target);468 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);
401 472
402 return nt;473 return nt;
403}474}
@@ -417,6 +488,7 @@ static void netconsole_process_cleanups_core(void) · 13 unmodified lines
417 list_for_each_entry_safe(nt, tmp, &target_cleanup_list, list) {488 list_for_each_entry_safe(nt, tmp, &target_cleanup_list, list) {
418 /* all entries in the cleanup_list needs to be disabled */489 /* all entries in the cleanup_list needs to be disabled */
419 WARN_ON_ONCE(nt->state == STATE_ENABLED);490 WARN_ON_ONCE(nt->state == STATE_ENABLED);
491 netconsole_skb_pool_flush(nt);
420 netcons_release_dev(nt);492 netcons_release_dev(nt);
421 /* moved the cleaned target to target_list. Need to hold both493 /* moved the cleaned target to target_list. Need to hold both
422 * locks494 * locks
@@ -429,21 +501,23 @@ static void netconsole_process_cleanups_core(void) · 6 unmodified lines
429 mutex_unlock(&target_cleanup_list_lock);501 mutex_unlock(&target_cleanup_list_lock);
430}502}
431 503
432static void netconsole_print_banner(struct netpoll *np)504static void netconsole_print_banner(struct netconsole_target *nt)
433{505{
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);
435 if (np->ipv6)509 if (np->ipv6)
436 np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.in6);510 np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.in6);
437 else511 else
438 np_info(np, "local IPv4 address %pI4\n", &np->local_ip.ip);512 np_info(np, "local IPv4 address %pI4\n", &np->local_ip.ip);
439 np_info(np, "interface name '%s'\n", np->dev_name);513 np_info(np, "interface name '%s'\n", np->dev_name);
440 np_info(np, "local ethernet address '%pM'\n", np->dev_mac);514 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);
442 if (np->ipv6)516 if (np->ipv6)
443 np_info(np, "remote IPv6 address %pI6c\n", &np->remote_ip.in6);517 np_info(np, "remote IPv6 address %pI6c\n", &np->remote_ip.in6);
444 else518 else
445 np_info(np, "remote IPv4 address %pI4\n", &np->remote_ip.ip);519 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);
447}521}
448 522
449/* Parse the string and populate the `inet_addr` union. Return 0 if IPv4 is523/* 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
561 635
562static ssize_t local_port_show(struct config_item *item, char *buf)636static ssize_t local_port_show(struct config_item *item, char *buf)
563{637{
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);
565}639}
566 640
567static ssize_t remote_port_show(struct config_item *item, char *buf)641static ssize_t remote_port_show(struct config_item *item, char *buf)
568{642{
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);
570}644}
571 645
572static ssize_t local_ip_show(struct config_item *item, char *buf)646static 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
599 673
600static ssize_t remote_mac_show(struct config_item *item, char *buf)674static ssize_t remote_mac_show(struct config_item *item, char *buf)
601{675{
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);
603}677}
604 678
605static ssize_t transmit_errors_show(struct config_item *item, char *buf)679static 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
756 * Skip netconsole_parser_cmdline() -- all the attributes are830 * Skip netconsole_parser_cmdline() -- all the attributes are
757 * already configured via configfs. Just print them out.831 * already configured via configfs. Just print them out.
758 */832 */
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);
760 842
761 ret = netpoll_setup(&nt->np);843 ret = netpoll_setup(&nt->np);
762 if (ret)844 if (ret) {
845 netconsole_skb_pool_flush(nt);
763 goto out_unlock;846 goto out_unlock;
847 }
764 848
765 nt->state = STATE_ENABLED;849 nt->state = STATE_ENABLED;
766 pr_info("network logging started\n");850 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
885 goto out_unlock;969 goto out_unlock;
886 }970 }
887 971
888 ret = kstrtou16(buf, 10, &nt->np.local_port);972 ret = kstrtou16(buf, 10, &nt->local_port);
889 if (ret < 0)973 if (ret < 0)
890 goto out_unlock;974 goto out_unlock;
891 ret = count;975 ret = count;
@@ -907,7 +991,7 @@ static ssize_t remote_port_store(struct config_item *item, · 15 unmodified lines
907 goto out_unlock;991 goto out_unlock;
908 }992 }
909 993
910 ret = kstrtou16(buf, 10, &nt->np.remote_port);994 ret = kstrtou16(buf, 10, &nt->remote_port);
911 if (ret < 0)995 if (ret < 0)
912 goto out_unlock;996 goto out_unlock;
913 ret = count;997 ret = count;
@@ -994,7 +1078,7 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf, · 80 unmodified lines
994 goto out_unlock;1078 goto out_unlock;
995 if (buf[MAC_ADDR_STR_LEN] && buf[MAC_ADDR_STR_LEN] != '\n')1079 if (buf[MAC_ADDR_STR_LEN] && buf[MAC_ADDR_STR_LEN] != '\n')
996 goto out_unlock;1080 goto out_unlock;
997 memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN);1081 memcpy(nt->remote_mac, remote_mac, ETH_ALEN);
998 1082
999 ret = count;1083 ret = count;
1000out_unlock:1084out_unlock:
@@ -1481,15 +1565,15 @@ static void drop_netconsole_target(struct config_group *group, · 480 unmodified lines
1481 1565
1482 mutex_lock(&target_cleanup_list_lock);1566 mutex_lock(&target_cleanup_list_lock);
1483 spin_lock_irqsave(&target_list_lock, flags);1567 spin_lock_irqsave(&target_list_lock, flags);
1484 /* A STATE_DEACTIVATED target may have been moved to1568 /* A target moved to target_cleanup_list by netconsole_netdev_event()
1485 * target_cleanup_list by netconsole_netdev_event() but not yet1569 * but not yet processed still owns a netpoll; unlinking it below hides
1486 * processed by netconsole_process_cleanups_core(). Unlinking it below1570 * it from the cleanup worker, so this path must tear it down itself.
1487 * hides it from the cleanup worker, so this path has to clean it up1571 * This covers NETDEV_UNREGISTER (STATE_DEACTIVATED) and
1488 * itself. Record that the target still owns a netpoll before the1572 * NETDEV_RELEASE / NETDEV_JOIN (STATE_DISABLED); key off nt->np.dev,
1489 * state is downgraded.1573 * which stays set until the netpoll is cleaned up.
1490 */1574 */
1491 needs_cleanup = nt->state == STATE_ENABLED ||1575 needs_cleanup = nt->state == STATE_ENABLED ||
1492 nt->state == STATE_DEACTIVATED;1576 nt->state == STATE_DEACTIVATED || nt->np.dev;
1493 /* Disable deactivated target to prevent races between resume attempt1577 /* Disable deactivated target to prevent races between resume attempt
1494 * and target removal.1578 * and target removal.
1495 */1579 */
@@ -1514,8 +1598,10 @@ static void drop_netconsole_target(struct config_group *group, · 18 unmodified lines
1514 * netpoll_cleanup() is idempotent (it skips when np->dev is NULL), so1598 * netpoll_cleanup() is idempotent (it skips when np->dev is NULL), so
1515 * it is safe even if the cleanup worker already tore the netpoll down.1599 * it is safe even if the cleanup worker already tore the netpoll down.
1516 */1600 */
1517 if (needs_cleanup)1601 if (needs_cleanup) {
1602 netconsole_skb_pool_flush(nt);
1518 netpoll_cleanup(&nt->np);1603 netpoll_cleanup(&nt->np);
1604 }
1519 1605
1520 config_item_put(&nt->group.cg_item);1606 config_item_put(&nt->group.cg_item);
1521}1607}
@@ -1706,7 +1792,7 @@ static struct notifier_block netconsole_netdev_notifier = { · 184 unmodified lines
1706 * pool locks and is therefore not NMI-safe. Skip the refill when called1792 * pool locks and is therefore not NMI-safe. Skip the refill when called
1707 * from NMI context; the next non-NMI caller will top the pool back up.1793 * from NMI context; the next non-NMI caller will top the pool back up.
1708 */1794 */
1709static struct sk_buff *netcons_skb_pop(struct netpoll *np, int len)1795static struct sk_buff *netcons_skb_pop(struct netconsole_target *nt, int len)
1710{1796{
1711 struct sk_buff *skb;1797 struct sk_buff *skb;
1712 1798
@@ -1718,19 +1804,21 @@ static struct sk_buff *netcons_skb_pop(struct netpoll *np, int len) · 5 unmodified lines
1718 if (!in_nmi())1804 if (!in_nmi())
1719 net_warn_ratelimited("netconsole: dropping message, requested skb len %d exceeds pool buffer size %zu on %s\n",1805 net_warn_ratelimited("netconsole: dropping message, requested skb len %d exceeds pool buffer size %zu on %s\n",
1720 len, (size_t)MAX_SKB_SIZE,1806 len, (size_t)MAX_SKB_SIZE,
1721 np->dev->name);1807 nt->np.dev->name);
1722 return NULL;1808 return NULL;
1723 }1809 }
1724 1810
1725 skb = skb_dequeue(&np->skb_pool);1811 skb = skb_dequeue(&nt->skb_pool);
1726 if (!in_nmi())1812 if (!in_nmi())
1727 schedule_work(&np->refill_wq);1813 schedule_work(&nt->refill_wq);
1728 1814
1729 return skb;1815 return skb;
1730}1816}
1731 1817
1732static struct sk_buff *find_skb(struct netpoll *np, int len, int reserve)1818static struct sk_buff *find_skb(struct netconsole_target *nt, int len,
1819 int reserve)
1733{1820{
1821 struct netpoll *np = &nt->np;
1734 int count = 0;1822 int count = 0;
1735 struct sk_buff *skb;1823 struct sk_buff *skb;
1736 1824
@@ -1739,7 +1827,7 @@ repeat: · 2 unmodified lines
1739 1827
1740 skb = alloc_skb(len, GFP_ATOMIC | __GFP_NOWARN);1828 skb = alloc_skb(len, GFP_ATOMIC | __GFP_NOWARN);
1741 if (!skb)1829 if (!skb)
1742 skb = netcons_skb_pop(np, len);1830 skb = netcons_skb_pop(nt, len);
1743 1831
1744 if (!skb) {1832 if (!skb) {
1745 if (++count < 10) {1833 if (++count < 10) {
@@ -1779,8 +1867,9 @@ static void netpoll_udp_checksum(struct netpoll *np, struct sk_buff *skb, · 33 unmodified lines
1779 udph->check = CSUM_MANGLED_0;1867 udph->check = CSUM_MANGLED_0;
1780}1868}
1781 1869
1782static void push_udp(struct netpoll *np, struct sk_buff *skb, int len)1870static void push_udp(struct netconsole_target *nt, struct sk_buff *skb, int len)
1783{1871{
1872 struct netpoll *np = &nt->np;
1784 struct udphdr *udph;1873 struct udphdr *udph;
1785 int udp_len;1874 int udp_len;
1786 1875
@@ -1790,21 +1879,22 @@ static void push_udp(struct netpoll *np, struct sk_buff *skb, int len) · 3 unmodified lines
1790 skb_reset_transport_header(skb);1879 skb_reset_transport_header(skb);
1791 1880
1792 udph = udp_hdr(skb);1881 udph = udp_hdr(skb);
1793 udph->source = htons(np->local_port);1882 udph->source = htons(nt->local_port);
1794 udph->dest = htons(np->remote_port);1883 udph->dest = htons(nt->remote_port);
1795 udph->len = htons(udp_len);1884 udph->len = htons(udp_len);
1796 1885
1797 netpoll_udp_checksum(np, skb, len);1886 netpoll_udp_checksum(np, skb, len);
1798}1887}
1799 1888
1800static void push_eth(struct netpoll *np, struct sk_buff *skb)1889static void push_eth(struct netconsole_target *nt, struct sk_buff *skb)
1801{1890{
1891 struct netpoll *np = &nt->np;
1802 struct ethhdr *eth;1892 struct ethhdr *eth;
1803 1893
1804 eth = skb_push(skb, ETH_HLEN);1894 eth = skb_push(skb, ETH_HLEN);
1805 skb_reset_mac_header(skb);1895 skb_reset_mac_header(skb);
1806 ether_addr_copy(eth->h_source, np->dev->dev_addr);1896 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);
1808 if (np->ipv6)1898 if (np->ipv6)
1809 eth->h_proto = htons(ETH_P_IPV6);1899 eth->h_proto = htons(ETH_P_IPV6);
1810 else1900 else
@@ -1861,8 +1951,10 @@ static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len) · 50 unmodified lines
1861 skb->protocol = htons(ETH_P_IPV6);1951 skb->protocol = htons(ETH_P_IPV6);
1862}1952}
1863 1953
1864static int netpoll_send_udp(struct netpoll *np, const char *msg, int len)1954static int netpoll_send_udp(struct netconsole_target *nt, const char *msg,
1955 int len)
1865{1956{
1957 struct netpoll *np = &nt->np;
1866 int total_len, ip_len, udp_len;1958 int total_len, ip_len, udp_len;
1867 struct sk_buff *skb;1959 struct sk_buff *skb;
1868 1960
@@ -1877,7 +1969,7 @@ static int netpoll_send_udp(struct netpoll *np, const char *msg, int len) · 8 unmodified lines
1877 1969
1878 total_len = ip_len + LL_RESERVED_SPACE(np->dev);1970 total_len = ip_len + LL_RESERVED_SPACE(np->dev);
1879 1971
1880 skb = find_skb(np, total_len + np->dev->needed_tailroom,1972 skb = find_skb(nt, total_len + np->dev->needed_tailroom,
1881 total_len - len);1973 total_len - len);
1882 if (!skb)1974 if (!skb)
1883 return -ENOMEM;1975 return -ENOMEM;
@@ -1885,12 +1977,12 @@ static int netpoll_send_udp(struct netpoll *np, const char *msg, int len) · 1 unmodified line
1885 skb_copy_to_linear_data(skb, msg, len);1977 skb_copy_to_linear_data(skb, msg, len);
1886 skb_put(skb, len);1978 skb_put(skb, len);
1887 1979
1888 push_udp(np, skb, len);1980 push_udp(nt, skb, len);
1889 if (np->ipv6)1981 if (np->ipv6)
1890 push_ipv6(np, skb, len);1982 push_ipv6(np, skb, len);
1891 else1983 else
1892 push_ipv4(np, skb, len);1984 push_ipv4(np, skb, len);
1893 push_eth(np, skb);1985 push_eth(nt, skb);
1894 skb->dev = np->dev;1986 skb->dev = np->dev;
1895 1987
1896 return (int)netpoll_send_skb(np, skb);1988 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
1908 */2000 */
1909static void send_udp(struct netconsole_target *nt, const char *msg, int len)2001static void send_udp(struct netconsole_target *nt, const char *msg, int len)
1910{2002{
1911 int result = netpoll_send_udp(&nt->np, msg, len);2003 int result = netpoll_send_udp(nt, msg, len);
1912 2004
1913 if (IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC)) {2005 if (IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC)) {
1914 if (result == NET_XMIT_DROP) {2006 if (result == NET_XMIT_DROP) {
@@ -2203,8 +2295,9 @@ __releases(&target_list_lock) · 288 unmodified lines
2203 spin_unlock_irqrestore(&target_list_lock, flags);2295 spin_unlock_irqrestore(&target_list_lock, flags);
2204}2296}
2205 2297
2206static int netconsole_parser_cmdline(struct netpoll *np, char *opt)2298static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt)
2207{2299{
2300 struct netpoll *np = &nt->np;
2208 bool ipversion_set = false;2301 bool ipversion_set = false;
2209 char *cur = opt;2302 char *cur = opt;
2210 char *delim;2303 char *delim;
@@ -2215,7 +2308,7 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt) · 4 unmodified lines
2215 if (!delim)2308 if (!delim)
2216 goto parse_failed;2309 goto parse_failed;
2217 *delim = 0;2310 *delim = 0;
2218 if (kstrtou16(cur, 10, &np->local_port))2311 if (kstrtou16(cur, 10, &nt->local_port))
2219 goto parse_failed;2312 goto parse_failed;
2220 cur = delim;2313 cur = delim;
2221 }2314 }
@@ -2262,7 +2355,7 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt) · 40 unmodified lines
2262 *delim = 0;2355 *delim = 0;
2263 if (*cur == ' ' || *cur == '\t')2356 if (*cur == ' ' || *cur == '\t')
2264 np_info(np, "warning: whitespace is not allowed\n");2357 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))
2266 goto parse_failed;2359 goto parse_failed;
2267 cur = delim;2360 cur = delim;
2268 }2361 }
@@ -2284,11 +2377,11 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt) · 15 unmodified lines
2284 2377
2285 if (*cur != 0) {2378 if (*cur != 0) {
2286 /* MAC address */2379 /* MAC address */
2287 if (!mac_pton(cur, np->remote_mac))2380 if (!mac_pton(cur, nt->remote_mac))
2288 goto parse_failed;2381 goto parse_failed;
2289 }2382 }
2290 2383
2291 netconsole_print_banner(np);2384 netconsole_print_banner(nt);
2292 2385
2293 return 0;2386 return 0;
2294 2387
@@ -2326,14 +2419,22 @@ static struct netconsole_target *alloc_param_target(char *target_config, · 31 unmodified lines
2326 }2419 }
2327 2420
2328 /* Parse parameters and setup netpoll */2421 /* Parse parameters and setup netpoll */
2329 err = netconsole_parser_cmdline(&nt->np, target_config);2422 err = netconsole_parser_cmdline(nt, target_config);
2330 if (err)2423 if (err)
2331 goto fail;2424 goto fail;
2332 2425
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
2333 err = netpoll_setup(&nt->np);2433 err = netpoll_setup(&nt->np);
2334 if (err) {2434 if (err) {
2335 pr_err("Not enabling netconsole for %s%d. Netpoll setup failed\n",2435 pr_err("Not enabling netconsole for %s%d. Netpoll setup failed\n",
2336 NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count);2436 NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count);
2437 netconsole_skb_pool_flush(nt);
2337 if (!IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC))2438 if (!IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC))
2338 /* only fail if dynamic reconfiguration is set,2439 /* only fail if dynamic reconfiguration is set,
2339 * otherwise, keep the target in the list, but disabled.2440 * otherwise, keep the target in the list, but disabled.
@@ -2355,6 +2456,8 @@ fail: · 15 unmodified lines
2355static void free_param_target(struct netconsole_target *nt)2456static void free_param_target(struct netconsole_target *nt)
2356{2457{
2357 cancel_work_sync(&nt->resume_wq);2458 cancel_work_sync(&nt->resume_wq);
2459 if (nt->state == STATE_ENABLED)
2460 netconsole_skb_pool_flush(nt);
2358 netpoll_cleanup(&nt->np);2461 netpoll_cleanup(&nt->np);
2359#ifdef CONFIG_NETCONSOLE_DYNAMIC2462#ifdef CONFIG_NETCONSOLE_DYNAMIC
2360 kfree(nt->userdata);2463 kfree(nt->userdata);
include/linux/netpoll.h+0−18
@@ -21,20 +21,6 @@ union inet_addr { · 20 unmodified lines
21 struct in6_addr in6;21 struct in6_addr in6;
22};22};
23 23
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
38struct netpoll {24struct netpoll {
39 struct net_device *dev;25 struct net_device *dev;
40 netdevice_tracker dev_tracker;26 netdevice_tracker dev_tracker;
@@ -49,10 +35,6 @@ struct netpoll { · 8 unmodified lines
49 35
50 union inet_addr local_ip, remote_ip;36 union inet_addr local_ip, remote_ip;
51 bool ipv6;37 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;
56};38};
57 39
58#define np_info(np, fmt, ...) \40#define np_info(np, fmt, ...) \
net/core/netpoll.c+1−50
@@ -36,12 +36,6 @@ · 35 unmodified lines
36#include <trace/events/napi.h>36#include <trace/events/napi.h>
37#include <linux/kconfig.h>37#include <linux/kconfig.h>
38 38
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
45#define USEC_PER_POLL 5039#define USEC_PER_POLL 50
46 40
47static unsigned int carrier_timeout = 4;41static unsigned int carrier_timeout = 4;
@@ -213,22 +207,6 @@ void netpoll_poll_enable(struct net_device *dev) · 165 unmodified lines
213 up(&ni->dev_lock);207 up(&ni->dev_lock);
214}208}
215 209
216static 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
232void netpoll_zap_completion_queue(void)210void netpoll_zap_completion_queue(void)
233{211{
234 unsigned long flags;212 unsigned long flags;
@@ -351,32 +329,12 @@ netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb) · 116 unmodified lines
351}329}
352EXPORT_SYMBOL(netpoll_send_skb);330EXPORT_SYMBOL(netpoll_send_skb);
353 331
354static 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
363static 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
371int __netpoll_setup(struct netpoll *np, struct net_device *ndev)332int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
372{333{
373 struct netpoll_info *npinfo;334 struct netpoll_info *npinfo;
374 const struct net_device_ops *ops;335 const struct net_device_ops *ops;
375 int err;336 int err;
376 337
377 skb_queue_head_init(&np->skb_pool);
378 INIT_WORK(&np->refill_wq, refill_skbs_work_handler);
379
380 if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {338 if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
381 np_err(np, "%s doesn't support polling, aborting\n",339 np_err(np, "%s doesn't support polling, aborting\n",
382 ndev->name);340 ndev->name);
@@ -411,9 +369,6 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) · 28 unmodified lines
411 np->dev = ndev;369 np->dev = ndev;
412 strscpy(np->dev_name, ndev->name, IFNAMSIZ);370 strscpy(np->dev_name, ndev->name, IFNAMSIZ);
413 371
414 /* fill up the skb queue */
415 refill_skbs(np);
416
417 /* last thing to do is link it to the net device structure */372 /* last thing to do is link it to the net device structure */
418 rcu_assign_pointer(ndev->npinfo, npinfo);373 rcu_assign_pointer(ndev->npinfo, npinfo);
419 374
@@ -603,7 +558,7 @@ int netpoll_setup(struct netpoll *np) · 183 unmodified lines
603 558
604 err = __netpoll_setup(np, ndev);559 err = __netpoll_setup(np, ndev);
605 if (err)560 if (err)
606 goto flush;561 goto put;
607 rtnl_unlock();562 rtnl_unlock();
608 563
609 /* Make sure all NAPI polls which started before dev->npinfo564 /* Make sure all NAPI polls which started before dev->npinfo
@@ -614,8 +569,6 @@ int netpoll_setup(struct netpoll *np) · 4 unmodified lines
614 569
615 return 0;570 return 0;
616 571
617flush:
618 skb_pool_flush(np);
619put:572put:
620 DEBUG_NET_WARN_ON_ONCE(np->dev);573 DEBUG_NET_WARN_ON_ONCE(np->dev);
621 if (ip_overwritten)574 if (ip_overwritten)
@@ -659,8 +612,6 @@ static void __netpoll_cleanup(struct netpoll *np) · 37 unmodified lines
659 disable_delayed_work_sync(&npinfo->tx_work);612 disable_delayed_work_sync(&npinfo->tx_work);
660 call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);613 call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
661 }614 }
662
663 skb_pool_flush(np);
664}615}
665 616
666void __netpoll_free(struct netpoll *np)617void __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