From: Ingo Rohloff <ingo.rohloff@lauterbach.com>
To: Neill Kapron <nkapron@google.com>
Cc: gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk,
me@samcday.com, michael.bommarito@gmail.com,
linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 2/2] usb: gadget: f_fs: register cancellation handler only after request queueing
Date: Wed, 18 Nov 2026 14:00:31 +0100 [thread overview]
Message-ID: <20261118140031.2f78df2b@ingpc2.intern.lauterbach.com> (raw)
In-Reply-To: <179495726171.2705769.12448849995784836228.b4-reply@b4>
Hello Neill,
Thanks for the explanation!
> with lockdep enabled, we get the following trace on a VM with dummy_hcd
> and a simple ffs test application:
>
========================================================
> WARNING: possible irq lock inversion dependency detected
> 7.4.0-rc3-g9b73231bde82 #2 Not tainted
> --------------------------------------------------------
> kworker/u64:0/13 just changed the state of lock:
> ffff8881014ebb40 (&io_data->aio_completion_lock){+.+.}-{3:3}, at: ffs_user_copy_worker+0x4b/0x170
> but this lock was taken by another, SOFTIRQ-safe lock in the past:
> (&ffs->eps_lock){..-.}-{3:3}
>
>
> and interrupts could create inverse lock ordering between them.
>
> other info that might help us debug this:
> Possible interrupt unsafe locking scenario:
>
> CPU0 CPU1
> ---- ----
> lock(&io_data->aio_completion_lock);
> local_irq_disable();
> lock(&ffs->eps_lock);
> lock(&io_data->aio_completion_lock);
> <Interrupt>
> lock(&ffs->eps_lock);
Ah now I understand :-)
I still don't think this can happen, because the
"lock(&io_data->aio_completion_lock);" on CPU0 can't happen
before the "lock(&io_data->aio_completion_lock);" on CPU1,
because the request first has to be scheduled via "usb_ep_queue()"
on CPU1 as far as I can tell.
But this argument sounds rather fragile...
> Switching ffs_user_copy_worker() to spin_lock_irq() / spin_unlock_irq()
> resolves the lockdep warning in testing.
If using the "_irq" variant satisfies lockdep, then it's certainly better
to use the "_irq" variants; after all the whole point of lockdep is
to find these kind of issues.
I will post another V3 patch variant, which will use the "_irq" variants.
with best regards
Ingo
On Tue, 17 Nov 2026 23:14:21 +0000
Neill Kapron <nkapron@google.com> wrote:
> On 2026-11-17 12:21:53+01:00, Ingo Rohloff wrote:
> > Hello Neill,
> >
> > > > @@ -887,7 +888,9 @@ static void ffs_user_copy_worker(struct work_struct *work)
> > >
> > > ffs_epfile_io() grabs the lock while holding ffs->eps_lock in interrupt
> > > context. Therefore, I think this could lead to lock inversion if we
> > > don't call with with spin_lock_irq() and a spin_unlock_irq(). Could you
> > > send a v3 with _irq() or the save/restore equivalents here?
> >
> > I can change that to the "_irq()" variants (this should be harmless),
> > but I would like to understand why.
> >
> > "ffs_epfile_io()" itself does not run in interrupt context.
> > That's also why it uses "spin_lock_irq(&epfile->ffs->eps_lock);",
> > unconditionally blocking IRQs.
>
> Hi Ingo,
>
> Sorry for the confusion- I misinterpreted the lockdep splat. You are
> correct that ffs_epfile_io() does not run in interrupt context, but with
> lockdep enabled, we get the following trace on a VM with dummy_hcd and a
> simple ffs test application):
>
> ========================================================
> WARNING: possible irq lock inversion dependency detected
> 7.4.0-rc3-g9b73231bde82 #2 Not tainted
> --------------------------------------------------------
> kworker/u64:0/13 just changed the state of lock:
> ffff8881014ebb40 (&io_data->aio_completion_lock){+.+.}-{3:3}, at: ffs_user_copy_worker+0x4b/0x170
> but this lock was taken by another, SOFTIRQ-safe lock in the past:
> (&ffs->eps_lock){..-.}-{3:3}
>
>
> and interrupts could create inverse lock ordering between them.
>
> other info that might help us debug this:
> Possible interrupt unsafe locking scenario:
>
> CPU0 CPU1
> ---- ----
> lock(&io_data->aio_completion_lock);
> local_irq_disable();
> lock(&ffs->eps_lock);
> lock(&io_data->aio_completion_lock);
> <Interrupt>
> lock(&ffs->eps_lock);
>
> *** DEADLOCK ***
> [...]
> the shortest dependencies between 2nd lock and 1st lock:
> -> (&ffs->eps_lock){..-.}-{3:3} {
> IN-SOFTIRQ-W at:
> lock_acquire+0xcf/0x2e0
> _raw_spin_lock_irqsave+0x35/0x50
> ffs_func_set_alt+0xaf/0x2b0
> composite_setup+0xc37/0x2000
> configfs_composite_setup+0x73/0xa0
> dummy_timer+0xa5c/0xe10
> __hrtimer_run_queues+0x146/0x310
> hrtimer_run_softirq+0x89/0xf0
> [...]
> }
> ... acquired at:
> lock_acquire+0xcf/0x2e0
> _raw_spin_lock+0x2c/0x40
> ffs_epfile_io+0x652/0x8c0
> ffs_epfile_read_iter+0x11a/0x1c0
> aio_read+0x12d/0x210
>
> -> (&io_data->aio_completion_lock){+.+.}-{3:3} {
> HARDIRQ-ON-W at:
> lock_acquire+0xcf/0x2e0
> _raw_spin_lock+0x2c/0x40
> ffs_user_copy_worker+0x4b/0x170
> process_one_work+0x278/0x6e0
> SOFTIRQ-ON-W at:
> lock_acquire+0xcf/0x2e0
> _raw_spin_lock+0x2c/0x40
> ffs_user_copy_worker+0x4b/0x170
> process_one_work+0x278/0x6e0
> [...]
> }
>
> Switching ffs_user_copy_worker() to spin_lock_irq() / spin_unlock_irq()
> resolves the lockdep warning in testing.
>
> Thanks,
> Neill
>
--
-------------------------------------------------------------------------
Dipl.-Inform.
Ingo ROHLOFF
Senior Staff Engineer
phone +49 8102 9876-142 - ingo.rohloff@lauterbach.com
Lauterbach Engineering GmbH & Co. KG
Altlaufstrasse 40, 85635 Hoehenkirchen-Siegertsbrunn, GERMANY
www.lauterbach.com
Registered Office: Hoehenkirchen-Siegertsbrunn, Germany,
Local Court: Munich, HRA 87406, VAT ID: DE246770537,
Managing Directors: Stephan Lauterbach, Dr. Thomas Ullmann
-------------------------------------------------------------------------
prev parent reply other threads:[~2026-11-18 13:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 17:12 [PATCH v2 0/2] usb: gadget: f_fs: cancellation fix Ingo Rohloff
2026-11-10 17:12 ` [PATCH v2 1/2] usb: gadget: f_fs: simplify error handling using goto Ingo Rohloff
2026-11-10 17:12 ` [PATCH v2 2/2] usb: gadget: f_fs: register cancellation handler only after request queueing Ingo Rohloff
2026-11-16 23:32 ` Neill Kapron
2026-11-17 11:21 ` Ingo Rohloff
2026-11-17 23:14 ` Neill Kapron
2026-11-18 13:00 ` Ingo Rohloff [this message]
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=20261118140031.2f78df2b@ingpc2.intern.lauterbach.com \
--to=ingo.rohloff@lauterbach.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=me@samcday.com \
--cc=michael.bommarito@gmail.com \
--cc=nkapron@google.com \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox