From patchwork Mon Sep 13 13:01:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 511494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 772BEC433EF for ; Mon, 13 Sep 2021 13:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E00060E8B for ; Mon, 13 Sep 2021 13:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239401AbhIMNED (ORCPT ); Mon, 13 Sep 2021 09:04:03 -0400 Received: from mail-bn8nam08on2055.outbound.protection.outlook.com ([40.107.100.55]:54369 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238423AbhIMNDo (ORCPT ); Mon, 13 Sep 2021 09:03:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EBMrGXDzpIGwJ+p9WuOHXOFVZuf5ViOpHn8JPvCYvhXgeFT1Y0yL/Yn4HREUY450Pd11OxvPalNCbrVIyijOgoU46tGso2U6wfd7OaXeYsgLiEL9DN5b+hjjmjMUsYvdbPiY5PgM18HrwFkBVOzsakKN3FanMVJqUbcYHzcx+EW9ns6CgzR/4NdSCNS6zQw1tJdNd0JSboZsxmgBY3K9n4/49Sup2TbU6V2kyI57OvBwp8tSzNY36POOTWheJ3xaYZzhMMJBb6rDfYXBEuPYB6L3iuoWu6bApQBHFejHVsY8ZaRsEiW+bwHrOYpnCZSWXVX/61zYAXIM0T5X3h60ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=A5/7GqCAYp3vk0jpEf5Ll7VwtNGaK4Te6PdbcTGXLL8=; b=oInRN52dimKGBGUJpcgAPAUm2tTq9N0zyOh4fqfOWwwQ7E3Fe6pqTeggIk+nLecHmKwDU96Kbkio4daKeLpVkkfw1MlwL1tQCaMpQEYE8/nDhz/Z/BqrXDQ4U1A2lgGIYyV5DxnW+NlU5H4R7n+Nw+IIKHfP988+rc5+tfmFgdc92mLeH5ES4pLHPdaeW/eTVK9tT1hlFH91gTDTjQayIFo7GzY99Vx6rhQy7MmwAjX/Mlqi41DQfdNv/9hoxCCz5/+2BpMvQpoln5XwRq7k5+N9Eyc4aRC0OWsCxLS6TNBlPvgTUqPf9XYQ2gnXUzEPz3eS3qbN5ncdOScZ8e28LA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A5/7GqCAYp3vk0jpEf5Ll7VwtNGaK4Te6PdbcTGXLL8=; b=SIQmwWca7IHtubbijnnf3VZlTo0katj7wFtOEoEsvDu0weDK6gpx7Hqt4AIGpIE1d+9c5B8Hgiv+Pcju+sV4zjuFzztF7NEDlNr3DtAGcqYX2ltRaoOo1gXeBD+Cp/FgJCU9xLGrpBBSvSJ7YZrdx+pSp142fHzjPODlc7I1kOY= Authentication-Results: driverdev.osuosl.org; dkim=none (message not signed) header.d=none; driverdev.osuosl.org; dmarc=none action=none header.from=silabs.com; Received: from SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) by SA2PR11MB4860.namprd11.prod.outlook.com (2603:10b6:806:11b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Mon, 13 Sep 2021 13:02:26 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd%7]) with mapi id 15.20.4500.017; Mon, 13 Sep 2021 13:02:26 +0000 From: Jerome Pouiller To: devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v3 05/32] staging: wfx: avoid possible lock-up during scan Date: Mon, 13 Sep 2021 15:01:36 +0200 Message-Id: <20210913130203.1903622-6-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913130203.1903622-1-Jerome.Pouiller@silabs.com> References: <20210913130203.1903622-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PR2P264CA0021.FRAP264.PROD.OUTLOOK.COM (2603:10a6:101::33) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 Received: from pc-42.silabs.com (37.71.187.125) by PR2P264CA0021.FRAP264.PROD.OUTLOOK.COM (2603:10a6:101::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 13:02:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9d458163-cbd1-4fa5-2264-08d976b6bc05 X-MS-TrafficTypeDiagnostic: SA2PR11MB4860: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:765; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vrls+GnK4zoQwfvXCnJ895h+fBDmsCDJTYn+CJ3E+KWc6X1vQbJhu7TfW3gTXPvs+h/60v8379Ct+t+cTMlfJORfO84GwTka4wn0rGS/4QcZBI+rnnTq8+6EGTyDKRBatoBi5W9wPGCGSuYhyXN7atWx4TlsDIfq6/paRsoC4MysvPDeGBECeIDTB5eJMq+I8Ln58S69CupjxnGkGiHDvpZzs2x+ligQa4+B23GaEL+rNCd/R77Hs0EK+ZRNR5JmDVrPJOOuYMPMjH/pqMONVFJ5SiWegyxDi5HkYa3YpeKoKTy5PEhWg90vTbMoRfu9i6LRrw9b38km7gUnaZoDRlwto07wgWz4FJyJ2dAYAuuIX+M8BBkWnfBVTWJlYL99G555PNhfgYT0W/AiGSVk1LFI12eXu+l8YP+q4ONKTX2WbIOnllfSxLRY3hANJiUQanareAgxqcclfksjOWLyEMdT7EbsgkBe7M6DQDTWdHScFRWsEkCWqQ0R4HdYxcC75qETHyQdve2LF0weYQ/keYNkt9RP2oVY/yJviK+X54vw/9HIK04IxtRIwdhuOpxo4h2GCgYkJa+K8haf+cJ4dLzq/+28esHpGCXE5LFT6BeHOMK1UMPHq48RXUBryiJy3AowlS/bl6Pzls015Y2XZ/OrHnLuP9lpM1uPZa7I5Rnu1j1BlxdLJXlHR71xr4BEjE/CDGOzVENvaX54A4w+OA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR11MB2718.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(956004)(66574015)(6666004)(66946007)(2616005)(26005)(36756003)(38100700002)(38350700002)(316002)(4326008)(107886003)(7696005)(54906003)(5660300002)(52116002)(66556008)(1076003)(66476007)(6486002)(508600001)(8936002)(83380400001)(86362001)(2906002)(8676002)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?peAb6WbSXt4Cv5/od3u5a7t3/?= =?utf-8?q?mvw1NDGkBQl/6uZnwSosQbFtu/9x8hnnwuSlJAd0tnG/QjrRczdzhnyE?= =?utf-8?q?1RHpIqFc0A61YHo7mx6SEKGEBKv1Sevkpw0dzbJjGnME2WEGUAUhSg0b?= =?utf-8?q?QcGZ32CzTB2lmScMwTLgC3BFgzq5HzAsKFWOIRms8ERyPXzT1rmL+tDl?= =?utf-8?q?UXLNfYcCrfBfuQ3C668bAi5rGpEmOQCjv/a6QZIhuB8Anc+BnziPX67S?= =?utf-8?q?zzudu8ZZZ8nWO1htLzQFgJ8tmY2JwIsdr3sGWjVxv/+d9gitIL/AVyN7?= =?utf-8?q?XedgRPA9/6KOrPKS0LcLbqQd1OO3RXi2DLKMZ+H0963xuc8xHijNKmMj?= =?utf-8?q?5vfvlHwd195FkeNBEs8XpMp+etBpshVz+r9Kq50bKtRhjf97XgohJqHb?= =?utf-8?q?kwEGUGKXRjxOsD4dwn92oXcMNPV++A8EUpy0J0Cv814zqIFE/rguM6Hb?= =?utf-8?q?2ymkrCGGGL6Jd+l7YMPnQPKeiPz0lzGC5QIlxEqmdnn1v5KtH/a8ono0?= =?utf-8?q?+V519kYE5rGSBCn7f1H2ZeymEQTD3aUIJgf6WWw5wEVjhrj25e+Uuh4G?= =?utf-8?q?YmrZQweGuqiV/3p/KKKJjWDqec/TaXICaKgVzd5unXI4bBIvXcpdxb+u?= =?utf-8?q?LJCEf079Hm40dfMo/CgulLj2nKH3q+PAiSQ2TUbw1ptbd62t8yasvkBF?= =?utf-8?q?EF6xFUk30sueDn1Insb/usKA7VvU2WrO+3e85p/wNsgMr7faZ0/kMMpE?= =?utf-8?q?yytKefYyVAaLo1hcTG/fydX80WDbGTSxpRhTsqS82T4rZlbD5GwyaS6P?= =?utf-8?q?XOkQ0YzI/xbuDBeHwN8ppMoe7DzsOav+wH2kid+YpN9SPsx0+b0BZSF7?= =?utf-8?q?HlUbxUlS4x1efwPz4+luXZwOvwSiq96P/DcrdsqoqkD28x5lHfuM+c/7?= =?utf-8?q?urJStkqLfB/JJiwI8X4Ahtpy7mtlMOH5nqIhAPV6JfUaDjVpOG/bXCR8?= =?utf-8?q?4Az/kgC7L250m/wWZteUM3Qff+vmxz2mID2OYmbQswTwRV4/aFfEM8lX?= =?utf-8?q?KYiyGhnbbwlI3HTzb21xAbWueREcc40Oph0kb3sCPO3O2pMkByeWxWlz?= =?utf-8?q?vsvbgZ4bFBtZPK49DLTP9BwcnntaWbhBcT5AOn+D6T3cm4Lq3tWe8gyi?= =?utf-8?q?1uDgy7QaIQ9ZG6Zku/KFE3y1UuPkJ/4oOwfeLi5+5bG84hLVFqcM/V7g?= =?utf-8?q?TM6oiHVTqJhqg2PLNFjQAk2gMjv49bOvvVZSoqyOomiMjuwf/6P1bAB0?= =?utf-8?q?1g1SJk+agoPUI12ThYZsjABZZWeJdz31UTtT2Eo63SsmiuJKpVRSnbiy?= =?utf-8?q?AmKD2a2xfNecZnTGkR0ohLYbQm67VZ+?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d458163-cbd1-4fa5-2264-08d976b6bc05 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 13:02:26.1493 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OZnAradG7Wv1AHOpMQe2WeGQIRth7dvnJD51UTh+27OyGOAa7H3fC30vGio5RpWvP9gykOsPf1zHRN4ekFr9Kw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB4860 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller If the environment is noisy, the device may take time to send scan requests. Thus, scan requests durations > 5s have already been observed. During the scan, traffic is neither received, neither sent. From the user point-of-view, the traffic is frozen for a long time. This patch reworks the scan processing. It gives to the device a smaller time budget than previously. However, it does not expect the scan to be complete and it is able to send another scan request to finish the work. A big part of the patch aims to avoid an infinite loop if the device goes crazy. Signed-off-by: Jérôme Pouiller --- drivers/staging/wfx/hif_rx.c | 3 ++- drivers/staging/wfx/scan.c | 48 ++++++++++++++++++++++-------------- drivers/staging/wfx/scan.h | 2 +- drivers/staging/wfx/wfx.h | 1 + 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/staging/wfx/hif_rx.c b/drivers/staging/wfx/hif_rx.c index 9fca7f26372a..a60c4a4ba935 100644 --- a/drivers/staging/wfx/hif_rx.c +++ b/drivers/staging/wfx/hif_rx.c @@ -175,13 +175,14 @@ static int hif_scan_complete_indication(struct wfx_dev *wdev, const void *buf) { struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); + const struct hif_ind_scan_cmpl *body = buf; if (!wvif) { dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__); return -EIO; } - wfx_scan_complete(wvif); + wfx_scan_complete(wvif, body->num_channels_completed); return 0; } diff --git a/drivers/staging/wfx/scan.c b/drivers/staging/wfx/scan.c index 1e03b130049b..695b06974194 100644 --- a/drivers/staging/wfx/scan.c +++ b/drivers/staging/wfx/scan.c @@ -41,7 +41,7 @@ static int update_probe_tmpl(struct wfx_vif *wvif, static int send_scan_req(struct wfx_vif *wvif, struct cfg80211_scan_request *req, int start_idx) { - int i, ret, timeout; + int i, ret; struct ieee80211_channel *ch_start, *ch_cur; for (i = start_idx; i < req->n_channels; i++) { @@ -56,31 +56,31 @@ static int send_scan_req(struct wfx_vif *wvif, wfx_tx_lock_flush(wvif->wdev); wvif->scan_abort = false; reinit_completion(&wvif->scan_complete); - ret = hif_scan(wvif, req, start_idx, i - start_idx, &timeout); + ret = hif_scan(wvif, req, start_idx, i - start_idx, NULL); if (ret) { - ret = -EIO; - goto err_scan_start; + wfx_tx_unlock(wvif->wdev); + return -EIO; } - ret = wait_for_completion_timeout(&wvif->scan_complete, timeout); + ret = wait_for_completion_timeout(&wvif->scan_complete, 1 * HZ); if (!ret) { - dev_notice(wvif->wdev->dev, "scan timeout\n"); hif_stop_scan(wvif); ret = wait_for_completion_timeout(&wvif->scan_complete, 1 * HZ); - if (!ret) - dev_err(wvif->wdev->dev, "scan didn't stop\n"); + dev_dbg(wvif->wdev->dev, "scan timeout (%d channels done)\n", + wvif->scan_nb_chan_done); + } + if (!ret) { + dev_err(wvif->wdev->dev, "scan didn't stop\n"); ret = -ETIMEDOUT; - goto err_timeout; - } - if (wvif->scan_abort) { + } else if (wvif->scan_abort) { dev_notice(wvif->wdev->dev, "scan abort\n"); ret = -ECONNABORTED; - goto err_timeout; + } else if (wvif->scan_nb_chan_done > i - start_idx) { + ret = -EIO; + } else { + ret = wvif->scan_nb_chan_done; } - ret = i - start_idx; -err_timeout: if (req->channels[start_idx]->max_power != wvif->vif->bss_conf.txpower) hif_set_output_power(wvif, wvif->vif->bss_conf.txpower); -err_scan_start: wfx_tx_unlock(wvif->wdev); return ret; } @@ -94,7 +94,7 @@ void wfx_hw_scan_work(struct work_struct *work) { struct wfx_vif *wvif = container_of(work, struct wfx_vif, scan_work); struct ieee80211_scan_request *hw_req = wvif->scan_req; - int chan_cur, ret; + int chan_cur, ret, err; mutex_lock(&wvif->wdev->conf_mutex); mutex_lock(&wvif->scan_lock); @@ -105,11 +105,20 @@ void wfx_hw_scan_work(struct work_struct *work) } update_probe_tmpl(wvif, &hw_req->req); chan_cur = 0; + err = 0; do { ret = send_scan_req(wvif, &hw_req->req, chan_cur); - if (ret > 0) + if (ret > 0) { chan_cur += ret; - } while (ret > 0 && chan_cur < hw_req->req.n_channels); + err = 0; + } + if (!ret) + err++; + if (err > 2) { + dev_err(wvif->wdev->dev, "scan has not been able to start\n"); + ret = -ETIMEDOUT; + } + } while (ret >= 0 && chan_cur < hw_req->req.n_channels); mutex_unlock(&wvif->scan_lock); mutex_unlock(&wvif->wdev->conf_mutex); __ieee80211_scan_completed_compat(wvif->wdev->hw, ret < 0); @@ -134,7 +143,8 @@ void wfx_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) hif_stop_scan(wvif); } -void wfx_scan_complete(struct wfx_vif *wvif) +void wfx_scan_complete(struct wfx_vif *wvif, int nb_chan_done) { + wvif->scan_nb_chan_done = nb_chan_done; complete(&wvif->scan_complete); } diff --git a/drivers/staging/wfx/scan.h b/drivers/staging/wfx/scan.h index c7496a766478..562ca1321daf 100644 --- a/drivers/staging/wfx/scan.h +++ b/drivers/staging/wfx/scan.h @@ -17,6 +17,6 @@ void wfx_hw_scan_work(struct work_struct *work); int wfx_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_scan_request *req); void wfx_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif); -void wfx_scan_complete(struct wfx_vif *wvif); +void wfx_scan_complete(struct wfx_vif *wvif, int nb_chan_done); #endif /* WFX_SCAN_H */ diff --git a/drivers/staging/wfx/wfx.h b/drivers/staging/wfx/wfx.h index 94898680ccde..56f1e4bb0b57 100644 --- a/drivers/staging/wfx/wfx.h +++ b/drivers/staging/wfx/wfx.h @@ -85,6 +85,7 @@ struct wfx_vif { struct mutex scan_lock; struct work_struct scan_work; struct completion scan_complete; + int scan_nb_chan_done; bool scan_abort; struct ieee80211_scan_request *scan_req;