wifi: rtw89: 8851be: add 8851BE PCI entry and fill PCI capabilities
Subsystems (4)
Sasha Levin
maintainerPATCH 2/4 bpf: Address KCSAN report on bpf_lru_list
In reply to Sasha LevinFrom: Martin KaFai Lau <[email protected]>
[ Upstream commit ee9fd0ac3017c4313be91a220a9ac4c99dde7ad4 ]
KCSAN reported a data-race when accessing node->ref. Although node->ref does not have to be accurate,
take this chance to use a more common READ_ONCE() and WRITE_ONCE() pattern instead of data_race().
There is an existing bpf_lru_node_is_ref() and bpf_lru_node_set_ref(). This patch also adds bpf_lru_node_clear_ref() to do the WRITE_ONCE(node->ref, 0) also.
==================================================================
BUG: KCSAN: data-race in __bpf_lru_list_rotate / __htab_lru_percpu_map_update_elem
write to 0xffff888137038deb of 1 bytes by task 11240 on cpu 1:
__bpf_lru_node_move kernel/bpf/bpf_lru_list.c:113 [inline] __bpf_lru_list_rotate_active kernel/bpf/bpf_lru_list.c:149 [inline] __bpf_lru_list_rotate+0x1bf/0x750 kernel/bpf/bpf_lru_list.c:240 bpf_lru_list_pop_free_to_local kernel/bpf/bpf_lru_list.c:329 [inline] bpf_common_lru_pop_free kernel/bpf/bpf_lru_list.c:447 [inline] bpf_lru_pop_free+0x638/0xe20 kernel/bpf/bpf_lru_list.c:499 prealloc_lru_pop kernel/bpf/hashtab.c:290 [inline] __htab_lru_percpu_map_update_elem+0xe7/0x820 kernel/bpf/hashtab.c:1316 bpf_percpu_hash_update+0x5e/0x90 kernel/bpf/hashtab.c:2313 bpf_map_update_value+0x2a9/0x370 kernel/bpf/syscall.c:200 generic_map_update_batch+0x3ae/0x4f0 kernel/bpf/syscall.c:1687 bpf_map_do_batch+0x2d9/0x3d0 kernel/bpf/syscall.c:4534 __sys_bpf+0x338/0x810 __do_sys_bpf kernel/bpf/syscall.c:5096 [inline] __se_sys_bpf kernel/bpf/syscall.c:5094 [inline] __x64_sys_bpf+0x43/0x50 kernel/bpf/syscall.c:5094 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd
read to 0xffff888137038deb of 1 bytes by task 11241 on cpu 0:
bpf_lru_node_set_ref kernel/bpf/bpf_lru_list.h:70 [inline] __htab_lru_percpu_map_update_elem+0x2f1/0x820 kernel/bpf/hashtab.c:1332 bpf_percpu_hash_update+0x5e/0x90 kernel/bpf/hashtab.c:2313 bpf_map_update_value+0x2a9/0x370 kernel/bpf/syscall.c:200 generic_map_update_batch+0x3ae/0x4f0 kernel/bpf/syscall.c:1687 bpf_map_do_batch+0x2d9/0x3d0 kernel/bpf/syscall.c:4534 __sys_bpf+0x338/0x810 __do_sys_bpf kernel/bpf/syscall.c:5096 [inline] __se_sys_bpf kernel/bpf/syscall.c:5094 [inline] __x64_sys_bpf+0x43/0x50 kernel/bpf/syscall.c:5094 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd
value changed: 0x01 -> 0x00
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 PID: 11241 Comm: syz-executor.3 Not tainted 6.3.0-rc7-syzkaller-00136-g6a66fdd29ea1 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/30/2023 ==================================================================
--- kernel/bpf/bpf_lru_list.c | 21 +++++++++++++-------- kernel/bpf/bpf_lru_list.h | 7 ++----- 2 files changed, 15 insertions(+), 13 deletions(-)
kernel/bpf/bpf_lru_list.c +13 -8
@@ -44,7 +44,12 @@ static struct list_head *local_pending_list(struct bpf_lru_locallist *loc_l)/* bpf_lru_node helpers */ static bool bpf_lru_node_is_ref (const struct bpf_lru_node *node) { -return node->ref; +return READ_ONCE (node->ref); +} + +static void bpf_lru_node_clear_ref (struct bpf_lru_node *node) +{ +WRITE_ONCE (node->ref,0 ); } static void bpf_lru_list_count_inc(struct bpf_lru_list *l,
@@ -92,7 +97,7 @@ static void __bpf_lru_node_move_in(struct bpf_lru_list *l,bpf_lru_list_count_inc (l, tgt_type); node->type = tgt_type; - node->ref =0 ; +bpf_lru_node_clear_ref (node);list_move (&node->list, &l->lists[tgt_type]); }
@@ -113,7 +118,7 @@ static void __bpf_lru_node_move(struct bpf_lru_list *l,bpf_lru_list_count_inc (l, tgt_type); node->type = tgt_type; } - node->ref =0 ; +bpf_lru_node_clear_ref (node);/* If the moving node is the next_inactive_rotation candidate, * move the next_inactive_rotation pointer also.
@@ -356,7 +361,7 @@ static void __local_list_add_pending(struct bpf_lru *lru, *(u32 *)((void *)node + lru->hash_offset) = hash; node->cpu = cpu; node->type =BPF_LRU_LOCAL_LIST_T_PENDING ; - node->ref =0 ; +bpf_lru_node_clear_ref (node);list_add (&node->list,local_pending_list (loc_l)); }
@@ -422,7 +427,7 @@ static struct bpf_lru_node *bpf_percpu_lru_pop_free(struct bpf_lru *lru,if (!list_empty (free_list)) { node = list_first_entry(free_list, struct bpf_lru_node, list); *(u32 *)((void *)node + lru->hash_offset) = hash; - node->ref =0 ; +bpf_lru_node_clear_ref (node);__bpf_lru_node_move (l, node,BPF_LRU_LIST_T_INACTIVE ); }
@@ -525,7 +530,7 @@ static void bpf_common_lru_push_free(struct bpf_lru *lru, } node->type =BPF_LRU_LOCAL_LIST_T_FREE ; - node->ref =0 ; +bpf_lru_node_clear_ref (node);list_move (&node->list,local_free_list (loc_l));raw_spin_unlock_irqrestore (&loc_l->lock, flags);
@@ -571,7 +576,7 @@ static void bpf_common_lru_populate(struct bpf_lru *lru, void *buf, node = (struct bpf_lru_node *)(buf + node_offset); node->type =BPF_LRU_LIST_T_FREE ; - node->ref =0 ; +bpf_lru_node_clear_ref (node);list_add (&node->list, &l->lists[BPF_LRU_LIST_T_FREE ]); buf += elem_size; }
@@ -597,7 +602,7 @@ static void bpf_percpu_lru_populate(struct bpf_lru *lru, void *buf, node = (struct bpf_lru_node *)(buf + node_offset); node->cpu = cpu; node->type =BPF_LRU_LIST_T_FREE ; - node->ref =0 ; +bpf_lru_node_clear_ref (node);list_add (&node->list, &l->lists[BPF_LRU_LIST_T_FREE ]); i++; buf += elem_size;
kernel/bpf/bpf_lru_list.h +2 -5
@@ -66,11 +66,8 @@ struct bpf_lru {static inline void bpf_lru_node_set_ref (struct bpf_lru_node *node) { -/* ref is an approximation on access frequency. It does not -* have to be very accurate. Hence, no protection is used. -*/ -if (!node->ref) - node->ref =1 ; +if (!READ_ONCE (node->ref)) +WRITE_ONCE (node->ref,1 ); } int bpf_lru_init(struct bpf_lru *lru, bool percpu, u32 hash_offset,
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 3/4 wifi: wext-core: Fix -Wstringop-overflow warning in ioctl_standard_iw_point()
In reply to Sasha LevinFrom: "Gustavo A. R. Silva" <[email protected]>
[ Upstream commit 71e7552c90db2a2767f5c17c7ec72296b0d92061 ]
-Wstringop-overflow is legitimately warning us about extra_size pontentially being zero at some point, hence potenially ending up _allocating_ zero bytes of memory for extra pointer and then trying to access such object in a call to copy_from_user().
Fix this by adding a sanity check to ensure we never end up trying to allocate zero bytes of data for extra pointer, before continue executing the rest of the code in the function.
Address the following -Wstringop-overflow warning seen when built
m68k architecture with allyesconfig configuration:
from net/wireless/wext-core.c:11:
In function '_copy_from_user',
inlined from 'copy_from_user' at include/linux/uaccess.h:183:7,
inlined from 'ioctl_standard_iw_point' at net/wireless/wext-core.c:825:7:arch/m68k/include/asm/string.h:48:25: warning: '__builtin_memset' writing 1 or more bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
48 | #define memset(d, c, n) __builtin_memset(d, c, n)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/uaccess.h:153:17: note: in expansion of macro 'memset'
153 | memset(to + (n - res), 0, res);
| ^~~~~~In function 'kmalloc',
inlined from 'kzalloc' at include/linux/slab.h:694:9,
inlined from 'ioctl_standard_iw_point' at net/wireless/wext-core.c:819:10:include/linux/slab.h:577:16: note: at offset 1 into destination object of size 0 allocated by '__kmalloc'
577 | return __kmalloc(size, flags);
| ^~~~~~~~~~~~~~~~~~~~~~This help with the ongoing efforts to globally enable -Wstringop-overflow.
--- net/wireless/wext-core.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/wireless/wext-core.c +6 -0
@@ -798,6 +798,12 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd, } } +/* Sanity-check to ensure we never end up _allocating_ zero +* bytes of data for extra. +*/ +if (extra_size <=0 ) +return -EFAULT ; +/* kzalloc() ensures NULL-termination for essid_compat. */ extra =kzalloc (extra_size,GFP_KERNEL );if (!extra)
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 4/4 igb: Fix igb_down hung on surprise removal
In reply to Sasha LevinFrom: Ying Hsu <[email protected]>
[ Upstream commit 004d25060c78fc31f66da0fa439c544dda1ac9d5 ]
In a setup where a Thunderbolt hub connects to Ethernet and a display through USB Type-C, users may experience a hung task timeout when they remove the cable between the PC and the Thunderbolt hub. This is because the igb_down function is called multiple times when the Thunderbolt hub is unplugged. For example, the igb_io_error_detected triggers the first call, and the igb_remove triggers the second call. The second call to igb_down will block at napi_synchronize. Here's the call trace:
__schedule+0x3b0/0xddb
? __mod_timer+0x164/0x5d3
schedule+0x44/0xa8
schedule_timeout+0xb2/0x2a4
? run_local_timers+0x4e/0x4e
msleep+0x31/0x38
igb_down+0x12c/0x22a [igb 6615058754948bfde0bf01429257eb59f13030d4]
__igb_close+0x6f/0x9c [igb 6615058754948bfde0bf01429257eb59f13030d4]
igb_close+0x23/0x2b [igb 6615058754948bfde0bf01429257eb59f13030d4]
__dev_close_many+0x95/0xec
dev_close_many+0x6e/0x103
unregister_netdevice_many+0x105/0x5b1
unregister_netdevice_queue+0xc2/0x10d
unregister_netdev+0x1c/0x23
igb_remove+0xa7/0x11c [igb 6615058754948bfde0bf01429257eb59f13030d4]
pci_device_remove+0x3f/0x9c
device_release_driver_internal+0xfe/0x1b4
pci_stop_bus_device+0x5b/0x7f
pci_stop_bus_device+0x30/0x7f
pci_stop_bus_device+0x30/0x7f
pci_stop_and_remove_bus_device+0x12/0x19
pciehp_unconfigure_device+0x76/0xe9
pciehp_disable_slot+0x6e/0x131
pciehp_handle_presence_or_link_change+0x7a/0x3f7
pciehp_ist+0xbe/0x194
irq_thread_fn+0x22/0x4d
? irq_thread+0x1fd/0x1fd
irq_thread+0x17b/0x1fd
? irq_forced_thread_fn+0x5f/0x5f
kthread+0x142/0x153
? __irq_get_irqchip_state+0x46/0x46
? kthread_associate_blkcg+0x71/0x71
ret_from_fork+0x1f/0x30In this case, igb_io_error_detected detaches the network interface and requests a PCIE slot reset, however, the PCIE reset callback is not being invoked and thus the Ethernet connection breaks down. As the PCIE error in this case is a non-fatal one, requesting a slot reset can be avoided.
This patch fixes the task hung issue and preserves Ethernet connection by ignoring non-fatal PCIE errors.
--- drivers/net/ethernet/intel/igb/igb_main.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/intel/igb/igb_main.c +5 -0
@@ -8257,6 +8257,11 @@ static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,struct net_device *netdev =pci_get_drvdata (pdev);struct igb_adapter *adapter =netdev_priv (netdev); +if (state == pci_channel_io_normal) { +dev_warn (&pdev->dev,"Non-correctable non-fatal error reported.\n" ); +return PCI_ERS_RESULT_CAN_RECOVER ; + } +netif_device_detach (netdev);if (state == pci_channel_io_perm_failure)
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 1/4 wifi: rtw89: 8851be: add 8851BE PCI entry and fill PCI capabilities
From: Ping-Ke Shih <[email protected]>
[ Upstream commit 99ff8da56322cda9eb9b37021e27b127c2d1cad8 ]
Add PCI entry to 8851BE with its device ID 10ec:b851, also fill PCI info according to its capabilities.
--- .../net/wireless/realtek/rtw89/rtw8851be.c | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 drivers/net/wireless/realtek/rtw89/rtw8851be.c
drivers/net/wireless/realtek/rtw89/rtw8851be.c new file +86 -0
@@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* Copyright(c) 2022-2023 Realtek Corporation +*/ + +#include <linux/module.h> +#include <linux/pci.h> + +#include "pci.h" +#include "reg.h" +#include "rtw8851b.h" + +static const struct rtw89_pci_info rtw8851b_pci_info = { + .txbd_trunc_mode =MAC_AX_BD_TRUNC , + .rxbd_trunc_mode =MAC_AX_BD_TRUNC , + .rxbd_mode =MAC_AX_RXBD_PKT , + .tag_mode =MAC_AX_TAG_MULTI , + .tx_burst =MAC_AX_TX_BURST_2048B , + .rx_burst =MAC_AX_RX_BURST_128B , + .wd_dma_idle_intvl =MAC_AX_WD_DMA_INTVL_256NS , + .wd_dma_act_intvl =MAC_AX_WD_DMA_INTVL_256NS , + .multi_tag_num =MAC_AX_TAG_NUM_8 , + .lbc_en =MAC_AX_PCIE_ENABLE , + .lbc_tmr =MAC_AX_LBC_TMR_2MS , + .autok_en =MAC_AX_PCIE_DISABLE , + .io_rcy_en =MAC_AX_PCIE_DISABLE , + .io_rcy_tmr =MAC_AX_IO_RCY_ANA_TMR_6MS , + + .init_cfg_reg =R_AX_PCIE_INIT_CFG1 , + .txhci_en_bit =B_AX_TXHCI_EN , + .rxhci_en_bit =B_AX_RXHCI_EN , + .rxbd_mode_bit =B_AX_RXBD_MODE , + .exp_ctrl_reg =R_AX_PCIE_EXP_CTRL , + .max_tag_num_mask =B_AX_MAX_TAG_NUM , + .rxbd_rwptr_clr_reg =R_AX_RXBD_RWPTR_CLR , + .txbd_rwptr_clr2_reg =0 , + .dma_stop1 = {R_AX_PCIE_DMA_STOP1 ,B_AX_TX_STOP1_MASK_V1 }, + .dma_stop2 = {0 }, + .dma_busy1 = {R_AX_PCIE_DMA_BUSY1 ,DMA_BUSY1_CHECK_V1 }, + .dma_busy2_reg =0 , + .dma_busy3_reg =R_AX_PCIE_DMA_BUSY1 , + + .rpwm_addr =R_AX_PCIE_HRPWM , + .cpwm_addr =R_AX_CPWM , + .tx_dma_ch_mask =BIT (RTW89_TXCH_ACH4 ) |BIT (RTW89_TXCH_ACH5 ) | +BIT (RTW89_TXCH_ACH6 ) |BIT (RTW89_TXCH_ACH7 ) | +BIT (RTW89_TXCH_CH10 ) |BIT (RTW89_TXCH_CH11 ), + .bd_idx_addr_low_power =NULL , + .dma_addr_set = &rtw89_pci_ch_dma_addr_set, + .bd_ram_table = &rtw89_bd_ram_table_single, + + .ltr_set = rtw89_pci_ltr_set, + .fill_txaddr_info = rtw89_pci_fill_txaddr_info, + .config_intr_mask = rtw89_pci_config_intr_mask, + .enable_intr = rtw89_pci_enable_intr, + .disable_intr = rtw89_pci_disable_intr, + .recognize_intrs = rtw89_pci_recognize_intrs, +}; + +static const struct rtw89_driver_info rtw89_8851be_info = { + .chip = &rtw8851b_chip_info, + .bus = { + .pci = &rtw8851b_pci_info, + }, +}; + +static const struct pci_device_id rtw89_8851be_id_table[] = { + { +PCI_DEVICE (PCI_VENDOR_ID_REALTEK ,0xb851 ), + .driver_data = (kernel_ulong_t)&rtw89_8851be_info, + }, + {}, +}; +MODULE_DEVICE_TABLE (pci, rtw89_8851be_id_table); + +static struct pci_driver rtw89_8851be_driver = { + .name ="rtw89_8851be" , + .id_table = rtw89_8851be_id_table, + .probe = rtw89_pci_probe, + .remove = rtw89_pci_remove, + .driver.pm = &rtw89_pm_ops, +}; +module_pci_driver (rtw89_8851be_driver); + +MODULE_AUTHOR ("Realtek Corporation" ); +MODULE_DESCRIPTION ("Realtek 802.11ax wireless 8851BE driver" ); +MODULE_LICENSE ("Dual BSD/GPL" );
Signature · 1 line
2.39.2