From patchwork Mon Dec 14 10:06:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fengwei Yin X-Patchwork-Id: 58326 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp1365466lbv; Mon, 14 Dec 2015 02:11:14 -0800 (PST) X-Received: by 10.66.162.38 with SMTP id xx6mr44542120pab.57.1450087874146; Mon, 14 Dec 2015 02:11:14 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e87si16278579pfj.20.2015.12.14.02.11.13; Mon, 14 Dec 2015 02:11:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932282AbbLNKLL (ORCPT + 1 other); Mon, 14 Dec 2015 05:11:11 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:33353 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932226AbbLNKLK (ORCPT ); Mon, 14 Dec 2015 05:11:10 -0500 Received: by pabur14 with SMTP id ur14so102056674pab.0 for ; Mon, 14 Dec 2015 02:11:09 -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=bUwWE9SaMr79m7haYjZaYdbr8HjbDTIkOtm5giQREJ0=; b=CIVyhCQokOw/PnHwK8hYEOuRQG2yQUNpa9VCR7v2gMkZA1sXlCXn+rNNbgk5rdGFBz toyTdvD+uvsS7zOjmd9EgaIhDCb4opMgNt0548fwOhrTjSIrwjYvs4nakNJigh3DTDDY V9xxaWNITucxfofSq0S/MZP0w23a/LP8ivjRCAUUH8loLz+T3fDy72VEmYlMrdQDsmsP BOxKEuMOOo7n8q+eF/MaqN5/nZkIic5Ess1XIsRhpWXwTEUjlDwejJ4hh/zKx6bCT3Sw 9j54HQizle7lQzzD3TemJeYIhd2fa3E5bEBy9uN8RdbzJ8vm/1wPtg1iziw10QljN10f l2ZA== 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=bUwWE9SaMr79m7haYjZaYdbr8HjbDTIkOtm5giQREJ0=; b=C7Z2s80HD/3dco8kbcyS4bDgCPhTgG8vWeeF/sQZAN4kNjU05jYX7hxoOrAhhkC82d Uy59q7mhhe4ALL/abVMIiuJY/gNX0TwX9T+WgnFGuJ5ckBmAD3uu6z9AKaYp8Tdm/VkH QM++dMURPHtjsTCisESxRAJceErv/twmv80JJxHB1i4e5r9Y0m3U1u1MZD+2iLPpvC6X 0vhz61xPDuF5awRlnPepQizNJJtCn0mF23mSK/cp+QwYsFDlh/CBdS4aoCmY2BWj0iMy RSFsA9bxlnJ2Z5nasUl1bKNJJYbjj+rFQ19xo+dSGBUIZO//gDx6ubmhpgD3xgnu+gxa snfQ== X-Gm-Message-State: ALoCoQmLrB0KPRxLUou319OaGNvGe6fjeNwDmgCHMRZ55MnwhpWaMzgaraaJRVyHp0op6/jZqSHDTMbkZ14sr+xwxBaPNlx7gg== X-Received: by 10.66.155.8 with SMTP id vs8mr33528475pab.18.1450087869200; Mon, 14 Dec 2015 02:11:09 -0800 (PST) Received: from localhost.localdomain ([45.116.12.36]) by smtp.googlemail.com with ESMTPSA id 186sm41333549pfa.24.2015.12.14.02.10.46 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Dec 2015 02:11:08 -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: fengwei.yin@linaro.org, lking@qti.qualcomm.com Subject: [PATCH v2] wcn36xx: handle rx skb allocation failure to avoid system crash Date: Mon, 14 Dec 2015 18:06:50 +0800 Message-Id: <1450087610-32477-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 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 --- Changes from v1: * Move switch block out of while loop. * Remove the warning of unknown channel because we didn't deal with it. drivers/net/wireless/ath/wcn36xx/dxe.c | 50 ++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 20 deletions(-) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/wireless/ath/wcn36xx/dxe.c b/drivers/net/wireless/ath/wcn36xx/dxe.c index f8dfa05..6b61874 100644 --- a/drivers/net/wireless/ath/wcn36xx/dxe.c +++ b/drivers/net/wireless/ath/wcn36xx/dxe.c @@ -467,6 +467,18 @@ out_err: } +#define GET_CH_CTRL_VALUE(x) \ + ({ u32 __v = WCN36XX_DXE_CTRL_RX_H; \ + if ((x) == WCN36XX_DXE_CH_RX_L) \ + __v = WCN36XX_DXE_CTRL_RX_L; \ + __v; }) + +#define GET_CH_INT_MASK(x) \ + ({ u32 __v = WCN36XX_DXE_INT_CH3_MASK; \ + if ((x) == WCN36XX_DXE_CH_RX_L) \ + __v = WCN36XX_DXE_INT_CH1_MASK; \ + __v; }) + static int wcn36xx_rx_handle_packets(struct wcn36xx *wcn, struct wcn36xx_dxe_ch *ch) { @@ -474,36 +486,34 @@ 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, int_mask; + u32 value; + + value = GET_CH_CTRL_VALUE(ch->ch_type); + int_mask = GET_CH_INT_MASK(ch->ch_type); while (!(dxe->ctrl & WCN36XX_DXE_CTRL_VALID_MASK)) { skb = ctl->skb; dma_addr = dxe->dst_addr_l; - wcn36xx_dxe_fill_skb(wcn->dev, ctl); - - switch (ch->ch_type) { - case WCN36XX_DXE_CH_RX_L: - dxe->ctrl = WCN36XX_DXE_CTRL_RX_L; - wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_ENCH_ADDR, - WCN36XX_DXE_INT_CH1_MASK); - break; - case WCN36XX_DXE_CH_RX_H: - dxe->ctrl = WCN36XX_DXE_CTRL_RX_H; - wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_ENCH_ADDR, - WCN36XX_DXE_INT_CH3_MASK); - break; - default: - wcn36xx_warn("Unknown channel\n"); - } - - dma_unmap_single(wcn->dev, dma_addr, WCN36XX_PKT_SIZE, - DMA_FROM_DEVICE); - wcn36xx_rx_skb(wcn, skb); + 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); + } /* else keep rx skb not submitted and use for rx DMA again */ + + dxe->ctrl = value; ctl = ctl->next; dxe = ctl->desc; } ch->head_blk_ctl = ctl; + wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_ENCH_ADDR, int_mask); + return 0; }