All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sedat Dilek <sedat.dilek@gmail.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Jiri Kosina <jikos@kernel.org>, Tejun Heo <tj@kernel.org>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Paul McKenney <paulmck@linux.vnet.ibm.com>,
	Andy Lutomirski <luto@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-usb@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH] usbhid: Fix lockdep unannotated irqs-off warning
Date: Wed, 2 Mar 2016 09:34:46 +0100	[thread overview]
Message-ID: <CA+icZUV9qDVLTAv_oj=Pj4Ry+f_kKUwJwejmGB+VBn4kzSLdTQ@mail.gmail.com> (raw)
In-Reply-To: <CA+icZUVDUSAp6NuNQOh5jf1Qc-mgONoyJ3RHkw+rWHw5OqUe6Q@mail.gmail.com>

On 3/2/16, Sedat Dilek <sedat.dilek@gmail.com> wrote:
> On 3/1/16, Alan Stern <stern@rowland.harvard.edu> wrote:
>> On Tue, 1 Mar 2016, Sedat Dilek wrote:
>>
>>> On Tue, Oct 13, 2015 at 2:57 AM, Steven Rostedt <rostedt@goodmis.org>
>>> wrote:
>>> > On Sat, 3 Oct 2015 12:05:42 +0200
>>> > Sedat Dilek <sedat.dilek@gmail.com> wrote:
>>> >
>>> >> So, at the beginning... dunno WTF is causing the problems - no
>>> >> workaround for CLANG.
>>> >
>>> > Probably need to compile with gcc and with clang and look at the
>>> > binary
>>> > differences. Or at least what objdump shows.
>>> >
>>>
>>> [ Hope to address this issue to the correct people - CCed some people
>>> I taped on their nerves ]
>>>
>>> Not sure if I should open a new thread?
>>> Please, some clear statements on this.
>>> Thanks.
>>>
>>> The issue is still visible and alive.
>>
>> ...
>>
>>> [ FACT #3: TEST-CASE #2 ]
>>>
>>> The most reliable test-case is to simply unplug my external Logitech
>>> USB mouse - saw this by accident.
>>> YES, it was so simple.
>>>
>>> --- dmesg_4.5.0-rc6-2-llvmlinux-amd64.txt       2016-02-29
>>> 21:23:56.399691975 +0100
>>> +++ dmesg_4.5.0-rc6-2-llvmlinux-amd64_usbmouse-unplugged.txt
>>> 2016-02-29 21:28:14.401832240 +0100
>>> @@ -832,3 +832,75 @@
>>>  [   66.529779] PPP BSD Compression module registered
>>>  [   66.563013] PPP Deflate Compression module registered
>>>  [   66.978977] usb 2-1.5: USB disconnect, device number 4
>>> +[  321.937369] usb 2-1.4: USB disconnect, device number 3
>>> +[  321.950810] BUG: sleeping function called from invalid context at
>>> kernel/workqueue.c:2785
>>> +[  321.950816] in_atomic(): 0, irqs_disabled(): 1, pid: 44, name:
>>> kworker/2:1
>>
>>> +[  321.950885] hardirqs last  enabled at (47769):
>>> [<ffffffff819426a2>] _raw_spin_unlock_irq+0x32/0x60
>>> +[  321.950889] hardirqs last disabled at (47770):
>>> [<ffffffff81115bdc>] del_timer_sync+0x3c/0x110
>>> +[  321.950894] softirqs last  enabled at (47112):
>>> [<ffffffff810871a2>] __do_softirq+0x5a2/0x610
>>> +[  321.950898] softirqs last disabled at (47097):
>>> [<ffffffff8108747c>] irq_exit+0x9c/0x120
>>> +[  321.950903] CPU: 2 PID: 44 Comm: kworker/2:1 Not tainted
>>> 4.5.0-rc6-2-llvmlinux-amd64 #1
>>> +[  321.950905] Hardware name: SAMSUNG ELECTRONICS CO., LTD.
>>> 530U3BI/530U4BI/530U4BH/530U3BI/530U4BI/530U4BH, BIOS 13XK 03/28/2013
>>> +[  321.950908] Workqueue: usb_hub_wq hub_event
>>> +[  321.950911]  ffff8800d3326948 0000000000000092 0000000000000000
>>> ffff8800d4347568
>>> +[  321.950915]  ffffffff814ba7d4 ffff8800d43474f8 ffff8800d4340cc0
>>> ffff8800d4347568
>>> +[  321.950919]  ffffffff810e28fd 0000000000000092 0000000000000096
>>> ffff8800d43475a8
>>> +[  321.950923] Call Trace:
>>> +[  321.950927]  [<ffffffff814ba7d4>] dump_stack+0xa4/0xf0
>>> +[  321.950931]  [<ffffffff810e28fd>] ? print_irqtrace_events+0xcd/0xe0
>>> +[  321.950936]  [<ffffffff810bf495>] ___might_sleep+0x295/0x2b0
>>> +[  321.950939]  [<ffffffff810bf18f>] __might_sleep+0x4f/0xc0
>>> +[  321.950943]  [<ffffffff810a12ef>] start_flush_work+0x2f/0x2a0
>>> +[  321.950946]  [<ffffffff810a129c>] flush_work+0x5c/0x80
>>> +[  321.950949]  [<ffffffff810a125a>] ? flush_work+0x1a/0x80
>>> +[  321.950953]  [<ffffffff810e247d>] ? trace_hardirqs_off+0xd/0x10
>>> +[  321.950956]  [<ffffffff810a032a>] ? try_to_grab_pending+0x4a/0x260
>>> +[  321.950960]  [<ffffffff810a1717>] __cancel_work_timer+0x197/0x290
>>> +[  321.950963]  [<ffffffff81115b8d>] ? try_to_del_timer_sync+0xad/0xc0
>>> +[  321.950966]  [<ffffffff810a1578>] cancel_work_sync+0x18/0x20
>>
>> It's possible that this could be a compiler-related error connected
>> with local_irq_save().  __cancel_work_timer() calls
>>
>> 		ret = try_to_grab_pending(work, is_dwork, &flags);
>>
>> and try_to_grab_pending() starts this way:
>>
>> static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
>> 			       unsigned long *flags)
>> {
>> 	struct worker_pool *pool;
>> 	struct pool_workqueue *pwq;
>>
>> 	local_irq_save(*flags);
>>
>> Then later on, __cancel_work_timer() does
>>
>> 	local_irq_restore(flags);
>>
>> Maybe CLANG doesn't like local_irq_save() applied to a pointer as
>> opposed to a stack variable.
>>
>> As a quick test, try applying the patch below.  (Note that there is a
>> similar construction in kernel/signal.c.)
>>
>> Alan Stern
>>
>>
>>
>> Index: usb-4.4/kernel/workqueue.c
>> ===================================================================
>> --- usb-4.4.orig/kernel/workqueue.c
>> +++ usb-4.4/kernel/workqueue.c
>> @@ -1175,12 +1175,14 @@ out_put:
>>   * This function is safe to call from any context including IRQ handler.
>>   */
>>  static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
>> -			       unsigned long *flags)
>> +			       unsigned long *pflags)
>>  {
>>  	struct worker_pool *pool;
>>  	struct pool_workqueue *pwq;
>> +	unsigned long flags;
>>
>> -	local_irq_save(*flags);
>> +	local_irq_save(flags);
>> +	*pflags = flags;
>>
>>  	/* try to steal the timer if it exists */
>>  	if (is_dwork) {
>> @@ -1241,7 +1243,7 @@ static int try_to_grab_pending(struct wo
>>  	}
>>  	spin_unlock(&pool->lock);
>>  fail:
>> -	local_irq_restore(*flags);
>> +	local_irq_restore(flags);
>>  	if (work_is_canceling(work))
>>  		return -ENOENT;
>>  	cpu_relax();
>>
>>
>
> might_sleep() is invoked in start_flush_work(), but there are no
> "flags" passed to local_irq_{disable,enable}.
>
> What about something like this?
>
> @@ -2781,13 +2783,14 @@ static bool start_flush_work(struct
> work_struct *work, struct wq_barrier *barr)
>         struct worker *worker = NULL;
>         struct worker_pool *pool;
>         struct pool_workqueue *pwq;
> +       unsigned long flags;
>
>         might_sleep();
>
> -       local_irq_disable();
> +       local_irq_disable(flags);
>         pool = get_work_pool(work);
>         if (!pool) {
> -               local_irq_enable();
> +               local_irq_enable(flags);
>                 return false;
>         }
>

start_flush_work() is the only place where no flags are passed.
That stuff above does not work - no clue how to do that.
Any help?

Then I see there...
...
spin_lock(&pool->lock);
...
spin_unlock_irq(&pool->lock);
...

Should that be spin_lock_irq()?

static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr)
{
        struct worker *worker = NULL;
        struct worker_pool *pool;
        struct pool_workqueue *pwq;

        might_sleep();

        local_irq_disable();
        pool = get_work_pool(work);
        if (!pool) {
                local_irq_enable();
                return false;
        }

        spin_lock(&pool->lock); <--- XXX: spin_lock_irq() ???
        /* see the comment in try_to_grab_pending() with the same code */
        pwq = get_work_pwq(work);
        if (pwq) {
                if (unlikely(pwq->pool != pool))
                        goto already_gone;
        } else {
                worker = find_worker_executing_work(pool, work);
                if (!worker)
                        goto already_gone;
                pwq = worker->current_pwq;
        }

        check_flush_dependency(pwq->wq, work);

        insert_wq_barrier(pwq, barr, work, worker);
        spin_unlock_irq(&pool->lock);

        /*
         * If @max_active is 1 or rescuer is in use, flushing another work
         * item on the same workqueue may lead to deadlock.  Make sure the
         * flusher is not running on the same workqueue by verifying write
         * access.
         */
        if (pwq->wq->saved_max_active == 1 || pwq->wq->rescuer)
                lock_map_acquire(&pwq->wq->lockdep_map);
        else
                lock_map_acquire_read(&pwq->wq->lockdep_map);
        lock_map_release(&pwq->wq->lockdep_map);

        return true;
already_gone:
        spin_unlock_irq(&pool->lock);
        return false;
}

- Sedat -

  reply	other threads:[~2016-03-02  8:34 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-28  8:10 [PATCH] usbhid: Fix lockdep unannotated irqs-off warning Sedat Dilek
2015-09-28 11:33 ` Jiri Kosina
2015-09-29  8:40   ` Sedat Dilek
2015-09-29  9:27     ` Jiri Kosina
2015-09-29 18:54       ` Sedat Dilek
2015-09-29 19:08         ` Steven Rostedt
2015-09-29 19:32           ` Sedat Dilek
     [not found]       ` <CA+icZUWH2vR_vpYu4hCS578U3ssmoiF0pLYUfM-Xo-57e8uN=g@mail.gmail.com>
2015-09-30  6:41         ` Sedat Dilek
2015-09-30  8:50           ` Steven Rostedt
2015-09-30  7:35         ` Jiri Kosina
2015-09-30  8:56           ` Steven Rostedt
2015-09-30  9:46             ` Sedat Dilek
2015-09-30 10:13               ` Steven Rostedt
2015-09-30 10:39                 ` Sedat Dilek
     [not found]                 ` <CA+icZUXSzScTmMgLZwPQq9RMH9cUsD5_iDxKTVuG0rrGqH-8Cw@mail.gmail.com>
2015-10-01  2:01                   ` Steven Rostedt
2015-10-01  5:34                     ` Sedat Dilek
2015-10-01  6:05                     ` Sedat Dilek
     [not found]                       ` <CA+icZUUyaHqHP2v52juhGhoTNS9xX7LT2YxkOppLz6f9Z+FBEA@mail.gmail.com>
     [not found]                         ` <CA+icZUWagGMVNs5gBPRBhYO0LsY2A1hK3KSLabp9ZpDVOTmtig@mail.gmail.com>
2015-10-13  0:57                           ` Steven Rostedt
2016-03-01 10:05                             ` Sedat Dilek
2016-03-01 15:07                               ` Steven Rostedt
2016-03-01 15:17                                 ` Peter Zijlstra
2016-03-02 15:00                                   ` Sedat Dilek
2016-03-02 15:17                                     ` Peter Zijlstra
2016-03-02 15:34                                       ` Sedat Dilek
2016-03-02 15:53                                       ` Sedat Dilek
2016-03-02 15:56                                         ` Steven Rostedt
2016-03-02 16:08                                           ` Sedat Dilek
2016-03-02 16:11                                             ` Sedat Dilek
2016-03-02 16:21                                               ` Sedat Dilek
2016-03-02 16:24                                         ` Peter Zijlstra
2016-03-02 16:35                                           ` Steven Rostedt
2016-03-02 16:42                                             ` Peter Zijlstra
2016-03-02 16:42                                           ` Sedat Dilek
2016-03-02 16:52                                             ` Sedat Dilek
2016-03-01 15:59                               ` Alan Stern
2016-03-02  6:25                                 ` Sedat Dilek
2016-03-04 16:04                                   ` Alan Stern
2016-03-05 22:30                                     ` Sedat Dilek
2016-03-06  8:51                                       ` Sedat Dilek
2016-03-06 17:23                                       ` Alan Stern
2016-03-02  6:36                                 ` Sedat Dilek
2016-03-02  8:34                                   ` Sedat Dilek [this message]
2016-03-02  8:37                                     ` Jiri Kosina
2016-03-02  9:11                                       ` Sedat Dilek
     [not found]     ` <CA+icZUX3tJvRor6CbOZFBecTAUZzyWzjLzJSEdb3c12yKRAT3g@mail.gmail.com>
2015-09-29 13:13       ` Steven Rostedt
2016-03-07 15:59 Sedat Dilek
2016-03-07 16:28 ` Sedat Dilek
2016-03-07 16:41 ` Alan Stern
2016-03-07 17:03   ` Steven Rostedt
2016-03-07 17:05   ` Jiri Kosina
2016-03-07 17:15     ` Sedat Dilek
2016-03-07 17:27       ` David Laight
2016-03-07 18:07         ` Alan Stern
2016-03-07 18:30           ` Linus Torvalds
2016-06-27 19:50             ` Sedat Dilek
2016-06-27 20:03               ` Sedat Dilek
2016-06-27 20:14               ` Linus Torvalds
2016-06-27 20:27                 ` Sedat Dilek
2016-06-27 20:36                   ` Linus Torvalds
2016-03-07 17:11   ` Steven Rostedt
2016-03-07 17:18   ` Sedat Dilek
2016-03-07 17:24     ` Jiri Kosina
2016-03-07 17:30       ` Steven Rostedt
2016-03-07 18:04         ` Andy Lutomirski
2016-03-07 19:10           ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+icZUV9qDVLTAv_oj=Pj4Ry+f_kKUwJwejmGB+VBn4kzSLdTQ@mail.gmail.com' \
    --to=sedat.dilek@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jiangshanlai@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stern@rowland.harvard.edu \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.