From patchwork Mon Sep 28 08:10:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sedat Dilek X-Patchwork-Id: 7275771 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E107ABEEA4 for ; Mon, 28 Sep 2015 08:10:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F04DC206D6 for ; Mon, 28 Sep 2015 08:10:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 745DB206CE for ; Mon, 28 Sep 2015 08:10:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756469AbbI1IK0 (ORCPT ); Mon, 28 Sep 2015 04:10:26 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:35731 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756449AbbI1IKW (ORCPT ); Mon, 28 Sep 2015 04:10:22 -0400 Received: by wicge5 with SMTP id ge5so93081812wic.0 for ; Mon, 28 Sep 2015 01:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=Q+RAhae/1W0lNJ6xSxdRuDh0hlB0NOxPEdLrmf79NGo=; b=lDLD4qFzwY/AN7FQRWEhtZ3hptk4+9bomaG7iNzq2HF5MWB1rGJy+iJjNNB20rznxG c8XSEegnG3vCf2opIuKkwWRXd7gUDYRnb6FiounSzNnMrd6SWy2OG62u8vOGylgRjD7O FubIBw59IELyVePzZfMm8S1VaeK6KWd+ZpU4d5K8DMq6C5Ocbqeqh+dRUPK3HABvK0i3 hdzxuMnT2IMtI2cBT/asodVt+menGWUF5ja3nP9VMqEFxBk+uTbWNSgD93irSLST88my pJAniK/gpxt7KvqG3dRhv9porCMNGp3J8hgu5IM8B7iUXKg6z7+5oicK80VZNevw+5NZ 1Dgg== X-Received: by 10.194.71.39 with SMTP id r7mr23064487wju.120.1443427820816; Mon, 28 Sep 2015 01:10:20 -0700 (PDT) Received: from fambox.fambox-domain ([46.114.72.11]) by smtp.gmail.com with ESMTPSA id fn4sm16940361wib.11.2015.09.28.01.10.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Sep 2015 01:10:20 -0700 (PDT) From: Sedat Dilek Cc: Sedat Dilek , Jiri Kosina , linux-input@vger.kernel.org, Tejun Heo , Lai Jiangshan , Steven Rostedt , Paul McKenney Subject: [PATCH] usbhid: Fix lockdep unannotated irqs-off warning Date: Mon, 28 Sep 2015 10:10:04 +0200 Message-Id: <1443427804-2957-1-git-send-email-sedat.dilek@gmail.com> X-Mailer: git-send-email 2.5.3 To: unlisted-recipients:; (no To-header on input) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When compiling Linux v4.2+ and v4.3-rc2+ with a llvmlinux patchset and CLANG v3.7 I see a BUG line like this: [ 24.705463] BUG: sleeping function called from invalid context at kernel/workqueue.c:2680 [ 24.705576] in_atomic(): 0, irqs_disabled(): 1, pid: 1447, name: acpid After some vital help from workqueue and hid folks it turned out to be a problem in the hid area. Jiri encouraged me to look into del_timer-sync()/cancel_work_sync(). So, I disassembled kernel/time/timer.o. This looked good. Both functions are called in hid_cancel_delayed_stuff(). Adding a might_sleep() on top of it showed hints towards lockdep and unannotated irqs-off. [ 23.723807] WARNING: CPU: 0 PID: 1451 at kernel/locking/lockdep.c:3519 check_flags+0x6c/0x1b0() [ 23.723866] DEBUG_LOCKS_WARN_ON(current->hardirqs_enabled) ... [ 23.774719] possible reason: unannotated irqs-off. Dealing with irqflags-tracing I enabled some helpful kernel-options: CONFIG_LOCKDEP=y CONFIG_DEBUG_LOCKDEP=y CONFIG_TRACING=y CONFIG_TRACE_IRQFLAGS=y CONFIG_IRQSOFF_TRACER=y The file irqflags-tracing.txt was helpful. Steven Rostedt pointed me to the irqsoff section in ftrace.txt documentation. Then, I tried to force to turn off the tracing of hardirqs in usbhid_close() via trace_hardirqs_off() - line by line. Finally, the spin_unlock_irq() within the if-statement looked like the culprit. Looking through commits having a similiar issue, I replaced spin_{un}lock_irq() with spin_{un}lock_bh() as this doesn't need interrupts disabled. This fixed the issue for me. Tested against Linux v4.3-rc3. Still unsure why the same kernel built with GCC v4.9 does not show this. Thanks to all involved people. [1] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/irqflags-tracing.txt [2] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/trace/ftrace.txt#n906 CC: Jiri Kosina CC: linux-input@vger.kernel.org CC: Tejun Heo CC: Lai Jiangshan CC: Steven Rostedt CC: Paul McKenney --- drivers/hid/usbhid/hid-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 36712e9f56c2..188f59348ec5 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -729,16 +729,16 @@ void usbhid_close(struct hid_device *hid) * data acquistion due to a resumption we no longer * care about */ - spin_lock_irq(&usbhid->lock); + spin_lock_bh(&usbhid->lock); if (!--hid->open) { - spin_unlock_irq(&usbhid->lock); + spin_unlock_bh(&usbhid->lock); hid_cancel_delayed_stuff(usbhid); if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) { usb_kill_urb(usbhid->urbin); usbhid->intf->needs_remote_wakeup = 0; } } else { - spin_unlock_irq(&usbhid->lock); + spin_unlock_bh(&usbhid->lock); } mutex_unlock(&hid_open_mut); }