All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Amerigo Wang <amwang@redhat.com>
Cc: dhowells@redhat.com, linux-kernel@vger.kernel.org,
	Brian Behlendorf <behlendorf1@llnl.gov>,
	Ben Woodard <bwoodard@llnl.gov>, Stable Team <stable@kernel.org>,
	akpm@linux-foundation.org
Subject: Re: [Patch v2] rwsem: fix rwsem_is_locked() bugs
Date: Mon, 05 Oct 2009 14:13:22 +0100	[thread overview]
Message-ID: <22214.1254748402@redhat.com> (raw)
In-Reply-To: <20091005063919.3958.65581.sendpatchset@localhost.localdomain>

Amerigo Wang <amwang@redhat.com> wrote:

> -	return (sem->activity != 0);
> +	return !(sem->activity == 0 && list_empty(&sem->wait_list));

This needs to be done in the opposite order with an smp_rmb() between[*], I
think, because the someone releasing the lock will first reduce activity to
zero, and then attempt to empty the list, so with your altered code as it
stands, you can get:

	CPU 1				CPU 2
	===============================	===============================
	[sem is read locked, 1 queued writer]
	-->up_read()
	sem->activity--			-->rwsem_is_locked()
	[sem->activity now 0]		sem->activity == 0 [true]
					<interrupt>
	-->__rwsem_do_wake()
	sem->activity = -1
	[sem->activity now !=0]
	list_del()
	[sem->wait_list now empty]	</interrupt>
					list_empty(&sem->wait_list) [true]
	wake_up_process()
	<--__rwsem_do_wake()
	<--up_read()
	[sem is write locked]		return false [ie. sem is not locked]

In fact, I don't think even swapping things around addresses the problem.  You
do not prevent the state inside the sem changing under you whilst you try to
interpret it.

[*] there would also need to be an smp_wmb() between the update of
    sem->activity and the deletion from sem->wait_list to balance out the
    smp_rmb().

David

  reply	other threads:[~2009-10-05 13:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-05  6:36 [Patch v2] rwsem: fix rwsem_is_locked() bugs Amerigo Wang
2009-10-05 13:13 ` David Howells [this message]
2009-10-06  7:02   ` Amerigo Wang
2009-10-06  7:18     ` David Howells

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=22214.1254748402@redhat.com \
    --to=dhowells@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=amwang@redhat.com \
    --cc=behlendorf1@llnl.gov \
    --cc=bwoodard@llnl.gov \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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 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.