From patchwork Wed Apr 17 19:15:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erik Stromdahl X-Patchwork-Id: 10906021 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3FCD1515 for ; Wed, 17 Apr 2019 19:15:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA18528ABE for ; Wed, 17 Apr 2019 19:15:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EAEA28AF8; Wed, 17 Apr 2019 19:15:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 43F3328A92 for ; Wed, 17 Apr 2019 19:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RORGojVAK78cohuzEyFivrvGuF0u5y/5wyxcug0v+tU=; b=shpVIvYdU6A+Fo cPHJbViQ1zkHj/OBcP5/gWDbYk5PPgSskKRSmtcQuSVJDNjcQ8shUW/iHBaGiPb+Lh/XZiL8RN19/ POf7SADbJU/SmcDlYxwnA4jNWljdQjk8LF4X8Rm+sg/VpYlYU2W98TX+IyexzgixVmUBtMRtBeIL8 paLid9P5W5IzueITGoYPfxuVspRXzobIkz+p3Jg9al9dntu27rIXw4JInh29kTSNeNfvGmp+P4RQh 4GXblQV/4UYQbrFraQk+E6EGfcu8b1NM67EhWcN6dHCi79UhBnNzKJJX4c29QufezP0TfzK4TidBa Kpzp5aD5yWmIlb+J36zA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGq25-0007aO-3F; Wed, 17 Apr 2019 19:15:45 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGq1r-0007GD-Pa for ath10k@lists.infradead.org; Wed, 17 Apr 2019 19:15:35 +0000 Received: by mail-lf1-x141.google.com with SMTP id u17so19748135lfi.3 for ; Wed, 17 Apr 2019 12:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bW57d87UKSeqIsF8dbOx4NI+/s5uPkAlrYgKadNV5CU=; b=ipeoyJLUSK1sgKEIGYNZc7AtuOTanB0QLIg82Pxv6xHgUAFsOBPcxWqvc5a0U/TRdP xpVSuWa6K0ni39eqUWbUu3Kr9VasrS7w9MmmRhschM0irJXSMpCYt2A6Xolk6cvoXaYj RzYCXo6JNgNl6BjeOmXrdd40MpJXz0k+hsG1KdkVad6cAmRKkFcPVRH4sbNyP6Iyk9Ix 9uKoZ1pZubGjkZk6Anu8c9/5wuI4gJ9+gb/u7/5b5KbTEcdUMRmoJDVkzsxdmWoGdR8E eLHush5B6Esrv9sotiDkcBTks11oVWlf9vIqPcTDVp1+w4k36UpZd5vHJKxeqeKxfvqe l5kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bW57d87UKSeqIsF8dbOx4NI+/s5uPkAlrYgKadNV5CU=; b=Hr4WWL1fV4pp3P1j9f0Yx051TxF5q263nUo4wSn5SpW2KYCuMBY4CKx8xMDs8gVxev QnuFf3I6NIs/jMWgPmCveE8bXT74hDHfwjOfeoxRdd4Ofj8V6iRzgxb0I4t6HauW9M+x /u/WVEhXdCY+bAY+6sCY2zf4Lne+XzcRaAvjxNSRj9GGzb+tstZ7J0ITP0iovItAH+d6 jrT+O2+yG21WcvvNKc0AJ6UVzOooLL39AN0kH7MQWKV1Dlv+TCrS1n6e8HWe+OKIOVgT Wqgr+3+ajmEgtKb6uPO5ByWJrXBrFS++yiXbS8TcoW/8VCfetSEaIxXe2wMbFao5JUFk vsjQ== X-Gm-Message-State: APjAAAU/znr1x2c1+Dx8GjjVwEGbsySRmHoA0GBVb/euCCsKL5qBgQnd VU+88YGFnqh4jdrsZNUMCbY= X-Google-Smtp-Source: APXvYqwt2YzwEQJL9qpjMFhkzMgeb0xAgnsFJgQoyNqCUFu+PJSZAgHrnK7eeL+AseZOvbEcdjJUQQ== X-Received: by 2002:ac2:5326:: with SMTP id f6mr27181776lfh.100.1555528530172; Wed, 17 Apr 2019 12:15:30 -0700 (PDT) Received: from localhost.localdomain (81-233-89-221-no75.tbcn.telia.com. [81.233.89.221]) by smtp.gmail.com with ESMTPSA id j27sm11387203lfk.97.2019.04.17.12.15.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 12:15:29 -0700 (PDT) From: Erik Stromdahl To: kvalo@qca.qualcomm.com, linux-wireless@vger.kernel.org, ath10k@lists.infradead.org Subject: [PATCH v2 5/5] ath10k: sdio: remove skb_trim in TX path Date: Wed, 17 Apr 2019 21:15:03 +0200 Message-Id: <20190417191503.18814-6-erik.stromdahl@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190417191503.18814-1-erik.stromdahl@gmail.com> References: <20190417191503.18814-1-erik.stromdahl@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190417_121531_988024_6B5E1F1E X-CRM114-Status: GOOD ( 15.45 ) X-BeenThere: ath10k@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Erik Stromdahl Sender: "ath10k" Errors-To: ath10k-bounces+patchwork-ath10k=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes a bug with padding of the skb data buffer. Since skb_trim can only be used to reduce the skb len, it is useless when we pad (increase the length of) the skb. Instead we allocate a new buffer with enough space to contain both the TX data and padding. Since some skb's have multiple references, we can't use skb_put_padto() to extend and pad skb->data (since it causes a panic if there is more than one reference). Also, in order to avoid the following possible deadlock issue (reported by lockdep): [ 26.508508] Possible interrupt unsafe locking scenario: [ 26.508508] [ 26.515314] CPU0 CPU1 [ 26.519862] ---- ---- [ 26.524408] lock(fs_reclaim); [ 26.527573] local_irq_disable(); [ 26.533508] lock(_xmit_ETHER#2); [ 26.539453] lock(fs_reclaim); [ 26.545135] [ 26.547769] lock(_xmit_ETHER#2); [ 26.551370] [ 26.551370] *** DEADLOCK *** ... we use the GFP_NOFS flag with kzalloc() Signed-off-by: Erik Stromdahl --- drivers/net/wireless/ath/ath10k/sdio.c | 27 ++++++++++++++++++++------ drivers/net/wireless/ath/ath10k/sdio.h | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/sdio.c b/drivers/net/wireless/ath/ath10k/sdio.c index b8b3059721ee..68d8e2d1b2ed 100644 --- a/drivers/net/wireless/ath/ath10k/sdio.c +++ b/drivers/net/wireless/ath/ath10k/sdio.c @@ -1279,6 +1279,7 @@ static void ath10k_sdio_free_bus_req(struct ath10k *ar, { struct ath10k_sdio *ar_sdio = ath10k_sdio_priv(ar); + kfree(bus_req->buf); memset(bus_req, 0, sizeof(*bus_req)); spin_lock_bh(&ar_sdio->lock); @@ -1294,7 +1295,7 @@ static void __ath10k_sdio_write_async(struct ath10k *ar, int ret; skb = req->skb; - ret = ath10k_sdio_write(ar, req->address, skb->data, skb->len); + ret = ath10k_sdio_write(ar, req->address, req->buf, req->buf_len); if (ret) ath10k_warn(ar, "failed to write skb to 0x%x asynchronously: %d", req->address, ret); @@ -1330,6 +1331,7 @@ static void ath10k_sdio_write_async_work(struct work_struct *work) static int ath10k_sdio_prep_async_req(struct ath10k *ar, u32 addr, struct sk_buff *skb, + size_t alloc_len, struct completion *comp, bool htc_msg, enum ath10k_htc_ep_id eid) { @@ -1343,9 +1345,17 @@ static int ath10k_sdio_prep_async_req(struct ath10k *ar, u32 addr, if (!bus_req) { ath10k_warn(ar, "unable to allocate bus request for async request\n"); - return -ENOMEM; + goto err; } + bus_req->buf_len = alloc_len; + bus_req->buf = kzalloc(alloc_len, GFP_NOFS); + if (!bus_req->buf) { + ath10k_warn(ar, + "unable to allocate data buffer for bus request\n"); + goto err_free_bus_req; + } + memcpy(bus_req->buf, skb->data, skb->len); bus_req->skb = skb; bus_req->eid = eid; bus_req->address = addr; @@ -1357,6 +1367,11 @@ static int ath10k_sdio_prep_async_req(struct ath10k *ar, u32 addr, spin_unlock_bh(&ar_sdio->wr_async_lock); return 0; + +err_free_bus_req: + ath10k_sdio_free_bus_req(ar, bus_req); +err: + return -ENOMEM; } /* IRQ handler */ @@ -1501,12 +1516,11 @@ static int ath10k_sdio_hif_tx_sg(struct ath10k *ar, u8 pipe_id, skb = items[i].transfer_context; padded_len = ath10k_sdio_calc_txrx_padded_len(ar_sdio, skb->len); - skb_trim(skb, padded_len); /* Write TX data to the end of the mbox address space */ address = ar_sdio->mbox_addr[eid] + ar_sdio->mbox_size[eid] - - skb->len; - ret = ath10k_sdio_prep_async_req(ar, address, skb, + padded_len; + ret = ath10k_sdio_prep_async_req(ar, address, skb, padded_len, NULL, true, eid); if (ret) return ret; @@ -1761,7 +1775,8 @@ static void ath10k_sdio_irq_disable(struct ath10k *ar) init_completion(&irqs_disabled_comp); ret = ath10k_sdio_prep_async_req(ar, MBOX_INT_STATUS_ENABLE_ADDRESS, - skb, &irqs_disabled_comp, false, 0); + skb, skb->len, &irqs_disabled_comp, + false, 0); if (ret) goto out; diff --git a/drivers/net/wireless/ath/ath10k/sdio.h b/drivers/net/wireless/ath/ath10k/sdio.h index 07e2cc6a3bd8..5a727993fbda 100644 --- a/drivers/net/wireless/ath/ath10k/sdio.h +++ b/drivers/net/wireless/ath/ath10k/sdio.h @@ -105,6 +105,8 @@ struct ath10k_sdio_bus_request { u32 address; struct sk_buff *skb; + u8 *buf; + size_t buf_len; enum ath10k_htc_ep_id eid; int status; /* Specifies if the current request is an HTC message.