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.4-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.4 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 10:02:53 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.4/net-vrf-remove-direct-access-to-skb-data.patch queue-4.4/tcp-fix-tcpi_segs_in-after-connection-establishment.patch queue-4.4/tun-bpf-fix-suspicious-rcu-usage-in-tun_-attach-detach-_filter.patch queue-4.4/mpls-find_outdev-check-for-err-ptr-in-addition-to-null-check.patch queue-4.4/ipv4-fix-broadcast-packets-reception.patch queue-4.4/ipv4-only-create-late-gso-skb-if-skb-is-already-set-up-with-checksum_partial.patch queue-4.4/ppp-release-rtnl-mutex-when-interface-creation-fails.patch queue-4.4/bridge-allow-zero-ageing-time.patch queue-4.4/qlge-fix-receive-packets-drop.patch queue-4.4/ppp-take-reference-on-channels-netns.patch queue-4.4/rocker-set-fdb-cleanup-timer-according-to-lowest-ageing-time.patch queue-4.4/bridge-allow-set-bridge-ageing-time-when-switchdev-disabled.patch queue-4.4/qmi_wwan-add-sierra-wireless-em74xx-device-id.patch queue-4.4/ax25-add-link-layer-header-validation-function.patch queue-4.4/net-validate-variable-length-ll-headers.patch queue-4.4/xfrm-fix-crash-observed-during-device-unregistration-and-decryption.patch queue-4.4/tcp-dccp-remove-obsolete-warn_on-in-icmp-handlers.patch queue-4.4/ip6_tunnel-set-rtnl_link_ops-before-calling-register_netdevice.patch queue-4.4/ppp-ensure-file-private_data-can-t-be-overridden.patch queue-4.4/sh_eth-fix-null-pointer-dereference-in-sh_eth_ring_format.patch queue-4.4/ipv4-don-t-do-expensive-useless-work-during-inetdev-destroy.patch queue-4.4/packet-validate-variable-length-ll-headers.patch queue-4.4/sh_eth-advance-rxdesc-later-in-sh_eth_ring_format.patch queue-4.4/mlxsw-spectrum-check-requested-ageing-time-is-valid.patch queue-4.4/farsync-fix-off-by-one-bug-in-fst_add_one.patch queue-4.4/macvtap-always-pass-ethernet-header-in-linear.patch queue-4.4/qmi_wwan-add-d-link-dwm-221-b1-device-id.patch queue-4.4/ipv6-udp-fix-udp_mib_ignoredmulti-updates.patch queue-4.4/ipv4-initialize-flowi4_flags-before-calling-fib_lookup.patch queue-4.4/sctp-lack-the-check-for-ports-in-sctp_v6_cmp_addr.patch queue-4.4/ipv6-count-in-extension-headers-in-skb-network_header.patch queue-4.4/net-qca_spi-don-t-clear-iff_broadcast.patch queue-4.4/net-fix-use-after-free-in-the-recvmmsg-exit-path.patch queue-4.4/ipv4-l2tp-fix-a-potential-issue-in-l2tp_ip_recv.patch queue-4.4/ath9k-fix-buffer-overrun-for-ar9287.patch queue-4.4/vxlan-fix-missing-options_len-update-on-rx-with-collect-metadata.patch queue-4.4/tuntap-restore-default-qdisc.patch queue-4.4/ipv6-l2tp-fix-a-potential-issue-in-l2tp_ip6_recv.patch queue-4.4/usbnet-cleanup-after-bind-in-probe.patch queue-4.4/qlcnic-remove-unnecessary-usage-of-atomic_t.patch queue-4.4/net-jme-fix-suspend-resume-on-jmc260.patch queue-4.4/rtnl-fix-msg-size-calculation-in-if_nlmsg_size.patch queue-4.4/udp6-fix-udp-ipv6-encap-resubmit-path.patch queue-4.4/bonding-fix-bond_get_stats.patch queue-4.4/ipv6-re-enable-fragment-header-matching-in-ipv6_find_hdr.patch queue-4.4/bpf-avoid-copying-junk-bytes-in-bpf_get_current_comm.patch queue-4.4/tunnel-clear-ipcb-skb-opt-before-dst_link_failure-called.patch queue-4.4/net-bcmgenet-fix-dma-api-length-mismatch.patch queue-4.4/qlcnic-fix-mailbox-completion-handling-during-spurious-interrupt.patch queue-4.4/net-fix-bridge-multicast-packet-checksum-validation.patch queue-4.4/cdc_ncm-toggle-altsetting-to-force-reset-before-setup.patch queue-4.4/mld-igmp-fix-reserved-tailroom-calculation.patch queue-4.4/tcp-convert-cached-rtt-from-usec-to-jiffies-when-feeding-initial-rto.patch queue-4.4/tipc-revert-tipc-use-existing-sk_write_queue-for-outgoing-packet-chain.patch queue-4.4/mlx4-add-missing-braces-in-verify_qp_parameters.patch queue-4.4/net-qca_spi-clear-iff_tx_skb_sharing.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