Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1202517

Re: [PATCH] zram: fix possible race when checking idle_strm

From Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] zram: fix possible race when checking idle_strm
Date 2015-08-07 11:40 +0200
Message-ID <pUMi7-3UR-23@gated-at.bofh.it> (permalink)
References <pUKT1-21E-39@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On (08/07/15 17:03), Joonsoo Kim wrote:
> Currently, when we enter the wait state due to lack of idle stream,
> we check idle_strm list without holding the lock in expanding of
> wait_event define. In this case, some one can see stale value and
> process could fall into wait state without any upcoming wakeup process.
> Although I didn't see any error related to this race, it should be fixed.
> 
> To fix it, we should check idle_strm with holding the lock and
> this patch implements it.
> 
> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>

Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

> ---
>  drivers/block/zram/zcomp.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
> index 80a62e7..837e9c3 100644
> --- a/drivers/block/zram/zcomp.c
> +++ b/drivers/block/zram/zcomp.c
> @@ -76,6 +76,17 @@ static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp)
>  	return zstrm;
>  }
>  
> +static bool avail_idle_strm(struct zcomp_strm_multi *zs)
> +{
> +	int avail;
> +
> +	spin_lock(&zs->strm_lock);
> +	avail = !list_empty(&zs->idle_strm);
> +	spin_unlock(&zs->strm_lock);
> +
> +	return avail;
> +}
> +
>  /*
>   * get idle zcomp_strm or wait until other process release
>   * (zcomp_strm_release()) one for us
> @@ -97,7 +108,7 @@ static struct zcomp_strm *zcomp_strm_multi_find(struct zcomp *comp)
>  		/* zstrm streams limit reached, wait for idle stream */
>  		if (zs->avail_strm >= zs->max_strm) {
>  			spin_unlock(&zs->strm_lock);
> -			wait_event(zs->strm_wait, !list_empty(&zs->idle_strm));
> +			wait_event(zs->strm_wait, avail_idle_strm(zs));
>  			continue;
>  		}
>  		/* allocate new zstrm stream */
> @@ -109,7 +120,7 @@ static struct zcomp_strm *zcomp_strm_multi_find(struct zcomp *comp)
>  			spin_lock(&zs->strm_lock);
>  			zs->avail_strm--;
>  			spin_unlock(&zs->strm_lock);
> -			wait_event(zs->strm_wait, !list_empty(&zs->idle_strm));
> +			wait_event(zs->strm_wait, avail_idle_strm(zs));
>  			continue;
>  		}
>  		break;
> -- 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] zram: fix possible race when checking idle_strm Joonsoo Kim <js1304@gmail.com> - 2015-08-07 10:10 +0200
  Re: [PATCH] zram: fix possible race when checking idle_strm Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-08-07 11:20 +0200
    Re: [PATCH] zram: fix possible race when checking idle_strm Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-08-07 11:40 +0200
  Re: [PATCH] zram: fix possible race when checking idle_strm Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-08-07 11:20 +0200
    Re: [PATCH] zram: fix possible race when checking idle_strm Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-08-07 12:00 +0200
      Re: [PATCH] zram: fix possible race when checking idle_strm Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2015-08-10 02:30 +0200
        Re: [PATCH] zram: fix possible race when checking idle_strm Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-08-10 04:20 +0200
          Re: [PATCH] zram: fix possible race when checking idle_strm Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2015-08-11 10:30 +0200
        Re: [PATCH] zram: fix possible race when checking idle_strm Minchan Kim <minchan@kernel.org> - 2015-08-11 01:30 +0200
          Re: [PATCH] zram: fix possible race when checking idle_strm Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-08-11 10:30 +0200
          Re: [PATCH] zram: fix possible race when checking idle_strm Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2015-08-11 10:30 +0200
  Re: [PATCH] zram: fix possible race when checking idle_strm Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-08-07 11:40 +0200
    Re: [PATCH] zram: fix possible race when checking idle_strm Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-08-07 12:20 +0200
  Re: [PATCH] zram: fix possible race when checking idle_strm Minchan Kim <minchan@kernel.org> - 2015-08-07 16:50 +0200
    Re: [PATCH] zram: fix possible race when checking idle_strm Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2015-08-10 02:30 +0200

csiph-web