From patchwork Wed Jul 19 20:57:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Rose X-Patchwork-Id: 791235 X-Patchwork-Delegate: joestringer@nicira.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZHmiywv1"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xCTsd2N5Gz9t36 for ; Thu, 20 Jul 2017 06:59:01 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7B820B2F; Wed, 19 Jul 2017 20:57:26 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 90F5AB01 for ; Wed, 19 Jul 2017 20:57:23 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 15F0C12A for ; Wed, 19 Jul 2017 20:57:23 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id z1so941540pgs.0 for ; Wed, 19 Jul 2017 13:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rg5KV7FvMPiY55y5MQhLI5g0NnQ1adtIHLsHoIJaF88=; b=ZHmiywv17keYaEN/SRP6i1tD1zSIxulmSTRnrAY/RibSpdZTX2MDv9OU/qVl4p2m3Q ytK09cAs6v/B8LehpnogKixJcr8jX+nJT8GP0k/UyniTs92LE4dJij9HrDKM+VQfI+pA uajagP6gTY7N5FeMAZ+YxxoOr0tPV7aPOMX/JzJ/p44hK3WGem67hrYHrMFN7IDR4MGH jyRoBH00CSCDZPAW4neXxpsnp8aY8xWbWpoGPFPHtmEUoWkq9MauZJ5IonjQpJIWcUPS xClfsSRYyd8ZJjfIlYIxpRywS03nCdPOhn3o7WdPYo+oftiYIJ2dCBVfEhnof5z1MARE PJ9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rg5KV7FvMPiY55y5MQhLI5g0NnQ1adtIHLsHoIJaF88=; b=rRv00G5wwb5TfslIhLOo+KFHR6nTfBmXbDKYYWJYYFr3yfHjdVewgRrhwi8dUMeBiE u0YSBAqbPfw2033ad8x80+0zpBSjn0Khtf328JyIgqydieM96TMB5I76rQe7t3Xk8Mdn QwgFAXCOcvvqCm4bG9cJh3sFRoZ480zN8KWN+eV1wOmNnATvV30kVZdQx59qKTeVt5NC W983kq4ubba3spQFDaIEBUFbAg+mnlVESpadtJ2FUN6tt123YwiA1/Ibb0LPpM0gfI+Q PNo6kGbKQZL0baP9O9gK+kmGNV1qUbdCXmidmPJraeC6aCsY0vpIKXKUeTwJfjFPNGi4 mOEA== X-Gm-Message-State: AIVw113U2qULPJEYMAJy8++hCpksQI+iQ3T6iJlB658vYJMke7xxNU04 Wfmhyy24vShM7Y85 X-Received: by 10.98.36.146 with SMTP id k18mr1390072pfk.282.1500497842272; Wed, 19 Jul 2017 13:57:22 -0700 (PDT) Received: from gizo.domain (184-100-139-69.ptld.qwest.net. [184.100.139.69]) by smtp.gmail.com with ESMTPSA id g79sm1171576pfd.163.2017.07.19.13.57.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jul 2017 13:57:21 -0700 (PDT) From: Greg Rose To: dev@openvswitch.org Date: Wed, 19 Jul 2017 13:57:08 -0700 Message-Id: <1500497833-30066-4-git-send-email-gvrose8192@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500497833-30066-1-git-send-email-gvrose8192@gmail.com> References: <1500497833-30066-1-git-send-email-gvrose8192@gmail.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 3/8] datapath: Fix inconsistent teardown and release of private netdev state. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Upstream commit: commit cf124db566e6b036b8bcbe8decbed740bdfac8c6 Author: David S. Miller Date: Mon May 8 12:52:56 2017 -0400 net: Fix inconsistent teardown and release of private netdev state. Network devices can allocate reasources and private memory using netdev_ops->ndo_init(). However, the release of these resources can occur in one of two different places. Either netdev_ops->ndo_uninit() or netdev->destructor(). The decision of which operation frees the resources depends upon whether it is necessary for all netdev refs to be released before it is safe to perform the freeing. netdev_ops->ndo_uninit() presumably can occur right after the NETDEV_UNREGISTER notifier completes and the unicast and multicast address lists are flushed. netdev->destructor(), on the other hand, does not run until the netdev references all go away. Further complicating the situation is that netdev->destructor() almost universally does also a free_netdev(). This creates a problem for the logic in register_netdevice(). Because all callers of register_netdevice() manage the freeing of the netdev, and invoke free_netdev(dev) if register_netdevice() fails. If netdev_ops->ndo_init() succeeds, but something else fails inside of register_netdevice(), it does call ndo_ops->ndo_uninit(). But it is not able to invoke netdev->destructor(). This is because netdev->destructor() will do a free_netdev() and then the caller of register_netdevice() will do the same. However, this means that the resources that would normally be released by netdev->destructor() will not be. Over the years drivers have added local hacks to deal with this, by invoking their destructor parts by hand when register_netdevice() fails. Many drivers do not try to deal with this, and instead we have leaks. Let's close this hole by formalizing the distinction between what private things need to be freed up by netdev->destructor() and whether the driver needs unregister_netdevice() to perform the free_netdev(). netdev->priv_destructor() performs all actions to free up the private resources that used to be freed by netdev->destructor(), except for free_netdev(). netdev->needs_free_netdev is a boolean that indicates whether free_netdev() should be done at the end of unregister_netdevice(). Now, register_netdevice() can sanely release all resources after ndo_ops->ndo_init() succeeds, by invoking both ndo_ops->ndo_uninit() and netdev->priv_destructor(). And at the end of unregister_netdevice(), we invoke netdev->priv_destructor() and optionally call free_netdev(). Signed-off-by: David S. Miller Applied the portion of the commit applicable to openvswitch. Signed-off-by: Greg Rose --- datapath/vport-internal_dev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/datapath/vport-internal_dev.c b/datapath/vport-internal_dev.c index 2fa9ab9..0aa331a 100644 --- a/datapath/vport-internal_dev.c +++ b/datapath/vport-internal_dev.c @@ -114,7 +114,9 @@ static void internal_dev_destructor(struct net_device *dev) struct vport *vport = ovs_internal_dev_get_vport(dev); ovs_vport_free(vport); +#ifndef HAVE_NEEDS_FREE_NETDEV free_netdev(dev); +#endif } static void @@ -188,7 +190,12 @@ static void do_setup(struct net_device *netdev) netdev->priv_flags &= ~IFF_TX_SKB_SHARING; netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH | IFF_PHONY_HEADROOM | IFF_NO_QUEUE; +#ifndef HAVE_NEEDS_FREE_NETDEV netdev->destructor = internal_dev_destructor; +#else + netdev->needs_free_netdev = true; + netdev->priv_destructor = internal_dev_destructor; +#endif /* HAVE_NEEDS_FREE_NETDEV */ netdev->ethtool_ops = &internal_dev_ethtool_ops; netdev->rtnl_link_ops = &internal_dev_link_ops;