linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Douglas Gilbert <dgilbert@interlog.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	SCSI development list <linux-scsi@vger.kernel.org>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	vaughan <vaughan.cao@oracle.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] sg: O_EXCL and other lock handling
Date: Wed, 6 Nov 2013 07:50:44 -0800	[thread overview]
Message-ID: <20131106155044.GA9323@infradead.org> (raw)
In-Reply-To: <5272AD80.90203@interlog.com>

On Thu, Oct 31, 2013 at 03:20:32PM -0400, Douglas Gilbert wrote:
> Yes, it is being used as a mutex. However looking at
> their semantics (mutex.h versus semaphore.h), a mutex
> takes into account the task owner. If the user space
> wants to pass around a sg file descriptor in a Unix
> domain socket (see TLPI, Kerrisk) I don't see why the
> sg driver should object (and pay the small performance
> hit for each check).

The sg driver won't object.  The lock is taken again and released
during sg_open and sg_release, which are guranteed not to migrate
to a different process during their run time.

> section) but why bother. Give me a simple mutex and
> I'll use it.

mutex_init/mutex_lock/mutex_unlock from <linux/mutex.h>

> Not (usually) in this case. The sdp->sfds list can only
> be expanded by another sg_open(same_dev) but this has
> been excluded by taking down(&sdp->or_sem) prior to that
> call. The sdp->sfds list is only normally decreased by
> sg_release() which is also excluded by down(&sdp->or_sem).

> The abnormal case is device removal (detaching). Now an
> open(same_dev, O_EXCL) may start waiting just after a
> detach but miss the wake up on open_wait. That suggests
> the wake_up(open_wait) in sg_remove() should also
> take the sdp->or_sem semaphore.
> Ah, and if sg_remove() can be called from an interrupt
> context then that takes out using mutexes :-)

I don't think that sg_remove can be called from irq context.
It always is called through the class interface remove_dev
method, which always is called under a lock.

> The two level of locks in sg_remove() is already making me
> uncomfortable, adding the sdp->or_sem semaphore to the
> mix calls for more analysis.

I would suggest to remove the list lock and only use the or_sem
replacement.

> IMO that is a bug in scsi_block_when_processing_errors()
> and the down() is placed lower than it should be in
> sg_open() to account for that bug.

How about we get that fixed first?


  parent reply	other threads:[~2013-11-06 15:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30 22:24 [PATCH v2] sg: O_EXCL and other lock handling Douglas Gilbert
2013-10-31 15:56 ` Christoph Hellwig
2013-10-31 19:20   ` Douglas Gilbert
2013-11-01  5:14     ` vaughan
2013-11-01  5:16     ` vaughan
2013-11-02 18:22       ` Douglas Gilbert
2013-11-03  6:32         ` Vaughan Cao
2013-11-06 15:50     ` Christoph Hellwig [this message]
2013-11-06 19:30       ` Douglas Gilbert
2013-11-07 21:44         ` Christoph Hellwig

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=20131106155044.GA9323@infradead.org \
    --to=hch@infradead.org \
    --cc=dgilbert@interlog.com \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=vaughan.cao@oracle.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 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).