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


Groups > linux.kernel > #1310919

Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition

From Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition
Date 2016-01-16 11:10 +0100
Message-ID <qRvXY-2Ws-13@gated-at.bofh.it> (permalink)
References (2 earlier) <qReNs-89q-9@gated-at.bofh.it> <qRqvf-7Hg-3@gated-at.bofh.it> <qRtMu-1ox-1@gated-at.bofh.it> <qRu5Q-1Kr-9@gated-at.bofh.it> <qRufw-1NG-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On (01/16/16 09:16), Vlastimil Babka wrote:
[..]
> BTW, couldn't the correct fix also just look like this?
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 9f15bdd9163c..43f743175ede 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -1635,8 +1635,8 @@ static int migrate_zspage(struct zs_pool *pool, struct
> size_class *class,
>                 free_obj = obj_malloc(d_page, class, handle);
>                 zs_object_copy(free_obj, used_obj, class);
>                 index++;
> +               /* This also effectively unpins the handle */
>                 record_obj(handle, free_obj);
> -               unpin_tag(handle);
>                 obj_free(pool, class, used_obj);
>         }

I think this will work.


> But I'd still recommend WRITE_ONCE in record_obj(). And I'm not even sure it's
> safe on all architectures to do a simple overwrite of a word against somebody
> else trying to lock a bit there?

hm... for example, generic bitops from include/asm-generic/bitops/atomic.h
use _atomic_spin_lock_irqsave()

 #define test_and_set_bit_lock(nr, addr)  test_and_set_bit(nr, addr)

 static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
 {
         unsigned long mask = BIT_MASK(nr);
         unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
         unsigned long old;
         unsigned long flags;

         _atomic_spin_lock_irqsave(p, flags);
         old = *p;
         *p = old | mask;
         _atomic_spin_unlock_irqrestore(p, flags);

         return (old & mask) != 0;
 }

so overwriting it from the outside world (w/o taking _atomic_spin_lock_irqsave(p))
can theoretically be tricky in some cases.

	-ss

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


Thread

Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Minchan Kim <minchan@kernel.org> - 2016-01-15 15:40 +0100
  Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Vlastimil Babka <vbabka@suse.cz> - 2016-01-15 16:50 +0100
    Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-01-16 05:20 +0100
      Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Vlastimil Babka <vbabka@suse.cz> - 2016-01-16 08:50 +0100
        Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-01-16 09:10 +0100
          Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Vlastimil Babka <vbabka@suse.cz> - 2016-01-16 09:20 +0100
            Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-01-16 11:10 +0100
              Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Junil Lee <junil0814.lee@lge.com> - 2016-01-18 02:10 +0100
            Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Minchan Kim <minchan@kernel.org> - 2016-01-18 07:40 +0100
              Re: [PATCH v2] zsmalloc: fix migrate_zspage-zs_free race condition Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-01-18 08:10 +0100

csiph-web