From patchwork Wed Oct 3 10:52:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10624561 X-Patchwork-Delegate: kvalo@adurom.com 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 276CD14BD for ; Wed, 3 Oct 2018 10:52:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1583E2877F for ; Wed, 3 Oct 2018 10:52:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0966628783; Wed, 3 Oct 2018 10:52:48 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CABA28782 for ; Wed, 3 Oct 2018 10:52:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726714AbeJCRkh (ORCPT ); Wed, 3 Oct 2018 13:40:37 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:34799 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726544AbeJCRkh (ORCPT ); Wed, 3 Oct 2018 13:40:37 -0400 Received: by mail-wm1-f67.google.com with SMTP id z25-v6so7377759wmf.1 for ; Wed, 03 Oct 2018 03:52:45 -0700 (PDT) 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; bh=lK8A+ScLheuUidpAFFkQWJ7iSC3gWLJJAqEZsJcbRqc=; b=c2WYM0VQzRtX9poPGLIFkw7dbdOLf/2x0hYVZ7V0rKhX+KOHS+e+/JV2Z/6RitAW0U x2hoSuyQIC6UznLT/6yR0kKBV7FvT7kdzDfBO5tvNr32deWCKwk6Rr8KkjO9g0GHhq/9 YBdKaGM9F3LzlcmyBVh5LaIigWo/RWXQ61RaCV9Q7JnCHyf5kMSK+qKChPFX4OmOwUTa JVQjoGCdDGUQxBpaZxYo19+38uh581QOPFAbuaFNuA4m6FRj9ZqRdL+tCkIDS92c64fs kAGWCZHc1CAbXjCxO+36YF6EpIFV3fbds6FUmQH8+saIjhNdC7n7a0iIYpLi6PIHNB90 S+7A== X-Gm-Message-State: ABuFfojfJ7HWwTKgSTgYVrIxluNd9bV5RfUdd6rdJasa3uV65d1hMalF AziSks5MpvMsk2atPeDFT7gtYA== X-Google-Smtp-Source: ACcGV62aE1GoI/sCacdGcCBqmHX6W2eLTC8nLgDS2IoDlpYFvFzfkk3FhOVlOGW/nMALXA/LdykIgg== X-Received: by 2002:a1c:d785:: with SMTP id o127-v6mr1029343wmg.67.1538563964821; Wed, 03 Oct 2018 03:52:44 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id e67-v6sm1782486wmd.41.2018.10.03.03.52.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Oct 2018 03:52:44 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 1/3] mt76: fix frag length allocation for usb Date: Wed, 3 Oct 2018 12:52:24 +0200 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Stanislaw Gruszka This is correct fix for c12128ce44b0 ("mt76: use a per rx queue page fragment cache"). We use wrong length when we allocate segments for MCU transmissions, which require bigger segment size than e->buf_size. Commit 481bb0432414 ("mt76: usb: make rx page_frag_cache access atomic") partially solved the problem or actually mask it by changing mt76u_mcu_init_rx() and mt76u_alloc_queues() sequence, so e->buf_size become non zero any longer, but still not big enough to handle MCU data. Patch fixes memory corruption which can manifest itself as random, not easy to reproduce crashes, during mt76 driver load or unload. Fixes: c12128ce44b0 ("mt76: use a per rx queue page fragment cache") Signed-off-by: Stanislaw Gruszka Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index de7785c4f6af..6b643ea701e3 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -286,7 +286,7 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76u_buf *buf, void *data; int offset; - data = page_frag_alloc(&q->rx_page, q->buf_size, GFP_ATOMIC); + data = page_frag_alloc(&q->rx_page, len, GFP_ATOMIC); if (!data) break; From patchwork Wed Oct 3 10:52:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10624563 X-Patchwork-Delegate: kvalo@adurom.com 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 55E2214BD for ; Wed, 3 Oct 2018 10:52:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 454572877F for ; Wed, 3 Oct 2018 10:52:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 399E028789; Wed, 3 Oct 2018 10:52:49 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B89A42877F for ; Wed, 3 Oct 2018 10:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbeJCRki (ORCPT ); Wed, 3 Oct 2018 13:40:38 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50881 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726672AbeJCRki (ORCPT ); Wed, 3 Oct 2018 13:40:38 -0400 Received: by mail-wm1-f66.google.com with SMTP id s12-v6so5256707wmc.0 for ; Wed, 03 Oct 2018 03:52:46 -0700 (PDT) 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; bh=TSEv2vUvKB9r0vVrv7TCSAr6fVWwxOkn09lQHCUCYF8=; b=A6odrBWTgJYVn4ATXa0nM/f4JhHtPIiwPESxuZrnJ9eNmXegltbQy5skt9wUqioUFV 6p3SLPJGsLJxhAQDLwUYPYl19x2pWaX/DgBPQpImNJzTlwLBho0091wauXwhds690mOQ NT+8Q6Y+wMmYwIsv0YGXNhNu4wqXQriwLpfvUz4hHrBhIp7Q9YBSM6LaEykHliKfhbFK ccsZ2ywUQIlGoyS6XhSjZ/B6iPYhZoBxiBiEKKMrko93uhVUHseF5o1uIuRdBiNNvbnA YDHfOVoutV7CZNI+bmSik/0eAkRNTkWeDeHyurcCmZnTIYpnDcNB7Nj4zjkDo0aXcXUt X69Q== X-Gm-Message-State: ABuFfoiJKJztBX5cC8OSKTYSHcnm9qGexwqiK2UhWSLvmwdaobHU7gaq HMkmx1UYYL8Bzmoq7FOlrnHKS4Vp1KA= X-Google-Smtp-Source: ACcGV63gDjrzGTcYBupDl6rILTceDM6jq4tm5wSDlWMOys6loDjcwFDd3D/+DblAqC/tH0KeGlgSMg== X-Received: by 2002:a1c:3795:: with SMTP id e143-v6mr1095552wma.9.1538563965731; Wed, 03 Oct 2018 03:52:45 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id e67-v6sm1782486wmd.41.2018.10.03.03.52.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Oct 2018 03:52:45 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 2/3] mt76: usb: fix hw initialization sequence Date: Wed, 3 Oct 2018 12:52:25 +0200 Message-Id: <33c6a1ce2525c59fd90c01e7af19a9f0e0b462a8.1538563675.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mt76u_alloc_queues need to be called before mt76u_mcu_init_rx since it initializes rx_page_lock spinlock used in mt76u_buf_alloc routine. Fixes: b11e19694dc9 ("mt76x0: add ieee80211_ops ops pointer to mt76x0_alloc_device signature") Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/usb.c | 18 +++++++++--------- .../wireless/mediatek/mt76/mt76x2/usb_init.c | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c index a76043213f55..dd437e77009f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c @@ -179,28 +179,28 @@ static int mt76x0u_register_device(struct mt76x0_dev *dev) struct ieee80211_hw *hw = dev->mt76.hw; int err; - err = mt76u_mcu_init_rx(&dev->mt76); + err = mt76u_alloc_queues(&dev->mt76); if (err < 0) - return err; + goto out_err; - err = mt76u_alloc_queues(&dev->mt76); + err = mt76u_mcu_init_rx(&dev->mt76); if (err < 0) - return err; + goto out_err; mt76x0_chip_onoff(dev, true, true); if (!mt76x02_wait_for_mac(&dev->mt76)) { err = -ETIMEDOUT; - goto err; + goto out_err; } err = mt76x0u_mcu_init(dev); if (err < 0) - goto err; + goto out_err; mt76x0_init_usb_dma(dev); err = mt76x0_init_hardware(dev); if (err < 0) - goto err; + goto out_err; mt76_rmw(dev, MT_US_CYC_CFG, MT_US_CYC_CNT, 0x1e); mt76_wr(dev, MT_TXOP_CTRL_CFG, @@ -209,7 +209,7 @@ static int mt76x0u_register_device(struct mt76x0_dev *dev) err = mt76x0_register_device(dev); if (err < 0) - goto err; + goto out_err; /* check hw sg support in order to enable AMSDU */ if (mt76u_check_sg(&dev->mt76)) @@ -221,7 +221,7 @@ static int mt76x0u_register_device(struct mt76x0_dev *dev) return 0; -err: +out_err: mt76x0u_cleanup(dev); return err; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c index 55e0dea568b8..a8222447d805 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c @@ -262,7 +262,7 @@ int mt76x2u_register_device(struct mt76x2_dev *dev) err = mt76u_mcu_init_rx(&dev->mt76); if (err < 0) - return err; + goto fail; err = mt76x2u_init_hardware(dev); if (err < 0) From patchwork Wed Oct 3 10:52:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10624565 X-Patchwork-Delegate: kvalo@adurom.com 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 0E39E14BD for ; Wed, 3 Oct 2018 10:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0BCC2877F for ; Wed, 3 Oct 2018 10:52:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E542028783; Wed, 3 Oct 2018 10:52:49 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E2E02877F for ; Wed, 3 Oct 2018 10:52:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726747AbeJCRkj (ORCPT ); Wed, 3 Oct 2018 13:40:39 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37678 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726544AbeJCRkj (ORCPT ); Wed, 3 Oct 2018 13:40:39 -0400 Received: by mail-wm1-f66.google.com with SMTP id 185-v6so5168569wmt.2 for ; Wed, 03 Oct 2018 03:52:47 -0700 (PDT) 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; bh=wll6P2h9sxl8LMKiwvb5DQelkbRPuFgjlIQkJ2BrnGc=; b=WRJz58ECIZs2aHVzQCBp+zwZS6Y9+XOSi8f7VVKEh9fMi3SguyxJlSO7vlWTs+CWTj 578tDr66wpVcFQ8koiRXQ5KDiUVRN/olgE5aK67IsPBShpSg1w9H7kgthitOGxtEoNx+ 5hB1p6GjGenfqFqHNyx4rOmunJlsuIT061MTlhk6p0VsjakE5VhSDq7ou41eq7TiPqW8 F7dccQD6XeoeYEWLb8dI5g1PilLltX09uyPRBrwt5S8lnf8BDgv8qwao1ktoXugKq1e2 gicqBtyBmr/cEF++ImXVLHLx8GuAu9RBa0brQn4Dy1Zny3dxZgeFmjD6RqJPkJUG4nh1 ZLkg== X-Gm-Message-State: ABuFfojA2tl8t511YuYPuzP65iM90l2/ohFcItaGQnictz3BGQdhnqh/ +Ku5o+/s0p4TMWheobgiP5olxUgi9vA= X-Google-Smtp-Source: ACcGV60Du+wKLtaTzJElFGifXyEeHHq62My1sSHM2sFzh+0kybnV4CB2YyNToyg8zoYzoAZDzlbZiQ== X-Received: by 2002:a7b:c017:: with SMTP id c23-v6mr1094435wmb.136.1538563966692; Wed, 03 Oct 2018 03:52:46 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id e67-v6sm1782486wmd.41.2018.10.03.03.52.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Oct 2018 03:52:46 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 3/3] mt76x0: usb: stop cal/mac workqueues at hw stop Date: Wed, 3 Oct 2018 12:52:26 +0200 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Stop mac and calibration work stopping the hw even if the device has been removed Fixes: b11e19694dc9 ("mt76x0: add ieee80211_ops ops pointer to mt76x0_alloc_device signature") Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76x0/usb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c index dd437e77009f..57862cacf22a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c @@ -86,14 +86,14 @@ static void mt76x0u_cleanup(struct mt76x0_dev *dev) static void mt76x0u_mac_stop(struct mt76x0_dev *dev) { - if (test_bit(MT76_REMOVED, &dev->mt76.state)) - return; - clear_bit(MT76_STATE_RUNNING, &dev->mt76.state); cancel_delayed_work_sync(&dev->cal_work); cancel_delayed_work_sync(&dev->mac_work); mt76u_stop_stat_wk(&dev->mt76); + if (test_bit(MT76_REMOVED, &dev->mt76.state)) + return; + mt76_clear(dev, MT_BEACON_TIME_CFG, MT_BEACON_TIME_CFG_TIMER_EN | MT_BEACON_TIME_CFG_SYNC_MODE | MT_BEACON_TIME_CFG_TBTT_EN | MT_BEACON_TIME_CFG_BEACON_TX);