linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Binoy Jayan <binoy.jayan@linaro.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: David Herrmann <dh.herrmann@gmail.com>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	"open list:HID CORE LAYER" <linux-input@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Rajendra <rnayak@codeaurora.org>, Mark Brown <broonie@kernel.org>,
	Jiri Kosina <jikos@kernel.org>,
	David Herrmann <dh.herrmann@googlemail.com>,
	Andrew de los Reyes <adlr@chromium.org>
Subject: Re: [PATCH v2] HID: Replace semaphore driver_lock with mutex
Date: Wed, 14 Jun 2017 10:52:31 +0530	[thread overview]
Message-ID: <CAHv-k_9Wxt+TkeTssLizjf5WNZAgfMy1bcXGPBfMePsNLRAY1Q@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a3bzOv6T_6mgjrEZupb4t5vi2JDZVze2qbNXmOiY1BDBA@mail.gmail.com>

Hi,

On 14 June 2017 at 01:55, Arnd Bergmann <arnd@arndb.de> wrote:

>> The mutex code clearly states mutex_trylock() must not be used in
>> interrupt context (see kernel/locking/mutex.c), hence we used a
>> semaphore here. Unless the mutex code is changed to allow this, we
>> cannot switch away from semaphores.
>
> Right, that makes a lot of sense. I don't think changing the mutex
> code is an option here, but I wonder if we can replace the semaphore
> with something simpler anyway.
>
> From what I can tell, it currently does two things:
>
> 1. it acts as a simple flag to prevent  hid_input_report from derefencing
>     the hid->driver pointer during initialization and exit. I think this could
>     be done equally well using a simple atomic set_bit()/test_bit() or similar.
>
> 2. it prevents the hid->driver pointer from becoming invalid while an
>     asynchronous hid_input_report() is in progress. This actually seems to
>     be a reference counting problem rather than a locking problem.
>     I don't immediately see how to better address it, or how exactly this
>     could go wrong in practice, but I would naively expect that either
>     hdev->driver->remove() needs to wait for the last user of hdev->driver
>     to complete, or we need kref_get/kref_put in hid_input_report()
>     to trigger the actual release function.

Thank you everyone for the comments. I'll resend the patch with Benjamin's
comments incorporated and address the changes in the second semaphore later.

Regards,
Binoy

  reply	other threads:[~2017-06-14  5:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1497345926-3262-1-git-send-email-binoy.jayan@linaro.org>
     [not found] ` <CAK8P3a27bGLpisra1YDT7VntWByk6oS0Fz3e2E0-Nmf-6pVYCA@mail.gmail.com>
2017-06-13  9:56   ` [PATCH v2] HID: Replace semaphore driver_lock with mutex Benjamin Tissoires
2017-06-13 10:09     ` Binoy Jayan
2017-06-13 20:00       ` Arnd Bergmann
2017-06-13 15:43     ` David Herrmann
2017-06-13 20:25       ` Arnd Bergmann
2017-06-14  5:22         ` Binoy Jayan [this message]
2017-06-14  7:20           ` Arnd Bergmann
2017-06-14  7:45             ` David Herrmann
2017-06-14 11:58               ` Arnd Bergmann
2017-06-19 10:20                 ` David Herrmann

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=CAHv-k_9Wxt+TkeTssLizjf5WNZAgfMy1bcXGPBfMePsNLRAY1Q@mail.gmail.com \
    --to=binoy.jayan@linaro.org \
    --cc=adlr@chromium.org \
    --cc=arnd@arndb.de \
    --cc=benjamin.tissoires@redhat.com \
    --cc=broonie@kernel.org \
    --cc=dh.herrmann@gmail.com \
    --cc=dh.herrmann@googlemail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rnayak@codeaurora.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;
as well as URLs for NNTP newsgroup(s).