From patchwork Wed Dec 2 05:27:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fengwei Yin X-Patchwork-Id: 7742511 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DE2789F39D for ; Wed, 2 Dec 2015 05:30:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F10EE20638 for ; Wed, 2 Dec 2015 05:30:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 309362062C for ; Wed, 2 Dec 2015 05:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750963AbbLBFae (ORCPT ); Wed, 2 Dec 2015 00:30:34 -0500 Received: from mail-pa0-f45.google.com ([209.85.220.45]:33272 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750947AbbLBFad (ORCPT ); Wed, 2 Dec 2015 00:30:33 -0500 Received: by pabfh17 with SMTP id fh17so30267843pab.0 for ; Tue, 01 Dec 2015 21:30:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=URhZvircF6cnFi1VieObwqf0yTeqg1IpbHzf5YaOAqU=; b=hnFMGXyYzXOH6l1P3fEJ4UsbO4T1rMtnGqlDkuLAZXjR36kiK7HbMk0lqXhA7V14PO 4DUeR8XQjga4Ul6Jbwg/+zQZTMyU7hkFegcNnxu/IGTtg+7xRs/xiCcOrvETs2dYPrOt KOfjwJ7Dyn+h9HSsmxGgg1IRoK8foKQ+r1DUOoo+dydwMgQVrZRxEY8jhFX601QEVdej 8G7xNN25CGkP/tuYjA4mUKUWDOQWt4ewN/y7wp7wFLC8XGP0KNxqEBhS8tCj9pgUUHc9 gJEBOTLWC4jlL2jTIFrw4O3FDw01TULC1xaG4yW63gCN2inujMLNVyhVPqQxmmCs7o0h jgdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=URhZvircF6cnFi1VieObwqf0yTeqg1IpbHzf5YaOAqU=; b=PsyupQSeOLjaVN8Xq+w4Jp9vQktBSvELfEaanKg57Y8XIenhvV5lerKSMcWXlE5tR/ sGdsSrU/mn/NxLS9on3RjO/ztS4kK0AEyIRUd5m8RzD/pOhMKwD3zQdv8D7YBe2kqcp3 vZ73jrfipgxgF76vAwoAMkTMroRKHHiUP+Es86HSbzXh2Ec0V1S7Zvzep7qc8AUAvSiM zFhFVLuPE2yP87HSeSqaKdM/ehK/c7a9IRwcM6zkb8cpskMHdywHlrgEgXjF6cwRO6jB SMu8/MVZK+E61XHa4J6ZKUn+7Zv2W/bImN1yn8fGe/T2818hIL2ifspCU27qBCWKyWTc TP+A== X-Gm-Message-State: ALoCoQnq2CUXRyIlTWpJmmMZXZ7JTKTNo5S9KUC0SQVw14NAmH9xnZ2PFEJoACp1w2yFaaz9+g2L X-Received: by 10.66.120.47 with SMTP id kz15mr1913157pab.84.1449034233303; Tue, 01 Dec 2015 21:30:33 -0800 (PST) Received: from localhost.localdomain ([45.116.12.36]) by smtp.googlemail.com with ESMTPSA id n16sm1342340pfa.53.2015.12.01.21.30.27 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 Dec 2015 21:30:32 -0800 (PST) From: Fengwei Yin To: linux-wireless@vger.kernel.org, wcn36xx@lists.infradead.org, me@bobcopeland.com, k.eugene.e@gmail.com, bjorn.andersson@sonymobile.com Cc: lking@qti.qualcomm.com, fengwei.yin@linaro.org Subject: [PATCH] wcn36xx: handle rx skb allocation failure to avoid system crash Date: Wed, 2 Dec 2015 13:27:31 +0800 Message-Id: <1449034051-12536-1-git-send-email-fengwei.yin@linaro.org> X-Mailer: git-send-email 2.1.4 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Lawrence reported that git clone could make system crash on a Qualcomm ARM soc based device (DragonBoard, 1G memory without swap) running 64bit Debian. It's turned out the crash is related with rx skb allocation failure. git could consume more than 600MB anonymous memory. And system is in extremely memory shortage case. But driver didn't handle the rx allocation failure case. This patch doesn't submit skb to upper layer if rx skb allocation fails. Instead, it reuse the old skb for rx DMA again. It's more like drop the packets if system is in memory shortage case. With this change, git clone is OOMed instead of system crash. Reported-by: King, Lawrence Signed-off-by: Fengwei Yin --- drivers/net/wireless/ath/wcn36xx/dxe.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/wcn36xx/dxe.c b/drivers/net/wireless/ath/wcn36xx/dxe.c index f8dfa05..8887c0f 100644 --- a/drivers/net/wireless/ath/wcn36xx/dxe.c +++ b/drivers/net/wireless/ath/wcn36xx/dxe.c @@ -474,11 +474,20 @@ static int wcn36xx_rx_handle_packets(struct wcn36xx *wcn, struct wcn36xx_dxe_desc *dxe = ctl->desc; dma_addr_t dma_addr; struct sk_buff *skb; + int ret = 0; while (!(dxe->ctrl & WCN36XX_DXE_CTRL_VALID_MASK)) { skb = ctl->skb; dma_addr = dxe->dst_addr_l; - wcn36xx_dxe_fill_skb(wcn->dev, ctl); + ret = wcn36xx_dxe_fill_skb(wcn->dev, ctl); + if (0 == ret) { + /* new skb allocation ok. Use the new one and queue + * the old one to network system. + */ + dma_unmap_single(wcn->dev, dma_addr, WCN36XX_PKT_SIZE, + DMA_FROM_DEVICE); + wcn36xx_rx_skb(wcn, skb); + } switch (ch->ch_type) { case WCN36XX_DXE_CH_RX_L: @@ -495,9 +504,6 @@ static int wcn36xx_rx_handle_packets(struct wcn36xx *wcn, wcn36xx_warn("Unknown channel\n"); } - dma_unmap_single(wcn->dev, dma_addr, WCN36XX_PKT_SIZE, - DMA_FROM_DEVICE); - wcn36xx_rx_skb(wcn, skb); ctl = ctl->next; dxe = ctl->desc; }