From patchwork Fri Jul 26 16:39:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Matyukevich X-Patchwork-Id: 11061391 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 2FF93912 for ; Fri, 26 Jul 2019 16:41:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FD6628AB7 for ; Fri, 26 Jul 2019 16:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1353728AC8; Fri, 26 Jul 2019 16:41:50 +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 024E428AB7 for ; Fri, 26 Jul 2019 16:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727753AbfGZQlr (ORCPT ); Fri, 26 Jul 2019 12:41:47 -0400 Received: from mx0b-00183b01.pphosted.com ([67.231.157.42]:45840 "EHLO mx0a-00183b01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727343AbfGZQlq (ORCPT ); Fri, 26 Jul 2019 12:41:46 -0400 Received: from pps.filterd (m0059811.ppops.net [127.0.0.1]) by mx0b-00183b01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6QGe2Cb007061; Fri, 26 Jul 2019 10:40:02 -0600 Received: from nam01-sn1-obe.outbound.protection.outlook.com (mail-sn1nam01lp2053.outbound.protection.outlook.com [104.47.32.53]) by mx0b-00183b01.pphosted.com with ESMTP id 2tywkqrwj4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jul 2019 10:40:02 -0600 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q1oFd1QBnAC4h9te+8fsbGycqEjzJz4LfsDsDzHpAbcDwNLuhwuzclJ/2ia5tpCE9U2e+OORkrLAsqWLGWVnLCgZJv9F58929jwL08p0Lze2hP3ALMC+RQZPGT8VtIqHramfQDy9WWsrYXSgTsz5kuU7AW/SPo7imWSMUwscEmkEDxhBGdWlGVIsUzBySMQWcjVNL537Aqp/IsrVkjTjIcHqZnKpg1fVB0pZiMpWytq7Buzv1x994nJqcebZ9rXMVeQlSKKoMeQHaKUtA6UGtdvCUjlYzOCKptv8fgwADUitZ8dyRkG9qM0iP+sZyy8uCB6+hbjRIlEoFNC/XCxUUw== 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=OCqhU2B+pNM5h8DdqOZ2JeOJdTopWQ2Hsj/cFiao3mA=; b=BOws8r4j3q+3dEElBZ+FfLZq86D06K0lMzAx3WxtzEsijx4BbWtQtBvpwua+II278KxhBs/WVwTg6vPUoZknBTy0lzZwFGyv0NzqQr6ciku/O+jzNQpGlXprxxqXnEOExJD02fqUpi5MoQZT2C7OhoNm5mNpA1oF16ZItvrYKl7Hp9CMQ0t+WXW/Y/66XugxsdVlX2tu5gNSAO/2hLxDVhZD+P56U5dzkKtPe6d52mXUgnxnl5WiqbuRqIIS5Zt0tX6zWdhMnxwp8dVZ2ZkBsVteYD7pL1zVMLaDwU+GDtM9tJOchm2kHzV4Z9xZcoAjcW4fl/3Q1WR+SkIWF0kmdw== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OCqhU2B+pNM5h8DdqOZ2JeOJdTopWQ2Hsj/cFiao3mA=; b=N7s/nM98VlQMesO0zuXbqihQZ8bvY2Slc0TzV/UoxYTW55i+H2xF9qhmveuBYPsy6lTneLMsZ89HRjhreGZNdn9eq94y9kCt9l2XRlgbEM5Ds1J51RlK/A5RlII7ErYQhEoX+EM7k3Q5pTeP+Z0g/291RAgmAv3cDFIr9YgvSW0= Received: from SN6PR05MB4703.namprd05.prod.outlook.com (52.135.114.213) by SN6PR05MB4959.namprd05.prod.outlook.com (20.177.249.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2136.9; Fri, 26 Jul 2019 16:40:00 +0000 Received: from SN6PR05MB4703.namprd05.prod.outlook.com ([fe80::78b3:7cea:d0b6:d11]) by SN6PR05MB4703.namprd05.prod.outlook.com ([fe80::78b3:7cea:d0b6:d11%5]) with mapi id 15.20.2115.005; Fri, 26 Jul 2019 16:40:00 +0000 Received: from BYAPR05MB4917.namprd05.prod.outlook.com (52.135.235.159) by BYAPR05MB4327.namprd05.prod.outlook.com (52.135.202.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.10; Fri, 26 Jul 2019 16:39:32 +0000 Received: from BYAPR05MB4917.namprd05.prod.outlook.com ([fe80::a5aa:dcd6:2812:334e]) by BYAPR05MB4917.namprd05.prod.outlook.com ([fe80::a5aa:dcd6:2812:334e%5]) with mapi id 15.20.2115.005; Fri, 26 Jul 2019 16:39:32 +0000 From: Sergey Matyukevich To: "linux-wireless@vger.kernel.org" CC: Johannes Berg , Igor Mitsyanko , Mikhail Karpenko , Sergey Matyukevich Subject: [PATCH v4 1/2] cfg80211: refactor cfg80211_bss_update Thread-Topic: [PATCH v4 1/2] cfg80211: refactor cfg80211_bss_update Thread-Index: AQHVQ9CzMkyU2IXzSEuwiE76ToNQiw== Date: Fri, 26 Jul 2019 16:39:32 +0000 Message-ID: <20190726163922.27509-2-sergey.matyukevich.os@quantenna.com> References: <20190726163922.27509-1-sergey.matyukevich.os@quantenna.com> In-Reply-To: <20190726163922.27509-1-sergey.matyukevich.os@quantenna.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR06CA0011.namprd06.prod.outlook.com (2603:10b6:a03:d4::24) To BYAPR05MB4917.namprd05.prod.outlook.com (2603:10b6:a03:42::31) 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: 57199ce3-c55c-4f9d-847c-08d711e7d5c9 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:BYAPR05MB4327; x-ms-traffictypediagnostic: BYAPR05MB4327:|SN6PR05MB4959: x-microsoft-antispam-prvs: x-moderation-data: 7/26/2019 4:39:58 PM x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 01106E96F6 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(136003)(366004)(376002)(346002)(39850400004)(189003)(199004)(6506007)(6436002)(2501003)(5640700003)(53936002)(386003)(107886003)(6512007)(102836004)(2906002)(99286004)(7736002)(86362001)(2616005)(71190400001)(4326008)(6916009)(186003)(6116002)(66066001)(25786009)(478600001)(14454004)(3846002)(103116003)(316002)(76176011)(54906003)(5660300002)(26005)(8936002)(1076003)(36756003)(50226002)(8676002)(66446008)(81166006)(66476007)(81156014)(68736007)(66556008)(64756008)(2351001)(476003)(71200400001)(446003)(436003)(66946007)(11346002)(52116002)(14444005)(486006)(305945005)(6486002)(256004);DIR:OUT;SFP:1101;SCL:1;SRVR:SN6PR05MB4959;H:SN6PR05MB4703.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: Hhl9YemNdSCFb22+TqSmpBzVwN1b3yIcYNNmwFQamQFKmhBoMZmDZ7Ed7kBu0vulbTTR/OqUvROJUEX234PLLCs5IUMvK+g1T50vhJbnUJIB9ryIMHoEUKILThLkqpCLlqeCXJSXf01NMeA0lJYkmEFfCSu6/1+A7o7JjQz4sEqYSke7Y9VjOn1MtztlO/suyQeY45N/f6TbwXXAXo+gV8UahN+TA8n8V+k5qHW5BIfyFy+egVGEsJaOzfMbdO3XYb/DgNo7bpqJcLekTQWRHMph5HOTS7Gxy4VkDr6NGOhTo8LYDbBtHRl/gVco5D5pbm/OMOEqp8eSiwRosS9H4CBybGu/ONQfghyPqBY3NM6XhaLuLf9ofpDFwaXxphTwKqnU460Q8Qc5++2IpChdpAzAqCknjrwTb/QTY+GZ9+w= MIME-Version: 1.0 X-OriginatorOrg: quantenna.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57199ce3-c55c-4f9d-847c-08d711e7d5c9 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_d3241082-88d9-4157-85a8-5a9c8795aa9d@quantenna.onmicrosoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jul 2019 16:40:00.1739 (UTC) X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR05MB4959 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-26_12:,, 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=986 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907260203 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 a98dabab557a..9119f5ce3677 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 Fri Jul 26 16:39:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Matyukevich X-Patchwork-Id: 11061387 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 76AFE14E5 for ; Fri, 26 Jul 2019 16:40:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66598289B4 for ; Fri, 26 Jul 2019 16:40:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59BD428A31; Fri, 26 Jul 2019 16:40: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=-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 0D3FC289D6 for ; Fri, 26 Jul 2019 16:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726279AbfGZQkI (ORCPT ); Fri, 26 Jul 2019 12:40:08 -0400 Received: from mx0a-00183b01.pphosted.com ([67.231.149.44]:8886 "EHLO mx0a-00183b01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725298AbfGZQkI (ORCPT ); Fri, 26 Jul 2019 12:40:08 -0400 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 x6QGZjn2003725; Fri, 26 Jul 2019 10:40:01 -0600 Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2056.outbound.protection.outlook.com [104.47.36.56]) by mx0a-00183b01.pphosted.com with ESMTP id 2u0560r098-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 26 Jul 2019 10:40:01 -0600 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dJnAINBjlGisDpJ4miJ2YdFF6wmOn9zhUDwdF2iSYi4TPE764Thx4p2Yu8foYQ8zv+CPNEo5TC5ppe8h4GW7nDFJzKO+6id5TYg7meM7y9iYWmFE4ZNdqs/E3bhTgp9++fzqCZPeVqIuGnLRz1OxgjkV2TE9NszDvDV5d96VlxnDNwq/K0IjKsu1U3QF5vAYVzEp3tQ0OMWcZpiH9yjh8dQ30tnpcollD+lMm3UAPmmQdTb2QZLyEeGc0FdPSFTUFg2ly+9htTWFmN1uZegIRyxMXnc36iwIepyecnTdOlJI5XGxWEjSB0W8Ec69rKQUK9rS5ihJk6WhkMZWq1EUog== 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=8PA46Gcs8yYFZrJR+ZEYBttDcP5fY2dU2EFn/rf/ldk=; b=SqK7QiaGb24H7brRgl4+BDwlQwZNsFS8nblfW8Mhs93XZgjv3rMaj9ZwYfulxvhiTNEG8jqD2sfnLucjsOtn7U74stLiIDjJ8ihb5RFQGBTt4AuC1vQMyIi6uqlrRaAYidZK4UVnyP9VEm53jUA9S7FQOQoCsKVtEW/Zi6vA88ycKEajdS7iKPe/z4rGXg8czvy/GWRZIY7hbNplvuEbKs9DAKIF9Q5z8Ia9jEy0ywSwXsETeIyxLafVsw3hdXFz+S0nKDCByU/qCuB50Gk8gUkVma/r5jDDUWyNz0eQFGtQuwoX+ESwDLaAbPqokTPeQzbKB+o0OlvvS0GWX0HA/w== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8PA46Gcs8yYFZrJR+ZEYBttDcP5fY2dU2EFn/rf/ldk=; b=q8wbdXEuccZrxNVGuWkyIEDrKJ5FvAELqBNydvNz/kLV1SBvOdNLHqSu2tBuaQf8LxIN4KXsVXvK6FwREJWTalpvYGQV8EKOJf2qUYMU2Wyk6u4yfaqxd7NrBFOYkei5qYP0fqXDuzBxBgrrD/FzB02Lamk4OUcXmNueCtJLK+k= Received: from BYAPR05MB4056.namprd05.prod.outlook.com (52.135.199.33) by BYAPR05MB6408.namprd05.prod.outlook.com (20.178.51.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.10; Fri, 26 Jul 2019 16:39:58 +0000 Received: from BYAPR05MB4056.namprd05.prod.outlook.com ([fe80::95ae:b687:6dd:cbd9]) by BYAPR05MB4056.namprd05.prod.outlook.com ([fe80::95ae:b687:6dd:cbd9%7]) with mapi id 15.20.2115.005; Fri, 26 Jul 2019 16:39:58 +0000 Received: from BYAPR05MB4917.namprd05.prod.outlook.com (52.135.235.159) by BYAPR05MB4327.namprd05.prod.outlook.com (52.135.202.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.10; Fri, 26 Jul 2019 16:39:34 +0000 Received: from BYAPR05MB4917.namprd05.prod.outlook.com ([fe80::a5aa:dcd6:2812:334e]) by BYAPR05MB4917.namprd05.prod.outlook.com ([fe80::a5aa:dcd6:2812:334e%5]) with mapi id 15.20.2115.005; Fri, 26 Jul 2019 16:39:34 +0000 From: Sergey Matyukevich To: "linux-wireless@vger.kernel.org" CC: Johannes Berg , Igor Mitsyanko , Mikhail Karpenko , Sergey Matyukevich Subject: [PATCH v4 2/2] cfg80211: fix duplicated scan entries after channel switch Thread-Topic: [PATCH v4 2/2] cfg80211: fix duplicated scan entries after channel switch Thread-Index: AQHVQ9C0GLu1A28lFkKn47oV7U1oNQ== Date: Fri, 26 Jul 2019 16:39:34 +0000 Message-ID: <20190726163922.27509-3-sergey.matyukevich.os@quantenna.com> References: <20190726163922.27509-1-sergey.matyukevich.os@quantenna.com> In-Reply-To: <20190726163922.27509-1-sergey.matyukevich.os@quantenna.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR06CA0011.namprd06.prod.outlook.com (2603:10b6:a03:d4::24) To BYAPR05MB4917.namprd05.prod.outlook.com (2603:10b6:a03:42::31) 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: 39eecef0-de86-4bab-b15c-08d711e7d6f8 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:BYAPR05MB4327; x-ms-traffictypediagnostic: BYAPR05MB4327:|BYAPR05MB6408: x-microsoft-antispam-prvs: x-moderation-data: 7/26/2019 4:39:56 PM x-ms-oob-tlc-oobclassifiers: OLM:3826; x-forefront-prvs: 01106E96F6 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(136003)(39850400004)(396003)(346002)(189003)(199004)(6916009)(66946007)(66446008)(68736007)(66556008)(2906002)(186003)(66476007)(26005)(6506007)(386003)(8936002)(14454004)(107886003)(11346002)(86362001)(5660300002)(436003)(476003)(5640700003)(53936002)(102836004)(446003)(2616005)(36756003)(4326008)(1076003)(305945005)(7736002)(486006)(6116002)(3846002)(66066001)(103116003)(14444005)(6436002)(2501003)(54906003)(50226002)(316002)(99286004)(6486002)(81166006)(8676002)(2351001)(25786009)(71190400001)(52116002)(478600001)(71200400001)(76176011)(6512007)(64756008)(256004)(81156014);DIR:OUT;SFP:1101;SCL:1;SRVR:BYAPR05MB6408;H:BYAPR05MB4056.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: zFr7CSU9dWDXhRqcPro7Ab07kNpD+wdAEoBrkPviU2CD7UOGdO9HzSAigC9kv7KVaSw/4LtgRBr7+NpxeHaN2kp/hKrvX+cYDO5rhZ7lew9G2ymaYby/qXYZxbbpX6oTnXXxHGv2F4I5G7nSr15hlqTOS6Dh03DiW1C6QJuknpsqsIqWqxYNxcZy6Q0OoKO/rfYJJyqtlGJ0IDUfz3VYzj5SbXQuarwiWfEWOH007EvVWZ6akq+oNwdwF5fyyjKWG1BDhaZNzQjlWS3kNQMrb+7suTyaaTJwVjwMV+5NxMvk7fpFdGLz7h9aeplx4Q9eX4cFuiDz3+0JRadhJ4lqy/hfstbCB8GNTdtIfuCnMLcuR+9sX7eD9GGGmklCQfwlXV4qNDUIuC1IefnHT3amI43cxG6JtWA7A6f9XCHwLD4= MIME-Version: 1.0 X-OriginatorOrg: quantenna.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39eecef0-de86-4bab-b15c-08d711e7d6f8 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_4acb5e86-e93b-4c01-ae1f-712441a9c274@quantenna.onmicrosoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jul 2019 16:39:58.5572 (UTC) X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6408 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-26_12:,, signatures=0 X-Proofpoint-Spam-Reason: safe 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 - for nontransmit BSS entry, the whole transmit BSS hierarchy is updated Signed-off-by: Sergey Matyukevich --- 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 10b57aa10227..a8d4b2b6b3ec 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -16116,7 +16116,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 9119f5ce3677..5e38f8092917 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -2001,6 +2001,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 transmitting 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)