| @@ -61,6 +61,19 @@ MODULE_IMPORT_NS("NETDEV_INTERNAL"); · 60 unmodified lines |
| 61 | 61 | #define MAX_USERDATA_ITEMS 256 |
| 62 | 62 | #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 | + |
| 64 | 77 | static char config[MAX_PARAM_LENGTH]; |
| 65 | 78 | module_param_string(netconsole, config, MAX_PARAM_LENGTH, 0); |
| 66 | 79 | 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 |
| 162 | 175 | * @np: The netpoll structure for this target. |
| 163 | 176 | * Contains the other userspace visible parameters: |
| 164 | 177 | * dev_name (read-write) |
| 165 | | − * local_port (read-write) |
| 166 | | − * remote_port (read-write) |
| 167 | 178 | * local_ip (read-write) |
| 168 | 179 | * remote_ip (read-write) |
| 169 | 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 | 184 | * @buf: The buffer used to send the full msg to the network stack |
| 172 | 185 | * @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 | */ |
| 174 | 192 | struct netconsole_target { |
| 175 | 193 | struct list_head list; |
| @@ -190,11 +208,15 @@ struct netconsole_target { · 14 unmodified lines |
| 190 | 208 | bool extended; |
| 191 | 209 | bool release; |
| 192 | 210 | struct netpoll np; |
| 211 | + u16 local_port, remote_port; |
| 212 | + u8 remote_mac[ETH_ALEN]; |
| 193 | 213 | /* protected by target_list_lock; +1 gives scnprintf() room for its |
| 194 | 214 | * NUL terminator so a full MAX_PRINT_CHUNK payload is not truncated |
| 195 | 215 | */ |
| 196 | 216 | char buf[MAX_PRINT_CHUNK + 1]; |
| 197 | 217 | struct work_struct resume_wq; |
| 218 | + struct sk_buff_head skb_pool; |
| 219 | + struct work_struct refill_wq; |
| 198 | 220 | }; |
| 199 | 221 | |
| 200 | 222 | #ifdef CONFIG_NETCONSOLE_DYNAMIC |
| @@ -292,11 +314,56 @@ static void netcons_release_dev(struct netconsole_target *nt) · 91 unmodified lines |
| 292 | 314 | memset(&nt->np.dev_name, 0, IFNAMSIZ); |
| 293 | 315 | } |
| 294 | 316 | |
| 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 | + |
| 295 | 354 | /* Attempts to resume logging to a deactivated target. */ |
| 296 | 355 | static 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 | 364 | if (netpoll_setup(&nt->np)) { |
| 299 | 365 | /* netpoll fails setup once, do not try again. */ |
| 366 | + netconsole_skb_pool_flush(nt); |
| 300 | 367 | nt->state = STATE_DISABLED; |
| 301 | 368 | return; |
| 302 | 369 | } |
| @@ -358,6 +425,7 @@ static void process_resume_target(struct work_struct *work) · 55 unmodified lines |
| 358 | 425 | rtnl_lock(); |
| 359 | 426 | if (nt->state == STATE_ENABLED && nt->np.dev && |
| 360 | 427 | nt->np.dev->reg_state != NETREG_REGISTERED) { |
| 428 | + netconsole_skb_pool_flush(nt); |
| 361 | 429 | netcons_release_dev(nt); |
| 362 | 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 | 462 | nt->np.name = "netconsole"; |
| 395 | 463 | 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); |
| 399 | 467 | nt->state = STATE_DISABLED; |
| 400 | 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 | 473 | return nt; |
| 403 | 474 | } |
| @@ -417,6 +488,7 @@ static void netconsole_process_cleanups_core(void) · 13 unmodified lines |
| 417 | 488 | list_for_each_entry_safe(nt, tmp, &target_cleanup_list, list) { |
| 418 | 489 | /* all entries in the cleanup_list needs to be disabled */ |
| 419 | 490 | WARN_ON_ONCE(nt->state == STATE_ENABLED); |
| 491 | + netconsole_skb_pool_flush(nt); |
| 420 | 492 | netcons_release_dev(nt); |
| 421 | 493 | /* moved the cleaned target to target_list. Need to hold both |
| 422 | 494 | * locks |
| @@ -429,21 +501,23 @@ static void netconsole_process_cleanups_core(void) · 6 unmodified lines |
| 429 | 501 | mutex_unlock(&target_cleanup_list_lock); |
| 430 | 502 | } |
| 431 | 503 | |
| 432 | | −static void netconsole_print_banner(struct netpoll *np) |
| 504 | +static 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 | 509 | if (np->ipv6) |
| 436 | 510 | np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.in6); |
| 437 | 511 | else |
| 438 | 512 | np_info(np, "local IPv4 address %pI4\n", &np->local_ip.ip); |
| 439 | 513 | np_info(np, "interface name '%s'\n", np->dev_name); |
| 440 | 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 | 516 | if (np->ipv6) |
| 443 | 517 | np_info(np, "remote IPv6 address %pI6c\n", &np->remote_ip.in6); |
| 444 | 518 | else |
| 445 | 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 | 523 | /* 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 | |
| 562 | 636 | static 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 | |
| 567 | 641 | static 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 | |
| 572 | 646 | 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 |
| 599 | 673 | |
| 600 | 674 | static 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 | |
| 605 | 679 | 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 |
| 756 | 830 | * Skip netconsole_parser_cmdline() -- all the attributes are |
| 757 | 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 | 843 | ret = netpoll_setup(&nt->np); |
| 762 | | − if (ret) |
| 844 | + if (ret) { |
| 845 | + netconsole_skb_pool_flush(nt); |
| 763 | 846 | goto out_unlock; |
| 847 | + } |
| 764 | 848 | |
| 765 | 849 | nt->state = STATE_ENABLED; |
| 766 | 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 | 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 | 973 | if (ret < 0) |
| 890 | 974 | goto out_unlock; |
| 891 | 975 | ret = count; |
| @@ -907,7 +991,7 @@ static ssize_t remote_port_store(struct config_item *item, · 15 unmodified lines |
| 907 | 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 | 995 | if (ret < 0) |
| 912 | 996 | goto out_unlock; |
| 913 | 997 | ret = count; |
| @@ -994,7 +1078,7 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf, · 80 unmodified lines |
| 994 | 1078 | goto out_unlock; |
| 995 | 1079 | if (buf[MAC_ADDR_STR_LEN] && buf[MAC_ADDR_STR_LEN] != '\n') |
| 996 | 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 | 1083 | ret = count; |
| 1000 | 1084 | out_unlock: |
| @@ -1481,15 +1565,15 @@ static void drop_netconsole_target(struct config_group *group, · 480 unmodified lines |
| 1481 | 1565 | |
| 1482 | 1566 | mutex_lock(&target_cleanup_list_lock); |
| 1483 | 1567 | 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. |
| 1490 | 1574 | */ |
| 1491 | 1575 | needs_cleanup = nt->state == STATE_ENABLED || |
| 1492 | | − nt->state == STATE_DEACTIVATED; |
| 1576 | + nt->state == STATE_DEACTIVATED || nt->np.dev; |
| 1493 | 1577 | /* Disable deactivated target to prevent races between resume attempt |
| 1494 | 1578 | * and target removal. |
| 1495 | 1579 | */ |
| @@ -1514,8 +1598,10 @@ static void drop_netconsole_target(struct config_group *group, · 18 unmodified lines |
| 1514 | 1598 | * netpoll_cleanup() is idempotent (it skips when np->dev is NULL), so |
| 1515 | 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 | 1603 | netpoll_cleanup(&nt->np); |
| 1604 | + } |
| 1519 | 1605 | |
| 1520 | 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 | 1792 | * pool locks and is therefore not NMI-safe. Skip the refill when called |
| 1707 | 1793 | * from NMI context; the next non-NMI caller will top the pool back up. |
| 1708 | 1794 | */ |
| 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) |
| 1710 | 1796 | { |
| 1711 | 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 | 1804 | if (!in_nmi()) |
| 1719 | 1805 | net_warn_ratelimited("netconsole: dropping message, requested skb len %d exceeds pool buffer size %zu on %s\n", |
| 1720 | 1806 | len, (size_t)MAX_SKB_SIZE, |
| 1721 | | − np->dev->name); |
| 1807 | + nt->np.dev->name); |
| 1722 | 1808 | return NULL; |
| 1723 | 1809 | } |
| 1724 | 1810 | |
| 1725 | | − skb = skb_dequeue(&np->skb_pool); |
| 1811 | + skb = skb_dequeue(&nt->skb_pool); |
| 1726 | 1812 | if (!in_nmi()) |
| 1727 | | − schedule_work(&np->refill_wq); |
| 1813 | + schedule_work(&nt->refill_wq); |
| 1728 | 1814 | |
| 1729 | 1815 | return skb; |
| 1730 | 1816 | } |
| 1731 | 1817 | |
| 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) |
| 1733 | 1820 | { |
| 1821 | + struct netpoll *np = &nt->np; |
| 1734 | 1822 | int count = 0; |
| 1735 | 1823 | struct sk_buff *skb; |
| 1736 | 1824 | |
| @@ -1739,7 +1827,7 @@ repeat: · 2 unmodified lines |
| 1739 | 1827 | |
| 1740 | 1828 | skb = alloc_skb(len, GFP_ATOMIC | __GFP_NOWARN); |
| 1741 | 1829 | if (!skb) |
| 1742 | | − skb = netcons_skb_pop(np, len); |
| 1830 | + skb = netcons_skb_pop(nt, len); |
| 1743 | 1831 | |
| 1744 | 1832 | if (!skb) { |
| 1745 | 1833 | if (++count < 10) { |
| @@ -1779,8 +1867,9 @@ static void netpoll_udp_checksum(struct netpoll *np, struct sk_buff *skb, · 33 unmodified lines |
| 1779 | 1867 | udph->check = CSUM_MANGLED_0; |
| 1780 | 1868 | } |
| 1781 | 1869 | |
| 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) |
| 1783 | 1871 | { |
| 1872 | + struct netpoll *np = &nt->np; |
| 1784 | 1873 | struct udphdr *udph; |
| 1785 | 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 | 1879 | skb_reset_transport_header(skb); |
| 1791 | 1880 | |
| 1792 | 1881 | 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); |
| 1795 | 1884 | udph->len = htons(udp_len); |
| 1796 | 1885 | |
| 1797 | 1886 | netpoll_udp_checksum(np, skb, len); |
| 1798 | 1887 | } |
| 1799 | 1888 | |
| 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) |
| 1801 | 1890 | { |
| 1891 | + struct netpoll *np = &nt->np; |
| 1802 | 1892 | struct ethhdr *eth; |
| 1803 | 1893 | |
| 1804 | 1894 | eth = skb_push(skb, ETH_HLEN); |
| 1805 | 1895 | skb_reset_mac_header(skb); |
| 1806 | 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 | 1898 | if (np->ipv6) |
| 1809 | 1899 | eth->h_proto = htons(ETH_P_IPV6); |
| 1810 | 1900 | else |
| @@ -1861,8 +1951,10 @@ static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len) · 50 unmodified lines |
| 1861 | 1951 | skb->protocol = htons(ETH_P_IPV6); |
| 1862 | 1952 | } |
| 1863 | 1953 | |
| 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) |
| 1865 | 1956 | { |
| 1957 | + struct netpoll *np = &nt->np; |
| 1866 | 1958 | int total_len, ip_len, udp_len; |
| 1867 | 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 | 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 | 1973 | total_len - len); |
| 1882 | 1974 | if (!skb) |
| 1883 | 1975 | return -ENOMEM; |
| @@ -1885,12 +1977,12 @@ static int netpoll_send_udp(struct netpoll *np, const char *msg, int len) · 1 unmodified line |
| 1885 | 1977 | skb_copy_to_linear_data(skb, msg, len); |
| 1886 | 1978 | skb_put(skb, len); |
| 1887 | 1979 | |
| 1888 | | − push_udp(np, skb, len); |
| 1980 | + push_udp(nt, skb, len); |
| 1889 | 1981 | if (np->ipv6) |
| 1890 | 1982 | push_ipv6(np, skb, len); |
| 1891 | 1983 | else |
| 1892 | 1984 | push_ipv4(np, skb, len); |
| 1893 | | − push_eth(np, skb); |
| 1985 | + push_eth(nt, skb); |
| 1894 | 1986 | skb->dev = np->dev; |
| 1895 | 1987 | |
| 1896 | 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 | */ |
| 1909 | 2001 | static 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 | 2005 | if (IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC)) { |
| 1914 | 2006 | if (result == NET_XMIT_DROP) { |
| @@ -2203,8 +2295,9 @@ __releases(&target_list_lock) · 288 unmodified lines |
| 2203 | 2295 | spin_unlock_irqrestore(&target_list_lock, flags); |
| 2204 | 2296 | } |
| 2205 | 2297 | |
| 2206 | | −static int netconsole_parser_cmdline(struct netpoll *np, char *opt) |
| 2298 | +static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt) |
| 2207 | 2299 | { |
| 2300 | + struct netpoll *np = &nt->np; |
| 2208 | 2301 | bool ipversion_set = false; |
| 2209 | 2302 | char *cur = opt; |
| 2210 | 2303 | char *delim; |
| @@ -2215,7 +2308,7 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt) · 4 unmodified lines |
| 2215 | 2308 | if (!delim) |
| 2216 | 2309 | goto parse_failed; |
| 2217 | 2310 | *delim = 0; |
| 2218 | | − if (kstrtou16(cur, 10, &np->local_port)) |
| 2311 | + if (kstrtou16(cur, 10, &nt->local_port)) |
| 2219 | 2312 | goto parse_failed; |
| 2220 | 2313 | cur = delim; |
| 2221 | 2314 | } |
| @@ -2262,7 +2355,7 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt) · 40 unmodified lines |
| 2262 | 2355 | *delim = 0; |
| 2263 | 2356 | if (*cur == ' ' || *cur == '\t') |
| 2264 | 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 | 2359 | goto parse_failed; |
| 2267 | 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 | 2378 | if (*cur != 0) { |
| 2286 | 2379 | /* MAC address */ |
| 2287 | | − if (!mac_pton(cur, np->remote_mac)) |
| 2380 | + if (!mac_pton(cur, nt->remote_mac)) |
| 2288 | 2381 | goto parse_failed; |
| 2289 | 2382 | } |
| 2290 | 2383 | |
| 2291 | | − netconsole_print_banner(np); |
| 2384 | + netconsole_print_banner(nt); |
| 2292 | 2385 | |
| 2293 | 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 | 2421 | /* Parse parameters and setup netpoll */ |
| 2329 | | − err = netconsole_parser_cmdline(&nt->np, target_config); |
| 2422 | + err = netconsole_parser_cmdline(nt, target_config); |
| 2330 | 2423 | if (err) |
| 2331 | 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 | 2433 | err = netpoll_setup(&nt->np); |
| 2334 | 2434 | if (err) { |
| 2335 | 2435 | pr_err("Not enabling netconsole for %s%d. Netpoll setup failed\n", |
| 2336 | 2436 | NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count); |
| 2437 | + netconsole_skb_pool_flush(nt); |
| 2337 | 2438 | if (!IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC)) |
| 2338 | 2439 | /* only fail if dynamic reconfiguration is set, |
| 2339 | 2440 | * otherwise, keep the target in the list, but disabled. |
| @@ -2355,6 +2456,8 @@ fail: · 15 unmodified lines |
| 2355 | 2456 | static void free_param_target(struct netconsole_target *nt) |
| 2356 | 2457 | { |
| 2357 | 2458 | cancel_work_sync(&nt->resume_wq); |
| 2459 | + if (nt->state == STATE_ENABLED) |
| 2460 | + netconsole_skb_pool_flush(nt); |
| 2358 | 2461 | netpoll_cleanup(&nt->np); |
| 2359 | 2462 | #ifdef CONFIG_NETCONSOLE_DYNAMIC |
| 2360 | 2463 | kfree(nt->userdata); |