Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3853990rdg; Wed, 18 Oct 2023 07:56:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERk+G692ezJ5je5R46yhVN6rI9c4shOjVKJX1nEqplRhOIBJRnFknC5onXA5xNNAx5sDEH X-Received: by 2002:a17:90b:23c7:b0:27d:28ad:3086 with SMTP id md7-20020a17090b23c700b0027d28ad3086mr5214359pjb.2.1697640969624; Wed, 18 Oct 2023 07:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697640969; cv=none; d=google.com; s=arc-20160816; b=dO8JaNjsFIMlsRynnLfplvXz1xJwemXvWmkihCUt3fGdaC2UHXcPVf64y8e4IkVrtw WxJ4J5Xazmi4JTLVn+Nvaf0Qn8wP9UcT0HYaOq2ugxlTHM9ZszZcEHRc77C3bG9g2x/d WBPjoVp1xdfxmN9l2KwMZf3nEsgoSXRuTHViBoWGZhIn/665OqpYso6QNNm9a559MMf0 BtsIdGtXmeJm9/N98C/7tJPc5rNlDJGTg6+K0/KhJ7/4o54bajdDWgYOXhrGq99hO74g cU5U7HAsM1fVv/ib8cn+YFmeYP/Uzq/Vd0D8ee4QZhfJOEYynD68ucQSGiggez6fW34w 4JnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=3y2MpDHKP4qaI2uYiMAtPzXR13mpbFUmNmDnqstQkkc=; fh=0hdKmUcTUr5j/r7Hj5mbXZSUW10oEW1JATmvT41AnF4=; b=b7idf4urasX1P7nosLzBl5OlDtu+mSYt049x3/v868d2j6KrlQT3XGMkE6clRxeaz2 22v4HwBzeYrS4zVXIlRJwanaMc8H7I53BwrbZP8+ljObawpli2FfWNBWukuUknUtCoFT ac73KDQBt6fFypPvkIBzFqDvGE2XO0J2Sje5DlzXB8fUCuVnp8VIIL+j/0RIl0X2HItb DyM7fqIYwQCWImjnY1+GTDaXSIhPqn+X5R/A5ZYMGCD9EK/QwuXGUNfPEPPEO5caRZce JWylrrxqHDZgLhCOhauL1jyhg06pAugRIhMczhXJhLiaqES7ibeJjNWlQVLZo2hFvNlg o0QA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id x2-20020a656aa2000000b00578b21f1890si2347176pgu.294.2023.10.18.07.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 07:56:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 290768226F1B; Wed, 18 Oct 2023 07:56:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235212AbjJRO4C (ORCPT + 99 others); Wed, 18 Oct 2023 10:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231247AbjJRO4A (ORCPT ); Wed, 18 Oct 2023 10:56:00 -0400 Received: from mout.perfora.net (mout.perfora.net [74.208.4.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12935EA; Wed, 18 Oct 2023 07:55:59 -0700 (PDT) Received: from toolbox.int.toradex.com ([213.66.31.70]) by mrelay.perfora.net (mreueus004 [74.208.5.2]) with ESMTPSA (Nemesis) id 1MBmM4-1qh0TB2c6m-00C7Sb; Wed, 18 Oct 2023 16:55:50 +0200 From: Marcel Ziswiler To: linux-bluetooth@vger.kernel.org Cc: Sherry Sun , Johan Hedberg , Luiz Augusto von Dentz , Neeraj Sanjay Kale , linux-kernel@vger.kernel.org, Marcel Holtmann , Marcel Ziswiler , Amitkumar Karwar , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v1 1/2] Bluetooth: btnxpuart: Fix btnxpuart_close Date: Wed, 18 Oct 2023 16:55:39 +0200 Message-Id: <20231018145540.34014-2-marcel@ziswiler.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20231018145540.34014-1-marcel@ziswiler.com> References: <20231018145540.34014-1-marcel@ziswiler.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:oD583C4O4S6hnR07PJUQUB5+5AhFERDWRI2YEgFT3hEsd0Y7Z16 zng+0NB95NXnii7QtK7MGtW5+oGlXXyMqmakuPuhQ+ZNv0KoKF4QwDxGqsSuB9xOVk2am2/ nS8XZWrSHrlk1WxuK7t4DSN5tfHB1Boq6rWinPEQ9hHbdyeZZmdF4L8a3vcNDgEC0SzKUDc nV+Gsmp2/fVxi0/b+Gmwg== UI-OutboundReport: notjunk:1;M01:P0:JxOcFXgpLkk=;86okk4k9JdGmfwTX1JGkSHdKOMV CYMQlQsOwkRcgTn0xgsf6uqICTXdC7c2g1rl0gZAUjF197c/8pnKDCHeKQj8IpZ1gs//qvtxy u+WtUhvKxMjwWyHcKFK4Myz+iBAlRsndg5dxKbz0+7fNpjMU7qKIXEbX1fMpHVd2sDckDeEdS mnU3LIw1CFXRFxY6yhAMMZAKlkJBXn/aCIT/Pv2Ek/ZcrcgtfKaUk5P9ptLyRjrQ+PfCFY9LS abDDXwNeIeIBFAzTYMh2+whyjl0HbAQoUzXXbP50hp14wLOVkOQa0znfNNjiaaSkqWcLhRtOB ARnfqQItLMTUEQ+8LFHMJCbQKGbudU3ha7k1jeeGc7KB/9cJaZexg0vu2jmVKMjbCDhLUsCZL +ExEwnTAPMNgCI8Hs7VaMnT5017cXohTdlekv8RxBmAhv1TVY8BXnpel9O0M9GvfUUxZ7j1vo nFI/NyUjljgrH1WSXIP9IdFVtgK82o+b6NHSejmA7b5ZUNFB6mppcnqE5zGNtOe0/Yb7RWjkh pYLGAwMEd4PbG2nZ2nCGQKElaOI1E5MvmIZbK7PK4F82Yl0jtUixXLinM5VUvHxRY1/C+qz4X u9fkhOoiGqm3hMr278Zl1Xj3tyK8YbglLczwDCwQ5WNt2P+h0lSZqiuLlYVywuSoKxm0F9BeS 42gm8sfPzkOGrNbxYZxsOkLo4lR8FUhF4mplwCHcyOBhyHLCYwjCPKeo6FvEat605sFnZPLAJ /G6xg6SQbFkbXUMB0e6t7BXm9gBNk8RqOpfoIsCHg1Azx8dNeXHcy3NmCMiblW/MXYiNqMran vsNuyJhKezOKYZ+pqHFdt4Pcz+9An5qpkz0M8iBMNUfpH51IcK/NU+oF7YdEsdSgBlyGNrK9C JE+Kf/rvHakdB9w== X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 18 Oct 2023 07:56:03 -0700 (PDT) From: Marcel Ziswiler Unfortunately, btnxpuart_close() may trigger a BUG: scheduling while atomic. Fix this by properly purging the transmit queue and freeing the receive skb. Fixes: 689ca16e5232 ("Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets") Signed-off-by: Marcel Ziswiler --- This is the kernel trace this commit fixes: [ 29.270685] BUG: scheduling while atomic: kworker/u3:0/55/0x00000002 [ 29.277062] Modules linked in: snd_soc_simple_card snd_soc_simple_card_utils crct10dif_ce btnxpuart usb_f_ncm u_ether rtc_ti_k3 k3_j72xx_bandgap mwifiex_sdio mwifiex snd_soc_davinci_mcasp snd_soc_ti_udma sa2ul snd_soc_ti_edma snd_soc_ti_sdma authenc ina2xx snd_soc_nau8822 tps65219_pwrbutton at24 ti_ads1015 industrialio_triggered_buffer kfifo_buf lm75 rtc_ds1307 spi_omap2_mcspi 8021q garp mrp stp llc cfg80211 bluetooth ecdh_generic ecc rfkill libcomposite fuse drm backlight ipv6 [ 29.319532] CPU: 0 PID: 55 Comm: kworker/u3:0 Not tainted 6.6.0-rc5-next-20231010-dirty #35 [ 29.327883] Hardware name: Toradex Verdin AM62 WB on Verdin Development Board (DT) [ 29.335450] Workqueue: hci0 hci_power_off [bluetooth] [ 29.340775] Call trace: [ 29.343220] dump_backtrace+0x98/0x118 [ 29.346984] show_stack+0x18/0x24 [ 29.350303] dump_stack_lvl+0x48/0x60 [ 29.353971] dump_stack+0x18/0x24 [ 29.357287] __schedule_bug+0x50/0x68 [ 29.360953] __schedule+0x7f0/0xa94 [ 29.364446] schedule+0x34/0xc8 [ 29.367588] rpm_resume+0x170/0x6c8 [ 29.371083] __pm_runtime_resume+0x4c/0x90 [ 29.375182] omap8250_set_mctrl+0x2c/0xbc [ 29.379198] serial8250_set_mctrl+0x20/0x40 [ 29.383387] uart_update_mctrl+0x58/0x78 [ 29.387311] uart_dtr_rts+0x104/0x114 [ 29.390975] tty_port_shutdown+0xd4/0xdc [ 29.394903] tty_port_close+0x40/0xbc [ 29.398567] uart_close+0x34/0x9c [ 29.401882] ttyport_close+0x50/0x94 [ 29.405460] serdev_device_close+0x40/0x50 [ 29.409557] btnxpuart_close+0x48/0xbc [btnxpuart] [ 29.414364] hci_dev_close_sync+0x2ec/0x754 [bluetooth] [ 29.419747] hci_dev_do_close+0x2c/0x70 [bluetooth] [ 29.424772] hci_power_off+0x20/0x64 [bluetooth] [ 29.429536] process_one_work+0x138/0x244 [ 29.433551] worker_thread+0x320/0x438 [ 29.437302] kthread+0x114/0x118 [ 29.440533] ret_from_fork+0x10/0x20 [ 29.445838] BUG: scheduling while atomic: kworker/u3:0/55/0x00000000 [ 29.453556] Modules linked in: snd_soc_simple_card snd_soc_simple_card_utils crct10dif_ce btnxpuart usb_f_ncm u_ether rtc_ti_k3 k3_j72xx_bandgap mwifiex_sdio mwifiex snd_soc_davinci_mcasp snd_soc_ti_udma sa2ul snd_soc_ti_edma snd_soc_ti_sdma authenc ina2xx snd_soc_nau8822 tps65219_pwrbutton at24 ti_ads1015 industrialio_triggered_buffer kfifo_buf lm75 rtc_ds1307 spi_omap2_mcspi 8021q garp mrp stp llc cfg80211 bluetooth ecdh_generic ecc rfkill libcomposite fuse drm backlight ipv6 [ 29.496085] CPU: 0 PID: 55 Comm: kworker/u3:0 Tainted: G W 6.6.0-rc5-next-20231010-dirty #35 [ 29.505912] Hardware name: Toradex Verdin AM62 WB on Verdin Development Board (DT) [ 29.513478] Workqueue: hci0 hci_power_off [bluetooth] [ 29.518787] Call trace: [ 29.521232] dump_backtrace+0x98/0x118 [ 29.524993] show_stack+0x18/0x24 [ 29.528312] dump_stack_lvl+0x48/0x60 [ 29.531980] dump_stack+0x18/0x24 [ 29.535296] __schedule_bug+0x50/0x68 [ 29.538961] __schedule+0x7f0/0xa94 [ 29.542452] schedule+0x34/0xc8 [ 29.545593] rpm_resume+0x170/0x6c8 [ 29.549087] __pm_runtime_resume+0x4c/0x90 [ 29.553186] omap_8250_pm+0x28/0x110 [ 29.556766] serial8250_pm+0x18/0x3c [ 29.560347] uart_tty_port_shutdown+0xa4/0x114 [ 29.564792] tty_port_shutdown+0x84/0xdc [ 29.568718] tty_port_close+0x40/0xbc [ 29.572382] uart_close+0x34/0x9c [ 29.575697] ttyport_close+0x50/0x94 [ 29.579275] serdev_device_close+0x40/0x50 [ 29.583373] btnxpuart_close+0x48/0xbc [btnxpuart] [ 29.588179] hci_dev_close_sync+0x2ec/0x754 [bluetooth] [ 29.593562] hci_dev_do_close+0x2c/0x70 [bluetooth] [ 29.598587] hci_power_off+0x20/0x64 [bluetooth] [ 29.603353] process_one_work+0x138/0x244 [ 29.607369] worker_thread+0x320/0x438 [ 29.611119] kthread+0x114/0x118 [ 29.614352] ret_from_fork+0x10/0x20 drivers/bluetooth/btnxpuart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c index b7e66b7ac570..9cb7529eef09 100644 --- a/drivers/bluetooth/btnxpuart.c +++ b/drivers/bluetooth/btnxpuart.c @@ -1234,6 +1234,9 @@ static int btnxpuart_close(struct hci_dev *hdev) ps_wakeup(nxpdev); serdev_device_close(nxpdev->serdev); + skb_queue_purge(&nxpdev->txq); + kfree_skb(nxpdev->rx_skb); + nxpdev->rx_skb = NULL; clear_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state); return 0; } -- 2.36.1