From patchwork Fri Sep 10 16:04:38 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: 509387 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, 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 952C9C4332F for ; Fri, 10 Sep 2021 16:05:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F66E611F2 for ; Fri, 10 Sep 2021 16:05:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbhIJQG7 (ORCPT ); Fri, 10 Sep 2021 12:06:59 -0400 Received: from mail-mw2nam10on2051.outbound.protection.outlook.com ([40.107.94.51]:21211 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229970AbhIJQGy (ORCPT ); Fri, 10 Sep 2021 12:06:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=El/iLtrs8NtOX+P7O+gE1AcoPJvwmaN/ura8aJmef1tBLMe3qs1+sNGkYIb48IvPr9sIkNoz6GFLF3uyCtthdPTUT0gpEJYwt6z+8sfQpTyOJQ1F+vXe9IDHSwAZE937BH+ZBf9qeq9fw/Vr4fOMU6yzUH59ldLsm4+dLHoYlO1MJr/sF1V2E/uskcOWyMZ65aE8unlGAr+XdMcsxUBdDJHmmC6PGe5CK1jYJ6rI7rJ4EtUoY47PlTvyED0rVD5ZPIuTVfHjCOV0dNYzWYlGxK6s72O1vQ69Ah0Dug3NEcKkcVud2DBIDXKPJZEmpEvH4ckpuiXB1BwNvDop6PYMKQ== 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=W9JLdsVznNuNAoPM1SGeRUS+0cTJdatTs8EuWKKVI8UKJzKzDU/RbCJvG0u2xTM2SUJ5l78Jzka/ApULEJD2Cz/x/yQI/pU8z6eQD04nmVBtnCpGmy8qjWn4ZEUJ5HgQKOFNhOiRljvUpkZ8FK+CmI7hbiuGckM2Mbk7Q0YWHeHbHyj4vwaxeQxrA+4ZBvv2XeCagnmr59OQPHKb5dvWjWyvtZhGqDTGwQL2F63pzrH9OUERRBg2b1Ir8y1z/HeZoBvr74JNv22vA7/CQfgU9UL8Y1pcdW1ZuHFDYIuxjO4zJMygpEAYKNwcDaR43nWnjN3+Oya+BKlsdmCnzOkiGA== 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=Vn4LEQMwWBx/eeqD7feUfNvYIU5zn2SlDNOow0DF2Ukwj31/NWfj1CAvaDd7E9f14YzLT4WJr5eMG6jVGQriH9zZovQMdDZb6ZfCt3oLvfOQNd2aC69S3UdK95igIUiXsXwb84VHfm8J5c7XcckmFZn1+Bxj3dzylev+eYvwsyI= 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 SN6PR11MB3118.namprd11.prod.outlook.com (2603:10b6:805:dc::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Fri, 10 Sep 2021 16:05:42 +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; Fri, 10 Sep 2021 16:05:42 +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 05/31] staging: wfx: avoid possible lock-up during scan Date: Fri, 10 Sep 2021 18:04:38 +0200 Message-Id: <20210910160504.1794332-6-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910160504.1794332-1-Jerome.Pouiller@silabs.com> References: <20210910160504.1794332-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SN4PR0601CA0006.namprd06.prod.outlook.com (2603:10b6:803:2f::16) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 Received: from pc-42.silabs.com (2a01:e34:ecb5:66a0:9876:e1d7:65be:d294) by SN4PR0601CA0006.namprd06.prod.outlook.com (2603:10b6:803:2f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.15 via Frontend Transport; Fri, 10 Sep 2021 16:05:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 215922e0-ecfa-4306-9ec2-08d97474d6a4 X-MS-TrafficTypeDiagnostic: SN6PR11MB3118: 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: lpwAP9rKYXBfSvOjXC8zPqYCBu3dbcfzftEnMjAIiYLS2bLViJnu9JXZEpO4od6tPI7SgOU12rCoqwjIqTIVOT4bioaM7FTswceCuin6XbGRXLM/bz5mxtx5HcQNVUrATdMgicOjvnPz0sc48n8OBisOgHNnPlPPyEEkPq0CmOvveuVf2LVgS5wgOFor2N0nPNXz06KSJhq5Oi7oYXEDVxz7mN5yBNPWsImHVFN8zB2wZjY6kzbkaMQdYv5CEdfITr6QH8BRS+zDchquLsb4a9m1YuajEV9WqIWp5HxOq7jN7PynuD0yzMHZGgwZMl1vn8TvIwMDDcUul0M2o//3HufbHBrmm0GLymkSvsnTngXzTj5Jo88CfqwapYQAxas/B3+wzapWiXFbDgx40c6Z/8FldS8fNya3M6qcwWJWIgkTWLH09lnR7RsGUB+VSXxmH1HaQ5sgLEL5ljRu2tAygUN7auwrdWOqiGtkGqU8AL3g5Fy5u7HKWNUsAbPcjMBDpyXWaqT8mAf17ErzwKupUwq5a7V9KEyN3nqLV+nHZ0Mtt3bB1FjocuIdBDAjuo9bw+Cudo76T1ZuZJcUsS/6Ox2xgKC/JWSbV8aQh+L1CWRI1J1S1l+EeAbIFP9Fd4DPqkini4rRGpfSE0t0c4HJDA== 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:(136003)(366004)(376002)(346002)(39850400004)(396003)(4326008)(66476007)(107886003)(36756003)(186003)(316002)(6486002)(66556008)(8676002)(86362001)(2906002)(54906003)(38100700002)(83380400001)(8936002)(66574015)(5660300002)(66946007)(1076003)(2616005)(52116002)(7696005)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?V0YAKP/LT9qunGSjoKjJZLXKU?= =?utf-8?q?OP7pJLJ8U1A+0+jLghE0x50wbjf9HlMRCtjjnMLhZnldBjMPGF5hFpeZ?= =?utf-8?q?hKMV1dM65UQGmW0A/FpgpZRLw+c7H0C8k8AqAyQVJ00iTHXzikrTw3eg?= =?utf-8?q?xcXjpSYOJRbtHGa7fXmpNNTp2pEykqifWX1EZyTojotH8qjGEbhlJCu2?= =?utf-8?q?cKYTN/VqY7JC/3EkI/PMzHc3Cw2l2LX827T+G75NPy7jIObWQKPFANko?= =?utf-8?q?sJlH8Z8maJ+EMDlBZTMYNg9FQuv9nBDssblHGB2qJXmrNpE2Mp6jDbD1?= =?utf-8?q?7eN0qIPcXCXX1p2L1/FXhz6927XeSAO7KZh7GHlzHudQ2nm7EoLUqk9q?= =?utf-8?q?AGAAC8n/2wyQLCittAFTCLSI449Qms1C7qk7sRZzQzVS6wlLe2BrrXG1?= =?utf-8?q?Xbglr1Lme8F9esVulPNW+PRELeuJ2i9xPWq15YYPwlDf5imPGW3up8lu?= =?utf-8?q?8c+yBiUCLToY7qf/4FbRg9YsKpvBOI1ou0RPTTcX4nYHmQX/UriRvgn1?= =?utf-8?q?rzLsDHlqvL/mJ050n0PSIrXx8dBkQBvjezA/YwYuaTjKFPpmTTv4zalO?= =?utf-8?q?2Tkfe379ndpLtDImm0FGle9Xte+ndXK2DtFBBw8BPGuoAt1TbOdGb5j3?= =?utf-8?q?wjXMxlsTWyqt3CspMVlSVT0YnFHdLJ/fJYkA2EqOYLRatI5xXGoJTbY5?= =?utf-8?q?NQKb3A2cMu4A113ccZhB+5FkMprdPiwQwxssuiTRXD/wI10C/AT6LNGH?= =?utf-8?q?JDB6Q6Ei0a+dW8oP27Ydds/0w/Gwq5JpF2ngwzrjDaTcGFDpn1SKLXr5?= =?utf-8?q?Pv6K3RFBkGsERIOHugtPQfVmuiJZnlosNCnWMOu0dPGMkjn3BpGd+mVp?= =?utf-8?q?gqKZZpqliwQJ32pj+omyyRVpcgKnWXCMQGssaaTRLg1k73l4EJWmAGAS?= =?utf-8?q?1jZ7l9RTZ1v/YvZcyGODQC9a9C5pH8rkuegRUf9UNUrDAfI//3Txx6DV?= =?utf-8?q?UCcyFPvoyyJOYonKyZaUxEXBI2eZAFO3n6L6qfTzEOSashnoUy0u9hB4?= =?utf-8?q?vg9khqpaPXWwHT2OwjsWOtr8zuiXkUsZ/2pkX+xtMWBGFadvUCTu0Nhy?= =?utf-8?q?UEm66DAkhI5/0tdPAy1gMogqGXgH6FlL9Is04tIR/OdG83rzP5/4ex43?= =?utf-8?q?SrFiZPU8PELTIFnAqN+2DvB02IOdqtHmo1zgdkUsTei3BNj+0VPuIUyA?= =?utf-8?q?ljJIl57+v929QmXtTSRv7cDbR0C6zlEzF2HsckS4Lj3nT3J/nNp76Xdg?= =?utf-8?q?3Yn2NdWLzKbKK89LEi7I0C6HtbYqLc5wVHR2/T4nmzdnd8gmyM25ez0Z?= =?utf-8?q?+Vyk9OMX9dI+2AV0Ba1R6jVw3jv4AdoUy0tSm/DcfQhDb91xwCshfOPX?= =?utf-8?q?9j5TjqYUsbASyFMRiFgjRDmeQWzt4tsRlX0De/6?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 215922e0-ecfa-4306-9ec2-08d97474d6a4 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2021 16:05:41.8845 (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: OO0+cSX6oQqH9onHKCW4QFtYJ54S89LMRo6NtFY0TVkzYkY7OW7x/fG405XecJ6KaHO3KoTXFjA8ol2buT/RPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3118 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;