From patchwork Mon Sep 13 08:30:17 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: 511654 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=unavailable 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 70205C433FE for ; Mon, 13 Sep 2021 08:32:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53C2160F46 for ; Mon, 13 Sep 2021 08:32:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238193AbhIMIde (ORCPT ); Mon, 13 Sep 2021 04:33:34 -0400 Received: from mail-dm6nam12on2050.outbound.protection.outlook.com ([40.107.243.50]:38689 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238170AbhIMIdI (ORCPT ); Mon, 13 Sep 2021 04:33:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ilp3HjAgrY5ljD5SZ5cfiG8Wm/A5kFqEqkqk/FWnBPftKO3Cn3iGiq28haxbOCj/4unBhBhhp1p6EJJJKZPgmVMFqabyJyix19x/wxoX9SjXp0mRcbErHTpk07s8P817nxZteYJeiTUnRw8jLn6iohdisAhhMZ5qOGYTuSHbR7d+DDBq0F5Xiij1uxSYdgFlT1HdzIxekYVpYuirmxyxPr1NtR7iT5NUF9dLieFlpO9MLz0PLDoUMKcLS18zz+H9A2k9jEDnBQm2vse3CvKcxuGsiDWPOT/pWUAvZRt4KZO4/816ZYq36bbeaVSI4/i4xS1kcgDd5IFWC6bVyf5hRA== 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=E9KVQX3XEE9y0fFYXy0bycch7Kq3RJrvEUags/dMGwUHEzu3LKpJUfp40SjrzQlkZ3oeMeDq9fPkFA2Exc51KL7wfXY53AD/A8roCDVR0Atb2NwVMpxLATrl60gJ9sc7qTQgJAyhu99FtHHS2/jZYjRPCxvjyn7dMhC6pv+wEuBjEFlnRMOawVM7egbkKVVacQDsYiacqP9icFxlQ9k9vGF23yxsFqaSkB5OL2ivcxJ+uIlAN+s5nPzFIiutjw4o5efwvARdSxkQBx3rrfbz+gttN1P3Sff1XIddCiXlSLp97NPEDJh3JJTZv/QY+WPqolKg8r1oov06PpoV4/Sy6g== 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=WLr81SGJrxXzF6giap1tXR1cQd2NM+Zp5Fh2FjJ2bcVZn3NGdggzHFGWnvUprC4g56CrHpZ4sdPnZFesjAKKDC11wTOTWhT+jRtlSOh4fzy/Ay8f9jB0pe4nhLHwMjoK9Qor3VA4ESfRxqYW2LnMGMExI1HXVHRI8sem3zNGNHs= 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 (52.135.97.18) by SN6PR11MB3263.namprd11.prod.outlook.com (52.135.109.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Mon, 13 Sep 2021 08:31:12 +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 08:31:12 +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 v2 05/33] staging: wfx: avoid possible lock-up during scan Date: Mon, 13 Sep 2021 10:30:17 +0200 Message-Id: <20210913083045.1881321-6-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913083045.1881321-1-Jerome.Pouiller@silabs.com> References: <20210913083045.1881321-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PAZP264CA0067.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1fd::10) 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 PAZP264CA0067.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1fd::10) 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 08:31:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 33627f58-8ed9-4364-51fb-08d97690d84c X-MS-TrafficTypeDiagnostic: SN6PR11MB3263: 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: 1AhPcYg0ZLaSU+HY5GgaGWBF5wP02Gn+42n8GzJI/4V3kT9gQNXYjMzPj3arfVSgfZS8+76EtVa7cwPWLQKDIENXPEufs0m41di+1TjdLgGGJ+nX0NoujnXop2yr9lJuiGwLpffQbz+lxJkK9tJ7t2p+P6viQOaL0OE0HOcvau+JNAryPtQhSFIKTuCctvQIDr746hzwVm5K77CDdG9h3PvZeHFgQQ78pvoHPOTAt+IziM4ajxik20YiQ/Ha084xzKHNpimfertehZPuSm2wZQ9khY6AhRf9SZLoAu5znQ097PCSYO9AFBxo5CofQIpKhtT7/wFZ+0FVG3h+HDCQFvDpAv5FBeBCgA4+uxPoFyh3YDFz96oTVrTU35DF6QUix3PoRnZeJ0Us1RamD8gtt6x37W7rjIOv1va39QnWu3uZAgQW3tiIH0g8E9QgbvgeOFZhXEFSZiXDGstputgRLOqOY+cZOZmP6q/QdPalemdplH8wGC1IBLFf1TTvVuoxAJyRFIscaU5sxk29MMVqpxxNRmjNFKQEe0UAL8Xpil+iwXwbMRkeMgjkQa70eOYqMxULY1kcM4iJfYQ+7w3DC9liuPOtOGL1ya1hNzAgLiUMfIdhY0CV0IqgDa/YM1EMAvcjMwMcXeY5Iv1BZAXrU6ESm1X+f2E4rQaEfDd4Ygw+mNv8ZlaYjmBtrR92qmhKjcZx16cnAAnanxD405p+rQ== 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)(83380400001)(66574015)(107886003)(956004)(2616005)(5660300002)(54906003)(38350700002)(4326008)(316002)(38100700002)(66946007)(26005)(66476007)(66556008)(186003)(8676002)(36756003)(8936002)(86362001)(508600001)(52116002)(7696005)(6486002)(1076003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?gzWkiMdJpRLS6kd9RZL5IGbde?= =?utf-8?q?bKzdckhoeWxarsCVWWifaK+ah5X7GSZZlFmopzm6TExVTeGhvl0ytQ48?= =?utf-8?q?D0z9Dg4z3miiHwFFfdJYcwc0aknZ83dq+VxxE5y/1Vk4sdNrLhyYoavl?= =?utf-8?q?bry8cNbI5cdkaI65AhLfH/+CwexKfikfgL/VCMEvLn1K4lXKjFBHFUGT?= =?utf-8?q?CEmFs48sJAlIpx3Xg1KWFpK/Fn0fadSq3WEhY7p9YsQEpsm5uUKajOns?= =?utf-8?q?mgLR1SFNtDgePy8pH33MuoPEaFc7jnu9PHmPHr5zIdk5w62eIq1ClUwZ?= =?utf-8?q?skSIW1BNKwfM4xqFKh7aQPrGATaKMQoIrrL6NUMeV+VYDfa5/JibouAI?= =?utf-8?q?XgzAgg84BVc4xfufKqdm65SmoBuIKExDZLdBB8IpSjHttU2v7PUfFqJz?= =?utf-8?q?WKJIyCfpcl67ehhcaHhLrP2Nmvot8J216S8JjUgvHpZeoMF1t5TTkc04?= =?utf-8?q?27Asv7QiC5bpxhLK0MKCBBf/3atNrpvhN1i1goOezCfk/wRzliQtYqxW?= =?utf-8?q?Q1dtY+Z2JWHIRK4em+QVM3+SLo5zcCV37aWRV0+ImOwA8SSTl3OpqdL9?= =?utf-8?q?H+wWO2LmiksEsBBzZNaC68wDupsydgTz+4XZ2NpJjhRBHygG+CPFQSj9?= =?utf-8?q?CU9eom0AOqRqgF/Nyh90WzshH+tNcIFcRH/Akx8NZJdtrkY6EEO0Y8HR?= =?utf-8?q?u5qwr9gG5DRHc7IPPsHOLe57kIWEXsjn51m1fdLKeye/OHF8xc/yW3IK?= =?utf-8?q?1ojqn0AsNewCcJ+4NDEWb9wIE95YhNqJh18IA4XmPSgH9i/KqA+StJDx?= =?utf-8?q?ZhjVhBu+AeQQyHReJZO9TmGrltn1pdVSO5tshNI5zoSghMRn3LFcsT5O?= =?utf-8?q?i8jyZNOD/DVvKR4mZHRgtlSlxnIl95pb3hq8ubmvPQkF/sX30FgV+eSC?= =?utf-8?q?w15KCV8Yvz1pZGXk0GYLFhHx0YtoZ2WPgJ3uBCblYzwE1x/ntHKkz/nl?= =?utf-8?q?ISSPJbBmGZ74eaU9vlqGrj2B/aQVYIocq09N4MQyNlmQCNc2Re4c3FD4?= =?utf-8?q?6FNrRTiDkC1NEY5R3fL32+J5EqB0/MYquMtNKgjbMSIP7wAOrVbV3TFG?= =?utf-8?q?+2F5HhrL1mLVsTlJv8i/siTVkiGAI/a/O1Zm8zwjk4VODEE7LSDG4S2l?= =?utf-8?q?tumsvI6R2PcefZ/3l9fXwCrSacFSZF/B6BE0lufwisJuKRQ33hm2k8zk?= =?utf-8?q?hRL0Op7FbpvCPHvJXYcmZlNxICxCwn1J6UwgV2zmida/MvaUyRH/30uS?= =?utf-8?q?gxvMNz/n+r3WyHLZphg/R/NB/L96awcjX2zZGn+ELawvndySB+tkqmFh?= =?utf-8?q?kZ1NeUN3BVA7Ffl9HPtLWlslG31qfMH?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33627f58-8ed9-4364-51fb-08d97690d84c X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 08:31:12.7523 (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: wdjAf/f6koxGsCCYwSWQP/DstXK5KC0wHcgfD9LCs8+cnm93pddYpllwNHDpFUB++4nm+0/fBgDCPv++Os/BPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3263 Precedence: bulk List-ID: X-Mailing-List: netdev@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;