2006-03-09 23:24:16

by Roland Dreier

[permalink] [raw]
Subject: Re: [PATCH 9 of 20] ipath - char devices for diagnostics and lightweight subnet management

> +static int ipath_sma_open(struct inode *in, struct file *fp)
> +{
> + int s;
> +
> + if (ipath_sma_alive) {
> + ipath_dbg("SMA already running (pid %u), failing\n",
> + ipath_sma_alive);
> + return -EBUSY;
> + }
> +
> + for (s = 0; s < atomic_read(&ipath_max); s++) {
> + struct ipath_devdata *dd = ipath_lookup(s);
> + /* we need at least one infinipath device to be initialized. */
> + if (dd && dd->ipath_flags & IPATH_INITTED) {
> + ipath_sma_alive = current->pid;

It seems there's a window here where two processes can both pass the
if (ipath_sma_alive) test and then proceed to step on each other.

- R.


2006-03-09 23:49:55

by Bryan O'Sullivan

[permalink] [raw]
Subject: Re: [PATCH 9 of 20] ipath - char devices for diagnostics and lightweight subnet management

On Thu, 2006-03-09 at 15:24 -0800, Roland Dreier wrote:

> It seems there's a window here where two processes can both pass the
> if (ipath_sma_alive) test and then proceed to step on each other.

Yep, this is a real race, albeit incredibly unlikely. I just turned
ipath_sma_alive into an atomic_t, and wrapped the open/close code in
spinlocks.

<b

2006-03-09 23:51:38

by Roland Dreier

[permalink] [raw]
Subject: Re: [PATCH 9 of 20] ipath - char devices for diagnostics and lightweight subnet management

Bryan> Yep, this is a real race, albeit incredibly unlikely. I
Bryan> just turned ipath_sma_alive into an atomic_t, and wrapped
Bryan> the open/close code in spinlocks.

How does making it an atomic_t help? I think you're only going to be
using atomic_set() and atomic_read(), and atomic_t doesn't provide
anything in that case.

- R.