public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rohit Sarkar <rohitsarkar5398@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	alexandru.ardelean@analog.com, dragos.bogdan@analog.com
Subject: Re: [PATCH v4] iio: adc: max1363: replace uses of mlock
Date: Sun, 8 Mar 2020 23:01:12 +0530	[thread overview]
Message-ID: <5e652be5.1c69fb81.bdd67.92b5@mx.google.com> (raw)
In-Reply-To: <20200308161426.716d1ffb@archlinux>

On Sun, Mar 08, 2020 at 04:14:26PM +0000, Jonathan Cameron wrote:
> On Sun, 8 Mar 2020 02:32:56 +0530
> Rohit Sarkar <rohitsarkar5398@gmail.com> wrote:
> 
> > On Sat, Mar 07, 2020 at 02:19:46PM +0000, Jonathan Cameron wrote:
> > > On Sat, 7 Mar 2020 13:34:51 +0530
> > > Rohit Sarkar <rohitsarkar5398@gmail.com> wrote:
> > >   
> > > > Replace usage indio_dev's mlock with either local lock or
> > > > iio_device_claim_direct_mode.
> > > > 
> > > > Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>  
> > > 
> > > There is a subtlety in here (which is why this one never
> > > got cleaned up before).  We need to protect against:
> > > 
> > > 1) Driver state being accessed from multiple places concurrently.
> > >    That will use your new lock.
> > > 2) Doing actions that cannot occur if in buffered mode.  The
> > >    claim_direct_mode stuff is for that.  
> > I did consider using both, the local driver lock and the claim_direct in
> > some places, however I noticed that the claim_direct_mode internally uses
> > the mlock, hence I didnt think it was necessary to set the local lock as
> > well, as according to my understanding once a process acquires the mlock
> > no other process can run the critical section before the initial process
> > releases the mlock. Thus the driver state also remains consistent.
> 
> Any state changes in the driver done under the local lock can still happen.
> There is also a question of 'obviousness'.  The driver code should not
> 'care' what the internals of claim_direct_mode is doing.
> That can be expected to protect against moving out of direct mode, but
> not anything about 'how'.
> 
> Hence, take them both.

That does make sense, when I thought about it again I realised doing
this is essentially what was wrong with the code in the first place.
Thanks for the pointers. Will send out an update.
Thanks,
Rohit

      reply	other threads:[~2020-03-08 17:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-07  8:04 [PATCH v4] iio: adc: max1363: replace uses of mlock Rohit Sarkar
2020-03-07 14:19 ` Jonathan Cameron
2020-03-07 21:02   ` Rohit Sarkar
2020-03-08 16:14     ` Jonathan Cameron
2020-03-08 17:31       ` Rohit Sarkar [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=5e652be5.1c69fb81.bdd67.92b5@mx.google.com \
    --to=rohitsarkar5398@gmail.com \
    --cc=alexandru.ardelean@analog.com \
    --cc=dragos.bogdan@analog.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@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