Message ID | 20230423082403.49143-1-mirsad.todorovac@alu.unizg.hr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2095783vqo; Sun, 23 Apr 2023 01:57:52 -0700 (PDT) X-Google-Smtp-Source: AKy350b3VAt7zi1fw3n6+3Ua+hupjOzSVaHChCjVzsBd8Kxwb280MgkGvVWIV6U9sPr7oIIfO4ai X-Received: by 2002:a05:6a00:1806:b0:63b:67d5:be9c with SMTP id y6-20020a056a00180600b0063b67d5be9cmr14160269pfa.29.1682240272254; Sun, 23 Apr 2023 01:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682240272; cv=none; d=google.com; s=arc-20160816; b=Dv00hSh8aYlQdl8t7XByyhHt5hKKLTV8ed4GvId7K5wRR24yIynQHmJHOj3X2/wpxi nsex2tXIvk2ClU+DVcPytmakC/Z5KV+Vs3A73QVQtY1ir9UJ1c1WUobVqaMBRoV6M4np pOwh9Nj08hb38G8tmmzy8X/DTLFxqgnTekUom8+JUmK9fUPj794We/ySZkj5l14pqpIi pBmLK9L6UV7S1Jk6vyymblItJXwCQTP2+vwAxXSV4BrM6mIz9opzPwpejwKePebrt2Fd EEJNrvbQqdGTeDEfE0SHRJXEDqC/4SHE59JAEiM3IeDhRPAiCna9coyNJ0WKr2KP1oO6 9Ehw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=8HrPXyV4YkfZ6jOKaYvmKCEwVihAsjdq3LTS+TyzWFg=; b=BTxBMPUolWktKb8YWkyFrixITBGXyZnqzuWdkysjBqdtsV/0WQZZKMCPWoHzy9jAmQ q/osJ3mIrdsN+Lwnebcb8EkvA7ELEcTrPPlz8hmpOZDSbY2J4pQCwZBnI2AfV/JtCj4A 87JwBvdnX9XLdZPh0kI3ujEoiR0+ua4Ups2DoBDtPOE9VRnHCUEwGFStqOt3JHmkmlqI Y4U+e3TGAXWHtx0F/ISHuvrbrIfLHJdXN6Z5lWRaQuA5XOzgAw/l3Hrmmh5yBxSlYl/e +3twMwIFH9YJ1apf1hO+YnetrukoNg+RgMbO9ylbwe9Xq/bkcDwiKLKaLYGRNVyVuyE2 Ob+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=wGp+Td+o; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=h6uu9H21; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alu.unizg.hr Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t12-20020a63eb0c000000b0051f15bd7215si8752969pgh.342.2023.04.23.01.57.38; Sun, 23 Apr 2023 01:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@alu.unizg.hr header.s=mail header.b=wGp+Td+o; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=h6uu9H21; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alu.unizg.hr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbjDWIkb (ORCPT <rfc822;fengqi706@gmail.com> + 99 others); Sun, 23 Apr 2023 04:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjDWIka (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 23 Apr 2023 04:40:30 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [161.53.235.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5A6D1BC2; Sun, 23 Apr 2023 01:40:28 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id CD7696015E; Sun, 23 Apr 2023 10:40:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1682239225; bh=NrrlTJuO2WOxeh84ut/e47TmcJC+8c5WzWqQwG1PyZM=; h=From:To:Cc:Subject:Date:From; b=wGp+Td+o+UT/S6x13KMiwr0evq+FpgQ35SnO8axIUu1KndCG36ab4g5H1X4Epe3X5 6iOrEGvFXGj9f7rf24cu1DQAZILmvknxsGVUI0Zxlc14EjNvaGVEWorFC9toty2Ptq EwE8KW2hnmkpIYqu1n+HTfz5YeyvhvOCE1UCzuPxH3/SvbKzCao5yTWqJbJ3OqoVOE ta1429MrqTlEilYvh5OCUJWYispnfe8OKkB/ZALFSRhdXiPWTBGzma4uoS+VheP5/j pu0wqE0xul5MA3/5vJ14wr3Hc//4rURDTsgGsiwM6bl24cooj3dRi/yQ1ZhflHlH2v DMUTbw9U2/6cA== X-Virus-Scanned: Debian amavisd-new at domac.alu.hr Received: from domac.alu.hr ([127.0.0.1]) by localhost (domac.alu.hr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2RCTnkPxMSfa; Sun, 23 Apr 2023 10:40:22 +0200 (CEST) Received: by domac.alu.hr (Postfix, from userid 1014) id 3B93C6015F; Sun, 23 Apr 2023 10:40:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1682239222; bh=NrrlTJuO2WOxeh84ut/e47TmcJC+8c5WzWqQwG1PyZM=; h=From:To:Cc:Subject:Date:From; b=h6uu9H21cv/CQb7i/w6iaZiCtnHDd6k/JZ+kg3zkyo1LktTCzrRay48eAqqhjYPQ6 RAQf+ap1wI8HeWv8va3hg/gja8U0bd+SpzUc1mwbr36D1q4DO51T7VG9qNA74jzASw k7FpCRsZYQEMzpAwLz8Asf/vIGPtUvKOxOUPLZJUtqdxQ7KjzNbOlgf7eREPpR6ntb Flg8d1UDCPNnoh2bVgZzp4cwO0KLOUaNFb30Cp6iwKZffA0XPcvYAsOvBkDlNUDgCR DgEGflKgN0lXN0aY4Mt5Koh/SIFr6/FMc1SzHnfwBS/fJLDaW6X5PvgsITHiV7zJRB vvby6RT8r9xkQ== From: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr> To: Johannes Berg <johannes.berg@intel.com>, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Johannes Berg <johannes@sipsolutions.net>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>, Alexander Wetzel <alexander@wetzel-home.de> Subject: [PATCH RFC v1 1/1] net: mac80211: fortify the spinlock against deadlock in interrupt Date: Sun, 23 Apr 2023 10:24:05 +0200 Message-Id: <20230423082403.49143-1-mirsad.todorovac@alu.unizg.hr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763956775844087125?= X-GMAIL-MSGID: =?utf-8?q?1763956775844087125?= |
Series |
[RFC,v1,1/1] net: mac80211: fortify the spinlock against deadlock in interrupt
|
|
Commit Message
Mirsad Todorovac
April 23, 2023, 8:24 a.m. UTC
In the function ieee80211_tx_dequeue() there is a locking sequence:
begin:
spin_lock(&local->queue_stop_reason_lock);
q_stopped = local->queue_stop_reasons[q];
spin_unlock(&local->queue_stop_reason_lock);
However small the chance (increased by ftracetest), an asynchronous
interrupt can occur in between of spin_lock() and spin_unlock(),
and the interrupt routine will attempt to lock the same
&local->queue_stop_reason_lock again.
This is the only remaining spin_lock() on local->queue_stop_reason_lock
that did not disable interrupts and could have possibly caused the deadlock
on the same CPU (core).
This will cause a costly reset of the CPU and wifi device or an
altogether hang in the single CPU and single core scenario.
This is the probable reproduce of the deadlock:
Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: Possible unsafe locking scenario:
Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: CPU0
Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: ----
Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: lock(&local->queue_stop_reason_lock);
Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: <Interrupt>
Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: lock(&local->queue_stop_reason_lock);
Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel:
*** DEADLOCK ***
Fixes: 4444bc2116ae
Link: https://lore.kernel.org/all/1f58a0d1-d2b9-d851-73c3-93fcc607501c@alu.unizg.hr/
Cc: Alexander Wetzel <alexander@wetzel-home.de>
Signed-off-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
---
net/mac80211/tx.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On Sun, 2023-04-23 at 10:24 +0200, Mirsad Goran Todorovac wrote: > In the function ieee80211_tx_dequeue() there is a locking sequence: > > begin: > spin_lock(&local->queue_stop_reason_lock); > q_stopped = local->queue_stop_reasons[q]; > spin_unlock(&local->queue_stop_reason_lock); > > However small the chance (increased by ftracetest), an asynchronous > interrupt can occur in between of spin_lock() and spin_unlock(), > and the interrupt routine will attempt to lock the same > &local->queue_stop_reason_lock again. > > This is the only remaining spin_lock() on local->queue_stop_reason_lock > that did not disable interrupts and could have possibly caused the deadlock > on the same CPU (core). > > This will cause a costly reset of the CPU and wifi device or an > altogether hang in the single CPU and single core scenario. > > This is the probable reproduce of the deadlock: > > Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: Possible unsafe locking scenario: > Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: CPU0 > Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: ---- > Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: lock(&local->queue_stop_reason_lock); > Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: <Interrupt> > Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: lock(&local->queue_stop_reason_lock); > Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: > *** DEADLOCK *** > > Fixes: 4444bc2116ae That fixes tag is wrong, should be Fixes: 4444bc2116ae ("wifi: mac80211: Proper mark iTXQs for resumption") Otherwise seems fine to me, submit it properly? johannes
On 24.4.2023. 19:27, Johannes Berg wrote: > On Sun, 2023-04-23 at 10:24 +0200, Mirsad Goran Todorovac wrote: >> In the function ieee80211_tx_dequeue() there is a locking sequence: >> >> begin: >> spin_lock(&local->queue_stop_reason_lock); >> q_stopped = local->queue_stop_reasons[q]; >> spin_unlock(&local->queue_stop_reason_lock); >> >> However small the chance (increased by ftracetest), an asynchronous >> interrupt can occur in between of spin_lock() and spin_unlock(), >> and the interrupt routine will attempt to lock the same >> &local->queue_stop_reason_lock again. >> >> This is the only remaining spin_lock() on local->queue_stop_reason_lock >> that did not disable interrupts and could have possibly caused the deadlock >> on the same CPU (core). >> >> This will cause a costly reset of the CPU and wifi device or an >> altogether hang in the single CPU and single core scenario. >> >> This is the probable reproduce of the deadlock: >> >> Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: Possible unsafe locking scenario: >> Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: CPU0 >> Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: ---- >> Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: lock(&local->queue_stop_reason_lock); >> Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: <Interrupt> >> Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: lock(&local->queue_stop_reason_lock); >> Apr 10 00:58:33 marvin-IdeaPad-3-15ITL6 kernel: >> *** DEADLOCK *** >> >> Fixes: 4444bc2116ae > > That fixes tag is wrong, should be > > Fixes: 4444bc2116ae ("wifi: mac80211: Proper mark iTXQs for resumption") > > Otherwise seems fine to me, submit it properly? > > johannes Will do, Sir. Do I have an Acked-by: ? Thank you. Mirsad
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 7699fb410670..45cb8e7bcc61 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -3781,6 +3781,7 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, ieee80211_tx_result r; struct ieee80211_vif *vif = txq->vif; int q = vif->hw_queue[txq->ac]; + unsigned long flags; bool q_stopped; WARN_ON_ONCE(softirq_count() == 0); @@ -3789,9 +3790,9 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, return NULL; begin: - spin_lock(&local->queue_stop_reason_lock); + spin_lock_irqsave(&local->queue_stop_reason_lock, flags); q_stopped = local->queue_stop_reasons[q]; - spin_unlock(&local->queue_stop_reason_lock); + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); if (unlikely(q_stopped)) { /* mark for waking later */