linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "Ed L. Cashin" <ecashin@coraid.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 09/13] remove race between use and initialization of locks
Date: Fri, 21 Dec 2007 22:00:40 -0800	[thread overview]
Message-ID: <20071221220040.5862b43b.akpm@linux-foundation.org> (raw)
In-Reply-To: <1198188961-25147-9-git-send-email-ecashin@coraid.com>

On Thu, 20 Dec 2007 17:15:57 -0500 "Ed L. Cashin" <ecashin@coraid.com> wrote:

> Alexey Dobriyan noticed a race in the initialization of the dynamic
> locks in ...
> 
>   Message-ID: <20070325190221.GA5308@martell.zuzino.mipt.ru>
> 
> Andrew Morton commented that these locks should be initialized at
> compile time, so this patch does that.
> 
> Signed-off-by: Ed L. Cashin <ecashin@coraid.com>
> ---
>  drivers/block/aoe/aoechr.c |    6 ++----
>  1 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
> index 1bc85aa..670bba6 100644
> --- a/drivers/block/aoe/aoechr.c
> +++ b/drivers/block/aoe/aoechr.c
> @@ -35,8 +35,8 @@ struct ErrMsg {
>  
>  static struct ErrMsg emsgs[NMSG];
>  static int emsgs_head_idx, emsgs_tail_idx;
> -static struct semaphore emsgs_sema;
> -static spinlock_t emsgs_lock;
> +static __DECLARE_SEMAPHORE_GENERIC(emsgs_sema, 0);

That's not very attractive.  This would be the only user of
__DECLARE_SEMAPHORE_GENERIC() in the tree.  It seems that all architectures
(apart from uml) do implement this (although I didn't verify that they all
offer the same interface for it).  But still...

And no, we don't appear to have a proper interface to statically declare a
locked semaphore.  Nor do we appear to have one for mutexes(!).

> +static DEFINE_SPINLOCK(emsgs_lock);
>  static int nblocked_emsgs_readers;
>  static struct class *aoe_class;
>  static struct aoe_chardev chardevs[] = {
> @@ -264,8 +264,6 @@ aoechr_init(void)
>  		printk(KERN_ERR "aoe: can't register char device\n");
>  		return n;
>  	}
> -	sema_init(&emsgs_sema, 0);
> -	spin_lock_init(&emsgs_lock);
>  	aoe_class = class_create(THIS_MODULE, "aoe");
>  	if (IS_ERR(aoe_class)) {
>  		unregister_chrdev(AOE_MAJOR, "aoechr");

I think it would be better to go back to initialising emsgs_lock at runtime
rather than fattening the exported semaphore API like this.

emssgs_sema is a weird-looking thing.  There really should be some comments
in there because it is unobvious what the code is attempting to do.

What is the code attempting to do?

It appears to me that nblocked_emsgs_readers gets incorrectly decremented
if the down_interruptible() got interrupted, btw.  

  reply	other threads:[~2007-12-22  6:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-20 22:15 [PATCH 01/13] bring driver version number to 47 Ed L. Cashin
2007-12-20 22:15 ` [PATCH 02/13] handle multiple network paths to AoE device Ed L. Cashin
2007-12-20 22:15 ` [PATCH 03/13] mac_addr: avoid 64-bit arch compiler warnings Ed L. Cashin
2007-12-20 22:15 ` [PATCH 04/13] clean up udev configuration example Ed L. Cashin
2007-12-20 22:15 ` [PATCH 05/13] eliminate goto and improve readability Ed L. Cashin
2007-12-20 22:15 ` [PATCH 06/13] user can ask driver to forget previously detected devices Ed L. Cashin
2007-12-20 22:15 ` [PATCH 07/13] dynamically allocate a capped number of skbs when necessary Ed L. Cashin
2007-12-20 22:15 ` [PATCH 08/13] only install new AoE device once Ed L. Cashin
2007-12-20 22:15 ` [PATCH 09/13] remove race between use and initialization of locks Ed L. Cashin
2007-12-22  6:00   ` Andrew Morton [this message]
2007-12-26 19:28     ` Ed L. Cashin
2007-12-26 20:25     ` [PATCH] aoe: initialize locking structures before registering char devices Ed L. Cashin
2007-12-26 20:35     ` [PATCH] aoe: document the behavior of /dev/etherd/err Ed L. Cashin
2007-12-20 22:15 ` [PATCH 10/13] add module parameter for users who need more outstanding I/O Ed L. Cashin
2007-12-20 22:15 ` [PATCH 11/13] the aoeminor doesn't need a long format Ed L. Cashin
2007-12-20 22:16 ` [PATCH 12/13] make error messages more specific Ed L. Cashin
2007-12-20 22:16 ` [PATCH 13/13] update copyright date Ed L. Cashin
2007-12-22  6:03   ` Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2007-12-07 17:47 [PATCH 01/13] bring driver version number to 47 Ed L. Cashin
2007-12-07 17:48 ` [PATCH 09/13] remove race between use and initialization of locks Ed L. Cashin

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=20071221220040.5862b43b.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=ecashin@coraid.com \
    --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;
as well as URLs for NNTP newsgroup(s).