Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5985845rwj; Wed, 21 Dec 2022 09:20:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXuVff9HHS/o6s5XRymZNtuuU7HNJp6zt1CAZ0Ce/SUdGGW5S4SMwV0B7Jr+3YMemHXenCoG X-Received: by 2002:a05:6a20:6f47:b0:a3:7d0b:5dcb with SMTP id gu7-20020a056a206f4700b000a37d0b5dcbmr17889008pzb.15.1671643259310; Wed, 21 Dec 2022 09:20:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671643259; cv=none; d=google.com; s=arc-20160816; b=zekh5238DHSNvRv+8vF8jKLkaAgL4LU0RIHCdYbaivq0n0VFVXjJQnFXgs/KE2LzYl IUVx9gP4dEE6DPRf6sNGOaFRZaNCTCnehPmsAjD2/DXmkjQN5kAEoj5cwqbgoozUS1Mc cGN5ffet1x3nCdc/ZPVLT2jFEUpi8BDd74s2BFvQL8mWlWhe2tr0bBcMCHUjOF/uN5eT HFyGOQAir/0PnVHqTiKyZBuH55J1jAVpKgaJEJgGH1M1vMW8jlRgadHwkyPJ6p/cq9UX cBaRhnjmA7xPL8Wz2Sjt7HgK5/jl3S0VK891hMroNk4uoSoahD/u/SFNXJ5KXc/1oft3 EYiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=5NQmoVw/q+8tvK2V4iRPmDMASULYZoPw14pX4rYwT4A=; b=oeGY8iLxXL3t5XIEdR/QLlUzOm0WymXbEo0mGfw4luzBilu81zk+3FR5HeLyu/cCtw 6fhJnxQhnimlOqbK/2v8UkjzhNtfaBk2rw9Nh1/HouSRFCHGOe/FyHCnORkKgnqokUNL G7NItNiYjxFo/zU5QSGEVolJ2v4E+4TuDN5Qo0uA4tmlCCiDEHAnNHoL6K+vEKkVOwGR wUq8ugFF063f9eAHRdKea1D1TLcLPIAQQxIR8P/kAip0bTn12e9Vg7qEqrIeDqaMW+7m 71fA4V4LNQbBGkqp0bExsheY27BakHDpYhcAU7g/V9tugW72b9nSXTCkG1oOFI9aAyzL X/Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=E4Y1LY7c; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i184-20020a6387c1000000b0047865b303a5si17302310pge.762.2022.12.21.09.20.48; Wed, 21 Dec 2022 09:20:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=E4Y1LY7c; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234887AbiLURSa (ORCPT + 66 others); Wed, 21 Dec 2022 12:18:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234831AbiLURRy (ORCPT ); Wed, 21 Dec 2022 12:17:54 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65D6F64CC; Wed, 21 Dec 2022 09:17:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5NQmoVw/q+8tvK2V4iRPmDMASULYZoPw14pX4rYwT4A=; b=E4Y1LY7caA9JODGRL9bGLDuFlX ViUy7CY6OeLy2kulFlgUTl10dcq9zU5QzOLVVP3z3yOI5IkKdvPfksiET7T3rTJTioWn87fdKm3mt +rpgLeWHCYHP99FJtDfIqdrCcotbjX/LeTXqR2p1naZOs7ywIHuQqXvg0wRE1m6r8U7o=; Received: from p200300daa720fc02a80cecba4b8062d5.dip0.t-ipconnect.de ([2003:da:a720:fc02:a80c:ecba:4b80:62d5] helo=nf.local) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1p82iD-00AdKg-7f; Wed, 21 Dec 2022 18:17:01 +0100 Message-ID: <3cb53fbd-0bee-22f9-bba2-6ac4a87db521@nbd.name> Date: Wed, 21 Dec 2022 18:17:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [6.2][regression] after commit cd372b8c99c5a5cf6a464acebb7e4a79af7ec8ae stopping working wifi mt7921e Content-Language: en-US To: Mikhail Gavrilov Cc: lorenzo@kernel.org, sujuan.chen@mediatek.com, Linux List Kernel Mailing , Linux List Kernel Mailing References: <678adc67-9e46-3eef-f274-c951b121570f@nbd.name> From: Felix Fietkau In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On 21.12.22 17:46, Mikhail Gavrilov wrote: > On Wed, Dec 21, 2022 at 7:12 PM Felix Fietkau wrote: >> >> Thanks! I guess I focused on the wrong part of your kernel log >> initially. After more code review, I found that there is in fact a DMA >> related bug in the commit that your bisection pointed to, which happened >> to uncover and trigger the deadlock fixed by my other patch. >> >> So here's my fix for the DMA issue: >> --- > [cutted] >> qbuf.skip_unmap = false; >> - if (mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t) < 0) { >> + if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf) < 0) { >> dma_unmap_single(dev->dma_dev, addr, len, >> DMA_FROM_DEVICE); >> skb_free_frag(buf); >> > > Sorry for stupid question. > > Do you have a separate branch? > I see that the code is differ between master branch and the patch. > > For example in patch the line: > - if (mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t) < 0) { > replaced by the line: > + if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf) < 0) { > > But in master branch > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/wireless/mediatek/mt76/dma.c?id=b6bb9676f2165d518b35ba3bea5f1fcfc0d969bf#n604 > after line: > qbuf.skip_unmap = false; > followed the line: > mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t); > without if condition. > > So I'm stuck applying the patch :( Sorry, I worked on a tree that had other pending fixes applied. Please try this: --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -205,6 +205,52 @@ mt76_dma_queue_reset(struct mt76_dev *dev, struct mt76_queue *q) mt76_dma_sync_idx(dev, q); } +static int +mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q, + struct mt76_queue_buf *buf, void *data) +{ + struct mt76_desc *desc = &q->desc[q->head]; + struct mt76_queue_entry *entry = &q->entry[q->head]; + struct mt76_txwi_cache *txwi = NULL; + u32 buf1 = 0, ctrl; + int idx = q->head; + int rx_token; + + ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len); + + if ((q->flags & MT_QFLAG_WED) && + FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_RX) { + txwi = mt76_get_rxwi(dev); + if (!txwi) + return -ENOMEM; + + rx_token = mt76_rx_token_consume(dev, data, txwi, buf->addr); + if (rx_token < 0) { + mt76_put_rxwi(dev, txwi); + return -ENOMEM; + } + + buf1 |= FIELD_PREP(MT_DMA_CTL_TOKEN, rx_token); + ctrl |= MT_DMA_CTL_TO_HOST; + } + + WRITE_ONCE(desc->buf0, cpu_to_le32(buf->addr)); + WRITE_ONCE(desc->buf1, cpu_to_le32(buf1)); + WRITE_ONCE(desc->ctrl, cpu_to_le32(ctrl)); + WRITE_ONCE(desc->info, 0); + + entry->dma_addr[0] = buf->addr; + entry->dma_len[0] = buf->len; + entry->txwi = txwi; + entry->buf = data; + entry->wcid = 0xffff; + entry->skip_buf1 = true; + q->head = (q->head + 1) % q->ndesc; + q->queued++; + + return idx; +} + static int mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q, struct mt76_queue_buf *buf, int nbufs, u32 info, @@ -212,65 +258,51 @@ mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q, { struct mt76_queue_entry *entry; struct mt76_desc *desc; - u32 ctrl; int i, idx = -1; + u32 ctrl, next; + + if (txwi) { + q->entry[q->head].txwi = DMA_DUMMY_DATA; + q->entry[q->head].skip_buf0 = true; + } for (i = 0; i < nbufs; i += 2, buf += 2) { u32 buf0 = buf[0].addr, buf1 = 0; idx = q->head; - q->head = (q->head + 1) % q->ndesc; + next = (q->head + 1) % q->ndesc; desc = &q->desc[idx]; entry = &q->entry[idx]; - if ((q->flags & MT_QFLAG_WED) && - FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_RX) { - struct mt76_txwi_cache *t = txwi; - int rx_token; - - if (!t) - return -ENOMEM; - - rx_token = mt76_rx_token_consume(dev, (void *)skb, t, - buf[0].addr); - buf1 |= FIELD_PREP(MT_DMA_CTL_TOKEN, rx_token); - ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len) | - MT_DMA_CTL_TO_HOST; - } else { - if (txwi) { - q->entry[q->head].txwi = DMA_DUMMY_DATA; - q->entry[q->head].skip_buf0 = true; - } - - if (buf[0].skip_unmap) - entry->skip_buf0 = true; - entry->skip_buf1 = i == nbufs - 1; - - entry->dma_addr[0] = buf[0].addr; - entry->dma_len[0] = buf[0].len; - - ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len); - if (i < nbufs - 1) { - entry->dma_addr[1] = buf[1].addr; - entry->dma_len[1] = buf[1].len; - buf1 = buf[1].addr; - ctrl |= FIELD_PREP(MT_DMA_CTL_SD_LEN1, buf[1].len); - if (buf[1].skip_unmap) - entry->skip_buf1 = true; - } - - if (i == nbufs - 1) - ctrl |= MT_DMA_CTL_LAST_SEC0; - else if (i == nbufs - 2) - ctrl |= MT_DMA_CTL_LAST_SEC1; + if (buf[0].skip_unmap) + entry->skip_buf0 = true; + entry->skip_buf1 = i == nbufs - 1; + + entry->dma_addr[0] = buf[0].addr; + entry->dma_len[0] = buf[0].len; + + ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len); + if (i < nbufs - 1) { + entry->dma_addr[1] = buf[1].addr; + entry->dma_len[1] = buf[1].len; + buf1 = buf[1].addr; + ctrl |= FIELD_PREP(MT_DMA_CTL_SD_LEN1, buf[1].len); + if (buf[1].skip_unmap) + entry->skip_buf1 = true; } + if (i == nbufs - 1) + ctrl |= MT_DMA_CTL_LAST_SEC0; + else if (i == nbufs - 2) + ctrl |= MT_DMA_CTL_LAST_SEC1; + WRITE_ONCE(desc->buf0, cpu_to_le32(buf0)); WRITE_ONCE(desc->buf1, cpu_to_le32(buf1)); WRITE_ONCE(desc->info, cpu_to_le32(info)); WRITE_ONCE(desc->ctrl, cpu_to_le32(ctrl)); + q->head = next; q->queued++; } @@ -577,17 +609,9 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) spin_lock_bh(&q->lock); while (q->queued < q->ndesc - 1) { - struct mt76_txwi_cache *t = NULL; struct mt76_queue_buf qbuf; void *buf = NULL; - if ((q->flags & MT_QFLAG_WED) && - FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_RX) { - t = mt76_get_rxwi(dev); - if (!t) - break; - } - buf = page_frag_alloc(rx_page, q->buf_size, GFP_ATOMIC); if (!buf) break; @@ -601,7 +625,12 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) qbuf.addr = addr + offset; qbuf.len = len - offset; qbuf.skip_unmap = false; - mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t); + if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf) < 0) { + dma_unmap_single(dev->dma_dev, addr, len, + DMA_FROM_DEVICE); + skb_free_frag(buf); + break; + } frames++; } --- a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c @@ -653,6 +653,13 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) desc->buf0 = cpu_to_le32(phy_addr); token = mt76_rx_token_consume(&dev->mt76, ptr, t, phy_addr); + if (token < 0) { + dma_unmap_single(dev->mt76.dma_dev, phy_addr, + wed->wlan.rx_size, DMA_TO_DEVICE); + skb_free_frag(ptr); + goto unmap; + } + desc->token |= cpu_to_le32(FIELD_PREP(MT_DMA_CTL_TOKEN, token)); desc++; --- a/drivers/net/wireless/mediatek/mt76/tx.c +++ b/drivers/net/wireless/mediatek/mt76/tx.c @@ -764,11 +764,12 @@ int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, spin_lock_bh(&dev->rx_token_lock); token = idr_alloc(&dev->rx_token, t, 0, dev->rx_token_size, GFP_ATOMIC); + if (token >= 0) { + t->ptr = ptr; + t->dma_addr = phys; + } spin_unlock_bh(&dev->rx_token_lock); - t->ptr = ptr; - t->dma_addr = phys; - return token; } EXPORT_SYMBOL_GPL(mt76_rx_token_consume);