Skip to content

[Deepin-Kernel-SIG] [Upstream] [linux 6.6-y] Sync some mac80211 bugfix from mainline v6.7 #614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions net/mac80211/debugfs_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,18 +888,20 @@ static void add_link_files(struct ieee80211_link_data *link,
}
}

void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata,
bool mld_vif)
{
char buf[10+IFNAMSIZ];

sprintf(buf, "netdev:%s", sdata->name);
sdata->vif.debugfs_dir = debugfs_create_dir(buf,
sdata->local->hw.wiphy->debugfsdir);
/* deflink also has this */
sdata->deflink.debugfs_dir = sdata->vif.debugfs_dir;
sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
sdata->vif.debugfs_dir);
add_files(sdata);

if (!(sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
if (!mld_vif)
add_link_files(&sdata->deflink, sdata->vif.debugfs_dir);
}

Expand Down Expand Up @@ -927,11 +929,24 @@ void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
debugfs_rename(dir->d_parent, dir, dir->d_parent, buf);
}

void ieee80211_debugfs_recreate_netdev(struct ieee80211_sub_if_data *sdata,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider using early returns/guard clauses to reduce nesting and improve readability in functions like ieee80211_debugfs_recreate_netdev and ieee80211_link_debugfs_add.

In functions like `ieee80211_debugfs_recreate_netdev` and `ieee80211_link_debugfs_add`, consider using early returns/guard clauses to avoid extra nesting. For example, you may refactor the nested if–statements in `ieee80211_debugfs_recreate_netdev` as follows:

--- Before ---
```c
ieee80211_debugfs_remove_netdev(sdata);
ieee80211_debugfs_add_netdev(sdata, mld_vif);

if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) {
    drv_vif_add_debugfs(sdata->local, sdata);
    if (!mld_vif)
        ieee80211_link_debugfs_drv_add(&sdata->deflink);
}

--- After ---

ieee80211_debugfs_remove_netdev(sdata);
ieee80211_debugfs_add_netdev(sdata, mld_vif);

if (!(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
    return;

drv_vif_add_debugfs(sdata->local, sdata);
if (mld_vif)
    return;

ieee80211_link_debugfs_drv_add(&sdata->deflink);

Similarly, in ieee80211_link_debugfs_add, instead of combining multiple WARN_ON checks in one compound condition, separate them:

--- Before ---

if (WARN_ON(!link->sdata->vif.debugfs_dir || link->debugfs_dir))
    return;
if (WARN_ON(!(link->sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)))
    return;

--- After ---

if (!link->sdata->vif.debugfs_dir) {
    WARN_ON(true);
    return;
}
if (link->debugfs_dir) {
    WARN_ON(true);
    return;
}
if (!(link->sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)) {
    WARN_ON(true);
    return;
}

These small changes improve readability by reducing nested branches while keeping the functionality intact.

bool mld_vif)
{
ieee80211_debugfs_remove_netdev(sdata);
ieee80211_debugfs_add_netdev(sdata, mld_vif);

if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) {
drv_vif_add_debugfs(sdata->local, sdata);
if (!mld_vif)
ieee80211_link_debugfs_drv_add(&sdata->deflink);
}
}

void ieee80211_link_debugfs_add(struct ieee80211_link_data *link)
{
char link_dir_name[10];

if (WARN_ON(!link->sdata->vif.debugfs_dir))
if (WARN_ON(!link->sdata->vif.debugfs_dir || link->debugfs_dir))
return;

/* For now, this should not be called for non-MLO capable drivers */
Expand Down Expand Up @@ -968,7 +983,8 @@ void ieee80211_link_debugfs_remove(struct ieee80211_link_data *link)

void ieee80211_link_debugfs_drv_add(struct ieee80211_link_data *link)
{
if (WARN_ON(!link->debugfs_dir))
if (link->sdata->vif.type == NL80211_IFTYPE_MONITOR ||
WARN_ON(!link->debugfs_dir))
return;

drv_link_add_debugfs(link->sdata->local, link->sdata,
Expand Down
15 changes: 12 additions & 3 deletions net/mac80211/debugfs_netdev.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Portions:
* Copyright (C) 2023 Intel Corporation
*/
/* routines exported for debugfs handling */

#ifndef __IEEE80211_DEBUGFS_NETDEV_H
Expand All @@ -7,9 +11,12 @@
#include "ieee80211_i.h"

#ifdef CONFIG_MAC80211_DEBUGFS
void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata);
void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata,
bool mld_vif);
void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata);
void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata);
void ieee80211_debugfs_recreate_netdev(struct ieee80211_sub_if_data *sdata,
bool mld_vif);

void ieee80211_link_debugfs_add(struct ieee80211_link_data *link);
void ieee80211_link_debugfs_remove(struct ieee80211_link_data *link);
Expand All @@ -18,15 +25,17 @@ void ieee80211_link_debugfs_drv_add(struct ieee80211_link_data *link);
void ieee80211_link_debugfs_drv_remove(struct ieee80211_link_data *link);
#else
static inline void ieee80211_debugfs_add_netdev(
struct ieee80211_sub_if_data *sdata)
struct ieee80211_sub_if_data *sdata, bool mld_vif)
{}
static inline void ieee80211_debugfs_remove_netdev(
struct ieee80211_sub_if_data *sdata)
{}
static inline void ieee80211_debugfs_rename_netdev(
struct ieee80211_sub_if_data *sdata)
{}

static inline void ieee80211_debugfs_recreate_netdev(
struct ieee80211_sub_if_data *sdata, bool mld_vif)
{}
static inline void ieee80211_link_debugfs_add(struct ieee80211_link_data *link)
{}
static inline void ieee80211_link_debugfs_remove(struct ieee80211_link_data *link)
Expand Down
17 changes: 12 additions & 5 deletions net/mac80211/driver-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ int drv_add_interface(struct ieee80211_local *local,
if (ret)
return ret;

sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
if (!(sdata->flags & IEEE80211_SDATA_IN_DRIVER)) {
sdata->flags |= IEEE80211_SDATA_IN_DRIVER;

if (!local->in_reconfig)
drv_vif_add_debugfs(local, sdata);
/* initially vif is not MLD */
ieee80211_link_debugfs_drv_add(&sdata->deflink);
}

return 0;
}
Expand Down Expand Up @@ -105,9 +108,13 @@ void drv_remove_interface(struct ieee80211_local *local,
if (!check_sdata_in_driver(sdata))
return;

sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;

/* Remove driver debugfs entries */
ieee80211_debugfs_recreate_netdev(sdata, sdata->vif.valid_links);

trace_drv_remove_interface(local, sdata);
local->ops->remove_interface(&local->hw, &sdata->vif);
sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
trace_drv_return_void(local);
}

Expand Down Expand Up @@ -512,7 +519,7 @@ int drv_change_vif_links(struct ieee80211_local *local,
if (ret)
return ret;

if (!local->in_reconfig) {
if (!local->in_reconfig && !local->resuming) {
for_each_set_bit(link_id, &links_to_add,
IEEE80211_MLD_MAX_NUM_LINKS) {
link = rcu_access_pointer(sdata->link[link_id]);
Expand Down Expand Up @@ -567,7 +574,7 @@ int drv_change_sta_links(struct ieee80211_local *local,
return ret;

/* during reconfig don't add it to debugfs again */
if (local->in_reconfig)
if (local->in_reconfig || local->resuming)
return 0;

for_each_set_bit(link_id, &links_to_add, IEEE80211_MLD_MAX_NUM_LINKS) {
Expand Down
42 changes: 41 additions & 1 deletion net/mac80211/drop.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,50 @@ typedef unsigned int __bitwise ieee80211_rx_result;
/* this line for the trailing \ - add before this */

#define MAC80211_DROP_REASONS_UNUSABLE(R) \
/* 0x00 == ___RX_DROP_UNUSABLE */ \
R(RX_DROP_U_MIC_FAIL) \
R(RX_DROP_U_REPLAY) \
R(RX_DROP_U_BAD_MMIE) \
R(RX_DROP_U_DUP) \
R(RX_DROP_U_SPURIOUS) \
R(RX_DROP_U_DECRYPT_FAIL) \
R(RX_DROP_U_NO_KEY_ID) \
R(RX_DROP_U_BAD_CIPHER) \
R(RX_DROP_U_OOM) \
R(RX_DROP_U_NONSEQ_PN) \
R(RX_DROP_U_BAD_KEY_COLOR) \
R(RX_DROP_U_BAD_4ADDR) \
R(RX_DROP_U_BAD_AMSDU) \
R(RX_DROP_U_BAD_AMSDU_CIPHER) \
R(RX_DROP_U_INVALID_8023) \
/* 0x10 */ \
R(RX_DROP_U_RUNT_ACTION) \
R(RX_DROP_U_UNPROT_ACTION) \
R(RX_DROP_U_UNPROT_DUAL) \
R(RX_DROP_U_UNPROT_UCAST_MGMT) \
R(RX_DROP_U_UNPROT_MCAST_MGMT) \
R(RX_DROP_U_UNPROT_BEACON) \
R(RX_DROP_U_UNPROT_UNICAST_PUB_ACTION) \
R(RX_DROP_U_UNPROT_ROBUST_ACTION) \
R(RX_DROP_U_ACTION_UNKNOWN_SRC) \
R(RX_DROP_U_REJECTED_ACTION_RESPONSE) \
R(RX_DROP_U_EXPECT_DEFRAG_PROT) \
R(RX_DROP_U_WEP_DEC_FAIL) \
R(RX_DROP_U_NO_IV) \
R(RX_DROP_U_NO_ICV) \
R(RX_DROP_U_AP_RX_GROUPCAST) \
R(RX_DROP_U_SHORT_MMIC) \
/* 0x20 */ \
R(RX_DROP_U_MMIC_FAIL) \
R(RX_DROP_U_SHORT_TKIP) \
R(RX_DROP_U_TKIP_FAIL) \
R(RX_DROP_U_SHORT_CCMP) \
R(RX_DROP_U_SHORT_CCMP_MIC) \
R(RX_DROP_U_SHORT_GCMP) \
R(RX_DROP_U_SHORT_GCMP_MIC) \
R(RX_DROP_U_SHORT_CMAC) \
R(RX_DROP_U_SHORT_CMAC256) \
R(RX_DROP_U_SHORT_GMAC) \
/* this line for the trailing \ - add before this */

/* having two enums allows for checking ieee80211_rx_result use with sparse */
Expand All @@ -46,7 +87,6 @@ enum mac80211_drop_reason {
RX_CONTINUE = (__force ieee80211_rx_result)___RX_CONTINUE,
RX_QUEUED = (__force ieee80211_rx_result)___RX_QUEUED,
RX_DROP_MONITOR = (__force ieee80211_rx_result)___RX_DROP_MONITOR,
RX_DROP_UNUSABLE = (__force ieee80211_rx_result)___RX_DROP_UNUSABLE,
#define DEF(x) x = (__force ieee80211_rx_result)___ ## x,
MAC80211_DROP_REASONS_MONITOR(DEF)
MAC80211_DROP_REASONS_UNUSABLE(DEF)
Expand Down
1 change: 1 addition & 0 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -2430,6 +2430,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,
struct txq_info *txq, int tid);
void ieee80211_txq_purge(struct ieee80211_local *local,
struct txq_info *txqi);
void ieee80211_purge_sta_txqs(struct sta_info *sta);
void ieee80211_txq_remove_vlan(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata);
void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
Expand Down
2 changes: 1 addition & 1 deletion net/mac80211/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
/* need to do this after the switch so vif.type is correct */
ieee80211_link_setup(&sdata->deflink);

ieee80211_debugfs_add_netdev(sdata);
ieee80211_debugfs_add_netdev(sdata, false);
}

static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
Expand Down
5 changes: 5 additions & 0 deletions net/mac80211/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ static int ieee80211_vif_update_links(struct ieee80211_sub_if_data *sdata,
RCU_INIT_POINTER(sdata->vif.link_conf[link_id], NULL);
}

if (!old_links)
ieee80211_debugfs_recreate_netdev(sdata, true);

/* link them into data structures */
for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
WARN_ON(!use_deflink &&
Expand All @@ -261,6 +264,8 @@ static int ieee80211_vif_update_links(struct ieee80211_sub_if_data *sdata,
old_links & old_active,
new_links & sdata->vif.active_links,
old);
if (!new_links)
ieee80211_debugfs_recreate_netdev(sdata, false);
}

if (ret) {
Expand Down
8 changes: 6 additions & 2 deletions net/mac80211/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ static void ieee80211_mesh_housekeeping_timer(struct timer_list *t)
*
* This function checks if the mesh configuration of a mesh point matches the
* local mesh configuration, i.e. if both nodes belong to the same mesh network.
*
* Returns: %true if both nodes belong to the same mesh
*/
bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
struct ieee802_11_elems *ie)
Expand Down Expand Up @@ -119,6 +121,8 @@ bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
* mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
*
* @ie: information elements of a management frame from the mesh peer
*
* Returns: %true if the mesh peer is willing to establish peer links
*/
bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
{
Expand Down Expand Up @@ -864,7 +868,7 @@ bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
* @meshsa: source address in the mesh. Same as TA, as frame is
* locally originated.
*
* Return the length of the 802.11 (does not include a mesh control header)
* Returns: the length of the 802.11 frame header (excludes mesh control header)
*/
int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
const u8 *meshda, const u8 *meshsa)
Expand Down Expand Up @@ -897,7 +901,7 @@ int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
* @addr6: 2nd address in the ae header, which corresponds to addr6 of the
* mesh frame
*
* Return the header length.
* Returns: the header length
*/
unsigned int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata,
struct ieee80211s_hdr *meshhdr,
Expand Down
2 changes: 2 additions & 0 deletions net/mac80211/mesh_hwmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ static void prepare_frame_for_deferred_tx(struct ieee80211_sub_if_data *sdata,
* Note: This function may be called with driver locks taken that the driver
* also acquires in the TX path. To avoid a deadlock we don't transmit the
* frame directly but add it to the pending queue instead.
*
* Returns: 0 on success
*/
int mesh_path_error_tx(struct ieee80211_sub_if_data *sdata,
u8 ttl, const u8 *target, u32 target_sn,
Expand Down
20 changes: 13 additions & 7 deletions net/mac80211/mesh_pathtbl.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2008, 2009 open80211s Ltd.
* Copyright (C) 2023 Intel Corporation
* Author: Luis Carlos Cobo <[email protected]>
*/

Expand Down Expand Up @@ -173,6 +174,11 @@ static void prepare_for_gate(struct sk_buff *skb, char *dst_addr,
/**
* mesh_path_move_to_queue - Move or copy frames from one mpath queue to another
*
* @gate_mpath: An active mpath the frames will be sent to (i.e. the gate)
* @from_mpath: The failed mpath
* @copy: When true, copy all the frames to the new mpath queue. When false,
* move them.
*
* This function is used to transfer or copy frames from an unresolved mpath to
* a gate mpath. The function also adds the Address Extension field and
* updates the next hop.
Expand All @@ -181,11 +187,6 @@ static void prepare_for_gate(struct sk_buff *skb, char *dst_addr,
* destination addresses are updated.
*
* The gate mpath must be an active mpath with a valid mpath->next_hop.
*
* @gate_mpath: An active mpath the frames will be sent to (i.e. the gate)
* @from_mpath: The failed mpath
* @copy: When true, copy all the frames to the new mpath queue. When false,
* move them.
*/
static void mesh_path_move_to_queue(struct mesh_path *gate_mpath,
struct mesh_path *from_mpath,
Expand Down Expand Up @@ -330,6 +331,8 @@ mpp_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx)
/**
* mesh_path_add_gate - add the given mpath to a mesh gate to our path table
* @mpath: gate path to add to table
*
* Returns: 0 on success, -EEXIST
*/
int mesh_path_add_gate(struct mesh_path *mpath)
{
Expand Down Expand Up @@ -388,6 +391,8 @@ static void mesh_gate_del(struct mesh_table *tbl, struct mesh_path *mpath)
/**
* mesh_gate_num - number of gates known to this interface
* @sdata: subif data
*
* Returns: The number of gates
*/
int mesh_gate_num(struct ieee80211_sub_if_data *sdata)
{
Expand Down Expand Up @@ -870,10 +875,9 @@ static void table_flush_by_iface(struct mesh_table *tbl)
/**
* mesh_path_flush_by_iface - Deletes all mesh paths associated with a given iface
*
* This function deletes both mesh paths as well as mesh portal paths.
*
* @sdata: interface data to match
*
* This function deletes both mesh paths as well as mesh portal paths.
*/
void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
{
Expand Down Expand Up @@ -953,6 +957,8 @@ void mesh_path_tx_pending(struct mesh_path *mpath)
* queue to that gate's queue. If there are more than one gates, the frames
* are copied from each gate to the next. After frames are copied, the
* mpath queues are emptied onto the transmission queue.
*
* Returns: 0 on success, -EHOSTUNREACH
*/
int mesh_path_send_to_gates(struct mesh_path *mpath)
{
Expand Down
6 changes: 5 additions & 1 deletion net/mac80211/mesh_plink.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ static u64 mesh_set_short_slot_time(struct ieee80211_sub_if_data *sdata)
* selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
* is selected if all peers in our 20/40MHz MBSS support HT and at least one
* HT20 peer is present. Otherwise no-protection mode is selected.
*
* Returns: BSS_CHANGED_HT or 0 for no change
*/
static u64 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata)
{
Expand Down Expand Up @@ -362,7 +364,7 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
* Mesh paths with this peer as next hop should be flushed
* by the caller outside of plink_lock.
*
* Returns beacon changed flag if the beacon content changed.
* Returns: beacon changed flag if the beacon content changed.
*
* Locking: the caller must hold sta->mesh->plink_lock
*/
Expand Down Expand Up @@ -390,6 +392,8 @@ static u64 __mesh_plink_deactivate(struct sta_info *sta)
* @sta: mesh peer link to deactivate
*
* All mesh paths with this peer as next hop will be flushed
*
* Returns: beacon changed flag if the beacon content changed.
*/
u64 mesh_plink_deactivate(struct sta_info *sta)
{
Expand Down
Loading
Loading