From patchwork Wed Jul 10 17:37:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Matyukevich X-Patchwork-Id: 11038787 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBEEF14E5 for ; Wed, 10 Jul 2019 18:10:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB7992869D for ; Wed, 10 Jul 2019 18:10:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF872288ED; Wed, 10 Jul 2019 18:10:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 1172A2869D for ; Wed, 10 Jul 2019 18:10:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727377AbfGJSK4 (ORCPT ); Wed, 10 Jul 2019 14:10:56 -0400 Received: from mx0a-00183b01.pphosted.com ([67.231.149.44]:24254 "EHLO mx0a-00183b01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727193AbfGJSKz (ORCPT ); Wed, 10 Jul 2019 14:10:55 -0400 X-Greylist: delayed 1987 seconds by postgrey-1.27 at vger.kernel.org; Wed, 10 Jul 2019 14:10:54 EDT Received: from pps.filterd (m0048105.ppops.net [127.0.0.1]) by mx0a-00183b01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6AHa78q030265; Wed, 10 Jul 2019 11:37:41 -0600 Received: from nam03-co1-obe.outbound.protection.outlook.com (mail-co1nam03lp2053.outbound.protection.outlook.com [104.47.40.53]) by mx0a-00183b01.pphosted.com with ESMTP id 2tnhmy8f5k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 10 Jul 2019 11:37:41 -0600 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eyyC/Y7B8rX2GY/rjQWam5gwizh9HeOxEmEbAVLp8jDS3LHDO02hBYPowNRTsEypUW/Qm4Wqn7EGNbHt2IYynXhe/f0aXkNI5UkPMNYFzKVySVAtkQ6KirRNOfdz+FdLn+B8GfV+JuUjbSiuQH6MiAYb7xuO6XVHLepRpgLQhY7v3KqtJo+CpazgobbilqxyUZWTuSYftTI7P6wzJQgdqrFGVwXJfunnfa1nrrNCR+/bOOlUJn5MCHraF+loPwJLRZhsZv7TZNhWsHrmfCiXgSR+Cj8WST2RT/W9Wc9OWu5FIEwYiSDIpv2PORIM7zQYNRWxTsCCeT30a+In2MWjAw== 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:X-MS-Exchange-SenderADCheck; bh=crcaJrwB69uZ+h0VncsQVmMCkx1ycPBis7K0y8HUYc8=; b=gDNy+GKpcH2aFuuP6XxZO1YAG+Nm3mIbEYYsBqTO5L85ntODpXhr3Gr96uzHKx7Xs9dh01VL7OsUhHSx+m0C604Umb6mwfxusx7Wqvq6wZszjpy+asM2YYF1Tnk8beSdq2Ae2Tcbx7KQpIwnY/ubpXrVdiEeylCCXtza/3qJ3TU3tIpD3o7tsQVHvZgrVYcIaoZxXXTaMISNkLRbXqbXb57KvFT0dtVDqz7KY9gFvU6b4zIL6uLun5hJp6dnqa+VwiNJiM45zqw4lizOKJ5aZT6oaabn/kNr9qiF9PI/wUmA4ohL+tQgHSAYT4Bg6Wjn6wuEt7bNcm25BjJYemwyBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=quantenna.com;dmarc=pass action=none header.from=quantenna.com;dkim=pass header.d=quantenna.com;arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quantenna.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=crcaJrwB69uZ+h0VncsQVmMCkx1ycPBis7K0y8HUYc8=; b=bn5/+xmB9SGIUZzs9JGIZSYAKtI++PZSRLfoAb6UfuDW8SJUMcz7dQnTyxveZ+Xj/tDSk8BYG95CraNNgCqYou1wJX1TaU0EkmbwzuGy2/SUPaunGLzsdQMyLmRIFzP16Y2wkRD9qY6TKZXEqxKoncRlQ0B1ICxaqbffmmyvKaE= Received: from DM6PR05MB5273.namprd05.prod.outlook.com (20.177.223.225) by DM6PR05MB4505.namprd05.prod.outlook.com (20.176.78.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.10; Wed, 10 Jul 2019 17:37:40 +0000 Received: from DM6PR05MB5273.namprd05.prod.outlook.com ([fe80::d571:4322:69c3:86e7]) by DM6PR05MB5273.namprd05.prod.outlook.com ([fe80::d571:4322:69c3:86e7%7]) with mapi id 15.20.2073.008; Wed, 10 Jul 2019 17:37:40 +0000 Received: from SN6PR05MB4928.namprd05.prod.outlook.com (52.135.117.74) by SN6PR05MB5200.namprd05.prod.outlook.com (20.177.251.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.10; Wed, 10 Jul 2019 17:37:04 +0000 Received: from SN6PR05MB4928.namprd05.prod.outlook.com ([fe80::13f:5819:79e7:ea8f]) by SN6PR05MB4928.namprd05.prod.outlook.com ([fe80::13f:5819:79e7:ea8f%5]) with mapi id 15.20.2073.008; Wed, 10 Jul 2019 17:37:04 +0000 From: Sergey Matyukevich To: "linux-wireless@vger.kernel.org" CC: Johannes Berg , Igor Mitsyanko , Mikhail Karpenko , Sergey Matyukevich Subject: [RFC PATCH v3 1/2] cfg80211: refactor cfg80211_bss_update Thread-Topic: [RFC PATCH v3 1/2] cfg80211: refactor cfg80211_bss_update Thread-Index: AQHVN0YUhHXBofQCAUidYlGg48NfoA== Date: Wed, 10 Jul 2019 17:37:01 +0000 Message-ID: <20190710173651.15770-2-sergey.matyukevich.os@quantenna.com> References: <20190710173651.15770-1-sergey.matyukevich.os@quantenna.com> In-Reply-To: <20190710173651.15770-1-sergey.matyukevich.os@quantenna.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR06CA0028.namprd06.prod.outlook.com (2603:10b6:a03:d4::41) To SN6PR05MB4928.namprd05.prod.outlook.com (2603:10b6:805:9d::10) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.11.0 x-originating-ip: [195.182.157.78] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a0a4892f-9b5d-4fed-08ba-08d7055d36fc x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:SN6PR05MB5200; x-ms-traffictypediagnostic: SN6PR05MB5200:|DM6PR05MB4505: x-microsoft-antispam-prvs: x-moderation-data: 7/10/2019 5:37:38 PM x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0094E3478A x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(979002)(366004)(136003)(376002)(346002)(39850400004)(396003)(189003)(199004)(66476007)(1076003)(66946007)(52116002)(64756008)(2351001)(66446008)(66556008)(14454004)(53936002)(66066001)(6506007)(6436002)(71190400001)(71200400001)(2501003)(6916009)(5660300002)(386003)(102836004)(68736007)(25786009)(5640700003)(86362001)(6512007)(3846002)(81166006)(316002)(2616005)(36756003)(11346002)(14444005)(256004)(436003)(8936002)(103116003)(26005)(50226002)(478600001)(2906002)(446003)(8676002)(4326008)(76176011)(6486002)(476003)(305945005)(54906003)(6116002)(7736002)(99286004)(81156014)(486006)(107886003)(6666004)(186003)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR05MB4505;H:DM6PR05MB5273.namprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: quantenna.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: efWtM0zOgaJnzv5YkxMr+pcHJLQcWavkCzGZtab+bo1Kk55Iz0EhSNrDjDydMecl51WZPZvwQhvWJB6bUcYWpi7Jsqss3Ty1AdKKgaj2KyMnPYEvYbgxv1LkfszS5OLjip3xfPGJ3WEFCMdGjXexHUffc3P2uiTnUJUzLxS1KOMIfZbahOJsnHszSF4R9cFXloc4j1lAHDXQxQEFSy/k6E8CYKeA3fY6l0wWshqw0MsCXuVo60XJ3HHAB2e61zx6VELojqBox5ZXPSlEA9ijuk5BkrnT/m2qtM7T0BS4ej/E0eGzsOLCSrL7tjtcvc8AmcjTBBYuZUYLp40TM9n/4yqsqljtd6NgUVrdIh+VWZKjsJay3z79OV1JzepZGOEeHT78xrCMXsvlfq1zLeJBP9VjEbbTYC96zMrmgJgs1+o= MIME-Version: 1.0 X-OriginatorOrg: quantenna.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0a4892f-9b5d-4fed-08ba-08d7055d36fc X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a355dbce-62b4-4789-9446-c1d5582180ff X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SecureScore_8b3391f4-af01-4ee8-b4ea-9871b2499735@quantenna.onmicrosoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jul 2019 17:37:40.1650 (UTC) X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR05MB4505 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-10_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=974 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907100198 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 This patch implements minor refactoring for cfg80211_bss_update function. Code path for updating known BSS is extracted into dedicated cfg80211_update_known_bss function. Signed-off-by: Sergey Matyukevich --- net/wireless/scan.c | 171 +++++++++++++++++++++++++++------------------------- 1 file changed, 89 insertions(+), 82 deletions(-) diff --git a/net/wireless/scan.c b/net/wireless/scan.c index d66e6d4b7555..9f21162f05e9 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -1091,6 +1091,93 @@ struct cfg80211_non_tx_bss { u8 bssid_index; }; +static bool +cfg80211_update_known_bss(struct cfg80211_registered_device *rdev, + struct cfg80211_internal_bss *known, + struct cfg80211_internal_bss *new, + bool signal_valid) +{ + lockdep_assert_held(&rdev->bss_lock); + + /* Update IEs */ + if (rcu_access_pointer(new->pub.proberesp_ies)) { + const struct cfg80211_bss_ies *old; + + old = rcu_access_pointer(known->pub.proberesp_ies); + + rcu_assign_pointer(known->pub.proberesp_ies, + new->pub.proberesp_ies); + /* Override possible earlier Beacon frame IEs */ + rcu_assign_pointer(known->pub.ies, + new->pub.proberesp_ies); + if (old) + kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head); + } else if (rcu_access_pointer(new->pub.beacon_ies)) { + const struct cfg80211_bss_ies *old; + struct cfg80211_internal_bss *bss; + + if (known->pub.hidden_beacon_bss && + !list_empty(&known->hidden_list)) { + const struct cfg80211_bss_ies *f; + + /* The known BSS struct is one of the probe + * response members of a group, but we're + * receiving a beacon (beacon_ies in the new + * bss is used). This can only mean that the + * AP changed its beacon from not having an + * SSID to showing it, which is confusing so + * drop this information. + */ + + f = rcu_access_pointer(new->pub.beacon_ies); + kfree_rcu((struct cfg80211_bss_ies *)f, rcu_head); + return false; + } + + old = rcu_access_pointer(known->pub.beacon_ies); + + rcu_assign_pointer(known->pub.beacon_ies, new->pub.beacon_ies); + + /* Override IEs if they were from a beacon before */ + if (old == rcu_access_pointer(known->pub.ies)) + rcu_assign_pointer(known->pub.ies, new->pub.beacon_ies); + + /* Assign beacon IEs to all sub entries */ + list_for_each_entry(bss, &known->hidden_list, hidden_list) { + const struct cfg80211_bss_ies *ies; + + ies = rcu_access_pointer(bss->pub.beacon_ies); + WARN_ON(ies != old); + + rcu_assign_pointer(bss->pub.beacon_ies, + new->pub.beacon_ies); + } + + if (old) + kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head); + } + + known->pub.beacon_interval = new->pub.beacon_interval; + + /* don't update the signal if beacon was heard on + * adjacent channel. + */ + if (signal_valid) + known->pub.signal = new->pub.signal; + known->pub.capability = new->pub.capability; + known->ts = new->ts; + known->ts_boottime = new->ts_boottime; + known->parent_tsf = new->parent_tsf; + known->pub.chains = new->pub.chains; + memcpy(known->pub.chain_signal, new->pub.chain_signal, + IEEE80211_MAX_CHAINS); + ether_addr_copy(known->parent_bssid, new->parent_bssid); + known->pub.max_bssid_indicator = new->pub.max_bssid_indicator; + known->pub.bssid_index = new->pub.bssid_index; + + return true; +} + /* Returned bss is reference counted and must be cleaned up appropriately. */ struct cfg80211_internal_bss * cfg80211_bss_update(struct cfg80211_registered_device *rdev, @@ -1114,88 +1201,8 @@ cfg80211_bss_update(struct cfg80211_registered_device *rdev, found = rb_find_bss(rdev, tmp, BSS_CMP_REGULAR); if (found) { - /* Update IEs */ - if (rcu_access_pointer(tmp->pub.proberesp_ies)) { - const struct cfg80211_bss_ies *old; - - old = rcu_access_pointer(found->pub.proberesp_ies); - - rcu_assign_pointer(found->pub.proberesp_ies, - tmp->pub.proberesp_ies); - /* Override possible earlier Beacon frame IEs */ - rcu_assign_pointer(found->pub.ies, - tmp->pub.proberesp_ies); - if (old) - kfree_rcu((struct cfg80211_bss_ies *)old, - rcu_head); - } else if (rcu_access_pointer(tmp->pub.beacon_ies)) { - const struct cfg80211_bss_ies *old; - struct cfg80211_internal_bss *bss; - - if (found->pub.hidden_beacon_bss && - !list_empty(&found->hidden_list)) { - const struct cfg80211_bss_ies *f; - - /* - * The found BSS struct is one of the probe - * response members of a group, but we're - * receiving a beacon (beacon_ies in the tmp - * bss is used). This can only mean that the - * AP changed its beacon from not having an - * SSID to showing it, which is confusing so - * drop this information. - */ - - f = rcu_access_pointer(tmp->pub.beacon_ies); - kfree_rcu((struct cfg80211_bss_ies *)f, - rcu_head); - goto drop; - } - - old = rcu_access_pointer(found->pub.beacon_ies); - - rcu_assign_pointer(found->pub.beacon_ies, - tmp->pub.beacon_ies); - - /* Override IEs if they were from a beacon before */ - if (old == rcu_access_pointer(found->pub.ies)) - rcu_assign_pointer(found->pub.ies, - tmp->pub.beacon_ies); - - /* Assign beacon IEs to all sub entries */ - list_for_each_entry(bss, &found->hidden_list, - hidden_list) { - const struct cfg80211_bss_ies *ies; - - ies = rcu_access_pointer(bss->pub.beacon_ies); - WARN_ON(ies != old); - - rcu_assign_pointer(bss->pub.beacon_ies, - tmp->pub.beacon_ies); - } - - if (old) - kfree_rcu((struct cfg80211_bss_ies *)old, - rcu_head); - } - - found->pub.beacon_interval = tmp->pub.beacon_interval; - /* - * don't update the signal if beacon was heard on - * adjacent channel. - */ - if (signal_valid) - found->pub.signal = tmp->pub.signal; - found->pub.capability = tmp->pub.capability; - found->ts = tmp->ts; - found->ts_boottime = tmp->ts_boottime; - found->parent_tsf = tmp->parent_tsf; - found->pub.chains = tmp->pub.chains; - memcpy(found->pub.chain_signal, tmp->pub.chain_signal, - IEEE80211_MAX_CHAINS); - ether_addr_copy(found->parent_bssid, tmp->parent_bssid); - found->pub.max_bssid_indicator = tmp->pub.max_bssid_indicator; - found->pub.bssid_index = tmp->pub.bssid_index; + if (!cfg80211_update_known_bss(rdev, found, tmp, signal_valid)) + goto drop; } else { struct cfg80211_internal_bss *new; struct cfg80211_internal_bss *hidden; From patchwork Wed Jul 10 17:37:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Matyukevich X-Patchwork-Id: 11038773 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44B68112C for ; Wed, 10 Jul 2019 17:39:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34A6F28965 for ; Wed, 10 Jul 2019 17:39:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 291FF28985; Wed, 10 Jul 2019 17:39:23 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 75A2428965 for ; Wed, 10 Jul 2019 17:39:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727503AbfGJRjV (ORCPT ); Wed, 10 Jul 2019 13:39:21 -0400 Received: from mx0b-00183b01.pphosted.com ([67.231.157.42]:51788 "EHLO mx0a-00183b01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725911AbfGJRjV (ORCPT ); Wed, 10 Jul 2019 13:39:21 -0400 Received: from pps.filterd (m0048104.ppops.net [127.0.0.1]) by mx0b-00183b01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6AHWWJw023717; Wed, 10 Jul 2019 11:37:36 -0600 Received: from nam03-dm3-obe.outbound.protection.outlook.com (mail-dm3nam03lp2051.outbound.protection.outlook.com [104.47.41.51]) by mx0b-00183b01.pphosted.com with ESMTP id 2tnck410h6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jul 2019 11:37:36 -0600 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CeRYOdNbJv9yv85NMGNdIMf/sucd1MRnAK/b+7iDCuQ///wov4LtdfqgVndSIW2/npLx3HjRUuJRKylCYil/lFhJ7IsB1TU699T6PyfEgndhmotmin37N3NTJIXJF0jfLmeZ8FSRSm/BZXGwIyU6J3shcwyjK0B80fIfIk5BeNfk9wSyGw5D5T+rCEYlMqy4YQUA4KWHwRBvUD6ILoDmaKujI8gU41WhvkS3C9XWQ6PTDRB8xWIy0Y1cmAJJO+yztLb9rMxSipfQlzK8aNW8vpgKSc06yN9eFqW1mBRsLukzYVybYSpQzrSRxpOr7UKfq0Np9BmiksOb/QXpqkgY1Q== 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:X-MS-Exchange-SenderADCheck; bh=0Ubs+/W26U+is2yUlzCPUBN8kl+9QVqYmoNo/WH9Aas=; b=BcxthykLflXcCBN0gzDvGKHjvXFsF5cJe0KjP/BTqf7mEy3PftVGnP05aYjy4GnZyZu2vl7ACfsi1JF536T/rQTqqZtS6ibcxaxnDgpyRJEkff6SESvWzXZGUXrvI2A3jgKeIqLW1OghEg6PZM3rUGdpT/gDKMdOLD/h3qrvfapaEqgjnRC7JoJsPQFEmB9AbNAPlSseHFXrzMUKZf5Mo8Ged/ivJjHYYMuo7VeTS5J+RLp+szLV/UezRlEKRmUcoWkV7AiFsmKTqbpqKV0Eots3Vk0oEfVFXYK7Nfiz5mW1lJrcBB6adEPXQc+K0LfjGoh2iTBLbukJEjo0UBjFlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=quantenna.com;dmarc=pass action=none header.from=quantenna.com;dkim=pass header.d=quantenna.com;arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quantenna.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0Ubs+/W26U+is2yUlzCPUBN8kl+9QVqYmoNo/WH9Aas=; b=J2SRHsy3mCxXk8G4eK6Cc0tNr+LkUKF6weXadUDb5IsfXfSRaUOXDTAf/u+22cnyXPBNSQK3Ka48SFpNZbgVSYfaWVZJyB0xsGi5e2hE4SkLs+Q8DjZDKvn8sA3hAMqJLAV/65j7Nv92cVIbjOrPbqHn20XUN1r1vnLgi38PMMg= Received: from BN7PR05MB4163.namprd05.prod.outlook.com (52.132.220.23) by BN7PR05MB4355.namprd05.prod.outlook.com (52.133.223.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.10; Wed, 10 Jul 2019 17:37:34 +0000 Received: from BN7PR05MB4163.namprd05.prod.outlook.com ([fe80::f8f6:ad25:294d:f733]) by BN7PR05MB4163.namprd05.prod.outlook.com ([fe80::f8f6:ad25:294d:f733%6]) with mapi id 15.20.2073.008; Wed, 10 Jul 2019 17:37:34 +0000 Received: from SN6PR05MB4928.namprd05.prod.outlook.com (52.135.117.74) by SN6PR05MB5200.namprd05.prod.outlook.com (20.177.251.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.10; Wed, 10 Jul 2019 17:37:04 +0000 Received: from SN6PR05MB4928.namprd05.prod.outlook.com ([fe80::13f:5819:79e7:ea8f]) by SN6PR05MB4928.namprd05.prod.outlook.com ([fe80::13f:5819:79e7:ea8f%5]) with mapi id 15.20.2073.008; Wed, 10 Jul 2019 17:37:04 +0000 From: Sergey Matyukevich To: "linux-wireless@vger.kernel.org" CC: Johannes Berg , Igor Mitsyanko , Mikhail Karpenko , Sergey Matyukevich Subject: [RFC PATCH v3 2/2] cfg80211: fix duplicated scan entries after channel switch Thread-Topic: [RFC PATCH v3 2/2] cfg80211: fix duplicated scan entries after channel switch Thread-Index: AQHVN0YVdcoRktgdq0CETrSEqiQijg== Date: Wed, 10 Jul 2019 17:37:03 +0000 Message-ID: <20190710173651.15770-3-sergey.matyukevich.os@quantenna.com> References: <20190710173651.15770-1-sergey.matyukevich.os@quantenna.com> In-Reply-To: <20190710173651.15770-1-sergey.matyukevich.os@quantenna.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR06CA0028.namprd06.prod.outlook.com (2603:10b6:a03:d4::41) To SN6PR05MB4928.namprd05.prod.outlook.com (2603:10b6:805:9d::10) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.11.0 x-originating-ip: [195.182.157.78] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 63f3c147-2e99-44c8-9777-08d7055d3845 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:SN6PR05MB5200; x-ms-traffictypediagnostic: SN6PR05MB5200:|BN7PR05MB4355: x-microsoft-antispam-prvs: x-moderation-data: 7/10/2019 5:37:31 PM x-ms-oob-tlc-oobclassifiers: OLM:4941; x-forefront-prvs: 0094E3478A x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(376002)(396003)(39840400004)(366004)(346002)(189003)(199004)(478600001)(8676002)(436003)(14454004)(8936002)(81166006)(81156014)(6116002)(6436002)(25786009)(3846002)(76176011)(5640700003)(386003)(6506007)(102836004)(26005)(14444005)(256004)(50226002)(186003)(7736002)(305945005)(5024004)(1076003)(2501003)(486006)(86362001)(99286004)(52116002)(6916009)(11346002)(446003)(4326008)(6486002)(2616005)(476003)(71200400001)(36756003)(66066001)(53936002)(107886003)(6512007)(103116003)(5660300002)(2351001)(54906003)(316002)(68736007)(2906002)(66446008)(66476007)(66556008)(64756008)(71190400001)(66946007);DIR:OUT;SFP:1101;SCL:1;SRVR:BN7PR05MB4355;H:BN7PR05MB4163.namprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: quantenna.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: VYu/g7ZdHkD+v261zczoQd55r/huSUmO0NTr9ZiSZ6BEGpj2nGxwq4yoQqmAxVJ68Aq7py6qG6+xDeH+m4uIkak9s6tFXp8NroPDX/VsbhLEaiUPQdSborFBAGXoqLjdNPLsbtcme+g5wzHe1bitVaEWRSZC43DVGJMvY3t/Z9yxJQv2CaZI/XVtPP3CFrqapm8UzcbJbWqfHAFmtboL8Y72H04568T9yvQGFQWOgLZ4i/S6Bo708EQ3E60amzp7gxS39FeDZYntRgHLhrBQf+aCJGA/ZRrbfE/FgSlSJ3FZU80ZTRuk4AHrt1eBUuj4Zg8k3663lLno3/sitJHUANjw9UGTCY7PeCeCAm6trk13aGQSED6jNFP+zZcUl+kn4ulLyB9SA1xUkb8h0JDIdL0RJNBYLaIHpEEpUNL5pnk= MIME-Version: 1.0 X-OriginatorOrg: quantenna.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63f3c147-2e99-44c8-9777-08d7055d3845 X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a355dbce-62b4-4789-9446-c1d5582180ff X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SPO_Arbitration_b1a04bc5-0a1e-4230-9ecb-d0ac830b24f0@quantenna.onmicrosoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jul 2019 17:37:34.4774 (UTC) X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR05MB4355 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-10_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907100198 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 When associated BSS completes channel switch procedure, its channel record needs to be updated. The existing mac80211 solution was extended to cfg80211 in commit 5dc8cdce1d72 ("mac80211/cfg80211: update bss channel on channel switch") However that solution still appears to be incomplete as it may lead to duplicated scan entries for associated BSS after channel switch. The root cause of the problem is as follows. Each BSS entry is included into the following data structures: - bss list rdev->bss_list - bss search tree rdev->bss_tree Updating BSS channel record without rebuilding bss_tree may break tree search since cmp_bss considers all of the following: channel, bssid, ssid. When BSS channel is updated, but its location in bss_tree is not updated, then subsequent search operations may fail to locate this BSS since they will be traversing bss_tree in wrong direction. As a result, for scan performed after associated BSS channel switch, cfg80211_bss_update may add the second entry for the same BSS to both bss_list and bss_tree, rather then update the existing one. To summarize, if BSS channel needs to be updated, then bss_tree should be rebuilt in order to put updated BSS entry into a proper location. This commit suggests the following straightforward solution: - if new entry has been already created for BSS after channel switch, then use its IEs to update known BSS entry and then remove new entry completely - use rb_erase/rb_insert_bss reinstall updated BSS in bss_tree - update channel and location in rb-tree for non-transmitting bss entries Signed-off-by: Sergey Matyukevich --- Cover email is not attached to patchwork, so duplicate it here as well... Suggested approach to handle non-transmitting BSS entries is simplified in the following sense. If new entries have been already created after channel switch, only transmitting bss will be updated using IEs of new entry for the same transmitting bss. Non-transmitting bss entries will be updated as soon as new mgmt frames are received. Updating non-transmitting bss entries seems too expensive: nested nontrans_list traversing is needed since we can not rely on the same order of old and new non-transmitting entries. Basic use-case tested using both iwlwifi and qtnfmac. However multi-BSSID support has not yet been tested. v1 -> v2 - use IEs of new BSS entry to update known BSS entry for this purpose extract BSS update code from cfg80211_bss_update into a separate function cfg80211_update_known_bss v2 -> v3 - minor cleanup according to review comments - split cfg80211_update_known_bss function into a separate patch - update channel and location in rb-tree for nontransmit bss entries Regards, Sergey --- net/wireless/core.h | 2 ++ net/wireless/nl80211.c | 2 +- net/wireless/scan.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/net/wireless/core.h b/net/wireless/core.h index ee8388fe4a92..77556c58d9ac 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -306,6 +306,8 @@ void ieee80211_set_bitrate_flags(struct wiphy *wiphy); void cfg80211_bss_expire(struct cfg80211_registered_device *rdev); void cfg80211_bss_age(struct cfg80211_registered_device *rdev, unsigned long age_secs); +void cfg80211_update_assoc_bss_entry(struct wireless_dev *wdev, + struct ieee80211_channel *channel); /* IBSS */ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index fc83dd179c1a..6ebb427883d0 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -16092,7 +16092,7 @@ void cfg80211_ch_switch_notify(struct net_device *dev, if (wdev->iftype == NL80211_IFTYPE_STATION && !WARN_ON(!wdev->current_bss)) - wdev->current_bss->pub.channel = chandef->chan; + cfg80211_update_assoc_bss_entry(wdev, chandef->chan); nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, NL80211_CMD_CH_SWITCH_NOTIFY, 0); diff --git a/net/wireless/scan.c b/net/wireless/scan.c index 9f21162f05e9..30932b955ebc 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -2002,6 +2002,85 @@ void cfg80211_bss_iter(struct wiphy *wiphy, } EXPORT_SYMBOL(cfg80211_bss_iter); +void cfg80211_update_assoc_bss_entry(struct wireless_dev *wdev, + struct ieee80211_channel *chan) +{ + struct wiphy *wiphy = wdev->wiphy; + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); + struct cfg80211_internal_bss *cbss = wdev->current_bss; + struct cfg80211_internal_bss *new = NULL; + struct cfg80211_internal_bss *bss; + struct cfg80211_bss *nontrans_bss; + struct cfg80211_bss *tmp; + + spin_lock_bh(&rdev->bss_lock); + + if (WARN_ON(cbss->pub.channel == chan)) + goto done; + + /* use transmitting bss */ + if (cbss->pub.transmitted_bss) + cbss = container_of(cbss->pub.transmitted_bss, + struct cfg80211_internal_bss, + pub); + + cbss->pub.channel = chan; + + list_for_each_entry(bss, &rdev->bss_list, list) { + if (!cfg80211_bss_type_match(bss->pub.capability, + bss->pub.channel->band, + wdev->conn_bss_type)) + continue; + + if (bss == cbss) + continue; + + if (!cmp_bss(&bss->pub, &cbss->pub, BSS_CMP_REGULAR)) { + new = bss; + break; + } + } + + if (new) { + /* to save time, update IEs for trasmitted bss only */ + if (cfg80211_update_known_bss(rdev, cbss, new, false)) { + new->pub.proberesp_ies = NULL; + new->pub.beacon_ies = NULL; + } + + list_for_each_entry_safe(nontrans_bss, tmp, + &new->pub.nontrans_list, + nontrans_list) { + bss = container_of(nontrans_bss, + struct cfg80211_internal_bss, pub); + if (__cfg80211_unlink_bss(rdev, bss)) + rdev->bss_generation++; + } + + WARN_ON(atomic_read(&new->hold)); + if (!WARN_ON(!__cfg80211_unlink_bss(rdev, new))) + rdev->bss_generation++; + } + + rb_erase(&cbss->rbn, &rdev->bss_tree); + rb_insert_bss(rdev, cbss); + rdev->bss_generation++; + + list_for_each_entry_safe(nontrans_bss, tmp, + &cbss->pub.nontrans_list, + nontrans_list) { + bss = container_of(nontrans_bss, + struct cfg80211_internal_bss, pub); + bss->pub.channel = chan; + rb_erase(&bss->rbn, &rdev->bss_tree); + rb_insert_bss(rdev, bss); + rdev->bss_generation++; + } + +done: + spin_unlock_bh(&rdev->bss_lock); +} + #ifdef CONFIG_CFG80211_WEXT static struct cfg80211_registered_device * cfg80211_get_dev_from_ifindex(struct net *net, int ifindex)