From patchwork Tue Oct 18 12:09:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 9382009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0D88460487 for ; Tue, 18 Oct 2016 12:09:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F14852956C for ; Tue, 18 Oct 2016 12:09:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E609F2956F; Tue, 18 Oct 2016 12:09:34 +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=-6.9 required=2.0 tests=BAYES_00,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 CC0602956C for ; Tue, 18 Oct 2016 12:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758602AbcJRMJ1 (ORCPT ); Tue, 18 Oct 2016 08:09:27 -0400 Received: from mail.skyhub.de ([78.46.96.112]:52895 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754468AbcJRMJ0 (ORCPT ); Tue, 18 Oct 2016 08:09:26 -0400 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (door.skyhub.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id dvBFpxIsSWuM; Tue, 18 Oct 2016 14:09:23 +0200 (CEST) Received: from pd.tnic (p5DDC60A3.dip0.t-ipconnect.de [93.220.96.163]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id E4A99245A89; Tue, 18 Oct 2016 14:09:22 +0200 (CEST) Received: by pd.tnic (Postfix, from userid 1000) id 16E4D16415A; Tue, 18 Oct 2016 14:09:22 +0200 (CEST) Date: Tue, 18 Oct 2016 14:09:22 +0200 From: Borislav Petkov To: linux-input@vger.kernel.org Cc: lkml , Dmitry Torokhov , Hans de Goede , Pali =?utf-8?B?Um9ow6Fy?= , Chris Diamand , Richard Pospesel Subject: Re: psmouse_disconnect lockdep splat Message-ID: <20161018120921.dhlo76bbkdhlm7ey@pd.tnic> References: <20160828093011.GA2842@nazgul.tnic> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160828093011.GA2842@nazgul.tnic> User-Agent: NeoMutt/ (1.7.0) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adding more people to CC. I still see this after 4.8 is out. So PeterZ suggested something like this: --- --- to fix the lock inversion but that might have the other problem of being racy by maybe ->reconnect() accessing psmouse->private in trackpoint_sync() outside of the psmouse_mutex lock and that won't be nice. But someone more knowledgeable with this code should take a look and suggest a proper fix. Thanks! (Leaving in the rest for reference). On Sun, Aug 28, 2016 at 11:30:11AM +0200, Borislav Petkov wrote: > Hi, > > just saw this while booting rc3+tip/master. Thought I should report it > in case it hasn't been caught and fixed yet. > > --- > > ... > [ 6.257924] snd_hda_codec_realtek hdaudioC0D0: Internal Mic=0x12 > [ 6.280232] iTCO_vendor_support: vendor-support=0 > [ 6.282063] snd_hda_intel 0000:00:1b.0: bound 0000:00:02.0 (ops i915_audio_component_bind_ops) > [ 6.285810] psmouse serio2: Failed to deactivate mouse on synaptics-pt/serio0 > [ 6.286331] iTCO_wdt: Intel TCO WatchDog Timer Driver v1.11 > [ 6.286392] iTCO_wdt: Found a Panther Point TCO device (Version=2, TCOBASE=0x0460) > [ 6.290473] input: HDA Digital PCBeep as /devices/pci0000:00/0000:00:1b.0/sound/card0/input10 > [ 6.293635] input: HDA Intel PCH Mic as /devices/pci0000:00/0000:00:1b.0/sound/card0/input11 > [ 6.298520] input: HDA Intel PCH Dock Mic as /devices/pci0000:00/0000:00:1b.0/sound/card0/input12 > [ 6.300605] iTCO_wdt: initialized. heartbeat=30 sec (nowayout=0) > [ 6.303861] input: HDA Intel PCH Headphone as /devices/pci0000:00/0000:00:1b.0/sound/card0/input13 > [ 6.307117] input: HDA Intel PCH Dock Headphone as /devices/pci0000:00/0000:00:1b.0/sound/card0/input14 > [ 6.310045] input: HDA Intel PCH HDMI/DP,pcm=3 as /devices/pci0000:00/0000:00:1b.0/sound/card0/input15 > [ 6.311645] input: HDA Intel PCH HDMI/DP,pcm=7 as /devices/pci0000:00/0000:00:1b.0/sound/card0/input16 > [ 6.312865] input: HDA Intel PCH HDMI/DP,pcm=8 as /devices/pci0000:00/0000:00:1b.0/sound/card0/input17 > [ 6.346990] usb 1-1: New USB device found, idVendor=8087, idProduct=0024 > [ 6.348316] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 > [ 6.350870] hub 1-1:1.0: USB hub found > [ 6.352530] hub 1-1:1.0: 6 ports detected > [ 6.390558] usb 2-1: New USB device found, idVendor=8087, idProduct=0024 > [ 6.391706] usb 2-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 > [ 6.393209] hub 2-1:1.0: USB hub found > [ 6.394534] hub 2-1:1.0: 8 ports detected > [ 6.415139] random: crng init done > [ 6.590812] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready > [ 6.749939] psmouse serio2: Failed to enable mouse on synaptics-pt/serio0 > > [ 7.000430] ====================================================== > [ 7.001447] [ INFO: possible circular locking dependency detected ] > [ 7.002453] 4.8.0-rc3+ #1 Not tainted > [ 7.003420] ------------------------------------------------------- > [ 7.004366] kworker/0:1/45 is trying to acquire lock: > [ 7.005291] (s_active#41){++++.+}, at: [] kernfs_remove_by_name_ns+0x45/0xa0 > [ 7.006243] > but task is already holding lock: > [ 7.008074] (psmouse_mutex){+.+.+.}, at: [] psmouse_disconnect+0x6c/0x150 > [ 7.009011] > which lock already depends on the new lock. > > [ 7.011753] > the existing dependency chain (in reverse order) is: > [ 7.013576] > -> #1 (psmouse_mutex){+.+.+.}: > [ 7.015456] [] lock_acquire+0xb2/0x200 > [ 7.016400] [] mutex_lock_interruptible_nested+0x64/0x440 > [ 7.017340] [] psmouse_attr_set_helper+0x31/0x110 > [ 7.018292] [] dev_attr_store+0x18/0x30 > [ 7.019214] [] sysfs_kf_write+0x45/0x60 > [ 7.020125] [] kernfs_fop_write+0x135/0x1c0 > [ 7.021023] [] __vfs_write+0x28/0x120 > [ 7.021917] [] vfs_write+0xb8/0x1b0 > [ 7.022793] [] SyS_write+0x49/0xa0 > [ 7.023650] [] entry_SYSCALL_64_fastpath+0x1c/0xac > [ 7.024500] > -> #0 (s_active#41){++++.+}: > [ 7.026151] [] __lock_acquire+0x1249/0x1480 > [ 7.026995] [] lock_acquire+0xb2/0x200 > [ 7.027845] [] __kernfs_remove+0x225/0x2f0 > [ 7.028681] [] kernfs_remove_by_name_ns+0x45/0xa0 > [ 7.029517] [] remove_files.isra.1+0x36/0x70 > [ 7.030349] [] sysfs_remove_group+0x44/0x90 > [ 7.031185] [] trackpoint_disconnect+0x24/0x40 > [ 7.032014] [] psmouse_disconnect+0x9a/0x150 > [ 7.032843] [] serio_disconnect_driver+0x32/0x40 > [ 7.033664] [] serio_driver_remove+0x15/0x20 > [ 7.034490] [] __device_release_driver+0xa1/0x160 > [ 7.035316] [] device_release_driver+0x25/0x40 > [ 7.036139] [] serio_disconnect_port+0x7a/0xb0 > [ 7.036955] [] serio_reconnect_subtree+0x51/0xb0 > [ 7.037762] [] serio_handle_event+0x192/0x210 > [ 7.038568] [] process_one_work+0x1e8/0x740 > [ 7.039350] [] worker_thread+0x48/0x4e0 > [ 7.040111] [] kthread+0xf3/0x110 > [ 7.040863] [] ret_from_fork+0x1f/0x40 > [ 7.041610] > other info that might help us debug this: > > [ 7.043777] Possible unsafe locking scenario: > > [ 7.045191] CPU0 CPU1 > [ 7.045883] ---- ---- > [ 7.046549] lock(psmouse_mutex); > [ 7.047216] lock(s_active#41); > [ 7.047881] lock(psmouse_mutex); > [ 7.048526] lock(s_active#41); > [ 7.049165] > *** DEADLOCK *** > > [ 7.051023] 6 locks held by kworker/0:1/45: > [ 7.051638] #0: ("events_long"){.+.+.+}, at: [] process_one_work+0x169/0x740 > [ 7.052298] #1: (serio_event_work){+.+.+.}, at: [] process_one_work+0x169/0x740 > [ 7.052964] #2: (serio_mutex){+.+.+.}, at: [] serio_handle_event+0x20/0x210 > [ 7.053633] #3: (&dev->mutex){......}, at: [] device_release_driver+0x1d/0x40 > [ 7.054312] #4: (&serio->drv_mutex){+.+.+.}, at: [] serio_disconnect_driver+0x20/0x40 > [ 7.055002] #5: (psmouse_mutex){+.+.+.}, at: [] psmouse_disconnect+0x6c/0x150 > [ 7.055702] > stack backtrace: > [ 7.057050] CPU: 0 PID: 45 Comm: kworker/0:1 Not tainted 4.8.0-rc3+ #1 > [ 7.057745] Hardware name: LENOVO 2320CTO/2320CTO, BIOS G2ET86WW (2.06 ) 11/13/2012 > [ 7.058462] Workqueue: events_long serio_handle_event > [ 7.059179] 0000000000000000 ffff880213537a20 ffffffff81336955 ffffffff825e1190 > [ 7.059917] ffffffff825e1190 ffff880213537a60 ffffffff810b8dd3 ffff880213537aa0 > [ 7.060657] ffff880213540828 ffff880213540850 0000000000000006 ffff880213540760 > [ 7.061390] Call Trace: > [ 7.062113] [] dump_stack+0x67/0x92 > [ 7.062843] [] print_circular_bug+0x1e3/0x250 > [ 7.063576] [] __lock_acquire+0x1249/0x1480 > [ 7.064305] [] ? mark_held_locks+0x6f/0xa0 > [ 7.065033] [] ? __mutex_unlock_slowpath+0xf8/0x1a0 > [ 7.065764] [] lock_acquire+0xb2/0x200 > [ 7.066495] [] ? kernfs_remove_by_name_ns+0x45/0xa0 > [ 7.067229] [] __kernfs_remove+0x225/0x2f0 > [ 7.067959] [] ? kernfs_remove_by_name_ns+0x45/0xa0 > [ 7.068691] [] ? kernfs_find_ns+0x94/0x140 > [ 7.069416] [] kernfs_remove_by_name_ns+0x45/0xa0 > [ 7.070148] [] remove_files.isra.1+0x36/0x70 > [ 7.070876] [] sysfs_remove_group+0x44/0x90 > [ 7.071605] [] trackpoint_disconnect+0x24/0x40 > [ 7.072334] [] psmouse_disconnect+0x9a/0x150 > [ 7.073063] [] serio_disconnect_driver+0x32/0x40 > [ 7.073795] [] serio_driver_remove+0x15/0x20 > [ 7.074528] [] __device_release_driver+0xa1/0x160 > [ 7.075260] [] device_release_driver+0x25/0x40 > [ 7.075991] [] serio_disconnect_port+0x7a/0xb0 > [ 7.076721] [] serio_reconnect_subtree+0x51/0xb0 > [ 7.077451] [] serio_handle_event+0x192/0x210 > [ 7.078183] [] process_one_work+0x1e8/0x740 > [ 7.078919] [] ? process_one_work+0x169/0x740 > [ 7.079663] [] worker_thread+0x48/0x4e0 > [ 7.080407] [] ? schedule+0x49/0xa0 > [ 7.081148] [] ? preempt_count_sub+0xa1/0x110 > [ 7.081901] [] ? process_one_work+0x740/0x740 > [ 7.082649] [] kthread+0xf3/0x110 > [ 7.083397] [] ret_from_fork+0x1f/0x40 > [ 7.084152] [] ? kthread_create_on_node+0x230/0x230 > [ 7.391560] device-mapper: ioctl: 4.35.0-ioctl (2016-06-23) initialised: dm-devel@redhat.com > [ 7.412104] loop: module loaded > [ 7.771919] psmouse serio2: trackpoint: IBM TrackPoint firmware: 0x0e, buttons: 3/3 > [ 7.961843] input: TPPS/2 IBM TrackPoint as /devices/platform/i8042/serio1/serio2/input/input18 > [ 8.474792] input: ACPI Virtual Keyboard Device as /devices/virtual/input/input19 > > -- > Regards/Gruss, > Boris. > > ECO tip #101: Trim your mails when you reply. > -- > diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c index fb4b185dea96..9112c3cecad7 100644 --- a/drivers/input/mouse/psmouse-base.c +++ b/drivers/input/mouse/psmouse-base.c @@ -1420,14 +1420,16 @@ static void psmouse_disconnect(struct serio *serio) psmouse_deactivate(parent); } - if (psmouse->disconnect) - psmouse->disconnect(psmouse); - if (parent && parent->pt_deactivate) parent->pt_deactivate(parent); psmouse_set_state(psmouse, PSMOUSE_IGNORE); + mutex_unlock(&psmouse_mutex); + if (psmouse->disconnect) + psmouse->disconnect(psmouse); + mutex_lock(&psmouse_mutex); + serio_close(serio); serio_set_drvdata(serio, NULL); input_unregister_device(psmouse->dev);