Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp82292ybg; Tue, 28 Jul 2020 00:06:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9Js1gnlHDPIzyw/DwKkHowhdezR/gd3Sf38Lhv7f7JBLft/NTC+rXppYXcmOD+NXKnwNY X-Received: by 2002:aa7:c655:: with SMTP id z21mr24901248edr.330.1595920003587; Tue, 28 Jul 2020 00:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595920003; cv=none; d=google.com; s=arc-20160816; b=mbRcFSF4Y8BCvwIeO6Ueh8kZyxSd7P78D2fhyvDAy4ats+CrxRCpeGJANmFlTouATq wh4+pmcfLYy/BGZ0imWAkZ6Ikaqx7YsRFcsJxj+MHnNwryNfNtgIAX6siKU/KDUmU7ef Va50F1WflnQ+7Uvs0KGSFwkBbKsvhswj3+oUS50EEUH92+ithH30h0BQmb24FW6c0LGL Ikm4pdqbi8VU4EGvMZb5yXH4OoaNf1bq/hv3SwYmPB5tt/yI9Djbo+hFIbVVPevFTTlK mwvBcqtG2zkX//K2KplUsg85hrFKUh6dH+QAmSXdISwAwOKhDA1/PQqVVDp4gxpet2/D o4IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=i/pRdBkVf4dFOKBKrmHVbMAEN+QwHAOUnunyWGBlPYw=; b=Zr7EUDugzmZgYsg92VhbHsjUM7mviopMObgOj8tuypuO0cIt7N2fivAN6Id/QcAQto dWEPOSO3EnwIScOKAZ8qRBTTdNsoUpDJWUDEao7bcPL/EjOWJNWA57cdMBxjWwujjWun TFfhsEvb5uDGMUJRKyySpTTH3n+bgh798BmLzixxC08NljQhc8t+WbdOXC7196xgpqeX YbklfFuaJnVi/Xfl6Jl4h+PjeIDtyuEaHn0hVQddCinFc4uH0CDbz0oaXVerOhGYzmi0 Y/rkTS9DMh3dIbrj4I/exY8ca7JKm/zqb5vdr0lCzw9cFhvtoPE0G9Ou85hsBLUJGJyt SAag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn20si7707420ejc.409.2020.07.28.00.06.21; Tue, 28 Jul 2020 00:06:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727097AbgG1HGD convert rfc822-to-8bit (ORCPT + 99 others); Tue, 28 Jul 2020 03:06:03 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:57429 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726874AbgG1HGC (ORCPT ); Tue, 28 Jul 2020 03:06:02 -0400 Received: from marcel-macbook.fritz.box (p4ff9f430.dip0.t-ipconnect.de [79.249.244.48]) by mail.holtmann.org (Postfix) with ESMTPSA id 8AD33CECCC; Tue, 28 Jul 2020 09:16:01 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH] Bluetooth: Fix suspend notifier race From: Marcel Holtmann In-Reply-To: <20200727142231.1.I7ebe9eaf684ddb07ae28634cb4d28cf7754641f1@changeid> Date: Tue, 28 Jul 2020 09:05:59 +0200 Cc: chromeos-bluetooth-upstreaming , linux-bluetooth , Miao-chen Chou , "David S. Miller" , Johan Hedberg , netdev , kernel list , Jakub Kicinski Content-Transfer-Encoding: 8BIT Message-Id: <534A8246-5B96-487F-A042-43F717A1CA24@holtmann.org> References: <20200727142231.1.I7ebe9eaf684ddb07ae28634cb4d28cf7754641f1@changeid> To: Abhishek Pandit-Subedi X-Mailer: Apple Mail (2.3608.80.23.2.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Abhishek, > Unregister from suspend notifications and cancel suspend preparations > before running hci_dev_do_close. Otherwise, the suspend notifier may > race with unregister and cause cmd_timeout even after hdev has been > freed. > > Signed-off-by: Abhishek Pandit-Subedi > Reviewed-by: Miao-chen Chou > --- > Hi Marcel, > > This fixes a race between hci_unregister_dev and the suspend notifier. > Without these changes, we encountered the following kernel panic when > a USB disconnect (with btusb) occurred on resume: > > [ 832.578518] Bluetooth: hci_core.c:hci_cmd_timeout() hci0: command 0x0c05 tx timeout > [ 832.586200] BUG: kernel NULL pointer dereference, address: 0000000000000000 > [ 832.586203] #PF: supervisor read access in kernel mode > [ 832.586205] #PF: error_code(0x0000) - not-present page > [ 832.586206] PGD 0 P4D 0 > [ 832.586210] PM: suspend exit > [ 832.608870] Oops: 0000 [#1] PREEMPT SMP NOPTI > [ 832.613232] CPU: 3 PID: 10755 Comm: kworker/3:7 Not tainted 5.4.44-04894-g1e9dbb96a161 #1 > [ 832.630036] Workqueue: events hci_cmd_timeout [bluetooth] > [ 832.630046] RIP: 0010:__queue_work+0xf0/0x374 > [ 832.630051] RSP: 0018:ffff9b5285f1fdf8 EFLAGS: 00010046 > [ 832.674033] RAX: ffff8a97681bac00 RBX: 0000000000000000 RCX: ffff8a976a000600 > [ 832.681162] RDX: 0000000000000000 RSI: 0000000000000009 RDI: ffff8a976a000748 > [ 832.688289] RBP: ffff9b5285f1fe38 R08: 0000000000000000 R09: ffff8a97681bac00 > [ 832.695418] R10: 0000000000000002 R11: ffff8a976a0006d8 R12: ffff8a9745107600 > [ 832.698045] usb 1-6: new full-speed USB device number 119 using xhci_hcd > [ 832.702547] R13: ffff8a9673658850 R14: 0000000000000040 R15: 000000000000001e > [ 832.702549] FS: 0000000000000000(0000) GS:ffff8a976af80000(0000) knlGS:0000000000000000 > [ 832.702550] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 832.702550] CR2: 0000000000000000 CR3: 000000010415a000 CR4: 00000000003406e0 > [ 832.702551] Call Trace: > [ 832.702558] queue_work_on+0x3f/0x68 > [ 832.702562] process_one_work+0x1db/0x396 > [ 832.747397] worker_thread+0x216/0x375 > [ 832.751147] kthread+0x138/0x140 > [ 832.754377] ? pr_cont_work+0x58/0x58 > [ 832.758037] ? kthread_blkcg+0x2e/0x2e > [ 832.761787] ret_from_fork+0x22/0x40 > [ 832.846191] ---[ end trace fa93f466da517212 ]--- > > The suspend notifier handler seemed to be scheduling commands even after > it was cleaned up and this was resulting in a panic in cmd_timeout (when > it tries to requeue the cmd_timer). > > This was tested on 5.4 kernel with a suspend+resume stress test for 500+ > iterations. I also confirmed that after a usb disconnect, the suspend > notifier times out before the USB device is probed again (fixing the > original race between the usb_disconnect + probe and the notifier). Can you please structure the commit message so that the oops is included. It is valuable information Everything after --- is a personal note to the maintainer. And we might want to include a Fixes tag as well. Regards Marcel