From patchwork Sat Jun 18 18:18:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 9185795 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0953B601C0 for ; Sat, 18 Jun 2016 18:20:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEC4226992 for ; Sat, 18 Jun 2016 18:20:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFE1828360; Sat, 18 Jun 2016 18:20:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 853F626992 for ; Sat, 18 Jun 2016 18:20:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751579AbcFRSTR (ORCPT ); Sat, 18 Jun 2016 14:19:17 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:36513 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751468AbcFRSTP (ORCPT ); Sat, 18 Jun 2016 14:19:15 -0400 Received: by mail-lf0-f66.google.com with SMTP id a2so2233643lfe.3; Sat, 18 Jun 2016 11:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F+lMCvvy5rBfTLgfKIT963545ynI4lZx4Egy0HTUnpE=; b=qjjJnkDUyr682QU7MQSXufLZA3R8vpfdEtDFqxsbUmYL0h260Jc2z6F1KD0933LCq0 3BCWOXiM5KFUeCfjyG2owwKauqge4UpB89gSXGElD45wOf+zgDDmvvKRljLwCnDAJRHN GqRTrSc9JXNbXxFU6YQnn4MxB+GoBLVZ2uk7A0SiNclb/kbpeLjMzPRDHhQMY9qHdPky ldn03j4dhBGvMmVEzCcoUCToxJzJy0llTszgWxk+IKnOm5Rnxq1biyG+L66Rq9uxFX6L f8yHIlppGEvdQycxFHhiza1jraKNzJtzKULNtP240feU3R8ntMnJ+3CHdSdJ7e4IY5on OqzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F+lMCvvy5rBfTLgfKIT963545ynI4lZx4Egy0HTUnpE=; b=HSDYH/XzzoN2damIRbYFSFylFUkXsMnKW29OLLFVZGnBnzfCUkD6Lx1R2SBfGPtu5E JmrfJdozoOQoQDnOMvN43Pdk92hfc0otM7B0sg3gODUuLX7d19Rf9ZpuqtZvh1ECnFf0 qj15XtRseszsahWh+atzM4+5AkGsYSLKm19M30GQbblTs8Ri4ruKd96Xn/Ul4hJbUPhW xv83KFx/6FJA2ZcUi/By8cHEoOlx6ddmbK9YMnTzjact0UtSd9RK8g9Kfc5BhBZVVofj +rVZAK+Q2URmzimd7AZCg2RJYFl5nRDoXDE/NKCA5InN8hRASyVWOyoGted8yXgJ5lsu nKWQ== X-Gm-Message-State: ALyK8tIeiOi7WolxNExhyhntNPcquiDDGXkf4iUMzf+/ju7HjPSK1WOwb+TY1DVhhq8JQQ== X-Received: by 10.25.23.225 with SMTP id 94mr1763652lfx.38.1466273953589; Sat, 18 Jun 2016 11:19:13 -0700 (PDT) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id h11sm4922151ljh.33.2016.06.18.11.19.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Jun 2016 11:19:12 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Kalle Valo Cc: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Arend van Spriel , Franky Lin , Hante Meuleman , Pieter-Paul Giesberts , "Franky (Zhenhui) Lin" , linux-wireless@vger.kernel.org (open list:BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER), brcm80211-dev-list.pdl@broadcom.com (open list:BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER), netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH RFC 1/2] brcmfmac: remove interface before notifying listener Date: Sat, 18 Jun 2016 20:18:34 +0200 Message-Id: <1466273932-11554-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So far when receiving event about in-firmware-interface removal we were notifying our listener and afterwards we were removing Linux interface. This order was most likely a try to avoid a lockup. Removing in-firmware interface could be requested by a driver code holding rtnl lock. Such code waits for a corresponding event (still holding rtnl lock) which prevents us from calling unregister_netdev. Notifying listener first allowed it to release rtnl lock and removing interface succesfully. Please note we couldn't switch to unregister_netdevice as interface removal event could also occur in other (unpredictable) moments. Unfortunately above workaround doesn't work in some corner cases. Focus on the time slot between calling event handler and removing Linux interface. During that time original caller may leave (unlocking rtnl semaphore) *and* another call to the same code may be done (locking it again). If that happens our event handler will stuck at removing Linux interface, it won't handle another event and will block process holding rtnl lock. So the real solution is to remove interface before notifying listener. We just need to know if rtnl is hold by a caller that triggered our event. Moreover this changes makes sure we call unregister_netdevice before del_virtual_intf leaves which isn't critical but it makes a bit more of sense to handle it this way. Signed-off-by: Rafał Miłecki --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c index 9da7a4c..5fd1886 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c @@ -18,6 +18,7 @@ #include "brcmu_wifi.h" #include "brcmu_utils.h" +#include "cfg80211.h" #include "core.h" #include "debug.h" #include "tracepoint.h" @@ -180,10 +181,16 @@ static void brcmf_fweh_handle_if_event(struct brcmf_pub *drvr, if (ifp && ifevent->action == BRCMF_E_IF_CHANGE) brcmf_fws_reset_interface(ifp); - err = brcmf_fweh_call_event_handler(ifp, emsg->event_code, emsg, data); + if (ifp && ifevent->action == BRCMF_E_IF_DEL) { + bool rtnl_locked = brcmf_cfg80211_vif_event_armed(drvr->config); + + brcmf_remove_interface(ifp, rtnl_locked); + } - if (ifp && ifevent->action == BRCMF_E_IF_DEL) - brcmf_remove_interface(ifp, false); + err = brcmf_fweh_call_event_handler(ifp, emsg->event_code, emsg, data); + if (err) + brcmf_err("event %d handler failed (%d)\n", emsg->event_code, + err); } /**