linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtw88/pci: Rearrange the memory usage for skb in RX ISR
@ 2019-07-08  6:32 Jian-Hong Pan
  2019-07-08  7:23 ` Tony Chuang
                   ` (4 more replies)
  0 siblings, 5 replies; 23+ messages in thread
From: Jian-Hong Pan @ 2019-07-08  6:32 UTC (permalink / raw)
  To: Yan-Hsuan Chuang, Kalle Valo, David S . Miller
  Cc: linux-wireless, netdev, linux-kernel, linux, Jian-Hong Pan,
	Daniel Drake, stable

Testing with RTL8822BE hardware, when available memory is low, we
frequently see a kernel panic and system freeze.

First, rtw_pci_rx_isr encounters a memory allocation failure (trimmed):

rx routine starvation
WARNING: CPU: 7 PID: 9871 at drivers/net/wireless/realtek/rtw88/pci.c:822 rtw_pci_rx_isr.constprop.25+0x35a/0x370 [rtwpci]
[ 2356.580313] RIP: 0010:rtw_pci_rx_isr.constprop.25+0x35a/0x370 [rtwpci]

Then we see a variety of different error conditions and kernel panics,
such as this one (trimmed):

rtw_pci 0000:02:00.0: pci bus timeout, check dma status
skbuff: skb_over_panic: text:00000000091b6e66 len:415 put:415 head:00000000d2880c6f data:000000007a02b1ea tail:0x1df end:0xc0 dev:<NULL>
------------[ cut here ]------------
kernel BUG at net/core/skbuff.c:105!
invalid opcode: 0000 [#1] SMP NOPTI
RIP: 0010:skb_panic+0x43/0x45

When skb allocation fails and the "rx routine starvation" is hit, the
function returns immediately without updating the RX ring. At this
point, the RX ring may continue referencing an old skb which was already
handed off to ieee80211_rx_irqsafe(). When it comes to be used again,
bad things happen.

This patch allocates a new skb first in RX ISR. If we don't have memory
available, we discard the current frame, allowing the existing skb to be
reused in the ring. Otherwise, we simplify the code flow and just hand
over the RX-populated skb over to mac80211.

In addition, to fixing the kernel crash, the RX routine should now
generally behave better under low memory conditions.

Buglink: https://bugzilla.kernel.org/show_bug.cgi?id=204053
Signed-off-by: Jian-Hong Pan <jian-hong@endlessm.com>
Reviewed-by: Daniel Drake <drake@endlessm.com>
Cc: <stable@vger.kernel.org>
---
 drivers/net/wireless/realtek/rtw88/pci.c | 28 +++++++++++-------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c
index cfe05ba7280d..1bfc99ae6b84 100644
--- a/drivers/net/wireless/realtek/rtw88/pci.c
+++ b/drivers/net/wireless/realtek/rtw88/pci.c
@@ -786,6 +786,15 @@ static void rtw_pci_rx_isr(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,
 		rx_desc = skb->data;
 		chip->ops->query_rx_desc(rtwdev, rx_desc, &pkt_stat, &rx_status);
 
+		/* discard current skb if the new skb cannot be allocated as a
+		 * new one in rx ring later
+		 * */
+		new = dev_alloc_skb(RTK_PCI_RX_BUF_SIZE);
+		if (WARN(!new, "rx routine starvation\n")) {
+			new = skb;
+			goto next_rp;
+		}
+
 		/* offset from rx_desc to payload */
 		pkt_offset = pkt_desc_sz + pkt_stat.drv_info_sz +
 			     pkt_stat.shift;
@@ -803,25 +812,14 @@ static void rtw_pci_rx_isr(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,
 			skb_put(skb, pkt_stat.pkt_len);
 			skb_reserve(skb, pkt_offset);
 
-			/* alloc a smaller skb to mac80211 */
-			new = dev_alloc_skb(pkt_stat.pkt_len);
-			if (!new) {
-				new = skb;
-			} else {
-				skb_put_data(new, skb->data, skb->len);
-				dev_kfree_skb_any(skb);
-			}
 			/* TODO: merge into rx.c */
 			rtw_rx_stats(rtwdev, pkt_stat.vif, skb);
-			memcpy(new->cb, &rx_status, sizeof(rx_status));
-			ieee80211_rx_irqsafe(rtwdev->hw, new);
+			memcpy(skb->cb, &rx_status, sizeof(rx_status));
+			ieee80211_rx_irqsafe(rtwdev->hw, skb);
 		}
 
-		/* skb delivered to mac80211, alloc a new one in rx ring */
-		new = dev_alloc_skb(RTK_PCI_RX_BUF_SIZE);
-		if (WARN(!new, "rx routine starvation\n"))
-			return;
-
+next_rp:
+		/* skb delivered to mac80211, attach the new one into rx ring */
 		ring->buf[cur_rp] = new;
 		rtw_pci_reset_rx_desc(rtwdev, new, ring, cur_rp, buf_desc_sz);
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2019-08-15 20:26 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08  6:32 [PATCH] rtw88/pci: Rearrange the memory usage for skb in RX ISR Jian-Hong Pan
2019-07-08  7:23 ` Tony Chuang
2019-07-08  8:07   ` Jian-Hong Pan
2019-07-08  9:00     ` Tony Chuang
2019-07-08  9:18       ` David Laight
2019-07-08  8:36 ` David Laight
2019-07-08 18:01 ` Larry Finger
2019-07-09 10:20 ` [PATCH v2 1/2] rtw88: pci: " Jian-Hong Pan
2019-07-10  8:36   ` Tony Chuang
2019-07-10  8:54     ` Jian-Hong Pan
2019-07-09 10:21 ` [PATCH v2 2/2] rtw88: pci: Use DMA sync instead of remapping " Jian-Hong Pan
2019-07-09 16:15   ` Christoph Hellwig
2019-07-10  8:38     ` [PATCH v3 1/2] rtw88: pci: Rearrange the memory usage for skb " Jian-Hong Pan
2019-07-10  8:57       ` David Laight
2019-07-11  3:50         ` Jian-Hong Pan
2019-07-11  5:24           ` [PATCH v4 " Jian-Hong Pan
2019-07-11  5:24             ` [PATCH v4 2/2] rtw88: pci: Use DMA sync instead of remapping " Jian-Hong Pan
2019-07-11  5:30               ` Jian-Hong Pan
2019-07-11  5:28             ` [PATCH v4 1/2] rtw88: pci: Rearrange the memory usage for skb " Jian-Hong Pan
2019-07-24  6:13               ` Jian-Hong Pan
2019-07-24 11:49             ` Kalle Valo
2019-08-15 20:25       ` [PATCH v3 " Brian Norris
2019-07-10  8:38     ` [PATCH v3 2/2] rtw88: pci: Use DMA sync instead of remapping " Jian-Hong Pan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).