From: Jiri Kosina <jikos@kernel.org>
To: Gary King <gary.king@oculus.com>
Cc: benjamin.tissoires@redhat.com, linux-input@vger.kernel.org
Subject: Re: [PATCH] hidraw: fix list->buffer race condition
Date: Mon, 10 Oct 2016 10:36:57 +0200 (CEST) [thread overview]
Message-ID: <alpine.LNX.2.00.1610101019040.31629@cbobk.fhfr.pm> (raw)
In-Reply-To: <alpine.OSX.1.10.1610071027351.23556@cromulentg-mba.local>
On Fri, 7 Oct 2016, Gary King wrote:
> > > diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
> > > index f0e2757..dc3465f 100644
> > > --- a/drivers/hid/hidraw.c
> > > +++ b/drivers/hid/hidraw.c
> > > @@ -53,6 +53,7 @@ static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count,
> > > mutex_lock(&list->read_mutex);
> > >
> > > while (ret == 0) {
> > > + smp_rmb();
> >
> > Which _wmb() does this one pair with?
>
> The _rmb() operations don't really pair with the _wmb()
That unfortunately immediately implies that its usage is incorrect though.
[ ... snip ... ]
> > I think this is just papering the real problem (missing list_lock) over in
> > an odd way; could you please look into whether locking list_lock properly
> > would resolve the crashes you're able to trigger on your ARM system?
>
> list_lock does not appear to be a good solution for this, since it is
> currently an IRQ-safe spinlock on the device. Using it would cause
> _read() to have unnecessary lock contention if the device is opened
> and read simultaneously from multiple fds, and every loop iteration would
> need to acquire the spinlock / disable interrupts at least once.
We could make the spinlock per struct file *, which'd remove the
contention bottleneck when the same device is accessed from through
multiple fds, but still maintain the correctness (as the list itself is a
per-fd thing anyway).
Probably introducing new spinlock would make more sense, as list_lock is
currently being used mostly to protect accessing of the dev->list linked
list.
> (Separately, the current locking design seems dangerous to me, since the
> amount of time spent with interrupts disabled in the current
> implementation may be arbitrarily long (the device may be opened
> multiple times, and the hidraw event buffer that is kmemdup'd for each
> open fd may be large),
We're memduping with GFP_ATOMIC of course, so there is really no
bottleneck there.
Thanks,
--
Jiri Kosina
SUSE Labs
next prev parent reply other threads:[~2016-10-10 9:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-05 0:44 [PATCH] hidraw: fix list->buffer race condition Gary King
2016-10-05 7:53 ` Benjamin Tissoires
2016-10-07 8:43 ` Jiri Kosina
2016-10-07 8:43 ` Jiri Kosina
2016-10-07 17:30 ` Gary King
2016-10-10 8:36 ` Jiri Kosina [this message]
2016-10-11 3:12 ` Dmitry Torokhov
2016-10-14 1:29 ` Gary King
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=alpine.LNX.2.00.1610101019040.31629@cbobk.fhfr.pm \
--to=jikos@kernel.org \
--cc=benjamin.tissoires@redhat.com \
--cc=gary.king@oculus.com \
--cc=linux-input@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox