From patchwork Thu May 12 12:49:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 621483 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3r5CYh4127z9s5g for ; Thu, 12 May 2016 22:52:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932296AbcELMtr (ORCPT ); Thu, 12 May 2016 08:49:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40816 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932228AbcELMtp (ORCPT ); Thu, 12 May 2016 08:49:45 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 984394C660; Thu, 12 May 2016 12:49:44 +0000 (UTC) Received: from vitty.brq.redhat.com (vitty.brq.redhat.com [10.34.26.3]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4CCndch027132; Thu, 12 May 2016 08:49:43 -0400 From: Vitaly Kuznetsov To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, Haiyang Zhang , "K. Y. Srinivasan" Subject: [PATCH 2/6] hv_netvsc: use start_remove flag to protect netvsc_link_change() Date: Thu, 12 May 2016 14:49:34 +0200 Message-Id: <1463057378-21118-3-git-send-email-vkuznets@redhat.com> In-Reply-To: <1463057378-21118-1-git-send-email-vkuznets@redhat.com> References: <1463057378-21118-1-git-send-email-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 12 May 2016 12:49:44 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org netvsc_link_change() can race with netvsc_change_mtu() or netvsc_set_channels() as these functions destroy struct netvsc_device and rndis filter. Use start_remove flag for syncronization. As netvsc_change_mtu()/netvsc_set_channels() are called with rtnl lock held we need to take it before checking start_remove value in netvsc_link_change(). Reported-by: Haiyang Zhang Signed-off-by: Vitaly Kuznetsov --- drivers/net/hyperv/netvsc_drv.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 48dc81c..9a46b3d 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -787,6 +787,8 @@ static int netvsc_set_channels(struct net_device *net, out: netvsc_open(net); net_device_ctx->start_remove = false; + /* We may have missed link change notifications */ + schedule_delayed_work(&net_device_ctx->dwork, 0); return ret; @@ -895,6 +897,9 @@ out: netvsc_open(ndev); ndevctx->start_remove = false; + /* We may have missed link change notifications */ + schedule_delayed_work(&ndevctx->dwork, 0); + return ret; } @@ -1015,6 +1020,11 @@ static void netvsc_link_change(struct work_struct *w) unsigned long flags, next_reconfig, delay; ndev_ctx = container_of(w, struct net_device_context, dwork.work); + + rtnl_lock(); + if (ndev_ctx->start_remove) + goto out_unlock; + net_device = hv_get_drvdata(ndev_ctx->device_ctx); rdev = net_device->extension; net = net_device->ndev; @@ -1028,7 +1038,7 @@ static void netvsc_link_change(struct work_struct *w) delay = next_reconfig - jiffies; delay = delay < LINKCHANGE_INT ? delay : LINKCHANGE_INT; schedule_delayed_work(&ndev_ctx->dwork, delay); - return; + goto out_unlock; } ndev_ctx->last_reconfig = jiffies; @@ -1042,9 +1052,7 @@ static void netvsc_link_change(struct work_struct *w) spin_unlock_irqrestore(&ndev_ctx->lock, flags); if (!event) - return; - - rtnl_lock(); + goto out_unlock; switch (event->event) { /* Only the following events are possible due to the check in @@ -1093,6 +1101,11 @@ static void netvsc_link_change(struct work_struct *w) */ if (reschedule) schedule_delayed_work(&ndev_ctx->dwork, LINKCHANGE_INT); + + return; + +out_unlock: + rtnl_unlock(); } static void netvsc_free_netdev(struct net_device *netdev)