]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: rtw89: pci: fix RX tag race condition resulting in wrong RX length
authorPing-Ke Shih <pkshih@realtek.com>
Tue, 11 Jun 2024 02:19:01 +0000 (10:19 +0800)
committerPing-Ke Shih <pkshih@realtek.com>
Mon, 17 Jun 2024 02:38:13 +0000 (10:38 +0800)
Read 32 bits RX info to a local variable to fix race condition between
reading RX length and RX tag.

Another solution is to get RX tag at first statement, but adopted solution
can save some memory read, and also save 15 bytes binary code.

RX tag, a sequence number, is used to ensure that RX data has been DMA to
memory completely, so driver must check sequence number is expected before
reading other data.

This potential problem happens only after enabling 36-bit DMA.

Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://msgid.link/20240611021901.26394-2-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/pci.c

index ccb4bfe1a9092a214c690857790bd76977d99c83..02afeb3acce469927a08bf81d45dd2c638345c06 100644 (file)
@@ -183,14 +183,17 @@ static void rtw89_pci_sync_skb_for_device(struct rtw89_dev *rtwdev,
 static void rtw89_pci_rxbd_info_update(struct rtw89_dev *rtwdev,
                                       struct sk_buff *skb)
 {
-       struct rtw89_pci_rxbd_info *rxbd_info;
        struct rtw89_pci_rx_info *rx_info = RTW89_PCI_RX_SKB_CB(skb);
+       struct rtw89_pci_rxbd_info *rxbd_info;
+       __le32 info;
 
        rxbd_info = (struct rtw89_pci_rxbd_info *)skb->data;
-       rx_info->fs = le32_get_bits(rxbd_info->dword, RTW89_PCI_RXBD_FS);
-       rx_info->ls = le32_get_bits(rxbd_info->dword, RTW89_PCI_RXBD_LS);
-       rx_info->len = le32_get_bits(rxbd_info->dword, RTW89_PCI_RXBD_WRITE_SIZE);
-       rx_info->tag = le32_get_bits(rxbd_info->dword, RTW89_PCI_RXBD_TAG);
+       info = rxbd_info->dword;
+
+       rx_info->fs = le32_get_bits(info, RTW89_PCI_RXBD_FS);
+       rx_info->ls = le32_get_bits(info, RTW89_PCI_RXBD_LS);
+       rx_info->len = le32_get_bits(info, RTW89_PCI_RXBD_WRITE_SIZE);
+       rx_info->tag = le32_get_bits(info, RTW89_PCI_RXBD_TAG);
 }
 
 static int rtw89_pci_validate_rx_tag(struct rtw89_dev *rtwdev,