All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Shuah Khan <shuah.kh@samsung.com>
Cc: gregkh@linuxfoundation.org, m.chehab@samsung.com,
	rafael.j.wysocki@intel.com, linux@roeck-us.net,
	toshi.kani@hp.com, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org, shuahkhan@gmail.com
Subject: Re: [RFC PATCH 2/2] drivers/base: add managed token devres interfaces
Date: Thu, 17 Apr 2014 16:22:21 -0400	[thread overview]
Message-ID: <20140417202221.GU15326@htj.dyndns.org> (raw)
In-Reply-To: <20140417201034.GT15326@htj.dyndns.org>

On Thu, Apr 17, 2014 at 04:10:34PM -0400, Tejun Heo wrote:
> On Thu, Apr 17, 2014 at 02:01:32PM -0600, Shuah Khan wrote:
> > Operating on the lock should be atomic, which is what devres_update()
> > is doing. It can be simplified as follows by holding devres_lock
> > in devm_token_lock().
> > 
> > spin_lock_irqsave(&dev->devres_lock, flags);
> > if (tkn_ptr->status == TOKEN_DEVRES_FREE)
> > 	tkn_ptr->status = TOKEN_DEVRES_BUSY;
> > spin_unlock_irqrestore(&dev->devres_lock, flags);
> > 
> > Is this in-line with what you have in mind?
> 
> How is that different from tkn_ptr->status = TOKEN_DEVRES_BUSY?

Let me clear it up.  How could the code snippet that you wrote
possibly function as a lock between two threads?  You're doing the
following.


	if (state == busy)
		return -EBUSY;

	spin_lock;
	if (state == free)
		state = busy;
	spin_unlock;

	return SUCCESS!!!11!!1!!;

The above is equivalent to

	if (state == busy)
		return -EBUSY;
	state = busy;
	return SUCCESS!!!11!!1!!;

Now, if you let two threads compete on it, both can return SUCCESS.
Can you see that?

Please consult with somebody who has basic understanding of
concurrency and synchronization.  Please do not implement locking
primitive directly if at all avoidable.  Why can't it use a mutex
embedded in the data area of a devres entry?  And if you for some
reason have to implement it directly, at least add lockdep
annotations.

Anyways, I really think this needs help from somebody who knows
better.

Thanks.

-- 
tejun

  reply	other threads:[~2014-04-17 20:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-09 15:21 [RFC PATCH 0/2] managed token devres interfaces Shuah Khan
2014-04-09 15:21 ` [RFC PATCH 1/2] drivers/base: add new devres_update() interface to devres_* Shuah Khan
2014-04-09 15:21 ` [RFC PATCH 2/2] drivers/base: add managed token devres interfaces Shuah Khan
2014-04-16 21:58   ` Tejun Heo
2014-04-17 20:01     ` Shuah Khan
2014-04-17 20:10       ` Tejun Heo
2014-04-17 20:22         ` Tejun Heo [this message]
2014-04-17 23:27           ` Shuah Khan
2014-04-17 20:50         ` Shuah Khan
2014-04-09 19:17 ` [RFC PATCH 0/2] " Greg KH
2014-04-09 22:44   ` Shuah Khan
2014-04-10 11:04     ` One Thousand Gnomes
2014-04-10 11:38       ` Mauro Carvalho Chehab
2014-04-10 11:46         ` One Thousand Gnomes
2014-04-10 14:39           ` Mauro Carvalho Chehab
2014-04-11 20:28             ` Shuah Khan
2014-04-14 22:48             ` Shuah Khan
2014-04-10 14:32         ` Shuah Khan

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=20140417202221.GU15326@htj.dyndns.org \
    --to=tj@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=m.chehab@samsung.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=shuah.kh@samsung.com \
    --cc=shuahkhan@gmail.com \
    --cc=toshi.kani@hp.com \
    /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.