This is a note to let you know that I've just added the patch titled ipv4: Don't do expensive useless work during inetdev destroy. to the 4.5-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: ipv4-don-t-do-expensive-useless-work-during-inetdev-destroy.patch and it can be found in the queue-4.5 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Sat Apr 16 09:15:18 PDT 2016 From: "David S. Miller" <davem@xxxxxxxxxxxxx> Date: Sun, 13 Mar 2016 23:28:00 -0400 Subject: ipv4: Don't do expensive useless work during inetdev destroy. From: "David S. Miller" <davem@xxxxxxxxxxxxx> [ Upstream commit fbd40ea0180a2d328c5adc61414dc8bab9335ce2 ] When an inetdev is destroyed, every address assigned to the interface is removed. And in this scenerio we do two pointless things which can be very expensive if the number of assigned interfaces is large: 1) Address promotion. We are deleting all addresses, so there is no point in doing this. 2) A full nf conntrack table purge for every address. We only need to do this once, as is already caught by the existing masq_dev_notifier so masq_inet_event() can skip this. Reported-by: Solar Designer <solar@xxxxxxxxxxxx> Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx> Tested-by: Cyrill Gorcunov <gorcunov@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- net/ipv4/devinet.c | 4 ++++ net/ipv4/fib_frontend.c | 4 ++++ net/ipv4/netfilter/nf_nat_masquerade_ipv4.c | 12 ++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -334,6 +334,9 @@ static void __inet_del_ifa(struct in_dev ASSERT_RTNL(); + if (in_dev->dead) + goto no_promotions; + /* 1. Deleting primary ifaddr forces deletion all secondaries * unless alias promotion is set **/ @@ -380,6 +383,7 @@ static void __inet_del_ifa(struct in_dev fib_del_ifaddr(ifa, ifa1); } +no_promotions: /* 2. Unlink it */ *ifap = ifa1->ifa_next; --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -922,6 +922,9 @@ void fib_del_ifaddr(struct in_ifaddr *if subnet = 1; } + if (in_dev->dead) + goto no_promotions; + /* Deletion is more complicated than add. * We should take care of not to delete too much :-) * @@ -997,6 +1000,7 @@ void fib_del_ifaddr(struct in_ifaddr *if } } +no_promotions: if (!(ok & BRD_OK)) fib_magic(RTM_DELROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim); if (subnet && ifa->ifa_prefixlen < 31) { --- a/net/ipv4/netfilter/nf_nat_masquerade_ipv4.c +++ b/net/ipv4/netfilter/nf_nat_masquerade_ipv4.c @@ -108,10 +108,18 @@ static int masq_inet_event(struct notifi unsigned long event, void *ptr) { - struct net_device *dev = ((struct in_ifaddr *)ptr)->ifa_dev->dev; + struct in_device *idev = ((struct in_ifaddr *)ptr)->ifa_dev; struct netdev_notifier_info info; - netdev_notifier_info_init(&info, dev); + /* The masq_dev_notifier will catch the case of the device going + * down. So if the inetdev is dead and being destroyed we have + * no work to do. Otherwise this is an individual address removal + * and we have to perform the flush. + */ + if (idev->dead) + return NOTIFY_DONE; + + netdev_notifier_info_init(&info, idev->dev); return masq_device_event(this, event, &info); } Patches currently in stable-queue which might be from davem@xxxxxxxxxxxxx are queue-4.5/tun-bpf-fix-suspicious-rcu-usage-in-tun_-attach-detach-_filter.patch queue-4.5/mpls-find_outdev-check-for-err-ptr-in-addition-to-null-check.patch queue-4.5/ipv4-fix-broadcast-packets-reception.patch queue-4.5/bridge-allow-zero-ageing-time.patch queue-4.5/qlge-fix-receive-packets-drop.patch queue-4.5/net-dsa-fix-cleanup-resources-upon-module-removal.patch queue-4.5/ppp-take-reference-on-channels-netns.patch queue-4.5/rocker-set-fdb-cleanup-timer-according-to-lowest-ageing-time.patch queue-4.5/bridge-allow-set-bridge-ageing-time-when-switchdev-disabled.patch queue-4.5/ax25-add-link-layer-header-validation-function.patch queue-4.5/net-validate-variable-length-ll-headers.patch queue-4.5/xfrm-fix-crash-observed-during-device-unregistration-and-decryption.patch queue-4.5/tcp-dccp-remove-obsolete-warn_on-in-icmp-handlers.patch queue-4.5/ip6_tunnel-set-rtnl_link_ops-before-calling-register_netdevice.patch queue-4.5/ppp-ensure-file-private_data-can-t-be-overridden.patch queue-4.5/sh_eth-fix-null-pointer-dereference-in-sh_eth_ring_format.patch queue-4.5/ipv4-don-t-do-expensive-useless-work-during-inetdev-destroy.patch queue-4.5/packet-validate-variable-length-ll-headers.patch queue-4.5/sh_eth-advance-rxdesc-later-in-sh_eth_ring_format.patch queue-4.5/mlxsw-spectrum-check-requested-ageing-time-is-valid.patch queue-4.5/farsync-fix-off-by-one-bug-in-fst_add_one.patch queue-4.5/macvtap-always-pass-ethernet-header-in-linear.patch queue-4.5/qmi_wwan-add-d-link-dwm-221-b1-device-id.patch queue-4.5/ipv6-udp-fix-udp_mib_ignoredmulti-updates.patch queue-4.5/ipv4-initialize-flowi4_flags-before-calling-fib_lookup.patch queue-4.5/ipv6-count-in-extension-headers-in-skb-network_header.patch queue-4.5/net-fix-use-after-free-in-the-recvmmsg-exit-path.patch queue-4.5/ipv4-l2tp-fix-a-potential-issue-in-l2tp_ip_recv.patch queue-4.5/ath9k-fix-buffer-overrun-for-ar9287.patch queue-4.5/net-mvneta-fix-spinlock-usage.patch queue-4.5/tuntap-restore-default-qdisc.patch queue-4.5/ipv6-l2tp-fix-a-potential-issue-in-l2tp_ip6_recv.patch queue-4.5/qlcnic-remove-unnecessary-usage-of-atomic_t.patch queue-4.5/rtnl-fix-msg-size-calculation-in-if_nlmsg_size.patch queue-4.5/bonding-fix-bond_get_stats.patch queue-4.5/bpf-avoid-copying-junk-bytes-in-bpf_get_current_comm.patch queue-4.5/net-bcmgenet-fix-dma-api-length-mismatch.patch queue-4.5/qlcnic-fix-mailbox-completion-handling-during-spurious-interrupt.patch queue-4.5/mlx4-add-missing-braces-in-verify_qp_parameters.patch -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html